drivers/md/raid5-cache.c
Source file repositories/reference/linux-study-clean/drivers/md/raid5-cache.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/raid5-cache.c- Extension
.c- Size
- 89924 bytes
- Lines
- 3188
- Domain
- Driver Families
- Bucket
- drivers/md
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/kernel.hlinux/wait.hlinux/blkdev.hlinux/slab.hlinux/raid/md_p.hlinux/crc32c.hlinux/random.hlinux/kthread.hlinux/types.hmd.hraid5.hmd-bitmap.hraid5-log.h
Detected Declarations
struct r5l_logstruct r5l_io_unitstruct r5l_recovery_ctxenum r5l_io_unit_statefunction r5c_finish_stripe_write_outfunction r5c_is_writebackfunction r5l_ring_addfunction r5l_ring_distancefunction r5l_has_free_spacefunction __r5l_set_io_unit_statefunction r5c_return_dev_pending_writesfunction r5c_handle_cached_data_endiofunction r5c_check_stripe_cache_usagefunction r5c_check_cached_full_stripefunction delayedfunction r5c_update_log_statefunction r5c_make_stripe_write_outfunction r5c_handle_data_cachedfunction r5c_handle_parity_cachedfunction writingfunction r5l_io_run_stripesfunction list_for_each_entry_safefunction r5l_log_run_stripesfunction list_for_each_entry_safefunction r5l_move_to_end_iosfunction list_for_each_entry_safefunction r5l_log_endiofunction r5l_do_submit_iofunction r5l_submit_io_asyncfunction r5c_disable_writeback_asyncfunction r5l_submit_current_iofunction r5_reserve_log_entryfunction r5l_get_metafunction r5l_append_payload_metafunction r5l_append_payload_pagefunction r5l_append_flush_payloadfunction r5l_log_stripefunction r5l_add_no_space_stripefunction r5l_write_stripefunction test_bitfunction yetfunction r5l_write_stripe_runfunction r5l_handle_flush_requestfunction r5l_run_no_space_stripesfunction r5c_calculate_new_cpfunction r5l_reclaimable_spacefunction r5l_run_no_mem_stripefunction r5l_complete_finished_ios
Annotated Snippet
struct r5l_log {
struct md_rdev *rdev;
u32 uuid_checksum;
sector_t device_size; /* log device size, round to
* BLOCK_SECTORS */
sector_t max_free_space; /* reclaim run if free space is at
* this size */
sector_t last_checkpoint; /* log tail. where recovery scan
* starts from */
u64 last_cp_seq; /* log tail sequence */
sector_t log_start; /* log head. where new data appends */
u64 seq; /* log head sequence */
sector_t next_checkpoint;
struct mutex io_mutex;
struct r5l_io_unit *current_io; /* current io_unit accepting new data */
spinlock_t io_list_lock;
struct list_head running_ios; /* io_units which are still running,
* and have not yet been completely
* written to the log */
struct list_head io_end_ios; /* io_units which have been completely
* written to the log but not yet written
* to the RAID */
struct list_head flushing_ios; /* io_units which are waiting for log
* cache flush */
struct list_head finished_ios; /* io_units which settle down in log disk */
struct bio flush_bio;
struct list_head no_mem_stripes; /* pending stripes, -ENOMEM */
struct kmem_cache *io_kc;
mempool_t io_pool;
struct bio_set bs;
mempool_t meta_pool;
struct md_thread __rcu *reclaim_thread;
unsigned long reclaim_target; /* number of space that need to be
* reclaimed. if it's 0, reclaim spaces
* used by io_units which are in
* IO_UNIT_STRIPE_END state (eg, reclaim
* doesn't wait for specific io_unit
* switching to IO_UNIT_STRIPE_END
* state) */
wait_queue_head_t iounit_wait;
struct list_head no_space_stripes; /* pending stripes, log has no space */
spinlock_t no_space_stripes_lock;
bool need_cache_flush;
/* for r5c_cache */
enum r5c_journal_mode r5c_journal_mode;
/* all stripes in r5cache, in the order of seq at sh->log_start */
struct list_head stripe_in_journal_list;
spinlock_t stripe_in_journal_lock;
atomic_t stripe_in_journal_count;
/* to submit async io_units, to fulfill ordering of flush */
struct work_struct deferred_io_work;
/* to disable write back during in degraded mode */
struct work_struct disable_writeback_work;
/* to for chunk_aligned_read in writeback mode, details below */
spinlock_t tree_lock;
struct radix_tree_root big_stripe_tree;
};
/*
* Enable chunk_aligned_read() with write back cache.
*
* Each chunk may contain more than one stripe (for example, a 256kB
* chunk contains 64 4kB-page, so this chunk contain 64 stripes). For
* chunk_aligned_read, these stripes are grouped into one "big_stripe".
* For each big_stripe, we count how many stripes of this big_stripe
* are in the write back cache. These data are tracked in a radix tree
* (big_stripe_tree). We use radix_tree item pointer as the counter.
* r5c_tree_index() is used to calculate keys for the radix tree.
*
* chunk_aligned_read() calls r5c_big_stripe_cached() to look up
* big_stripe of each chunk in the tree. If this big_stripe is in the
* tree, chunk_aligned_read() aborts. This look up is protected by
* rcu_read_lock().
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/wait.h`, `linux/blkdev.h`, `linux/slab.h`, `linux/raid/md_p.h`, `linux/crc32c.h`, `linux/random.h`, `linux/kthread.h`.
- Detected declarations: `struct r5l_log`, `struct r5l_io_unit`, `struct r5l_recovery_ctx`, `enum r5l_io_unit_state`, `function r5c_finish_stripe_write_out`, `function r5c_is_writeback`, `function r5l_ring_add`, `function r5l_ring_distance`, `function r5l_has_free_space`, `function __r5l_set_io_unit_state`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: integration 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.