From patchwork Wed Sep 13 09:51:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13382706 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 89462CA5537 for ; Wed, 13 Sep 2023 09:52:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F6536B0179; Wed, 13 Sep 2023 05:52:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A85D6B017A; Wed, 13 Sep 2023 05:52:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01FBB6B017B; Wed, 13 Sep 2023 05:52:22 -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 E598A6B0179 for ; Wed, 13 Sep 2023 05:52:22 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id BC2B21A0321 for ; Wed, 13 Sep 2023 09:52:22 +0000 (UTC) X-FDA: 81231108924.10.7A601FF Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf12.hostedemail.com (Postfix) with ESMTP id 1BEAE4000B for ; Wed, 13 Sep 2023 09:52:19 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.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=1694598741; a=rsa-sha256; cv=none; b=5MAoaT/pU1qL7lN4yoE3wCTM4wCbe8AxyS0JQTi6R7vtITaqSBDetvOJLX1m24MnEDY90O N+wCfAQ4e5owZ9kr9BH3dc6gLFpdFPJCQnwBfc8ZyjvLI54woVKGT2eODPkm9OC601cqmI uyOeSdj+ythsWXQonOo6QxRM3dWpkqQ= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.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=1694598741; 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=RK3S6ofLX88DWyIyY123P5aohf1PFWYOerflINyiNM4=; b=22ZIV4ueH18UvJ20e9fUDMDrCLOsgdcmOhqwj5XLukhJ2KWtlhkwj2ZXvf8D1qFYSu4iKl cYRDHW/KvbxM1eK1WrhTd4GYSgIbRFWEHo6dvfdnDKNBcUh34KLlmqZG+b/YVpkOsP2lBN O9kJXZruGR1YR1bESeDd/nZcsUCkSvM= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Rlwdk1Y6FzVkfH; Wed, 13 Sep 2023 17:49:14 +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.31; Wed, 13 Sep 2023 17:52:01 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , Zi Yan , Mike Kravetz , , Kefeng Wang Subject: [PATCH v3 6/8] mm: migrate: use a folio in add_page_for_migration() Date: Wed, 13 Sep 2023 17:51:29 +0800 Message-ID: <20230913095131.2426871-7-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230913095131.2426871-1-wangkefeng.wang@huawei.com> References: <20230913095131.2426871-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1BEAE4000B X-Stat-Signature: bd6pzfux7kzqbaqmks3ngp4g6ta857x6 X-HE-Tag: 1694598739-478013 X-HE-Meta: U2FsdGVkX1++9bhSt9jvyQwtvnx55GoMdrl5cH5AaYYjupvxzA8O+23rtx2PXk/jrEal5qkMtdhJ4LgyCp6Huv/MOMsuYhQUc6CEmM9qcv0mCjzjoAhCI8LHaAY97R5yjXynW2Ycw0AbSF398hca3Q0WpmfjN9Us54M3KXr3wHiEbj/HRc3sDyuVbNtQ5OS40EUwEqJOGIpmiRYeziKES9dhRC3fyJTlZfQ5wzCfQ6I5doFYB1WfnozWZ7a7Z93DjsyiIP5a5O8IF0ApmEXIx3YJ0qKWEZ2U8FeGH5PtZPEi4EkGKkolap5EMBk1e4P/hc/cBFZj6BHpC4vM1hvIZ9f3gVxMOBo8+7GC+jsbj7yqSuA7Wg0QFXk8R4AVzuWWugRnYliKoRvCUWNehWt2S1qErHrVN9ibJfWYijMv5Wo/fhTp64X7O9nqPueGmk7tY8kwTDbFdK7XbhvHe+wSwZobUdrbaozeHxpHmxYoI5Pta7kDLS8AaY9ynHuItfzeQEwPE/xlL2KGbQXa/WNMzYsknzHP9wl+hfV7LmknPkrVArWf0u/6e0In4RmGJwOkL9WLrfZgq1fRXRyQq7VTm6o21PP1qyolX2U7tX80r554GziW+JaRd8KcAyocI+4cfu4b9jZ6U1g65jjhJZJG7pBoLsCllufr35BY0NUl4CT2qwfGYILQuuB+2d8aAuTWvMDgrcjbHwPCRlymsjfukIH0wKgNkrLTtxzbzdJsW/viIHGYQm8N8u0/WKPlzwyNTXzsZ9aqjiSv2GBRPyJKsV80eUIdAZOTSc8zdP6T1Ot1vhQEASkxhL45k5smAHpzQlU6myl2NYWPwb42PDbl6oY5PP6wMqaLFbhTQGFsBts/UKDlCS+XA6tSY7ZlzTsHiiDw+XWW7kAYI3hyqsnncCFBljEI9bMk4Kw/gH6Nj8TO/wcxQr7cM4FsyVrXie2axZeMDS8jx6SMtFOCu5A 4A3k60B5 awiuJ9M1TamdbCy7HDkSPH/fRQGnpC631/lB2M7rkvx47i5MTHOnM7OMXidHR+Hldeiyk/xwQAy/OOz3njbo5vbBPF/l+9QOQ6OzWEQ8RrspZ31RaIDt6uIStIMukMQUMhw6TwO+te/zPsOTxj8oNI5WPqvAtdWEUJ1HHLWiFprg4P5H15wJQufZdhUyQzAeX3hFY5H/FsvFytZH4f+mvVaQFHg== 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: Use a folio in add_page_for_migration() to save compound_head() calls. Reviewed-by: Zi Yan Signed-off-by: Kefeng Wang --- mm/migrate.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 264923aac04e..cf5c9254fdad 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2057,6 +2057,7 @@ static int add_page_for_migration(struct mm_struct *mm, const void __user *p, struct vm_area_struct *vma; unsigned long addr; struct page *page; + struct folio *folio; int err; bool isolated; @@ -2079,45 +2080,42 @@ static int add_page_for_migration(struct mm_struct *mm, const void __user *p, if (!page) goto out; - if (is_zone_device_page(page)) - goto out_putpage; + folio = page_folio(page); + if (folio_is_zone_device(folio)) + goto out_putfolio; err = 0; - if (page_to_nid(page) == node) - goto out_putpage; + if (folio_nid(folio) == node) + goto out_putfolio; err = -EACCES; if (page_mapcount(page) > 1 && !migrate_all) - goto out_putpage; + goto out_putfolio; - if (PageHuge(page)) { + if (folio_test_hugetlb(folio)) { if (PageHead(page)) { - isolated = isolate_hugetlb(page_folio(page), pagelist); + isolated = isolate_hugetlb(folio, pagelist); err = isolated ? 1 : -EBUSY; } } else { - struct page *head; - - head = compound_head(page); - isolated = isolate_lru_page(head); + isolated = folio_isolate_lru(folio); if (!isolated) { err = -EBUSY; - goto out_putpage; + goto out_putfolio; } err = 1; - list_add_tail(&head->lru, pagelist); - mod_node_page_state(page_pgdat(head), - NR_ISOLATED_ANON + page_is_file_lru(head), - thp_nr_pages(head)); + list_add_tail(&folio->lru, pagelist); + node_stat_mod_folio(folio, + NR_ISOLATED_ANON + folio_is_file_lru(folio), + folio_nr_pages(folio)); } -out_putpage: +out_putfolio: /* - * Either remove the duplicate refcount from - * isolate_lru_page() or drop the page ref if it was - * not isolated. + * Either remove the duplicate refcount from folio_isolate_lru() + * or drop the folio ref if it was not isolated. */ - put_page(page); + folio_put(folio); out: mmap_read_unlock(mm); return err;