Re: [PATCH v2 RESEND] ext4: cancel dirty accounting for folios without buffers

From: Muchun Song

Date: Thu Dec 03 2026 - 04:12:44 EST




> On Dec 3, 2026, at 17:00, Jia Zhu <zhujia.zj@xxxxxxxxxxxxx> wrote:
>
> Since commit cc5095747edf ("ext4: don't BUG if someone dirty pages
> without asking ext4 first"), mpage_prepare_extent_to_map() handles dirty
> folios without buffer heads by warning, clearing PG_dirty, and skipping
> them. ext4 cannot write these folios because there are no buffer heads to
> map and submit.
>
> That recovery leaves dirty accounting behind: folio_clear_dirty() clears
> PG_dirty but does not undo the accounting charged when the folio was
> dirtied. We have seen this in production as Dirty/nr_dirty staying high
> while Writeback/nr_writeback and device write IO stayed near zero, with
> many writer tasks blocked in balance_dirty_pages() throttling. Thus the
> warning-and-skip recovery can still become a dirty-throttle DoS.
>
> Use folio_cancel_dirty() so dropping PG_dirty also cancels the dirty
> accounting. Then cycle the folio through writeback state so the generic
> writeback helpers update the xarray DIRTY/TOWRITE tags.
>
> Fixes: cc5095747edf ("ext4: don't BUG if someone dirty pages without asking ext4 first")
> Cc: stable@xxxxxxxxxxxxxxx
> Suggested-by: Zhang Yi <yizhang089@xxxxxxxxx>
> Reviewed-by: Jan Kara <jack@xxxxxxx>
> Reviewed-by: Zhang Yi <yi.zhang@xxxxxxxxxx>
> Signed-off-by: Jia Zhu <zhujia.zj@xxxxxxxxxxxxx>

Acked-by: Muchun Song (ByteDance) <muchun.song@xxxxxxxxx>

Thanks.