shmem_get_folio(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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, *foliop is NULL and 0 is returned β€” very "nothing to see here, moving on" πŸ’€
  • for SGP_NOALLOC, *foliop is NULL and -ENOENT is 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 🌸


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 πŸ’…πŸ’–πŸŽ€πŸ¦‹πŸŒΈ

shmem_get_folio(9)

πŸ“¦ where this page comes from