shmem_read_folio_gfp(9)
π 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'saddress_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:
shmem_recalc_inode(9)shmem_writeout(9)shmem_get_folio(9)shmem_kernel_file_setup(9)shmem_file_setup(9)shmem_file_setup_with_mnt(9)shmem_zero_setup(9)shmem_zero_setup_desc(9)
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
- 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