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.

Dependency Surface

Detected Declarations

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

Implementation Notes