kmap(9)
π kmap(9) β the Kernel API Manual, bestie edition π
okay so welcome to kmap(9), straight out of the Kernel API Manual, and no cap this is one of those little functions that has a bigger personality than it looks π
β¨ NAME β¨
kmap β map a page for long term usage πΊοΈβ¨
πΈ SYNOPSIS πΈ
void * kmap (struct page *page );
π ARGUMENTS π
pageβ pointer to the page that's getting mapped π«Ά
β RETURN β
it hands you back the virtual address of the mapping, periodt β¨
π¦ DESCRIPTION π¦
so here's the vibe check π β you can only invoke this from preemptible task context. why? because on 32bit systems with CONFIG_HIGHMEM enabled, this function might sleep π΄π. like, it will literally nap on you. so don't be that girl calling it from somewhere that can't handle a snooze.
for systems with CONFIG_HIGHMEM=n, and also for pages sitting in the low memory area, it just returns the virtual address of the direct kernel mapping π― easy, clean, slay.
the returned virtual address is globally visible and stays valid right up to the point where it gets unmapped via kunmap π. and yes bestie, the pointer can be handed off to other contexts β it's not a one-context-only situation, it's main character energy that travels π.
now the β οΈ moment: for highmem pages on 32bit systems this can be slow π¬ because the mapping space is limited and protected by a global lock π. and if there's no mapping slot available? the function blocks until a slot gets released via kunmap π§ it's giving "waiting in line at the club" energy fr fr.
π SEE ALSO π
kernel file ./include/linux/highmem.h π« and all these icons:
kunmap(9)kmap_to_page(9)kmap_flush_unused(9)kmap_local_page(9)kmap_local_folio(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)
π«Ά friendly reminder bestie: preemptible task context only. she might sleep. do not test her.
and that's the whole page, no notes π this icon of a manpage lives under ./include/linux, dated October 2026, and answers to the name kmap(9) β mwah, go map something responsibly π
π
π¦ 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