drivers/md/bcache/bset.h
Source file repositories/reference/linux-study-clean/drivers/md/bcache/bset.h
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/bcache/bset.h- Extension
.h- Size
- 20031 bytes
- Lines
- 606
- 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
linux/kernel.hlinux/types.hbcache_ondisk.hutil.h
Detected Declarations
struct btree_keysstruct btree_iterstruct btree_iter_setstruct bkey_floatstruct bset_treestruct btree_keys_opsstruct btree_keysstruct btree_iterstruct btree_iter_setstruct btree_iter_stackstruct bset_sort_statestruct bset_statsstruct keylistfunction bset_writtenfunction bkey_writtenfunction bset_byte_offsetfunction bset_sector_offsetfunction bch_btree_keys_u64s_remainingfunction bch_btree_sortfunction bkey_initfunction bkey_cmpfunction bch_cut_frontfunction bch_cut_backfunction preceding_keyfunction bch_ptr_invalidfunction bch_ptr_badfunction bch_bkey_to_textfunction bch_bkey_equal_headerfunction bch_keylist_initfunction bch_keylist_init_singlefunction bch_keylist_pushfunction bch_keylist_addfunction bch_keylist_emptyfunction bch_keylist_resetfunction bch_keylist_freefunction bch_keylist_nkeysfunction bch_keylist_bytesfunction __bch_count_datafunction __printffunction btree_keys_expensive_checksfunction bch_count_data
Annotated Snippet
struct bset_tree {
/*
* We construct a binary tree in an array as if the array
* started at 1, so that things line up on the same cachelines
* better: see comments in bset.c at cacheline_to_bkey() for
* details
*/
/* size of the binary tree and prev array */
unsigned int size;
/* function of size - precalculated for to_inorder() */
unsigned int extra;
/* copy of the last key in the set */
struct bkey end;
struct bkey_float *tree;
/*
* The nodes in the bset tree point to specific keys - this
* array holds the sizes of the previous key.
*
* Conceptually it's a member of struct bkey_float, but we want
* to keep bkey_float to 4 bytes and prev isn't used in the fast
* path.
*/
uint8_t *prev;
/* The actual btree node, with pointers to each sorted set */
struct bset *data;
};
struct btree_keys_ops {
bool (*sort_cmp)(struct btree_iter_set l,
struct btree_iter_set r);
struct bkey *(*sort_fixup)(struct btree_iter *iter,
struct bkey *tmp);
bool (*insert_fixup)(struct btree_keys *b,
struct bkey *insert,
struct btree_iter *iter,
struct bkey *replace_key);
bool (*key_invalid)(struct btree_keys *bk,
const struct bkey *k);
bool (*key_bad)(struct btree_keys *bk,
const struct bkey *k);
bool (*key_merge)(struct btree_keys *bk,
struct bkey *l, struct bkey *r);
void (*key_to_text)(char *buf,
size_t size,
const struct bkey *k);
void (*key_dump)(struct btree_keys *keys,
const struct bkey *k);
/*
* Only used for deciding whether to use START_KEY(k) or just the key
* itself in a couple places
*/
bool is_extents;
};
struct btree_keys {
const struct btree_keys_ops *ops;
uint8_t page_order;
uint8_t nsets;
unsigned int last_set_unwritten:1;
bool *expensive_debug_checks;
/*
* Sets of sorted keys - the real btree node - plus a binary search tree
*
* set[0] is special; set[0]->tree, set[0]->prev and set[0]->data point
* to the memory we have allocated for this btree node. Additionally,
* set[0]->data points to the entire btree node as it exists on disk.
*/
struct bset_tree set[MAX_BSETS];
};
static inline struct bset_tree *bset_tree_last(struct btree_keys *b)
{
return b->set + b->nsets;
}
static inline bool bset_written(struct btree_keys *b, struct bset_tree *t)
{
return t <= b->set + b->nsets - b->last_set_unwritten;
}
static inline bool bkey_written(struct btree_keys *b, struct bkey *k)
{
return !b->last_set_unwritten || k < b->set[b->nsets].data->start;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `bcache_ondisk.h`, `util.h`.
- Detected declarations: `struct btree_keys`, `struct btree_iter`, `struct btree_iter_set`, `struct bkey_float`, `struct bset_tree`, `struct btree_keys_ops`, `struct btree_keys`, `struct btree_iter`, `struct btree_iter_set`, `struct btree_iter_stack`.
- 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.