try_to_free_buffers(9)
π 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:
bio_endio_bh(9)end_buffer_read_sync(9)bh_end_read(9)bh_end_write(9)bh_end_async_write(9)mmb_sync(9)block_dirty_folio(9)mark_buffer_dirty(9)__brelse(9)__bforget(9)bh_submit(9)bdev_getblk(9)__bread_gfp(9)block_invalidate_folio(9)clean_bdev_aliases(9)bh_uptodate_or_lock(9)__bh_read(9)__bh_read_batch(9)
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
- 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