folio_maybe_mapped_shared(9)
π
folio_maybe_mapped_shared β the folio_maybe_mapped_shared(9) page, bestie edition
okay so real talk, this is a page straight out of the Kernel API Manual, and it's about one tiny function that answers one huge question: is this folio out here living its shared life, or is it in a committed exclusive relationship with one MM? π«Ά Let's get into it.
β¨ NAME β¨
folio_maybe_mapped_shared β literally the whole vibe check of whether the folio is mapped into the page tables of more than one MM. π
πΈ SYNOPSIS πΈ
bool folio_maybe_mapped_shared (struct folio *folio );
π ARGUMENTS π
folioβ the folio in question. the main character, if you will. π
π¦ DESCRIPTION π¦
so this function checks if the folio maybe is currently mapped into more than one MM (we call that "maybe mapped shared"), or if the folio is certainly mapped into a single MM (that one's "mapped exclusively"). cute, right? it's giving "i'm not sure but i'm pretty sure." π
for KSM folios, this function also returns "mapped shared" when a folio is mapped multiple times into the same MM β because the individual page mappings are independent. like, they're not doing it together, they're each doing their own thing. π
for small anonymous folios and anonymous hugetlb folios, the return value will be exactly correct: non-KSM folios can only be mapped at most once into an MM, and they cannot be partially mapped. KSM folios are considered shared even if mapped multiple times into the same MM. periodt. β¨
for other folios, the result can be fuzzy, and by fuzzy i mean:
- For partially-mappable large folios (THP), the return value can wrongly indicate "mapped shared" (a false positive) if a folio was mapped by more than two MMs at one point in time.
- For pagecache folios (including hugetlb), the return value can wrongly indicate "mapped shared" (a false positive) when two VMAs in the same MM cover the same file range.
further, this function only considers current page table mappings that are tracked using the folio mapcount(s). iykyk. π
and it does not consider these, bestie: 1. If the folio might get mapped in the (near) future (e.g.,swapcache,pagecache, temporary unmapping for migration). 2. If the folio is mapped differently (VM_PFNMAP). 3. If hugetlb page table sharing applies. Callers might want to checkhugetlb_pmd_shared.
β RETURN β
whether the folio is estimated to be mapped into more than one MM. that's it, that's the tea. π
π SEE ALSO π
the whole group chat, no cap β from the kernel file ./include/linux/mm.h:
folio_page_idx(9)vma_flag_t(9)fault_flag_allow_retry_first(9)vma_kernel_pagesize(9)folio_order(9)folio_reset_order(9)folio_mapcount(9)folio_mapped(9)thp_order(9)thp_size(9)folio_get(9)folio_put(9)folio_put_refs(9)folios_put(9)vma_flags_is_cow_mapping(9)vma_is_cow_mapping(9)vma_desc_is_cow_mapping(9)folio_pfn(9)folio_mk_pte(9)folio_mk_pmd(9)folio_mk_pud(9)folio_maybe_dma_pinned(9)is_zero_page(9)is_zero_folio(9)folio_nr_pages(9)folio_next(9)folio_shift(9)folio_size(9)folio_expected_ref_count(9)zap_vma(9)ptdesc_address(9)ptdesc_set_kernel(9)ptdesc_clear_kernel(9)ptdesc_test_kernel(9)pagetable_alloc(9)pagetable_free(9)vma_lookup(9)vma_start_pgoff(9)vma_end_pgoff(9)vma_last_pgoff(9)vma_start_anon_pgoff(9)vma_end_anon_pgoff(9)vma_last_anon_pgoff(9)mmap_action_remap(9)mmap_action_remap_full(9)mmap_action_ioremap(9)mmap_action_ioremap_full(9)mmap_action_simple_ioremap(9)mmap_action_map_kernel_pages(9)mmap_action_map_kernel_pages_full(9)range_is_subset(9)range_in_vma(9)range_in_vma_desc(9)clear_pages(9)
and that's the whole page, bestie π this one came from the kernel tree at ./include/linux, dated October 2026 β go forth and map responsibly, mwah π
π¦ 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