From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F0FBC2BB1D for ; Fri, 17 Apr 2020 23:46:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CA2BD214D8 for ; Fri, 17 Apr 2020 23:46:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="af4cPLmg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA2BD214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=samsung.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 62D378E0003; Fri, 17 Apr 2020 19:46:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5DDDA8E0001; Fri, 17 Apr 2020 19:46:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A55E8E0003; Fri, 17 Apr 2020 19:46:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0069.hostedemail.com [216.40.44.69]) by kanga.kvack.org (Postfix) with ESMTP id 2EBDC8E0001 for ; Fri, 17 Apr 2020 19:46:08 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E0E2C180ACEF0 for ; Fri, 17 Apr 2020 23:46:07 +0000 (UTC) X-FDA: 76718982774.28.soda79_1839db5f32931 X-HE-Tag: soda79_1839db5f32931 X-Filterd-Recvd-Size: 12527 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Fri, 17 Apr 2020 23:46:06 +0000 (UTC) Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20200417234603epoutp04b12eed837bf024eefde93807b267b11d~GwCA0G8EZ1888418884epoutp04W for ; Fri, 17 Apr 2020 23:46:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20200417234603epoutp04b12eed837bf024eefde93807b267b11d~GwCA0G8EZ1888418884epoutp04W DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1587167163; bh=seeFjaJPhc37ohY0tFs3YsQBiO34ZkHGGBV7nfv9MB4=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=af4cPLmgLxl4H4+S2XJygobRl+UpzOgo+v8oxQismPwpiG3u6fcbJ/0eoWRfOppHi NoM+mid5Js3xap0CKjdHm2HIC531ZivlL5jI8h/9W37GKRBuOHZNVPaJvP4+mKcyQP 8pHRDsrsHNWqLGBU4HG8HMF5c/atVVwZpMy1Cw94= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20200417234602epcas1p1e8891fa092ba7f39bafcc9bcb0699035~GwB-uF0sq0133501335epcas1p1T; Fri, 17 Apr 2020 23:46:02 +0000 (GMT) Received: from epsmges1p4.samsung.com (unknown [182.195.40.165]) by epsnrtp1.localdomain (Postfix) with ESMTP id 493t5P0kzmzMqYlr; Fri, 17 Apr 2020 23:46:01 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p4.samsung.com (Symantec Messaging Gateway) with SMTP id DF.21.04744.8BF3A9E5; Sat, 18 Apr 2020 08:46:01 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200417234600epcas1p16b8b877f0d1eb8a172ce2406a5cdcc9c~GwB_EjHBT2847028470epcas1p1f; Fri, 17 Apr 2020 23:46:00 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200417234600epsmtrp119cfb65d3db21be0e957007d85e4ec7f~GwB_A7EQN2171921719epsmtrp1O; Fri, 17 Apr 2020 23:46:00 +0000 (GMT) X-AuditID: b6c32a38-26bff70000001288-5f-5e9a3fb85643 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 35.86.04024.8BF3A9E5; Sat, 18 Apr 2020 08:46:00 +0900 (KST) Received: from [10.253.104.82] (unknown [10.253.104.82]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20200417234559epsmtip1e38c1d6a564bc86df37f397101493c50~GwB9l4wLq0883008830epsmtip1i; Fri, 17 Apr 2020 23:45:59 +0000 (GMT) Subject: Re: [PATCH] mm/vmscan: skip layzfree page on reclaim_clean_pages_from_list To: Minchan Kim , Johannes Weiner Cc: mgorman@suse.de, m.szyprowski@samsung.com, mina86@mina86.com, riel@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, jaewon31.kim@gmail.com, ytk.lee@samsung.com From: Jaewon Kim Message-ID: <5E9A3FB7.1040803@samsung.com> Date: Sat, 18 Apr 2020 08:45:59 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <20200417151358.GA178621@google.com> X-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VPJyiupHlNavrDV MBbO+7dm59Q1243uZkX+Zef7ZS5YZxXDbHIk4uHbf+dbrbKdxVSOZZ/qTb3NEqXEUpyRaKjF XFScCAApbl6e2AMAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprMIsWRmVeSWpSXmKPExsWy7bCSnO4O+1lxBmefslvMWb+GzWL1Jl+L 7s0zGS0u75rDZnFvzX9Wi7VH7rJbTH73jNFiwfEWVotlX9+zW/y9sp7F4vF6bgduj8Nv3jN7 7Jx1l91j06pONo9Nnyaxe5yY8ZvFY92fV0we7/ddZfPo27KK0WPz6WqPz5vkAriiuGxSUnMy y1KL9O0SuDJuHPzMWLDSuKLv2l2mBsb3ml2MnBwSAiYSy7avYu9i5OIQEtjNKLHnUzs7REJG 4s35pyxdjBxAtrDE4cPFEDWvGSVObJ0MViMsECqxYflyMFtEwEvi84qVrBBFtxklLqzaAZZg FjgP5FxxAbHZBLQl3i+YxAoylFdAS2LKtTCQMIuAqsS679dYQGxRgQiJ1euuMYPYvAKCEidn PgGLcwoYSvQu/cgE0sosoC6xfp4QxHR5ieats5knMArOQtIxC6FqFpKqBYzMqxglUwuKc9Nz iw0LDPNSy/WKE3OLS/PS9ZLzczcxgqNKS3MH4+Ul8YcYBTgYlXh4DXpmxgmxJpYVV+YeYpTg YFYS4T3oBhTiTUmsrEotyo8vKs1JLT7EKM3BoiTO+zTvWKSQQHpiSWp2ampBahFMlomDU6qB sTLw/56NC/o71zIzCUqX8zgri+db31zUcmbCFZ2byZ9+vDiwyZajrME7reZD38kLMbGnuSeu C129YNl1/XPm0/b39pZa7362f0kFl1+nupRimoLYnIhdmdIaHUY+2gJJ2Z535c6Eq5e93qdS V+5bnSqqL7Y2eeL8RTdnBG18osb69O2Rua7pSizFGYmGWsxFxYkAZUUMa6YCAAA= X-CMS-MailID: 20200417234600epcas1p16b8b877f0d1eb8a172ce2406a5cdcc9c 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: 20200416033543epcas1p2b256bef770bb1310a9bf62bda80a976a References: <20200416033514.6366-1-jaewon31.kim@samsung.com> <20200417003837.GA90471@google.com> <20200417151358.GA178621@google.com> Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2020=EB=85=84 04=EC=9B=94 18=EC=9D=BC 00:13, Minchan Kim wrote: > On Thu, Apr 16, 2020 at 05:38:37PM -0700, Minchan Kim wrote: >> Hi Jaewon, >> >> On Thu, Apr 16, 2020 at 12:35:14PM +0900, Jaewon Kim wrote: >>> 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 lazyfr= ee >>> page, then the lazyfree page is changed to a normal anon page having >>> SwapBacked by commit 18863d3a3f59 ("mm: remove SWAP_DIRTY in ttu"). E= ven >>> with the change, reclaim context correctly counts isolated files beca= use >>> it uses is_file_lru to distinguish file. And the change to anon is no= t >>> happened if try_to_unmap_one is used for migration. So migration cont= ext >>> like compaction also correctly counts isolated files even though it u= ses >>> page_is_file_lru insted of is_file_lru. Recently page_is_file_cache w= as >>> 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 duri= ng >>> contiguous allocation instead of migration") to reclaim clean file pa= ges >>> without migration. The cma alloc uses both reclaim_clean_pages_from_l= ist >>> 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 a= re >>> counted as isolated anon after finished. >>> >>> Mem-Info: >>> Node 0 active_anon:3045904kB inactive_anon:611448kB active_file:14892= kB inactive_file:205636kB unevictable:10416kB isolated(anon):0kB isolated= (file):37664kB mapped:630216kB dirty:384kB writeback:0kB shmem:42576kB wr= iteback_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 isolat= ed >>> anon is 0, I found that the internal value of isolated anon was the >>> negative value of isolated file. >>> >>> Fix this by skipping anon pages on reclaim_clean_pages_from_list. The >>> lazyfree page can be checked by both PageAnon(page) and >>> page_is_file_lru. But in this case, PageAnon is enough to skip all >>> anon pages. >>> >>> Reported-by: Yong-Taek Lee >>> Signed-off-by: Jaewon Kim >> Thanks for the investigation! >> The thing is MADV_FREEed page since supporting swapless could change >> his LRU status between reclaim. >> >> I am worry about voiding the optimization we have kept in CMA but >> also don't have good idea, either so I tend to agree with this. >> >> Let me Cc Johannes who might have better idea. >> >>> --- >>> mm/vmscan.c | 3 +++ >>> 1 file changed, 3 insertions(+) >>> >>> diff --git a/mm/vmscan.c b/mm/vmscan.c >>> index b06868fc4926..9380a18eef5e 100644 >>> --- a/mm/vmscan.c >>> +++ b/mm/vmscan.c >>> @@ -1497,6 +1497,9 @@ unsigned long reclaim_clean_pages_from_list(str= uct zone *zone, >>> LIST_HEAD(clean_pages); >>> =20 >>> list_for_each_entry_safe(page, next, page_list, lru) { >>> + /* to avoid race with MADV_FREE anon page */ >>> + if (PageAnon(page)) >>> + continue; >>> if (page_is_file_lru(page) && !PageDirty(page) && >>> !__PageMovable(page) && !PageUnevictable(page)) { >>> ClearPageActive(page); >>> --=20 >>> 2.13.7 >>> > Hi Jaewon, > > How about this idea? I think it could solve the issue with keeping > CMA alloc latency optimization. Hello Minchan It looks good to me except compilation error. And to apply this patch on other stable branches, we may need some other dependent patches though. Thank you > > 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; > }; > =20 > enum writeback_stat_item { > diff --git a/mm/vmscan.c b/mm/vmscan.c > index 4c8a1cdccbba..b390f6094f2f 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -1296,11 +1296,15 @@ static unsigned long shrink_page_list(struct li= st_head *page_list, > */ > if (page_mapped(page)) { > enum ttu_flags flags =3D ttu_flags | TTU_BATCH_FLUSH; > + bool lazyfree =3D PageAnon(page) && !PageSwapBacked(page); > =20 > if (unlikely(PageTransHuge(page))) > flags |=3D TTU_SPLIT_HUGE_PMD; > + > if (!try_to_unmap(page, flags)) { > stat->nr_unmap_fail +=3D nr_pages; > + if (lazyfree && PageSwapBacked(page)) > + stat->nr_lazyfree_fail +=3D nr_pages; > goto activate_locked; > } > } > @@ -1492,8 +1496,8 @@ unsigned long reclaim_clean_pages_from_list(struc= t zone *zone, > .priority =3D DEF_PRIORITY, > .may_unmap =3D 1, > }; > - struct reclaim_stat dummy_stat; > - unsigned long ret; > + struct reclaim_stat stat; > + unsigned long reclaimed; > struct page *page, *next; > LIST_HEAD(clean_pages); > =20 > @@ -1505,11 +1509,21 @@ unsigned long reclaim_clean_pages_from_list(str= uct zone *zone, > } > } > =20 > - ret =3D shrink_page_list(&clean_pages, zone->zone_pgdat, &sc, > - TTU_IGNORE_ACCESS, &dummy_stat, true); > + reclaimed =3D 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); should be stat.nr_lazyfree_fail and -stat.nr_lazyfree_fail instead of -> > + return reclaimed; > } > =20 > /*