From patchwork Tue Feb 14 13:59:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13140176 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 DAF97C05027 for ; Tue, 14 Feb 2023 13:59:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBE496B0074; Tue, 14 Feb 2023 08:59:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C94C16B007B; Tue, 14 Feb 2023 08:59:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B5BDE6B0075; Tue, 14 Feb 2023 08:59:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 97C246B0074 for ; Tue, 14 Feb 2023 08:59:49 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 65F5D40E6F for ; Tue, 14 Feb 2023 13:59:49 +0000 (UTC) X-FDA: 80466055698.06.5522D08 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by imf25.hostedemail.com (Postfix) with ESMTP id E26E1A0016 for ; Tue, 14 Feb 2023 13:59:45 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf25.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.101 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=1676383187; 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=rnPWLtdBtYpQIQtLw48u5NxM3aYMB7bUn7hnam1xGxg=; b=G9t7cwFNiHqrZuY9wyLu1h/++rf+Py1Ly61R2WeVZEXpLpctSe3hn1dx/yvIenTwonL7dY rNsAg+FlrIjFbkgrvz2f76pX+9GVOCDtvXoPpg+mQ1QsYZkWRELQSmbpidsZuMUhrco2n5 VjPI692EFqDjUD+XdXO6emZ0PXZ9SCw= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf25.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.101 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676383187; a=rsa-sha256; cv=none; b=dQMHPGzX3n9aqwDWMUzvBOXVre7nmZ+dUQrQ0BsFzbu4c8ZeQb1pe456ULFwzD6J5INFwC 3XVUnorgr7PKH5M9cJI1HLkUYvtXxw6WXFjPcT5flWUXyJvQrXPGBmAtbR9dpSj4OCjezR UyyWc4mmVwOkhJkAYxlj8k4N1DwwUFs= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0VbgTJ0s_1676383180; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VbgTJ0s_1676383180) by smtp.aliyun-inc.com; Tue, 14 Feb 2023 21:59:40 +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 v2 1/4] mm: change to return bool for folio_isolate_lru() Date: Tue, 14 Feb 2023 21:59:29 +0800 Message-Id: <7abe2897803410fdc8f167b46bb5b0467de0e3c9.1676382188.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: E26E1A0016 X-Stat-Signature: 578cmzc891s5zwede9oti4k4zig78si6 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1676383185-963047 X-HE-Meta: U2FsdGVkX1/w6LqMglAI9Gs76pBDheILHKTgSTSoiw0CeqXZejcHzifr7yfYJtGhk5X7vLeILktWBd1jE7kUmqds93Fk1w7KruzUmoXOh5gTaJ8YKbDUxyb40rEOYvyU+9G+UtkmDRdWPJKHMATFMDHqUMitSmDmLBmplzvVJocPcJD6xBACGNl9dnT0O5ewOkgzgWp+QLIVQalTr56LiAjGpZG3lochbM2y2i8PtY2XGz5eCsvjJrazOWX4PTKQ0Vts4zE2vueT5ba953hQ09cBVDoyXr1WP9eEOWpDohrYZibwaWQYO/5qQg2Bvr+pns4e3rq+GieKCiHMvcM/l9H7f7U7ywdJmHM2NoHQMZZ0J/6GXC/TJpr0k2VU8sSDUEYaYnRa7PnUj5jmLMc/PtiwGQoyGFDBaJwjWElyXG1tnR/Aic0M+DtLI3d492s9exPiSB/sakBPCzm4A+kjpYWVClYkPXOaupV5mPhF5SrtgsQR4l0kFjjnZU5CbIkEECcw53tq0+mxWTTTLtEqMQoUXJY3W+BTGaHDkvbTSni92ZRfG7A6Xv5NjDlbtw/b7KcEifTWbfRUVNSe8q7iPxC3hzDiuQRbksULd2kkYjXCADzpwdjV6JLuQTr3LMEeB5AGMT6/gsA8a9FyzJ9Zv7yXKrHsXur50mWb0rn5nkEzmC43IXkQips8r6chR/mT2G27WZ+efINixHdDJ87JpmSEyzjInMxzw8M6sx1iVXYt8uD6AsZBhUQiM3zSveOtyGtjR2AvKUR+IRvMhO+fFVgZDcpfUbIfK6Owj5/niTFr60373B9uzgBrKq1LGGrjmL9rU+lSfEkGVh6WAGQiDxKRlYtmrGM7+E6jbafGByQo9PF9qkurgOIjsow28rNX9ej6nZfkHA296FoSyirHIXkTMY24OIw/F5HMmsCql0HHeO/P7G9MggY8sSCQEQ4TBYsxtXHKT55FhmjCrln OI/VcMbX e+YjLApkUPa3MUsL051JD/C7/AWvq6KrvwYXnX8o2XlccWYYKUDbOtkgssTfe83guIL2xxiSAR7Mm+Qo2QOjsNBfDb384eIcvl2P9f9CvlsfwUXY8ep/aBTiZM/hLqjTXE+nZI9HQ/N1jfKR/gy1ODO/cRiV73YT2k18wYkeAcWGv2h4jldT+4ajAyxGHjKJd6GxZdLeSx6C6KXIL2CGEQiKTlbSSxdff6fXwkFbZRLaX58EIPrRusMs29chRVsp5oQdTsdUQEZ8PDnCAgg7j0dIESqR0z2G+TNMyr2UqOezGrFTyAhTFypnWUZHx+XFK0hJ8D8kuBmoaspUwD7/kWgt27crlQ4bJ6p5S79qM2eKgSdY= 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 --- 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; From patchwork Tue Feb 14 13:59:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13140177 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 5EED8C6379F for ; Tue, 14 Feb 2023 13:59:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2F286B0073; Tue, 14 Feb 2023 08:59:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F056A6B0075; Tue, 14 Feb 2023 08:59:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D7EBA6B007D; Tue, 14 Feb 2023 08:59:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BCAEA6B0073 for ; Tue, 14 Feb 2023 08:59:49 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9C20D160858 for ; Tue, 14 Feb 2023 13:59:49 +0000 (UTC) X-FDA: 80466055698.07.F589CAA Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by imf16.hostedemail.com (Postfix) with ESMTP id 6CB1018000F for ; Tue, 14 Feb 2023 13:59:46 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.101 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676383188; 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=f5+plW8QmHBpok1iycf64Rs+0aWZUBtZGTMoNSmdslE=; b=putjE/yjKi8Gh2FjdC5qJmWNVmoX53MgVn98NWnWoeiWd+KjLmPeM92OzHd+KzLsjOJ2J+ 4g5WIj7bI8wXEQZBGUOlyatO6LBgxYYPWgbi3LgPCdf33jb/7YcjGxLLsAgJ027lS5T5W3 p2RAUfE0m17LgQNtsCddKGWgf2ZOnKE= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.101 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676383188; a=rsa-sha256; cv=none; b=hFBCjR5Sa/bFUUmc95pVydw6lcpbRhu+kaXKEYHzZgJkYBw4QnKHsB955YaDYXdYDmBION bswGq6UW73P0fHiQWodGnfUMc+Xtajt008PYZoQ//svPds6TUMLj3kG/3c7Zhgv55XHMla 58LIcNlUNBnTp8d8LeOuHYUD6YRxk2Y= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0VbgLy-t_1676383181; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VbgLy-t_1676383181) by smtp.aliyun-inc.com; Tue, 14 Feb 2023 21:59:41 +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 v2 2/4] mm: change to return bool for isolate_lru_page() Date: Tue, 14 Feb 2023 21:59:30 +0800 Message-Id: <3635a17b9a0cf4be011a886415bf620b1c682ff6.1676382188.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-Stat-Signature: buqqizz7uh7mwfy6jdhuzwxqm6c75drk X-Rspam-User: X-Rspamd-Queue-Id: 6CB1018000F X-Rspamd-Server: rspam06 X-HE-Tag: 1676383186-575988 X-HE-Meta: U2FsdGVkX1+7WGDfn6POgIDQxCGGnR2dbViYKqIjhayb2EdQiNKX6LnMRiUpal8ouF1751NzhER2yv1ld3kBLQ+sajLRHoYGLpxvfAO2kyQzGrnN+l099dJH5m1Im5wzE/TdvTzHhXEaFHWVWWezMLFlyYqDxvB2yVQrl/qr674ctJPbEJqqtc84f8mxTb6JVfQZbZUiV7hQQnb54WZ+CZp/xhEp/l3KO5g8qju/qPfSomvq+iy+8hrGwxuzg+SKLLic7T9bCUC2FkAqV8M7rUznQnkR5EZ/p+2PM96qfHAnNyFHsPFUynRQq57PrX842w+Uygk+vNC9VGzhIR/U2lYm/ZLkTF4BMxTiQeXKBzol318vd08qNzjlLWXPfpGe0zTRmXJLZanj8xbZ/RBb/9lII3HYlUSPjadEk7sXsNadAAMAS4nljYIrf0tKqYIkoilBlvioCjgtItPHSfTRInXn79g2VjypNZwtP7PeWInA1RqIi7rc6gEbP2/yVCedS6R4mZWxZ9N0IqFBt1p2mnXeYnqBql2Pi/vhO//hw+vam8g5luuuEZlt9JFDXj04R5INxBJIMLsBsdHyiJ1dzjFc+t3Vzcpqwa8lV8zmhJ6ze/18IqusB04HsziCdwG833xLVf5aKazZOeHignmwXYXwt49Rk/1zoOHXlTBvg//4ndA8QPTuygXxUGq6dS98i4slcKFtunL1emDR8+/SKCM3qF81qBgOBf+ivJQ8h7kN8ukFkD0G8mph/6Rzs5LOBJ5WjPipi6hkK9+feNU/yZCLsMgMImByN5VT/oahBkACy95RZQcU1Uqneru67NpoFM1hbrXvwU//xn7E4AfiBzQXmuUE6b4evAyH+aqI0zQ2Cv8CVQU2x41sxgUjQO4kG/c73fuT4nbVBPndTp2Jkt8uzslvFnLrWihRUW5JkLSjDnV4TYbgrF6btSec8IMX5fgyHzJ0tE0dCdXdp8V BTKPProw Xc++lyRQYnyv4JLYfqgLhxxDVIFTwniUwnV8hXxqq7qPgJTxu6PSIuTDwtwvCdJd/rPtJa2hlMmZQKgaGJon9gPucuWuIlF7le7sslvn1HOBBrNfAXKehzpQzYyeacvBBioPmN2qH+hDzT/WZqFQAvUVux/7tEgXoZpsz 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: The isolate_lru_page() can only return 0 or -EBUSY, and most users did not care about the negative error of isolate_lru_page(), except one user in add_page_for_migration(). So we can convert the isolate_lru_page() to return a boolean value, which can help to make the code more clear when checking the return value of isolate_lru_page(). Also convert all users' logic of checking the isolation state. No functional changes intended. Signed-off-by: Baolin Wang --- mm/folio-compat.c | 12 +++--------- mm/internal.h | 2 +- mm/khugepaged.c | 2 +- mm/memcontrol.c | 4 ++-- mm/memory-failure.c | 4 ++-- mm/memory_hotplug.c | 2 +- mm/migrate.c | 9 ++++++--- mm/migrate_device.c | 2 +- 8 files changed, 17 insertions(+), 20 deletions(-) diff --git a/mm/folio-compat.c b/mm/folio-compat.c index 540373cf904e..cabcd1de9ecb 100644 --- a/mm/folio-compat.c +++ b/mm/folio-compat.c @@ -113,17 +113,11 @@ struct page *grab_cache_page_write_begin(struct address_space *mapping, } EXPORT_SYMBOL(grab_cache_page_write_begin); -int isolate_lru_page(struct page *page) +bool isolate_lru_page(struct page *page) { - bool ret; - if (WARN_RATELIMIT(PageTail(page), "trying to isolate tail page")) - return -EBUSY; - ret = folio_isolate_lru((struct folio *)page); - if (ret) - return 0; - - return -EBUSY; + return false; + return folio_isolate_lru((struct folio *)page); } void putback_lru_page(struct page *page) diff --git a/mm/internal.h b/mm/internal.h index 8645e8496537..fc01fd092ea5 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -187,7 +187,7 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr, /* * in mm/vmscan.c: */ -int isolate_lru_page(struct page *page); +bool isolate_lru_page(struct page *page); bool folio_isolate_lru(struct folio *folio); void putback_lru_page(struct page *page); void folio_putback_lru(struct folio *folio); diff --git a/mm/khugepaged.c b/mm/khugepaged.c index cee659cfa3c1..8dbc39896811 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -659,7 +659,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, * Isolate the page to avoid collapsing an hugepage * currently in use by the VM. */ - if (isolate_lru_page(page)) { + if (!isolate_lru_page(page)) { unlock_page(page); result = SCAN_DEL_PAGE_LRU; goto out; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 17335459d8dc..e8fd42be5fab 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6176,7 +6176,7 @@ static int mem_cgroup_move_charge_pte_range(pmd_t *pmd, target_type = get_mctgt_type_thp(vma, addr, *pmd, &target); if (target_type == MC_TARGET_PAGE) { page = target.page; - if (!isolate_lru_page(page)) { + if (isolate_lru_page(page)) { if (!mem_cgroup_move_account(page, true, mc.from, mc.to)) { mc.precharge -= HPAGE_PMD_NR; @@ -6226,7 +6226,7 @@ static int mem_cgroup_move_charge_pte_range(pmd_t *pmd, */ if (PageTransCompound(page)) goto put; - if (!device && isolate_lru_page(page)) + if (!device && !isolate_lru_page(page)) goto put; if (!mem_cgroup_move_account(page, false, mc.from, mc.to)) { diff --git a/mm/memory-failure.c b/mm/memory-failure.c index db85c2d37f70..e504362fdb23 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -846,7 +846,7 @@ static const char * const action_page_types[] = { */ static int delete_from_lru_cache(struct page *p) { - if (!isolate_lru_page(p)) { + if (isolate_lru_page(p)) { /* * Clear sensible page flags, so that the buddy system won't * complain when the page is unpoison-and-freed. @@ -2513,7 +2513,7 @@ static bool isolate_page(struct page *page, struct list_head *pagelist) bool lru = !__PageMovable(page); if (lru) - isolated = !isolate_lru_page(page); + isolated = isolate_lru_page(page); else isolated = !isolate_movable_page(page, ISOLATE_UNEVICTABLE); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index a1e8c3e9ab08..17ed80707518 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1668,7 +1668,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) * LRU and non-lru movable pages. */ if (PageLRU(page)) - ret = isolate_lru_page(page); + ret = !isolate_lru_page(page); else ret = isolate_movable_page(page, ISOLATE_UNEVICTABLE); if (!ret) { /* Success */ diff --git a/mm/migrate.c b/mm/migrate.c index ef68a1aff35c..53010a142e7f 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2132,11 +2132,14 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, } } else { struct page *head; + bool isolated; head = compound_head(page); - err = isolate_lru_page(head); - if (err) + isolated = isolate_lru_page(head); + if (!isolated) { + err = -EBUSY; goto out_putpage; + } err = 1; list_add_tail(&head->lru, pagelist); @@ -2541,7 +2544,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) return 0; } - if (isolate_lru_page(page)) + if (!isolate_lru_page(page)) return 0; mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + page_is_file_lru(page), diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 6c3740318a98..d30c9de60b0d 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -388,7 +388,7 @@ static unsigned long migrate_device_unmap(unsigned long *src_pfns, allow_drain = false; } - if (isolate_lru_page(page)) { + if (!isolate_lru_page(page)) { src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; restore++; continue; From patchwork Tue Feb 14 13:59:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13140178 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 E84ABC05027 for ; Tue, 14 Feb 2023 13:59:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56C426B0075; Tue, 14 Feb 2023 08:59:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CCD76B007B; Tue, 14 Feb 2023 08:59:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 393BA6B007D; Tue, 14 Feb 2023 08:59:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 21E1D6B007B for ; Tue, 14 Feb 2023 08:59:50 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id F3617C0A81 for ; Tue, 14 Feb 2023 13:59:49 +0000 (UTC) X-FDA: 80466055698.02.3A6BAA2 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) by imf01.hostedemail.com (Postfix) with ESMTP id E3AB44000A for ; Tue, 14 Feb 2023 13:59:47 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.118 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676383188; a=rsa-sha256; cv=none; b=wMbE7aSAvDXZkBucrRHtlgmtx8qSwWm4LFO6NiO858fspADso9N2h1RgCuRaz4kG1tjdN5 Va1htHrNgdtUuWjlmDHj9mwWKm3IFlsutl0UlqD6YUPbQxDIwqm+Vb1+xgspK/nCRpMlIu fiL1zdbW4qt3KM7ZcaYnyYmLXn+KVno= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.118 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676383188; 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=tavTW6mS6LWW8vN024hVsoRg4fwkLBzVbpZuJzXonoI=; b=1i8xIX6vLQ39TRjUfhz+AQVPnucEBh/CZ2RAFSnamMtb9T7XZ5omFKjohf47w31rC/k/gg /loSnMJO0zG1yRaZnXW00gXqQu423uTi/Gv/0lKROF1Ii04E8EwzquizHnILsdlSJaIKPp kdUzjPOpuAH7Im0thW3uhRAUI2Sqe4M= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R531e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0VbgLy.7_1676383182; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VbgLy.7_1676383182) by smtp.aliyun-inc.com; Tue, 14 Feb 2023 21:59:43 +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 v2 3/4] mm: hugetlb: change to return bool for isolate_hugetlb() Date: Tue, 14 Feb 2023 21:59:31 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: E3AB44000A X-Rspamd-Server: rspam01 X-Stat-Signature: odyzzfxj8p9skyg39wzdarxiapknzg5r X-HE-Tag: 1676383187-38362 X-HE-Meta: U2FsdGVkX19dF74LM6dAag2wzRDG/08n3DN8eFwj12HlaY2llJsMh7BjcAwIG0fqYDWgkyUzt/yt32ROuW1C7iu0MyreVOFyCSEVwO7FAH8XkcvIeZYUBhBZt8DxfcwAX2ads1Jy1o9bF9UCBV0jdVNTOMzBplPjznChHKwuRsXsOffP07EBOfFU8VgVHLzlpFdJDYRhJd49aYsRT0/MyZhKT0yvGot3fFAJ1t5X7Y3qxX504Y5p3VY1yMlzkF7el0+USLsvsQl/maGvmbS5uwIyUqmH+9iJyw0gldRegb2rd3CqfzqkNtIxiu0SMG3dOMp8e5QTapYQWSftY3M/q8Z1Or6mq0mbb83EAhDNDTuW8mJGz6rFPNFlU7s9MSR92CAQmkpUo+69wtgYAoIU1XcIDiZDBB3iEpEi4iDPBGw5fLSCVGRsL0vPcpD7LBMdbQUgy6oxcvGIil0D+I5B/y0TcLty9oEUrz9hXbalwk3ErIkJKbDr334Yz9dLxOkuYNwQtSvxCbxTYKNYUSFFibCvTDxRzYQvfrWuBCACNMuCinq5bFxPrpB/f/cetqepeeapCWhDRGAsYE8h/m0YFP02LLgXvGmr913yftjFWvK+w2QD1IPIHVD9V62K8uPLobTLEFOLXXWguLDzgz6JXN0Q7HSNzI39IVQ3yo/30CkCCRpOQcSRcnOH7bLpTf17c0JwH8lkCtUjB0ySv/+T0fAeHVqRQU4GeI3egtZyoOuRtnH7A8DTpoExMStz/X+SVRWaoBLriHtyX1sfFYDYBusOQqMszL97QlOXRcR0A8Sl2HSBbi5o6LPfcEvGj85Cm30F58J/S0BDuenH1hr/kzTTZbdb7SFFfEx0mPFJq+A1xrW+Ryrnf5tYIycK+LwfbOKDp0qlwEWIfz4ZUZcw/leWh3C/N9md55XLn3CumbgB8h0YIsb6KYGyE1cxJDm8kaG1WPudvubjWiLtoTa H/oqrbJV oeGzpW/DyPy/r6XmccijqfXg3NB25caedyA9lVMLbL6U4Gaa+zVXojeiVAdeAliHonlEDcmimSK9o7GVhFQoteocOWiOEY/xWpOPgzY3X4kUysN19E1y4jqAT0glTDDcDnARa3ukI0fLsPZtEXOzoeFecxBR7KNFIRMZ739+JizyE+DTQn1MUCCTlz4DAGhSHa1HpeSN0+PYjJh7lwO8SVbZTDWjXFQxWgMOd9eZaDxB5RF4VBXUktdaP+nx3m9nGsqMV 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 isolate_hugetlb() only returns 0 or -EBUSY, and most users did not care about the negative value, thus we can convert the isolate_hugetlb() to return a boolean value to make code more clear when checking the hugetlb isolation state. Moreover converts 2 users which will consider the negative value returned by isolate_hugetlb(). No functional changes intended. Signed-off-by: Baolin Wang --- include/linux/hugetlb.h | 6 +++--- mm/hugetlb.c | 12 ++++++++---- mm/memory-failure.c | 2 +- mm/mempolicy.c | 2 +- mm/migrate.c | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index df6dd624ccfe..5f5e4177b2e0 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -171,7 +171,7 @@ bool hugetlb_reserve_pages(struct inode *inode, long from, long to, vm_flags_t vm_flags); long hugetlb_unreserve_pages(struct inode *inode, long start, long end, long freed); -int isolate_hugetlb(struct folio *folio, struct list_head *list); +bool isolate_hugetlb(struct folio *folio, struct list_head *list); int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison); int get_huge_page_for_hwpoison(unsigned long pfn, int flags, bool *migratable_cleared); @@ -413,9 +413,9 @@ static inline pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr, return NULL; } -static inline int isolate_hugetlb(struct folio *folio, struct list_head *list) +static inline bool isolate_hugetlb(struct folio *folio, struct list_head *list) { - return -EBUSY; + return false; } static inline int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool unpoison) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 3a01a9dbf445..75097e3abc18 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2932,6 +2932,10 @@ static int alloc_and_dissolve_hugetlb_folio(struct hstate *h, spin_unlock_irq(&hugetlb_lock); ret = isolate_hugetlb(old_folio, list); spin_lock_irq(&hugetlb_lock); + if (!ret) + ret = -EBUSY; + else + ret = 0; goto free_new; } else if (!folio_test_hugetlb_freed(old_folio)) { /* @@ -3005,7 +3009,7 @@ int isolate_or_dissolve_huge_page(struct page *page, struct list_head *list) if (hstate_is_gigantic(h)) return -ENOMEM; - if (folio_ref_count(folio) && !isolate_hugetlb(folio, list)) + if (folio_ref_count(folio) && isolate_hugetlb(folio, list)) ret = 0; else if (!folio_ref_count(folio)) ret = alloc_and_dissolve_hugetlb_folio(h, folio, list); @@ -7251,15 +7255,15 @@ __weak unsigned long hugetlb_mask_last_page(struct hstate *h) * These functions are overwritable if your architecture needs its own * behavior. */ -int isolate_hugetlb(struct folio *folio, struct list_head *list) +bool isolate_hugetlb(struct folio *folio, struct list_head *list) { - int ret = 0; + bool ret = true; spin_lock_irq(&hugetlb_lock); if (!folio_test_hugetlb(folio) || !folio_test_hugetlb_migratable(folio) || !folio_try_get(folio)) { - ret = -EBUSY; + ret = false; goto unlock; } folio_clear_hugetlb_migratable(folio); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index e504362fdb23..8604753bc644 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2508,7 +2508,7 @@ static bool isolate_page(struct page *page, struct list_head *pagelist) bool isolated = false; if (PageHuge(page)) { - isolated = !isolate_hugetlb(page_folio(page), pagelist); + isolated = isolate_hugetlb(page_folio(page), pagelist); } else { bool lru = !__PageMovable(page); diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 2751bc3310fd..a256a241fd1d 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -609,7 +609,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned long hmask, if (flags & (MPOL_MF_MOVE_ALL) || (flags & MPOL_MF_MOVE && folio_estimated_sharers(folio) == 1 && !hugetlb_pmd_shared(pte))) { - if (isolate_hugetlb(folio, qp->pagelist) && + if (!isolate_hugetlb(folio, qp->pagelist) && (flags & MPOL_MF_STRICT)) /* * Failed to isolate folio but allow migrating pages diff --git a/mm/migrate.c b/mm/migrate.c index 53010a142e7f..c5136fa48638 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2128,7 +2128,7 @@ static int add_page_for_migration(struct mm_struct *mm, unsigned long addr, if (PageHead(page)) { err = isolate_hugetlb(page_folio(page), pagelist); if (!err) - err = 1; + err = -EBUSY; } } else { struct page *head; From patchwork Tue Feb 14 13:59:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13140179 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 C5A0CC64ED6 for ; Tue, 14 Feb 2023 13:59:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14C7B6B007B; Tue, 14 Feb 2023 08:59:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D5976B007D; Tue, 14 Feb 2023 08:59:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE0A46B007E; Tue, 14 Feb 2023 08:59:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DBB5F6B007B for ; Tue, 14 Feb 2023 08:59:54 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 532D040DFB for ; Tue, 14 Feb 2023 13:59:54 +0000 (UTC) X-FDA: 80466055908.23.B3684A8 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by imf14.hostedemail.com (Postfix) with ESMTP id 9928A100015 for ; Tue, 14 Feb 2023 13:59:51 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.101 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=1676383192; 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=ERYW5/aezTXNO1pqffZ8S7kC9G8bfbzOznEWZRFlSUI=; b=xlx/K5d69CSLX04LLos7GVfe12xUExYqStuCnmQCzVFXQwy6TFSqE7u1e6qAl1YlwEtNVc f4DZ/JSQCUS/cuGKzeLFaffK6UI4WI41r0LDE3M5VOYL/T/UaZs0PSJ+2d0uM0LaqmCDVP wcAzLFjPO6TPwm0MEkqfNG/q70RWAy8= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf14.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.101 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676383192; a=rsa-sha256; cv=none; b=w4q8jMSXJdgnpi8X8ChWUUq9cBSeeADIAhZZMi8jNkdH00BcQ6mamLppItveCrB+VYCXca m1P3VMU2KlHDVjRnwdscciM/zUfF9UZ2Kl97071/NNUOdkv8Odxty5av3LBxNPeaAWz7v8 qJq23qul9weASktunH0c4JBCey6H3gQ= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R691e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0VbgTJ1R_1676383183; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VbgTJ1R_1676383183) by smtp.aliyun-inc.com; Tue, 14 Feb 2023 21:59:44 +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 v2 4/4] mm: change to return bool for isolate_movable_page() Date: Tue, 14 Feb 2023 21:59:32 +0800 Message-Id: <57406039579e764fb6002648699d4896da56ba4a.1676382188.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: 9928A100015 X-Stat-Signature: fwnpsktxaxht9pa1giymztehs6wro7oj X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1676383191-340149 X-HE-Meta: U2FsdGVkX19yBYSl+cXiIjlGMw+Y374abkZKqICRUxY8LZs/7JyOBCKLcxUJ7nCkpkKRP923HIOe0Thf1wJ3UDSGc5x+oi4lXghB62J8uJTiFgtiDvpynUbnNUxVjs2RkEaj49G66pLvP+k0dJvj3XZ6t90nfNAxj6Kgl/0kCSU5kq1g7P9lo+5Z2GVbpxtzznHATgiOfB91FYfzBGEVp+OxH52ZDgptJiVQjEQO1aUkTgPFhHw1FSt51NHihY30owEa+/7JQ17NPQWxt5DFaGN3WVgHv3l7XH0ES0ePJ2UkQqu3Ja+X/8os5erNwaTJtkQDlaoRau3IJRzslwUzGxRagvMEb744K4cDHjWFIi1Mt8irL6PZdsZ6AGc3pQ3heRrfPibu2dGGgq/UPxsOwIaoNlFlA7T/xvcszbrFuVFrxUE+Dc2oZ+YNhV8Fl+2JupQEYY+9taZbU3heU4+MZz4c536165fNrgE4jd9kpbepdBRE3Fhz6BKc79qMLKMFFu0ZRZH0vJQgUtlNHse1P+UpujuoFZx7TVYGs4eACt1rUCEUKqa2khcnhjj1Aku1gbFZLF1A7yAqaX/ly4sz1o+DAX1v6SUdErBhDXi9immCLZSRUa7w2r7hfFPShdeOlpQ59JXYnbOxdz6eVJaqJ0nq3h/z7+GTvzGKg2tjQ65p8pJhou1fHodxF4KiqscJaulh16XA/E3CvwhdnXVpmcjvDqtRrv1/GY2fCWHUwIQsN7kGY1JVK15L56HqBrvlHp1VAPyzC34e8Q0jnAGb0hVk3/V61iw3hQnXpRLGyOCV3U87rg6chCExr10Ls3GmDoIybHsHy6cR2xfNDRDW2WHO14cXJ7UOIEMfqp1vmuqi9nEyvudB78ydv2EgSO4BXn+azdOGJcBn8SWsZaXJ/C4XQhoZPKQozcRydAuA5IVfwRCfD3oV9TiZNt+KoRRQJndxX1PHX8Gp4c8GhUs rpJFcPfI 4AgSHpe2iYrrHCTCyzMlV088IdQBfOOpzyVAHhQf/ZxeMoRxzTqbyVlYcmultjzz0TsrApa2gS/BBOILH/BdK7CWynU1UMAvnS4kOzUsAS1UBqNjYIaPV/CClyQf7lU4NrpaFA0/MeHntmSX7Wtf82rJf53eUegfN/HNq 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 isolate_movable_page() can only return 0 or -EBUSY, and no users will care about the negative return value, thus we can convert the isolate_movable_page() to return a boolean value to make the code more clear when checking the movable page isolation state. No functional changes intended. Signed-off-by: Baolin Wang --- include/linux/migrate.h | 6 +++--- mm/compaction.c | 2 +- mm/memory-failure.c | 4 ++-- mm/memory_hotplug.c | 4 ++-- mm/migrate.c | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index c88b96b48be7..6b252f519c86 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -71,7 +71,7 @@ extern int migrate_pages(struct list_head *l, new_page_t new, free_page_t free, unsigned long private, enum migrate_mode mode, int reason, unsigned int *ret_succeeded); extern struct page *alloc_migration_target(struct page *page, unsigned long private); -extern int isolate_movable_page(struct page *page, isolate_mode_t mode); +extern bool isolate_movable_page(struct page *page, isolate_mode_t mode); int migrate_huge_page_move_mapping(struct address_space *mapping, struct folio *dst, struct folio *src); @@ -92,8 +92,8 @@ static inline int migrate_pages(struct list_head *l, new_page_t new, static inline struct page *alloc_migration_target(struct page *page, unsigned long private) { return NULL; } -static inline int isolate_movable_page(struct page *page, isolate_mode_t mode) - { return -EBUSY; } +static inline bool isolate_movable_page(struct page *page, isolate_mode_t mode) + { return false; } static inline int migrate_huge_page_move_mapping(struct address_space *mapping, struct folio *dst, struct folio *src) diff --git a/mm/compaction.c b/mm/compaction.c index d73578af44cc..ad7409f70519 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -976,7 +976,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, locked = NULL; } - if (!isolate_movable_page(page, mode)) + if (isolate_movable_page(page, mode)) goto isolate_success; } diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 8604753bc644..a1ede7bdce95 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2515,8 +2515,8 @@ static bool isolate_page(struct page *page, struct list_head *pagelist) if (lru) isolated = isolate_lru_page(page); else - isolated = !isolate_movable_page(page, - ISOLATE_UNEVICTABLE); + isolated = isolate_movable_page(page, + ISOLATE_UNEVICTABLE); if (isolated) { list_add(&page->lru, pagelist); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 17ed80707518..e54c4aa69636 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1668,10 +1668,10 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) * LRU and non-lru movable pages. */ if (PageLRU(page)) - ret = !isolate_lru_page(page); + ret = isolate_lru_page(page); else ret = isolate_movable_page(page, ISOLATE_UNEVICTABLE); - if (!ret) { /* Success */ + if (ret) { /* Success */ list_add_tail(&page->lru, &source); if (!__PageMovable(page)) inc_node_page_state(page, NR_ISOLATED_ANON + diff --git a/mm/migrate.c b/mm/migrate.c index c5136fa48638..b7982aa745b0 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -58,7 +58,7 @@ #include "internal.h" -int isolate_movable_page(struct page *page, isolate_mode_t mode) +bool isolate_movable_page(struct page *page, isolate_mode_t mode) { struct folio *folio = folio_get_nontail_page(page); const struct movable_operations *mops; @@ -119,14 +119,14 @@ int isolate_movable_page(struct page *page, isolate_mode_t mode) folio_set_isolated(folio); folio_unlock(folio); - return 0; + return true; out_no_isolated: folio_unlock(folio); out_putfolio: folio_put(folio); out: - return -EBUSY; + return false; } static void putback_movable_folio(struct folio *folio)