From patchwork Fri Aug 16 09:04:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13765783 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 6C2B3C3DA4A for ; Fri, 16 Aug 2024 09:05:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBFA96B00D2; Fri, 16 Aug 2024 05:05:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E6F696B00D4; Fri, 16 Aug 2024 05:05:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D10D26B00D6; Fri, 16 Aug 2024 05:05:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B0E046B00D2 for ; Fri, 16 Aug 2024 05:05:49 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 74A5B1619D7 for ; Fri, 16 Aug 2024 09:05:49 +0000 (UTC) X-FDA: 82457526018.02.972C409 Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf08.hostedemail.com (Postfix) with ESMTP id 380CF16000F for ; Fri, 16 Aug 2024 09:05:46 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf08.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.32 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=1723799074; 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=F9V6vtzmymLxPi8zqHe75k6AQGMlfqWwO+fGi+Nuqww=; b=ImAJS7VaCWX1mOw1Tl0WGRzOoyfpkGIiqEaVDvZmPa8v8cjILK8plgX9OuNoMDtXq38Auh k+TYNJe4EIQcHzs7jkRij9lC1oNBhpBbwIq1s03Ul5KSHTZkne4A1WbWUVXPa6lwAh732I LwkfYx1pWJr6gWz1TENtT7mmJdMbFjk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723799074; a=rsa-sha256; cv=none; b=Kt+HYRBT717OhJd7uCKuGVPICa1ys66jzcc8i0YIJxhjvLWsasWhHw8Y4D8+O6Q/itxktw 7bgbFbPLJysqMcb9Kgg+a8pApY7q94cmjsO971RafyhTVZUTaNXYZz8Ct6vEVq+8E1cyqV 7DjfJSSk9lNF2Y44NFvDHMFb0pbJE9Q= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf08.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.32 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4Wlbcf0ctdz1xvNW; Fri, 16 Aug 2024 17:03:14 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 5B68314037D; Fri, 16 Aug 2024 17:05:06 +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; Fri, 16 Aug 2024 17:05:05 +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: Fri, 16 Aug 2024 17:04:31 +0800 Message-ID: <20240816090435.888946-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240816090435.888946-1-wangkefeng.wang@huawei.com> References: <20240816090435.888946-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: 380CF16000F X-Stat-Signature: yrdqh5xh4ycu35k8zbc5cf674fjc5hwn X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1723799146-939428 X-HE-Meta: U2FsdGVkX1/9tHgpBodWnYnijnUaT1YCbAGbdJyKMl7Q2NrwhsDkHkF9b4a8bHQevGgblkh7ngh3CQtSVmYz6tlz4ctd3UJJYxxbiGG+6fMywha8LX4P1cPTH6SL1e1C/ePlsGQ8BLnmONASov0QzI+Pz8/ih063te9QcDQHumWhuOU99b1lQCy+QVQ/w6N94PUUDQRgzSQg+xjO1jzp7Xb4ioEQwIM5q1JfVpUIDdmmdfTWcBHGr2leuyUGPSfCjjqDNiaIftjMRpepG99tHE/2RD86e7BPPDWq17JfVqqEXC7O/7j7kfcaQdFmc6fUdWwAsrsmly79n8rvYzZYP1OVhwX7o6YkBk6KVDya8LAYOFQ1KO+dEQZ5TtupAR5UD6hCGOPOYNdRFxHfb5l+FGHZL78TN8sdyvVtJecondNM7G9um0lYz37kB0AAft/zs9jH0m1LbpyizAjBFdkdtGdL85GAZDegOox92YUaoaBP3AkTIHoauQeuhCm7TZ7wuZqnq9fLFuhl5FWRFxaspHSgGldlANgj1JpXmUyGh721Hny9U0bZms9VBGcfveMQgAGRNQexaLJkS+OXrdlmrrCCcvFNVt30p58Y0+4ByuepPEfByxnp/zTSZ1p6wTpLaeRYmUmF6RCDho6YZsdq/2hdZN/oALhbmBxtonUEl2aQUre+tZAYOBdtmBFAAlqTxg/KsIurreu5M+mfLzxGQoe6dwIwMrg+kIiWDvqoLw/gSqAQfTD1qg4EMwwt8JrD/tjKcaxXhe68K6hL77XVVVuh6d/QNDfivwZWHoMzC1xEGf3KKIofrS6Hp/vb3X+M4b43ayqIkdRG+Bcttdk32aAmD1iOz0ThFbd1Iz5Gb96UnWOa6by5d41xiBafkw2bP0+Pg258lsLu1qPnb2wk6KOrbAlvewfVFQECupCl1tIEKOBgaTo1srfgQQO8BYloBs5VBayB9P7NSejHB/v eikXSfvv AGI4pa+SGPB6EvrkKdECsvFxF3LqWgToeFV4WI+yLjPNrA+Wd4KpqU745/+/Wm++dYPQ9K3tD5pTaMjfuYpzwmWdYXXATHiJIMkKKKuR8Jyqb5GdRgy3ec3TdgOLes4juQIiM8Row2qCdBbM8puo5ZTMYLb9S6Ga6+nDDt0Kloqls2n0xJYsM7MaeiF2z6JecqsokhEKJe/bcg1oaGF6TYCRUV5lH3FG5oXxFTdeIV9TH2owImPVg1tDICkKhqv2corOw 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 --- 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..7c674cec3c18 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); + continue; + } + } /* * HWPoison pages have elevated reference counts so the migration would