From patchwork Mon Aug 21 11:56:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13359347 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 A12CDEE49AB for ; Mon, 21 Aug 2023 11:45:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 561938E0005; Mon, 21 Aug 2023 07:45:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 496708E0009; Mon, 21 Aug 2023 07:45:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 162C18E0005; Mon, 21 Aug 2023 07:45: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 C9B368E0008 for ; Mon, 21 Aug 2023 07:45:42 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A19FB80BF9 for ; Mon, 21 Aug 2023 11:45:42 +0000 (UTC) X-FDA: 81147932124.04.0B5BABF Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf27.hostedemail.com (Postfix) with ESMTP id D81D240002 for ; Mon, 21 Aug 2023 11:45:39 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.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=1692618340; 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=gYRQXXuBTVIE5GzI3ExSiDKN/ek1HbmSw0AD4SoCzLw=; b=KSgPMwGwIed/gVc4UY2V9iwoecE5XLj2YZL8FemiiRsfE+gQG7z/82zuDnEcwwcr43+iHF lw7CuBlC3YFEdU6ze74GIdtWx1JUJjtQ3Fdqk0LJRdWszk3SOn86scU+8fPJG5Akyddh9w +Rb+8Ma5ByQixM4D1/+ehG7du7w7taY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.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=1692618340; a=rsa-sha256; cv=none; b=YyE/thDtSMhRTRU3TAz8zPC+7/RwTHXfInEnFQevTpdDZiEd4vFdRa2JSzE/8qENVYRk3D wvqdATw4BdR5dZ9gSLbhZyLYOZoYkm2LxptNA3O2ExivwI0tdjBHNwf3R5PDw/gKdJ4tUt RiLrZmBQUV4HuwLV1cIRiNT7z9bGFaE= Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4RTrDV3ZNWzNnSY; Mon, 21 Aug 2023 19:42:02 +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.31; Mon, 21 Aug 2023 19:45:35 +0800 From: Kefeng Wang To: Andrew Morton CC: , , , , , Zi Yan , Mike Kravetz , , Kefeng Wang Subject: [PATCH v2 6/8] mm: migrate: use a folio in add_page_for_migration() Date: Mon, 21 Aug 2023 19:56:22 +0800 Message-ID: <20230821115624.158759-7-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230821115624.158759-1-wangkefeng.wang@huawei.com> References: <20230821115624.158759-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm100001.china.huawei.com (7.185.36.93) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: D81D240002 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 9cid48x8ne9p71jskm8b6d3jz1ksm99q X-HE-Tag: 1692618339-961277 X-HE-Meta: U2FsdGVkX1946tHccJcJEwF6geexi6wk6uLC3DJ7uMOmkVFSKLBwluzzylmpw/wB6IkkIHIzoGQI8v3KnuIONNL8GDjsN0DzBQBJZNUtcnZK/8czqLpSthlmwJhRMn7QioSV6kmpB5yGlBpxcbUVUpP9NsydbW0cL5IEzPrGB1yblpdPsszKNiXiBP32+qmKVyALXZ+OMXDwDtX4suQ0SwAmABv94choauTFSZ8joCbW5/DeZ7ddlqQAdOKbh544aL/oB6meniL5o1Zppx4+GoZeqJWQwYWYKByLGIE1vGTtEzqK+pjXJdld/0s/RQn0zHkQAW0e0vnSmrLz9IQPvLbQbyFs5tRmxEEsNpdn5Qqajz5fJ6Jqy3dzRC7Ull3NtoH/UGjrL32Gzs9tSn5fTrcHMnyRViwh47xHqqD4YfmXmKCd3a1E1Ayy4oGRCKsWGpMEEP4c5ZZlXjjTRX0cQHdkzANYcwYpOkZDVTUhSoKPP0HCosmE61gyhbUu0iflHRXwZncarrSPefURSiuHNn8Ci/5XYtRfb+M4zsutUGuc00XKv8eiAo4aUMBOlr/zK3alJNzlPwfIKrvVyksI0tuiKBGzzjALeCcy3pmp5/B9atNPa6LYLhsrP719dHS7LiNPxt36wAYvsdfaqEnMS9ep1YCGAuJbwK8yVLxVC6rUW5nNxekwWvEGKzXxDMyGuLxJtRzKYzyBRMoptK21HmJnqBV8DNI310J1l9DMEYXjX3I4NvmNRb9gU8wTabmjMJDNIAiMTVcOX9lnH+zZ0z/QDCwyWHE+3pg9fTksgQnJiZ/5koEHzrURPj1Dx6/xZFuG2zg4N1Og1jn7xsNcukbc8NRWJVBYKhDUG0KoK53VT5aRkqKijYM0Gkhh+hxbIlrxaLqKAuClR0yA9uggsgPfywMfcSUhGgaOJnlH9DivbnS+lDeKCbyjxXoK9Yo50nodU2AL0hXgW+HxFde wH5uF6jH byRqkGTNgkgqIyr7UmA1tR+tvdpVNPsGK34CDKVBG9bUVbc9YxoKUq9ynljy563CWY26kLQyyjQQK1fJQiEKT/7zaeSOqBUAOwlSTAvUvTjccu0Dk0UIxd1pQS8BwnykQ4sgvQcqg7JzXU238+Hj9APm0QDa6F3103oURhUjW4ARQvPxJkEBnVDiGX9XC2pag0Xo7 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 | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index b715cd59bdec..73572d5a5cd4 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;