From patchwork Sat Aug 17 08:49:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13767069 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 43E1BC52D7D for ; Sat, 17 Aug 2024 08:54:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57C546B017F; Sat, 17 Aug 2024 04:54:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D56A6B0282; Sat, 17 Aug 2024 04:54:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 235706B017F; Sat, 17 Aug 2024 04:54:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CCA986B0283 for ; Sat, 17 Aug 2024 04:54:07 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7441A1A0537 for ; Sat, 17 Aug 2024 08:54:07 +0000 (UTC) X-FDA: 82461125334.03.77A9AF2 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf03.hostedemail.com (Postfix) with ESMTP id BC0DA20009 for ; Sat, 17 Aug 2024 08:54:03 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723884784; a=rsa-sha256; cv=none; b=p2E8QBaT0vg1OsvYU6Mm5PEPJox5HAmBs2OGyuKI43WggTA291iUa0A9iKiT3zyWOK7Wcf DQNavaatpw5LIASBB4sfiKbRpc/WzPv/YyP15rjxYjB4rTPtJ5lHor/u9xoWlbpMshAI04 Qiysg2ciota/kBQGRyBdjPTo882UbAY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.35 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=1723884784; 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=r+c1gcN4OuvNzeGJthnLiu58/EiznLaJlYlDrS3BRXs=; b=O1aKuHgoWO3e5VESjyuUpxeRKKnjfjS2Qxeghqaox8YjkY2sxXL2BGa60cjbXRFr5GgR/t o5WqUCjrVB4OfygiEHTVgLpnwC/Pch1m4LXJsa64jq3FECURU4lGuIqNBoaFeheg9dI+XL 77I1dZsp2M5w5NZdPLRgSXQoDy6iwmA= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4WmCFq4SYVz1S7c9; Sat, 17 Aug 2024 16:49:03 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id B5B42140154; Sat, 17 Aug 2024 16:53:59 +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; Sat, 17 Aug 2024 16:53:59 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , Kefeng Wang Subject: [PATCH v2 1/5] mm: memory_hotplug: remove head variable in do_migrate_range() Date: Sat, 17 Aug 2024 16:49:37 +0800 Message-ID: <20240817084941.2375713-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240817084941.2375713-1-wangkefeng.wang@huawei.com> References: <20240817084941.2375713-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemf100008.china.huawei.com (7.185.36.138) X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BC0DA20009 X-Stat-Signature: u6fgerxhj3yceqkfafk7g5xpas5y5er1 X-Rspam-User: X-HE-Tag: 1723884843-710625 X-HE-Meta: U2FsdGVkX1/UdT0kwHxx6yRCHDKCrGsVMsaMS4MY98tP9xSaX551dokk+DE9szI3MlzntdKSbl8+rem9hV7HIwstmbstLdBxc1N0hgoYjfOlsWUXervKpG/f3MOh6aEwJX4XbcVOAKDVb1qzbsG2OYqQaPgOujbu7r0WHDBsyj0pRMECDXjOICEz7+Gzn9/tH1xJY0zfA++Th7iyZm7D8WhXV8jtDCa4xoIyUBUUTrb2PWYzZEEX+dIHWbw9ItSXLxIn5WQkgwzScF0gv7DqMN4XhGheWkviBWvX0v2ruzU30IVY5mBfmm28Ar53zRkJS9JqNfympeOmdMuX4Xt/fhJpEfB/cbfUlJjoSa0d0uwQg93gKzicLO4wfl5OUhw2Q0P9jP1VkHRV8zHHjpK9ASG6UpcdzO4QHay0hA5famgOFcpRrnPYebM4t/R0NI6HLaJQy+XXIhKYeLYzavp7cRHkCyDZR/5xETJ9TP8IZV/s5ezgKNCGrUfUSaiuK3sflap61iWvjw0vMMhuPMa2E8DKmxjsRK1nEO27m2NZOiYSHSKcIYmFv17zlMsHCss6J6vl2zdI0vt+hJ0W5/kTk7D5RqzgaQWyaj2blPy0krq8AH/BLkCpLSKb3k7v1Bv8kEu1KPhH73ErlyFjPdRWIAvk7Ac+3qhSBBl7XVcnpoJ3KdMk61G6AMnj4ZdYChzMUaehSjjXuM8gI5hpA7GBe0y8rSn7Kd5UT2ml9l4As4ygu1D439oVUPfahZO4vV+mi7ZucJOZP6FzEnnRqXKS9vahNa7iWHA+2YCXFYPb3GcU3JeE9Cfrm6uQxvh8qdaKUDRo7EeQg3QVblL3Lj2WqMtvor43sNH+WKocdEe+c91ArjewOWTEPNKrRwXkWoNdFCCZDOA8wBd8gO40TOPoKymJHEoSw6FbN+RJpPf/WvoU5Qj1VgzX6fmlDyJAc4CamKzSDNrIjE/JJp7f5is X1yd4qel n/2lNba8rvbo5oYl/tH5lkw3kpuPBzg7g4bnqHI54N1afXmOPXihHrNopfEficGCauiDPKFQ2xg311Jm0JFJafNn6eQ8GEl02fqNKjMDqrR3oD32o0zYDy3m/1wpIEePLCgacrsV7zeBvfKQ/1/YHR8jSTBXXKrOKgaCPT72+tRoYBKhHc2EmwLxKHYOwiH8egaXw0URFtSmkxPYS08AZzo+J2PgmtfMAHm+Z6dsg6d5a/uqmtttZDpsmc7G71TnPWKtA 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. Signed-off-by: Kefeng Wang Reviewed-by: Miaohe Lin Acked-by: David Hildenbrand --- 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 df291f2e509d..dc19b0e28fbc 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; + /* + * The folio hold no reference or lock, it might be changed + * concurrently(eg, split), folio_nr_pages() may read garbage, + * but out loop could handle that as it revisits 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