From patchwork Wed Aug 2 09:53:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13337932 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 73F97C001DE for ; Wed, 2 Aug 2023 09:45:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF9C1280145; Wed, 2 Aug 2023 05:45:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D59EE280143; Wed, 2 Aug 2023 05:45:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD496280145; Wed, 2 Aug 2023 05:45:29 -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 A097E280143 for ; Wed, 2 Aug 2023 05:45:29 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7CCE3160D7B for ; Wed, 2 Aug 2023 09:45:29 +0000 (UTC) X-FDA: 81078681978.20.EC7F3BD Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf18.hostedemail.com (Postfix) with ESMTP id 0E45A1C0010 for ; Wed, 2 Aug 2023 09:45:25 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.189 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=1690969526; 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=sKA63lWYPN2MF+P3BEUtg/sR22zgj0WfA+RU7kxoC38=; b=W8+obUt5UbtiIuNhV6q+y1xUbf7YM/78oiSyYD2W76+R7xvooEQTe6fQL9ZtBX2UNvV/h7 hLVyEmaNNhk0o6r8Gu9ThyHBIyOjVtvz0gK62kTZn4xITu4glfA6mU0ePyIdmcCFWEaoKB w5KnqmxYbs6sicpX/CrbIRhDqxrmVFA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690969526; a=rsa-sha256; cv=none; b=5yhMNlGC9ilIKD5eWgWHewXHxS8jjP9tmUzZOdbkkrReDIu4P9QvU+/YQg+z2594rnmN+Z y09sSgkzy9rGaGPFIpy8gAGodvoWSsOHqI6dtBpR1+0NOjqg7AY++F14NV5ghTWqlADnQ+ 1I4LnsDZq94Q/QAIdwumo9eXfhgJ8YU= 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.189 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4RG6TT1cQ1zLnxK; Wed, 2 Aug 2023 17:42:37 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) 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.27; Wed, 2 Aug 2023 17:45:19 +0800 From: Kefeng Wang To: Andrew Morton , , CC: Huang Ying , David Hildenbrand , Matthew Wilcox , Kefeng Wang Subject: [PATCH 1/4] mm: migrate: use a folio in add_page_for_migration() Date: Wed, 2 Aug 2023 17:53:43 +0800 Message-ID: <20230802095346.87449-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230802095346.87449-1-wangkefeng.wang@huawei.com> References: <20230802095346.87449-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 0E45A1C0010 X-Rspam-User: X-Stat-Signature: 7oidiis1ui4nxafkr5pn9rpm7bfp5c6z X-Rspamd-Server: rspam03 X-HE-Tag: 1690969525-61908 X-HE-Meta: U2FsdGVkX19lCbSRzTo7Jljieb6N2pH5BeqnwcIhL/WM77MEDkDPNjHUFsQuf8+t7vsg4Q26jXogIRnAgw9cNXvXOe4pi9BvuV6s3E1qR5H4eehoe5mTo6/vMvyalwwcqiWTpAlY8FSPIxjs7C8Nsz69QWuJH76iaJexnLmIzGg17fD9D1vMKHzlBDQV9M2zMhdI4lyliRCVJT3K5UJp9kaXFwc4Kb563IfMdxTm8dd+36LIAFDOO4BjVFruSOwLwmpvnaT/2qIoeHTyKjd8uMx55X7xdJ7fydgyQPFyOP7whCjDWgDSQp7K3qAMRNlIOvpngQUbHZ1po8MG4YoWR8Bjbzay6SrLmqh3wK9KPuU2wkiCyXfb31Ku7xOvsip2NsetQ97PhBTtfqSMHaWX0LN/V2aNIAcs6QyuKn8JO4qgaYQVOXytSnw1vy6SM61P0WSqYYQYFqsqUuOFRQwm20bcpRC8XIpaTQ11s0eWrNHtYIYIbe2Zj9DKrQ/zefJp7MW564A73ISggULiwcJr9vtkxU5/8W+dQbXzvui1lljyMyGWPbIpT/lMsGJS1lScOH0Q5kCpRgWjF/cJ64cxEj7rPoj4I0BMgvMoTUMZf0UmR1/HaiTO3vOIZ6Oz47gG3a+GyuLQ4vITYc1vNIpbURU/zTtqtFQEAAau+oEBqkqW95uwx6RYWVDBFIekwG1gVnU09OU4jl2NeZHDBB5fxmGs9yTT7q1fqUHDmH74IBcAqrYv6GT5VKyrXKIv4/zTm12GSEacdNqv9gsxD5O5qvmfMnewrIAQ96KGf9Z2tfFVGnZlw02Dlg0xgOZElCYYAQYIhapG6qlhGMY+tApXicp0/FaPRR0qc1qeUUDlquEIfUzAm+I/l05m0is7qRZjCK/7kR0gK+hKwSoDZZrEdthD+qUz8Vb0PTI5Tjkvib7B2ZpEWKl93mONNRF82ohGlGnmdrsmuflBvbzDK2R FMaaz7fU QB98jkfDGvBnjAUAWsPSlWk16eC9R4RwkIcLesw+a1TqMcQYyegSJOO5vVv91u4BlaV/XQ6IDTmKOuIUSN8tJL/+ceA7cedv9YuoJ2KEuL+4RULW00meeNjUQ+65x2APLyDpdAc72L6J2zrolzE0uTlo2hwSt3oP/CdTdV50EXkYrGdQk9ujT9im3BJy/lULGUKmA 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. Signed-off-by: Kefeng Wang --- mm/migrate.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index e21d5a7e7447..b0c318bc531c 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; + if (folio_estimated_sharers(folio) > 1 && !migrate_all) + goto out_putfolio; - if (PageHuge(page)) { - if (PageHead(page)) { - isolated = isolate_hugetlb(page_folio(page), pagelist); + if (folio_test_hugetlb(folio)) { + if (folio_test_large(folio)) { + 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;