From patchwork Wed Apr 24 13:59: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: 13641917 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 D75B3C10F15 for ; Wed, 24 Apr 2024 13:59:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C09BF8D0015; Wed, 24 Apr 2024 09:59:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E23B8D0001; Wed, 24 Apr 2024 09:59:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E8148D0001; Wed, 24 Apr 2024 09:59:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5045B8D0011 for ; Wed, 24 Apr 2024 09:59:43 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 04ED31C16EE for ; Wed, 24 Apr 2024 13:59:42 +0000 (UTC) X-FDA: 82044583446.11.5257B8E Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf18.hostedemail.com (Postfix) with ESMTP id D41891C000F; Wed, 24 Apr 2024 13:59:38 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1713967180; a=rsa-sha256; cv=none; b=YvltvAr98Ybo08HEarZAhEmnfwbRogvOsBRxGBkdKHdj0JPYhCqgoxVDw2E3mja5askP43 orB8n3R5663QPG104j6sTlg7KFLkspQUOdzLhOO0FuctHg/OO6DWe+8GtJU0Kqw6dCYVbT 8KR4zRKtqnQSn9VTwGNOlS2dAUWfAoM= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1713967180; 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=Vu1YiVu6PQ5uFxuNgUVhOf6cPkfOX5wbV6cSCZY4a4Y=; b=RWcJ8oK/ima2xoHXlXOsrUe0yr/BwWd4rRPXp2vl4mx4/20Ytki5YjuFvo/MeEnIv5Ba4s 5OxhKNXRC2vTXNPOsgriTW6FkoS9NDMZX+wQh0VX9PtxOsanVgwaMhAn0Fx9FAY4GpH37k YJkGfIPB2URHaEMCZbFhe6Pxl6jSXEY= Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VPgYx5036zShf3; Wed, 24 Apr 2024 21:58:29 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 58825180080; Wed, 24 Apr 2024 21:59:34 +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; Wed, 24 Apr 2024 21:59:33 +0800 From: Kefeng Wang To: Andrew Morton , CC: Tony Luck , Miaohe Lin , Naoya Horiguchi , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , , , Zi Yan , Jiaqi Yan , Hugh Dickins , Vishal Moola , Kefeng Wang Subject: [PATCH v2 01/10] mm: migrate: simplify __buffer_migrate_folio() Date: Wed, 24 Apr 2024 21:59:20 +0800 Message-ID: <20240424135929.2847185-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> References: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: D41891C000F X-Stat-Signature: 8t4dausmh647hsb8ohfnhn78na57js1j X-Rspam-User: X-HE-Tag: 1713967178-440835 X-HE-Meta: U2FsdGVkX199092zkML4ByyQkeXOu2fXCzQ1vQAotcVR+T7HXNyVyWsM17WWYAEzxeA9LjhY4lM++tYW+hR+2256Y7/u7Lw46UEh/tTyWpqHERxhX+szAYqPSXZLadxmd6cdaSUsqqtgVLQMXC3kCTRdcIzczjZFDW2Kwb/KXOlNNPfW6CEQU9FSG5TVEIYxNVG5ibXpjF1jqKBAtNsh0rdfcWrc7+FDaEnWJA0q13ZxYJuTDh/qf7/WQINADUnBePsDg67BZZw+1rgUhe8Svhp/yCC5RxSXvifWvLfYMb8q2vIJ6iXaOBGY7VYkmMrqhvwmoFyvGFIFdpmbTGFslId/+E8R0C0oQjSmz0PYIBFKKbCxa5Wps+lUfADSJMyeMZ/Lww8NAtQpat6MicW+6jzR8FjSV2/vZWzgUNr1IJatYrNA0cmm7fMCCL4A89WTTAJq/RdP7uIA6p2QUQeap/K2f6vsLRIwFVY950ZUBn6BmkLIQjeqAOBrH1SQsWL1LqP6cAbTqIZwU2xvIiSc7XLGTs8dF0XiMuxjZaHOb65+0zxOTqC7KrKbDyapQWAOAWpsrNhBZakhVLCrg+wwJ6GkAbgMqKxE+ipzUlaiXp+M6qRHzAIFPYdBPiHXTna9FhujEaly9znY/evjsGzYwXevycHDnmAlLYhG5mWlxDr6UmTvM/oIfnN7NYlqRw6dS6bTPCmyWj0ZqXKVvjZmX+bxOl4wLyG0q9kSYcWJeLOfaOUmsDZbaH6RjqoFgQPtjE0towZHUrjZmnrxap6KwfUIqNayIPwj53VwRjkggkg8Navyx8kuE8/Mdj6Ncr9WXVZ0zjvYf9aadGnp9jjckk5VlIQpCfRzY8Zv1g6ENKnBJHREhDZ3QLpG2neyvpi2XQnSonK+opvakqzz2I6/nlk50VLJD6DkRyZuxOkK5C5+SCgV9GiDI6aD+3lhMosxMtA6npBWfBtLzT+lvpq hV3sbqTx /7nOdd9nOHZZtcAGiTNWPg40ObxeKIG09Y1x0RqBKzNIEaQZP7rmPAoMlM8ePiwKeiEP2bwvwyneTQSss7SN9NxX7dtUEDq2m7qZlwwok2K/Mv768Dn1Kd2yli3108hVm8ijWUc8M9rcq9FBGGfDw/nxPN/+AS8uOabIvSjvhq9+niDNiTnYC+y07aVx7/CFjY3uWf0n76zhr68fFDVCzrB7nAFneY/LJFpeWPUPCCLhHTSoUds7cRd1QH+738Y6dq7OZt9BARH9BM//Lg6p40NV8sWm4siNFIeOUWh+RGu1EPBpoyi+8p35RXSfvKImOMyViq8JRleTCsObKGQY8bWSPmOvbMBpRT0oe 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: Use filemap_migrate_folio() helper to simplify __buffer_migrate_folio(). Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Vishal Moola (Oracle) Reviewed-by: Miaohe Lin Signed-off-by: Kefeng Wang --- mm/migrate.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 4fbc7ff39da3..9cc5a3e1d97c 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -803,24 +803,16 @@ static int __buffer_migrate_folio(struct address_space *mapping, } } - rc = folio_migrate_mapping(mapping, dst, src, 0); + rc = filemap_migrate_folio(mapping, dst, src, mode); if (rc != MIGRATEPAGE_SUCCESS) goto unlock_buffers; - folio_attach_private(dst, folio_detach_private(src)); - bh = head; do { folio_set_bh(bh, dst, bh_offset(bh)); bh = bh->b_this_page; } while (bh != head); - if (mode != MIGRATE_SYNC_NO_COPY) - folio_migrate_copy(dst, src); - else - folio_migrate_flags(dst, src); - - rc = MIGRATEPAGE_SUCCESS; unlock_buffers: if (check_refs) spin_unlock(&mapping->i_private_lock); From patchwork Wed Apr 24 13:59:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13641920 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 E28A8C4345F for ; Wed, 24 Apr 2024 13:59:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D662B8D0010; Wed, 24 Apr 2024 09:59:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC8268D0012; Wed, 24 Apr 2024 09:59:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B1E388D0010; Wed, 24 Apr 2024 09:59:44 -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 566828D0017 for ; Wed, 24 Apr 2024 09:59:44 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1C7411A10AA for ; Wed, 24 Apr 2024 13:59:44 +0000 (UTC) X-FDA: 82044583488.30.6C3AC4B Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf14.hostedemail.com (Postfix) with ESMTP id EFD8E100014; Wed, 24 Apr 2024 13:59:38 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.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=1713967180; 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=0GBpOw54h9vDdVipFA0f2BFetWj3AA+oUq3Hfr+E/MM=; b=Iqgfntq52y8rDMgNHkPgBNpNH5noGDoXmEnMcusKzw4BItASQKqpP6EGFmc5CWSpQxmqYk WAEEcjyr83rfblxMRGCPucAxVKcxBI0JRAn8H7fVbGoiIyBJhJq4sFG+PvlBOnuHIJwnB7 oOR7kYga+rjZCib+6X9a5FHw2QdvSkE= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713967180; a=rsa-sha256; cv=none; b=rfXJeIuRA1ZDr1ZQNW3OfOGIWsOG8/JzMxf7DW6dG+llXRmGnCKVdV/ZXklqI15xkItSlU eU/HFlyC2FFSekVa0aUL46Cufb4DJ1V2WwDv2vLSB5mYV6ey3jPfTFIBGY4YktG8+nLV1K dIG4yH3cyjbio8OVhXpsRO9sU9vu2Dk= Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4VPgWj2kcpz1R8X0; Wed, 24 Apr 2024 21:56:33 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 16E7C18007D; Wed, 24 Apr 2024 21:59:35 +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; Wed, 24 Apr 2024 21:59:34 +0800 From: Kefeng Wang To: Andrew Morton , CC: Tony Luck , Miaohe Lin , Naoya Horiguchi , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , , , Zi Yan , Jiaqi Yan , Hugh Dickins , Vishal Moola , Kefeng Wang Subject: [PATCH v2 02/10] mm: migrate_device: use more folio in __migrate_device_pages() Date: Wed, 24 Apr 2024 21:59:21 +0800 Message-ID: <20240424135929.2847185-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> References: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Stat-Signature: 1farh4k4a9jdnsd3s575arsnp7guo4gh X-Rspamd-Queue-Id: EFD8E100014 X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1713967178-192813 X-HE-Meta: U2FsdGVkX1/bNA/jbWs0LsLSOyv0ZNr7OPAjZ6lwBKsc8iJnqfglo6234LkZR1riULtM38nOPdeXR9e6A9ZiQjW0q+UbnqBJtZsK9uEwClNDw8CpB8qhtrRrKoVBi7SZwafBaAML3MpZDGlFXBOiKrlzhpVFm0GNAt5vsLCvCrgAm75ICVj1chJ77oP26f2H2c7Z+2KarJZ+LDTV+Jq5H8ItbqOFMsA31mcHI8RsVq6dDnMocij488ZCbEA4QKU1I7O+HzNJdkOkK3FuW0tOU+8iF4Y/O211CTqsrsa91gRbX/O8fAEn2nMKX3g9a4b6I+EYm7iIQcvqmBxPeYcBveF/oSOOoS2S0xsZDzD0bBlnpMk5eMyF2n9r0BHOwe1vnlR9f4riTaRNuzhrcZQhJ2HOzVFDu26Nnf3Dz06RPag0qZwwa3vn/rdVAI5MmgTT9J431OvzMVFQXQ4sQR/0J+2lRcC7WS4+E7BhTeo4uMIbkqtGTfqBCBRNvK9fM9XBDd75pZFb3jr8+n7tuwGuAMlsULq7K1ZJ8Jd8RzzIOH1IJqoF0j9GThkns1ypanx0OoaYeyfZycWn9jFRvVM0igbBBDu6splwygIl3XyxEuPgET0Xp0RsG/91UBl/YyDAW24dT5iRdUgNHwLoHo5r4ScaZNL6gpvb7pR9NzkqbrBpHrf2y53pD9CIvpmwl+7aLOC28yCAHiWj70+8nxvo5i6MKEEucdrLAY33mH+JXky6iks8mKFDW64+AhqYCxFegequvO9lBhpUagwQ+QwFn2IYkTABrMJz9epvSlvtOFUKEJuCKUdBZfLKKioXmLMmNphOjUsQQHmPNM/Rs5ySLBMaR4WefFAP+SmTIn8dovJE0I6bXGucPNl8QSCYkbQf5CGK3F2qphjtm5dvmWRg6467SkkhvDtEg+tw7kNQAJYj9dRMX+Gso8oqzDGBC7i6uJnouZzbHBfojcqxJSs 1Wg== 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: Use newfolio/folio for migrate_folio_extra()/migrate_folio() to save four compound_head() calls. Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Vishal Moola (Oracle) Reviewed-by: Miaohe Lin Signed-off-by: Kefeng Wang --- mm/migrate_device.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index a1f87aada1bd..1b6658519f64 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -690,6 +690,7 @@ static void __migrate_device_pages(unsigned long *src_pfns, struct page *newpage = migrate_pfn_to_page(dst_pfns[i]); struct page *page = migrate_pfn_to_page(src_pfns[i]); struct address_space *mapping; + struct folio *newfolio, *folio; int r; if (!newpage) { @@ -724,14 +725,13 @@ static void __migrate_device_pages(unsigned long *src_pfns, continue; } - mapping = page_mapping(page); + newfolio = page_folio(newpage); + folio = page_folio(page); + mapping = folio_mapping(folio); - if (is_device_private_page(newpage) || - is_device_coherent_page(newpage)) { + if (folio_is_device_private(newfolio) || + folio_is_device_coherent(newfolio)) { if (mapping) { - struct folio *folio; - - folio = page_folio(page); /* * For now only support anonymous memory migrating to @@ -745,7 +745,7 @@ static void __migrate_device_pages(unsigned long *src_pfns, continue; } } - } else if (is_zone_device_page(newpage)) { + } else if (folio_is_zone_device(newfolio)) { /* * Other types of ZONE_DEVICE page are not supported. */ @@ -754,12 +754,11 @@ static void __migrate_device_pages(unsigned long *src_pfns, } if (migrate && migrate->fault_page == page) - r = migrate_folio_extra(mapping, page_folio(newpage), - page_folio(page), + r = migrate_folio_extra(mapping, newfolio, folio, MIGRATE_SYNC_NO_COPY, 1); else - r = migrate_folio(mapping, page_folio(newpage), - page_folio(page), MIGRATE_SYNC_NO_COPY); + r = migrate_folio(mapping, newfolio, folio, + MIGRATE_SYNC_NO_COPY); if (r != MIGRATEPAGE_SUCCESS) src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; } From patchwork Wed Apr 24 13:59:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13641919 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 B95A5C4345F for ; Wed, 24 Apr 2024 13:59:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A3538D001A; Wed, 24 Apr 2024 09:59:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 120E48D0012; Wed, 24 Apr 2024 09:59:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D66CD8D0017; Wed, 24 Apr 2024 09:59:43 -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 85F5A8D0010 for ; Wed, 24 Apr 2024 09:59:43 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E9B9A1A0262 for ; Wed, 24 Apr 2024 13:59:42 +0000 (UTC) X-FDA: 82044583404.30.851E3D9 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf09.hostedemail.com (Postfix) with ESMTP id 1190C14002C; Wed, 24 Apr 2024 13:59:38 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1713967180; 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=9Xogj8tkPJgc13hmp0EWgxmC3HKBDn3Wr1krWpw+Nk4=; b=iQGGxyNOkFDTPgcwsTSgL6x4LcJaMV1dPo8yXuJjLTPMBtct2THW6fJdbiGLtRcJLh/e/t 7D7e/DlAI9mVlKaw6E6ix7uQcT6wK157owQlTuDviTnVimtK3dIZyDGanJWOM8WwhTlBZX fHHzpZvoH8hbxBnK94Z9UrcliA7BFVM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713967180; a=rsa-sha256; cv=none; b=2BjrgvPpBsYHQJNxpUBxeZHSatID5Z8R8vZ3S2fM+jGQ4TlaA5dIQwpr6ZWVMJfe5F8K4L SWil31B4rFsWKxZOmVxTFAX3pziZImkqxeKts086eR/N+mTeeK4edjuk9xX0QrjfG53R7l jehc2lho5JEjDrs6u8GNajFb88Fie3Q= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; spf=pass (imf09.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VPgYz1RCnzShcs; Wed, 24 Apr 2024 21:58:31 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id CFF1F18006B; Wed, 24 Apr 2024 21:59:35 +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; Wed, 24 Apr 2024 21:59:35 +0800 From: Kefeng Wang To: Andrew Morton , CC: Tony Luck , Miaohe Lin , Naoya Horiguchi , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , , , Zi Yan , Jiaqi Yan , Hugh Dickins , Vishal Moola , Kefeng Wang Subject: [PATCH v2 03/10] mm: migrate_device: unify migrate folio for MIGRATE_SYNC_NO_COPY Date: Wed, 24 Apr 2024 21:59:22 +0800 Message-ID: <20240424135929.2847185-4-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> References: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1190C14002C X-Stat-Signature: bp63s5wi1aza91ne3od7wo8fj898erz4 X-Rspam-User: X-HE-Tag: 1713967178-526896 X-HE-Meta: U2FsdGVkX1+q+25tNNNZayI877Dtt2kW09nVFfFFMxhJw3eYydLY+hBJNIom5B4usQ2zMKSSmhWI44YyQw51yZYJMhuLf6e7UDyErgtnZnHbAu8SznrQSd67Oo767hMnKcv8IeE7kElVChzEgdV7CV/fyQO0rs+8qy4lgwPE6y7tgHXB+4c/QO7xZ5gr5NdEfh5nr8c43xVYqC4rVvQbpfnns0z+Zi4ePIIJpZ1Kudprlh5GvSpmjy79wkVfwUloCq5qUplcE0S4HJ1zQ15SvnJWn+skqDSu8WyufInFViIUAP1AJyGjTmG9RRo09Wmj9mtx/MyqVkrUc7xY8Ro4KMSGx+OWIvB89ruVC73wkZaj/RqamT2swKX3GkFmuwRc/ZNHyfzkkkK/+sgsBVLPOlk5GgdtN+aYs64VZjFGjc6Wk0XAcoSkUQLDoFtzvr6Tuc2kqw63rFfJKG1Pl57PqOWL6Rq5PdsTLl98+hYMOSvsYKOG7SN+4IL7bVyKISoxEOZYmVG6+5dtxHVS1+q9TF7WehR0cpynJwHQDX8U9sp1+f1TDfXLfniGULseifO4Q+vgtqlu8QI74+9TU93I7AVWq56tNocSiRQbl9nyRIRIOyAaUOgZEE5nKChsCovPIJFVLEr4TZzQMkpA9GM1RS31ZuWw0amB67BRZV46kqbsRP7CQn9Ex/PwlPVbQg2Tq/xctMJzQlPk6DYcMWTmQarFIpE1ubw0+jufCk0zS5NKJVq2nIeymFZRlT91bj011Yoznm62hKI4aym5bjKTZfGjBr0E7bfKBG+nzgNjqUbsuBz3Q4WFXQuKEc8/gShLvdT+cdc0g5aCgfwyvM1L/W0s9unSe9LOtUMefo+S4XAs6F4AorCxkLGhHOUqyq/iRTzWolthZdV5TNYUFuN/11C9mXvyA8dVOT/OMDcWNvf7vQOT4agcr0J9N5beYM6Rp63GzuOoNhcuSx4IScf ertus4sP U+vY3RXDpAfw73kSEgr/4ADtKFvgZcIMrPG6u+CuBuffVk/bXBNgCfDGzLPWtlr6aG/bWQf1WySktNuRJB2tILWcJQDeHX0hxG06JC+SsxZFCno7JKn6Pqm6Bal/Ow4tU2Hwu+gcpLMIq0LjvgroA8yGRmTlqzimGnVANIjTfogu0aHBm+3cQV44u97NZ+MmCpOVA6fqys54qSwxXmfWijA6I+dap4Cahl9cmR3MnLdWreSDDrdpW27dc8xI1xcfEgGffs16ipDpIuFg= 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 __migrate_device_pages() won't copy page so MIGRATE_SYNC_NO_COPY passed into migrate_folio()/migrate_folio_extra(), actually a easy way is just to call folio_migrate_mapping()/folio_migrate_flags(), converting it to unify and simplify the migrate device pages, which also remove the only call for MIGRATE_SYNC_NO_COPY. Signed-off-by: Kefeng Wang --- mm/migrate_device.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 1b6658519f64..5c0237b7f26b 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -691,7 +691,7 @@ static void __migrate_device_pages(unsigned long *src_pfns, struct page *page = migrate_pfn_to_page(src_pfns[i]); struct address_space *mapping; struct folio *newfolio, *folio; - int r; + int r, extra_cnt = 0; if (!newpage) { src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; @@ -753,14 +753,15 @@ static void __migrate_device_pages(unsigned long *src_pfns, continue; } + BUG_ON(folio_test_writeback(folio)); + if (migrate && migrate->fault_page == page) - r = migrate_folio_extra(mapping, newfolio, folio, - MIGRATE_SYNC_NO_COPY, 1); - else - r = migrate_folio(mapping, newfolio, folio, - MIGRATE_SYNC_NO_COPY); + extra_cnt = 1; + r = folio_migrate_mapping(mapping, newfolio, folio, extra_cnt); if (r != MIGRATEPAGE_SUCCESS) src_pfns[i] &= ~MIGRATE_PFN_MIGRATE; + else + folio_migrate_flags(newfolio, folio); } if (notified) From patchwork Wed Apr 24 13:59:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13641922 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 AEF2DC10F15 for ; Wed, 24 Apr 2024 14:00:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C9858D001B; Wed, 24 Apr 2024 09:59:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D2988D0013; Wed, 24 Apr 2024 09:59:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C31FF8D001B; Wed, 24 Apr 2024 09:59:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3E3B68D0010 for ; Wed, 24 Apr 2024 09:59:44 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E23324097D for ; Wed, 24 Apr 2024 13:59:43 +0000 (UTC) X-FDA: 82044583446.29.95729C2 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf08.hostedemail.com (Postfix) with ESMTP id 470E516001D; Wed, 24 Apr 2024 13:59:39 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1713967181; 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=NOrRckkjpv1GZbrWZHGDKbwKYiLPnl2coNQstv+7hsw=; b=2PP728jHZOJmbhhS82LpidWXDmJej3v9EQu3w8Kk/0YmfJlo9RId63crz8TMC4cPvapOKW ctGfGJWQctBvTAEmUck9HhQxz7T4Mc48UoilZ958r9v6bKto9Dfgt+nhn4w0FXYCSCaknU prKTb8DlffwvSzDxS/Rl4sgVO9n80Zk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713967181; a=rsa-sha256; cv=none; b=GdEHjiKdgF+9kpqzO+N/FisYHuM5H02ATLJ2xj4UGDZkVDpvVH3Ypb/Cs+ZcD/fR1ENDSw aoOTBql/KOEJcwW1dTJVoeIPG0dqruHSskS1RGCklEWjFhn2sdrtA07LcpSQqhbqB9ia/Y lQnGnW16CDsmN4Divo4YQH776O87rgA= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; spf=pass (imf08.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VPgWY4SdxzwSNk; Wed, 24 Apr 2024 21:56:25 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 8AF18140156; Wed, 24 Apr 2024 21:59:36 +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; Wed, 24 Apr 2024 21:59:35 +0800 From: Kefeng Wang To: Andrew Morton , CC: Tony Luck , Miaohe Lin , Naoya Horiguchi , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , , , Zi Yan , Jiaqi Yan , Hugh Dickins , Vishal Moola , Kefeng Wang Subject: [PATCH v2 04/10] mm: migrate: remove migrate_folio_extra() Date: Wed, 24 Apr 2024 21:59:23 +0800 Message-ID: <20240424135929.2847185-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> References: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 470E516001D X-Stat-Signature: nna4w63nt5hiyrix3zhq8sq46pedzndn X-HE-Tag: 1713967179-725641 X-HE-Meta: U2FsdGVkX197nKErbYtnmruMH5oZr9tGnk8GeP0f6JQ3BZit+0RVk6QloraynDpbXcTG9L7xGyuZw7tjmmZChtA92J2O6u0M091QnPP6JgElcEFCmdFRsR++XSHU/23h0IEm5hlNVo+fKwRb1Izno37BFETb1IFnyWlY6kigRreB8MUbt73o2pn9QcS5PuKrk5fAePdeW7M84sGCi0ljx1/URcZiWVXLXtjIt34yvNaT40tfYoEL+t2nG0pvZMqnU/wwU5GcVnmSO8Ho2duiJVHGXd+qgLs4BbCfofDFMxgj1Phkv0Z3xnur+ELepguuptbTfEKqIDxbrwPtkOCP4/XG2GQ/eFSo4bQHCtbhAHK2gFNtWDI4iN7sovzGcddrrkNOar5kaF65swuqM9uQMqjJg/TaBcwgpFYIKQXCN/OXxwFx90ZQhgQL8C4t5cWYFEEacXlBJl/9aMMCWhJiAthBVEG4aym7CTnMVWL/cRZ744hGcNRdirWy2fssp4gDSWszqKdupmH8Gy96GjZedrQzRih7mNVPWOSsHzYEot25vZ3pk/sd2RQmqO2MmoaeXkp08XM8wf87vFyh1HcqxLGGL/3GTJrr7dgWm6TJg7mw8GAX7zId8ktizUNVN4GIblL6wDSkmLSjorXjRxyFH2BnJvQ8ySgGvjuzkzdwQ5sKvoZvWTVucC+5ydSJR+HRVJHA7xCZ4qoNZZwHbm8gI6oTL6y6eqRQIMw3KkCQPRLiPHNVyMReD3or2mDm7AkN7y4uYlGfszYH6OCjnS2lXE2O3/m3LSQ8chiixXSzC42j3A45rwOqyL3sFAybdPKUXr+UGtpWlodFGYc7RJFWuY7t+AjugveqCtTjouSCTQFEq5T2rE6R3b2aBHZ95Mhu9TJDPRsKY2ra4V4wq9qpsliY9wYOMEfl3q140Vzitn9TyLnXfUeGlhwHMfkQttkryAL9XWgTOssLhimu9ZV JpOA9yB7 P73Volht8hNLQVotrKpgZI7rsjxudF5Ju3Z4NNEOD5cQ7flkkpnXKcOkfvmiMR4MyLUywJrex2aONdJP3G2A46zLnLx/h7cBjRnUpCgRA/E9992VT4emyT4cDulGtTPMIFS81zpKFaMUDjWYX8Ra0iG8twKqfTDtGXioYk4Qqar3oWb+VuCffPlVgg+GWu3d/hSFU9EWD0jO1//Fmu4ueyVS01lTl6ebB7IqORCk8m9pyveHtptRGct/Kr2xt66mpiuTCBm8QrLnermY= 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 migrate_folio_extra() only called in migrate.c now, convert it a static function and take a new src_private argument which could be shared by migrate_folio() and filemap_migrate_folio() to simplify code a bit. Signed-off-by: Kefeng Wang --- include/linux/migrate.h | 2 -- mm/migrate.c | 33 +++++++++++---------------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 938efa2fd6d7..535d1a5561c4 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -63,8 +63,6 @@ extern const char *migrate_reason_names[MR_TYPES]; #ifdef CONFIG_MIGRATION void putback_movable_pages(struct list_head *l); -int migrate_folio_extra(struct address_space *mapping, struct folio *dst, - struct folio *src, enum migrate_mode mode, int extra_count); int migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, enum migrate_mode mode); int migrate_pages(struct list_head *l, new_folio_t new, free_folio_t free, diff --git a/mm/migrate.c b/mm/migrate.c index 9cc5a3e1d97c..ce4142ac8565 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -684,18 +684,19 @@ EXPORT_SYMBOL(folio_migrate_copy); * Migration functions ***********************************************************/ -int migrate_folio_extra(struct address_space *mapping, struct folio *dst, - struct folio *src, enum migrate_mode mode, int extra_count) +static int __migrate_folio(struct address_space *mapping, struct folio *dst, + struct folio *src, void *src_private, + enum migrate_mode mode) { int rc; - BUG_ON(folio_test_writeback(src)); /* Writeback must be complete */ - - rc = folio_migrate_mapping(mapping, dst, src, extra_count); - + rc = folio_migrate_mapping(mapping, dst, src, 0); if (rc != MIGRATEPAGE_SUCCESS) return rc; + if (src_private) + folio_attach_private(dst, folio_detach_private(src)); + if (mode != MIGRATE_SYNC_NO_COPY) folio_migrate_copy(dst, src); else @@ -716,9 +717,10 @@ int migrate_folio_extra(struct address_space *mapping, struct folio *dst, * Folios are locked upon entry and exit. */ int migrate_folio(struct address_space *mapping, struct folio *dst, - struct folio *src, enum migrate_mode mode) + struct folio *src, enum migrate_mode mode) { - return migrate_folio_extra(mapping, dst, src, mode, 0); + BUG_ON(folio_test_writeback(src)); /* Writeback must be complete */ + return __migrate_folio(mapping, dst, src, NULL, mode); } EXPORT_SYMBOL(migrate_folio); @@ -872,20 +874,7 @@ EXPORT_SYMBOL_GPL(buffer_migrate_folio_norefs); int filemap_migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, enum migrate_mode mode) { - int ret; - - ret = folio_migrate_mapping(mapping, dst, src, 0); - if (ret != MIGRATEPAGE_SUCCESS) - return ret; - - if (folio_get_private(src)) - folio_attach_private(dst, folio_detach_private(src)); - - if (mode != MIGRATE_SYNC_NO_COPY) - folio_migrate_copy(dst, src); - else - folio_migrate_flags(dst, src); - return MIGRATEPAGE_SUCCESS; + return __migrate_folio(mapping, dst, src, folio_get_private(src), mode); } EXPORT_SYMBOL_GPL(filemap_migrate_folio); From patchwork Wed Apr 24 13:59:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13641918 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 A6140C4345F for ; Wed, 24 Apr 2024 13:59:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F37EE8D0001; Wed, 24 Apr 2024 09:59:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BB74B8D0013; Wed, 24 Apr 2024 09:59:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96FC18D0018; Wed, 24 Apr 2024 09:59:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 64FC88D0013 for ; Wed, 24 Apr 2024 09:59:43 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1EF1FC1010 for ; Wed, 24 Apr 2024 13:59:43 +0000 (UTC) X-FDA: 82044583446.29.B6F676D Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf13.hostedemail.com (Postfix) with ESMTP id CD05F2000A; Wed, 24 Apr 2024 13:59:39 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1713967181; 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=+Baf5+y3xEGVLSMICdjOioJzAGqdEUd/r7Jd/zhwmr0=; b=JULeGp0Z1juNm9U0VZ3Nm/BSJSNJLMNR512kXiA418lyjTZPLdRzl/oW+fDQJd/CN1zCzh kOvV0vtwB/h+/63WvapYlx4VT3jm7L5Umdl5rfd1wFzWKeGx2FW2woyOZ5Nma25HQVtWvo NxSLsFR4bXzpr7W5JIp2sYeXeormFUE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713967181; a=rsa-sha256; cv=none; b=bACYFvthuEdMbualUV8jXtBbdq4pSPjGasCuxlZ/0WGgwnQsiv1y4VHJYRI3hCMmDJc+p9 r6vEpDt5zXtQAvc1tkKiAZyrSwSmmOVygmnOVeoGMZ5ahIeHRmq450NhFs9sZXE3/67aS/ bGwn3aLAzVSuB8OLA4qeIzj6o99ywJI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VPgWC4KHqzXlVt; Wed, 24 Apr 2024 21:56:07 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 481EE140156; Wed, 24 Apr 2024 21:59:37 +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; Wed, 24 Apr 2024 21:59:36 +0800 From: Kefeng Wang To: Andrew Morton , CC: Tony Luck , Miaohe Lin , Naoya Horiguchi , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , , , Zi Yan , Jiaqi Yan , Hugh Dickins , Vishal Moola , Kefeng Wang Subject: [PATCH v2 05/10] mm: remove MIGRATE_SYNC_NO_COPY mode Date: Wed, 24 Apr 2024 21:59:24 +0800 Message-ID: <20240424135929.2847185-6-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> References: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: CD05F2000A X-Rspam-User: X-Stat-Signature: htzd8qpq6wmyfb8c4mk9i1naw5b313ts X-HE-Tag: 1713967179-382243 X-HE-Meta: U2FsdGVkX19P+bwyk0yapF7gI73rpSjGnQroNmAyCMQGttXWl+jqzGagkGdr5E0zuhsPKgCG6N63JV2meHM87OqLYaOAmARtB33UhKdOATJYJHV7rl/vhqBUtlmHP98Qp6QdTDC+RSngT0yemtTvu6aJ9Ut1m4k/cc8ICLsP0wTJgpr5+OjNmFFmeJoword/6VPqe0TX6Fz3vpi/qqGICza0vzUBEgWQcepUtvB72praVVxkTa1nrfhqESzlczg7MNiEB3N8Z7eG6wKH5Kv/N5wRXZUKUooOi8Pyl+F+hjtu+NdLA51ZSVBF/LVaIl0iiOUymlsTEdEqpXPt2b7v1XilarzazpcRV/F/mwD5NCq7dS6OGyGswWk2e19nIYMhabAyTt+UXIM4PM4DyShNxue0ewRSZSFKpIBrUKF9cIaMAq7PPcywTxVWnSkoZFzF6X9e5daJOYTzc9azTPM6jZ5amvJtqafEqXi6mxR1LZM6djxykZGsfqCeAlMxTiOPHgKPX1QmU8p44uQlwI/B5PdTsiGGRLASRVNgMqAkU+1AG1if6RIn7PmydrvVeP0UMf3p2+Ry8qMiEoFUkiDT4lMfJRTXN0vBs0+x3OnEgxq+eCyxf71+cMT6IVsd0PZirztNwPm1ZlPeuqRW3IE61////jvuy4tGsS0CP1J4lQtTQ/oYy2uR0c5Zqo7Amuj8/U/1j7GjbgcywMKx4L2cgJ9zRb+WU2uqKhVO8UrecboqgVJo9I+Axqib2bYhzYmGD0C24LnbBGfqgsnRkPaRuUP2hpbLuXcJhPW5mwTIzMxAdWhkwy8ntkyhm0VpiD7wrHt5nLWoCN+QNRQs1/MQAY1AazmyKNCQzFsmSGFZYEcLm47mhVPnWgjzf+pk5EDEyKEY45+xBLD49QQT4ckpQwPxpFJCqEXhE4a66lG29o58C6BGXC0WtWs94/EuAAuVivMnlpCm4DTKE7brJr3 sMg== 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: Commit 2916ecc0f9d4 ("mm/migrate: new migrate mode MIGRATE_SYNC_NO_COPY") introduce a new MIGRATE_SYNC_NO_COPY mode to allow to offload the copy to a device DMA engine, which is only used __migrate_device_pages() to decide whether or not copy the old page, and the MIGRATE_SYNC_NO_COPY mode only set in hmm, as the MIGRATE_SYNC_NO_COPY set is removed by previous cleanup, it seems that we could remove the unnecessary MIGRATE_SYNC_NO_COPY. Signed-off-by: Kefeng Wang --- fs/aio.c | 12 +----------- fs/hugetlbfs/inode.c | 5 +---- include/linux/migrate_mode.h | 5 ----- mm/balloon_compaction.c | 8 -------- mm/migrate.c | 8 +------- mm/zsmalloc.c | 8 -------- 6 files changed, 3 insertions(+), 43 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 6ed5507cd330..dc7a10f2a6e2 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -410,17 +410,7 @@ static int aio_migrate_folio(struct address_space *mapping, struct folio *dst, struct kioctx *ctx; unsigned long flags; pgoff_t idx; - int rc; - - /* - * We cannot support the _NO_COPY case here, because copy needs to - * happen under the ctx->completion_lock. That does not work with the - * migration workflow of MIGRATE_SYNC_NO_COPY. - */ - if (mode == MIGRATE_SYNC_NO_COPY) - return -EINVAL; - - rc = 0; + int rc = 0; /* mapping->i_private_lock here protects against the kioctx teardown. */ spin_lock(&mapping->i_private_lock); diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 412f295acebe..6df794ed4066 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -1128,10 +1128,7 @@ static int hugetlbfs_migrate_folio(struct address_space *mapping, hugetlb_set_folio_subpool(src, NULL); } - if (mode != MIGRATE_SYNC_NO_COPY) - folio_migrate_copy(dst, src); - else - folio_migrate_flags(dst, src); + folio_migrate_copy(dst, src); return MIGRATEPAGE_SUCCESS; } diff --git a/include/linux/migrate_mode.h b/include/linux/migrate_mode.h index f37cc03f9369..9fb482bb7323 100644 --- a/include/linux/migrate_mode.h +++ b/include/linux/migrate_mode.h @@ -7,16 +7,11 @@ * on most operations but not ->writepage as the potential stall time * is too significant * MIGRATE_SYNC will block when migrating pages - * MIGRATE_SYNC_NO_COPY will block when migrating pages but will not copy pages - * with the CPU. Instead, page copy happens outside the migratepage() - * callback and is likely using a DMA engine. See migrate_vma() and HMM - * (mm/hmm.c) for users of this mode. */ enum migrate_mode { MIGRATE_ASYNC, MIGRATE_SYNC_LIGHT, MIGRATE_SYNC, - MIGRATE_SYNC_NO_COPY, }; enum migrate_reason { diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c index 22c96fed70b5..6597ebea8ae2 100644 --- a/mm/balloon_compaction.c +++ b/mm/balloon_compaction.c @@ -234,14 +234,6 @@ static int balloon_page_migrate(struct page *newpage, struct page *page, { struct balloon_dev_info *balloon = balloon_page_device(page); - /* - * We can not easily support the no copy case here so ignore it as it - * is unlikely to be used with balloon pages. See include/linux/hmm.h - * for a user of the MIGRATE_SYNC_NO_COPY mode. - */ - if (mode == MIGRATE_SYNC_NO_COPY) - return -EINVAL; - VM_BUG_ON_PAGE(!PageLocked(page), page); VM_BUG_ON_PAGE(!PageLocked(newpage), newpage); diff --git a/mm/migrate.c b/mm/migrate.c index ce4142ac8565..6a9bb4af2595 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -697,10 +697,7 @@ static int __migrate_folio(struct address_space *mapping, struct folio *dst, if (src_private) folio_attach_private(dst, folio_detach_private(src)); - if (mode != MIGRATE_SYNC_NO_COPY) - folio_migrate_copy(dst, src); - else - folio_migrate_flags(dst, src); + folio_migrate_copy(dst, src); return MIGRATEPAGE_SUCCESS; } @@ -929,7 +926,6 @@ static int fallback_migrate_folio(struct address_space *mapping, /* Only writeback folios in full synchronous migration */ switch (mode) { case MIGRATE_SYNC: - case MIGRATE_SYNC_NO_COPY: break; default: return -EBUSY; @@ -1187,7 +1183,6 @@ static int migrate_folio_unmap(new_folio_t get_new_folio, */ switch (mode) { case MIGRATE_SYNC: - case MIGRATE_SYNC_NO_COPY: break; default: rc = -EBUSY; @@ -1398,7 +1393,6 @@ static int unmap_and_move_huge_page(new_folio_t get_new_folio, goto out; switch (mode) { case MIGRATE_SYNC: - case MIGRATE_SYNC_NO_COPY: break; default: goto out; diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index b42d3545ca85..6e7967853477 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1752,14 +1752,6 @@ static int zs_page_migrate(struct page *newpage, struct page *page, unsigned long old_obj, new_obj; unsigned int obj_idx; - /* - * We cannot support the _NO_COPY case here, because copy needs to - * happen under the zs lock, which does not work with - * MIGRATE_SYNC_NO_COPY workflow. - */ - if (mode == MIGRATE_SYNC_NO_COPY) - return -EINVAL; - VM_BUG_ON_PAGE(!PageIsolated(page), page); /* The page is locked, so this pointer must remain valid */ From patchwork Wed Apr 24 13:59:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13641921 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 822E8C4345F for ; Wed, 24 Apr 2024 13:59:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 183B78D0012; Wed, 24 Apr 2024 09:59:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 094338D001D; Wed, 24 Apr 2024 09:59:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDD2D8D0013; Wed, 24 Apr 2024 09:59:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 767968D001D for ; Wed, 24 Apr 2024 09:59:44 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3540B1C03FD for ; Wed, 24 Apr 2024 13:59:44 +0000 (UTC) X-FDA: 82044583488.07.E0180A4 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf01.hostedemail.com (Postfix) with ESMTP id BEF4340011; Wed, 24 Apr 2024 13:59:40 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 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=1713967182; a=rsa-sha256; cv=none; b=rxz/WWpAhUNemoOZwMP0gHWcV4htowaJTd77NCqoXJn02sKl6chlAaxo3EFQjWKkBHrJC2 M6ZDAnBjndeNwRQXlxf8JpSyBrTLj5yGtPQpKdXpAUul1ipX4kRQpjdQq8bwm8Zyv7kQfk dqr/7F1EjniEn572fSpO24xzl3a8qtg= 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.188 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=1713967182; 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=AuCRYv5qf7jpoyEmEUvAKvvJNQvrHxNIxCpDBspvJfE=; b=tpPJEEYBTn4DxGFOXQDNGTcUPVrxjK4LL9ldoFs9nDc+80D7RJWF9hBaEcHmhLfV715ii8 X8N8TLYzR3JnH+k9iJfhiKoy9u9UGN9LmfHSYDGHi96k3cB/sRdlYffYPm6WV+r1rogBJL D2DBPb80IuNCQBxJGRIQHqjIYsMS2FU= Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VPgZ12htfzShdP; Wed, 24 Apr 2024 21:58:33 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 0B09318007B; Wed, 24 Apr 2024 21:59:38 +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; Wed, 24 Apr 2024 21:59:37 +0800 From: Kefeng Wang To: Andrew Morton , CC: Tony Luck , Miaohe Lin , Naoya Horiguchi , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , , , Zi Yan , Jiaqi Yan , Hugh Dickins , Vishal Moola , Kefeng Wang Subject: [PATCH v2 06/10] mm: migrate: split folio_migrate_mapping() Date: Wed, 24 Apr 2024 21:59:25 +0800 Message-ID: <20240424135929.2847185-7-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> References: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: BEF4340011 X-Stat-Signature: 7pj53gmn4pixnft6t9o5hcrettyjqyqi X-Rspam-User: X-HE-Tag: 1713967180-777942 X-HE-Meta: U2FsdGVkX19Q9hck6UKoTlnUzR0+3fBVousmoqj5jHXCc/d0jT8AZ0AWxK2XX2/TjuTxksjlLAU/Qru6sjSs1WmAvPRpV4824GSH27lRmM7eUx86/gTJjeHlRaNbYLNWJk3bTyPJpzkAKlX0eYqKPQfOLKohveaCjxdv6im3VGwjHvJ3W3dhs17KaaFCv+v1+X89/qMjui8Sh4IpuFQN6OeogzDvj9go/Mu2ZJlYRB3TtE38q3e+p+JXpRY/l581qy2a4eLcB+H3OIRE+bzcD9d7Ply6vyTYzpoubgbCOSmEArkBaiPflHbWvCMcgpILtMGFuJG+3DNyLYU2eJPJDjg3PvMB3FwcTaVzzp2TTiC6qr702cgraEfyTLaK+NmXyl0A9f1uk7fWL79/IQaqx2iRod7m2NKNi1e95nSuDCLtljt9ny2GcLaeJfwFMHz2ffUS/qZrpmvqmM3b8giOZK1YI+mW1MORMEO8Cd4OKAgrTlWJntq2zAXx1eKKh+lJFeS/spFlv/IBYqbyW1PIdMlOaWBKuJlq6MiPtZOuW3cFGMcuEtrO9UvCIQAPHYKvdPiAd9D8nNK/LABfQdls9WmkmTcaK8ePTQQ+ioM2eMgSjHNsWO1BkbJT1CxmPI64aLq5TD+zr20sz5z6174a6YvZPe34vYXdxtPe08ZeAr4aIXkEA3BVXpGuWpdJUj8CXLzt5OaNHSTLc4jNlYuUpqXgc0jpVquef6q/inVIIJ0p/37Kclb3CXLhJn6yiSGvFK/hUmSAC1QVrfW/ve5IV+80BeHv5Fo/AmFNpkd99HDMG7TBsoU+pL7+3ZcmuP12vxHrSh/ODzK2lWsWxy+byDUztn6wgW/pMk4q0/eNr6T42wO6nZK8P3kKF1mQIc1qepY9wHLvnhCAMVCQQdx9CP7aCxZCFakIoGDhoqe2dw8atVWbkSlDHdRQUS8G8H4uBAZ9FtYl7LzeAEO2fnv OkwJ6y5w i1TRuKO0UuUtKx/MtIXbFif0mfYHP8E1Hu1U/ujwbjdwRJYUl2Dslc5xSCzR9HTic7dYl5yrpmr+8suQ9CweF5g7wX0NRtJsaYqBXKjffNGZOS79jpplOVV53HaZJrZI4ynf6Sgz1AyfTcTGBsdNjsw1rkbEx5m95AbHJB9W/n/BItMxihUPwPZti2C2kxSPtrcFCitm2fAp08wjpBPEzgip3k4SOvMjHkUc4lB4T5Zgm0aY4EZFyMqxFzfadHIySpI+njRqlMmMeCtU= 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_migrate_mapping() function is splitted into two parts, folio_refs_check_and_freeze() and folio_replace_mapping_and_unfreeze(), 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 | 74 +++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 6a9bb4af2595..b27c66af385d 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -419,50 +419,49 @@ static int folio_expected_refs(struct address_space *mapping, } /* - * Replace the page 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 int folio_refs_check_and_freeze(struct address_space *mapping, + struct folio *folio, int expected_cnt) +{ + if (!mapping) { + if (folio_ref_count(folio) != expected_cnt) + return -EAGAIN; + } else { + if (!folio_ref_freeze(folio, expected_cnt)) + return -EAGAIN; + } + + return 0; +} + +/* The folio refcount must be freezed if folio with a mapping */ +static void folio_replace_mapping_and_unfreeze(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); + /* Now we know that no one else is looking at the folio */ 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. - */ newfolio->index = folio->index; newfolio->mapping = folio->mapping; folio_ref_add(newfolio, nr); /* add cache reference */ @@ -478,7 +477,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); @@ -492,22 +491,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. */ @@ -544,7 +543,18 @@ 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 ret, expected = folio_expected_refs(mapping, folio) + extra_count; + + ret = folio_refs_check_and_freeze(mapping, folio, expected); + if (ret) + return ret; + folio_replace_mapping_and_unfreeze(mapping, newfolio, folio, expected); return MIGRATEPAGE_SUCCESS; } EXPORT_SYMBOL(folio_migrate_mapping); From patchwork Wed Apr 24 13:59:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13641923 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 61D4DC4345F for ; Wed, 24 Apr 2024 14:00:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6C3E8D001D; Wed, 24 Apr 2024 09:59:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A08638D0013; Wed, 24 Apr 2024 09:59:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FC098D0017; Wed, 24 Apr 2024 09:59:45 -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 4AA1C8D001F for ; Wed, 24 Apr 2024 09:59:45 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0B0E214036A for ; Wed, 24 Apr 2024 13:59:45 +0000 (UTC) X-FDA: 82044583530.01.FC669DE Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf01.hostedemail.com (Postfix) with ESMTP id EA33E4000A; Wed, 24 Apr 2024 13:59:41 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1713967183; 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=SCexoy3QOIvE9h0oQt70L02W57GetfdhfaowtDPnZ3E=; b=fW/R5WMU259FtVbVBEnpQaLNUNcT/U5yGqSbR6AKn3ggS9/z8XGKHnd8pflrijthvkuO8o 5WKbp3rMVNb5xPciGBsGMfyRs0culBWDauvHWpM3tn252PoTbBXAnlCmnJ8pKZXDIHoRFu 3S6EIPl7dbwgspM9blgsq8zPgrya5C4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713967183; a=rsa-sha256; cv=none; b=zxocv+UdgCWIansSzxD0/YeirSxjuRY5vtFC1h2wlXYhsUm99mIcgpKL0h91SHgcTQPxpm WkgnwXJLij5A4Ix6rp0aLWPhn0mpYeovt0+UMezlGSogw3ev3JFQhMxXJSYT/plLwXr2k+ wK5K8eGakaHOBOuvVTs+0M3+bubvNaA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VPgWb5tC8zwSJR; Wed, 24 Apr 2024 21:56:27 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id BBADA14011F; Wed, 24 Apr 2024 21:59:38 +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; Wed, 24 Apr 2024 21:59:37 +0800 From: Kefeng Wang To: Andrew Morton , CC: Tony Luck , Miaohe Lin , Naoya Horiguchi , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , , , Zi Yan , Jiaqi Yan , Hugh Dickins , Vishal Moola , Kefeng Wang Subject: [PATCH v2 07/10] mm: add folio_mc_copy() Date: Wed, 24 Apr 2024 21:59:26 +0800 Message-ID: <20240424135929.2847185-8-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> References: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Stat-Signature: wpcfxcko6ep8ccbzmspbci1556jecupo X-Rspamd-Queue-Id: EA33E4000A X-Rspamd-Server: rspam06 X-Rspam-User: X-HE-Tag: 1713967181-758772 X-HE-Meta: U2FsdGVkX18Y4EgZ0nAz1ATpGpbypRBfP1g21GYLUH0lf2mhgWNCwqj2ipxs5PYFL1UcT5IP5hej/3JtuPVSmYgIkq+IjfsQ7Q7zhb0C8f6Js2eUBjLUOipUqZQGmDvzzLkmzc01OrMb1npEBUySxVcbRk8O5UIQmcY6JNiQ6ELUG/nDD1ycAIQnppD9Jjx28Ymt5NsMqp2xue36dxbMJP/sAIIThSupaIl3dPgDTUCViDRXHJNwt3LURxX5YjSlXvWDu9K1W9HVanEiw+GXJvNwwAElOYIcigMZpx4ad9y/yAdEAThb8yLr82f8mmy+Pv5wK5Vig8Cyw8sAfvltulx+gW0T1Y8g5bxeSPE/S4eXo7z+IrhYWCKWIWV+Kxp8hUE6msFbQ9w3fDyeddjZreEfA9i7WTCV4dUMUxoU+Ox1g2FQw26ellttQXdNuNw3yS9Xxw1VMeHCfuLTOQb6j04k3blDm5L1czc4DmWmvdt45JRQTViBnxqotz30tUcFIrEJAXRHRHdyhQBHt0wNkYxZtJrBlkbUuHJCN6+wGyCCRIOsKiF4FkqqSNUKbiF8/kdHIhUJNxtq5HdlX4gj4C+4hO2auYLGwiuMn/2ZQlST8W2W5NMlZOoxoEztmC7w0Ek1CM3jBTF/FL/Mbyo/FE9jgZVa6KZOoqXx46OaIrFxO1X8TGoPXnFq9reGhzV8dOueGeWkyNivQ4TgsTQHff5mlJuJ/4GA8rGVnF4BMt2esB7Jqcx2+et1yl/2hG5DDqJ1o7i45i0sK9DIVNX/teqJNCwQcQ2BdGiXl9NFkHp8MTgz8DcS57yVCqeiTYqy+kKaQ5wVcLvwHZ5OSllGk3FcDOQwkXv6qNa63/AMeDpDsl0K08gfbmy1EGYnpUyk8MA8FFypC3Bmvu4gNsu7A8K+R9UKP2FwJ5nhvWnyR7T+luL7gCrh6iDmEs+5viaR86+JWSWm49vde0obd83 6eLbzo4s 7qRF/gH3hmzfIJ2QtcOKeMnUPDD3aIqPT3AubcNW5CXeuSw0EwYF5kGsZCUvzcO/zePTOpQu0PtSCSWoD60wCXsw6OgNJSVLPSQOTUXjINqRUH1toLtowPzOjN83RYm7e929anrmYb303HL4Dh08lkm7FM21RiNJ/nju8Jjf5qGis0Y1QCG+ZsgB10RZ8kMJr0k36Xtnhs1SpQ0A3ayfzjEFpdjOkyiwA/DEXQ7aqK9NL9fq+Xn1JDpz9AfZzYJLby4Q7CRj4SSdabj4= 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: Add a variant of folio_copy() which use copy_mc_highpage() to support machine check safe copy when folio copy. Signed-off-by: Kefeng Wang --- include/linux/mm.h | 1 + mm/util.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 326a4ce0cff8..89bbb2064a97 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1317,6 +1317,7 @@ void put_pages_list(struct list_head *pages); void split_page(struct page *page, unsigned int order); void folio_copy(struct folio *dst, struct folio *src); +int folio_mc_copy(struct folio *dst, struct folio *src); unsigned long nr_free_buffer_pages(void); diff --git a/mm/util.c b/mm/util.c index c9e519e6811f..9462dbf7ce02 100644 --- a/mm/util.c +++ b/mm/util.c @@ -828,6 +828,26 @@ void folio_copy(struct folio *dst, struct folio *src) } EXPORT_SYMBOL(folio_copy); +int folio_mc_copy(struct folio *dst, struct folio *src) +{ + long nr = folio_nr_pages(src); + long i = 0; + int ret = 0; + + for (;;) { + if (copy_mc_highpage(folio_page(dst, i), folio_page(src, i))) { + ret = -EFAULT; + break; + } + if (++i == nr) + break; + cond_resched(); + } + + return ret; +} +EXPORT_SYMBOL(folio_mc_copy); + int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; int sysctl_overcommit_ratio __read_mostly = 50; unsigned long sysctl_overcommit_kbytes __read_mostly; From patchwork Wed Apr 24 13:59:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13641924 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 EE7C7C4345F for ; Wed, 24 Apr 2024 14:00:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94D0B8D0023; Wed, 24 Apr 2024 09:59:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 80F6A8D0021; Wed, 24 Apr 2024 09:59:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59F808D0020; Wed, 24 Apr 2024 09:59:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2D2018D0013 for ; Wed, 24 Apr 2024 09:59:46 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EF172160DC0 for ; Wed, 24 Apr 2024 13:59:45 +0000 (UTC) X-FDA: 82044583530.17.46E5139 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf03.hostedemail.com (Postfix) with ESMTP id 31B8420028; Wed, 24 Apr 2024 13:59:41 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.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=1713967183; 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=kNW8OqtsQ7OYIXjhgVws521+WAPaUqPunCADCbHaJbQ=; b=QcGR2v8JPgeIu6KyRVkM0B7X6mVIykRuYZBazeiEJ2riE583pbpmQLNYcrbrynBpodovkC +xoZRx3W52IvpIOyJmkHo5KvwEZZ4mSUoAaLlnbLLTzIXWpE+41JwSyfsZkyIuo5wD+i1I N9Cvwss5tpGZ5l5x7amouMmwDsfCw6Y= 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 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=1713967183; a=rsa-sha256; cv=none; b=SNSuInr2Yrup3qBEqjhPJu49OOXwhfh3ag2pVT6wWkCN8gdHsjcMcFghHPLrhS9jnD5Hjq kwbGUBqGkYzZp8bTI321A0V7mtVjZx9kfH9culixfYxMYnDtMfws1hAC5GNapAm8RSCUPs EVT6ss68rLdwFbsw/bwLK/vGP4oHl5c= Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VPgZ25zHVzShMx; Wed, 24 Apr 2024 21:58:34 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 7B3F418006B; Wed, 24 Apr 2024 21:59:39 +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; Wed, 24 Apr 2024 21:59:38 +0800 From: Kefeng Wang To: Andrew Morton , CC: Tony Luck , Miaohe Lin , Naoya Horiguchi , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , , , Zi Yan , Jiaqi Yan , Hugh Dickins , Vishal Moola , Kefeng Wang Subject: [PATCH v2 08/10] mm: migrate: support poisoned recover from migrate folio Date: Wed, 24 Apr 2024 21:59:27 +0800 Message-ID: <20240424135929.2847185-9-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> References: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 31B8420028 X-Stat-Signature: 9m8jcset74ducj8si1kjzhn8bky3kajm X-HE-Tag: 1713967181-17171 X-HE-Meta: U2FsdGVkX1/52oUsXarjacY5AEsWBL9+zDdoO3mJrZyR9xG9Q9FtdmuAhT/FMv/QSVriFFv1OtFx+a+mldiH65VHhzYojUtifvCkNsqBYoRRJ8WuAQPKj0reObx1ee/n4OVKDUDbLJDr0zmGBe2aRNVPB1Mnjm68HNz09mXrOXLyLTIaW6XM6/K3mH1pRCmjErDfGjsD2wIm4N8w9o1KL7r5gBjiFxZGCnQQTWk0fwSIA7m7YAIkXjL5BJj/XtGJOifBesqCRDa1So6oeashbX6bMakVchA7mG51NEMMIQcQzvZ8g/pyh0CWNVd4vApWxIyy75DWV9VSXsA7jyJS3HYZQEgjYicG1YdbkchssB8bCwCMDpb98i/iCD6HOtc6tsKQZ82y7kuBg2/ajc+S9s56OA7LfQ4T6iLF5NanWLgrUO3s0v90y+DAjjCxKVL5QEpKqJWuUZMQLNNHeExyegDNPc951jZ/Zc5XYat0s56LG++dGwqI0QZuT2HrmXfjxnpUm/FGOBwWapAiW8nR8QbZmmmAcOquOFggDT8WEAe7cNy93DMllJIQC5omNDZie1+QcFnbHbewBYVVh9PmxRxzCjAt2owFju8gEfYOv8UmkV/rFmgPWpHgnB7g9yg8Yu1sZd8smD7/GsBA+LWXrl78QA8GrPLS3X0SL9jDirNs/2ufc8qMgPuYDNZKhWrDkIFkZQLuBcu8POYnzwSBoQtt4qCghomDCkmYyYIRg4rxkX6QfZLb5ADR1/oKgGK/TOBRFQsB5rc5YPZQrv/rg47EluZgOtwFUer/cxaNmhqM/TbYJ/opkqe96/wHHr0akEun4YbZvtSUO1cK5Tmaqg1MFgPFojz8Dl2UIAwnp2xdH0Di3WgzubsgelEoe6OCff5ofd9PHoLQRm3U0EYSr+a2pnnvp7tK1my/JZyTawJ/adlR693IklBf5bKEYWU8sqqKXRrfywFm7JeN1eM w0PPGTMG cwLarZstOebNfVTusaL1eUG6i/9AyS3I5PQHncmZIRhyK0JybFRlhteh9Y+wCauAATCIjztGKOBZQc2BJcuNUO0QRvBBmJs2AcOMWY54Th0kZtYAHWaSZjeVOdZea928n7dSxrW0WGpDX3vvWPy0QoIOXV9Aq+zker+gHXx7628ajTsJpIpVoiWSMLRbwIXtFYYcgk5jMmuXzpNf9HRdlcl/AM9/YVx+WuXnJ 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 migration is widely used in kernel, memory compaction, memory hotplug, soft offline page, numa balance, memory demote/promotion, etc, but once access a poisoned source folio when migrating, the kerenl will panic. There is a mechanism in the kernel to recover from uncorrectable memory errors, ARCH_HAS_COPY_MC, which is already used in other core-mm paths, eg, CoW, khugepaged, coredump, ksm copy, see copy_mc_to_{user,kernel}, copy_mc_{user_}highpage callers. In order to support poisoned folio copy recover from migrate folio, we chose to make folio migration tolerant of memory failures and return error for folio migration, because folio migration is no guarantee of success, this could avoid the similar panic shown below. CPU: 1 PID: 88343 Comm: test_softofflin Kdump: loaded Not tainted 6.6.0 pc : copy_page+0x10/0xc0 lr : copy_highpage+0x38/0x50 ... Call trace: copy_page+0x10/0xc0 folio_copy+0x78/0x90 migrate_folio_extra+0x54/0xa0 move_to_new_folio+0xd8/0x1f0 migrate_folio_move+0xb8/0x300 migrate_pages_batch+0x528/0x788 migrate_pages_sync+0x8c/0x258 migrate_pages+0x440/0x528 soft_offline_in_use_page+0x2ec/0x3c0 soft_offline_page+0x238/0x310 soft_offline_page_store+0x6c/0xc0 dev_attr_store+0x20/0x40 sysfs_kf_write+0x4c/0x68 kernfs_fop_write_iter+0x130/0x1c8 new_sync_write+0xa4/0x138 vfs_write+0x238/0x2d8 ksys_write+0x74/0x110 Signed-off-by: Kefeng Wang --- mm/migrate.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index b27c66af385d..60d4e29c5186 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -698,16 +698,25 @@ static int __migrate_folio(struct address_space *mapping, struct folio *dst, struct folio *src, void *src_private, enum migrate_mode mode) { - int rc; + int rc, expected_cnt = folio_expected_refs(mapping, src); - rc = folio_migrate_mapping(mapping, dst, src, 0); - if (rc != MIGRATEPAGE_SUCCESS) + rc = folio_refs_check_and_freeze(mapping, src, expected_cnt); + if (rc) return rc; + rc = folio_mc_copy(dst, src); + if (rc) { + if (mapping) + folio_ref_unfreeze(src, expected_cnt); + return rc; + } + + folio_replace_mapping_and_unfreeze(mapping, dst, src, expected_cnt); + if (src_private) folio_attach_private(dst, folio_detach_private(src)); - folio_migrate_copy(dst, src); + folio_migrate_flags(dst, src); return MIGRATEPAGE_SUCCESS; } From patchwork Wed Apr 24 13:59:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13641925 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 B0511C4345F for ; Wed, 24 Apr 2024 14:00:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2C328D0020; Wed, 24 Apr 2024 09:59:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DDB758D0017; Wed, 24 Apr 2024 09:59:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C04848D0022; Wed, 24 Apr 2024 09:59:46 -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 726318D0017 for ; Wed, 24 Apr 2024 09:59:46 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2A8301608B5 for ; Wed, 24 Apr 2024 13:59:46 +0000 (UTC) X-FDA: 82044583572.22.8ADC6FD Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf29.hostedemail.com (Postfix) with ESMTP id E6ED3120016; Wed, 24 Apr 2024 13:59:42 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1713967184; 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=upFkI2XpQGH06l4wc3gzZMhU250ficRWyophhap6ZXc=; b=6OESfR4ch60cwOza3QGREOVxRYbPnEk9zpijDhyv+FbZvH6lr9SnjbGBkiRyq7HBLl6S4E /oQWRM9hO+uEfS2XyLHKcEOEMo71P4b9jrJ4PCfrTTHoQ/gzA+LR7HJJqNDLz071DXLV5m PE/usSQCKzU3eHcDCHkdLtSDjA9/eeo= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713967184; a=rsa-sha256; cv=none; b=5HCUE2FjmMjZdOL2x6wjT2LeruD548LYRBhZ1q7WMZr/hdfJ954HgjD3rTcmBWFRoWfIy2 yuzvmR3tx5WvlcCcRNatIPSmzL8/mKf64JgZmC4Efseyh/EMTYIoEwVRND5JbRRDtgGLW3 +7jrQfCiQ1A8bKswo2k0YkpetYM07B4= Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VPgWp2WqqzvPrC; Wed, 24 Apr 2024 21:56:38 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 39DE518007B; Wed, 24 Apr 2024 21:59:40 +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; Wed, 24 Apr 2024 21:59:39 +0800 From: Kefeng Wang To: Andrew Morton , CC: Tony Luck , Miaohe Lin , Naoya Horiguchi , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , , , Zi Yan , Jiaqi Yan , Hugh Dickins , Vishal Moola , Kefeng Wang Subject: [PATCH v2 09/10] fs: hugetlbfs: support poison recover from hugetlbfs_migrate_folio() Date: Wed, 24 Apr 2024 21:59:28 +0800 Message-ID: <20240424135929.2847185-10-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> References: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E6ED3120016 X-Rspam-User: X-Stat-Signature: ko1aqfs7xrzpwaq3uueqqgy6se773h3s X-HE-Tag: 1713967182-397471 X-HE-Meta: U2FsdGVkX18nufQ9za1nzo4Ec6jSJAxBjIAAia9x4qbaBCer9PKvcOTevBsLEll7L5Z6JmlCkNZ/C3O4NW/cxFuogeDE2MpbuhMOehGHflKpswUoQilWHaihwIIALq+0am3S8btHFmFHB5cQodASqOv00gtYMJmQdZpCU5M1pskW2SOxQTuyE16OO6z3v7xBGAGnF6nLvF++djm4A5Y6Z0eix+PtK+xgZiyxZSyGZZtoyQlt5en5URAGFpB80u9Hukx9Tsb3DB7OJNH+YI2QADoCvXZ2dRKhqYOUY4HHg+RerHc+jmjWeyQpvhP7L2WVzFswDHkTAwQ6qG/g0PhODRCrgz6k/JVJa3j4S5Xea6EJEFsNSkZeg9qgEivvbVcW5etNuOU0KdnuY08eH5UrCA5cDYfmRhZLXOHfPR7DY+u6XTrHwr74c1atv9gK+DboQF5BG/8XaJxFpYsXbalUg6L77AnoGOGYETJXdUo4ejQyTQoBW2kX1GBzw6Zt1bsRCbMxY34JWTws7B8gSJ9RigyRErJbYKEV6id2K5R31DhujLCJoHm7BPtfCuniLBr0pE/UEMMI9d2YBzShUfO+C4BSb4I5Y17NIZ9xvVnnLfOx35IFkQGqE5fL7KbzAQfacCcoEZKYaZgkWJJtZoaEF0gaHofEEMnYWFdOjpi5TcJGKO0HBS6RP9kRuoO82l9dJ2J/ZhXs0cX4tXcpAKvOnbgV/KBypdNbDdjZE1YuhsoqbASMpwBeHHMTu4bYbl6OEQNaD4BA5uQOfyh9ZrBr1jRLldtFbPJK9zQPhlhI22YQIs0OLYKlNMW+tdYvcT1VuG034v7RLvhSidQZ6M90RGBG486cZtWU7HFYtmgvGDwkHl8cu30TG/oM2/p/cFSEP3Ru6HpgPfqqYUr98nkBqj8Poz4VSEjy6XLE/o/ubFncXG3+Op1aNnToAOui1CuJJK+AN781djOu8or+j93 ZGs0xv9v 2GXhzb9Kpwh1rIs1sln5l470W4AXTwbJlNM8in9vfmWFKQcc2tCmHii7ifoiOkSInrcqP2u/kCYuRxTVgPXVPYD/14A7ZxNsTBljMjqVDHM4t8F6tPV9IBeySYHzGcdwQei5veIIkWlsMMq7zRubAKm3i6xxRliE083fiUef5AbOMuTMi/nkBaXSKo3abhq6JRa+MIrS2DVVqhxnp8jYvghLaEJrVeO/AV3BZLHH8yCgnQ783eOKHj4xKOgvxL9z7pmuRSakK1hfG0YE= 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 similar to __migrate_folio(), use folio_mc_copy() in HugeTLB folio migration to avoid panic when copy from poisoned folio. Signed-off-by: Kefeng Wang --- fs/hugetlbfs/inode.c | 2 +- mm/migrate.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 6df794ed4066..1107e5aa8343 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -1128,7 +1128,7 @@ static int hugetlbfs_migrate_folio(struct address_space *mapping, hugetlb_set_folio_subpool(src, NULL); } - folio_migrate_copy(dst, src); + folio_migrate_flags(dst, src); return MIGRATEPAGE_SUCCESS; } diff --git a/mm/migrate.c b/mm/migrate.c index 60d4e29c5186..4493ef57c99f 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -567,15 +567,19 @@ int migrate_huge_page_move_mapping(struct address_space *mapping, struct folio *dst, struct folio *src) { XA_STATE(xas, &mapping->i_pages, folio_index(src)); - int expected_count; + int rc, expected_count = folio_expected_refs(mapping, src); - xas_lock_irq(&xas); - expected_count = folio_expected_refs(mapping, src); - if (!folio_ref_freeze(src, expected_count)) { - xas_unlock_irq(&xas); + if (!folio_ref_freeze(src, expected_count)) return -EAGAIN; + + rc = folio_mc_copy(dst, src); + if (rc) { + folio_ref_unfreeze(src, expected_count); + return rc; } + xas_lock_irq(&xas); + dst->index = src->index; dst->mapping = src->mapping; From patchwork Wed Apr 24 13:59:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13641926 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 536B5C4345F for ; Wed, 24 Apr 2024 14:00:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB11D8D0025; Wed, 24 Apr 2024 09:59:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D64D68D0017; Wed, 24 Apr 2024 09:59:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BDF188D001F; Wed, 24 Apr 2024 09:59:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8EF168D001F for ; Wed, 24 Apr 2024 09:59:47 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4EBAC161011 for ; Wed, 24 Apr 2024 13:59:47 +0000 (UTC) X-FDA: 82044583614.05.151CD0B Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) by imf19.hostedemail.com (Postfix) with ESMTP id 218CE1A001E; Wed, 24 Apr 2024 13:59:43 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.32 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=1713967185; 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=mps2PVum0eLnbJWRuh/v2qps3mbA1AtkDvxPmi80hF4=; b=6Lr279lbS1XNPBiGtMDzXQRCsvLEi7FBlvu+Qk1EvdMMB+15Ivl685e9uZhXAUiRkrpCWA YAT07f48CGWUUDKsbSG2dA4Zme/83prYP4ssi9yKTBuC+BnzLv2pjoaq0Qj5gEiXeljOD+ XJoB06cvBQZqE5MO7ocbAtGuqOsGWuk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.32 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=1713967185; a=rsa-sha256; cv=none; b=ovPPsY5bCs02eQUoLeu5z9oDBcEp8lf2rTEXxE0McsfdXJdPvBmwB3R/BU5jMpgKCXiNny Wc9iYLoimJjKYmwh6Mm9QDWPdR2WyxogxP642S8r4G7Pt2iG3XV/jwL69gmjVCDQEMsFS+ jo4EC8sJWhODdJa6bE/06m2neHxhFV4= Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4VPgZ720KBz1wr57; Wed, 24 Apr 2024 21:58:39 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id E92A81403D4; Wed, 24 Apr 2024 21:59:40 +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; Wed, 24 Apr 2024 21:59:40 +0800 From: Kefeng Wang To: Andrew Morton , CC: Tony Luck , Miaohe Lin , Naoya Horiguchi , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , , , Zi Yan , Jiaqi Yan , Hugh Dickins , Vishal Moola , Kefeng Wang Subject: [PATCH v2 10/10] mm: migrate: remove folio_migrate_copy() Date: Wed, 24 Apr 2024 21:59:29 +0800 Message-ID: <20240424135929.2847185-11-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> References: <20240424135929.2847185-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Queue-Id: 218CE1A001E X-Stat-Signature: u394yck1r78jy7u1db1n3ri8a8xr1jad X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1713967183-333831 X-HE-Meta: U2FsdGVkX18fW3Msmcta1q8RnwG+Brd6WGBJoKlaKJlWg1tQTQoFL0wUKcm4s6juTqFh79M0zwfYxVkIrpAScv8A2IockBiJHQXlUwhWYL80GDWAETo+XMZl/CHJoQ8ilt3OstLehqohbYmEpxJ2hzzmw2ue0YbMK9c0cBljmsUcWmwTE+iWa+OcmPxIDpakHyeHd2lGtT1zoG//6pnTcLCpdRk910PKAWbwCc1GMhbE+k9CMoJ7ttZiP/+wkj8DlrrWb5YSuxPoDCQKoPjy7S64mQ4I7lgBSk606/xm7Dc/dVEeb6NQMfOrNIBwVutyihRLWW7pvNvYxuXA/HWWsLzNUcaKmF8fBECurMfZevF7T/SAQbWCD594x70Nj8mR+P3Qrk00eKB/yKz7q5m0bIvkSvagFWZobDAXLev2HYx2J3M9S1cm+qhtUGOohyUtKJeBoVqRWDhWVdshRPjWAArmd5d+r/dCI234F6Wniu85heAxptiHvyXrbC9mmH7k53DxzADNPsMG61WwdCWhusDd9d5v3yY4yICdsk6r81T7gXzYfSMeDI4bm14qV93YP2Zx6tVnDykOPJ7UGjI7iLnWx6dem7kzf1XQD7N7ZHaFYrJFRNarr5lu5RbtL6DgkEyly+0BFil0JQNBeaqrvftr0Xt26YcmnngtnqglEJNXDwHv3Ry8LHN14y15ANnicrQE7XCTDbpRXXJEkBK20lf8bu7ozAEISTZY2pbSoeHjDESO4MTl0+uxTEnUs+UrJTPUYqxMUdbT3fRxjNBEP4iGoHBi3t3HMlNwZWiCOtMisb9mX6X+wlyGMgAnQhyusA2kmLhK/4j/1Qwouajh8K/S8Py/BNHASHGr0q891r+yrcomQyi2+StHVC+h5nEYOr6wvRMKWYMaCJWhuxXfo27iV9+F7VGB8L7CFY30TtEHOg/zqLDYQBzw+gn2ELLhqDt4Q2wraeRtniHcbRe XzA== 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_migrate_copy() is just a wrapper of folio_copy() and folio_migrate_flags(), it is simple and only aio use it for now, unfold it and remove folio_migrate_copy(). Signed-off-by: Kefeng Wang --- fs/aio.c | 3 ++- include/linux/migrate.h | 1 - mm/migrate.c | 7 ------- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index dc7a10f2a6e2..ea7b956fd900 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -455,7 +455,8 @@ static int aio_migrate_folio(struct address_space *mapping, struct folio *dst, * events from being lost. */ spin_lock_irqsave(&ctx->completion_lock, flags); - folio_migrate_copy(dst, src); + folio_copy(dst, src); + folio_migrate_flags(dst, src); BUG_ON(ctx->ring_folios[idx] != src); ctx->ring_folios[idx] = dst; spin_unlock_irqrestore(&ctx->completion_lock, flags); diff --git a/include/linux/migrate.h b/include/linux/migrate.h index 535d1a5561c4..b9966d4355d0 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -76,7 +76,6 @@ int migrate_huge_page_move_mapping(struct address_space *mapping, void migration_entry_wait_on_locked(swp_entry_t entry, spinlock_t *ptl) __releases(ptl); void folio_migrate_flags(struct folio *newfolio, struct folio *folio); -void folio_migrate_copy(struct folio *newfolio, struct folio *folio); int folio_migrate_mapping(struct address_space *mapping, struct folio *newfolio, struct folio *folio, int extra_count); diff --git a/mm/migrate.c b/mm/migrate.c index 4493ef57c99f..f393e66813dc 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -687,13 +687,6 @@ void folio_migrate_flags(struct folio *newfolio, struct folio *folio) } EXPORT_SYMBOL(folio_migrate_flags); -void folio_migrate_copy(struct folio *newfolio, struct folio *folio) -{ - folio_copy(newfolio, folio); - folio_migrate_flags(newfolio, folio); -} -EXPORT_SYMBOL(folio_migrate_copy); - /************************************************************ * Migration functions ***********************************************************/