try_to_free_buffers(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… try_to_free_buffers β€” a Kernel API Manual moment ✨

okay so bestie, welcome to the try_to_free_buffers(9) page, aka the kernel API manual entry you didn't know you needed but now literally cannot live without 🫢


🌸 NAME 🌸

try_to_free_buffers β€” release buffers attached to this folio. that's it. that's the whole vibe. πŸŽ€


✨ SYNOPSIS ✨

bool try_to_free_buffers (struct folio *folio );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • folio β€” the folio. yes, that's genuinely all it says. it's giving "I have one job and I'm doing it." πŸ‘‘

πŸ’– DESCRIPTION πŸ’–

so here's the tea β˜• β€” if any buffers are in use (dirty, under writeback, elevated refcount), no buffers will be freed. like, none. zero. the whole thing just nopes out πŸ™ˆ

and here's where it gets a little spicy 🌢️ β€” if the folio is dirty but all the buffers are clean, then we need to be sure to mark the folio clean as well. why?? because the folio may be against a block device, and a later reattachment of buffers to a dirty folio will set all buffers dirty. which would corrupt filesystem data on the same device. 😭 so yeah, that's a real "do not skip this step" situation, no cap.

the same applies to regular filesystem folios: if all the buffers are clean then we set the folio clean and proceed. slay. πŸ’… but to do that, we require total exclusion from block_dirty_folio. that is obtained with i_private_lock. total exclusion, bestie β€” we're not doing "mostly excluded," we're doing the whole thing πŸ”₯

and if you want exclusion against try_to_free_buffers, you can get it by either locking the folio or by holding its mapping's i_private_lock. pick your fighter, both are valid 🧚


🌈 CONTEXT 🌈

process context. folio must be locked. will not sleep. 😴🚫


⭐ RETURN ⭐

true if all buffers attached to this folio were freed. otherwise, well… not true, bestie πŸ’€


πŸ‘‘ SEE ALSO πŸ‘‘

kernel file ./fs/buffer.c, plus the whole friend group:


and that's the page, babes πŸ“ this little icon lives in ./fs and it's stamped October 2026 β€” so go forth, free those buffers, and remember: lock the folio first πŸ’œβœ¨

πŸ“¦ where this page comes from