From patchwork Fri Mar 18 11:16:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12784164 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F40C2C433EF for ; Thu, 17 Mar 2022 14:41:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DAFCD8D0003; Thu, 17 Mar 2022 10:41:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D359B6B0073; Thu, 17 Mar 2022 10:41:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C26378D0003; Thu, 17 Mar 2022 10:41:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0077.hostedemail.com [216.40.44.77]) by kanga.kvack.org (Postfix) with ESMTP id AD5E86B0072 for ; Thu, 17 Mar 2022 10:41:57 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6AA54A3EC9 for ; Thu, 17 Mar 2022 14:41:57 +0000 (UTC) X-FDA: 79254142674.17.99CD21D Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf28.hostedemail.com (Postfix) with ESMTP id 9077BC0022 for ; Thu, 17 Mar 2022 14:41:56 +0000 (UTC) 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 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 X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 9077BC0022 X-Stat-Signature: tkjw4yywensx5yrwwnfuk7o6az6ft6iy Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf28.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-HE-Tag: 1647528116-797901 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 '|=' to '=' 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_new_page, goto put_anon; if (page_mapped(hpage)) { - bool mapping_locked = false; enum ttu_flags ttu = 0; 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; - mapping_locked = true; - ttu |= TTU_RMAP_LOCKED; + ttu = TTU_RMAP_LOCKED; } try_to_migrate(src, ttu); page_was_mapped = 1; - if (mapping_locked) + if (ttu & TTU_RMAP_LOCKED) i_mmap_unlock_write(mapping); } From patchwork Fri Mar 18 11:17:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12784169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59526C433EF for ; Thu, 17 Mar 2022 14:42:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 301A98D0007; Thu, 17 Mar 2022 10:42:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 264D36B0074; Thu, 17 Mar 2022 10:42:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DB7C8D0007; Thu, 17 Mar 2022 10:42:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0097.hostedemail.com [216.40.44.97]) by kanga.kvack.org (Postfix) with ESMTP id E72A06B0073 for ; Thu, 17 Mar 2022 10:42:02 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9032418289580 for ; Thu, 17 Mar 2022 14:42:02 +0000 (UTC) X-FDA: 79254142884.21.BFD5AE4 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf29.hostedemail.com (Postfix) with ESMTP id DF4A6120009 for ; Thu, 17 Mar 2022 14:42:01 +0000 (UTC) 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 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 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: DF4A6120009 X-Stat-Signature: 3jxd6t841jmheyea4qg7eaw713a1z3id Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-HE-Tag: 1647528121-331891 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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(struct page *page, newpage = alloc_pages_node(nid, (GFP_TRANSHUGE_LIGHT | __GFP_THISNODE), HPAGE_PMD_ORDER); - if (!newpage) - goto out; + if (newpage) + prep_transhuge_page(newpage); - prep_transhuge_page(newpage); - -out: return newpage; } From patchwork Fri Mar 18 11:17:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12784161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86A8CC433FE for ; Thu, 17 Mar 2022 14:41:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C27418D0001; Thu, 17 Mar 2022 10:41:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD5E96B0072; Thu, 17 Mar 2022 10:41:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC4558D0001; Thu, 17 Mar 2022 10:41:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com [216.40.44.221]) by kanga.kvack.org (Postfix) with ESMTP id 9D7BD6B0071 for ; Thu, 17 Mar 2022 10:41:54 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4C57A9D645 for ; Thu, 17 Mar 2022 14:41:54 +0000 (UTC) X-FDA: 79254142506.28.93B10D7 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf23.hostedemail.com (Postfix) with ESMTP id 4D536140027 for ; Thu, 17 Mar 2022 14:41:53 +0000 (UTC) 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 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 X-Rspamd-Queue-Id: 4D536140027 X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=none; spf=pass (imf23.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Stat-Signature: sa9ijojhictkycpfs6a57wbmwqg5n638 X-Rspamd-Server: rspam07 X-HE-Tag: 1647528113-663537 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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(struct page *page, static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) { - int page_lru; int nr_pages = thp_nr_pages(page); int order = compound_order(page); @@ -2060,8 +2059,7 @@ static int numamigrate_isolate_page(pg_data_t *pgdat, struct page *page) if (isolate_lru_page(page)) return 0; - page_lru = 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); /* From patchwork Fri Mar 18 11:17:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12784170 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 537C9C433F5 for ; Thu, 17 Mar 2022 14:42:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 151838D0009; Thu, 17 Mar 2022 10:42:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 102156B0074; Thu, 17 Mar 2022 10:42:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F30EA8D0009; Thu, 17 Mar 2022 10:42:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id DA0506B0073 for ; Thu, 17 Mar 2022 10:42:03 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B864E207B4 for ; Thu, 17 Mar 2022 14:42:03 +0000 (UTC) X-FDA: 79254142926.13.C694101 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf29.hostedemail.com (Postfix) with ESMTP id 151E7120016 for ; Thu, 17 Mar 2022 14:42:02 +0000 (UTC) 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 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 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 151E7120016 X-Stat-Signature: usy5b9x9fhed1y7qq3ejyiuo8a49jo4q Authentication-Results: imf29.hostedemail.com; dkim=none; spf=pass (imf29.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-HE-Tag: 1647528122-173963 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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) new_page = __alloc_pages(gfp_mask, order, nid, mtc->nmask); - if (new_page && PageTransHuge(new_page)) + if (new_page && PageTransHuge(page)) prep_transhuge_page(new_page); return new_page; From patchwork Fri Mar 18 11:17:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12784163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89570C433F5 for ; Thu, 17 Mar 2022 14:41:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D3DF58D0002; Thu, 17 Mar 2022 10:41:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C98306B0073; Thu, 17 Mar 2022 10:41:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98CB38D0003; Thu, 17 Mar 2022 10:41:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 860896B0072 for ; Thu, 17 Mar 2022 10:41:56 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 54AB724E60 for ; Thu, 17 Mar 2022 14:41:56 +0000 (UTC) X-FDA: 79254142632.09.B1B95D3 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf18.hostedemail.com (Postfix) with ESMTP id 7930D1C0028 for ; Thu, 17 Mar 2022 14:41:55 +0000 (UTC) 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 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 X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 7930D1C0028 Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-Stat-Signature: qg158xn79eaaba9fsyf4cknend14epdb X-HE-Tag: 1647528115-423620 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 *mm, unsigned long addr, mmap_read_lock(mm); err = -EFAULT; - vma = find_vma(mm, addr); - if (!vma || addr < vma->vm_start || !vma_migratable(vma)) + vma = vma_lookup(mm, addr); + if (!vma || !vma_migratable(vma)) goto out; /* FOLL_DUMP to ignore special (like zero) pages */ From patchwork Fri Mar 18 11:17:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12784171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD059C433FE for ; Thu, 17 Mar 2022 14:42:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A522C8D000A; Thu, 17 Mar 2022 10:42:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A02086B0074; Thu, 17 Mar 2022 10:42:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EF818D000A; Thu, 17 Mar 2022 10:42:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id 80EA86B0073 for ; Thu, 17 Mar 2022 10:42:04 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 46BBD8249980 for ; Thu, 17 Mar 2022 14:42:04 +0000 (UTC) X-FDA: 79254142968.17.2048CE8 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf02.hostedemail.com (Postfix) with ESMTP id AC3F180031 for ; Thu, 17 Mar 2022 14:42:03 +0000 (UTC) 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 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 X-Rspam-User: X-Rspamd-Queue-Id: AC3F180031 X-Stat-Signature: nei1uk61jkw5brkqy5su6fb1egiiajqe Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam03 X-HE-Tag: 1647528123-88790 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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, unsigned 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]; while (nr_pages) { - unsigned long chunk_nr; - - chunk_nr = nr_pages; - if (chunk_nr > DO_PAGES_STAT_CHUNK_NR) - chunk_nr = DO_PAGES_STAT_CHUNK_NR; + unsigned long chunk_nr = min(nr_pages, DO_PAGES_STAT_CHUNK_NR); if (in_compat_syscall()) { if (get_compat_pages_array(chunk_pages, pages, From patchwork Fri Mar 18 11:17:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12784165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A21C2C433F5 for ; Thu, 17 Mar 2022 14:42:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1037B8D0005; Thu, 17 Mar 2022 10:42:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BACF6B0073; Thu, 17 Mar 2022 10:42:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E952D8D0005; Thu, 17 Mar 2022 10:41:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id C9D4A6B0072 for ; Thu, 17 Mar 2022 10:41:59 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9FBE124E60 for ; Thu, 17 Mar 2022 14:41:59 +0000 (UTC) X-FDA: 79254142758.07.7BD382F Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf19.hostedemail.com (Postfix) with ESMTP id F36C31A0023 for ; Thu, 17 Mar 2022 14:41:58 +0000 (UTC) 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 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 X-Rspamd-Queue-Id: F36C31A0023 X-Stat-Signature: uxzuqo5djs3s1tdu5phf7i19rfugon7s X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam02 X-HE-Tag: 1647528118-186178 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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, nodemask_t *used, */ static void __set_migration_target_nodes(void) { - nodemask_t next_pass = NODE_MASK_NONE; - nodemask_t this_pass = NODE_MASK_NONE; + nodemask_t next_pass; + nodemask_t this_pass; nodemask_t used_targets = NODE_MASK_NONE; int node, best_distance; From patchwork Fri Mar 18 11:17:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12784166 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63FA7C4332F for ; Thu, 17 Mar 2022 14:42:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F355C8D0006; Thu, 17 Mar 2022 10:42:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE41E6B0073; Thu, 17 Mar 2022 10:42:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAA478D0006; Thu, 17 Mar 2022 10:42:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id C91756B0072 for ; Thu, 17 Mar 2022 10:42:00 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 877DB182890D1 for ; Thu, 17 Mar 2022 14:42:00 +0000 (UTC) X-FDA: 79254142800.28.14987E1 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf21.hostedemail.com (Postfix) with ESMTP id 5DEA31C0005 for ; Thu, 17 Mar 2022 14:41:58 +0000 (UTC) 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 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 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5DEA31C0005 X-Stat-Signature: qq4rg731pbakzdei4x6b8uc3ypmnnuqu X-Rspam-User: Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf21.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-HE-Tag: 1647528118-212875 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 += nr_subpages; - break; - } - /* Hugetlb migration is unsupported */ - if (!no_subpage_counting) + } else if (!no_subpage_counting) { nr_failed++; + } + nr_failed_pages += 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 += nr_subpages; - goto out; + } else if (!no_subpage_counting) { + nr_failed++; } - if (!no_subpage_counting) - nr_failed++; nr_failed_pages += nr_subpages; goto out; case -EAGAIN: - if (is_thp) { + if (is_thp) thp_retry++; - break; - } - retry++; + else + retry++; break; case MIGRATEPAGE_SUCCESS: nr_succeeded += 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 += nr_subpages; - break; - } - - if (!no_subpage_counting) + else if (!no_subpage_counting) nr_failed++; + nr_failed_pages += nr_subpages; break; } From patchwork Fri Mar 18 11:17:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12784172 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9F6EC433EF for ; Thu, 17 Mar 2022 14:42:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 85A7C6B0073; Thu, 17 Mar 2022 10:42:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 805658D000C; Thu, 17 Mar 2022 10:42:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CE058D000B; Thu, 17 Mar 2022 10:42:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id 564216B0073 for ; Thu, 17 Mar 2022 10:42:13 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1868FA3EC9 for ; Thu, 17 Mar 2022 14:42:13 +0000 (UTC) X-FDA: 79254143346.24.C95EEB1 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf16.hostedemail.com (Postfix) with ESMTP id B49B1180023 for ; Thu, 17 Mar 2022 14:42:04 +0000 (UTC) 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 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 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B49B1180023 X-Stat-Signature: 5c7gnf5h5sw1z5jdac8hfia6c3jg85xe Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-HE-Tag: 1647528124-512194 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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, } nr_failed_pages += 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 += thp_retry; goto out; case -EAGAIN: if (is_thp) From patchwork Fri Mar 18 11:17:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12784168 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DD01C433F5 for ; Thu, 17 Mar 2022 14:42:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD0326B0072; Thu, 17 Mar 2022 10:42:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D418A8D0009; Thu, 17 Mar 2022 10:42:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D94A6B0073; Thu, 17 Mar 2022 10:42:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 89AAF8D0007 for ; Thu, 17 Mar 2022 10:42:01 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id DF90F12174A for ; Thu, 17 Mar 2022 14:42:00 +0000 (UTC) X-FDA: 79254142800.09.D9D0033 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf02.hostedemail.com (Postfix) with ESMTP id 3131A80010 for ; Thu, 17 Mar 2022 14:42:00 +0000 (UTC) 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 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 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 3131A80010 X-Stat-Signature: 15bmoc3eejgx59y6yeimmfw6sn61qcqj Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-HE-Tag: 1647528120-824349 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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; - node_demotion = kmalloc_array(nr_node_ids, - sizeof(struct demotion_nodes), - GFP_KERNEL); + node_demotion = kcalloc(nr_node_ids, + sizeof(struct demotion_nodes), + GFP_KERNEL); WARN_ON(!node_demotion); ret = cpuhp_setup_state_nocalls(CPUHP_MM_DEMOTION_DEAD, "mm/demotion:offline", From patchwork Fri Mar 18 11:17:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12784167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F938C433EF for ; Thu, 17 Mar 2022 14:42:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B8A7D8D0008; Thu, 17 Mar 2022 10:42:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC4C48D0007; Thu, 17 Mar 2022 10:42:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 940968D0008; Thu, 17 Mar 2022 10:42:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 684836B0072 for ; Thu, 17 Mar 2022 10:42:01 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3713D21892 for ; Thu, 17 Mar 2022 14:42:01 +0000 (UTC) X-FDA: 79254142842.15.7B19E5B Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf28.hostedemail.com (Postfix) with ESMTP id 65E54C002A for ; Thu, 17 Mar 2022 14:42:00 +0000 (UTC) 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 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 X-Rspam-User: X-Rspamd-Queue-Id: 65E54C002A X-Stat-Signature: zo1ko7mozkoyxyn1mfh6qzaz3h7668qh Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf28.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam03 X-HE-Tag: 1647528120-843303 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 *mm, unsigned long nr_pages, goto set_status; /* FOLL_DUMP to ignore special (like zero) pages */ - page = follow_page(vma, addr, FOLL_DUMP); + page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP); err = PTR_ERR(page); if (IS_ERR(page)) goto set_status; - err = page ? page_to_nid(page) : -ENOENT; + if (page) { + err = page_to_nid(page); + put_page(page); + } else { + err = -ENOENT; + } set_status: *status = err;