From patchwork Wed Feb 15 10:39:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13141507 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5781EC6379F for ; Wed, 15 Feb 2023 10:39:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94A026B0073; Wed, 15 Feb 2023 05:39:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F73D6B0074; Wed, 15 Feb 2023 05:39:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BF886B0075; Wed, 15 Feb 2023 05:39:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6EC036B0073 for ; Wed, 15 Feb 2023 05:39:53 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E8F87C14E4 for ; Wed, 15 Feb 2023 10:39:52 +0000 (UTC) X-FDA: 80469180624.16.6617264 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by imf08.hostedemail.com (Postfix) with ESMTP id 903E1160003 for ; Wed, 15 Feb 2023 10:39:50 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf08.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676457591; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6mQCLPmyPTuTiyp8vHoPb0USCZMfC62NkilSxB9NCMo=; b=1lEpB3LLkA/PWoYUfQgG0SW4wpS1Gv4z0+sCebA2Ejb4PavHnsaWPTQ7A7lQVG6yl1DET8 PtyBlMxUkYQDtntzT5Tkx5ZSeZCbrNYi63N6gKvWQlWKBDACwNkVX8UhMWiS2AEq8hzrjs hkY2/Wz3MX9ORNdMeuIv7Xx74DzGrFg= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf08.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.99 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676457591; a=rsa-sha256; cv=none; b=BHDBoJqGuBjo4md3pQ+BIBGo8Ufaoz1ANtGP6j+OiQTV6zW47+ChGM/S1baqRUmHJRhrws O5kfylSAM8o0enkL5Jawg5IlhSsT+9Ug42u2Otv9fRw7GBANFCti1n6Qu9uh1W6RD5QFUH qgpzKLNaGl662uyyRfLc3KvrrpTNeK4= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R241e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0Vbk1bhe_1676457585; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Vbk1bhe_1676457585) by smtp.aliyun-inc.com; Wed, 15 Feb 2023 18:39:46 +0800 From: Baolin Wang To: akpm@linux-foundation.org Cc: torvalds@linux-foundation.org, sj@kernel.org, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, naoya.horiguchi@nec.com, linmiaohe@huawei.com, david@redhat.com, osalvador@suse.de, mike.kravetz@oracle.com, willy@infradead.org, baolin.wang@linux.alibaba.com, damon@lists.linux.dev, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] mm: change to return bool for folio_isolate_lru() Date: Wed, 15 Feb 2023 18:39:34 +0800 Message-Id: <8a4e3679ed4196168efadf7ea36c038f2f7d5aa9.1676424378.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 903E1160003 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: gewcb7kdzgdtrur94115d54n8gwabgeu X-HE-Tag: 1676457590-934195 X-HE-Meta: U2FsdGVkX19f12x+eCq6a6QL9pXZIDdkzjAlpN1ktLgqTH1xleIBEzTBYYV4oncMB6ZuuJqOhSmxHC2BJiYLPMVuf6sskmsd7iD69V47rUMKMUGT2TYuNfXudO7teu2Yhl8YE4He8FPhE/zHpmtvxuVeFDLeo7ixJi/foWnrCO7xiLu84IyJdCTs6qUnl2VBXGVcaT0s4bGNyTB8CG/3B3ISDwGby7xP6YVWg4AI6NY5DkNh8x1BvucQfao5s54YL6PXzbLo4IPNM2ipaUi3ggZl4cRnVM9Rkk9XGhIPGyIfWdOt/ChmTb7evLgbbX/wgrz36VXRKZy0TchV7L2JiEXUEsnV8czWZip1DnPEBIa12JuOgbu7pLIkVWZ34OQVc9D5qnlGXbR9LAoel4Q7wpCF9yaNYG7yiY+juZGTjaL2pj8lCg/4vzNzpWKo5eCMpVVLYmOJ9t/kvyQH+bn1sdeVLxwsJcPLF07U3pXTJy+n9+TGF1siSCBzhOWz3sERVwgYT5V44HmTT8TVeNzllnisuQiTDXSiVnAGH7V/98Lgw/V189S9SW7vgOJsuBbqzhIUsakup3LZyDOND9OZ2okFo3dMRCHWxxVNFtvJMBFXVWJ24cL1cqpr7DoQCH1xRVQVpKzJVj7e4x5xibb8KO0H772SpxobKfqulwVX6qYpIds4jvChgMxg5MyJucg0y8Ufr3vkqadHH6hQAsxO3Bg4py7yn1A9sW7K1KqmlYP1fNhX4gvEtWvk3M3xPwkP0GcmVUg30bGg6DynNZSHOIa3Sl1mkThAKIOxZ0mMU/LF8SCp9kTwmw17yiw91M73QVRXems+zqbtkdRBefHnRrmkQir1RZ2ttilMltQTTAagTgw3sGJULbZUz8aipFHZxSbmBdijNWbaBOlNuOblKypTItnek9QVKRCVCQKVhhjQdEqCtw3NpyF3o97Lag2tLcKf/GbEuugDtOmkszF Dn9At/lm tsuIf0MvNHKwJ5mqp5/18TqbDYCXbmIqcvTvKZWOQXAPmoWVwGUH3XZuQoJ+PYZhm94u3brRF1AzNQPLvHDGrLz5iATPsqTV7HuQ7Zqql8avvAHojEM2xFVN1ehxZg2PTdLfCW8OFvYIBLywMinhIN4teCZ70Nc5V8T8npp/wjxf5qi/X4TF96d/zDCApNSULWW6jB85hmCrxxTfQIdA41m3ezctQve1bZscOwSsxBxFCyJKSMtPHqQKXjXujNLr/WeP6n1JHT5ri+FUGdfGEDrsbB2MQWonpb+1J8JpPdfr1o8vH87EOUu4lL+scJJyG/A1yd1XySWxvh7faMp6Mce6mqrqgchV3wu6x4eML+pKbA2CrI0Wni0fE5defFA7HuGMP1ssLFexCVzA= 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: Now the folio_isolate_lru() did not return a boolean value to indicate isolation success or not, however below code checking the return value can make people think that it was a boolean success/failure thing, which makes people easy to make mistakes (see the fix patch[1]). if (folio_isolate_lru(folio)) continue; Thus it's better to check the negative error value expilictly returned by folio_isolate_lru(), which makes code more clear per Linus's suggestion[2]. Moreover Matthew suggested we can convert the isolation functions to return a boolean[3], since most users did not care about the negative error value, and can also remove the confusing of checking return value. So this patch converts the folio_isolate_lru() to return a boolean value, which means return 'true' to indicate the folio isolation is successful, and 'false' means a failure to isolation. Meanwhile changing all users' logic of checking the isolation state. No functional changes intended. [1] https://lore.kernel.org/all/20230131063206.28820-1-Kuan-Ying.Lee@mediatek.com/T/#u [2] https://lore.kernel.org/all/CAHk-=wiBrY+O-4=2mrbVyxR+hOqfdJ=Do6xoucfJ9_5az01L4Q@mail.gmail.com/ [3] https://lore.kernel.org/all/Y+sTFqwMNAjDvxw3@casper.infradead.org/ Signed-off-by: Baolin Wang Reviewed-by: SeongJae Park Acked-by: David Hildenbrand Reviewed-by: Matthew Wilcox (Oracle) --- mm/damon/paddr.c | 2 +- mm/folio-compat.c | 8 +++++++- mm/gup.c | 2 +- mm/internal.h | 2 +- mm/khugepaged.c | 2 +- mm/madvise.c | 4 ++-- mm/mempolicy.c | 2 +- mm/vmscan.c | 10 +++++----- 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index b4df9b9bcc0a..607bb69e526c 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -246,7 +246,7 @@ static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s) folio_clear_referenced(folio); folio_test_clear_young(folio); - if (folio_isolate_lru(folio)) { + if (!folio_isolate_lru(folio)) { folio_put(folio); continue; } diff --git a/mm/folio-compat.c b/mm/folio-compat.c index 18c48b557926..540373cf904e 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -115,9 +115,15 @@ EXPORT_SYMBOL(grab_cache_page_write_begin); int isolate_lru_page(struct page *page) { + bool ret; + if (WARN_RATELIMIT(PageTail(page), "trying to isolate tail page")) return -EBUSY; - return folio_isolate_lru((struct folio *)page); + ret = folio_isolate_lru((struct folio *)page); + if (ret) + return 0; + + return -EBUSY; } void putback_lru_page(struct page *page) diff --git a/mm/gup.c b/mm/gup.c index b0885f70579c..eab18ba045db 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1939,7 +1939,7 @@ static unsigned long collect_longterm_unpinnable_pages( drain_allow = false; } - if (folio_isolate_lru(folio)) + if (!folio_isolate_lru(folio)) continue; list_add_tail(&folio->lru, movable_page_list); diff --git a/mm/internal.h b/mm/internal.h index dfb37e94e140..8645e8496537 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -188,7 +188,7 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr, * in mm/vmscan.c: */ int isolate_lru_page(struct page *page); -int folio_isolate_lru(struct folio *folio); +bool folio_isolate_lru(struct folio *folio); void putback_lru_page(struct page *page); void folio_putback_lru(struct folio *folio); extern void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_state reason); diff --git a/mm/khugepaged.c b/mm/khugepaged.c index a5d32231bfad..cee659cfa3c1 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2047,7 +2047,7 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, goto out_unlock; } - if (folio_isolate_lru(folio)) { + if (!folio_isolate_lru(folio)) { result = SCAN_DEL_PAGE_LRU; goto out_unlock; } diff --git a/mm/madvise.c b/mm/madvise.c index 5a5a687d03c2..c2202f51e9dd 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -406,7 +406,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, folio_clear_referenced(folio); folio_test_clear_young(folio); if (pageout) { - if (!folio_isolate_lru(folio)) { + if (folio_isolate_lru(folio)) { if (folio_test_unevictable(folio)) folio_putback_lru(folio); else @@ -500,7 +500,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, folio_clear_referenced(folio); folio_test_clear_young(folio); if (pageout) { - if (!folio_isolate_lru(folio)) { + if (folio_isolate_lru(folio)) { if (folio_test_unevictable(folio)) folio_putback_lru(folio); else diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 0919c7a719d4..2751bc3310fd 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1033,7 +1033,7 @@ static int migrate_folio_add(struct folio *folio, struct list_head *foliolist, * expensive, so check the estimated mapcount of the folio instead. */ if ((flags & MPOL_MF_MOVE_ALL) || folio_estimated_sharers(folio) == 1) { - if (!folio_isolate_lru(folio)) { + if (folio_isolate_lru(folio)) { list_add_tail(&folio->lru, foliolist); node_stat_mod_folio(folio, NR_ISOLATED_ANON + folio_is_file_lru(folio), diff --git a/mm/vmscan.c b/mm/vmscan.c index 34535bbd4fe9..7658b40df947 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2337,12 +2337,12 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, * (2) The lru_lock must not be held. * (3) Interrupts must be enabled. * - * Return: 0 if the folio was removed from an LRU list. - * -EBUSY if the folio was not on an LRU list. + * Return: true if the folio was removed from an LRU list. + * false if the folio was not on an LRU list. */ -int folio_isolate_lru(struct folio *folio) +bool folio_isolate_lru(struct folio *folio) { - int ret = -EBUSY; + bool ret = false; VM_BUG_ON_FOLIO(!folio_ref_count(folio), folio); @@ -2353,7 +2353,7 @@ int folio_isolate_lru(struct folio *folio) lruvec = folio_lruvec_lock_irq(folio); lruvec_del_folio(lruvec, folio); unlock_page_lruvec_irq(lruvec); - ret = 0; + ret = true; } return ret;