drivers/md/dm-writecache.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-writecache.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-writecache.c- Extension
.c- Size
- 70738 bytes
- Lines
- 2772
- 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/device-mapper.hlinux/module.hlinux/init.hlinux/vmalloc.hlinux/kthread.hlinux/dm-io.hlinux/dm-kcopyd.hlinux/dax.hlinux/libnvdimm.hlinux/delay.hdm-io-tracker.h
Detected Declarations
struct wc_memory_entrystruct wc_memory_superblockstruct wc_entrystruct dm_writecachestruct writeback_structstruct copy_structstruct io_notifystruct writeback_listenum wc_map_opfunction wc_lockfunction wc_unlockfunction persistent_memory_claimfunction persistent_memory_claimfunction persistent_memory_releasefunction persistent_memory_page_offsetfunction persistent_memory_flush_cachefunction persistent_memory_invalidate_cachefunction cache_sectorfunction read_original_sectorfunction read_seq_countfunction clear_seq_countfunction write_original_sector_seq_countfunction writecache_flush_all_metadatafunction writecache_flush_regionfunction writecache_notify_iofunction writecache_wait_for_iosfunction ssd_commit_flushedfunction ssd_commit_superblockfunction writecache_commit_flushedfunction writecache_disk_flushfunction writecache_insert_entryfunction writecache_unlinkfunction writecache_add_to_freelistfunction writecache_verify_watermarkfunction writecache_max_age_timerfunction writecache_free_entryfunction writecache_wait_on_freelistfunction writecache_poison_listsfunction writecache_flush_entryfunction writecache_entry_is_committedfunction writecache_flushfunction writecache_flush_workfunction writecache_autocommit_timerfunction writecache_schedule_autocommitfunction writecache_discardfunction writecache_wait_for_writebackfunction writecache_suspendfunction writecache_alloc_entries
Annotated Snippet
struct wc_memory_entry {
__le64 original_sector;
__le64 seq_count;
};
struct wc_memory_superblock {
union {
struct {
__le32 magic;
__le32 version;
__le32 block_size;
__le32 pad;
__le64 n_blocks;
__le64 seq_count;
};
__le64 padding[8];
};
struct wc_memory_entry entries[];
};
struct wc_entry {
struct rb_node rb_node;
struct list_head lru;
unsigned short wc_list_contiguous;
#if BITS_PER_LONG == 64
bool write_in_progress : 1;
unsigned long index : 47;
#else
bool write_in_progress;
unsigned long index;
#endif
unsigned long age;
#ifdef DM_WRITECACHE_HANDLE_HARDWARE_ERRORS
uint64_t original_sector;
uint64_t seq_count;
#endif
};
#ifdef DM_WRITECACHE_HAS_PMEM
#define WC_MODE_PMEM(wc) ((wc)->pmem_mode)
#define WC_MODE_FUA(wc) ((wc)->writeback_fua)
#else
#define WC_MODE_PMEM(wc) false
#define WC_MODE_FUA(wc) false
#endif
#define WC_MODE_SORT_FREELIST(wc) (!WC_MODE_PMEM(wc))
struct dm_writecache {
struct mutex lock;
struct list_head lru;
union {
struct list_head freelist;
struct {
struct rb_root freetree;
struct wc_entry *current_free;
};
};
struct rb_root tree;
size_t freelist_size;
size_t writeback_size;
size_t freelist_high_watermark;
size_t freelist_low_watermark;
unsigned long max_age;
unsigned long pause;
unsigned int uncommitted_blocks;
unsigned int autocommit_blocks;
unsigned int max_writeback_jobs;
int error;
unsigned long autocommit_jiffies;
struct timer_list autocommit_timer;
struct wait_queue_head freelist_wait;
struct timer_list max_age_timer;
atomic_t bio_in_progress[2];
struct wait_queue_head bio_in_progress_wait[2];
struct dm_target *ti;
struct dm_dev *dev;
struct dm_dev *ssd_dev;
sector_t start_sector;
void *memory_map;
uint64_t memory_map_size;
size_t metadata_sectors;
size_t n_blocks;
uint64_t seq_count;
Annotation
- Immediate include surface: `linux/device-mapper.h`, `linux/module.h`, `linux/init.h`, `linux/vmalloc.h`, `linux/kthread.h`, `linux/dm-io.h`, `linux/dm-kcopyd.h`, `linux/dax.h`.
- Detected declarations: `struct wc_memory_entry`, `struct wc_memory_superblock`, `struct wc_entry`, `struct dm_writecache`, `struct writeback_struct`, `struct copy_struct`, `struct io_notify`, `struct writeback_list`, `enum wc_map_op`, `function wc_lock`.
- 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.