GENERIC RADIX TREES SPARSE ARRAYS(9)
β¨ Generic radix trees/sparse arrays β¨
okay bestie, welcome to section 9 of the Kernel API Manual β this is the genradix page and honestly? it's giving "small but mighty" π
πΈ DESCRIPTION πΈ
So a genradix is very simple and minimalistic, and it supports arbitrary size entries up to GENRADIX_NODE_SIZE. no cap, that's the whole vibe β tiny API, does one thing, slays.
You define a genradix with the type it's gonna store, like this π:
static GENRADIX(struct foo) foo_genradix;
and the main operations are, like, the whole squad:
genradix_init(radix)β initialize an empty genradix β¨genradix_free(radix)β frees all memory owned by the genradix and reinitializes it (two-for-one, we love a multitasker) πgenradix_ptr(radix, idx)β gets a pointer to the entry atidx, returningNULLif that entry does not exist πgenradix_ptr_alloc(radix, idx, gfp)β gets a pointer to an entry, allocating it if necessary π οΈgenradix_for_each(radix, iter, p)β iterate over each entry in a genradix π
Now the important deets, bestie, listen up π«Ά: the radix tree allocates one page of entries at a time, so entries may exist that were never explicitly allocated β and those get initialized to all zeroes. free zeroes, no drama, iconic.
Internally a genradix is just a radix tree of pages, and indexing works in terms of byte offsets. The wrappers in this header file use sizeof on the type the radix contains to calculate a byte offset from the index β see __idx_to_offset. that's the whole magic trick, iykyk π§
π₯ SEE ALSO π₯
Kernel file ./include/linux/generic-radix-tree.h, plus the whole friend group: genradix_init(9), genradix_free(9), genradix_ptr(9), genradix_ptr_alloc(9), genradix_iter_init(9), genradix_iter_peek(9), genradix_iter_peek_prev(9), genradix_for_each(9), genradix_for_each_reverse(9), genradix_prealloc(9) β
and that's the page, periodt π
mwah π«Ά this cutie came from ./include/linux, dated October 2026, and it goes by Generic rad...parse arrays(9) β yes the title is truncated like that, it's a whole aesthetic, don't question it ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms