filemap_fault(9)
π NAME π
filemap_fault β bestie, this is the one that reads in your file data when a page fault comes knocking β¨
(also hi, you're in the Kernel API Manual, section 9, and this whole page is literally about filemap_fault π«Ά)
πΈ SYNOPSIS πΈ
vm_fault_t filemap_fault (struct vm_fault *vmf );
π ARGUMENTS π
vmfβ astruct vm_faultthat's carrying all the deets of the fault π like, every little detail of what went down, packed into one struct
β¨ DESCRIPTION β¨
Okay so picture this: filemap_fault gets invoked via the vma operations vector for a mapped memory region, and its whole job is to read in file data during a page fault. That's it, that's the gig π
And ngl, the goto's are kind of ugly π but they streamline the normal case of having it in the page cache, and handle the special cases reasonably without having a lot of duplicated code. So likeβ¦ yeah. Iconic tradeoff, fr fr.
β οΈ IMPORTANT LORE β οΈ vma->vm_mm->mmap_lock must be held on entry. No exceptions, bestie. Hold the lock π
Now for the return-value tea β because this is the part where you really gotta pay attention:
- If our return value has
VM_FAULT_RETRYset, it's because themmap_lockmay be dropped before doing I/O or bylock_folio_maybe_drop_mmap. - If our return value does not have
VM_FAULT_RETRYset, themmap_lockhas not been released. - We never return with
VM_FAULT_RETRYand a bit fromVM_FAULT_ERRORset. Never ever. That combo is not a thing π«
π RETURN π
A bitwise-OR of VM_FAULT_ codes π (yes, the whole bouquet of them, OR'd together, slay)
π SEE ALSO π
The kernel file in question: ./mm/filemap.c π¦
And here's the whole friend group, no cap β every single one of them π«Ά
filemap_remove_folio(9)filemap_fdatawrite_range(9)filemap_flush_range(9)filemap_flush(9)filemap_range_has_page(9)filemap_fdatawait_range(9)filemap_fdatawait_range_keep_errors(9)file_fdatawait_range(9)filemap_fdatawait_keep_errors(9)filemap_write_and_wait_range(9)file_check_and_advance_wb_err(9)file_write_and_wait_range(9)replace_page_cache_folio(9)softleaf_entry_wait_on_locked(9)folio_put_wait_locked(9)folio_unlock(9)folio_end_read(9)folio_end_private_2(9)folio_wait_private_2(9)folio_wait_private_2_killable(9)folio_end_writeback_no_dropbehind(9)folio_end_writeback(9)__folio_lock(9)page_cache_next_miss(9)page_cache_prev_miss(9)__filemap_get_folio_mpol(9)find_get_entries(9)find_lock_entries(9)filemap_get_folios(9)filemap_get_folios_contig(9)filemap_get_folios_tag(9)filemap_get_folios_dirty(9)filemap_read(9)generic_file_read_iter(9)filemap_splice_read(9)mapping_seek_hole_data(9)read_cache_folio(9)mapping_read_folio_gfp(9)read_cache_page_gfp(9)__generic_file_write_iter(9)generic_file_write_iter(9)filemap_release_folio(9)filemap_invalidate_inode(9)filemap_cachestat(9)
βΏ k bye ily, go read your file data βΏ
This little page came from the ./mm source and it's dated October 2026 ποΈπ mwah, catch you on the next fault π§ββοΈ
π¦ 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