Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp708867rwo; Wed, 2 Aug 2023 02:59:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlG2gIIkO6EdZDQ34/4Vjc78ftJb+LPhiugMyCiy8R8SIy7YsRlvUDwPxp5eE0D95alWw8r1 X-Received: by 2002:a05:6870:b527:b0:1be:cf5d:6f7b with SMTP id v39-20020a056870b52700b001becf5d6f7bmr11073947oap.17.1690970367100; Wed, 02 Aug 2023 02:59:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690970367; cv=none; d=google.com; s=arc-20160816; b=RLxRXvoWQuCHAWYrWnGlnAhyYbqPeoO3QNHo4qlcgCPtYDg2tbbFyFEcWeke0hsA2/ otyK5qIlRHc9XLMt4MTpB+tQxYuLKryyRrmySZfpnt1BSfnXKT4RrjqNloLqt4xO0qa3 2e8dztVpn/vaVwV42oK6BMCrG9Qir7QVeDsm1E6146NRi9ZPLeS8Mg1Q7kHkPW/W3cFj mkxgumD/7YZBLxJv3WezDAXwQHkf6mr4NLNHdyIIgJ30RkY5pU7UHJ8ixfN+EcF99JvA g/VphxuzrTCXu7gAwwnN9ELUdCFLCebCw/vZ+fMgK/QsEZM9YRysUpSedBQmfJBd47DS MsfQ== 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=sKA63lWYPN2MF+P3BEUtg/sR22zgj0WfA+RU7kxoC38=; fh=frTJ5b0OruHscvMLDfKfibXYJSJ4/6aFlw/4ZMUelj0=; b=CvA/hyHxFxZ93BT/ZdeV9ABOBXiOo5X4yD0NZrFgwiL0oB1nXqUJow7vPHEINMMq1a cJSKk1ArH6iTl0nhuYevH4pODzQejTTmD9xiqg8XJp/Es20kQ1cwRSBxCw8tN6gylZaA p6rGBTx2rpDF2oTOQWgUqRvEZeQ1Pjdb4CjIXOciEG3vlarynm7DtE9cG3QtDkXsjwZh EFiac8xbal//hZbCM5U+ySHupp1bGeVzFEFky77jSBEToZrYEPiVxGdOfwBE04C4mr7m +Rp6RChF8hxrWIeCwwc06V0kN/E3Xdg1Ntpn5JjRCm7txpvgeFMaPYKWBWjeVoCx/Vhr z7rA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a17090a098600b0025c1ff9cd67si917111pjo.184.2023.08.02.02.59.14; Wed, 02 Aug 2023 02:59:27 -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 S233610AbjHBJpe (ORCPT + 99 others); Wed, 2 Aug 2023 05:45:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230494AbjHBJpc (ORCPT ); Wed, 2 Aug 2023 05:45:32 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 902512D53 for ; Wed, 2 Aug 2023 02:45:21 -0700 (PDT) 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 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; -- 2.41.0