drivers/md/bcache/bset.c
Source file repositories/reference/linux-study-clean/drivers/md/bcache/bset.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/md/bcache/bset.c- Extension
.c- Size
- 33576 bytes
- Lines
- 1391
- 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.
- 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
util.hbset.hlinux/console.hlinux/sched/clock.hlinux/random.hlinux/prefetch.h
Detected Declarations
struct bkey_floatstruct bset_search_iterfunction bch_dump_bsetfunction bch_dump_bucketfunction __bch_count_datafunction __bch_check_keysfunction for_each_keyfunction bch_btree_iter_next_checkfunction bch_btree_iter_next_checkfunction bch_keylist_pop_frontfunction bch_bkey_copy_single_ptrfunction __bch_cut_frontfunction __bch_cut_backfunction bytesfunction btree_keys_cachelinesfunction bset_tree_bytesfunction bset_prev_bytesfunction bch_btree_keys_freefunction bch_btree_keys_allocfunction bch_btree_keys_initfunction kzallocfunction inorder_prevfunction __to_inorderfunction to_inorderfunction __inorder_to_treefunction inorder_to_treefunction inorder_testfunction cacheline_to_bkeyfunction bkey_to_cachelinefunction bkey_to_cacheline_offsetfunction shrd128function make_bfloatfunction make_bfloatfunction bset_alloc_treefunction bch_bset_build_unwritten_treefunction bch_bset_init_nextfunction nodefunction bch_bset_fix_invalidated_keyfunction bch_bset_fix_lookup_tablefunction bch_bkey_try_mergefunction bch_bset_insertfunction bch_btree_insert_keyfunction bset_search_write_setfunction bset_search_treefunction bset_search_write_setfunction btree_iter_cmpfunction btree_iter_endfunction bch_btree_iter_push
Annotated Snippet
struct bkey_float {
unsigned int exponent:BKEY_EXPONENT_BITS;
unsigned int m:BKEY_MID_BITS;
unsigned int mantissa:BKEY_MANTISSA_BITS;
} __packed;
/*
* BSET_CACHELINE was originally intended to match the hardware cacheline size -
* it used to be 64, but I realized the lookup code would touch slightly less
* memory if it was 128.
*
* It definites the number of bytes (in struct bset) per struct bkey_float in
* the auxiliar search tree - when we're done searching the bset_float tree we
* have this many bytes left that we do a linear search over.
*
* Since (after level 5) every level of the bset_tree is on a new cacheline,
* we're touching one fewer cacheline in the bset tree in exchange for one more
* cacheline in the linear search - but the linear search might stop before it
* gets to the second cacheline.
*/
#define BSET_CACHELINE 128
/* Space required for the btree node keys */
static inline size_t btree_keys_bytes(struct btree_keys *b)
{
return PAGE_SIZE << b->page_order;
}
static inline size_t btree_keys_cachelines(struct btree_keys *b)
{
return btree_keys_bytes(b) / BSET_CACHELINE;
}
/* Space required for the auxiliary search trees */
static inline size_t bset_tree_bytes(struct btree_keys *b)
{
return btree_keys_cachelines(b) * sizeof(struct bkey_float);
}
/* Space required for the prev pointers */
static inline size_t bset_prev_bytes(struct btree_keys *b)
{
return btree_keys_cachelines(b) * sizeof(uint8_t);
}
/* Memory allocation */
void bch_btree_keys_free(struct btree_keys *b)
{
struct bset_tree *t = b->set;
if (bset_prev_bytes(b) < PAGE_SIZE)
kfree(t->prev);
else
free_pages((unsigned long) t->prev,
get_order(bset_prev_bytes(b)));
if (bset_tree_bytes(b) < PAGE_SIZE)
kfree(t->tree);
else
free_pages((unsigned long) t->tree,
get_order(bset_tree_bytes(b)));
free_pages((unsigned long) t->data, b->page_order);
t->prev = NULL;
t->tree = NULL;
t->data = NULL;
}
int bch_btree_keys_alloc(struct btree_keys *b,
unsigned int page_order,
gfp_t gfp)
{
struct bset_tree *t = b->set;
BUG_ON(t->data);
b->page_order = page_order;
t->data = (void *) __get_free_pages(__GFP_COMP|gfp, b->page_order);
if (!t->data)
goto err;
t->tree = bset_tree_bytes(b) < PAGE_SIZE
? kmalloc(bset_tree_bytes(b), gfp)
: (void *) __get_free_pages(gfp, get_order(bset_tree_bytes(b)));
if (!t->tree)
goto err;
Annotation
- Immediate include surface: `util.h`, `bset.h`, `linux/console.h`, `linux/sched/clock.h`, `linux/random.h`, `linux/prefetch.h`.
- Detected declarations: `struct bkey_float`, `struct bset_search_iter`, `function bch_dump_bset`, `function bch_dump_bucket`, `function __bch_count_data`, `function __bch_check_keys`, `function for_each_key`, `function bch_btree_iter_next_check`, `function bch_btree_iter_next_check`, `function bch_keylist_pop_front`.
- 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.