block_dirty_folio(9)
π block_dirty_folio(9) β like, the Kernel API Manual, but make it make sense β¨
okay bestie, so you've wandered into the kernel API manual (yes, that one) and you clicked on block_dirty_folio β good choice, this one's actually kind of a baddie. let's get into it π«Ά
β¨ NAME β¨
block_dirty_folio β mark a folio as dirty. that's it. that's the whole vibe. π
πΈ SYNOPSIS πΈ
bool block_dirty_folio (struct address_space *mapping , struct folio
*folio );
π ARGUMENTS π
mappingβ the address space that's holding this folio, iykyk π«folioβ the actual folio we're marking dirty. sorry bestie, it's getting dirty, no cap π
π₯ DESCRIPTION π₯
okay so listen β if your filesystem uses buffer_heads, you can literally just use this function as your ->dirty_folio implementation. iconic. π
some filesystems need to do a little bit of work before calling this function, and that's valid, we respect the hustle. but if your filesystem does not use buffer_heads? bestie, wrong function β you want filemap_dirty_folio instead. periodt. π
now here's where it gets cute. if the folio has buffers, the uptodate buffers get set dirty, and the whole reason is to preserve dirty-state coherency between the folio and the buffers. the way that consistency mattersβ¦ π¦
buffers added to a dirty folio are created dirty. born dirty. main character energy from day one, honestly. β
and the order matters, okay? the buffers are dirtied before the folio is dirtied. there's a small race window in which writeback may see the folio cleanness but not the buffer dirtiness. and that's fine! π but if this code were to set the folio dirty before the buffers, writeback could clear the folio dirty flag, see a bunch of clean buffers, and we'd end up with dirty buffers/clean folio on the dirty folio list. and that's giving disaster. π so we don't do that.
we use i_private_lock to lock against try_to_free_buffers while using the folio's buffer list. this also prevents clean buffers being added to the folio after it was set dirty. locked down, protected, safe. π§
π CONTEXT π
may only be called from process context. does not sleep. π΄π«
and the caller has to make sure that folio cannot be truncated during this call β typically by holding the folio lock or having a page in the folio mapped and holding the page table lock. no truncation, no surprises, we don't do that here. π
β RETURN β
True if the folio was dirtied; false if it was already dirtied. slay either way tbh. π
πΈ SEE ALSO πΈ
Kernel file ./fs/buffer.c β go read it, it's giving lore π
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)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)try_to_free_buffers(9)bh_uptodate_or_lock(9)__bh_read(9)__bh_read_batch(9)
and that's the whole page, bestie!! π«Ά this one came from the ./fs corner of the kernel world, dated October 2026 β block_dirty_folio(9), you ate. π
β¨
π¦ 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