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: 138727 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp969607vqx; Wed, 13 Sep 2023 02:57:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0aogcUnDb/gDpwuqlbVfJ+7YkT2D9gDabcv9z0dPBx0W1Vf46KoFHg3Qvm+rtoZwK/4IM X-Received: by 2002:a05:6a20:7f93:b0:122:10f9:f635 with SMTP id d19-20020a056a207f9300b0012210f9f635mr2148035pzj.19.1694599038202; Wed, 13 Sep 2023 02:57:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694599038; cv=none; d=google.com; s=arc-20160816; b=N4S3261kAaxGKh3pelQmiMJAWKnaCeaMv+N26pwIDD+T069aKI/WP0eHAsMTB4yT9j h3IhhoUKUyIfX5WNsYyUcrgoNw1hIKEWhi1dy7CJoQgXGNGCh05uiN7T5orLD1+3S4TY Rld7ry6tCCh7y0zYsmf/GVcm3nTf+NLXQxV02Mkt1QKGjSqo2ubffCKqAqNqCUWnl7FN Sa83E7FzePYPkKIXSZt7B/YQNYA8FSLFGpSsYPfkVeYq10XrYgJTMiHFCPYjxOdXZeNl JkfsTDZXkorQfrgPBF2AHouh3pQMFJbD7qSBnhvEBjWLYPZFKQ8aOVBxAAqXg/cy95wQ LMRA== 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=RK3S6ofLX88DWyIyY123P5aohf1PFWYOerflINyiNM4=; fh=Je6qNyAM729b1goCtB6PkBk+yQrlQCIjJMRY6BFgKTo=; b=KDatg9E1DrFjeSKeUnQxxpAsQCzQxFTsVo1nlGx6msZtqRa2dr1jWiletp9S/Bc0s2 A4T7+vtQKmBjykN15tQR9LbMKmP0G2VIG3PjkjU0MXsIsAgyOkwp6WuyPdaj4qLyALGI Ad/d53UzVJQuUjxVpMuFnvVml/M4DXzgxTrefeHITiQTUq0Zva/4F7M8wqI2Jy9fwrgJ IWvgrJ098V53NCF3/rm1WNFmClBKqX3wgs4XQyiXpWkQxlW/fz43fbjElA4gOQDOZznI wwbTIvFa4XKa2AatyaTC6jzgf+OQ/4zrMOpzdIbmXzmIrGK4q8sGijF5yyPCU1bga+6x 3cQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id cl7-20020a17090af68700b0026b56ee767esi1181508pjb.106.2023.09.13.02.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 02:57:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 64E768228808; Wed, 13 Sep 2023 02:52:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239574AbjIMJwT (ORCPT + 36 others); Wed, 13 Sep 2023 05:52:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239506AbjIMJwI (ORCPT ); Wed, 13 Sep 2023 05:52:08 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A674199D for ; Wed, 13 Sep 2023 02:52:03 -0700 (PDT) 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 13 Sep 2023 02:52:55 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776915880838501496 X-GMAIL-MSGID: 1776915880838501496 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;