From patchwork Thu Jul 25 01:16:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13741488 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 7ED1CC3DA63 for ; Thu, 25 Jul 2024 01:17:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4AAA6B0083; Wed, 24 Jul 2024 21:16:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE9A86B0095; Wed, 24 Jul 2024 21:16:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 803CE6B0092; Wed, 24 Jul 2024 21:16:58 -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 503366B0085 for ; Wed, 24 Jul 2024 21:16:58 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DFBA9140D1B for ; Thu, 25 Jul 2024 01:16:57 +0000 (UTC) X-FDA: 82376510874.21.49C9740 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf08.hostedemail.com (Postfix) with ESMTP id 2AC90160017 for ; Thu, 25 Jul 2024 01:16:54 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1721870167; 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=D+v9lNFi0AegKW6E5+crUO69itjTxP9IMrXOWgsbrdc=; b=GigxxsNa6fXqQ7Ya9pmiD1C0QsCLWEHO0d6b3kKluvxa5HEN/b2EuJrjEn/4vZCZCWLKUi 36dNE9WPye0gxSMxPkYfpvIvnxOynppFEnfJwEgyHrK8iYz975RIe2L3wpR4MLDl3+2NQU wCQ9L108pIMwsTnMcf50XyipA2sodD4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721870167; a=rsa-sha256; cv=none; b=aPA9NNybQd2TESNP2H3OLmH2VLstN7p815x72FdF/0J5PeQAMWFsM+Bx0XPvDmZ7Dsy+Go A6fTuOG6m0fp+8e757hzgXyJDEARO3Jl02647x7Q8Nzs70ROQOPHizACxl1UcxnmCrK4My O2yJ0UmjtG1EnKzCqYfltUAO1Ay6fKY= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WTtJc6wpHzxTrJ; Thu, 25 Jul 2024 09:16:48 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 272AF1402CB; Thu, 25 Jul 2024 09:16:52 +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; Thu, 25 Jul 2024 09:16:51 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Oscar Salvador , Miaohe Lin , Naoya Horiguchi , , Kefeng Wang Subject: [PATCH 3/4] mm: migrate: add isolate_folio_to_list() Date: Thu, 25 Jul 2024 09:16:46 +0800 Message-ID: <20240725011647.1306045-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240725011647.1306045-1-wangkefeng.wang@huawei.com> References: <20240725011647.1306045-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100008.china.huawei.com (7.185.36.138) X-Stat-Signature: q84467ikx61d7bbxnzz4eweqfjs1n1r6 X-Rspamd-Queue-Id: 2AC90160017 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1721870214-194212 X-HE-Meta: U2FsdGVkX1/voNT4uqoumdg9EKyFc7aPab1dydmefyOD7I6zkXriKqpj07eRZfx+c5yqWPHC1Yj+rXdpFtRIfj20S36xz6DB/VGFk9URGY4gUQ35YfY3ORAsdd19Nrg0lYJgAJgklqR4N1sabIiO/H3GQb1YzDZX3yjT7xVAfRov9MbU/h0Lsx2XfgEfZS1tc21pyJ2iptLNaYOxgwZhvgJAwRjiSaTEvZVyXQMjBKuE3JT+FSaZpcJqKn+pGgF1DDqCzAbkmANlN2ZsRndgwMfIiML9bYrMGCnI8IPqP+DNkXWgUaJ0B7sXFMwOwuoWG2H4oLaj1IPOD9//lYt9JO9ku9b2KHPVkmQrC8zowbh+c4c4j2CsJE5VoKs6/IQODD3RDG/68tJSmJ04WnpN94Nj3lhzb52+yW1nL6uw+2BeKdLY3Zt9HAMJuMVT2rr1u3QCpq60a2I9XMDRA51FClQGz/5rJJsqGn/GBrbcYJpe4Pzd4UbWBItUSObDywPEf/GtfffqSwkQvLqB9VXGS6WhDtXo35Ue2acoknzlnUPwGndWIh/PugpGCUQJNGkgT/VYR1XvqBzNQ0Czp43WbyKOowbUZ4MrrYhTx0vJBkmkcrUGo1SVuvaJbJD1KS9vUlRJDt/WR00ObZlhEzAGDYrllBPZqf8K8z5VmbMScBX1XHk01ZLfqhpmKn/mfxM1PBq644YatdVYj6/CQiEr8E46PJiIGRjNtPXhJSII6sV3g/lNOMffASUu+6M1B+pmF6Pk2ZbHY4wR8meOqoTesnapnUtLgQt8oTm8+ZPly6JDYHloEPcj5GM8LVSwRF4S+jHJ2/YMdOlS9LkUrPTN3FFQmt97NdXtZYHNp9sA1Xi5JN/VDoOIp/rgGXZFM6uz9q/gsjVgNPCQYDaq0kh8WdDFEXkZ6tR4OjeGra2TQFpVqeALhwy63W3XVF3yXh3GbyBEKNXcm9BkvuFEEx5 eYXC/yNe 4v9UUG96FQ46qAmy1AVus0j/56zbsTQXK8njiwvjPb19pl80MlqwZBqrflFJKRdA5kXLvdhi4aEESzOn9We1EPGaY0/C7zxA6NPjnyUKPYnLS1Gv8FW/2HJFecHdjbT4sYipY4HqJcWXcBtl6NmJ0VSTrzLkPKgUNvge/ohhkf2ur6zd5LweUzYtrjg7iYE1C51D6zsyh9dqTnuzUvjs5VlL8anDUEa0+h3sxiakrBvinNoobmEj4Jq5WJHx3s1a0IBiXcryJjdgjA2M= 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 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. Signed-off-by: Kefeng Wang Acked-by: David Hildenbrand --- mm/internal.h | 2 ++ mm/memory-failure.c | 21 +-------------------- mm/migrate.c | 27 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index c5bd24c4fa3a..2484191c0764 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -403,6 +403,8 @@ extern unsigned long highest_memmap_pfn; */ #define MAX_RECLAIM_RETRIES 16 +bool isolate_folio_to_list(struct folio *folio, struct list_head *list); + /* * in mm/vmscan.c: */ diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 99d92565cbb0..7e0f143bd51a 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2659,26 +2659,7 @@ EXPORT_SYMBOL(unpoison_memory); 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)); - } - } + bool isolated = isolate_folio_to_list(folio, pagelist); /* * If we succeed to isolate the folio, we grabbed another refcount on diff --git a/mm/migrate.c b/mm/migrate.c index e7296c0fb5d5..51cab1103502 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -177,6 +177,33 @@ void putback_movable_pages(struct list_head *l) } } +/* Must be called with an elevated refcount on the 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; +} + /* * Restore a potential migration pte to a working pte entry */