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 555D4C54E67 for ; Wed, 27 Mar 2024 14:36:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E34736B009D; Wed, 27 Mar 2024 10:36:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DE48F6B009F; Wed, 27 Mar 2024 10:36:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CAC4C6B00A0; Wed, 27 Mar 2024 10:36:52 -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 AC76D6B009D for ; Wed, 27 Mar 2024 10:36:52 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4600EA0E34 for ; Wed, 27 Mar 2024 14:36:52 +0000 (UTC) X-FDA: 81943070664.02.96DBD83 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf06.hostedemail.com (Postfix) with ESMTP id 718C018001B for ; Wed, 27 Mar 2024 14:36:49 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1711550210; 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=M2blYuGVSNFI3X2pxMwbwxKH0XJemcbiF/ji5pBDlF4=; b=lmFTRS02CLF40flWXySzMkjmdE7aC7960dQxljW1OTZLnwb7QcqziSMvC0NII9m/y4nvph xZ2patfcA/LJ6z7XR/ot3z8qzdvoivQLBZPJTkWOQqktRXdzBBaqSkq46JH5WxRRbUvvuW 7ft+ulS7KeUHzlbzQ/VS5py2H13r170= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711550210; a=rsa-sha256; cv=none; b=kxJKrp20+GvV2QHxVejKL+TD80hOcruyHlxw6DECc8EZU1ENUY06E+BOgsVRw7UE+kEAys EyFMwOeTCjl5GAJxdQxIkKN9yWRavcxJUU08sSRUnWjeRLyu+IQ7tXbWdLLzEH+tjVHKva pA+Y6m+CjlhITlG/2S4wLe1Ub/xKpQI= Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4V4Tk16CLmzRjng; Wed, 27 Mar 2024 22:35:53 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id C248C140258; Wed, 27 Mar 2024 22:36:45 +0800 (CST) Received: from [10.174.177.243] (10.174.177.243) 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; Wed, 27 Mar 2024 22:36:45 +0800 Message-ID: Date: Wed, 27 Mar 2024 22:36:44 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/6] mm: migrate: add isolate_movable_folio() Content-Language: en-US To: Zi Yan CC: Andrew Morton , , Miaohe Lin , Naoya Horiguchi , David Hildenbrand , Oscar Salvador , Hugh Dickins , Jonathan Corbet , , , Baolin Wang References: <20240327141034.3712697-1-wangkefeng.wang@huawei.com> <20240327141034.3712697-2-wangkefeng.wang@huawei.com> From: Kefeng Wang In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Queue-Id: 718C018001B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: x7b5ats5ehkn8pbcbx4ru5szr79wjmoq X-HE-Tag: 1711550209-415178 X-HE-Meta: U2FsdGVkX19OXEWGmDAYqke7Mhmk21MTmRTah8kVUXCWpgHoyMDjpUQFGDP7NElH5ullFG7D0bPq+hdKySkhpmO1gyb4sqUiV7YvGdjC6/sQhkkiEPZj09rj5Qhs4x8xA87CL5qpwM9R8kY6ohreMmGRW2yHm+hZ0py8hxOtT+nE8YTNdEFfelvPzLVRAyPZzM3Gl7MESX8hzUexy/xf4XdkcA/lQrfaczglnOtuLgSqOxk6jt+JjWyFBkRieiP+EyyjsDede8bvdFIrCVvJJtlYQiw7YjUgi+wquu9GYxEH+2ST9bg+GT0pZUGPKvd1OZJuzcu+blbJFrt/r2yi1+4ggotEsimses8FFIjSighceOJT3h4cxgn2vRAXchAwBZlB82vq8lJ2VDk2bgu/G7EmNR3ioGrUxexk+BDohBggInv9jdIej8QVuKTBXz6+HQNuc/lDqge53RZvUT3kghrutYVztlec5fVtBH1kd5jbgt1MC3W8MKTUhM8PPKkUCW4EAjuDmodlF1Lsm5xVeZ8lOlf9tNZD1Zpguk0KzVmBdq+P6isK2KyeSwAzpX6+UT8Mhbt9clTMwrdWiqszfOXtl0bDArEX2H5QOMkj9ryDOwzUCgVaYQ0w6iV+HgadfRt/VzehXrPgJlXdMqdfWIimVugD5uF8FmZGTj8V0P4rt7yWU2ckhq5ftO5MUJ8PaMMevaVW/V5gQ9rfoxlR6knieI6dzXOVbGUcg+Nu521IDzKmt9mwVtVxxArzLzfG0ijuYRS/mj90WMQZemPayEQ013ns9CI880bUKDx8BKpFuEW3vGicqSHUT6gORr1yibJiliGp3jn9Zj8COTC34MRnoezElsc7YuEQRkk/NXu/xVjUjliQGoKP/NFrIZg04rcQhglNE96vgf3G6zVKmHB3V2h+FyDMxELWECu/R8MaNxXWKNdLnI+qLPhXqIitYq5OsMQMYwUN6xjzTbu lyy2H9dE nxlX18UgR5pelfr1aY+NpDDQ5FsJ2iOKt68/Oqk/6OMOHD0++Z+fVK/l72FhVZtsfddgf6Bh2OKZDSlaWcz4ZpL1Cino0Sw7V5B6tzFP7ZWWS2FKD0uzmtxUI0AWQkIqSLUG+Qqml6K4uoj8l/bjK0+TO5JPZ2rkLYyJbTAfxUhMs6G2q2o/m9YEuB5fAv9ZUj6zQAZp07lWdCJLIdLK/ZVmdjhvERF7ZrJvQ9EmY3VYuY9AWK8HYUSCExQ== 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/3/27 22:29, Zi Yan wrote: > On 27 Mar 2024, at 10:10, Kefeng Wang wrote: > >> Like isolate_lru_page(), make isolate_movable_page() as a wrapper >> around isolate_lru_folio(), since isolate_movable_page() always >> fails on a tail page, add a warn for tail page and return immediately. >> >> Signed-off-by: Kefeng Wang >> --- >> include/linux/migrate.h | 3 +++ >> mm/migrate.c | 41 +++++++++++++++++++++++------------------ >> 2 files changed, 26 insertions(+), 18 deletions(-) >> >> diff --git a/include/linux/migrate.h b/include/linux/migrate.h >> index f9d92482d117..a6c38ee7246a 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_movable_folio(struct folio *folio, isolate_mode_t mode); >> >> 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_movable_folio(struct page *page, isolate_mode_t mode) >> + { return false; } >> >> static inline int migrate_huge_page_move_mapping(struct address_space *mapping, >> struct folio *dst, struct folio *src) >> diff --git a/mm/migrate.c b/mm/migrate.c >> index 2228ca681afb..b2195b6ff32c 100644 >> --- a/mm/migrate.c >> +++ b/mm/migrate.c >> @@ -57,31 +57,29 @@ >> >> #include "internal.h" >> >> -bool isolate_movable_page(struct page *page, isolate_mode_t mode) >> +bool isolate_movable_folio(struct folio *folio, isolate_mode_t mode) >> { >> - struct folio *folio = folio_get_nontail_page(page); >> const struct movable_operations *mops; >> >> /* >> - * Avoid burning cycles with pages that are yet under __free_pages(), >> + * Avoid burning cycles with folios that are yet under __free_pages(), >> * or just got freed under us. >> * >> - * In case we 'win' a race for a movable page being freed under us and >> + * In case we 'win' a race for a movable folio being freed under us and >> * raise its refcount preventing __free_pages() from doing its job >> - * the put_page() at the end of this block will take care of >> - * release this page, thus avoiding a nasty leakage. >> + * the folio_put() at the end of this block will take care of >> + * release this folio, thus avoiding a nasty leakage. >> */ >> - if (!folio) >> - goto out; >> + folio_get(folio); > > You need folio_try_get() instead. Since folio_get_nontail_page() calls > get_page_unless_zero() first. Oh, indeed, will fix. > >> >> if (unlikely(folio_test_slab(folio))) >> goto out_putfolio; >> /* Pairs with smp_wmb() in slab freeing, e.g. SLUB's __free_slab() */ >> smp_rmb(); >> /* >> - * Check movable flag before taking the page lock because >> - * we use non-atomic bitops on newly allocated page flags so >> - * unconditionally grabbing the lock ruins page's owner side. >> + * Check movable flag before taking the folio lock because >> + * we use non-atomic bitops on newly allocated folio flags so >> + * unconditionally grabbing the lock ruins folio's owner side. >> */ >> if (unlikely(!__folio_test_movable(folio))) >> goto out_putfolio; >> @@ -91,13 +89,13 @@ bool isolate_movable_page(struct page *page, isolate_mode_t mode) >> goto out_putfolio; >> >> /* >> - * As movable pages are not isolated from LRU lists, concurrent >> - * compaction threads can race against page migration functions >> - * as well as race against the releasing a page. >> + * As movable folios are not isolated from LRU lists, concurrent >> + * compaction threads can race against folio migration functions >> + * as well as race against the releasing a folio. >> * >> - * In order to avoid having an already isolated movable page >> + * In order to avoid having an already isolated movable folio >> * being (wrongly) re-isolated while it is under migration, >> - * or to avoid attempting to isolate pages being released, >> + * or to avoid attempting to isolate folios being released, >> * lets be sure we have the page lock >> * before proceeding with the movable page isolation steps. >> */ >> @@ -113,7 +111,7 @@ bool isolate_movable_page(struct page *page, isolate_mode_t mode) >> if (!mops->isolate_page(&folio->page, mode)) >> goto out_no_isolated; >> >> - /* Driver shouldn't use PG_isolated bit of page->flags */ >> + /* Driver shouldn't use PG_isolated bit of folio->flags */ >> WARN_ON_ONCE(folio_test_isolated(folio)); >> folio_set_isolated(folio); >> folio_unlock(folio); >> @@ -124,10 +122,17 @@ bool isolate_movable_page(struct page *page, isolate_mode_t mode) >> folio_unlock(folio); >> out_putfolio: >> folio_put(folio); >> -out: >> return false; >> } >> >> +bool isolate_movable_page(struct page *page, isolate_mode_t mode) >> +{ >> + if (WARN_RATELIMIT(PageTail(page), "trying to isolate tail page")) >> + return false; > > Why bother adding a warning here? There was no warning before. Also, > after this series, isolate_movable_page() will be gone. I copy from isolate_lru_page(), but as you said, it seems useless, will remove it. Thanks. > >> + >> + return isolate_movable_folio((struct folio *)page, mode); >> +} >> + >> static void putback_movable_folio(struct folio *folio) >> { >> const struct movable_operations *mops = folio_movable_ops(folio); >> -- >> 2.27.0 > > > -- > Best Regards, > Yan, Zi