From nobody Fri Sep 12 02:51:06 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B226FC64EC7 for ; Tue, 14 Feb 2023 03:18:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231416AbjBNDSf (ORCPT ); Mon, 13 Feb 2023 22:18:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230055AbjBNDSb (ORCPT ); Mon, 13 Feb 2023 22:18:31 -0500 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D261A869C; Mon, 13 Feb 2023 19:18:29 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R331e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0Vbe-fy8_1676344706; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Vbe-fy8_1676344706) by smtp.aliyun-inc.com; Tue, 14 Feb 2023 11:18:27 +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, baolin.wang@linux.alibaba.com, damon@lists.linux.dev, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] mm: check negative error of folio_isolate_lru() when failed to isolate a folio Date: Tue, 14 Feb 2023 11:18:06 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The folio_isolate_lru() will return a negative error if failed to isolate a folio from its LRU list, thus better to check the negative error to make the code more clear per Linus's suggestion[1]. No functional changes. [1] https://lore.kernel.org/all/CAHk-=3DwiBrY+O-4=3D2mrbVyxR+hOqfdJ=3DDo6xo= ucfJ9_5az01L4Q@mail.gmail.com/ Signed-off-by: Baolin Wang --- mm/damon/paddr.c | 2 +- mm/gup.c | 2 +- mm/khugepaged.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index b4df9b9bcc0a..ebf3dd084af2 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -246,7 +246,7 @@ static unsigned long damon_pa_pageout(struct damon_regi= on *r, struct damos *s) =20 folio_clear_referenced(folio); folio_test_clear_young(folio); - if (folio_isolate_lru(folio)) { + if (folio_isolate_lru(folio) < 0) { folio_put(folio); continue; } diff --git a/mm/gup.c b/mm/gup.c index b0885f70579c..7fdddd43663c 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1939,7 +1939,7 @@ static unsigned long collect_longterm_unpinnable_page= s( drain_allow =3D false; } =20 - if (folio_isolate_lru(folio)) + if (folio_isolate_lru(folio) < 0) continue; =20 list_add_tail(&folio->lru, movable_page_list); diff --git a/mm/khugepaged.c b/mm/khugepaged.c index a5d32231bfad..463dfca4b841 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -2047,7 +2047,7 @@ static int collapse_file(struct mm_struct *mm, unsign= ed long addr, goto out_unlock; } =20 - if (folio_isolate_lru(folio)) { + if (folio_isolate_lru(folio) < 0) { result =3D SCAN_DEL_PAGE_LRU; goto out_unlock; } --=20 2.27.0 From nobody Fri Sep 12 02:51:06 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0F72C636CC for ; Tue, 14 Feb 2023 03:18:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231467AbjBNDSl (ORCPT ); Mon, 13 Feb 2023 22:18:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231398AbjBNDSd (ORCPT ); Mon, 13 Feb 2023 22:18:33 -0500 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4EEE12587; Mon, 13 Feb 2023 19:18:32 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R851e4;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=13;SR=0;TI=SMTPD_---0VbdtbCV_1676344707; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VbdtbCV_1676344707) by smtp.aliyun-inc.com; Tue, 14 Feb 2023 11:18:27 +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, baolin.wang@linux.alibaba.com, damon@lists.linux.dev, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm: check negative error of isolate_lru_page() when failed to isolate a page Date: Tue, 14 Feb 2023 11:18:07 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Better to check the negative error of isolate_lru_page() when failed to isolate a page from its LRU, which makes the code more clear. No functional changes. Signed-off-by: Baolin Wang --- mm/khugepaged.c | 2 +- mm/memcontrol.c | 2 +- mm/migrate.c | 4 ++-- mm/migrate_device.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 463dfca4b841..99a2d993b51c 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) < 0) { unlock_page(page); result =3D SCAN_DEL_PAGE_LRU; goto out; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 17335459d8dc..33cad66a4132 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6226,7 +6226,7 @@ static int mem_cgroup_move_charge_pte_range(pmd_t *pm= d, */ if (PageTransCompound(page)) goto put; - if (!device && isolate_lru_page(page)) + if (!device && isolate_lru_page(page) < 0) goto put; if (!mem_cgroup_move_account(page, false, mc.from, mc.to)) { diff --git a/mm/migrate.c b/mm/migrate.c index ef68a1aff35c..eaae39564f86 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2135,7 +2135,7 @@ static int add_page_for_migration(struct mm_struct *m= m, unsigned long addr, =20 head =3D compound_head(page); err =3D isolate_lru_page(head); - if (err) + if (err < 0) goto out_putpage; =20 err =3D 1; @@ -2541,7 +2541,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat,= struct page *page) return 0; } =20 - if (isolate_lru_page(page)) + if (isolate_lru_page(page) < 0) return 0; =20 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..1ab56b5b7914 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 =3D false; } =20 - if (isolate_lru_page(page)) { + if (isolate_lru_page(page) < 0) { src_pfns[i] &=3D ~MIGRATE_PFN_MIGRATE; restore++; continue; --=20 2.27.0 From nobody Fri Sep 12 02:51:06 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1B42C636CC for ; Tue, 14 Feb 2023 03:18:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230089AbjBNDSh (ORCPT ); Mon, 13 Feb 2023 22:18:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231381AbjBNDSc (ORCPT ); Mon, 13 Feb 2023 22:18:32 -0500 Received: from out30-97.freemail.mail.aliyun.com (out30-97.freemail.mail.aliyun.com [115.124.30.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C783D4694; Mon, 13 Feb 2023 19:18:31 -0800 (PST) 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=ay29a033018045192;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---0VbdtbCo_1676344708; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VbdtbCo_1676344708) by smtp.aliyun-inc.com; Tue, 14 Feb 2023 11:18:28 +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, baolin.wang@linux.alibaba.com, damon@lists.linux.dev, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] mm: mempolicy: check negative error of isolate_hugetlb() when failed to isolate a hugetlb Date: Tue, 14 Feb 2023 11:18:08 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Better to check the negative error of isolate_hugetlb() when failed to isolate a hugetlb page, which makes the code more clear. No functional changes. Signed-off-by: Baolin Wang --- mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 0919c7a719d4..e3d87b21516b 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -609,7 +609,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned lo= ng hmask, if (flags & (MPOL_MF_MOVE_ALL) || (flags & MPOL_MF_MOVE && folio_estimated_sharers(folio) =3D=3D 1 && !hugetlb_pmd_shared(pte))) { - if (isolate_hugetlb(folio, qp->pagelist) && + if (isolate_hugetlb(folio, qp->pagelist) < 0 && (flags & MPOL_MF_STRICT)) /* * Failed to isolate folio but allow migrating pages --=20 2.27.0