From patchwork Tue May 28 13:45:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13676758 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 345FCC25B7C for ; Tue, 28 May 2024 13:45:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C6EE6B009A; Tue, 28 May 2024 09:45:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 74AD26B009C; Tue, 28 May 2024 09:45:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5904A6B009A; Tue, 28 May 2024 09:45:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3294F6B0098 for ; Tue, 28 May 2024 09:45:26 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AE9341416E2 for ; Tue, 28 May 2024 13:45:24 +0000 (UTC) X-FDA: 82167926568.19.B79E46B Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf09.hostedemail.com (Postfix) with ESMTP id 952D3140021; Tue, 28 May 2024 13:45:21 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf09.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 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=1716903922; 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=NIlQH8BolWvIKyx3dCT2okUV2IPP2oITPYQWwW2wQYQ=; b=WZ67bLbZ1kMw3McHOCICd8IZXqdaKg5I/ZMWKbv2NxRaWuK5XNIbQnDIfVC5pXPEaw8dpJ kJC5qZvaM8A4mVfSDMqnJfkslOGpDMY6xBJwRBN/4iBav8L4sMDq/R2vuHRTmSc8JA5wBy hHdm8ubOugeJAnxQCJp7JsQFU4FN3IY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716903922; a=rsa-sha256; cv=none; b=0lC6cqyULRwQIYJkyQ/GDJ5y71xPTxPcku67hMIUPCGCDMf1w4YJba0fKQyrYtYoe/MXG4 XoFJuVXwcByHL95+66DyXQ1FwXe848VwZMyjcKa9C+Uu7F3ezc8+J8iiO5o3okaUod3Wmc dStGBdgGzq82ExoRFBm59HlI0qBTcNc= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf09.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4VpYZh0Dctz1S8DC; Tue, 28 May 2024 21:41:32 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 25AEF14037F; Tue, 28 May 2024 21:45:18 +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; Tue, 28 May 2024 21:45:17 +0800 From: Kefeng Wang To: , CC: Tony Luck , Miaohe Lin , , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , Zi Yan , Jiaqi Yan , Hugh Dickins , Vishal Moola , Alistair Popple , Jane Chu , Oscar Salvador , Kefeng Wang Subject: [PATCH v3 2/5] mm: migrate: split folio_migrate_mapping() Date: Tue, 28 May 2024 21:45:10 +0800 Message-ID: <20240528134513.2283548-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240528134513.2283548-1-wangkefeng.wang@huawei.com> References: <20240528134513.2283548-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm100001.china.huawei.com (7.185.36.93) X-Stat-Signature: pp5941ws49yqpz9mos8srrwcdr4me6wh X-Rspamd-Queue-Id: 952D3140021 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1716903921-897572 X-HE-Meta: U2FsdGVkX180BBDFfut+nTfdjX5jsyKzv2r5jscm58ULzzHKrqtFuzgru80irjFD7d9LomIStAEH2jNEGibWfxw7TMOfTf7Dw1CL7F76Q4TJ+x4x75Mfpaw8ZOq5vDQ6uScFNwIGGHdc9Cyn+iNJ4lf1lqD5JMEr0h0GmxnNcCrxIQgGuCwrnYg1Tz+A6sxSdO92/xN/EGTv3hEOC3PtncKjEICOcwy97ubPo3bOBX8BCDWuNfrsvRqNXvJSYU7Sd60EjbOenc9oA4b7Ck2inJlDr3OCXjBd8L70I7j6OLjIcIzaAvf1P2rCHgBTDC0fEeMJC+YNM6BxsHLZeZ09Uy7mFyhK5hB5e/TXgzLjipUXc9ZXXA7S+GeMD4IQ9mmpTEGoBLVeEPcvAWOZf5aeUD7IKE0YeyVWCK6CV644bDaEeu/cPXVZGpMOTtdzAKccJzwSSXe7uUkXRghYC2+elRbixqsJfnjdrbVyDlNj9Xb4k7EuGFHHJidre8mfAAfjlMvGewQ939wM8eh3Z7HWwFZSbsMCXpUux0d58XDH4nBrKajjyZxmgACu+vCcRiQYGWL8VdbAgUHTuWZGinRI61v8/QOFeKzQKofODjTZGIiBnMKlYbvT09QyxBne/tAvsM6US4njfoSwE5FX7MPVTRKycuHB9mpWVq4zXmXFYz4PRobl2KrK1XnckujoV3xrdnUEkyWR06IpzhYO0eEn2HXPZH1MCU0XBn0f6Js1V6ubulF8C5qKxD9YTfEg0wt0uOMWgZRDqMIkWHCUi+xQoJPft3LXo7wH6fgKfqfkMG9JrTg4EeOK8aAQGG+dHwLmG0D4MDq9CmoinUhyqx2igGyFTwJHInajB42FncjCIxyg5HDU9lwN5noOmsXGvrq/79CzhxYxG+/mAmjdU7jucsc+8gxS0CzLT0ER+dtItf/SFUrSO4TBScZQKI2C7pZuB772FwuIATghQ+r8Nqt KSiH7EPL hrP/6trI6aXbFPT/LLRzcErAKTscmTq5cCv7wp/EJyoSS4ulpeC7cgPdchsE8+PCj7ppu56BY9slJyb+V926ALwHcDFReqnQiA7K0PI0/g4hG2BzAGjr890X1xeDmEyNZXbDTfCl6v5mXPUprRwHgHkjELZy1cv+ACUwmvACjnjLe4kHrodzdo0wUNXiOn1Bm9f7mD4c6Gzlcgj+reXuLRhXNKXslBECZIYz4BMAQUGY6VF74In0bPPWtO7hHzgFTvOG/lXzFRgKXA9c= 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: The folio refcount check for !mapping and folio_ref_freeze() for mapping are moved out of the orignal folio_migrate_mapping(), and there is no turning back for the new __folio_migrate_mapping(), also update comment from page to folio. Note, the folio_ref_freeze() is moved out of xas_lock_irq(), Since the folio is already isolated and locked during migration, so suppose that there is no functional change. Signed-off-by: Kefeng Wang --- mm/migrate.c | 63 ++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index e04b451c4289..e930376c261a 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -393,50 +393,36 @@ static int folio_expected_refs(struct address_space *mapping, } /* - * Replace the page in the mapping. + * Replace the folio in the mapping. * * The number of remaining references must be: - * 1 for anonymous pages without a mapping - * 2 for pages with a mapping - * 3 for pages with a mapping and PagePrivate/PagePrivate2 set. + * 1 for anonymous folios without a mapping + * 2 for folios with a mapping + * 3 for folios with a mapping and PagePrivate/PagePrivate2 set. */ -int folio_migrate_mapping(struct address_space *mapping, - struct folio *newfolio, struct folio *folio, int extra_count) +static void __folio_migrate_mapping(struct address_space *mapping, + struct folio *newfolio, struct folio *folio, int expected_cnt) { XA_STATE(xas, &mapping->i_pages, folio_index(folio)); struct zone *oldzone, *newzone; - int dirty; - int expected_count = folio_expected_refs(mapping, folio) + extra_count; long nr = folio_nr_pages(folio); long entries, i; + int dirty; if (!mapping) { - /* Anonymous page without mapping */ - if (folio_ref_count(folio) != expected_count) - return -EAGAIN; - - /* No turning back from here */ + /* Anonymous folio without mapping */ newfolio->index = folio->index; newfolio->mapping = folio->mapping; if (folio_test_swapbacked(folio)) __folio_set_swapbacked(newfolio); - - return MIGRATEPAGE_SUCCESS; + return; } oldzone = folio_zone(folio); newzone = folio_zone(newfolio); xas_lock_irq(&xas); - if (!folio_ref_freeze(folio, expected_count)) { - xas_unlock_irq(&xas); - return -EAGAIN; - } - - /* - * Now we know that no one else is looking at the folio: - * no turning back from here. - */ + /* Now we know that no one else is looking at the folio */ newfolio->index = folio->index; newfolio->mapping = folio->mapping; folio_ref_add(newfolio, nr); /* add cache reference */ @@ -452,7 +438,7 @@ int folio_migrate_mapping(struct address_space *mapping, entries = 1; } - /* Move dirty while page refs frozen and newpage not yet exposed */ + /* Move dirty while folio refs frozen and newfolio not yet exposed */ dirty = folio_test_dirty(folio); if (dirty) { folio_clear_dirty(folio); @@ -466,22 +452,22 @@ int folio_migrate_mapping(struct address_space *mapping, } /* - * Drop cache reference from old page by unfreezing - * to one less reference. + * Since old folio's refcount freezed, now drop cache reference from + * old folio by unfreezing to one less reference. * We know this isn't the last reference. */ - folio_ref_unfreeze(folio, expected_count - nr); + folio_ref_unfreeze(folio, expected_cnt - nr); xas_unlock(&xas); /* Leave irq disabled to prevent preemption while updating stats */ /* * If moved to a different zone then also account - * the page for that zone. Other VM counters will be + * the folio for that zone. Other VM counters will be * taken care of when we establish references to the - * new page and drop references to the old page. + * new folio and drop references to the old folio. * - * Note that anonymous pages are accounted for + * Note that anonymous folios are accounted for * via NR_FILE_PAGES and NR_ANON_MAPPED if they * are mapped to swap space. */ @@ -518,7 +504,22 @@ int folio_migrate_mapping(struct address_space *mapping, } } local_irq_enable(); +} + +int folio_migrate_mapping(struct address_space *mapping, struct folio *newfolio, + struct folio *folio, int extra_count) +{ + int expected_cnt = folio_expected_refs(mapping, folio) + extra_count; + + if (!mapping) { + if (folio_ref_count(folio) != expected_cnt) + return -EAGAIN; + } else { + if (!folio_ref_freeze(folio, expected_cnt)) + return -EAGAIN; + } + __folio_migrate_mapping(mapping, newfolio, folio, expected_cnt); return MIGRATEPAGE_SUCCESS; } EXPORT_SYMBOL(folio_migrate_mapping);