PT_MAKE_LEVELS(9)
π PT_MAKE_LEVELS(9) β a kernel API manual page, but make it cute
okay so bestie, this one's from the Kernel API Manual and it's genuinely kind of iconic once you get it. Let's go β¨
πΈ NAME πΈ
PT_MAKE_LEVELS β build an unwound walker. yes that's the whole name, she's efficient π
π SYNOPSIS π
PT_MAKE_LEVELS (fn , do_fn );
(no cap, that spacing is exactly how she ships, we do not touch it π)
π¦ ARGUMENTS π¦
fnβ the name of the walker function. that's her name, that's her whole identity π«Άdo_fnβ the function that gets called at each level. she's the one doing the actual work at every stop on the tour π
β¨ DESCRIPTION β¨
so what this does is build a function call tree that can be fully inlined. fully! like, completely absorbed into the caller, no call overhead, no vibes lost π
the caller has to provide a function body in an __always_inline function, and that body looks like this, exactly:
static __always_inline int do_fn(struct pt_range *range, void *arg,
unsigned int level, struct pt_table_p *table,
pt_level_fn_t descend_fn)
then the macro creates an inline function for each table level, and each one calls do_fn with a compile time constant for level plus a pointer to the next lower function. so it's a chain, each level handing off to the one below, all inlined, all gorgeous π
the result is an optimally inlined walk where every single one of those functions sees a constant level β which means the compiler can codegen the exact constants/etc for that level. like, she knows exactly which level she's on at compile time and she can optimize accordingly. main character energy, honestly β
β οΈ heads up though: note this can produce a lot of code! like, a LOT. codegen says slay but your binary size said π
πΊ SEE ALSO πΊ
kernel file ./drivers/iommu/generic_pt/pt_iter.h β and also her whole friend group, go say hi:
pt_check_range(9)pt_index_to_va(9)pt_entry_fully_covered(9)pt_range_to_index(9)pt_range_to_end_index(9)pt_next_entry(9)for_each_pt_level_entry(9)pt_load_single_entry(9)pt_top_range(9)pt_all_range(9)pt_upper_range(9)pt_make_range(9)pt_init(9)pt_init_top(9)pt_descend(9)pt_walk_range(9)pt_range_slice(9)pt_top_memsize_lg2(9)pt_compute_best_pgsize(9)
and that's the page, bestie π she lives in ./drivers/iommu/generic_pt, dated October 2026. go inline something. periodt. πβ¨
π¦ 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