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=-6.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 60B9AC55181 for ; Wed, 22 Apr 2020 05:41:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D9BA22072D for ; Wed, 22 Apr 2020 05:41:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PAcLGzCN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9BA22072D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3D2A78E0005; Wed, 22 Apr 2020 01:41:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35D338E0003; Wed, 22 Apr 2020 01:41:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2251F8E0005; Wed, 22 Apr 2020 01:41:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id 03E498E0003 for ; Wed, 22 Apr 2020 01:41:02 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9EB444DD8 for ; Wed, 22 Apr 2020 05:41:02 +0000 (UTC) X-FDA: 76734392364.23.steam72_91079cbdf437 X-HE-Tag: steam72_91079cbdf437 X-Filterd-Recvd-Size: 12101 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Wed, 22 Apr 2020 05:41:02 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id b8so515685pfp.8 for ; Tue, 21 Apr 2020 22:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=uBImYFPEvlWaVjtMRb0VCbEwinzl3N8twx+hX4o14p0=; b=PAcLGzCNQxoSeWCXdDwtKHvJyaRU0j+OQ55Z9Frs4TNGkaBxmjBsJYujOWSp/Zy9gg FhiJU4WOi/hRU/vPtYHW1FEsM5/8JK3w6J2XxkW2sCBTlskPwkn4TLQJZD2QJNDUGl1c PImUZq+ekaAFcnmim8U35e1g275O3924ilKHY++f5JUevcpM+eChaepUxS0wweQAFlc1 5QzX1yGJVCC4A7yF5jGOydZlv1lifo/3UsEWWXc4i+AFDVgJ9cB/dAc5KojOB2/dhRga vCegeqshYNcuWfGdjPtOOHh1aAQKUwY1CEM++nrFhm8n0vb6YKvDuORmZV+IQE2blGoz AV4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to; bh=uBImYFPEvlWaVjtMRb0VCbEwinzl3N8twx+hX4o14p0=; b=jGVGhDZCfCYyh25u7hwdUpsL34cT4BjnNUC44ZLAj6paHjQ+XP9QXJ8WxysMQ+Tri0 2EetHKEO4QlPTUDRxgAZbIvoUQE/BLNG9o3C05wwzuzO2wbm+GK/4dRtrUWzTrNoSCLM xurttccD0aS7ySxkbQLkrBEadN1fDgxpKhCBPws67MWkAq3vubSl4UAt+CFAb34I73vp EjEQUbD9qhGREd+UmR2zSRN0zb8pcSqLDvGsmQpexQwWCfRguYex0875WHpXPXDVR5sq NzbR2f/DWjDIw9AK7M7pgem3obrQ9tbJk3Jzb53LOgBRQ+UHhWqFVekCwksECLL8BYTc x/0w== X-Gm-Message-State: AGi0PuZTO5WHmWgXvPIWN4pLV+fCFLygztEdjbQgqp+Sq6URRTxXKpgc yMn8Evo8ehsaIfEakVr5XYc= X-Google-Smtp-Source: APiQypISFdoyegiLRlxTIhukhAHNyAPT+BKJoDO30n9h8KkmeCkYp2QEa1V13f5GiH4Kq+sDkdepnw== X-Received: by 2002:a62:528e:: with SMTP id g136mr11633989pfb.165.1587534060954; Tue, 21 Apr 2020 22:41:00 -0700 (PDT) Received: from google.com ([2601:647:4001:3000::50e3]) by smtp.gmail.com with ESMTPSA id h27sm4000958pgb.90.2020.04.21.22.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 22:40:59 -0700 (PDT) Date: Tue, 21 Apr 2020 22:40:57 -0700 From: Minchan Kim To: Jaewon Kim Cc: Johannes Weiner , 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, shli@fb.com Subject: Re: [PATCH] mm/vmscan: skip layzfree page on reclaim_clean_pages_from_list Message-ID: <20200422054057.GA97071@google.com> References: <20200416033514.6366-1-jaewon31.kim@samsung.com> <20200417003837.GA90471@google.com> <20200417151358.GA178621@google.com> <5E9A3FB7.1040803@samsung.com> <5E9D3EFD.8030008@samsung.com> <5E9EE1CD.1030809@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5E9EE1CD.1030809@samsung.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 Tue, Apr 21, 2020 at 09:06:37PM +0900, Jaewon Kim wrote: >=20 >=20 > On 2020=EB=85=84 04=EC=9B=94 20=EC=9D=BC 15:19, Jaewon Kim wrote: > > > > On 2020=EB=85=84 04=EC=9B=94 18=EC=9D=BC 08:45, Jaewon Kim wrote: > >> 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 dirt= y > >>>>> lazyfree page. > >>>>> > >>>>> If try_to_unmap_one is used for reclaim and it detects a dirty la= zyfree > >>>>> page, then the lazyfree page is changed to a normal anon page hav= ing > >>>>> SwapBacked by commit 18863d3a3f59 ("mm: remove SWAP_DIRTY in ttu"= ). Even > >>>>> with the change, reclaim context correctly counts isolated files = because > >>>>> it uses is_file_lru to distinguish file. And the change to anon i= s 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_cac= he was > >>>>> renamed to page_is_file_lru by commit 9de4f22a60f7 ("mm: code cle= anup 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 fil= e pages > >>>>> without migration. The cma alloc uses both reclaim_clean_pages_fr= om_list > >>>>> and migrate_pages, and it uses page_is_file_lru to count isolated > >>>>> files. If there are dirty lazyfree pages allocated from cma memor= y > >>>>> region, the pages are counted as isolated file at the beginging b= ut are > >>>>> counted as isolated anon after finished. > >>>>> > >>>>> Mem-Info: > >>>>> Node 0 active_anon:3045904kB inactive_anon:611448kB active_file:1= 4892kB inactive_file:205636kB unevictable:10416kB isolated(anon):0kB isol= ated(file):37664kB mapped:630216kB dirty:384kB writeback:0kB shmem:42576k= B 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 f= ile in > >>>>> system wide. It could be reproducible by running two programs, do= ing > >>>>> MADV_FREE, writing and doing cma alloc, respectively. Although is= olated > >>>>> anon is 0, I found that the internal value of isolated anon was t= he > >>>>> 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 al= l > >>>>> 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 chan= ge > >>>> 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= (struct 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 o= ther > >> 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(struc= t list_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(s= truct 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= (struct 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, &s= c, > >>> + 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, -reclaime= d); > >>> + /* > >>> + * Since lazyfree pages are isolated from file LRU from the begin= ning, > >>> + * 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 o= f -> > >>> + return reclaimed; > >>> } > >>> =20 > >>> /* > > Let me just CC Shaohua Li for commit 802a3a92ad7a ("mm: reclaim MADV_= FREE pages") > > , because I missed him/her on other mail thread=20 > > : Sorry, I think I pointed a wrong commit, the SwapBacked was recove= red > > : by commit 802a3a92ad7a ("mm: reclaim MADV_FREE pages"). > > > > > > Hello Minchan > > > > I tested on my v4.19 based source tree and it seems to work. > > > > Prior to your patch I applied commit 060f005f0747 ( > > "mm/vmscan.c: do not allocate duplicate stack variables in shrink_pag= e_list()" > > for struct reclaim_stat. > > > > I considered other dependent changes below to follow code changes, no= t really needed for this issue though. > > v5.3 98879b3b9edc mm: vmscan: correct some vmscan counters for THP sw= apout > > v5.2 886cf1901db9 mm: move recent_rotated pages calculation to shrink= _inactive_list() > Hello Minchan >=20 > Are you preparing a complete patch for this issue? > Sorry if I am bugging you. Hi Jaewon Sorry for the late. You catched the bug and gave good description with the solution. What I did was just suggestion for alternative so feel free to send the patch with your SoB. You could use my Suggested-by and Acked-by. It's totally your credit! Thanks! Thanks!