drivers/md/dm-cache-background-tracker.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-cache-background-tracker.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-cache-background-tracker.c- Extension
.c- Size
- 4973 bytes
- Lines
- 240
- 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
dm-cache-background-tracker.h
Detected Declarations
struct background_trackerfunction btracker_destroyfunction cmp_oblockfunction __insert_pendingfunction update_statsfunction btracker_nr_demotions_queuedfunction max_work_reachedfunction btracker_queuefunction btracker_issuefunction btracker_completefunction btracker_promotion_already_presentexport btracker_createexport btracker_destroyexport btracker_nr_demotions_queuedexport btracker_queueexport btracker_issueexport btracker_completeexport btracker_promotion_already_present
Annotated Snippet
struct background_tracker {
unsigned int max_work;
atomic_t pending_promotes;
atomic_t pending_writebacks;
atomic_t pending_demotes;
struct list_head issued;
struct list_head queued;
struct rb_root pending;
};
struct kmem_cache *btracker_work_cache = NULL;
struct background_tracker *btracker_create(unsigned int max_work)
{
struct background_tracker *b = kmalloc_obj(*b);
if (!b) {
DMERR("couldn't create background_tracker");
return NULL;
}
b->max_work = max_work;
atomic_set(&b->pending_promotes, 0);
atomic_set(&b->pending_writebacks, 0);
atomic_set(&b->pending_demotes, 0);
INIT_LIST_HEAD(&b->issued);
INIT_LIST_HEAD(&b->queued);
b->pending = RB_ROOT;
return b;
}
EXPORT_SYMBOL_GPL(btracker_create);
void btracker_destroy(struct background_tracker *b)
{
struct bt_work *w, *tmp;
BUG_ON(!list_empty(&b->issued));
list_for_each_entry_safe (w, tmp, &b->queued, list) {
list_del(&w->list);
kmem_cache_free(btracker_work_cache, w);
}
kfree(b);
}
EXPORT_SYMBOL_GPL(btracker_destroy);
static int cmp_oblock(dm_oblock_t lhs, dm_oblock_t rhs)
{
if (from_oblock(lhs) < from_oblock(rhs))
return -1;
if (from_oblock(rhs) < from_oblock(lhs))
return 1;
return 0;
}
static bool __insert_pending(struct background_tracker *b,
struct bt_work *nw)
{
int cmp;
struct bt_work *w;
struct rb_node **new = &b->pending.rb_node, *parent = NULL;
while (*new) {
w = container_of(*new, struct bt_work, node);
parent = *new;
cmp = cmp_oblock(w->work.oblock, nw->work.oblock);
if (cmp < 0)
new = &((*new)->rb_left);
else if (cmp > 0)
new = &((*new)->rb_right);
else
/* already present */
return false;
}
rb_link_node(&nw->node, parent, new);
rb_insert_color(&nw->node, &b->pending);
return true;
}
Annotation
- Immediate include surface: `dm-cache-background-tracker.h`.
- Detected declarations: `struct background_tracker`, `function btracker_destroy`, `function cmp_oblock`, `function __insert_pending`, `function update_stats`, `function btracker_nr_demotions_queued`, `function max_work_reached`, `function btracker_queue`, `function btracker_issue`, `function btracker_complete`.
- 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.