drivers/md/md-bitmap.c
Source file repositories/reference/linux-study-clean/drivers/md/md-bitmap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/md-bitmap.c- Extension
.c- Size
- 84998 bytes
- Lines
- 3142
- Domain
- Driver Families
- Bucket
- drivers/md
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/blkdev.hlinux/module.hlinux/errno.hlinux/slab.hlinux/init.hlinux/timer.hlinux/sched.hlinux/list.hlinux/file.hlinux/mount.hlinux/buffer_head.hlinux/seq_file.htrace/events/block.hmd.hmd-bitmap.hmd-cluster.h
Detected Declarations
struct bitmap_pagestruct bitmapstruct bitmap_countsstruct bitmap_storagestruct bitmap_unplug_workenum bitmap_page_attrfunction bitmap_enabledfunction md_bitmap_checkpagefunction md_bitmap_checkfreefunction read_sb_pagefunction rdev_for_eachfunction optimal_io_sizefunction bitmap_io_sizefunction __write_sb_pagefunction write_sb_pagefunction end_bitmap_writefunction write_file_pagefunction free_buffersfunction blockfunction write_file_pagefunction free_buffersfunction filemap_write_pagefunction md_bitmap_wait_writesfunction bitmap_update_sbfunction bitmap_print_sbfunction md_bitmap_new_disk_sbfunction md_bitmap_read_sbfunction file_page_indexfunction file_page_offsetfunction md_bitmap_storage_allocfunction md_bitmap_file_unmapfunction md_bitmap_file_kickfunction set_page_attrfunction clear_page_attrfunction test_page_attrfunction test_and_clear_page_attrfunction setfunction md_bitmap_file_clear_bitfunction md_bitmap_file_test_bitfunction __bitmap_unplugfunction md_bitmap_unplug_fnfunction bitmap_unplug_asyncfunction bitmap_unplugfunction md_bitmap_init_from_diskfunction bitmap_write_allfunction md_bitmap_count_pagefunction md_bitmap_set_pendingfunction mddev_set_timeout
Annotated Snippet
struct bitmap_page {
/*
* map points to the actual memory page
*/
char *map;
/*
* in emergencies (when map cannot be alloced), hijack the map
* pointer and use it as two counters itself
*/
unsigned int hijacked:1;
/*
* If any counter in this page is '1' or '2' - and so could be
* cleared then that page is marked as 'pending'
*/
unsigned int pending:1;
/*
* count of dirty bits on the page
*/
unsigned int count:30;
};
/* the main bitmap structure - one per mddev */
struct bitmap {
struct bitmap_counts {
spinlock_t lock;
struct bitmap_page *bp;
/* total number of pages in the bitmap */
unsigned long pages;
/* number of pages not yet allocated */
unsigned long missing_pages;
/* chunksize = 2^chunkshift (for bitops) */
unsigned long chunkshift;
/* total number of data chunks for the array */
unsigned long chunks;
} counts;
struct mddev *mddev; /* the md device that the bitmap is for */
__u64 events_cleared;
int need_sync;
struct bitmap_storage {
/* backing disk file */
struct file *file;
/* cached copy of the bitmap file superblock */
struct page *sb_page;
unsigned long sb_index;
/* list of cache pages for the file */
struct page **filemap;
/* attributes associated filemap pages */
unsigned long *filemap_attr;
/* number of pages in the file */
unsigned long file_pages;
/* total bytes in the bitmap */
unsigned long bytes;
} storage;
unsigned long flags;
int allclean;
atomic_t behind_writes;
/* highest actual value at runtime */
unsigned long behind_writes_used;
/*
* the bitmap daemon - periodically wakes up and sweeps the bitmap
* file, cleaning up bits and flushing out pages to disk as necessary
*/
unsigned long daemon_lastrun; /* jiffies of last run */
/*
* when we lasted called end_sync to update bitmap with resync
* progress.
*/
unsigned long last_end_sync;
/* pending writes to the bitmap file */
atomic_t pending_writes;
wait_queue_head_t write_wait;
wait_queue_head_t overflow_wait;
wait_queue_head_t behind_wait;
struct kernfs_node *sysfs_can_clear;
/* slot offset for clustered env */
int cluster_slot;
};
static struct workqueue_struct *md_bitmap_wq;
static struct attribute_group md_bitmap_internal_group;
Annotation
- Immediate include surface: `linux/blkdev.h`, `linux/module.h`, `linux/errno.h`, `linux/slab.h`, `linux/init.h`, `linux/timer.h`, `linux/sched.h`, `linux/list.h`.
- Detected declarations: `struct bitmap_page`, `struct bitmap`, `struct bitmap_counts`, `struct bitmap_storage`, `struct bitmap_unplug_work`, `enum bitmap_page_attr`, `function bitmap_enabled`, `function md_bitmap_checkpage`, `function md_bitmap_checkfree`, `function read_sb_page`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.