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: 13398595 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 D221FE81806 for ; Tue, 26 Sep 2023 01:11:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 625BE8D0005; Mon, 25 Sep 2023 21:11:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 516688D005D; Mon, 25 Sep 2023 21:11:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B67E8D0005; Mon, 25 Sep 2023 21:11:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 013A58D002E for ; Mon, 25 Sep 2023 21:11:53 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CAC3E1CAA44 for ; Tue, 26 Sep 2023 01:11:53 +0000 (UTC) X-FDA: 81276971706.29.409E16C Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf22.hostedemail.com (Postfix) with ESMTP id 3785DC000F for ; Tue, 26 Sep 2023 01:11:50 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695690711; a=rsa-sha256; cv=none; b=sPuoNg4aWUcjVThixkveVwip6QoSUsVk688m6F6BSkKRZEnDfJlixgQqjX7rdCS9Msay5g T2+mCwrPApNS+n42T8jP+OplQO1sipV4BKbSw02O0+7W4aHhGyr4AbwULT1LwGTB8hOisy JnIW7t3pxf0cTZEn3ee+KqlbqMUply8= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf22.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 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=1695690711; 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=Z4qWbMQVyNDvnH/0/qkU92K86v2t3NC3Tu9QW6Z7yRg=; b=zwcxtzGxNrSaGwwjaD5E2Tnq1unN278OBLn7PGX+LK0mlqmdRK46Tw/xsxv7BCwcUKd/8d Nf7bo70HQ1AKvpIBmBhjg+5ifT96leMt4nbLlPXbly4ObokaBQ5BPSiyvKFy4E2bGQGCq9 3I5bpyRP/7uiAZFNELdAneNSvFhhzwA= 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-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 3785DC000F X-Stat-Signature: gisgx5aaqoafrrswy4m7rgg3fbj7qkst X-Rspam-User: X-HE-Tag: 1695690710-574779 X-HE-Meta: U2FsdGVkX195w3I9Jck3B2nJ0byNBgS1QbM4zUl/Bdv64icWrbKOKHaGz4pbmuR+APyXRHyPIRuaKh9ERY60Dz45a6QvLLOhNurYTIbbOFFRq3DOVbY9HtqqI9gaYy+nxs2UleeCeZsFEAtbzK5YuCgklJXl1/SI+n+Xi2d3nMgP2tIA5pCeCgdyjG8C9HYTvShb/AlgkmYcTy2oXnBkVPdLXj34yC/qPruJYOKNNfAZWInVNxzS+8FZgdlHChe0Pwcld8fzvCfWKvUuMvf4yU0z2MpexipHiJsfe6dQdXGjS3CjAzoq2lozTYs75VYV5Dq5SBAFfIJIaZVJp0v7710JPvp6MERuSvMkgMqoHUA9yhodzNNe0UWxRifbPJ2+FB9DAaibxpl1CshK6jXvClQM+tD4mJOpNZ9zyiB6Xm6fCYPt6RDfPUhbnOq6siIs7DxOGTo0pPUwfhrOoCNcI7df232uVAOBNny62csuKG1HO/CFeCbBTN8UJ+yiUCndDCsEkmxPeWeqFXusnU0GgYZREiKjpkZjgLPsGtwz7fG/CDk5/5u/5MtKn/85CJsqipK/ncoI2N0PZ6q46LgTC7lZS+MofwwqsqRj1zokM0ZDmGi7ztjKBpfgCn6UM2aRxcVXdUbKBqg+kPSYs5P+qUISsCPOTf7zB+0/E/yAp0Rbbyjn4JFb6NcBxZTLuzJRFtEeoO0tHWlIgFIGGQIUGsIe4Ob8+fUAavlz7TxI4xQYYqxTTyZTtRpNvotpgIUhDnP/T3+zoGbJTuilVRcNd6DKlakyXq4e+v89KFhUvyL7AdsZr9WeIqDs6fsuFtRJGhEP7h3C1R2YoSsh6q6T83JzjzZTWRphiZzfB6+Ipg28DFHm3gjY4QMJOIortyWoZRNcZad+lsuzyWo/Wxx648fcSHZXKNQ6KtqhLEro6bUkFZyjsNbDmjxIwOnPbUq11wCnj5tVLTnH5O6g4eQ Wl5ig9k6 Y0WidNR8MwRfl1PAiMGWzXv0o5eASVWceOz0KSKSNHofJWCFZ0ycb9/SOOMwKtkMPQRKTGcBg7uOr1ySwoQQmcBkdR4ueHYcyD4ED9pDon320z9EQrl/raY1RqeQn6UnpipqYeSaUJygrUJpGLsDffH1Dmw6/GVTEi1KFc+LDX3YwtKvqQEe2QiDZBHKfULEnC5Yy 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: 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),