memfd_pin_folios(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… memfd_pin_folios(9) β€” the kernel API manual glow-up πŸŽ€

okay so bestie, buckle up β€” this one's a Kernel API Manual entry for memfd_pin_folios(9) and it's literally about pinning folios that belong to a memfd. yes, pinning. like putting a little metaphorical pin in memory so it does not move. main character energy fr fr ✨


🌸 NAME 🌸

memfd_pin_folios β€” pin folios associated with a memfd 🫢


✨ SYNOPSIS ✨

long memfd_pin_folios (struct file *memfd , loff_t start , loff_t end ,
struct folio **folios , unsigned int max_folios , pgoff_t *offset );

πŸŽ€ ARGUMENTS πŸŽ€

  • memfd β€” the memfd whose folios we're gonna pin, iykyk πŸ’–
  • start β€” the first memfd offset ⭐
  • end β€” the last memfd offset, and yes bestie it's inclusive πŸ‘‘
  • folios β€” the array that receives pointers to the folios that got pinned πŸ“₯
  • max_folios β€” the maximum number of entries in folios (capacity check, periodt) πŸ’€
  • offset β€” the offset into the first folio 🌈

πŸ¦‹ DESCRIPTION πŸ¦‹

So the vibe is: we attempt to pin folios associated with a memfd in the contiguous range [start, end]. And because a memfd is either backed by shmem or hugetlb, the folios can either be found in the page cache or they need to be allocated if necessary β€” the kernel handles that, no cap πŸ™ˆ

Once the folios are located, they are all pinned via FOLL_PIN, and offset is populated with the offset into the first folio. (the original says "populatedwith" and honestly? relatable typo, but the meaning is populated-with, bestie πŸ’…)

And eventually β€” eventually β€” these pinned folios must be released, either using unpin_folios or unpin_folio. like please don't just leave them pinned forever, that's not the vibe 😭

it must be noted that the folios may be pinned for an indefinite amount of time. and in most cases, the duration of time they may stay pinned would be controlled by the userspace. this behavior is effectively the same as using FOLL_LONGTERM with other GUP APIs. long-term commitment fr fr 🫢

Returns the number of folios pinned β€” which could be less than max_folios, because it depends on the folio sizes that cover the range [start, end] (sizes do be varying). If no folios were pinned, it returns -errno. sad girl hours πŸ’€


🧚 SEE ALSO 🧚

all the sister entries, linked like a group chat πŸ’œ


and that's the whole page, bestie πŸ’– it lives in ./mm and it's dated October 2026 β€” pls cite it properly, mwah πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from