drivers/md/dm-pcache/cache_segment.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-pcache/cache_segment.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-pcache/cache_segment.c- Extension
.c- Size
- 9183 bytes
- Lines
- 309
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
cache_dev.hcache.hbacking_dev.hdm_pcache.h
Detected Declarations
function cache_seg_info_writefunction cache_seg_info_loadfunction cache_seg_ctrl_loadfunction cache_seg_putfunction cache_seg_ctrl_initfunction cache_seg_meta_loadfunction cache_seg_set_next_segfunction cache_seg_initfunction cache_seg_gen_increasefunction cache_seg_getfunction cache_seg_invalidatefunction cache_seg_put
Annotated Snippet
if (cache->last_cache_seg) {
cache->last_cache_seg = 0;
goto again;
}
cache->cache_full = true;
spin_unlock(&cache->seg_map_lock);
return NULL;
}
/*
* found an available cache_seg, mark it used in seg_map
* and update the search hint ->last_cache_seg
*/
__set_bit(seg_id, cache->seg_map);
cache->last_cache_seg = seg_id;
spin_unlock(&cache->seg_map_lock);
cache_seg = &cache->segments[seg_id];
cache_seg->cache_seg_id = seg_id;
return cache_seg;
}
static void cache_seg_gen_increase(struct pcache_cache_segment *cache_seg)
{
spin_lock(&cache_seg->gen_lock);
cache_seg->gen++;
spin_unlock(&cache_seg->gen_lock);
cache_seg_ctrl_write(cache_seg);
}
void cache_seg_get(struct pcache_cache_segment *cache_seg)
{
atomic_inc(&cache_seg->refs);
}
static void cache_seg_invalidate(struct pcache_cache_segment *cache_seg)
{
struct pcache_cache *cache;
cache = cache_seg->cache;
cache_seg_gen_increase(cache_seg);
spin_lock(&cache->seg_map_lock);
if (cache->cache_full)
cache->cache_full = false;
__clear_bit(cache_seg->cache_seg_id, cache->seg_map);
spin_unlock(&cache->seg_map_lock);
pcache_defer_reqs_kick(CACHE_TO_PCACHE(cache));
/* clean_work will clean the bad key in key_tree*/
queue_work(cache_get_wq(cache), &cache->clean_work);
}
void cache_seg_put(struct pcache_cache_segment *cache_seg)
{
if (atomic_dec_and_test(&cache_seg->refs))
cache_seg_invalidate(cache_seg);
}
Annotation
- Immediate include surface: `cache_dev.h`, `cache.h`, `backing_dev.h`, `dm_pcache.h`.
- Detected declarations: `function cache_seg_info_write`, `function cache_seg_info_load`, `function cache_seg_ctrl_load`, `function cache_seg_put`, `function cache_seg_ctrl_init`, `function cache_seg_meta_load`, `function cache_seg_set_next_seg`, `function cache_seg_init`, `function cache_seg_gen_increase`, `function cache_seg_get`.
- 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.