From mboxrd@z Thu Jan 1 00:00:00 1970 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 AE6B9C3DA4A for ; Tue, 20 Aug 2024 09:33:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 093466B0083; Tue, 20 Aug 2024 05:33:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 043756B0085; Tue, 20 Aug 2024 05:33:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E26D96B0088; Tue, 20 Aug 2024 05:33:02 -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 C4DB36B0083 for ; Tue, 20 Aug 2024 05:33:02 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8A35EA1962 for ; Tue, 20 Aug 2024 09:33:02 +0000 (UTC) X-FDA: 82472109804.09.E242941 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf03.hostedemail.com (Postfix) with ESMTP id 2170B20005 for ; Tue, 20 Aug 2024 09:32:58 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724146322; a=rsa-sha256; cv=none; b=x0cyBxFSyZC/G6t3zOlt/ELfnSuoRoD+cN1Ej6Jy0/VGDTuaGXifZ4DhAqPPJL5JiAss/S PRt84S5v9XEC3kWvkJB2Dv5vYzOk9wlRADLwxCznvaUoQrCHkfG2voT1RSvg++pYbsaLPS 7J7nq5zEfBF1phdyYxMPh3pHAGPIS9Q= 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 linmiaohe@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724146322; 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=AY/DH5+a0zla06ymWSieu7kM0Il6iKqf/rPGi4Wl098=; b=X7TYg/iQzvuywvhIgKo7p9X7iKktqL55QxryQ8khta92ZL9wCcKQp4sxZ1jalx/GMsf91O bl0OQ5irDAZczgZxnekTsysuEn/81BbPH/J4/YRWH5X7e+dqFjtWNNZF2dOSUZX6qnrMxj 8GXvWcKf2zMCHR+/0GI/dtSEh4t8Pgg= Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Wp3zc0kzNz20m06; Tue, 20 Aug 2024 17:28:12 +0800 (CST) Received: from kwepemd200019.china.huawei.com (unknown [7.221.188.193]) by mail.maildlp.com (Postfix) with ESMTPS id 949AE1A0188; Tue, 20 Aug 2024 17:32:52 +0800 (CST) Received: from [10.173.127.72] (10.173.127.72) by kwepemd200019.china.huawei.com (7.221.188.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 20 Aug 2024 17:32:51 +0800 Subject: Re: [PATCH v2 4/5] mm: migrate: add isolate_folio_to_list() To: Kefeng Wang , Andrew Morton CC: David Hildenbrand , Oscar Salvador , Naoya Horiguchi , References: <20240817084941.2375713-1-wangkefeng.wang@huawei.com> <20240817084941.2375713-5-wangkefeng.wang@huawei.com> From: Miaohe Lin Message-ID: <6df49109-d39b-9852-b5b2-a5b88c9329e3@huawei.com> Date: Tue, 20 Aug 2024 17:32:51 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20240817084941.2375713-5-wangkefeng.wang@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.173.127.72] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemd200019.china.huawei.com (7.221.188.193) X-Rspamd-Queue-Id: 2170B20005 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: rp3cnrhkd91sir1wqb9nsgcyyq66hdsj X-HE-Tag: 1724146378-446193 X-HE-Meta: U2FsdGVkX1+ZcWgYqmGl8wWT+hOzh8TsaZryMb3G1aBJ/Fcx7SWe+kwLb99ll5FUkXmBabHd+TNfYKGnST0+BEvoV3Bzzuc3pQuXazx8MrFAUmjJk6Lp4KwktwjRKsgqu5O0qTDZ0rFyhiUa4S8M89aKnns5ToT+R/WGpLpHntW8TlK9sAw17lf6i6X3GvNCMX5821MwF8134QxU3s173G6HWWkUxXTPOSkndmaSwdAmwOdTmrHoEfi03kyBw/2wFCXI+HeMpXIJANTx5zlyBJVnI48VknNrrL6IRE6TABkERR2Jz6Rbx/Bb6CB+7wWawrQ0l0RhG/Qgi7gbrbOvWmOrJBEclyvzmnfmyTs6rKnpSs27rEvf+BjZtQ1rx2OPW48poMMhPRIWl1DvY2qlZm8qNfL6LubIYCmCvt8T7whuJRKwH/POlaeXu51nrVa/MqrZ0eM6wdEX4KT7EeJX2/SV3wH7AWWiK30QA7bK992eXc5kI/Y7tjS+UGuRgLFqHitgvYOmVw8deH4fuuLkPuE3yljA9U91vPGK0xgYwJXdrtwffriiiNBoDNOUjMznty+eV5ihXE7mya/4ELGqjDPsKuG7ZTngFW4uJjQObCTMHZCH8BXaMdnM8IlcIUCs9ABh4oKaxj07YOn/f8XaqrDwMWiy1bIQvP+vX+4m5olgnwCuPCx3yVZRC/Wc22x9YiEp+RudyjfV5KlfH+qwPUjzrvTpRG3NcCBGcqOwvlzCMktDKmY6Yz/P9tmWWxMAr39+dTK6Q7SvAOVnn+jxGKyt6tV0P0yFS/X+HgbxetOWEO6TLX7alMFi/TIP7Ej4Zr4/2qt0f1/qyFhP09V1NObf8+7HMw1OVxMW6DLBNI7R+E9lvXIb6AFgzlGlbwxxnorzEqrmrspOJ3gU6KcfR+03UQd5P/sIXNaL21x5otPxE+DKf7HMbP2RebuzZwsPFlioPanhvYqEjH6G8w1 ra8OuS3v cUQHkRMAcGB06MZZxaCQO7FpAmd+GgtE23xybJ9/l7XLurdjSOkegcEdKNs6JVz50d/FFxsVbjoi8DBeJsAFmBOGaDS6pPqAJZ8YyUzJsrqjUCZKubs/Qr9fRCc0OuKzz7qaNAAigiVU3RX0LpWlHW5Uv1DoWQOb32x5Rzx+LlVVzu1+AGMGBoEVwtb8xWdAEEBiIjgN769sqICNTGEGW1dgjpF/rg13/7d+t8hfUxDupZLQGE+cWzxswHDPiEIqPSOgW1iG2TWj/yAUzJB7DsR4pL3UQipec+JGylqLyUNRAeUI= 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: On 2024/8/17 16:49, Kefeng Wang wrote: > 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 Thanks for your patch. > --- > 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); Why folio_put() is deferred here? With this change, folio will have extra two refcnt when calling migrate_pages() above. One is from get_any_page() and another one from folio_isolate_lru(). This would lead to migrate_pages() never success. And my many testcases failed due to this change. Thanks. .