Add a no_stats_accounting bitfield to wbc that callers can set. Hook this up to __folio_clear_dirty_for_io() when preparing writeback. This is so that for filesystems that implement granular dirty writeback for its large folios, the stats reflect only the dirty pages that are written back instead of all the pages in the folio, which helps enforce more accurate / less conservative dirty page balancing. Signed-off-by: Joanne Koong --- include/linux/writeback.h | 7 +++++++ mm/page-writeback.c | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 0df11d00cce2..f63a52b56dff 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -71,6 +71,13 @@ struct writeback_control { */ unsigned no_cgroup_owner:1; + /* + * Do not do any stats accounting. The caller will do this themselves. + * This is useful for filesystems that implement granular dirty + * writeback for its large folios. + */ + unsigned no_stats_accounting:1; + /* internal fields used by the ->writepages implementation: */ struct folio_batch fbatch; pgoff_t index; diff --git a/mm/page-writeback.c b/mm/page-writeback.c index fe39137f01d6..294339887e55 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2402,6 +2402,7 @@ void tag_pages_for_writeback(struct address_space *mapping, } EXPORT_SYMBOL(tag_pages_for_writeback); +static bool __folio_clear_dirty_for_io(struct folio *folio, bool update_stats); static bool folio_prepare_writeback(struct address_space *mapping, struct writeback_control *wbc, struct folio *folio) { @@ -2428,7 +2429,7 @@ static bool folio_prepare_writeback(struct address_space *mapping, } BUG_ON(folio_test_writeback(folio)); - if (!folio_clear_dirty_for_io(folio)) + if (!__folio_clear_dirty_for_io(folio, !wbc->no_stats_accounting)) return false; return true; -- 2.47.3