Skip to content

Commit 726d061

Browse files
hnaztorvalds
authored andcommitted
mm: vmscan: kick flushers when we encounter dirty pages on the LRU
Memory pressure can put dirty pages at the end of the LRU without anybody running into dirty limits. Don't start writing individual pages from kswapd while the flushers might be asleep. Unlike the old direct reclaim flusher wakeup (removed in the next patch) that flushes the number of pages just scanned, this patch wakes the flushers for all outstanding dirty pages. That seemed to perform better in a synthetic test that pushes dirty pages to the end of the LRU and into reclaim, because we know LRU aging outstrips writeback already, and this way we give younger dirty pages a headstart rather than wait until reclaim runs into them as well. It also means less plugging and risk of exhausting the struct request pool from reclaim. There is a concern that this will cause temporary files that used to get dirtied and truncated before writeback to now get written to disk under memory pressure. If this turns out to be a real problem, we'll have to revisit this and tame the reclaim flusher wakeups. [[email protected]: mention dirty expiration as a condition] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Johannes Weiner <[email protected]> Acked-by: Minchan Kim <[email protected]> Acked-by: Michal Hocko <[email protected]> Acked-by: Mel Gorman <[email protected]> Acked-by: Hillf Danton <[email protected]> Cc: Rik van Riel <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 1276ad6 commit 726d061

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

include/linux/writeback.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ enum writeback_sync_modes {
4646
*/
4747
enum wb_reason {
4848
WB_REASON_BACKGROUND,
49-
WB_REASON_TRY_TO_FREE_PAGES,
49+
WB_REASON_VMSCAN,
5050
WB_REASON_SYNC,
5151
WB_REASON_PERIODIC,
5252
WB_REASON_LAPTOP_TIMER,

include/trace/events/writeback.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#define WB_WORK_REASON \
3333
EM( WB_REASON_BACKGROUND, "background") \
34-
EM( WB_REASON_TRY_TO_FREE_PAGES, "try_to_free_pages") \
34+
EM( WB_REASON_VMSCAN, "vmscan") \
3535
EM( WB_REASON_SYNC, "sync") \
3636
EM( WB_REASON_PERIODIC, "periodic") \
3737
EM( WB_REASON_LAPTOP_TIMER, "laptop_timer") \

mm/vmscan.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,12 +1798,20 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec,
17981798

17991799
/*
18001800
* If dirty pages are scanned that are not queued for IO, it
1801-
* implies that flushers are not keeping up. In this case, flag
1802-
* the pgdat PGDAT_DIRTY and kswapd will start writing pages from
1803-
* reclaim context.
1801+
* implies that flushers are not doing their job. This can
1802+
* happen when memory pressure pushes dirty pages to the end of
1803+
* the LRU before the dirty limits are breached and the dirty
1804+
* data has expired. It can also happen when the proportion of
1805+
* dirty pages grows not through writes but through memory
1806+
* pressure reclaiming all the clean cache. And in some cases,
1807+
* the flushers simply cannot keep up with the allocation
1808+
* rate. Nudge the flusher threads in case they are asleep, but
1809+
* also allow kswapd to start writing pages during reclaim.
18041810
*/
1805-
if (stat.nr_unqueued_dirty == nr_taken)
1811+
if (stat.nr_unqueued_dirty == nr_taken) {
1812+
wakeup_flusher_threads(0, WB_REASON_VMSCAN);
18061813
set_bit(PGDAT_DIRTY, &pgdat->flags);
1814+
}
18071815

18081816
/*
18091817
* If kswapd scans pages marked marked for immediate
@@ -2787,7 +2795,7 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
27872795
writeback_threshold = sc->nr_to_reclaim + sc->nr_to_reclaim / 2;
27882796
if (total_scanned > writeback_threshold) {
27892797
wakeup_flusher_threads(laptop_mode ? 0 : total_scanned,
2790-
WB_REASON_TRY_TO_FREE_PAGES);
2798+
WB_REASON_VMSCAN);
27912799
sc->may_writepage = 1;
27922800
}
27932801
} while (--sc->priority >= 0);

0 commit comments

Comments
 (0)