From patchwork Mon Aug 26 06:58:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13777229 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 98153C5472F for ; Mon, 26 Aug 2024 06:58:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FBD46B044E; Mon, 26 Aug 2024 02:58:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AD0A6B044F; Mon, 26 Aug 2024 02:58:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 573546B0450; Mon, 26 Aug 2024 02:58:40 -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 35D936B044E for ; Mon, 26 Aug 2024 02:58:40 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DDF68C0C6E for ; Mon, 26 Aug 2024 06:58:39 +0000 (UTC) X-FDA: 82493493558.02.ABDD54E Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf28.hostedemail.com (Postfix) with ESMTP id C1CD0C000D for ; Mon, 26 Aug 2024 06:58:37 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 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=1724655475; a=rsa-sha256; cv=none; b=YMXQcb7io5X1BdvT9KqQI+5DMyBr6dqeRq1Sw4hk+BjCMdnEforap5rap1RgxPteI3Heh5 r8gdyrkaS5tNUZov2tmZ7L51UCxryJCylTJKUsHytrcFR69DCkVE1B7U/romPEb+7H3JlJ eUBreFUnS36fHCvh2lY1tDkOH4mmTk0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.190 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=1724655475; 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=UeRNGyW+q+LLT1TGeS5gLwataL560hmhkLfMBu+4W60=; b=sgpJvYjtlJTAOqnl0hrufpZsYFBJ8qDhY4wFzHlK9cOUbGLc7YHpWG4MxFRzoTMbxvkS5u CEfkfruy6kKeiecYGejVp/WUsQ6fA+5/aMdXki3b/6V09d9if1TwQfhg1mhqrzD2hBb2vo blj/QWN8EcgrATZsJvWXSGbnWe10bKw= Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4WshN0091rz2CnZy; Mon, 26 Aug 2024 14:58:24 +0800 (CST) Received: from dggpemf100008.china.huawei.com (unknown [7.185.36.138]) by mail.maildlp.com (Postfix) with ESMTPS id 8E46F1402CC; Mon, 26 Aug 2024 14:58:32 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemf100008.china.huawei.com (7.185.36.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Mon, 26 Aug 2024 14:58:32 +0800 From: Kefeng Wang To: Andrew Morton CC: David Hildenbrand , Matthew Wilcox , Baolin Wang , Zi Yan , Alistair Popple , Jonathan Corbet , , Kefeng Wang Subject: [PATCH 4/6] mm: migrate_device: use more folio in migrate_device_finalize() Date: Mon, 26 Aug 2024 14:58:12 +0800 Message-ID: <20240826065814.1336616-5-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240826065814.1336616-1-wangkefeng.wang@huawei.com> References: <20240826065814.1336616-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemf100008.china.huawei.com (7.185.36.138) X-Stat-Signature: jx3pc4n4bbqaw8pafxrx77adt61abj8x X-Rspamd-Queue-Id: C1CD0C000D X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724655517-535741 X-HE-Meta: U2FsdGVkX18fGUC7TI5Zr8PiSH/FuCgFnmfcd12eYgZWBEusKPwVLbaltlhL1kKXEBUEAa3aWqjesLATh9x+QLEWw4GUA8lMoHAMZYA0PHu8pRp+ZeRkyOj9u9RwOM66OzGVlYp/aYd/yLwOFN/g3+UkPqBpJU1KBMPW+L7KA9eBghTr/aG3ms7ivr9WClLezTsemrOQchM+7OOA+5TLcEGO/6zEuy+7PWjG8aIXeAqx3/XizYsHwOYd0yao81UN9mEjDBNBJJyqMLf+N7DHdjkrqUqjH9Qnau+pT5N7M+SwU9/TJIDkBOHEflxFSQAdsKxyGZ3eO23T5rD4hPs/n3C8IwHqfrmBlKtfjt9YVKhEB/3JcfesI6YTttNwW7SI6PO6jipN9ZZdAAEqvH70xMM66SmLo7p89YK0vpWp6q3rmDpbmuSYcQxUWbPpjfU+OYef/6ORirq9hJBxBFp0hiIYm1nw7etZR71Xpi9FVlRWQtjBMiaWRW5724URbQMOzOYSxBGswGG/MWJMQUF2FJ4NxtQcPOmGqPyEeQSn4xMfi/yGuiI8HeF9sDjLrETokjNnFkpRK1jXidRb7aLp4CFgEdh4msiwrLZDLzi1tzUUujpj+tb9yLFoo7G7NqsZJL9G+rE+WOn7la3AYdCYnJf2di8ONZquHGP0CaU8XnhLHnvZ8s5jJaYC1hbyiY0VRWzk0d01hkBqe6u1tjlK/FunMQi7n3VzIcegystKPB6E+1PFNtq28LJnM6xZHnqWH+6FWz/RYeIdA7sJmZmZITlwwLAH2K++HbTEopThxlf7An18yQA9LMB0ybl2TOnieoq8FP1xxhA+zLPtZP4AmAGEGIXJL/HrSGC2nQlE8k5dDrxu0xO7WxH3Ts+13j/+s6xupCq0vT/xtv5D2z7jBM9JngvpRtAdgIbePv8d1wRH7VuNCIXMhaQH6vNg78BWxMP0xKSG8jHAt51dQKI +y6CMh70 15uXHHD46Snpkx+z9fbHMxY3jLpSHMfB5YO0r+4FQwwk9AbBL1qW5syDK2JeWfhOzN49G1Un2qw4lcSsYW5xbIA7Z3PPzfD7oz4lt5AGSO8eDXcNoqC0oMpQ3WVOxc75tM13GslaejikkrDrLsHVVUM4uqSOeut4QB+RqkLrPYgOg1ewWniLI7b/vR7QMfmiwCIdDL4VenMVH61G/cKzYdNgHcbS/9JnIoistsEqQbLnVhqEHDptvgDDRWne5P1O+bkxY8Gv2byzH9dn5Sma3GbRgwOCf2Us0RkPEoVoajmL+4sNmR5TzGz3mQA== 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: Saves a couple of calls to compound_head() and remove last two callers of putback_lru_page(). Signed-off-by: Kefeng Wang Reviewed-by: Vishal Moola (Oracle) Reviewed-by: Alistair Popple --- mm/migrate_device.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index b49f4956617a..6ea3d055f520 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -815,42 +815,45 @@ void migrate_device_finalize(unsigned long *src_pfns, unsigned long i; for (i = 0; i < npages; i++) { - struct folio *dst, *src; + struct folio *dst = NULL, *src = NULL; struct page *newpage = migrate_pfn_to_page(dst_pfns[i]); struct page *page = migrate_pfn_to_page(src_pfns[i]); + if (newpage) + dst = page_folio(newpage); + if (!page) { - if (newpage) { - unlock_page(newpage); - put_page(newpage); + if (dst) { + folio_unlock(dst); + folio_put(dst); } continue; } - if (!(src_pfns[i] & MIGRATE_PFN_MIGRATE) || !newpage) { - if (newpage) { - unlock_page(newpage); - put_page(newpage); + src = page_folio(page); + + if (!(src_pfns[i] & MIGRATE_PFN_MIGRATE) || !dst) { + if (dst) { + folio_unlock(dst); + folio_put(dst); } - newpage = page; + dst = src; } - src = page_folio(page); - dst = page_folio(newpage); remove_migration_ptes(src, dst, false); folio_unlock(src); - if (is_zone_device_page(page)) - put_page(page); + if (folio_is_zone_device(src)) + folio_put(src); else - putback_lru_page(page); + folio_putback_lru(src); - if (newpage != page) { - unlock_page(newpage); - if (is_zone_device_page(newpage)) - put_page(newpage); + if (dst != src) { + folio_unlock(dst); + if (folio_is_zone_device(dst)) + folio_put(dst); else - putback_lru_page(newpage); + folio_putback_lru(dst); } } }