From nobody Tue Jun 23 13:09:52 2026 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 B4374C433FE for ; Fri, 4 Mar 2022 09:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237634AbiCDJgC (ORCPT ); Fri, 4 Mar 2022 04:36:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237368AbiCDJfr (ORCPT ); Fri, 4 Mar 2022 04:35:47 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CCAE18886B for ; Fri, 4 Mar 2022 01:35:00 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4K92jH597Xzdb9v; Fri, 4 Mar 2022 17:33:39 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:34:57 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 01/16] mm/migration: remove unneeded local variable mapping_locked Date: Fri, 4 Mar 2022 17:33:54 +0800 Message-ID: <20220304093409.25829-2-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When mapping_locked is true, TTU_RMAP_LOCKED is always set to ttu. We can check ttu instead so mapping_locked can be removed. And ttu is either 0 or TTU_RMAP_LOCKED now. Change '|=3D' to '=3D' to reflect this. Signed-off-by: Miaohe Lin Reviewed-by: Muchun Song --- mm/migrate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 42e3a944f35c..50bc62d85eaf 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1230,7 +1230,6 @@ static int unmap_and_move_huge_page(new_page_t get_ne= w_page, goto put_anon; =20 if (page_mapped(hpage)) { - bool mapping_locked =3D false; enum ttu_flags ttu =3D 0; =20 if (!PageAnon(hpage)) { @@ -1244,14 +1243,13 @@ static int unmap_and_move_huge_page(new_page_t get_= new_page, if (unlikely(!mapping)) goto unlock_put_anon; =20 - mapping_locked =3D true; - ttu |=3D TTU_RMAP_LOCKED; + ttu =3D TTU_RMAP_LOCKED; } =20 try_to_migrate(src, ttu); page_was_mapped =3D 1; =20 - if (mapping_locked) + if (ttu & TTU_RMAP_LOCKED) i_mmap_unlock_write(mapping); } =20 --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 E1B81C433EF for ; Fri, 4 Mar 2022 09:35:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236683AbiCDJf6 (ORCPT ); Fri, 4 Mar 2022 04:35:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237370AbiCDJfr (ORCPT ); Fri, 4 Mar 2022 04:35:47 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10AA918DA8E for ; Fri, 4 Mar 2022 01:35:01 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4K92dN3vG3zbcG9; Fri, 4 Mar 2022 17:30:16 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:34:58 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 02/16] mm/migration: remove unneeded out label Date: Fri, 4 Mar 2022 17:33:55 +0800 Message-ID: <20220304093409.25829-3-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We can do prep_transhuge_page when newpage is not NULL. Thus we can remove out label to simplify the code. Signed-off-by: Miaohe Lin Reviewed-by: Muchun Song --- mm/migrate.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 50bc62d85eaf..bc1867a5706c 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2025,12 +2025,9 @@ static struct page *alloc_misplaced_dst_page_thp(str= uct page *page, =20 newpage =3D alloc_pages_node(nid, (GFP_TRANSHUGE_LIGHT | __GFP_THISNODE), HPAGE_PMD_ORDER); - if (!newpage) - goto out; + if (newpage) + prep_transhuge_page(newpage); =20 - prep_transhuge_page(newpage); - -out: return newpage; } =20 --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 56278C4332F for ; Fri, 4 Mar 2022 09:35:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237886AbiCDJgH (ORCPT ); Fri, 4 Mar 2022 04:36:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237288AbiCDJft (ORCPT ); Fri, 4 Mar 2022 04:35:49 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15FC7180238 for ; Fri, 4 Mar 2022 01:35:02 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4K92fh0ZHZz9sYS; Fri, 4 Mar 2022 17:31:24 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:34:59 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 03/16] mm/migration: remove unneeded local variable page_lru Date: Fri, 4 Mar 2022 17:33:56 +0800 Message-ID: <20220304093409.25829-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We can use page_is_file_lru() directly to help account the isolated pages to simplify the code a bit as same as local variable follflags. Signed-off-by: Miaohe Lin --- mm/migrate.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index bc1867a5706c..da5a81052468 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1609,7 +1609,6 @@ static int add_page_for_migration(struct mm_struct *m= m, unsigned long addr, { struct vm_area_struct *vma; struct page *page; - unsigned int follflags; int err; =20 mmap_read_lock(mm); @@ -1619,8 +1618,7 @@ static int add_page_for_migration(struct mm_struct *m= m, unsigned long addr, goto out; =20 /* FOLL_DUMP to ignore special (like zero) pages */ - follflags =3D FOLL_GET | FOLL_DUMP; - page =3D follow_page(vma, addr, follflags); + page =3D follow_page(vma, addr, FOLL_GET | FOLL_DUMP); =20 err =3D PTR_ERR(page); if (IS_ERR(page)) @@ -2033,7 +2031,6 @@ static struct page *alloc_misplaced_dst_page_thp(stru= ct page *page, =20 static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) { - int page_lru; int nr_pages =3D thp_nr_pages(page); int order =3D compound_order(page); =20 @@ -2060,8 +2057,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat,= struct page *page) if (isolate_lru_page(page)) return 0; =20 - page_lru =3D page_is_file_lru(page); - mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + page_lru, + mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + page_is_file_lru= (page), nr_pages); =20 /* --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 55718C433FE for ; Fri, 4 Mar 2022 09:35:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237524AbiCDJgL (ORCPT ); Fri, 4 Mar 2022 04:36:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237377AbiCDJfu (ORCPT ); Fri, 4 Mar 2022 04:35:50 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF3B8EBAFD for ; Fri, 4 Mar 2022 01:35:02 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4K92dQ3KPvzbcD4; Fri, 4 Mar 2022 17:30:18 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:00 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 04/16] mm/migration: reduce the rcu lock duration Date: Fri, 4 Mar 2022 17:33:57 +0800 Message-ID: <20220304093409.25829-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" rcu_read_lock is required by grabbing the task refcount but it's not needed for ptrace_may_access. So we could release the rcu lock after task refcount is successfully grabbed to reduce the rcu holding time. Signed-off-by: Miaohe Lin Reviewed-by: Muchun Song --- mm/migrate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index da5a81052468..26943bd819e8 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1907,17 +1907,16 @@ static struct mm_struct *find_mm_struct(pid_t pid, = nodemask_t *mem_nodes) return ERR_PTR(-ESRCH); } get_task_struct(task); + rcu_read_unlock(); =20 /* * Check if this process has the right to modify the specified * process. Use the regular "ptrace_may_access()" checks. */ if (!ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS)) { - rcu_read_unlock(); mm =3D ERR_PTR(-EPERM); goto out; } - rcu_read_unlock(); =20 mm =3D ERR_PTR(security_task_movememory(task)); if (IS_ERR(mm)) --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 DE640C433EF for ; Fri, 4 Mar 2022 09:35:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238014AbiCDJgN (ORCPT ); Fri, 4 Mar 2022 04:36:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237246AbiCDJfu (ORCPT ); Fri, 4 Mar 2022 04:35:50 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEDEA7307E for ; Fri, 4 Mar 2022 01:35:03 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4K92jM4PLQzdbB0; Fri, 4 Mar 2022 17:33:43 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:01 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 05/16] mm/migration: fix the confusing PageTransHuge check Date: Fri, 4 Mar 2022 17:33:58 +0800 Message-ID: <20220304093409.25829-6-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" prep_transhuge_page should be called when PageTransHuge(page) is true. The newly allocated new_page is not yet PageTransHuge though it could pass the check as PageTransHuge only checks PageHead now. Signed-off-by: Miaohe Lin Reviewed-by: Muchun Song --- mm/migrate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index 26943bd819e8..15cac2dabc93 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1560,7 +1560,7 @@ struct page *alloc_migration_target(struct page *page= , unsigned long private) =20 new_page =3D __alloc_pages(gfp_mask, order, nid, mtc->nmask); =20 - if (new_page && PageTransHuge(new_page)) + if (new_page && PageTransHuge(page)) prep_transhuge_page(new_page); =20 return new_page; --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 6458AC433F5 for ; Fri, 4 Mar 2022 09:35:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238975AbiCDJgW (ORCPT ); Fri, 4 Mar 2022 04:36:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237307AbiCDJfw (ORCPT ); Fri, 4 Mar 2022 04:35:52 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C729D8F9B6 for ; Fri, 4 Mar 2022 01:35:04 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4K92jN47dkzdbB2; Fri, 4 Mar 2022 17:33:44 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:02 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 06/16] mm/migration: use helper function vma_lookup() in add_page_for_migration Date: Fri, 4 Mar 2022 17:33:59 +0800 Message-ID: <20220304093409.25829-7-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We could use helper function vma_lookup() to lookup the needed vma to simplify the code. Signed-off-by: Miaohe Lin --- mm/migrate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 15cac2dabc93..bc79d7338780 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1613,8 +1613,8 @@ static int add_page_for_migration(struct mm_struct *m= m, unsigned long addr, =20 mmap_read_lock(mm); err =3D -EFAULT; - vma =3D find_vma(mm, addr); - if (!vma || addr < vma->vm_start || !vma_migratable(vma)) + vma =3D vma_lookup(mm, addr); + if (!vma || !vma_migratable(vma)) goto out; =20 /* FOLL_DUMP to ignore special (like zero) pages */ --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 19F4CC433F5 for ; Fri, 4 Mar 2022 09:35:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237558AbiCDJga (ORCPT ); Fri, 4 Mar 2022 04:36:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235351AbiCDJfw (ORCPT ); Fri, 4 Mar 2022 04:35:52 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A09F175603 for ; Fri, 4 Mar 2022 01:35:05 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4K92hm6g18zBrt1; Fri, 4 Mar 2022 17:33:12 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:03 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 07/16] mm/migration: use helper macro min_t in do_pages_stat Date: Fri, 4 Mar 2022 17:34:00 +0800 Message-ID: <20220304093409.25829-8-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We could use helper macro min_t to help set the chunk_nr to simplify the code. Signed-off-by: Miaohe Lin Reviewed-by: Muchun Song --- mm/migrate.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index bc79d7338780..c84eec19072a 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1858,9 +1858,7 @@ static int do_pages_stat(struct mm_struct *mm, unsign= ed long nr_pages, while (nr_pages) { unsigned long chunk_nr; =20 - chunk_nr =3D nr_pages; - if (chunk_nr > DO_PAGES_STAT_CHUNK_NR) - chunk_nr =3D DO_PAGES_STAT_CHUNK_NR; + chunk_nr =3D min_t(unsigned long, nr_pages, DO_PAGES_STAT_CHUNK_NR); =20 if (in_compat_syscall()) { if (get_compat_pages_array(chunk_pages, pages, --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 73F4CC433EF for ; Fri, 4 Mar 2022 09:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238369AbiCDJgl (ORCPT ); Fri, 4 Mar 2022 04:36:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237400AbiCDJfx (ORCPT ); Fri, 4 Mar 2022 04:35:53 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0B7075603 for ; Fri, 4 Mar 2022 01:35:06 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4K92dV2pXQzbcJP; Fri, 4 Mar 2022 17:30:22 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:04 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 08/16] mm/migration: avoid unneeded nodemask_t initialization Date: Fri, 4 Mar 2022 17:34:01 +0800 Message-ID: <20220304093409.25829-9-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Avoid unneeded next_pass and this_pass initialization as they're always set before using to save possible cpu cycles when there are plenty of nodes in the system. Signed-off-by: Miaohe Lin Reviewed-by: Baolin Wang Reviewed-by: Muchun Song --- mm/migrate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index c84eec19072a..abb0c6715e1f 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2378,8 +2378,8 @@ static int establish_migrate_target(int node, nodemas= k_t *used, */ static void __set_migration_target_nodes(void) { - nodemask_t next_pass =3D NODE_MASK_NONE; - nodemask_t this_pass =3D NODE_MASK_NONE; + nodemask_t next_pass; + nodemask_t this_pass; nodemask_t used_targets =3D NODE_MASK_NONE; int node, best_distance; =20 --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 0B572C433EF for ; Fri, 4 Mar 2022 09:35:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237697AbiCDJge (ORCPT ); Fri, 4 Mar 2022 04:36:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237428AbiCDJfz (ORCPT ); Fri, 4 Mar 2022 04:35:55 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5A06188865 for ; Fri, 4 Mar 2022 01:35:07 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4K92jR0dhfzdg7F; Fri, 4 Mar 2022 17:33:47 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:05 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 09/16] mm/migration: remove some duplicated codes in migrate_pages Date: Fri, 4 Mar 2022 17:34:02 +0800 Message-ID: <20220304093409.25829-10-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove the duplicated codes in migrate_pages to simplify the code. Minor readability improvement. No functional change intended. Signed-off-by: Miaohe Lin Reviewed-by: Baolin Wang --- mm/migrate.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index abb0c6715e1f..cb970d201147 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1414,14 +1414,11 @@ int migrate_pages(struct list_head *from, new_page_= t get_new_page, nr_thp_split++; goto retry; } - - nr_failed_pages +=3D nr_subpages; - break; - } - /* Hugetlb migration is unsupported */ - if (!no_subpage_counting) + } else if (!no_subpage_counting) { nr_failed++; + } + nr_failed_pages +=3D nr_subpages; break; case -ENOMEM: @@ -1436,28 +1433,22 @@ int migrate_pages(struct list_head *from, new_page_= t get_new_page, nr_thp_split++; goto retry; } - - nr_failed_pages +=3D nr_subpages; - goto out; + } else if (!no_subpage_counting) { + nr_failed++; } =20 - if (!no_subpage_counting) - nr_failed++; nr_failed_pages +=3D nr_subpages; goto out; case -EAGAIN: - if (is_thp) { + if (is_thp) thp_retry++; - break; - } - retry++; + else + retry++; break; case MIGRATEPAGE_SUCCESS: nr_succeeded +=3D nr_subpages; - if (is_thp) { + if (is_thp) nr_thp_succeeded++; - break; - } break; default: /* @@ -1466,14 +1457,11 @@ int migrate_pages(struct list_head *from, new_page_= t get_new_page, * removed from migration page list and not * retried in the next outer loop. */ - if (is_thp) { + if (is_thp) nr_thp_failed++; - nr_failed_pages +=3D nr_subpages; - break; - } - - if (!no_subpage_counting) + else if (!no_subpage_counting) nr_failed++; + nr_failed_pages +=3D nr_subpages; break; } --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 7A0EDC433F5 for ; Fri, 4 Mar 2022 09:36:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237816AbiCDJgu (ORCPT ); Fri, 4 Mar 2022 04:36:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237467AbiCDJgC (ORCPT ); Fri, 4 Mar 2022 04:36:02 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B5B718886B for ; Fri, 4 Mar 2022 01:35:08 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4K92dX2453zbc6c; Fri, 4 Mar 2022 17:30:24 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:05 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 10/16] mm/migration: remove PG_writeback handle in folio_migrate_flags Date: Fri, 4 Mar 2022 17:34:03 +0800 Message-ID: <20220304093409.25829-11-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When newfolio reaches here, it's guaranteed that PG_writeback is not set because caller ensures writeback must have been completed. Remove this unneeded check and cleanup the relevant comment. Signed-off-by: Miaohe Lin --- mm/migrate.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index cb970d201147..1de5289a4af0 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -549,18 +549,6 @@ void folio_migrate_flags(struct folio *newfolio, struc= t folio *folio) if (!folio_test_hugetlb(folio)) folio->private =3D NULL; =20 - /* - * If any waiters have accumulated on the new page then - * wake them up. - */ - if (folio_test_writeback(newfolio)) - folio_end_writeback(newfolio); - - /* - * PG_readahead shares the same bit with PG_reclaim. The above - * end_page_writeback() may clear PG_readahead mistakenly, so set the - * bit after that. - */ if (folio_test_readahead(folio)) folio_set_readahead(newfolio); =20 --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 78A34C4332F for ; Fri, 4 Mar 2022 09:36:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237570AbiCDJgr (ORCPT ); Fri, 4 Mar 2022 04:36:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237502AbiCDJgC (ORCPT ); Fri, 4 Mar 2022 04:36:02 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99CF018E3C8 for ; Fri, 4 Mar 2022 01:35:09 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4K92hr5V19zBrt3; Fri, 4 Mar 2022 17:33:16 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:06 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 11/16] mm/migration: remove unneeded lock page and PageMovable check Date: Fri, 4 Mar 2022 17:34:04 +0800 Message-ID: <20220304093409.25829-12-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When non-lru movable page was freed from under us, __ClearPageMovable must have been done. Even if it's not done, __ClearPageIsolated here won't hurt as page will be freed soon. So we can thus remove unneeded lock page and PageMovable check here. Signed-off-by: Miaohe Lin --- mm/migrate.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 1de5289a4af0..e0db06927f02 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1074,12 +1074,8 @@ static int unmap_and_move(new_page_t get_new_page, /* page was freed from under us. So we are done. */ ClearPageActive(page); ClearPageUnevictable(page); - if (unlikely(__PageMovable(page))) { - lock_page(page); - if (!PageMovable(page)) - __ClearPageIsolated(page); - unlock_page(page); - } + if (unlikely(__PageMovable(page))) + __ClearPageIsolated(page); goto out; } =20 --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 EC382C433F5 for ; Fri, 4 Mar 2022 09:36:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239062AbiCDJhM (ORCPT ); Fri, 4 Mar 2022 04:37:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237540AbiCDJgC (ORCPT ); Fri, 4 Mar 2022 04:36:02 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7627D18E3EA for ; Fri, 4 Mar 2022 01:35:10 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4K92fr5clbz9sRb; Fri, 4 Mar 2022 17:31:32 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:07 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 12/16] mm/migration: fix potential page refcounts leak in migrate_pages Date: Fri, 4 Mar 2022 17:34:05 +0800 Message-ID: <20220304093409.25829-13-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In -ENOMEM case, there might be some subpages of fail-to-migrate THPs left in thp_split_pages list. We should move them back to migration list so that they could be put back to the right list by the caller otherwise the page refcnt will be leaked here. Also adjust nr_failed and nr_thp_failed accordingly to make vm events account more accurate. Fixes: b5bade978e9b ("mm: migrate: fix the return value of migrate_pages()") Signed-off-by: Miaohe Lin Reviewed-by: "Huang, Ying" Reviewed-by: Baolin Wang --- mm/migrate.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/migrate.c b/mm/migrate.c index e0db06927f02..6c2dfed2ddb8 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1422,6 +1422,15 @@ int migrate_pages(struct list_head *from, new_page_t= get_new_page, } =20 nr_failed_pages +=3D nr_subpages; + /* + * There might be some subpages of fail-to-migrate THPs + * left in thp_split_pages list. Move them back to migration + * list so that they could be put back to the right list by + * the caller otherwise the page refcnt will be leaked. + */ + list_splice_init(&thp_split_pages, from); + nr_failed +=3D retry; + nr_thp_failed +=3D thp_retry; goto out; case -EAGAIN: if (is_thp) --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 A19CAC433EF for ; Fri, 4 Mar 2022 09:36:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238973AbiCDJgy (ORCPT ); Fri, 4 Mar 2022 04:36:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237556AbiCDJgC (ORCPT ); Fri, 4 Mar 2022 04:36:02 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AF0118A7B6 for ; Fri, 4 Mar 2022 01:35:11 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4K92jW2DJgzdb9k; Fri, 4 Mar 2022 17:33:51 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:08 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 13/16] mm/migration: return errno when isolate_huge_page failed Date: Fri, 4 Mar 2022 17:34:06 +0800 Message-ID: <20220304093409.25829-14-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We should return errno (-EBUSY here) when failed to isolate the huge page rather than always return 1 which could confuse the user. Signed-off-by: Miaohe Lin Reviewed-by: Baolin Wang Reviewed-by: Muchun Song --- mm/migrate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 6c2dfed2ddb8..279940c0c064 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1618,10 +1618,8 @@ static int add_page_for_migration(struct mm_struct *= mm, unsigned long addr, goto out_putpage; =20 if (PageHuge(page)) { - if (PageHead(page)) { - isolate_huge_page(page, pagelist); - err =3D 1; - } + if (PageHead(page)) + err =3D isolate_huge_page(page, pagelist) ? 1 : -EBUSY; } else { struct page *head; =20 --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 C9CACC433EF for ; Fri, 4 Mar 2022 09:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239051AbiCDJg6 (ORCPT ); Fri, 4 Mar 2022 04:36:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237452AbiCDJgC (ORCPT ); Fri, 4 Mar 2022 04:36:02 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77B1C1903C5 for ; Fri, 4 Mar 2022 01:35:12 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4K92jW6Nn2zdgC7; Fri, 4 Mar 2022 17:33:51 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:09 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 14/16] mm/migration: fix potential invalid node access for reclaim-based migration Date: Fri, 4 Mar 2022 17:34:07 +0800 Message-ID: <20220304093409.25829-15-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If we failed to setup hotplug state callbacks for mm/demotion:online in some corner cases, node_demotion will be left uninitialized. Invalid node might be returned from the next_demotion_node() when doing reclaim-based migration. Use kcalloc to allocate node_demotion to fix the issue. Fixes: ac16ec835314 ("mm: migrate: support multiple target nodes demotion") Signed-off-by: Miaohe Lin Reviewed-by: "Huang, Ying" --- mm/migrate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 279940c0c064..7b1c0b988234 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2516,9 +2516,9 @@ static int __init migrate_on_reclaim_init(void) { int ret; =20 - node_demotion =3D kmalloc_array(nr_node_ids, - sizeof(struct demotion_nodes), - GFP_KERNEL); + node_demotion =3D kcalloc(nr_node_ids, + sizeof(struct demotion_nodes), + GFP_KERNEL); WARN_ON(!node_demotion); =20 ret =3D cpuhp_setup_state_nocalls(CPUHP_MM_DEMOTION_DEAD, "mm/demotion:of= fline", --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 4410FC433EF for ; Fri, 4 Mar 2022 09:36:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238129AbiCDJhC (ORCPT ); Fri, 4 Mar 2022 04:37:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237652AbiCDJgD (ORCPT ); Fri, 4 Mar 2022 04:36:03 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72C451903DB for ; Fri, 4 Mar 2022 01:35:13 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4K92hw4XcPzBrsy; Fri, 4 Mar 2022 17:33:20 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:10 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 15/16] mm/migration: fix possible do_pages_stat_array racing with memory offline Date: Fri, 4 Mar 2022 17:34:08 +0800 Message-ID: <20220304093409.25829-16-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When follow_page peeks a page, the page could be reclaimed under heavy memory pressure and thus be offlined while it's still being used by the do_pages_stat_array(). Use FOLL_GET to hold the page refcnt to fix this potential issue. Signed-off-by: Miaohe Lin --- mm/migrate.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 7b1c0b988234..98a968e6f465 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1788,13 +1788,18 @@ static void do_pages_stat_array(struct mm_struct *m= m, unsigned long nr_pages, goto set_status; =20 /* FOLL_DUMP to ignore special (like zero) pages */ - page =3D follow_page(vma, addr, FOLL_DUMP); + page =3D follow_page(vma, addr, FOLL_GET | FOLL_DUMP); =20 err =3D PTR_ERR(page); if (IS_ERR(page)) goto set_status; =20 - err =3D page ? page_to_nid(page) : -ENOENT; + if (page) { + err =3D page_to_nid(page); + put_page(page); + } else { + err =3D -ENOENT; + } set_status: *status =3D err; =20 --=20 2.23.0 From nobody Tue Jun 23 13:09:52 2026 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 9B6CCC433EF for ; Fri, 4 Mar 2022 09:36:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237968AbiCDJhH (ORCPT ); Fri, 4 Mar 2022 04:37:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237689AbiCDJgD (ORCPT ); Fri, 4 Mar 2022 04:36:03 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 760F018E3F1 for ; Fri, 4 Mar 2022 01:35:14 -0800 (PST) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4K92df22mhz1GCQ8; Fri, 4 Mar 2022 17:30:30 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 4 Mar 2022 17:35:11 +0800 From: Miaohe Lin To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH 16/16] mm/migration: fix potential pte_unmap on an not mapped pte Date: Fri, 4 Mar 2022 17:34:09 +0800 Message-ID: <20220304093409.25829-17-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220304093409.25829-1-linmiaohe@huawei.com> References: <20220304093409.25829-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" __migration_entry_wait and migration_entry_wait_on_locked assume pte is always mapped from caller. But this is not the case when it's called from migration_entry_wait_huge and follow_huge_pmd. And a parameter unmap to indicate whether pte needs to be unmapped to fix this issue. Fixes: 30dad30922cc ("mm: migration: add migrate_entry_wait_huge()") Signed-off-by: Miaohe Lin --- include/linux/migrate.h | 2 +- include/linux/swapops.h | 4 ++-- mm/filemap.c | 10 +++++----- mm/hugetlb.c | 2 +- mm/migrate.c | 14 ++++++++------ 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 66a34eae8cb6..3ef4ff699bef 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -41,7 +41,7 @@ extern int migrate_huge_page_move_mapping(struct address_= space *mapping, extern int migrate_page_move_mapping(struct address_space *mapping, struct page *newpage, struct page *page, int extra_count); void migration_entry_wait_on_locked(swp_entry_t entry, pte_t *ptep, - spinlock_t *ptl); + spinlock_t *ptl, bool unmap); void folio_migrate_flags(struct folio *newfolio, struct folio *folio); void folio_migrate_copy(struct folio *newfolio, struct folio *folio); int folio_migrate_mapping(struct address_space *mapping, diff --git a/include/linux/swapops.h b/include/linux/swapops.h index d356ab4047f7..d66556875d7d 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -213,7 +213,7 @@ static inline swp_entry_t make_writable_migration_entry= (pgoff_t offset) } =20 extern void __migration_entry_wait(struct mm_struct *mm, pte_t *ptep, - spinlock_t *ptl); + spinlock_t *ptl, bool unmap); extern void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd, unsigned long address); extern void migration_entry_wait_huge(struct vm_area_struct *vma, @@ -235,7 +235,7 @@ static inline int is_migration_entry(swp_entry_t swp) } =20 static inline void __migration_entry_wait(struct mm_struct *mm, pte_t *pte= p, - spinlock_t *ptl) { } + spinlock_t *ptl, bool unmap) { } static inline void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd, unsigned long address) { } static inline void migration_entry_wait_huge(struct vm_area_struct *vma, diff --git a/mm/filemap.c b/mm/filemap.c index 8f7e6088ee2a..18c353d52aae 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1389,6 +1389,7 @@ static inline int folio_wait_bit_common(struct folio = *folio, int bit_nr, * @ptep: mapped pte pointer. Will return with the ptep unmapped. Only req= uired * for pte entries, pass NULL for pmd entries. * @ptl: already locked ptl. This function will drop the lock. + * @unmap: indicating whether ptep need to be unmapped. * * Wait for a migration entry referencing the given page to be removed. Th= is is * equivalent to put_and_wait_on_page_locked(page, TASK_UNINTERRUPTIBLE) e= xcept @@ -1402,7 +1403,7 @@ static inline int folio_wait_bit_common(struct folio = *folio, int bit_nr, * there. */ void migration_entry_wait_on_locked(swp_entry_t entry, pte_t *ptep, - spinlock_t *ptl) + spinlock_t *ptl, bool unmap) { struct wait_page_queue wait_page; wait_queue_entry_t *wait =3D &wait_page.wait; @@ -1439,10 +1440,9 @@ void migration_entry_wait_on_locked(swp_entry_t entr= y, pte_t *ptep, * a valid reference to the page, and it must take the ptl to remove the * migration entry. So the page is valid until the ptl is dropped. */ - if (ptep) - pte_unmap_unlock(ptep, ptl); - else - spin_unlock(ptl); + spin_unlock(ptl); + if (unmap && ptep) + pte_unmap(ptep); =20 for (;;) { unsigned int flags; diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 07668781c246..8088128c25db 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6713,7 +6713,7 @@ follow_huge_pmd(struct mm_struct *mm, unsigned long a= ddress, } else { if (is_hugetlb_entry_migration(pte)) { spin_unlock(ptl); - __migration_entry_wait(mm, (pte_t *)pmd, ptl); + __migration_entry_wait(mm, (pte_t *)pmd, ptl, false); goto retry; } /* diff --git a/mm/migrate.c b/mm/migrate.c index 98a968e6f465..5519261f54fe 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -281,7 +281,7 @@ void remove_migration_ptes(struct folio *src, struct fo= lio *dst, bool locked) * When we return from this function the fault will be retried. */ void __migration_entry_wait(struct mm_struct *mm, pte_t *ptep, - spinlock_t *ptl) + spinlock_t *ptl, bool unmap) { pte_t pte; swp_entry_t entry; @@ -295,10 +295,12 @@ void __migration_entry_wait(struct mm_struct *mm, pte= _t *ptep, if (!is_migration_entry(entry)) goto out; =20 - migration_entry_wait_on_locked(entry, ptep, ptl); + migration_entry_wait_on_locked(entry, ptep, ptl, unmap); return; out: - pte_unmap_unlock(ptep, ptl); + spin_unlock(ptl); + if (unmap) + pte_unmap(ptep); } =20 void migration_entry_wait(struct mm_struct *mm, pmd_t *pmd, @@ -306,14 +308,14 @@ void migration_entry_wait(struct mm_struct *mm, pmd_t= *pmd, { spinlock_t *ptl =3D pte_lockptr(mm, pmd); pte_t *ptep =3D pte_offset_map(pmd, address); - __migration_entry_wait(mm, ptep, ptl); + __migration_entry_wait(mm, ptep, ptl, true); } =20 void migration_entry_wait_huge(struct vm_area_struct *vma, struct mm_struct *mm, pte_t *pte) { spinlock_t *ptl =3D huge_pte_lockptr(hstate_vma(vma), mm, pte); - __migration_entry_wait(mm, pte, ptl); + __migration_entry_wait(mm, pte, ptl, false); } =20 #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION @@ -324,7 +326,7 @@ void pmd_migration_entry_wait(struct mm_struct *mm, pmd= _t *pmd) ptl =3D pmd_lock(mm, pmd); if (!is_pmd_migration_entry(*pmd)) goto unlock; - migration_entry_wait_on_locked(pmd_to_swp_entry(*pmd), NULL, ptl); + migration_entry_wait_on_locked(pmd_to_swp_entry(*pmd), NULL, ptl, false); return; unlock: spin_unlock(ptl); --=20 2.23.0