From patchwork Mon Jan 29 07:09:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13535065 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 1B044C47422 for ; Mon, 29 Jan 2024 07:10:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77E196B0082; Mon, 29 Jan 2024 02:10:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6DEF26B0093; Mon, 29 Jan 2024 02:10:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BAD46B0082; Mon, 29 Jan 2024 02:10:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1E28A6B0082 for ; Mon, 29 Jan 2024 02:10:01 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C770BA13AA for ; Mon, 29 Jan 2024 07:10:00 +0000 (UTC) X-FDA: 81731474160.11.5B7E4C0 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf13.hostedemail.com (Postfix) with ESMTP id 0A75020008; Mon, 29 Jan 2024 07:09:56 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.191 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706512198; 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=wob4Vgn1ZkSMoOSUbtWxys1VhnUJlKtaKtwaTBq2NW4=; b=vv9SW+jQ0q8TxWFLX+QYW6Q6ZXVwagi8QX2rMQdjWwzpslB2gi1E49cju4ykHHej5/L55m gn25tIeyzA0wMYFIRW5mPI6x2XiRoE6opcnichNoH5mVJjdH7PrKrA8cRVU3MRqL6VuJxn SrQ2rGAbr71zApW/zuLboRvlcmXoQzk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706512198; a=rsa-sha256; cv=none; b=Gl4vWCNGPl4Shn5kmC4K8/zCkz047epYlUN9G7hkWbfVoXMGwSkpbOcHdNckm+MuPQB3WJ nVeQzA7mxt+cpIBQNyfK5x49mchikr6gYpHSKAhCif514pJkuZXQ6HpV49zu2ikdCINBSf r7KrCUQlyw58UVKmpYH1MCFqVFzbiEs= 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.191 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.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4TNfSz2Kfxz1FJmJ; Mon, 29 Jan 2024 15:05:23 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 1734A1400DD; Mon, 29 Jan 2024 15:09:50 +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_128_GCM_SHA256) id 15.1.2507.35; Mon, 29 Jan 2024 15:09:49 +0800 From: Kefeng Wang To: Andrew Morton , CC: Tony Luck , Naoya Horiguchi , Miaohe Lin , Matthew Wilcox , David Hildenbrand , Muchun Song , Benjamin LaHaise , , , , Kefeng Wang Subject: [PATCH rfc 6/9] mm: migrate: support poisoned recover from migrate folio Date: Mon, 29 Jan 2024 15:09:31 +0800 Message-ID: <20240129070934.3717659-7-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240129070934.3717659-1-wangkefeng.wang@huawei.com> References: <20240129070934.3717659-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Queue-Id: 0A75020008 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: rqx4yecuhyjcxc15af4e86o6yr8bjmmi X-HE-Tag: 1706512196-658370 X-HE-Meta: U2FsdGVkX1+Rd+KhBJp/hp44VUcoDky7r2NgJhzkUGdz/OYKQ785CNlJBeSt9TPXwbZu7W8HPEdqkEyknhUvLi++39LHbo0vC7KcGI4vN24VWiBbM5iAA4q0IGSY4w4F5X1cxn23V/3qvclJyhraX+Fm0PABia/X9XwTtatp97Cs/MFj/UOZ1pOqwbvsFRTImfxrXaYffmKuYfymm/pIgjo6rrXEG4iuCWSSO+wH5Zx5EwdaCeQK4T8P4Wg9fhqZyUXlrsMQcPRT0p0fxlwfQNg1NdDQsB8lKfklVAe3E88shguWAp5cihnsb24Pxp5uZ8RAcP4SO+YCTusc97UOZVlAYMr3Q2Lf4Oek5nmFCKEdJ3F8ZR3P0GZuSjEg9I0MHbhAJuNCTZiKlcZc106LPnJo+7Reo5vYQ5nDUE/yhzA7di4L6++MAvCWjOZn1AkfD6oL29JLhQpo5SGqzIKnnvXiSzVio2MJFn+tD3s48hpSE3wDKsKNNoen8kfpjlngDL6uTRoV4DNQn5u+VxwH2UA+5GiE/kBDpyERe1va6JdG0gENoKCyrY/iLZl4lHnu06xnh8JhJcXvFS2EtghXLRZL1ugTHRPd2kBFHrvo3A8GpJwJ/OvVhB4iVxPp5S+2tUjdbw3IMsgTvVFsaIfZpV3kUr2fiYjAjaXwZJ2lI2QblGJcddxkJUXZGF679sLrx6PGg164pbAeuCO4ArN1w+/OKvqHJmrOSNILCPaLYQNg/aOC5lYFc8RnpsaB2ggRf28YnfpMeyo4LQHAXArLIiA/zxqK6tQnxk3+jTu/EjGMKdsGKkBfHj94n9jzrtI3raa2Ohn4DZeNNdu5KouQ06lOWCPx90sJ/7x1p8LV+H8RnzkFkDfXdlNL75hByym2Z1hBED0o2wqyAc0+LJsWfZj2Eh8g4OLZOjDxesY2csUiliPRa8VjakvX0S+MgbFE87QAvNfjJFZL8VjLkE+ kS95a5r5 WTOru+4mKBXmLl8sDvI5g5E9FDo4d7eJ0ZVGexhVwzFQrtCVp7HpEg/yZMjqul8A9Nk9DD+i65fDjFZ4slrwzgMxoHs9qBpkR1UYqwxg03/YBAOeQe9pVhpzF9ySUF+WJnrqcjsCkqHu/pr4= 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: In order to support poisoned folio copy recover from migrate folio, let's use folio_mc_copy() and move it in the begin of the function of __migrate_folio(), which could simply error handling since there is no turning back if folio_migrate_mapping() return success, the downside is the folio copied even though folio_migrate_mapping() return fail, a small optimization is to check whether folio does not have extra refs before we do more work ahead in __migrate_folio(), which could help us avoid unnecessary folio copy. Signed-off-by: Kefeng Wang --- mm/migrate.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mm/migrate.c b/mm/migrate.c index 107965bbc852..99286394b5e5 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -661,6 +661,14 @@ static int __migrate_folio(struct address_space *mapping, struct folio *dst, { int rc; + /* Check whether src does not have extra refs before we do more work */ + if (folio_ref_count(src) != folio_expected_refs(mapping, src)) + return -EAGAIN; + + rc = folio_mc_copy(dst, src); + if (rc) + return rc; + rc = folio_migrate_mapping(mapping, dst, src, 0); if (rc != MIGRATEPAGE_SUCCESS) return rc; @@ -668,7 +676,7 @@ static int __migrate_folio(struct address_space *mapping, struct folio *dst, if (src_private) folio_attach_private(dst, folio_detach_private(src)); - folio_migrate_copy(dst, src); + folio_migrate_flags(dst, src); return MIGRATEPAGE_SUCCESS; }