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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, 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 0910CC5519F for ; Sun, 22 Nov 2020 14:02:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 61A6920782 for ; Sun, 22 Nov 2020 14:02:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 61A6920782 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 906D46B006E; Sun, 22 Nov 2020 09:02:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B7616B0070; Sun, 22 Nov 2020 09:02:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CE1C6B0071; Sun, 22 Nov 2020 09:02:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id 50D656B006E for ; Sun, 22 Nov 2020 09:02:21 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DC2482839 for ; Sun, 22 Nov 2020 14:02:20 +0000 (UTC) X-FDA: 77512218840.25.milk80_0716e8b2735d Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id B49711804E3B2 for ; Sun, 22 Nov 2020 14:02:20 +0000 (UTC) X-HE-Tag: milk80_0716e8b2735d X-Filterd-Recvd-Size: 8979 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Sun, 22 Nov 2020 14:02:19 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R421e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04407;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0UG8gdoX_1606053728; Received: from IT-FVFX43SYHV2H.lan(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0UG8gdoX_1606053728) by smtp.aliyun-inc.com(127.0.0.1); Sun, 22 Nov 2020 22:02:09 +0800 Subject: Re: [PATCH next] mm/vmscan: __isolate_lru_page_prepare clean up To: Matthew Wilcox Cc: Andrew Morton , Hugh Dickins , Yu Zhao , Vlastimil Babka , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1605859413-53864-1-git-send-email-alex.shi@linux.alibaba.com> <20201120151307.4d9e3ef092ba01a325db7ce2@linux-foundation.org> <20201122123552.GF4327@casper.infradead.org> From: Alex Shi Message-ID: <728874d7-2d93-4049-68c1-dcc3b2d52ccd@linux.alibaba.com> Date: Sun, 22 Nov 2020 22:00:24 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20201122123552.GF4327@casper.infradead.org> Content-Type: text/plain; charset=gbk 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: =D4=DA 2020/11/22 =CF=C2=CE=E78:35, Matthew Wilcox =D0=B4=B5=C0: > On Sun, Nov 22, 2020 at 08:00:19PM +0800, Alex Shi wrote: >> mm/compaction.c | 2 +- >> mm/vmscan.c | 69 +++++++++++++++++++++++-------------------------= - >> 2 files changed, 34 insertions(+), 37 deletions(-) >=20 > How is it possible you're changing the signature of a function without > touching a header file? Surely __isolate_lru_page_prepare() must be de= clared > in mm/internal.h ? >=20 >> +++ b/mm/vmscan.c >> @@ -1536,19 +1536,17 @@ unsigned int reclaim_clean_pages_from_list(str= uct zone *zone, >> * page: page to consider >> * mode: one of the LRU isolation modes defined above >> * >> - * returns 0 on success, -ve errno on failure. >> + * returns ture on success, false on failure. >=20 > "true". >=20 >> @@ -1674,35 +1672,34 @@ static unsigned long isolate_lru_pages(unsigne= d long nr_to_scan, >> * only when the page is being freed somewhere else. >> */ >> scan +=3D nr_pages; >> - switch (__isolate_lru_page_prepare(page, mode)) { >> - case 0: >> + if (!__isolate_lru_page_prepare(page, mode)) { >> + /* else it is being freed elsewhere */ >=20 > I don't think the word "else" helps here. Just > /* It is being freed elsewhere */ >=20 >> + if (!TestClearPageLRU(page)) { >> /* >> + * This page may in other isolation path, >> + * but we still hold lru_lock. >> */ >=20 > I don't think this comment helps me understand what's going on here. > Maybe: >=20 > /* Another thread is already isolating this page */ >=20 >> + put_page(page); >> list_move(&page->lru, src); >> + continue; >> } Hi Matthew, Thanks a lot for all comments, I picked all up and here is the v3: >From 167131dd106a96fd08af725df850e0da6ec899af Mon Sep 17 00:00:00 2001 From: Alex Shi Date: Fri, 20 Nov 2020 14:49:16 +0800 Subject: [PATCH v3 next] mm/vmscan: __isolate_lru_page_prepare clean up The function just return 2 results, so use a 'switch' to deal with its result is unnecessary, and simplify it to a bool func as Vlastimil suggested. Also remove 'goto' by reusing list_move(), and take Matthew Wilcox's suggestion to update comments in function. Signed-off-by: Alex Shi Cc: Andrew Morton Cc: Matthew Wilcox Cc: Hugh Dickins Cc: Yu Zhao Cc: Vlastimil Babka Cc: Michal Hocko Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- include/linux/swap.h | 2 +- mm/compaction.c | 2 +- mm/vmscan.c | 68 ++++++++++++++++++++------------------------ 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 596bc2f4d9b0..5bba15ac5a2e 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -356,7 +356,7 @@ extern void lru_cache_add_inactive_or_unevictable(str= uct page *page, extern unsigned long zone_reclaimable_pages(struct zone *zone); extern unsigned long try_to_free_pages(struct zonelist *zonelist, int or= der, gfp_t gfp_mask, nodemask_t *mask); -extern int __isolate_lru_page_prepare(struct page *page, isolate_mode_t = mode); +extern bool __isolate_lru_page_prepare(struct page *page, isolate_mode_t= mode); extern unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *mem= cg, unsigned long nr_pages, gfp_t gfp_mask, diff --git a/mm/compaction.c b/mm/compaction.c index b68931854253..8d71ffebe6cb 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -988,7 +988,7 @@ isolate_migratepages_block(struct compact_control *cc= , unsigned long low_pfn, if (unlikely(!get_page_unless_zero(page))) goto isolate_fail; =20 - if (__isolate_lru_page_prepare(page, isolate_mode) !=3D 0) + if (!__isolate_lru_page_prepare(page, isolate_mode)) goto isolate_fail_put; =20 /* Try isolate the page */ diff --git a/mm/vmscan.c b/mm/vmscan.c index c6f94e55c3fe..4d2703c43310 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1536,19 +1536,17 @@ unsigned int reclaim_clean_pages_from_list(struct= zone *zone, * page: page to consider * mode: one of the LRU isolation modes defined above * - * returns 0 on success, -ve errno on failure. + * returns true on success, false on failure. */ -int __isolate_lru_page_prepare(struct page *page, isolate_mode_t mode) +bool __isolate_lru_page_prepare(struct page *page, isolate_mode_t mode) { - int ret =3D -EBUSY; - /* Only take pages on the LRU. */ if (!PageLRU(page)) - return ret; + return false; =20 /* Compaction should not handle unevictable pages but CMA can do so */ if (PageUnevictable(page) && !(mode & ISOLATE_UNEVICTABLE)) - return ret; + return false; =20 /* * To minimise LRU disruption, the caller can indicate that it only @@ -1561,7 +1559,7 @@ int __isolate_lru_page_prepare(struct page *page, i= solate_mode_t mode) if (mode & ISOLATE_ASYNC_MIGRATE) { /* All the caller can do on PageWriteback is block */ if (PageWriteback(page)) - return ret; + return false; =20 if (PageDirty(page)) { struct address_space *mapping; @@ -1577,20 +1575,20 @@ int __isolate_lru_page_prepare(struct page *page,= isolate_mode_t mode) * from the page cache. */ if (!trylock_page(page)) - return ret; + return false; =20 mapping =3D page_mapping(page); migrate_dirty =3D !mapping || mapping->a_ops->migratepage; unlock_page(page); if (!migrate_dirty) - return ret; + return false; } } =20 if ((mode & ISOLATE_UNMAPPED) && page_mapped(page)) - return ret; + return false; =20 - return 0; + return true; } =20 /* @@ -1674,35 +1672,31 @@ static unsigned long isolate_lru_pages(unsigned l= ong nr_to_scan, * only when the page is being freed somewhere else. */ scan +=3D nr_pages; - switch (__isolate_lru_page_prepare(page, mode)) { - case 0: - /* - * Be careful not to clear PageLRU until after we're - * sure the page is not being freed elsewhere -- the - * page release code relies on it. - */ - if (unlikely(!get_page_unless_zero(page))) - goto busy; - - if (!TestClearPageLRU(page)) { - /* - * This page may in other isolation path, - * but we still hold lru_lock. - */ - put_page(page); - goto busy; - } - - nr_taken +=3D nr_pages; - nr_zone_taken[page_zonenum(page)] +=3D nr_pages; - list_move(&page->lru, dst); - break; + if (!__isolate_lru_page_prepare(page, mode)) { + /* It is being freed elsewhere */ + list_move(&page->lru, src); + continue; + } + /* + * Be careful not to clear PageLRU until after we're + * sure the page is not being freed elsewhere -- the + * page release code relies on it. + */ + if (unlikely(!get_page_unless_zero(page))) { + list_move(&page->lru, src); + continue; + } =20 - default: -busy: - /* else it is being freed elsewhere */ + if (!TestClearPageLRU(page)) { + /* Another thread is already isolating this page */ + put_page(page); list_move(&page->lru, src); + continue; } + + nr_taken +=3D nr_pages; + nr_zone_taken[page_zonenum(page)] +=3D nr_pages; + list_move(&page->lru, dst); } =20 /* --=20 2.29.GIT