From nobody Mon Jun 22 18:10:51 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 1697EC433F5 for ; Thu, 17 Mar 2022 14:42:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235293AbiCQOn2 (ORCPT ); Thu, 17 Mar 2022 10:43:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235397AbiCQOnI (ORCPT ); Thu, 17 Mar 2022 10:43:08 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82FA4200946 for ; Thu, 17 Mar 2022 07:41:50 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KK8q50TL1z1GCTw; Thu, 17 Mar 2022 22:36:49 +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; Thu, 17 Mar 2022 22:41:48 +0800 From: Miaohe Lin To: CC: , , , , , , , Subject: [PATCH v2 01/11] mm/migration: remove unneeded local variable mapping_locked Date: Fri, 18 Mar 2022 19:16:59 +0800 Message-ID: <20220318111709.60311-2-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220318111709.60311-1-linmiaohe@huawei.com> References: <20220318111709.60311-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 Mon Jun 22 18:10:51 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 62C0DC433F5 for ; Thu, 17 Mar 2022 14:42:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235303AbiCQOnb (ORCPT ); Thu, 17 Mar 2022 10:43:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235400AbiCQOnI (ORCPT ); Thu, 17 Mar 2022 10:43:08 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FC57200949 for ; Thu, 17 Mar 2022 07:41:51 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KK8q52n25zcb7Z; Thu, 17 Mar 2022 22:36:49 +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; Thu, 17 Mar 2022 22:41:48 +0800 From: Miaohe Lin To: CC: , , , , , , , Subject: [PATCH v2 02/11] mm/migration: remove unneeded out label Date: Fri, 18 Mar 2022 19:17:00 +0800 Message-ID: <20220318111709.60311-3-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220318111709.60311-1-linmiaohe@huawei.com> References: <20220318111709.60311-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 Mon Jun 22 18:10:51 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 B9C99C433EF for ; Thu, 17 Mar 2022 14:42:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235290AbiCQOn0 (ORCPT ); Thu, 17 Mar 2022 10:43:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235399AbiCQOnI (ORCPT ); Thu, 17 Mar 2022 10:43:08 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 982F920095D for ; Thu, 17 Mar 2022 07:41:51 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KK8v84hfZzfZ7k; Thu, 17 Mar 2022 22:40: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; Thu, 17 Mar 2022 22:41:49 +0800 From: Miaohe Lin To: CC: , , , , , , , Subject: [PATCH v2 03/11] mm/migration: remove unneeded local variable page_lru Date: Fri, 18 Mar 2022 19:17:01 +0800 Message-ID: <20220318111709.60311-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220318111709.60311-1-linmiaohe@huawei.com> References: <20220318111709.60311-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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. Signed-off-by: Miaohe Lin --- mm/migrate.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index bc1867a5706c..0ea555e4eaae 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2033,7 +2033,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 +2059,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 Mon Jun 22 18:10:51 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 64BF7C433FE for ; Thu, 17 Mar 2022 14:42:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235342AbiCQOnh (ORCPT ); Thu, 17 Mar 2022 10:43:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235403AbiCQOnJ (ORCPT ); Thu, 17 Mar 2022 10:43:09 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D7B3200962 for ; Thu, 17 Mar 2022 07:41:52 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KK8rS2d1vz9sW5; Thu, 17 Mar 2022 22:38:00 +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; Thu, 17 Mar 2022 22:41:49 +0800 From: Miaohe Lin To: CC: , , , , , , , Subject: [PATCH v2 04/11] mm/migration: fix the confusing PageTransHuge check Date: Fri, 18 Mar 2022 19:17:02 +0800 Message-ID: <20220318111709.60311-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220318111709.60311-1-linmiaohe@huawei.com> References: <20220318111709.60311-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 0ea555e4eaae..b16c561a9a4b 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 Mon Jun 22 18:10:51 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 5E8E2C433F5 for ; Thu, 17 Mar 2022 14:42:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235334AbiCQOng (ORCPT ); Thu, 17 Mar 2022 10:43:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235404AbiCQOnJ (ORCPT ); Thu, 17 Mar 2022 10:43:09 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DE37200963 for ; Thu, 17 Mar 2022 07:41:52 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KK8vB0zlmzfYtx; Thu, 17 Mar 2022 22:40: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; Thu, 17 Mar 2022 22:41:50 +0800 From: Miaohe Lin To: CC: , , , , , , , Subject: [PATCH v2 05/11] mm/migration: use helper function vma_lookup() in add_page_for_migration Date: Fri, 18 Mar 2022 19:17:03 +0800 Message-ID: <20220318111709.60311-6-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220318111709.60311-1-linmiaohe@huawei.com> References: <20220318111709.60311-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 b16c561a9a4b..eb1c736750da 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1614,8 +1614,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 Mon Jun 22 18:10:51 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 2A2C1C433F5 for ; Thu, 17 Mar 2022 14:42:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235315AbiCQOnd (ORCPT ); Thu, 17 Mar 2022 10:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235407AbiCQOnJ (ORCPT ); Thu, 17 Mar 2022 10:43:09 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02C74200964 for ; Thu, 17 Mar 2022 07:41:53 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KK8q74JQPzcb6B; Thu, 17 Mar 2022 22:36: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; Thu, 17 Mar 2022 22:41:50 +0800 From: Miaohe Lin To: CC: , , , , , , , Subject: [PATCH v2 06/11] mm/migration: use helper macro min in do_pages_stat Date: Fri, 18 Mar 2022 19:17:04 +0800 Message-ID: <20220318111709.60311-7-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220318111709.60311-1-linmiaohe@huawei.com> References: <20220318111709.60311-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 to help set the chunk_nr to simplify the code. Signed-off-by: Miaohe Lin Reviewed-by: Muchun Song --- mm/migrate.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index eb1c736750da..92068d090db8 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1853,16 +1853,12 @@ static int do_pages_stat(struct mm_struct *mm, unsi= gned long nr_pages, const void __user * __user *pages, int __user *status) { -#define DO_PAGES_STAT_CHUNK_NR 16 +#define DO_PAGES_STAT_CHUNK_NR 16UL const void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR]; int chunk_status[DO_PAGES_STAT_CHUNK_NR]; =20 while (nr_pages) { - unsigned long chunk_nr; - - chunk_nr =3D nr_pages; - if (chunk_nr > DO_PAGES_STAT_CHUNK_NR) - chunk_nr =3D DO_PAGES_STAT_CHUNK_NR; + unsigned long chunk_nr =3D min(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 Mon Jun 22 18:10:51 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 2155CC433EF for ; Thu, 17 Mar 2022 14:42:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235365AbiCQOnl (ORCPT ); Thu, 17 Mar 2022 10:43:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235416AbiCQOnL (ORCPT ); Thu, 17 Mar 2022 10:43:11 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3271C200949 for ; Thu, 17 Mar 2022 07:41:54 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KK8tY4ZsCzCqj8; Thu, 17 Mar 2022 22:39:49 +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; Thu, 17 Mar 2022 22:41:51 +0800 From: Miaohe Lin To: CC: , , , , , , , Subject: [PATCH v2 07/11] mm/migration: avoid unneeded nodemask_t initialization Date: Fri, 18 Mar 2022 19:17:05 +0800 Message-ID: <20220318111709.60311-8-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220318111709.60311-1-linmiaohe@huawei.com> References: <20220318111709.60311-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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: Muchun Song Reviewed-by: Baolin Wang --- mm/migrate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 92068d090db8..bb36f6b40f18 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2379,8 +2379,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 Mon Jun 22 18:10:51 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 654DAC433EF for ; Thu, 17 Mar 2022 14:42:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235352AbiCQOni (ORCPT ); Thu, 17 Mar 2022 10:43:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235415AbiCQOnL (ORCPT ); Thu, 17 Mar 2022 10:43:11 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3297D20095D for ; Thu, 17 Mar 2022 07:41:54 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KK8rV41Jjz9sh1; Thu, 17 Mar 2022 22:38:02 +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; Thu, 17 Mar 2022 22:41:51 +0800 From: Miaohe Lin To: CC: , , , , , , , Subject: [PATCH v2 08/11] mm/migration: remove some duplicated codes in migrate_pages Date: Fri, 18 Mar 2022 19:17:06 +0800 Message-ID: <20220318111709.60311-9-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220318111709.60311-1-linmiaohe@huawei.com> References: <20220318111709.60311-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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: Zi Yan 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 bb36f6b40f18..63a87ef0996f 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 Mon Jun 22 18:10:51 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 E34BEC433F5 for ; Thu, 17 Mar 2022 14:42:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235374AbiCQOnp (ORCPT ); Thu, 17 Mar 2022 10:43:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235417AbiCQOnL (ORCPT ); Thu, 17 Mar 2022 10:43:11 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1588200946 for ; Thu, 17 Mar 2022 07:41:54 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KK8vC6qVqzfZFk; Thu, 17 Mar 2022 22:40:23 +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; Thu, 17 Mar 2022 22:41:52 +0800 From: Miaohe Lin To: CC: , , , , , , , Subject: [PATCH v2 09/11] mm/migration: fix potential page refcounts leak in migrate_pages Date: Fri, 18 Mar 2022 19:17:07 +0800 Message-ID: <20220318111709.60311-10-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220318111709.60311-1-linmiaohe@huawei.com> References: <20220318111709.60311-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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: Zi Yan Reviewed-by: "Huang, Ying" Reviewed-by: Baolin Wang Reviewed-by: Muchun Song --- mm/migrate.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/migrate.c b/mm/migrate.c index 63a87ef0996f..97dfd1f4870d 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1438,6 +1438,14 @@ 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_thp_failed +=3D thp_retry; goto out; case -EAGAIN: if (is_thp) --=20 2.23.0 From nobody Mon Jun 22 18:10:51 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 E72DFC433EF for ; Thu, 17 Mar 2022 14:42:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235383AbiCQOnt (ORCPT ); Thu, 17 Mar 2022 10:43:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235420AbiCQOnL (ORCPT ); Thu, 17 Mar 2022 10:43:11 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A77D200962 for ; Thu, 17 Mar 2022 07:41:55 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KK8q95h19zcbCl; Thu, 17 Mar 2022 22:36:53 +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; Thu, 17 Mar 2022 22:41:53 +0800 From: Miaohe Lin To: CC: , , , , , , , Subject: [PATCH v2 10/11] mm/migration: fix potential invalid node access for reclaim-based migration Date: Fri, 18 Mar 2022 19:17:08 +0800 Message-ID: <20220318111709.60311-11-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220318111709.60311-1-linmiaohe@huawei.com> References: <20220318111709.60311-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 97dfd1f4870d..dbd91fbdb127 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2534,9 +2534,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 Mon Jun 22 18:10:51 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 4E734C433EF for ; Thu, 17 Mar 2022 14:42:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232793AbiCQOn4 (ORCPT ); Thu, 17 Mar 2022 10:43:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235423AbiCQOnM (ORCPT ); Thu, 17 Mar 2022 10:43:12 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE472200963 for ; Thu, 17 Mar 2022 07:41:55 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4KK8rX1f68z9shf; Thu, 17 Mar 2022 22:38:04 +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; Thu, 17 Mar 2022 22:41:53 +0800 From: Miaohe Lin To: CC: , , , , , , , Subject: [PATCH v2 11/11] mm/migration: fix possible do_pages_stat_array racing with memory offline Date: Fri, 18 Mar 2022 19:17:09 +0800 Message-ID: <20220318111709.60311-12-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220318111709.60311-1-linmiaohe@huawei.com> References: <20220318111709.60311-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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 migrated and then 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 race. Signed-off-by: Miaohe Lin Acked-by: "Huang, Ying" Reviewed-by: Muchun Song --- mm/migrate.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index dbd91fbdb127..cd85ba0ab592 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1807,13 +1807,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