folio_ref_count(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… folio_ref_count(9)

ok so real talk, this page is from the Kernel API Manual and it's all about folio_ref_count, and honestly bestie, it's giving "small function, big lore" energy. let's get into it ✨


🌸 NAME

folio_ref_count β€” the reference count on this folio. that's it, that's the whole vibe check πŸ’–


πŸŽ€ SYNOPSIS

int folio_ref_count (const struct folio *folio );

πŸ¦‹ ARGUMENTS

  • folio β€” the folio. yes, that's the entire description. she's lowkey mysterious like that πŸ™ˆ

πŸ‘‘ DESCRIPTION

so!! folios contain a reference count. periodt. and when that reference count hits zero, the folio becomes what we call frozen 🧊 β€” at that point it'll usually get returned to the memory allocator, BUT some parts of the kernel deliberately freeze folios so they can do unusual little operations on them, like splitting or migration. main character behaviour, honestly.

the refcount is usually incremented by calls to folio_get and decremented by calls to folio_put. and who are the typical users of the folio refcount? bestie, i'm so glad you asked πŸ’…

  • each reference from a page table
  • the page cache
  • filesystem private data
  • the LRU list
  • pipes
  • direct IO which references this page in the process address space

now here's the tea β˜• β€” the reference count has three components: expected, temporary, and spurious:

  • the expected reference count of a folio is the count we'd logically expect it to be from just reading the code.
  • temporary refcounts are gained by threads that need a temporary reference so they can make sure the folio isn't reallocated while they're using it.
  • spurious refcounts are gained by threads which β€” thanks to RCU walks of the page tables or file cache β€” find a stale pointer to a folio. these threads will drop the refcount after discovering the pointer is stale, but ngl it can surprise other users to see the spurious refcount sitting on a freshly allocated folio (like, they may see a refcount of 2 instead of 1 😭). not me accidentally looking popular, iβ€” πŸ’€

⭐ RETURN

the number of references to this folio. slay, that's the whole return value 🫢


🌈 SEE ALSO


and that's the page!! brought to you by ./include/linux, dated October 2026 β€” mwah, go read your refcounts responsibly bestie πŸ“πŸ’œβœ¨

πŸ“¦ where this page comes from