filemap_grab_folio(9)
π filemap_grab_folio(9) β from the Kernel API Manual, bestie π
okay so picture this: you're deep in the kernel, you need a folio, and this little icon is literally the page-cache vending machine. grab a snack, get a folio. no cap.
β¨ NAME β¨
filemap_grab_folio β grab a folio from the page cache π«Ά
πΈ SYNOPSIS πΈ
struct folio * filemap_grab_folio (struct address_space *mapping ,
pgoff_t index );
π¦ ARGUMENTS π¦
mappingβ the address space to search π like, the whole neighbourhood you're looking inindexβ the page index π the exact house number
π DESCRIPTION π
So the way this works: it looks up the page cache entry at mapping & index. Cute, right?
if no folio is found, a new folio is created. yes, it manifests one. main character energy fr fr β¨
the folio is locked, marked as accessed, and returned. so it comes back to you locked and already flagged as "yeah someone touched this" β all in one trip π
π RETURN π
a found or created folio π
but if it's giving nothing β like, no folio was found and creating one failed β you get ERR_PTR(-ENOMEM) π so always check, bestie, don't just vibe with the pointer.
π SEE ALSO π
the kernel file ./include/linux/pagemap.h and honestly, the whole extended friend group:
filemap_set_wb_err(9)filemap_check_wb_err(9)filemap_sample_wb_err(9)file_sample_sb_err(9)mapping_set_error(9)mapping_set_large_folios(9)mapping_align_index(9)mapping_pmd_folio_support(9)folio_flush_mapping(9)folio_inode(9)folio_attach_private(9)folio_change_private(9)folio_detach_private(9)fgf_t(9)fgf_set_order(9)write_begin_get_folio(9)filemap_get_folio(9)filemap_lock_folio(9)find_get_page(9)find_lock_page(9)find_or_create_page(9)grab_cache_page_nowait(9)folio_next_index(9)folio_next_pos(9)folio_file_page(9)folio_contains(9)page_pgoff(9)folio_pos(9)linear_page_delta(9)linear_page_index(9)linear_anon_page_index(9)folio_trylock(9)folio_lock(9)lock_page(9)folio_lock_killable(9)filemap_range_needs_writeback(9)struct readahead_control(9)page_cache_sync_readahead(9)page_cache_async_readahead(9)readahead_folio(9)readahead_pos(9)readahead_length(9)readahead_index(9)readahead_count(9)readahead_batch_length(9)folio_mkwrite_check_truncate(9)i_blocks_per_folio(9)
π small heads up: the folio you get back is locked β so bestie, you own the unlock. don't ghost it. π
and that's the whole page, mwah π β this one lives in ./include/linux and it's dated October 2026, so mark your calendar π
β¨ slay, go read some folios π¦π
π¦ 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