kmap_local_folio(9)
β¨ kmap_local_folio(9) β¨
okay bestie, so this one's from the Kernel API Manual and it's literally called kmap_local_folio β and yes, it's all lowercase with the (9) because that's just how kernel man pages roll π
πΈ NAME πΈ
kmap_local_folio β map a page in this folio for temporary usage π
π¦ SYNOPSIS π¦
void * kmap_local_folio (const struct folio *folio , size_t offset );
π ARGUMENTS π
folioβ the folio that's holding the page you want, iykyk π«Άoffsetβ the byte offset within the folio that pins down which page we're talking about β
π DESCRIPTION π
okay so here's the tea β β this needs careful handling when you're nesting multiple mappings, because the map management is stack based. that means the unmap has to happen in the reverse order of the map operation. no cap, order matters:
addr1 = kmap_local_folio(folio1, offset1);
addr2 = kmap_local_folio(folio2, offset2);
...
kunmap_local(addr2);
kunmap_local(addr1);
π unmappingaddr1beforeaddr2is invalid and causes malfunction. literally do not do it. the vibes will be rancid and your kernel will suffer.
and here's the thing that makes it different from the kmap mappings β this mapping is only valid in the context of the caller and cannot be handed off to other contexts. it's giving main character energy that refuses to be shared, honestly π
on CONFIG_HIGHMEM=n kernels and for low memory pages, it just returns the virtual address of the direct mapping. only real highmem pages actually get temporarily mapped. lowkey efficient π¦
while it is significantly faster than kmap for the highmem case, it comes with restrictions about the pointer validity β so enjoy the speed, but respect the rules β¨
on HIGHMEM enabled systems, mapping a highmem page has the side effect of disabling migration, all in order to keep the virtual address stable across preemption. but bestie, listen β no caller of kmap_local_folio can rely on this side effect. it's a side quest, not a feature π
π CONTEXT π
can be invoked from any context. queen behavior, honestly π
β RETURN β
the virtual address of offset. that's it, that's the whole answer π
π§ SEE ALSO π§
kernel file ./include/linux/highmem.h, plus this whole friend group of functions:
kmap(9),kunmap(9),kmap_to_page(9),kmap_flush_unused(9),kmap_local_page(9),kmap_atomic(9),clear_user_page(9),clear_user_pages(9),clear_user_highpage(9),clear_user_highpages(9),vma_alloc_zeroed_movable_folio(9),memcpy_from_folio(9),memcpy_to_folio(9),folio_zero_tail(9),folio_fill_tail(9),memcpy_from_file_folio(9),folio_zero_segments(9),folio_zero_segment(9),folio_zero_range(9),folio_release_kmap(9)
and that's the whole page, bestie π«Ά this one lives in ./include/linux, dated October 2026 β go off, kernel docs, we love to see 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