From patchwork Thu Apr 25 08:40:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13642966 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 1FC88C19F4E for ; Thu, 25 Apr 2024 08:40:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 866596B0092; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 778706B008A; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A8196B008C; Thu, 25 Apr 2024 04:40:56 -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 0AE3D6B0087 for ; Thu, 25 Apr 2024 04:40:56 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 85816140480 for ; Thu, 25 Apr 2024 08:40:55 +0000 (UTC) X-FDA: 82047408870.23.4A648EE Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf02.hostedemail.com (Postfix) with ESMTP id CCE648000B for ; Thu, 25 Apr 2024 08:40:52 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 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=1714034453; a=rsa-sha256; cv=none; b=13tABhgiqeaR7VCv73JjN4l1Qn3E6dytzMfaLRbiCZi9d2zIci4+EcMqoFKVZh2SJM/2YA e3zhfNFtgM4rJtgn7cy1BignSMprozM4lD1SalXu4Ex5BGUTCTar7YWXWA9uWzOkOUYcT+ mxZhQMHp0IRRf0z5/TBZ5hND+8D+XyE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 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=1714034453; 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=jMcGND5JzvfOIQ3yEYYI6abptlC3TzE6FGd8qMzjE8Q=; b=oIEtyYgm+PvpOoyFVjsqGWPSWCvN+2x54PGkl1l3QdFQeZBKSYbSWruxzWBLdXPEpwmc7Z p8hDMeXU2kSMSzR0kk9mJZUbJPoOaarM7tramFtTXyRpPnDFbzg4GJhxYkvBviX6DOZs4I 85JR8NGDRW3kQBiETGHWTRWCod14S0I= Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4VQ8Rk69jJz1HBkD; Thu, 25 Apr 2024 16:39:46 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 40FDA1A016F; Thu, 25 Apr 2024 16:40:49 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 25 Apr 2024 16:40:48 +0800 From: Kefeng Wang To: Andrew Morton CC: , David Hildenbrand , Miaohe Lin , Naoya Horiguchi , Oscar Salvador , Zi Yan , Hugh Dickins , Jonathan Corbet , , Vishal Moola , Kefeng Wang Subject: [PATCH v2 02/10] mm: add isolate_folio_to_list() Date: Thu, 25 Apr 2024 16:40:20 +0800 Message-ID: <20240425084028.3888403-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240425084028.3888403-1-wangkefeng.wang@huawei.com> References: <20240425084028.3888403-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 dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: CCE648000B X-Stat-Signature: winjwmrhycmecbsyiagi1jwmax8fgwbz X-Rspam-User: X-HE-Tag: 1714034452-784830 X-HE-Meta: U2FsdGVkX1/9Crp3gTGMBqWW4bnNsJS/3RWu+JCGRxc2pywu9A4cfl6vhHObyYyVNFwCbbzScyZ/JkIN4pYzDuQBNOebf7Ty9pFBWHd35QqM8PKpLl3WwktEQJ+6vRNgaF3ZEBnG1U46VDVVtWKNtT1bM1ksrKFB4g9bnQ6TSVMscPFK1+N5FMEoY4mapw5BEzytTGnhFovddkVc75Cfpl1EM25mtsETGGPYQc7RsZX0hCNzq2RiGofn+1b9Y5Og8jsMb7SoyS0uSULretciLP7fmepITKm/MixWdc1obCRen+x+ZYgFc9acr9PFI0OcY9eJ0xAeQ6s0MBPo2R2vlMovgFH3Oawe0+1rMbCMc7bl37d37hf05C+MKAb1shzSK67+cqK47hpbnEQr7esFIjS7F3TH5CNDrqgXA8M2lEC6/eTE/uBoEWeqdx+oqGN2ysr9ZwB7LSAiFy9ECIZGxV6jT+TPzcgKaEnngKWHSmtm0WStciYdan6vwDROyCKi/g2LBu4rjUD1BhlRSO0pGoqbjTNtv+x8+RLlCS4Ep1rgF7lQsIt6XsMGc6h9AOYzinzwy+47/zrxTX7WjvRJTdFYuGST9Rgz9jg0sySiug7yi7oSwO0lL8IauXUJSNSqT4S4APrPsS+C0aGl/R40NDR8VLdDIupG9UkszBInL5WHdgNJIskEQivD7UxLmpguO026ybh3s90dyyNPBCKgbuwHwRld9T/xVLBpVj1oYbEwNFpTp/QSww1yM2Rmt4c/AyLSQ8pPhOBydRJq4IVltwNBKuH2wAgs74v3xI9J13I4U7bEI9fTzt5a3dWVBUSxwOZcGUqxJlLBbgOlbJwWbnHFzCYFHgSeeqV6HQCzg92R/YpOGJ6/F4KS/L6ZDkXjOI+h122BSlKzyvH2KfvcFu+Zi9q4BJ/2toiJRhEfAOl2SSA1Ddz7+1oWdu1+zIOX3fzN5J/PmMFlrrKPOgO jejuAqmr DuQxqZKrT5xujAfe76o6wSet/wXgsksJccQalVRbvJ3lW3mAmbrLcprVmWM1KVbR+GVtBp8cjcAaKH8UOqYbs+oAFxa32p0Pq2pSs8ABL8SEpTc3hFSkeIUmOWAT8bH0aw60TT2tHZc4pmg7FnWO50Qj9fUvdHEP1N1LH7tzPd36xFIDwZhw0W0BCVMoz+27S7lG+m81UTsl8XLIjDrVJBYzr7R07Mxo0XRffidDRRDcHozy+FLfnhyhR09d7z3NSk4sVq+0oFbyceFE= 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: This is to add isolate_folio_to_list() to try to isolate hugepage, 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 --- 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 2adc3f616b71..e3968061010b 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -378,6 +378,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 68e1fe1c0b72..793c1cf02bd9 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2620,26 +2620,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 c7692f303fa7..788747dd5225 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 */