SLAB_SHIFT_FROM_SIZE
Description
Compile-time ctz for the supported slot sizes. Folded to a constant when the input is a literal (the common case – SlabAllocatorInit(16)). For runtime values, evaluates as a small conditional cascade once at init. Always paired with SLAB_ROUNDUP_POW2 so the input is guaranteed to land on a supported power of two.
Parameters
| Name | Direction | Description |
|---|---|---|
s |
in | Power-of-two slot size in bytes (caller-guaranteed via SLAB_ROUNDUP_POW2). |
Success
Returns log2(s) for supported sizes (16..4096), as a u32 literal in [4, 12].
Failure
Returns 0 for any unsupported input; the slab validator rejects a slot_size_shift == 0 slab at first allocation.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Slab.h:189:
.bitmaps = NULL, \
.slot_size = SLAB_ROUNDUP_POW2(slot_size_bytes), \
.slot_size_shift = (u8)SLAB_SHIFT_FROM_SIZE(SLAB_ROUNDUP_POW2(slot_size_bytes)), \
.bitmap_words_per_slab = 0, \
.page = PageAllocatorInit() \
- In
Slab.h:217:
.bitmaps = NULL, \
.slot_size = SLAB_ROUNDUP_POW2(slot_size_bytes), \
.slot_size_shift = (u8)SLAB_SHIFT_FROM_SIZE(SLAB_ROUNDUP_POW2(slot_size_bytes)), \
.bitmap_words_per_slab = 0, \
.page = PageAllocatorInit() \
Last updated on