pcpu_setup_first_chunk(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… NAME πŸ’…

okay so pcpu_setup_first_chunk β€” bestie, it initializes the first percpu chunk and it's kind of a big deal πŸ‘‘

(this whole thing lives in the Kernel API Manual, iykyk 🫢)


✨ SYNOPSIS ✨

void pcpu_setup_first_chunk (const struct pcpu_alloc_info *ai , void
*base_addr );

πŸŽ€ ARGUMENTS πŸŽ€

  • ai β€” the pcpu_alloc_info that describes how the percpu area is shaped. it's literally the blueprint, no cap πŸ“
  • base_addr β€” the mapped address. that's where it lives πŸ’–

πŸ¦‹ DESCRIPTION πŸ¦‹

So like. This function initializes the first percpu chunk, which contains the kernel static percpu area. The way it works: you call it from the arch percpu area setup path. that's the vibe check ⭐

ai contains all the information necessary to initialize the first chunk and prime the dynamic percpu allocator. she's carrying everything, main character energy fr fr πŸ‘‘

ai->static_size is the size of the static percpu area. simple as that πŸ’…

ai->reserved_size, if it's non-zero, specifies the amount of bytes to reserve after the static area in the first chunk. This reserves the first chunk such that it's available only through reserved percpu allocation. This is primarily used to serve module percpu static areas on architectures where the addressing model has limited offset range for symbol relocations, to guarantee module percpu symbols fall inside the relocatable range. like, she's doing it for the safety of the symbols, iconic πŸŽ€

ai->dyn_size determines the number of bytes available for dynamic allocation in the first chunk. The area between ai->static_size + ai->reserved_size + ai->dyn_size and ai->unit_size is unused. give it a little alone time, she's not part of the party πŸ™ˆ

ai->unit_size specifies unit size and must be aligned to PAGE_SIZE and equal to or larger than ai->static_size + ai->reserved_size + ai->dyn_size. no wiggle room bestie, this is the rule 🫢

ai->atom_size is the allocation atom size and it's used as alignment for vm areas. little atom, big responsibility ✨

ai->alloc_size is the allocation size and it's always a multiple of ai->atom_size. This is larger than ai->atom_size if ai->unit_size is larger than ai->atom_size. math is mathing πŸ”₯

ai->nr_groups and ai->groups describe the virtual memory layout of percpu areas. Units which should be colocated are put into the same group. Dynamic VM areas will be allocated according to these groupings. And if ai->nr_groups is zero, a single group containing all units is assumed. default era πŸ¦‹

The caller should have mapped the first chunk at base_addr and copied static data to each unit. don't skip this step, it's giving prerequisites 😭

The first chunk will always contain a static and a dynamic region. However β€” and this is the part that lowkey trips people up β€” the static region is not managed by any chunk. If the first chunk also contains a reserved region, it is served by two chunks: one for the reserved region and one for the dynamic region. They share the same vm, but use offset regions in the area allocation map. The chunk serving the dynamic region is circulated in the chunk slots and available for dynamic allocation like any other chunk. periodt πŸ’…βœ¨


🌸 SEE ALSO 🌸

Kernel file ./mm/percpu.c β€” and honestly the whole percpu friend group showed up, so:


k that's the whole page bestie, go set up that first chunk πŸ’œ

sign-off szn πŸŽ€ this one ships from ./mm, October 2026, and it's filed under pcpu_setup_first_chunk(9) β€” slay, bye! πŸ’…βœ¨

πŸ“¦ where this page comes from