page_cache_next_miss(9)
π page_cache_next_miss(9) π
okay so this is from the Kernel API Manual and bestie, it's literally the "find me a hole" function. no cap, the whole personality is gap hunting π΅οΈββοΈβ¨
πΈ NAME πΈ
page_cache_next_miss β Find the next gap in the page cache. that's it, that's the whole job π
π¦ SYNOPSIS π¦
pgoff_t page_cache_next_miss (struct address_space *mapping , pgoff_t
index , unsigned long max_scan );
three args, one return, zero drama (well, mostly) π
β¨ ARGUMENTS β¨
mappingβ the Mapping. yes that's the actual description. it's giving "trust me bro" but ok πindexβ the Index. where you're starting your little scavenger hunt πmax_scanβ Maximum range to search. i.e. how far you're willing to look before you give up and go home πββοΈπ¨
π DESCRIPTION π
So what it does: it searches the range [index, min(index + max_scan - 1, ULONG_MAX)] looking for the gap with the lowest index. lowkey obsessed with that formula tbh, max_scan - 1 is doing so much work there π§
Now the important caveat, listen up because this is the main character plot twist π
This function may be called under the rcu_read_lock. However, that does not mean you get an atomic search of a snapshot of the cache at a single point in time. so like... it's not a frozen-in-amber moment, it's more of a "vibes at the time of asking" situation π
Example time, because examples ate: if a gap is created at index 5, and then subsequently a gap is created at index 10, a page_cache_next_miss covering both indices may return 10 if it's called under the rcu_read_lock. yeah. it might skip past the 5. she's fast, she's not psychic π
π₯ RETURN π₯
- The index of the gap if found β
- otherwise an index outside the range you specified β in which case
'return - index >= max_scan'will be true. so you can actually check that, iconic behavior honestly π - and in the rare case of index wrap-around,
0will be returned. rare but she happens πͺοΈ
π SEE ALSO π
Kernel file ./mm/filemap.c, plus the entire extended friend group right here β no gatekeeping, we're tagging everyone π«Ά
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_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)filemap_fault(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)
fr fr read the range formula twice before you file that bug report, bestie π
kay bye, this page came from ./mm and it's dated October 2026 β go find some gaps, slay π§ββοΈπβ
π¦ 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