drivers/md/bcache/writeback.c
Source file repositories/reference/linux-study-clean/drivers/md/bcache/writeback.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/bcache/writeback.c- Extension
.c- Size
- 29010 bytes
- Lines
- 1100
- 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
bcache.hbtree.hdebug.hwriteback.hlinux/delay.hlinux/kthread.hlinux/sched/clock.htrace/events/bcache.h
Detected Declarations
struct dirty_iostruct sectors_dirty_initfunction update_gc_after_writebackfunction __calc_target_ratefunction __update_writeback_ratefunction idle_counter_exceededfunction update_writeback_ratefunction update_writeback_ratefunction test_bitfunction numberfunction writeback_delayfunction dirty_initfunction CLOSURE_CALLBACKfunction CLOSURE_CALLBACKfunction dirty_endiofunction CLOSURE_CALLBACKfunction read_dirty_endiofunction CLOSURE_CALLBACKfunction read_dirtyfunction bcache_dev_sectors_dirty_addfunction dirty_predfunction refill_full_stripesfunction refill_dirtyfunction bch_writeback_threadfunction bch_cached_dev_detachfunction highfunction sectors_dirty_init_fnfunction bch_root_node_dirty_initfunction bch_dirty_init_threadfunction bch_btre_dirty_init_thread_nrfunction bch_sectors_dirty_initfunction for_each_key_filterfunction bch_cached_dev_writeback_initfunction bch_cached_dev_writeback_start
Annotated Snippet
struct dirty_io {
struct closure cl;
struct cached_dev *dc;
uint16_t sequence;
struct bio bio;
};
static void dirty_init(struct keybuf_key *w)
{
struct dirty_io *io = w->private;
struct bio *bio = &io->bio;
bio_init_inline(bio, NULL,
DIV_ROUND_UP(KEY_SIZE(&w->key), PAGE_SECTORS), 0);
if (!io->dc->writeback_percent)
bio->bi_ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_IDLE, 0);
bio->bi_iter.bi_size = KEY_SIZE(&w->key) << 9;
bio->bi_private = w;
bch_bio_map(bio, NULL);
}
static CLOSURE_CALLBACK(dirty_io_destructor)
{
closure_type(io, struct dirty_io, cl);
kfree(io);
}
static CLOSURE_CALLBACK(write_dirty_finish)
{
closure_type(io, struct dirty_io, cl);
struct keybuf_key *w = io->bio.bi_private;
struct cached_dev *dc = io->dc;
bio_free_pages(&io->bio);
/* This is kind of a dumb way of signalling errors. */
if (KEY_DIRTY(&w->key)) {
int ret;
unsigned int i;
struct keylist keys;
bch_keylist_init(&keys);
bkey_copy(keys.top, &w->key);
SET_KEY_DIRTY(keys.top, false);
bch_keylist_push(&keys);
for (i = 0; i < KEY_PTRS(&w->key); i++)
atomic_inc(&PTR_BUCKET(dc->disk.c, &w->key, i)->pin);
ret = bch_btree_insert(dc->disk.c, &keys, NULL, &w->key);
if (ret)
trace_bcache_writeback_collision(&w->key);
atomic_long_inc(ret
? &dc->disk.c->writeback_keys_failed
: &dc->disk.c->writeback_keys_done);
}
bch_keybuf_del(&dc->writeback_keys, w);
up(&dc->in_flight);
closure_return_with_destructor(cl, dirty_io_destructor);
}
static void dirty_endio(struct bio *bio)
{
struct keybuf_key *w = bio->bi_private;
struct dirty_io *io = w->private;
if (bio->bi_status) {
SET_KEY_DIRTY(&w->key, false);
bch_count_backing_io_errors(io->dc, bio);
}
closure_put(&io->cl);
}
static CLOSURE_CALLBACK(write_dirty)
{
closure_type(io, struct dirty_io, cl);
struct keybuf_key *w = io->bio.bi_private;
struct cached_dev *dc = io->dc;
uint16_t next_sequence;
if (atomic_read(&dc->writeback_sequence_next) != io->sequence) {
Annotation
- Immediate include surface: `bcache.h`, `btree.h`, `debug.h`, `writeback.h`, `linux/delay.h`, `linux/kthread.h`, `linux/sched/clock.h`, `trace/events/bcache.h`.
- Detected declarations: `struct dirty_io`, `struct sectors_dirty_init`, `function update_gc_after_writeback`, `function __calc_target_rate`, `function __update_writeback_rate`, `function idle_counter_exceeded`, `function update_writeback_rate`, `function update_writeback_rate`, `function test_bit`, `function number`.
- 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.