writeback_iter(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– writeback_iter(9) πŸ’–

okay so this is a page from the Kernel API Manual and it's all about writeback_iter β€” the little function that hands you folios one at a time while you're doing writeback. bestie, it's literally the backbone of your ->writepages implementation and i need you to respect it. 🫢


✨ NAME ✨

writeback_iter β€” iterate folio of a mapping for writeback


🌸 SYNOPSIS 🌸

struct folio * writeback_iter (struct address_space *mapping , struct
       writeback_control *wbc , struct folio *folio , int *error );

πŸŽ€ ARGUMENTS πŸŽ€

  • mapping β€” the address space structure you wanna write, bestie. that's the whole target of the operation πŸ’…
  • wbc β€” the writeback context. it's giving "here's how we're doing this writeback" energy
  • folio β€” the folio you iterated before. pass NULL to start, and then keep feeding back what you got πŸ¦‹
  • error β€” an in-out pointer for writeback errors (peep the description below, it matters πŸ‘€)

πŸ’œ DESCRIPTION πŸ’œ

so this function returns the next folio for the writeback operation described by wbc on mapping, and you should be calling it in a while loop inside your ->writepages implementation. no cap. that's the whole deal.

to start the writeback operation, you pass NULL in the folio argument β€” that's your opening move. then, for every subsequent iteration, you pass the folio you got back last time right back in. yes, it's a little handoff ritual, and honestly? iconic. ✨

if there was an error in the per-folio writeback inside the writeback_iter loop, error should be set to that error value. don't be shy about it, tell the truth to the pointer. πŸ™ˆ

once the writeback described in wbc has finished, this function returns NULL β€” that's your "we're done here" moment β€” and if there was an error in any iteration, it restores it to error. so the error you stashed does not get lost, periodt.


πŸ”₯ NOTE πŸ”₯

callers should not manually break out of the loop using break or goto β€” no ma'am, absolutely not. you must keep calling writeback_iter until it returns NULL. it's a whole commitment, like finishing a series. πŸ’€

⭐ RETURN ⭐

the folio to write, or NULL if the loop is done. that's it, that's the answer. πŸ‘‘


🌈 SEE ALSO 🌈

kernel file ./mm/page-writeback.c and all its friends:


and that's the whole page, bestie!! πŸ’– this one comes to you straight from ./mm (the source, mwah) and it's dated October 2026 β€” so like, very on-trend. go forth and iterate your folios responsibly πŸ§šβ€β™€οΈπŸ’…

πŸ“¦ where this page comes from