From patchwork Tue Aug 27 11:47:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13779370 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 9CC94C54735 for ; Tue, 27 Aug 2024 11:47:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 248226B008A; Tue, 27 Aug 2024 07:47:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F7B86B008C; Tue, 27 Aug 2024 07:47:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 05D0F6B0093; Tue, 27 Aug 2024 07:47:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DC6006B008A for ; Tue, 27 Aug 2024 07:47:42 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 67FEF81768 for ; Tue, 27 Aug 2024 11:47:42 +0000 (UTC) X-FDA: 82497850764.16.85B28C2 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf30.hostedemail.com (Postfix) with ESMTP id 3D1A480007 for ; Tue, 27 Aug 2024 11:47:38 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf30.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724759174; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3cgPSm+/FxyFHnCmNGNZx2+AN3lgsXCtk/zttMxp4pI=; b=Yr7APrgJhRNz53KBiQPUoLyPEIfUyqvkZeALRaD2cZmCTtOrtvgqQLOEJnpO59P1hCsONr YMEYC6sukHaNi7UqI+wJCOModo6zqD7yo8rhiLrTDFB2/ss22J4jItJeA9UeuWl+QG/wzo obWO+nTFz/ksMqxB8azhQB2FFJsWt3c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724759174; a=rsa-sha256; cv=none; b=MvU98ri42ckicjDZFIdACH7NAN+cZ3AI0pLSj/gqlUdiVr9mcUvdxMk+B4ouo8g/1JNfgR dictSqtnsAoEgJtdOKoXRKdUav5vFqOrAoj7e6ajbeKRNz5cyNDpJ7IUBx2cgDZDPkx0Pu HmO5Rrq+sEECWVmXeaoY2nsQT72wumc= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf30.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WtQjH21BPzpTX1; Tue, 27 Aug 2024 19:45:55 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id D1ABE140137; Tue, 27 Aug 2024 19:47:35 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 27 Aug 2024 19:47:35 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , , Jonathan Cameron , Kefeng Wang Subject: [PATCH v3 1/5] mm: memory_hotplug: remove head variable in do_migrate_range() Date: Tue, 27 Aug 2024 19:47:24 +0800 Message-ID: <20240827114728.3212578-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240827114728.3212578-1-wangkefeng.wang@huawei.com> References: <20240827114728.3212578-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Queue-Id: 3D1A480007 X-Stat-Signature: gck4fm5x6zf36rtfd4skc5arjotxf5pj X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1724759258-551733 X-HE-Meta: U2FsdGVkX1+HEzuCKw5tvu9YQDM52ftfWzadRIHMzuPR2ZPFsAYRsbIM0GJa8SebFa7P1eaaKORqldmRH1jdRYj2bjeGx7FqfNdo7KKgL1dgfwQoIhIPBkiZ4CO6+/xZqUHSpgzLipEpN/iVu5rxshoioz8lVWDXXovSXDRptgu16JUQF6eGjxt26s3tkz6iuyppwCe3rbvVuWzKKakK72yv3re5PVQ32fjTcG+nX8BRyDmFgRam2Z5rnkUdFo+N2DyjUVDekYsWSIbgo2P0DQAFJGuOWQoW0m+KgT83DW00xqpd0L8M5Mn2dEc4qV4vU7A7ZjlRLvQBe3XC6ra6qUOPm3NBh7OtnUuY8JeqbiYkYo4JjIQqKhqWRUvsQ22toHcF1iEVpaXAa3zhqUfQnw0CSHwWlutin9ZL3N2m0ja31r0C1oEVz2bkAwNaf+dOJi7T8q7SZnAn/T0B9OFO/VPueF9NdV6ZWG/ayERZ+eAk+uS2K8Vr58LLOOTGJIbjJYXoCPM85jYsC9bX8zSoPTImtbqY3AhQYwvStKVXhcouTirFqKTFDTUR2j+KTicyWJpYV5KW800WO6UOcjYjyzoAWXXTi5nQSR4lcd5I5BiBANcJDCgV3E5/+kMUQvGnSGJkqpe2pd9yZ8cOb+t0+b/9Aq2JdbGOjGwdSJ3mP6lFgFahzqIc4pomLqPUN93QGiyonTgOzpMag8dFCi/R6kDHPOi5vMu38z+8mHjLKJZ25ICv4Zdxn6N4jNXp5JEJYjIEam5W1J35vgYvXvIMaeFfz8e/TVqpST7QCItCwEiBvTZJsepD9iSIRtwovAHoliEPUwisq0GEPlIeLL/8l+vuAYpNM8ai1/tmLG4jdQUg4tetHV2sUFANR1OSEE0jjfMHgPUanJiK7YN3LSONUztwrZRnUq5mNK2FfGzzQZ6aU2wwkmawHxlAIiLHDByZTt+1e77q/xdq43kLSFY jBEV9QtV WQFT6SLEMyiDnlO/BGblH0Kz+amUIEoTYX8lOV5Uy/ks2MOrrfF2O/8aZNMTGUoqawGV2zDDwktsiIhk4WcYe/MUtaf/j2f7X0nUjLIFpyIDmMzDF/SvsVxTD4XxSvnprw5wTILMx+YfBeV7Jynfxv5aVA1HwUpB+tfZQ7Pug3pO1rn9D1i1B/27+GqlqXj95zmzcQg+fCfK43WpH9xLbtx2xo+UveIXQFjWZpHJQ6SVwSScb7AZKX3HYo219L1ch9PjzWPFx65eWItJlWULqouMc4vN+gv94khsG 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: List-Subscribe: List-Unsubscribe: Directly use a folio for HugeTLB and THP when calculate the next pfn, then remove unused head variable. Reviewed-by: Miaohe Lin Acked-by: David Hildenbrand Signed-off-by: Kefeng Wang --- mm/memory_hotplug.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 38ecd45c3f94..9ef776a25b9d 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1773,7 +1773,7 @@ static int scan_movable_pages(unsigned long start, unsigned long end, static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) { unsigned long pfn; - struct page *page, *head; + struct page *page; LIST_HEAD(source); static DEFINE_RATELIMIT_STATE(migrate_rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); @@ -1786,14 +1786,20 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) continue; page = pfn_to_page(pfn); folio = page_folio(page); - head = &folio->page; - if (PageHuge(page)) { - pfn = page_to_pfn(head) + compound_nr(head) - 1; - isolate_hugetlb(folio, &source); - continue; - } else if (PageTransHuge(page)) - pfn = page_to_pfn(head) + thp_nr_pages(page) - 1; + /* + * No reference or lock is held on the folio, so it might + * be modified concurrently (e.g. split). As such, + * folio_nr_pages() may read garbage. This is fine as the outer + * loop will revisit the split folio later. + */ + if (folio_test_large(folio)) { + pfn = folio_pfn(folio) + folio_nr_pages(folio) - 1; + if (folio_test_hugetlb(folio)) { + isolate_hugetlb(folio, &source); + continue; + } + } /* * HWPoison pages have elevated reference counts so the migration would