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: 136397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp3023304vqi; Mon, 21 Aug 2023 07:00:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFiCN9Z2S4ndMGRqLjIWGlO2edK3y71R0NPHVGRtMnnpcuZwj1HHb14lber5FtzyquOOAO1 X-Received: by 2002:a05:6a00:180e:b0:67a:a906:9edb with SMTP id y14-20020a056a00180e00b0067aa9069edbmr9184781pfa.30.1692626444024; Mon, 21 Aug 2023 07:00:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692626443; cv=none; d=google.com; s=arc-20160816; b=YF1iGEb3gLo+9guW8Rk/O8W471XxezkToWJW/P6dfcQSNCHOb/bVrTjdtxqoyJL4RH l4ljYYaJHhxJ7+wqzd+YgCz+XQXrLv5wxixl0BLd9iIt6vT4SzwlF/jl45rQP1iRmGZD +kifr9B1xs/a/43nDnqaOUb1EOgKG52/e6niNkojsHrFScKQGBCT4KJ/KZpRM6xqU806 8bgTe0rQUQjndAMR6A/Q9oGPl8em1ogk/vjnZax65fCUsfyZ/ss9Vg8648hQPo3mgVK/ AsoNSiUWzGHo4OLL90qD3Jnbzreie7RyESJ/Gc4WkBg5MRWBRUZ9YD75ml0Fc6W0D1G6 yqTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=gYRQXXuBTVIE5GzI3ExSiDKN/ek1HbmSw0AD4SoCzLw=; fh=DVvJTBiVFbttu4Lo4kJqW9uQ6WV1aWAR2MVr11q/QiQ=; b=JwzMQzyM0/6gTwW/A5zBEXMPK7V2zJjRW1COgOb/AZ/0qcA+AdhPmhVGQOH1vMAaEF 8vjBOBXiwsSFwkQUIgfhAyWz5zsx7/wB14OSSxzCoT7AO/WIruR0gfWTef3QSGuZHb7v LAfwUISuuRJtedhhFv1Mua2AiZdyz5VBf0L8yGqMSaHX7CBSjb/9icUzGUtjkMiiVnfe AeBK6ZUll6RHXwFz9+m6nxGYERxSOp1UxU3Qgz5pVxbRkPqFXnJLD5ZFt2hwLTWyjSvt 3qy4Y878AkDEwXQEhPV5GB7+O5yLZgSo9d+iGa1G7W1D/7TJR1/wyxu5IKlvsTM2pZzr 6+AA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o71-20020a62cd4a000000b0068a3edcf295si3290438pfg.60.2023.08.21.07.00.27; Mon, 21 Aug 2023 07:00:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233360AbjHULpx (ORCPT + 99 others); Mon, 21 Aug 2023 07:45:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233267AbjHULps (ORCPT ); Mon, 21 Aug 2023 07:45:48 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AAFDF3 for ; Mon, 21 Aug 2023 04:45:38 -0700 (PDT) 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774847466339332286 X-GMAIL-MSGID: 1774847466339332286 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;