pcpu_embed_first_chunk(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– pcpu_embed_first_chunk β€” Kernel API Manual ✨

okay so bestie, welcome to the pcpu_embed_first_chunk(9) page from the Kernel API Manual πŸ’… this one's all about embedding the first percpu chunk into bootmem, and honestly? it's giving allocation realness πŸŽ€


🌸 NAME 🌸

pcpu_embed_first_chunk β€” embed the first percpu chunk into bootmem 🧚


✨ SYNOPSIS ✨

int pcpu_embed_first_chunk (size_t reserved_size , size_t dyn_size ,
size_t atom_size , pcpu_fc_cpu_distance_fn_t cpu_distance_fn ,
pcpu_fc_cpu_to_node_fn_t cpu_to_nd_fn );

like, that's the whole signature, no cap πŸ’œ


πŸ¦‹ ARGUMENTS πŸ¦‹

  • reserved_size β€” the size of the reserved percpu area, in bytes πŸ“
  • dyn_size β€” the minimum free size for dynamic allocation, in bytes πŸ“
  • atom_size β€” the allocation atom size ⭐
  • cpu_distance_fn β€” a callback to determine the distance between cpus; it's optional, so no pressure 🫢
  • cpu_to_nd_fn β€” a callback to convert a cpu to its node; also optional πŸ™ˆ

πŸ’€ DESCRIPTION πŸ’€

so this function is a little helper whose whole job is to make setting up the embedded first percpu chunk easier, and you can call it anywhere pcpu_setup_first_chunk is expected πŸ‘‘

if this function is what you use to set up the first chunk, then that chunk gets allocated by calling pcpu_fc_alloc and it's used as-is, like literally without being mapped into the vmalloc area 😭

allocations are always whole multiples of atom_size, aligned to atom_size β€” that's the vibe check it always passes ✨

this is what lets the first chunk piggy back on the linear physical mapping, which often uses a larger page size πŸ”₯

⚠️ but bestie, please note: this can result in a very sparse cpu->unit mapping on NUMA machines, which then requires a large vmalloc address space. so don't use this allocator if vmalloc space is not orders of magnitude larger than the distances between node memory addresses (ie. 32bit NUMA machines). like, that's the warning, take it seriously πŸ’…

dyn_size specifies the minimum dynamic area size 🌈

and if the needed size is smaller than the minimum or the specified unit size, the leftover is returned using pcpu_fc_free πŸŽ€


⭐ RETURN ⭐

0 on success, -errno on failure 😀 that's it, that's the whole return section, and yes it ate πŸ’–


πŸ’œ SEE ALSO πŸ’œ

the kernel file ./mm/percpu.c, plus this whole friend group of functions (iykyk) πŸ¦‹:


and that's the whole page, bestie 🫢 this one lives in ./mm and it's dated October 2026 β€” mwah, go forth and embed your chunks πŸ’‹πŸ‘‘

πŸ“¦ where this page comes from