shmem_get_folio(9)
π shmem_get_folio(9) β Kernel API Manual, but make it make sense π
okay bestie, gather round, because today we're learning about shmem_get_folio β the little kernel function that goes "hey, do we already have this folio? and can I lock it real quick?" π it lives in the Kernel API Manual and honestly? she's kind of a big deal in ./mm. let's get into it β¨
β¨ NAME β¨
shmem_get_folio β find, and lock a shmem folio. that's it. that's the whole job description. π
πΈ SYNOPSIS πΈ
int shmem_get_folio (struct inode *inode , pgoff_t index , loff_t
write_end , struct folio **foliop , enum sgp_type sgp );
like, five whole arguments, she's got range π
π¦ ARGUMENTS π¦
inodeβ the inode to search. this is the thing we're digging around in, iykyk πindexβ the page index. which page we're looking for, fr fr πwrite_endβ end of a write, could extend inode size. so like, if you're writing past the end, this is where the tea gets spicy πΆοΈfoliopβ pointer to the folio if found. she's a pointer-to-a-pointer situation, very main character energy πsgpβSGP_*flags to control behavior. these are the vibe check knobs, remember them π
π₯ DESCRIPTION π₯
okay so the whole bit: it looks up the page cache entry at inode & index. if a folio is already present, it gets returned locked with an increased refcount. no cap, that's the deal π
now listen, this part is important π«Ά if the caller modifies data in the folio, it must call folio_mark_dirty before unlocking the folio β that's how we make sure the folio doesn't get reclaimed out from under us π and the good news? there's no need to reserve space before calling folio_mark_dirty. so you can just go for it, periodt β¨
when no folio is found, the behavior depends on sgp, and it splits three ways:
- for
SGP_READ,*foliopisNULLand0is returned β very "nothing to see here, moving on" π - for
SGP_NOALLOC,*foliopisNULLand-ENOENTis returned β she said no and she meant it π« - for all other flags a new folio is allocated, inserted into the page cache and returned locked in
foliopβ brand new folio just dropped, slay π
π CONTEXT π
may sleep. π΄ that's genuinely the whole section. she may sleep. let her rest, bestie. π§
β RETURN β
0 if successful, else a negative error code. simple, iconic, no notes π
π SEE ALSO π
kernel file ./mm/shmem.c and the whole shmem girlie squad β go read these next, bestie, they're all connected πΈ
shmem_recalc_inode(9)shmem_writeout(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)shmem_read_folio_gfp(9)
okay and one last reminder because I love you: mark that folio dirty before you unlock it, or the folio could get reclaimed and you'll be sad ππ
and that's the whole page!! sourced from ./mm, dated October 2026, and yes it lives in the Kernel API Manual β mwah, kisses, go forth and lock your folios responsibly π
πππ¦πΈ
π¦ 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