Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp474731ybz; Wed, 22 Apr 2020 01:50:13 -0700 (PDT) X-Google-Smtp-Source: APiQypJA4rpFjJXdmpiDRaBhFxIEaeXyEZe8kM1/VQvUHwNfw+o/3he8j9QrYH/99wjwhHvFxJEH X-Received: by 2002:a05:6402:1adc:: with SMTP id ba28mr15777587edb.336.1587545413271; Wed, 22 Apr 2020 01:50:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587545413; cv=none; d=google.com; s=arc-20160816; b=zObIDwuA/E0UwrXdndXmKOsS7EeVUuIba4cXQXznetn+RwRiMMRj2TNCB4NnpagVJ4 o/mJyat04NTQZl5Ed+bpsQizkV0aNPhAsCONGRjZClla940F3tfMKzmlPGAUj0vWNw0a DBsKELIWzO6Pkq+/otYPVrA7Ab1Lg+s1b79z28SCt5EPsZOS8Dsrjd6kWUPfh6ZyxJc0 /bWKeVMbblcgYuAqy2Y3d8hH1UnBd5o3Ic0z+7Z7tU2FCZZzQf8yx2k560yET3cWUZY2 aBrtysblam+GyfDIXprXgfJQd52kzHZO4Xygk56ItHcFC8pfUrmCI0iN5doYBWgI2ef5 NPWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type:message-id :date:subject:cc:to:from:dkim-signature:dkim-filter; bh=eQSA8h2xg1wXg3fIRq7J83yR47+XW1DnktB+3VwIZXI=; b=cnkKzf3Si+3mJIuXqyfcA+0P8YUpiWAYzq1/Tn1x+LY+Mkw+nKyXXD37lwy9XJJtX5 UufcrNgKp4/ZoZ9oXxOyFGUFou+FeOxSPmrSsO1qClS8ZNytPLlIv2KggEquzRJzp5n1 Ktj+Ze0cGFo+aKK0zzJ7dFqheeHw6syDhM4MgF1KdvXZm7ZtFNfKOA0S86uimrAn5RZd gZQhgbNmv8akL7QrPHsP3KYqBEEZxMWws1FGXdjtmGFc/FL1yVVzPYGfJhJrLr199Kql F7N82/GRGMzoX1z6EXeLn6O/9QRQnyYIOmEllgaH7R8mNf+jFYRtHxoYFQaf6S5cDKbZ BpyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=Sgk74T1H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g8si3051710ejb.359.2020.04.22.01.49.50; Wed, 22 Apr 2020 01:50:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=Sgk74T1H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726545AbgDVIsk (ORCPT + 99 others); Wed, 22 Apr 2020 04:48:40 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:11482 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726447AbgDVIsj (ORCPT ); Wed, 22 Apr 2020 04:48:39 -0400 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20200422084835epoutp03bcac1d1017289299b797647d8a554cc5~IGA2i7ueN2433724337epoutp03t for ; Wed, 22 Apr 2020 08:48:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20200422084835epoutp03bcac1d1017289299b797647d8a554cc5~IGA2i7ueN2433724337epoutp03t DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1587545315; bh=eQSA8h2xg1wXg3fIRq7J83yR47+XW1DnktB+3VwIZXI=; h=From:To:Cc:Subject:Date:References:From; b=Sgk74T1HcYskWRrHtU/QYzDuDnUW4NF/pak9r42uNRkN1HAFs0VAyJ8Tg37LzoPJz PUMQEG9lXCkypYIRmdNhdZNk1MVTbgJnFSP71iftBFe29Z9DEavRi41ZycYBduJ9MW w1ctan+lmPxfvGuKWV1l+DGTyXecpqMFmfU6uieg= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20200422084834epcas1p2d258c0bbc7d7a3b2a1d430235488778e~IGA12TL_g2724327243epcas1p2I; Wed, 22 Apr 2020 08:48:34 +0000 (GMT) Received: from epsmges1p4.samsung.com (unknown [182.195.40.162]) by epsnrtp2.localdomain (Postfix) with ESMTP id 496YxY45wGzMqYkV; Wed, 22 Apr 2020 08:48:33 +0000 (GMT) Received: from epcas1p2.samsung.com ( [182.195.41.46]) by epsmges1p4.samsung.com (Symantec Messaging Gateway) with SMTP id 25.9D.04744.1E400AE5; Wed, 22 Apr 2020 17:48:33 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20200422084832epcas1p333225f9b6a00c9ce36f5f5d63fe6e3bf~IGAz6cMT90541005410epcas1p3l; Wed, 22 Apr 2020 08:48:32 +0000 (GMT) Received: from epsmgms1p2new.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200422084832epsmtrp1a57fc1df04dbeea36a5614e95117a474~IGAz5ei8E1528715287epsmtrp1Z; Wed, 22 Apr 2020 08:48:32 +0000 (GMT) X-AuditID: b6c32a38-253ff70000001288-4d-5ea004e1aa22 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 8A.C6.04158.0E400AE5; Wed, 22 Apr 2020 17:48:32 +0900 (KST) Received: from jaewon-linux.10.32.193.11 (unknown [10.253.104.82]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200422084832epsmtip12c8d7257ca3409a76ed0a09342adb55a~IGAztwAtT0500705007epsmtip1W; Wed, 22 Apr 2020 08:48:32 +0000 (GMT) From: Jaewon Kim To: minchan@kernel.org, mgorman@suse.de, hannes@cmpxchg.org, m.szyprowski@samsung.com, mina86@mina86.com, shli@fb.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, ytk.lee@samsung.com, Jaewon Kim Subject: [PATCH v2] mm/vmscan: count layzfree pages and fix nr_isolated_* mismatch Date: Wed, 22 Apr 2020 17:48:15 +0900 Message-Id: <20200422084815.21913-1-jaewon31.kim@samsung.com> X-Mailer: git-send-email 2.13.7 X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0hTcRTH+e3eu01rdVuvX9JjXeih5dyas5+VEWRxowKjKJByXbbrlPbi 3i16/GO5TFPT9ZAMq/UkNDPuLJo9IJOeYpFkL1aZtUpqC0sTyurOa9R/n3PO98s5nHOUmLpc nqDMd7hZzsHYKHk8fulmoja5E/fn6AL741FNwzk5qhNWotJANUDl0W4Zam+qkaOX534TqL4l pED7I2GA/Le9BDrTG1WgM8EKHHU1DFs0nL75KYrRvsKIgg4eDiloobZETgs9+xT0nUM/cPr8 z24ZvbexFtCB+9vpr8LkrPhs24I8lrGwnIZ1mJ2WfIc1g1q+2rTYZEzT6ZP16WgupXEwdjaD ylyRlbw03yZOTWk2MzaPmMpieJ5KWbiAc3rcrCbPybszKNZlsbn0OpeWZ+y8x2HVmp32eXqd bo5RVG605b3qeoe7gjO2+J724gWgU7MHxCkhmQrvXq/GYqwmLwPYUrp2D4gXuQfAqtPPhwp9 ADZdZf4afB3VMkl0DcCCijcKKfgO4L3dA4MOOTkLRv37iBiPIQ8A2NdIx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ytxDjBIczEoivBseAoV4UxIrq1KL8uOLSnNSiw8xSnOwKInzyucfixQSSE8sSc1OTS1ILYLJ MnFwSjUwZmgYbVLKnKVoePP40qU3E7SDvjg8D1fTbvD/lvQ6wSNW68f+hCVmxvXiD9xLf0fz yV+x1/oquc5s7s4PIabprye5FfA4z9+6Idxpyq7yJVWGArEdBy94NrzqPq2cGPpPKWXbAb5P cc++TzKX7Nt3YGeO5rqPexxPKDx5ffSQ4TX2Ww/VX85rVmIpzkg01GIuKk4EAGrvZJ9OAgAA X-CMS-MailID: 20200422084832epcas1p333225f9b6a00c9ce36f5f5d63fe6e3bf X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20200422084832epcas1p333225f9b6a00c9ce36f5f5d63fe6e3bf References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch fix nr_isolate_* mismatch problem between cma and dirty lazyfree page. If try_to_unmap_one is used for reclaim and it detects a dirty lazyfree page, then the lazyfree page is changed to a normal anon page having SwapBacked by commit 802a3a92ad7a ("mm: reclaim MADV_FREE pages"). Even with the change, reclaim context correctly counts isolated files because it uses is_file_lru to distinguish file. And the change to anon is not happened if try_to_unmap_one is used for migration. So migration context like compaction also correctly counts isolated files even though it uses page_is_file_lru insted of is_file_lru. Recently page_is_file_cache was renamed to page_is_file_lru by commit 9de4f22a60f7 ("mm: code cleanup for MADV_FREE"). But the nr_isolate_* mismatch problem happens on cma alloc. There is reclaim_clean_pages_from_list which is being used only by cma. It was introduced by commit 02c6de8d757c ("mm: cma: discard clean pages during contiguous allocation instead of migration") to reclaim clean file pages without migration. The cma alloc uses both reclaim_clean_pages_from_list and migrate_pages, and it uses page_is_file_lru to count isolated files. If there are dirty lazyfree pages allocated from cma memory region, the pages are counted as isolated file at the beginging but are counted as isolated anon after finished. Mem-Info: Node 0 active_anon:3045904kB inactive_anon:611448kB active_file:14892kB inactive_file:205636kB unevictable:10416kB isolated(anon):0kB isolated(file):37664kB mapped:630216kB dirty:384kB writeback:0kB shmem:42576kB writeback_tmp:0kB unstable:0kB all_unreclaimable? no Like log above, there was too much isolated file, 37664kB, which triggers too_many_isolated in reclaim when there is no isolated file in system wide. It could be reproducible by running two programs, doing MADV_FREE, writing and doing cma alloc, respectively. Although isolated anon is 0, I found that the internal value of isolated anon was the negative value of isolated file. Fix this by compensating the isolated count for both LRU lists. Count non-discarded lazyfree pages in shrink_page_list, then compensate the counted number in reclaim_clean_pages_from_list. Reported-by: Yong-Taek Lee Signed-off-by: Jaewon Kim Suggested-by: and Acked-by: Minchan Kim --- v2: do not change logic regarding lazyfree just count dirty lazyfree pages and fix the count issue v1: skip dirty lazyfree pages in reclaim_clean_pages_from_list --- include/linux/vmstat.h | 1 + mm/vmscan.c | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h index 292485f3d24d..10cc932e209a 100644 --- a/include/linux/vmstat.h +++ b/include/linux/vmstat.h @@ -29,6 +29,7 @@ struct reclaim_stat { unsigned nr_activate[2]; unsigned nr_ref_keep; unsigned nr_unmap_fail; + unsigned nr_lazyfree_fail; }; enum writeback_stat_item { diff --git a/mm/vmscan.c b/mm/vmscan.c index b06868fc4926..cd6881810ee9 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1295,11 +1295,15 @@ static unsigned long shrink_page_list(struct list_head *page_list, */ if (page_mapped(page)) { enum ttu_flags flags = ttu_flags | TTU_BATCH_FLUSH; + bool lazyfree = PageAnon(page) && !PageSwapBacked(page); if (unlikely(PageTransHuge(page))) flags |= TTU_SPLIT_HUGE_PMD; + if (!try_to_unmap(page, flags)) { stat->nr_unmap_fail += nr_pages; + if (lazyfree && PageSwapBacked(page)) + stat->nr_lazyfree_fail += nr_pages; goto activate_locked; } } @@ -1491,8 +1495,8 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone, .priority = DEF_PRIORITY, .may_unmap = 1, }; - struct reclaim_stat dummy_stat; - unsigned long ret; + struct reclaim_stat stat; + unsigned long reclaimed; struct page *page, *next; LIST_HEAD(clean_pages); @@ -1504,11 +1508,21 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone, } } - ret = shrink_page_list(&clean_pages, zone->zone_pgdat, &sc, - TTU_IGNORE_ACCESS, &dummy_stat, true); + reclaimed = shrink_page_list(&clean_pages, zone->zone_pgdat, &sc, + TTU_IGNORE_ACCESS, &stat, true); list_splice(&clean_pages, page_list); - mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, -ret); - return ret; + mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, -reclaimed); + /* + * Since lazyfree pages are isolated from file LRU from the beginning, + * they will rotate back to anonymous LRU in the end if it failed to + * discard so isolated count will be mismatched. + * Compensate the isolated count for both LRU lists. + */ + mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_ANON, + stat.nr_lazyfree_fail); + mod_node_page_state(zone->zone_pgdat, NR_ISOLATED_FILE, + -stat.nr_lazyfree_fail); + return reclaimed; } /* -- 2.13.7