kmap_local_folio(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ 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);
πŸ’€ unmapping addr1 before addr2 is 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:


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