Skip to content

Commit 10352b8

Browse files
yangdongshengkawasaki
authored andcommitted
dm-pcache: add cache_key
Add *cache_key.c* which becomes the heart of dm-pcache’s in-memory index and on-media key-set (“kset”) format. * Key objects (`struct pcache_cache_key`) - Slab-backed allocator & ref-count helpers - `cache_key_encode()/decode()` translate between in-memory keys and their on-disk representation, validating CRC when *cache_data_crc* is enabled. * Kset construction & persistence - Per-kset buffer lives in `struct pcache_cache_kset`; keys are appended until full or *force_close* triggers an immediate flush. - `cache_kset_close()` writes the kset to the *key_head* segment, automatically chaining a *LAST* kset header when rolling over to a freshly allocated segment. * Red-black tree with striping - Cache space is divided into *subtrees* to reduce lock contention; each subtree owns its own RB-root + spinlock. - Complex overlap-resolution logic (`cache_insert_fixup()`) ensures newly inserted keys never leave overlapping stale ranges behind (head/tail/contain/contained cases handled). * Replay on start-up - `cache_replay()` walks from *key_tail* to *key_head*, re-hydrates keys, validates CRC/magic, seamlessly skipping placeholder “empty” keys left by read-misses. * Background maintenance - `clean_work` lazily prunes invalidated keys after GC. - `kset_flush_work` background thread to close a kset. With this patch dm-pcache can persistently track cached extents, rebuild its index after crash, and guarantee non-overlapping key space – paving the way for functional read/write caching. Signed-off-by: Dongsheng Yang <[email protected]>
1 parent 525b046 commit 10352b8

1 file changed

Lines changed: 900 additions & 0 deletions

File tree

0 commit comments

Comments
 (0)