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 58532C3DA4A for ; Tue, 20 Aug 2024 09:46:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5BB16B0083; Tue, 20 Aug 2024 05:46:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C0BF16B0085; Tue, 20 Aug 2024 05:46:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD32C6B0088; Tue, 20 Aug 2024 05:46:52 -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 8D93E6B0083 for ; Tue, 20 Aug 2024 05:46:52 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3CD691C5964 for ; Tue, 20 Aug 2024 09:46:52 +0000 (UTC) X-FDA: 82472144664.25.1AB4F31 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf01.hostedemail.com (Postfix) with ESMTP id 4764340003 for ; Tue, 20 Aug 2024 09:46:46 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.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=1724147147; 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=83doj0/kGyS4eH1WnyDTDPs6BgTr2JPuSqj+qlPsMzw=; b=bfe1pTeq1erMMbqFgKRpqTBZ8Vx2X7QEdRiPd0QJMulfssWgU4ssazauOfistj7XgEWX5t wqyYXXwcJ48MK+KbUIlGv+BS01rOS8i7O0QJqbmmiHIW2zoBT/bBso0AxntZho7sctqDlA KJjMa8KW+Pgvo+IMl4D80sgq/t1aFGs= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.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=1724147147; a=rsa-sha256; cv=none; b=Be2E+sc0FERyvAk0KxjvkbY0x7WvA1/t1YtrPQlB+9MMlJdI+s2DG5CY+QcMoBY/uxVq9Y XQ/YiNQTKmW5vyCt5vjQi370/eDDfCnd65AYc3iIP7b5s8BgwcKW57q4xc3YSinVV9KWGt xsFtnOVEFsfhaKc96vaepeB18g4knOg= Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Wp4HB5rjpz1j6n5; Tue, 20 Aug 2024 17:41:42 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 4E93F1401F2; Tue, 20 Aug 2024 17:46:42 +0800 (CST) Received: from [10.174.177.243] (10.174.177.243) 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; Tue, 20 Aug 2024 17:46:41 +0800 Message-ID: <927205ab-bd83-4765-b2bb-3fd311f5ac6d@huawei.com> Date: Tue, 20 Aug 2024 17:46:41 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 4/5] mm: migrate: add isolate_folio_to_list() Content-Language: en-US To: Miaohe Lin , Andrew Morton CC: David Hildenbrand , Oscar Salvador , Naoya Horiguchi , References: <20240817084941.2375713-1-wangkefeng.wang@huawei.com> <20240817084941.2375713-5-wangkefeng.wang@huawei.com> <6df49109-d39b-9852-b5b2-a5b88c9329e3@huawei.com> From: Kefeng Wang In-Reply-To: <6df49109-d39b-9852-b5b2-a5b88c9329e3@huawei.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf100008.china.huawei.com (7.185.36.138) X-Stat-Signature: mk5efdhynruk6i5zbkuidw91scoud9bj X-Rspam-User: X-Rspamd-Queue-Id: 4764340003 X-Rspamd-Server: rspam02 X-HE-Tag: 1724147206-45781 X-HE-Meta: U2FsdGVkX1/cEWsNcZ6HIXhJH7p1BgyoWLtGvJXvyVZlBKoP1nngO/dbx2+19SwRJmrApsLTQ7ReGX8kj79EU1rjtDX7ah7c8PU1frF8VtczYGFLrMc+I1YXk4HGQvR1oW3ZmGsT3N0SsoTrY7bPy9ItQ0nJDL4oM7zv6yzeKujcxXIBlqBExNnb0dS/aFvz4C1hh5F0Qz63hFXtIWkCUDYG4FjnbzIfeomSWTLaLY1zbUSsDEcWnbJ9NuY0hcWeWSFvydXW9ynzL0i3bHWX/Q5tCnR7bnjXInSXtyJ8WswAouOGk8HOQ3CcHRxWDcXFLCBrpD13QEwNgs8aXW7W872fORUEvMAHtD6CJfIyeNyrznqnyc9+ZQQ3C5C2D/Alm0mSlg43aHDww50qcq98XTRfTkNGA4mKuDfR/yCFd0/NKxtJatednKprNW9OrKNs/VM//En5S8w5gmyAZ3R9XiFkECTP1kbSQSpUgxm6yTgyCJFx0bRLBnQIZMGjkSWoUWjdAYnYQnUk9CwFsdAAefLQDfPukl9TKI3p83PyKsvoMpZ3Wpoui9scyPHQQmc3oqBTnIgbAb0kl3S6QDcZePDYX5CrCib/kcSlBOjPXfirBZCaI747uZb9cY2j3zBCTpqxbqXkzS4Rl8jhuI1IEHaogdG8Rnwi9G5+lzFh05wz7msuHW7bJ7bcyuV7FyR8OBsg8dw0nnbdvfmw2HxE0l3Qq8iZLChR+hRE1rubmRMxCHcash3vhryyI12Qjxm/hzp7IreIcUP68pNe9+nKiZxLRryVQsSt1kU5K8L1J59M0UILmKQWOct+MwmODXTBJNu6TNEew3/Jt2Yf3p5VIVwhKviL9o+FGBSFxFaK50Ha1XkEWWY1yQH9NI6ubXGyYd/c1FN6zJj+5oC+kiXHdnff5rPpbYgmD0aic+PtkkN2hElKvWmH/pPA81psHt49afcOrIYIhd6AM7U+DEq ijRZY2b5 gxHY9DCjvgOPhTwOPfsTSXtEFgi66tPXeAmBZLguhyAvzglEsDcAMZ9zDQAp79fS/nghK3+RJhcqNf6+wkNwQ10XPi3BQhsxRzLVkH7zm0ESFM4iSGaYX+f2p+SnW9PAi7SJ56c1+vmi7C41O4ljfp1MkKjqdBjy0Go3uo6b+GLMRSv/K9GiupguFVEK7IC4GYkeOc+2rESkRYBHkw0oLPXKrD4F5MUxSUHLVgZw0i/zn7jbMgVqZCI6Zd42K49vsCo+z6Mj8uSMVZUUmDA5N7XYtU2KYVlqPDuRKqvcaR9cv2JZ3o9dJVv5CAY7iE3l4Rd0UGUMRoDYOzic= 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/20 17:32, Miaohe Lin wrote: > 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 for your review, missing this, only test memory-hotplug, could you try this, diff --git a/mm/memory-failure.c b/mm/memory-failure.c index d8298017bd99..64a145a0e29f 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2671,6 +2671,7 @@ static int soft_offline_in_use_page(struct page *page) struct folio *folio = page_folio(page); char const *msg_page[] = {"page", "hugepage"}; bool huge = folio_test_hugetlb(folio); + bool isolated; LIST_HEAD(pagelist); struct migration_target_control mtc = { .nid = NUMA_NO_NODE, @@ -2710,7 +2711,18 @@ static int soft_offline_in_use_page(struct page *page) return 0; } - if (isolate_folio_to_list(folio, &pagelist)) { + isolated = isolate_folio_to_list(folio, &pagelist); + + /* + * 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); + + if (isolated) { ret = migrate_pages(&pagelist, alloc_migration_target, NULL, (unsigned long)&mtc, MIGRATE_SYNC, MR_MEMORY_FAILURE, NULL); if (!ret) { @@ -2733,15 +2745,6 @@ static int soft_offline_in_use_page(struct page *page) 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; } > > Thanks. > .