From 9655215689729527c501184f5dd1ae8e1e100f99 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sat, 8 Mar 2003 03:22:49 -0800 Subject: [PATCH] [PATCH] fix possible latency in balance_dirty_pages() Tasks which throttle in balance_dirty_pages() will loop until the amount of dirty memory falls below the configured dirty_ratio. This exposes the possibility that one task could be stuck in there for arbitrary periods of time due to page dirtying activity by other tasks. The patch changes the logic so that tasks will break out of the loop if they have written enough pages, regardless of the current dirty memory limits. Here "enough" pages is 1.5x the number of pages which they just dirtied. If the amount of dirty memory in the machine happens to still exceed dirty_ratio (say, due to MAP_SHARED activity) then the task will again throttle after dirtying a single page. But there is now an upper limit on the time for which a single task will be captured in balance_dirty_pages(). --- mm/page-writeback.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 5cc38dac73199..7348c97a4b255 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -139,6 +139,9 @@ void balance_dirty_pages(struct address_space *mapping) struct page_state ps; long background_thresh; long dirty_thresh; + unsigned long pages_written = 0; + unsigned long write_chunk = sync_writeback_pages(); + struct backing_dev_info *bdi = mapping->backing_dev_info; get_dirty_limits(&ps, &background_thresh, &dirty_thresh); @@ -147,7 +150,7 @@ void balance_dirty_pages(struct address_space *mapping) .bdi = bdi, .sync_mode = WB_SYNC_NONE, .older_than_this = NULL, - .nr_to_write = sync_writeback_pages(), + .nr_to_write = write_chunk, }; dirty_exceeded = 1; @@ -158,10 +161,14 @@ void balance_dirty_pages(struct address_space *mapping) get_dirty_limits(&ps, &background_thresh, &dirty_thresh); if (ps.nr_dirty + ps.nr_writeback <= dirty_thresh) break; + pages_written += write_chunk - wbc.nr_to_write; + if (pages_written >= write_chunk) + break; /* We've done our duty */ blk_congestion_wait(WRITE, HZ/10); } - dirty_exceeded = 0; + if (ps.nr_dirty + ps.nr_writeback <= dirty_thresh) + dirty_exceeded = 0; if (!writeback_in_progress(bdi) && ps.nr_dirty > background_thresh) pdflush_operation(background_writeout, 0); -- 2.53.0