pcpu_embed_first_chunk(9)
π 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) π¦:
pcpu_addr_in_chunk(9)pcpu_check_block_hint(9)pcpu_next_md_free_region(9)pcpu_next_fit_region(9)pcpu_mem_zalloc(9)pcpu_mem_free(9)pcpu_chunk_relocate(9)pcpu_block_update(9)pcpu_chunk_refresh_hint(9)pcpu_block_refresh_hint(9)pcpu_block_update_hint_alloc(9)pcpu_block_update_hint_free(9)pcpu_is_populated(9)pcpu_find_block_fit(9)pcpu_alloc_area(9)pcpu_free_area(9)pcpu_alloc_first_chunk(9)pcpu_chunk_populated(9)pcpu_chunk_depopulated(9)pcpu_chunk_addr_search(9)pcpu_alloc(9)pcpu_balance_free(9)pcpu_balance_populated(9)pcpu_reclaim_populated(9)pcpu_balance_workfn(9)free_percpu(9)is_kernel_percpu_address(9)per_cpu_ptr_to_phys(9)pcpu_alloc_alloc_info(9)pcpu_free_alloc_info(9)pcpu_dump_alloc_info(9)pcpu_setup_first_chunk(9)pcpu_build_alloc_info(9)pcpu_page_first_chunk(9)
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
- 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