From patchwork Tue Sep 26 00:52:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 144656 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1590394vqu; Mon, 25 Sep 2023 17:55:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTQJnBV/K0Va0w2X+nBmhPOTgMyixaMJO3v1KuTp2+msfxs8EN71J3R332ZcaqMzmPrAp7 X-Received: by 2002:a05:6808:2a5b:b0:3a8:1db8:456b with SMTP id fa27-20020a0568082a5b00b003a81db8456bmr7046513oib.35.1695689752424; Mon, 25 Sep 2023 17:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695689752; cv=none; d=google.com; s=arc-20160816; b=U2GDPZEZyHmHqCfUqalX6R2CMOG/IEgS7V5ST1Eh0eNJ7snFjDeENSPKxt1sGpbZaA Is2P5fuab3prF0QfPcnRCVmslC3+E8scJSUCNBwiPFgXSTQlzgcXgsa1sNTLWkN0dWqU GGhKj8NyeX7cMBKpu/YrJMv1nlf/8DzSFmqhT9HzEBRwx+io09ZMbbEb/jg5akqSvYNS GshqqZS9TbxLhBUH+BTdfdIMm1jFfpQu0CE87b0PWrbMHLuNun21N8uZ9y9uwcetrmL4 peRgKTfj9MXLiz3qwq+dh1sZifGxR9ZQZBAGNvjZuDzurxoj/RmA9hcMjnLOl3NGuYeQ 4n3g== 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=Z4qWbMQVyNDvnH/0/qkU92K86v2t3NC3Tu9QW6Z7yRg=; fh=FiTqiBStz9H28Qh/9rW0myzOFac7M9VOPFJTunt8oTE=; b=a13417A/6DD+X6gqYTCfVo/irxmT9krPqz70WcRhNoVTR5awRXE84ptPrSPOhqm+0b yiMRDb/IvSfW0OtgDXcwWRzW98a99BscWCMvzFHfjQI9fb6BLZV6OvZFwgXEzWCb0mIA QNC8dleBShYRXptaeeIzKD3BxCa+3SJvfk+7LCiY3EixgTjjh4uidU/Ryu31JO1I47pU Q2lymc9Q8csF72OIWkSdZ8mnbCP27JqpiVnLNT6b3SYxEWc+s+M1sNYBiyb07tHs9LXL 2Kt13OjLTp5vv0sQqCJDT+HrBl9CgIqNdvF1x9FJE2gCOtMCOaUGRnGZG2kfcVGd+TCj PABA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id k24-20020a6568d8000000b0056569ee3ae7si11365673pgt.540.2023.09.25.17.55.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 17:55:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id A239283348BD; Mon, 25 Sep 2023 17:54:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233454AbjIZAxk (ORCPT + 27 others); Mon, 25 Sep 2023 20:53:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232566AbjIZAxU (ORCPT ); Mon, 25 Sep 2023 20:53:20 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18705109 for ; Mon, 25 Sep 2023 17:53:14 -0700 (PDT) Received: from dggpemm100001.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Rvh2C6FzGztT3x; Tue, 26 Sep 2023 08:48:51 +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; Tue, 26 Sep 2023 08:53:11 +0800 From: Kefeng Wang To: Andrew Morton CC: Mike Rapoport , Matthew Wilcox , David Hildenbrand , , , , Zi Yan , Kefeng Wang Subject: [PATCH -next 8/9] mm: page_alloc: use a folio in free_pages_prepare() Date: Tue, 26 Sep 2023 08:52:53 +0800 Message-ID: <20230926005254.2861577-9-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230926005254.2861577-1-wangkefeng.wang@huawei.com> References: <20230926005254.2861577-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 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Mon, 25 Sep 2023 17:54:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778059577900065505 X-GMAIL-MSGID: 1778059577900065505 The page should not a tail page in free_pages_prepare(), let's use a folio in free_pages_prepare() to save several compound_head() calls. Signed-off-by: Kefeng Wang --- mm/page_alloc.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 06be8821d833..a888b9d57751 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1070,6 +1070,7 @@ static __always_inline bool free_pages_prepare(struct page *page, unsigned int order, fpi_t fpi_flags) { int bad = 0; + struct folio *folio = page_folio(page); bool skip_kasan_poison = should_skip_kasan_poison(page, fpi_flags); bool init = want_init_on_free(); @@ -1078,12 +1079,12 @@ static __always_inline bool free_pages_prepare(struct page *page, trace_mm_page_free(page, order); kmsan_free_page(page, order); - if (unlikely(PageHWPoison(page)) && !order) { + if (unlikely(folio_test_hwpoison(folio)) && !order) { /* * Do not let hwpoison pages hit pcplists/buddy * Untie memcg state and reset page's owner */ - if (memcg_kmem_online() && PageMemcgKmem(page)) + if (memcg_kmem_online() && folio_memcg_kmem(folio)) __memcg_kmem_uncharge_page(page, order); reset_page_owner(page, order); page_table_check_free(page, order); @@ -1095,10 +1096,10 @@ static __always_inline bool free_pages_prepare(struct page *page, * avoid checking PageCompound for order-0 pages. */ if (unlikely(order)) { - bool compound = PageCompound(page); + bool compound = folio_test_large(folio); int i; - VM_BUG_ON_PAGE(compound && compound_order(page) != order, page); + VM_BUG_ON_FOLIO(compound && folio_order(folio) != order, folio); if (compound) page[1].flags &= ~PAGE_FLAGS_SECOND; @@ -1114,9 +1115,9 @@ static __always_inline bool free_pages_prepare(struct page *page, (page + i)->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; } } - if (PageMappingFlags(page)) + if (folio_mapping_flags(folio)) page->mapping = NULL; - if (memcg_kmem_online() && PageMemcgKmem(page)) + if (memcg_kmem_online() && folio_memcg_kmem(folio)) __memcg_kmem_uncharge_page(page, order); if (is_check_pages_enabled()) { if (free_page_is_bad(page)) @@ -1130,7 +1131,7 @@ static __always_inline bool free_pages_prepare(struct page *page, reset_page_owner(page, order); page_table_check_free(page, order); - if (!PageHighMem(page)) { + if (!folio_test_highmem(folio)) { debug_check_no_locks_freed(page_address(page), PAGE_SIZE << order); debug_check_no_obj_freed(page_address(page),