When setting swapiness to 0, the anon pages should be reclaimed if and only if the value of file_is_tiny is true. __zone_watermark_ok uses per-zone watermark and lowmem_reserve to determine whether allocating page from the zone. In the mean time, file_is_tiny is calculated by per-node watermark. There are inconsistencies between the two scenarios. If total free pages on node is enough, then file_is_tiny can not be true, so the anon pages can not be reclaimed. If the free pages in each zone is less than watermark + lowmem_reserve, then the allocation will failed too. Due to lowmem_reserve, these two cases can occur at the same time: zone_page_state(zone, NR_FREE_PAGES) < watermark + lowmem_reserve node_page_state(pgdat, NR_FREE_PAGES) > total_high_wmark When both are met, there will be many anon pages that can not be reclaimed because file_is_tiny is false, and in the same time, the allocation failed because per-zone watermark is not suitable. Split the condition (file + free <= high_wmark) to per-zone to fix it. Reported-and-tested-by: Jinjiang Tu <tujinjiang@xxxxxxxxxx> Signed-off-by: Liu Shixin <liushixin2@xxxxxxxxxx> --- mm/vmscan.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index e73e2df8828d..f1dc0dbf1cdb 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3009,21 +3009,23 @@ static void prepare_scan_count(pg_data_t *pgdat, struct scan_control *sc) * anon pages. Try to detect this based on file LRU size. */ if (!cgroup_reclaim(sc)) { - unsigned long total_high_wmark = 0; unsigned long free, anon; int z; - free = sum_zone_node_page_state(pgdat->node_id, NR_FREE_PAGES); - file = node_page_state(pgdat, NR_ACTIVE_FILE) + - node_page_state(pgdat, NR_INACTIVE_FILE); - for (z = 0; z < MAX_NR_ZONES; z++) { struct zone *zone = &pgdat->node_zones[z]; if (!managed_zone(zone)) continue; - total_high_wmark += high_wmark_pages(zone); + free = zone_page_state(zone, NR_FREE_PAGES); + file = zone_page_state(zone, NR_ZONE_ACTIVE_FILE) + + zone_page_state(zone, NR_ZONE_INACTIVE_FILE); + + if (file + free <= high_wmark_pages(zone)) { + sc->file_is_tiny = true; + break; + } } /* @@ -3033,8 +3035,7 @@ static void prepare_scan_count(pg_data_t *pgdat, struct scan_control *sc) */ anon = node_page_state(pgdat, NR_INACTIVE_ANON); - sc->file_is_tiny = - file + free <= total_high_wmark && + sc->file_is_tiny = sc->file_is_tiny && !(sc->may_deactivate & DEACTIVATE_ANON) && anon >> sc->priority; } -- 2.25.1