drivers/md/dm-vdo/indexer/sparse-cache.c
Source file repositories/reference/linux-study-clean/drivers/md/dm-vdo/indexer/sparse-cache.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/dm-vdo/indexer/sparse-cache.c- Extension
.c- Size
- 21316 bytes
- Lines
- 623
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sparse-cache.hlinux/cache.hlinux/delay.hlinux/dm-bufio.hlogger.hmemory-alloc.hpermassert.hchapter-index.hconfig.hindex.h
Detected Declarations
struct search_liststruct threads_barrierstruct sparse_cachefunction initialize_threads_barrierfunction __downfunction enter_threads_barrierfunction initialize_cached_chapter_indexfunction make_search_listfunction uds_make_sparse_cachefunction set_skip_searchfunction score_search_hitfunction score_search_missfunction release_cached_chapter_indexfunction uds_free_sparse_cachefunction set_newest_entryfunction uds_sparse_cache_containsfunction uds_update_sparse_cachefunction cache_chapter_indexfunction copy_search_listfunction uds_update_sparse_cachefunction uds_invalidate_sparse_cachefunction should_skip_chapterfunction search_cached_chapter_indexfunction uds_search_sparse_cache
Annotated Snippet
struct search_list {
u8 capacity;
u8 first_dead_entry;
struct cached_chapter_index *entries[];
};
struct threads_barrier {
/* Lock for this barrier object */
struct semaphore lock;
/* Semaphore for threads waiting at this barrier */
struct semaphore wait;
/* Number of threads which have arrived */
int arrived;
/* Total number of threads using this barrier */
int thread_count;
};
struct sparse_cache {
const struct index_geometry *geometry;
unsigned int capacity;
unsigned int zone_count;
unsigned int skip_threshold;
struct search_list *search_lists[MAX_ZONES];
struct cached_chapter_index **scratch_entries;
struct threads_barrier begin_update_barrier;
struct threads_barrier end_update_barrier;
struct cached_chapter_index chapters[];
};
static void initialize_threads_barrier(struct threads_barrier *barrier,
unsigned int thread_count)
{
sema_init(&barrier->lock, 1);
barrier->arrived = 0;
barrier->thread_count = thread_count;
sema_init(&barrier->wait, 0);
}
static inline void __down(struct semaphore *semaphore)
{
/*
* Do not use down(semaphore). Instead use down_interruptible so that
* we do not get 120 second stall messages in kern.log.
*/
while (down_interruptible(semaphore) != 0) {
/*
* If we're called from a user-mode process (e.g., "dmsetup
* remove") while waiting for an operation that may take a
* while (e.g., UDS index save), and a signal is sent (SIGINT,
* SIGUSR2), then down_interruptible will not block. If that
* happens, sleep briefly to avoid keeping the CPU locked up in
* this loop. We could just call cond_resched, but then we'd
* still keep consuming CPU time slices and swamp other threads
* trying to do computational work.
*/
fsleep(1000);
}
}
static void enter_threads_barrier(struct threads_barrier *barrier)
{
__down(&barrier->lock);
if (++barrier->arrived == barrier->thread_count) {
/* last thread */
int i;
for (i = 1; i < barrier->thread_count; i++)
up(&barrier->wait);
barrier->arrived = 0;
up(&barrier->lock);
} else {
up(&barrier->lock);
__down(&barrier->wait);
}
}
static int __must_check initialize_cached_chapter_index(struct cached_chapter_index *chapter,
const struct index_geometry *geometry)
{
int result;
chapter->virtual_chapter = NO_CHAPTER;
chapter->index_pages_count = geometry->index_pages_per_chapter;
result = vdo_allocate(chapter->index_pages_count, __func__, &chapter->index_pages);
if (result != VDO_SUCCESS)
Annotation
- Immediate include surface: `sparse-cache.h`, `linux/cache.h`, `linux/delay.h`, `linux/dm-bufio.h`, `logger.h`, `memory-alloc.h`, `permassert.h`, `chapter-index.h`.
- Detected declarations: `struct search_list`, `struct threads_barrier`, `struct sparse_cache`, `function initialize_threads_barrier`, `function __down`, `function enter_threads_barrier`, `function initialize_cached_chapter_index`, `function make_search_list`, `function uds_make_sparse_cache`, `function set_skip_search`.
- Atlas domain: Driver Families / drivers/md.
- Implementation status: source implementation candidate.
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.