shmem_read_folio_gfp(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– shmem_read_folio_gfp(9) β€” the kernel API manual, bestie edition πŸ’–

okay so real talk, this one's from the kernel API manual (section 9, iykyk) and it's literally about reading into the page cache with the page allocation flags you pick. main character energy for a helper function ngl πŸŽ€


✨ NAME ✨

shmem_read_folio_gfp β€” read into page cache, using specified page allocation flags.

πŸ¦‹ SYNOPSIS πŸ¦‹

struct folio * shmem_read_folio_gfp (struct address_space *mapping ,
pgoff_t index , gfp_t gfp );

🌸 ARGUMENTS 🌸

  • mapping β€” the folio's address_space. yes, that one. the space it lives in πŸ’…
  • index β€” the folio index. like, which folio we're talking about 🫢
  • gfp β€” the page allocator flags to use if allocating. your vibe for the allocation, basically ⭐

πŸ‘‘ DESCRIPTION πŸ‘‘

So here's the tea: this behaves as a tmpfs read_cache_page_gfp(mapping, index, gfp), with any new page allocations done using the specified allocation flags. slay.

But β€” and this is the plot twist 😭 β€” read_cache_page_gfp uses the ->read_folio method, which does not suit tmpfs, since it may have pages in swapcache, and needs to find those for itself. so it's out here doing its own thing, looking for its own pages. iconic but chaotic.

although, plot twist part two: drivers/gpu/drm i915 and ttm rely upon this support. so like, don't come for it πŸ”₯

And one more thing, and lowkey this bit matters: i915_gem_object_get_pages_gtt mixes __GFP_NORETRY | __GFP_NOWARN in with the mapping_gfp_mask, to avoid OOMing the machine unnecessarily. not the machine getting OOM'd for no reason πŸ’€ we love a thoughtful flag combo fr fr.

🧚 SEE ALSO 🧚

Kernel file ./mm/shmem.c β€” the whole friend group:


okay that's the whole page bestie, go read some folios πŸ’–βœ¨

mwah, this one's from ./mm, October 2026, and it's shmem_read_folio_gfp(9) β€” periodt πŸ’…

πŸ“¦ where this page comes from