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 From patchwork Fri Aug 16 09:04:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13765785 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 929BEC3DA4A for ; Fri, 16 Aug 2024 09:05:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C0AFF6B0114; Fri, 16 Aug 2024 05:05:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A195B6B0116; Fri, 16 Aug 2024 05:05:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 681E26B011E; Fri, 16 Aug 2024 05:05:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1ED016B00D4 for ; Fri, 16 Aug 2024 05:05:50 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B37A7C1A01 for ; Fri, 16 Aug 2024 09:05:49 +0000 (UTC) X-FDA: 82457526018.04.4E65503 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf27.hostedemail.com (Postfix) with ESMTP id 23C1440002 for ; Fri, 16 Aug 2024 09:05:46 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 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=1723799065; 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=D6fIsSygiHw7ao2LpsxFR4VWJoD82NgGLk9UhUYZyKs=; b=hkyBc4wz3CowCVTZt7I2hoGFJteUw55CfpeFlvHgE2k8qeIu1wA8YFjcrXA5WF9VLu1uYa 5jgzc38Hn3VmYIxWOld3WM1kzp3KLpcpjO+ev6emi4D4N9nTUfxNZ3DcISw3uvuZUrg9gw I6vJLpPzENDOPxZd20Tq+KSkln4vGXE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723799065; a=rsa-sha256; cv=none; b=HgO5Vn3qG6bcx8Y3qZJDH1SDZpwFcOZrmlkPZ9glamyRJIchcg2bjBzLS/CI5RAdS2LGuk ii0uxGHmviN2xEFygnhUsFpluLPI53JcqZSwedq1RuiYcO583ciNRZA51LzVcUSQdbyDZ+ MTrF4JZ9M7BX+oVw19SrDXQrK7epSTI= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WlbY83X7Tz1j6Z9; Fri, 16 Aug 2024 17:00:12 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id C7B0B1A016C; 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:06 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , Kefeng Wang Subject: [PATCH v2 2/5] mm: memory-failure: add unmap_posioned_folio() Date: Fri, 16 Aug 2024 17:04:32 +0800 Message-ID: <20240816090435.888946-3-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-Server: rspam07 X-Rspamd-Queue-Id: 23C1440002 X-Stat-Signature: x6ubao6j3muaqj5wdt8muwx9r865n4px X-Rspam-User: X-HE-Tag: 1723799146-496706 X-HE-Meta: U2FsdGVkX1/0bsgA36PlGMJx7a1p2oDgOlMJVM+cQ138MBGvvOT1uwnpRX1zbHJm7BZYbW7Eobx+ILt6RNk3SE4N49IRGhqNTZ/nDSODEqWaCoq9HPJKZ2oNX+l6Uo/dyDSTF2d6PI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QKzl1C2y27910u5mH33OpQ5B+KIRW5blAqcIvYpRK3FBtKrjOGefhR7l+9Yps5IlOglP 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: Add unmap_posioned_folio() helper which will be reused by do_migrate_range() from memory hotplug soon. Acked-by: David Hildenbrand Signed-off-by: Kefeng Wang --- mm/internal.h | 9 +++++++++ mm/memory-failure.c | 43 ++++++++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index adbf8c88c9df..5b80c65f82b6 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1054,6 +1054,8 @@ static inline int find_next_best_node(int node, nodemask_t *used_node_mask) /* * mm/memory-failure.c */ +#ifdef CONFIG_MEMORY_FAILURE +int unmap_posioned_folio(struct folio *folio, enum ttu_flags ttu); void shake_folio(struct folio *folio); extern int hwpoison_filter(struct page *p); @@ -1074,6 +1076,13 @@ void add_to_kill_ksm(struct task_struct *tsk, struct page *p, unsigned long ksm_addr); unsigned long page_mapped_in_vma(struct page *page, struct vm_area_struct *vma); +#else +static inline int unmap_posioned_folio(struct folio *folio, enum ttu_flags ttu) +{ + return 0; +} +#endif + extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long); diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 353254537b54..93848330de1f 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1554,6 +1554,30 @@ static int get_hwpoison_page(struct page *p, unsigned long flags) return ret; } +int unmap_posioned_folio(struct folio *folio, enum ttu_flags ttu) +{ + if (folio_test_hugetlb(folio) && !folio_test_anon(folio)) { + struct address_space *mapping; + /* + * For hugetlb pages in shared mappings, try_to_unmap + * could potentially call huge_pmd_unshare. Because of + * this, take semaphore in write mode here and set + * TTU_RMAP_LOCKED to indicate we have taken the lock + * at this higher level. + */ + mapping = hugetlb_folio_mapping_lock_write(folio); + if (!mapping) + return -EAGAIN; + + try_to_unmap(folio, ttu|TTU_RMAP_LOCKED); + i_mmap_unlock_write(mapping); + } else { + try_to_unmap(folio, ttu); + } + + return 0; +} + /* * Do all that is necessary to remove user space mappings. Unmap * the pages and send SIGBUS to the processes if the data was dirty. @@ -1615,23 +1639,8 @@ static bool hwpoison_user_mappings(struct folio *folio, struct page *p, */ collect_procs(folio, p, &tokill, flags & MF_ACTION_REQUIRED); - if (folio_test_hugetlb(folio) && !folio_test_anon(folio)) { - /* - * For hugetlb pages in shared mappings, try_to_unmap - * could potentially call huge_pmd_unshare. Because of - * this, take semaphore in write mode here and set - * TTU_RMAP_LOCKED to indicate we have taken the lock - * at this higher level. - */ - mapping = hugetlb_folio_mapping_lock_write(folio); - if (mapping) { - try_to_unmap(folio, ttu|TTU_RMAP_LOCKED); - i_mmap_unlock_write(mapping); - } else - pr_info("%#lx: could not lock mapping for mapped huge page\n", pfn); - } else { - try_to_unmap(folio, ttu); - } + if (unmap_posioned_folio(folio, ttu)) + pr_info("%#lx: could not lock mapping for mapped huge page\n", pfn); unmap_success = !folio_mapped(folio); if (!unmap_success) From patchwork Fri Aug 16 09:04:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13765782 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 B0479C531DE for ; Fri, 16 Aug 2024 09:05:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE04A8D0059; Fri, 16 Aug 2024 05:05:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC6908D005A; Fri, 16 Aug 2024 05:05:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 918FE8D0059; Fri, 16 Aug 2024 05:05:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 68E488D005A for ; Fri, 16 Aug 2024 05:05:14 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A8BB1141B25 for ; Fri, 16 Aug 2024 09:05:13 +0000 (UTC) X-FDA: 82457524506.04.9963BE4 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf17.hostedemail.com (Postfix) with ESMTP id F36BF40027 for ; Fri, 16 Aug 2024 09:05:10 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723799057; a=rsa-sha256; cv=none; b=xIyCGI2WpUdJXwWGdck1dQVR3apWVRU3wZNIi4Q881AMQfbWNMZ9oxOeOwjUq8GiKemSlf cIFQxxzTDaJx6yvvzX6/i7Q7AWSAHqHUxApHOY/SkeHp5uAOmin9YnYw8mnz1+VNzb43Bz nRQ+DzAoGcCPCljHxgrqLzgbGS+DqnU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1723799057; 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=khJuWYhZwI8BbxRlqM3Mz7vStZbppgfXOQKESbVVV5M=; b=dX1Hr3MrR01vCBh+9aogq4IEUxP2d435PJQtGfmQzD9C97kxY0RdRH/LdlMox7uDCK3pfN DB3HHTU98Eii7/Y5FveeVa0DJQiIndQAAIZWq8FhjtIDFS6NRtXHVpaozpSGKwlJWLeZhg pgL4CJAbAWf1DRw5l9Sk721DdCzf0mc= Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WlbfV1KkyzcdXF; Fri, 16 Aug 2024 17:04:50 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 42501140137; Fri, 16 Aug 2024 17:05:07 +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:06 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , Kefeng Wang Subject: [PATCH v2 3/5] mm: memory_hotplug: check hwpoisoned page firstly in do_migrate_range() Date: Fri, 16 Aug 2024 17:04:33 +0800 Message-ID: <20240816090435.888946-4-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: F36BF40027 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: dgn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HuqXv00zw8m4zx7UwZJlThLGvnDbTa9nOw2zp7bsZhDjQkEijnoV/M7MRYk4KUnOV2bV9dOWFbiptn9XQMX3OPNJhTe/yrx3nR97n8uYSAi85lmCTkv3TxjgwpK9QtIdbreu6Qwfmpn76vb4MsIgHezgcujxwfV9W8mV/aq+aHsvJE9FWcWjClw2O/OCDfCqWW3uW+aW+Sr57/Bm4mAOY9gEfaT2ZaOxQToR7IK8uXq6SlWlNmaQE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The commit b15c87263a69 ("hwpoison, memory_hotplug: allow hwpoisoned pages to be offlined") don't handle the hugetlb pages, the endless loop still occur if offline a hwpoison hugetlb, luckly, with the commit e591ef7d96d6 ("mm,hwpoison,hugetlb,memory_hotplug: hotremove memory section with hwpoisoned hugepage") section with hwpoisoned hugepage"), the HPageMigratable of hugetlb page will be clear, and the hwpoison hugetlb page will be skipped in scan_movable_pages(), so the endless loop issue is fixed. However if the HPageMigratable() check passed(without reference and lock), the hugetlb page may be hwpoisoned, it won't cause issue since the hwpoisoned page will be handled correctly in the next movable pages scan loop, and it will be isolated in do_migrate_range() but fails to migrate. In order to avoid the unnecessary isolation and unify all hwpoisoned page handling, let's unconditionally check hwpoison firstly, and if it is a hwpoisoned hugetlb page, try to unmap it as the catch all safety net like normal page does. Signed-off-by: Kefeng Wang --- mm/memory_hotplug.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 7c674cec3c18..02a0d4fbc3fe 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1793,13 +1793,8 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) * but out loop could handle that as it revisits the split * folio later. */ - if (folio_test_large(folio)) { + 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 @@ -1808,11 +1803,17 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) * (e.g. current hwpoison implementation doesn't unmap KSM pages but keep * the unmap as the catch all safety net). */ - if (PageHWPoison(page)) { + if (folio_test_hwpoison(folio) || + (folio_test_large(folio) && folio_test_has_hwpoisoned(folio))) { if (WARN_ON(folio_test_lru(folio))) folio_isolate_lru(folio); if (folio_mapped(folio)) - try_to_unmap(folio, TTU_IGNORE_MLOCK); + unmap_posioned_folio(folio, TTU_IGNORE_MLOCK); + continue; + } + + if (folio_test_hugetlb(folio)) { + isolate_hugetlb(folio, &source); continue; } From patchwork Fri Aug 16 09:04:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13765781 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 758F5C531DC for ; Fri, 16 Aug 2024 09:05:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5242B6B00AB; Fri, 16 Aug 2024 05:05:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 484598D0059; Fri, 16 Aug 2024 05:05:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 295606B00AF; Fri, 16 Aug 2024 05:05:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F06EF8D0059 for ; Fri, 16 Aug 2024 05:05:13 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A18B281A1E for ; Fri, 16 Aug 2024 09:05:13 +0000 (UTC) X-FDA: 82457524506.05.99D4728 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf20.hostedemail.com (Postfix) with ESMTP id CF96F1C000B for ; Fri, 16 Aug 2024 09:05:10 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723799098; 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=JZgsubj0IZR+728WrHLKeUMAqlRqiJF4zEKWK7JasHw=; b=dHNZs/RuFPhBOGEcInFchup8vNAKnDwAUUp8ff0wi2eSPp4B5RFxDYDPwA6mYJm63kOX3D LBp0M0OJtaedIYOsmfEnrsOShj//YNfwoHUuxwhhQpZwMLooUBNOML0ZW1FiC4wnCem/w5 Hqyw/LX/sBQqSQ7t/NRDL7RSAYpR3RA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=pass (imf20.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723799098; a=rsa-sha256; cv=none; b=Y65q9BHhMU5dCVQxZ1cYkZ820naDO4zFcXSXeJ6NNS0wyczwc8Z0LVAewDqTl0FOvd5xyv a9xwE/b++QC4ZfkFuun7QyPBbxywjn2/g2qPFSMNIkfUVBX9tSVD1w6Y2rAHchb2jmpEUn uFtzrb75Js7FhcxY5UZac5V05kV6Kwo= Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4WlbYW18HHzQq1Q; Fri, 16 Aug 2024 17:00:31 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id AC8851401E9; Fri, 16 Aug 2024 17:05:07 +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:07 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , Kefeng Wang Subject: [PATCH v2 4/5] mm: migrate: add isolate_folio_to_list() Date: Fri, 16 Aug 2024 17:04:34 +0800 Message-ID: <20240816090435.888946-5-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-Rspam-User: X-Stat-Signature: qexpw63scweqzgj9dxfbben1izpu7fre X-Rspamd-Queue-Id: CF96F1C000B X-Rspamd-Server: rspam11 X-HE-Tag: 1723799110-801107 X-HE-Meta: U2FsdGVkX1/3HIL9gfKeG1/KBOBMzibHRDb0Ov1ftx0I3kvEF4ik9XFGr/o4Ty0bDcbusby+WyV/WyV/5tLxJWxKXm2kjYhIuZ2HOunx5nZtm9KoWVVuQsUSXhx3lI91wsELYSG/0mPxpsMO8N8txs55/T4cpGcx3ff/2KuRcQM3SSIcL5G6lpeAmagsT5iJXMWvPy5dL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, 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: Add isolate_folio_to_list() helper to try to isolate HugeTLB, no-LRU movable and LRU folios to a list, which will be reused by do_migrate_range() from memory hotplug soon, also drop the mf_isolate_folio() since we could directly use new helper in the soft_offline_in_use_page(). Acked-by: David Hildenbrand Signed-off-by: Kefeng Wang --- include/linux/migrate.h | 3 +++ mm/memory-failure.c | 46 ++++++++++------------------------------- mm/migrate.c | 27 ++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 644be30b69c8..002e49b2ebd9 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -70,6 +70,7 @@ int migrate_pages(struct list_head *l, new_folio_t new, free_folio_t free, unsigned int *ret_succeeded); struct folio *alloc_migration_target(struct folio *src, unsigned long private); bool isolate_movable_page(struct page *page, isolate_mode_t mode); +bool isolate_folio_to_list(struct folio *folio, struct list_head *list); int migrate_huge_page_move_mapping(struct address_space *mapping, struct folio *dst, struct folio *src); @@ -91,6 +92,8 @@ static inline struct folio *alloc_migration_target(struct folio *src, { return NULL; } static inline bool isolate_movable_page(struct page *page, isolate_mode_t mode) { return false; } +static inline bool isolate_folio_to_list(struct folio *folio, struct list_head *list) + { return false; } static inline int migrate_huge_page_move_mapping(struct address_space *mapping, struct folio *dst, struct folio *src) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 93848330de1f..d8298017bd99 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2659,40 +2659,6 @@ EXPORT_SYMBOL(unpoison_memory); #undef pr_fmt #define pr_fmt(fmt) "Soft offline: " fmt -static bool mf_isolate_folio(struct folio *folio, struct list_head *pagelist) -{ - bool isolated = false; - - if (folio_test_hugetlb(folio)) { - isolated = isolate_hugetlb(folio, pagelist); - } else { - bool lru = !__folio_test_movable(folio); - - if (lru) - isolated = folio_isolate_lru(folio); - else - isolated = isolate_movable_page(&folio->page, - ISOLATE_UNEVICTABLE); - - if (isolated) { - list_add(&folio->lru, pagelist); - if (lru) - node_stat_add_folio(folio, NR_ISOLATED_ANON + - folio_is_file_lru(folio)); - } - } - - /* - * If we succeed to isolate the folio, we grabbed another refcount on - * the folio, so we can safely drop the one we got from get_any_page(). - * If we failed to isolate the folio, it means that we cannot go further - * and we will return an error, so drop the reference we got from - * get_any_page() as well. - */ - folio_put(folio); - return isolated; -} - /* * soft_offline_in_use_page handles hugetlb-pages and non-hugetlb pages. * If the page is a non-dirty unmapped page-cache page, it simply invalidates. @@ -2744,7 +2710,7 @@ static int soft_offline_in_use_page(struct page *page) return 0; } - if (mf_isolate_folio(folio, &pagelist)) { + if (isolate_folio_to_list(folio, &pagelist)) { ret = migrate_pages(&pagelist, alloc_migration_target, NULL, (unsigned long)&mtc, MIGRATE_SYNC, MR_MEMORY_FAILURE, NULL); if (!ret) { @@ -2766,6 +2732,16 @@ static int soft_offline_in_use_page(struct page *page) pfn, msg_page[huge], page_count(page), &page->flags); ret = -EBUSY; } + + /* + * If we succeed to isolate the folio, we grabbed another refcount on + * the folio, so we can safely drop the one we got from get_any_page(). + * If we failed to isolate the folio, it means that we cannot go further + * and we will return an error, so drop the reference we got from + * get_any_page() as well. + */ + folio_put(folio); + return ret; } diff --git a/mm/migrate.c b/mm/migrate.c index 6e32098ac2dc..7b7b5b16e610 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -178,6 +178,33 @@ void putback_movable_pages(struct list_head *l) } } +/* Must be called with an elevated refcount on the non-hugetlb folio */ +bool isolate_folio_to_list(struct folio *folio, struct list_head *list) +{ + bool isolated = false; + + if (folio_test_hugetlb(folio)) { + isolated = isolate_hugetlb(folio, list); + } else { + bool lru = !__folio_test_movable(folio); + + if (lru) + isolated = folio_isolate_lru(folio); + else + isolated = isolate_movable_page(&folio->page, + ISOLATE_UNEVICTABLE); + + if (isolated) { + list_add(&folio->lru, list); + if (lru) + node_stat_add_folio(folio, NR_ISOLATED_ANON + + folio_is_file_lru(folio)); + } + } + + return isolated; +} + static bool try_to_map_unused_to_zeropage(struct page_vma_mapped_walk *pvmw, struct folio *folio, unsigned long idx) From patchwork Fri Aug 16 09:04:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13765784 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 965DEC531DE for ; Fri, 16 Aug 2024 09:05:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BF0A6B0111; Fri, 16 Aug 2024 05:05:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F9676B00D4; Fri, 16 Aug 2024 05:05:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FBAD6B0114; Fri, 16 Aug 2024 05:05:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 248926B00D6 for ; Fri, 16 Aug 2024 05:05:50 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C2C1D819F2 for ; Fri, 16 Aug 2024 09:05:49 +0000 (UTC) X-FDA: 82457526018.30.D9C5971 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf25.hostedemail.com (Postfix) with ESMTP id 5D039A0014 for ; Fri, 16 Aug 2024 09:05:46 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723799134; a=rsa-sha256; cv=none; b=AHtzyS1rDiAYuFZv0FPn1cQ2wQ+Y7mq6A2uIM+kO4wCU9xLVlDq+/0Bk8FgEPOaTJZq0im do9R1eDwWQ3Td8Ax2mwKsKxMaGJAVr93snIobqktu/MBFc/xkPrR2CG+T7YjIb1A81YjKj h5sAKVo+5U0k9HzaIgtOs+K386GtTUs= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf25.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 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=1723799134; 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=k4PijjS54tHclFDjnkXcHqSsxQhhlIxc0hCoJeNbyJA=; b=VDMNSzTRX/tXCJALQX0Fxvo8w7ujpLd7aJU7xgSVFC8RfgfPRjUluzWSOy4OGG+Ue73tLV WvYDKNsciYltDpQQW3qvcr+2mbkF6x3+Sa+tJJv2CM643gaDo9qlCk08Is1Oi07bDfJz+9 acgUtJalqWAwZJL/xGyVi10+gjedhCc= Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WlbY962fPz1j6ZC; Fri, 16 Aug 2024 17:00:13 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 29CC014010C; Fri, 16 Aug 2024 17:05:08 +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:07 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , Kefeng Wang Subject: [PATCH v2 5/5] mm: memory_hotplug: unify Huge/LRU/non-LRU movable folio isolation Date: Fri, 16 Aug 2024 17:04:35 +0800 Message-ID: <20240816090435.888946-6-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-Rspam-User: X-Rspamd-Queue-Id: 5D039A0014 X-Rspamd-Server: rspam01 X-Stat-Signature: r1pqdzotwh83w131e89xfnj4odcmd81t X-HE-Tag: 1723799146-221472 X-HE-Meta: U2FsdGVkX1/sfDdXROIce2O8/QIKr0rCACMd5Iyqh6D8+1MfvKXT5VDhi2dsAeyA5x+WfvZBQ0RzgDCBFrO6I3FFMTc4e37RAs+OlgfrpXE6hc329PPtbP0jSYFc3XLi/DfsCs5oH1z/FhqjXomcLvzOoUBv2BVH+x60mAa/IqhdVTv0X5Ducv07VHjGyKnyRDZXpkNDhJZSnafKYmTvak78dWXGbgOlHE5wSrOqauP5Q9MtEI32mY/8Wv8fw72q5TrvUvDm5uuHwhhmgXmGVpDj1VZx/yq9DT8r+LXPw5W6wduyl/sD4aNUfNUOXAzTKkZQW5DFx4gUtd+aDSAI23KOKXhK1UO8A8bM/3iH01lmB+eTh6vKjYmJtrmnShRIt4DJfV34wtxXyyLkSqUKngxhVytHoerH/aJvFdAJdeNiqpMuCPdAngbETPPoDOtaMV6MhPIULEBpBjUjb+3L9f8yUSQqh+QTMe5RjNJFyol+Z9TBj8cObKHZiDbyWXNFsGlR+8TQoykYUgyNCsKsTNMJ48FrcQalHyFUsf15N8lR2hr+m/QOSevb7N4NUfG4QNOwDWT7Flp/HQRr1XLG9nowhp241L5r4HvMlDTrRPp4D+v6OhVSOz49KTvLy9DEDRa1KFG1AASvhTT1GumXeVuZIl+bF1HrfJ71uMaFCdctuLWtTne+WHWLldc/3jiZ28IvBRApon/XVQv3pNlygiJZ2GDaJ9jbzxbu9ZsVmzcnqprs6WEHrYrObbcpT2u43kBlXPhHHwRWQtSsnBLfu8XuATHcBgVTnX7vdDRQ7qvXUONFnBMbjHwjfTYcj4XoeNws0pKUpfJD9/njSErUMhOAqj3tbmKJVVioxHSEnNzCtahjQLTxBqNodcFSVGozIOxOrDNwKvBRi6b++jDLywM73v2owaa4QNhXvU0Wb/p07mV0BcAYogKwC6UNyqauKO/CJTsJicUKvvOzsSZ a12jwUZ9 StIr4lwP0dgiUJ9AKSyB8VWPFUlHeM7JoXP5pDTn8tCaCSWQVs3z0vVqP7oW7QQoBjDx5cKnyHsOaNPDE3Ucwzw0fraJjKOM8ocTfNZj3Czw+e8f7+YGbeqDLmaWqzNBb0iMUg/YY8vnGIQOGOvh5VScYhTiBCXG3ONJfszKUIm5K5o8DOJu9pqe6hvoAACc3Kd3K3BGy8vpaT3YulcAE+2ZRGX0slNNVLA9totI1kXPiUqAEQCSsVnjb0H8u/LR2tWdL 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: Use the isolate_folio_to_list() to unify hugetlb/LRU/non-LRU folio isolation, which cleanup code a bit and save a few calls to compound_head(). Signed-off-by: Kefeng Wang --- mm/memory_hotplug.c | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 02a0d4fbc3fe..cc9c16db2f8c 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1773,14 +1773,14 @@ 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; LIST_HEAD(source); + struct folio *folio; static DEFINE_RATELIMIT_STATE(migrate_rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); for (pfn = start_pfn; pfn < end_pfn; pfn++) { - struct folio *folio; - bool isolated; + struct page *page; + bool huge; if (!pfn_valid(pfn)) continue; @@ -1812,34 +1812,22 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) continue; } - if (folio_test_hugetlb(folio)) { - isolate_hugetlb(folio, &source); - continue; + huge = folio_test_hugetlb(folio); + if (!huge) { + folio = folio_get_nontail_page(page); + if (!folio) + continue; } - if (!get_page_unless_zero(page)) - continue; - /* - * We can skip free pages. And we can deal with pages on - * LRU and non-lru movable pages. - */ - if (PageLRU(page)) - isolated = isolate_lru_page(page); - else - isolated = isolate_movable_page(page, ISOLATE_UNEVICTABLE); - if (isolated) { - list_add_tail(&page->lru, &source); - if (!__PageMovable(page)) - inc_node_page_state(page, NR_ISOLATED_ANON + - page_is_file_lru(page)); - - } else { + if (!isolate_folio_to_list(folio, &source)) { if (__ratelimit(&migrate_rs)) { pr_warn("failed to isolate pfn %lx\n", pfn); dump_page(page, "isolation failed"); } } - put_page(page); + + if (!huge) + folio_put(folio); } if (!list_empty(&source)) { nodemask_t nmask = node_states[N_MEMORY]; @@ -1854,7 +1842,7 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) * We have checked that migration range is on a single zone so * we can use the nid of the first page to all the others. */ - mtc.nid = page_to_nid(list_first_entry(&source, struct page, lru)); + mtc.nid = folio_nid(list_first_entry(&source, struct folio, lru)); /* * try to allocate from a different node but reuse this node @@ -1867,11 +1855,12 @@ static void do_migrate_range(unsigned long start_pfn, unsigned long end_pfn) ret = migrate_pages(&source, alloc_migration_target, NULL, (unsigned long)&mtc, MIGRATE_SYNC, MR_MEMORY_HOTPLUG, NULL); if (ret) { - list_for_each_entry(page, &source, lru) { + list_for_each_entry(folio, &source, lru) { if (__ratelimit(&migrate_rs)) { pr_warn("migrating pfn %lx failed ret:%d\n", - page_to_pfn(page), ret); - dump_page(page, "migration failure"); + folio_pfn(folio), ret); + dump_page(&folio->page, + "migration failure"); } } putback_movable_pages(&source);