filemap_lock_folio(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– filemap_lock_folio(9) πŸ’–

okay bestie, welcome to the Kernel API Manual, this is filemap_lock_folio(9) and it's literally the "hey can u find that folio and also lock it" girlie. short page, big main-character energy. let's go πŸ’…


✨ NAME ✨

filemap_lock_folio β€” find a folio and lock it. that's it, that's the whole job 🫢


🌸 SYNOPSIS 🌸

struct folio * filemap_lock_folio (struct address_space *mapping ,
pgoff_t index );

like, yes, the line break in the middle of the params is a little feral but we respect it 😭 copy it exactly, no cap.


πŸŽ€ ARGUMENTS πŸŽ€

  • mapping β€” the address_space we're searching. this is the place we're digging in, okurrr πŸ”
  • index β€” the page index. like which page we want, number-wise ✨

πŸ¦‹ DESCRIPTION πŸ¦‹

so it looks up the page cache entry at mapping & index (yes, that & is doing the matching, that's how it's written, don't come for me).

if a folio is actually present? it gets returned locked with an increased refcount. so you're walking away with a folio that's all yours and also holding a lock, so please, for the love of everything, put it back when you're done 🫢


πŸ’œ CONTEXT πŸ’œ

May sleep. πŸ’€

read that again, bestie. may. sleep. don't be out here calling this in atomic context, i'm begging πŸ™ˆ


⭐ RETURN ⭐

you get either:

  • a folio, or
  • ERR_PTR(-ENOENT) if there's genuinely no folio in the cache for this index 😭

and a very important heads up: it will not return a shadow, swap or DAX entry. not those. never those. don't ask πŸ’€


πŸ”₯ SEE ALSO πŸ”₯

okay this list is long, but it's giving thorough, and honestly? iconic. the kernel file lives at ./include/linux/pagemap.h, and here's the whole squad:

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_grab_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)

like i said. the whole squad. go read them. iykyk πŸ“šπŸ’…


and that's the page, babes πŸŽ€ this one came out of ./include/linux, dated October 2026, and it's filed under filemap_lock_folio(9) β€” go lock a folio responsibly, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from