From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DBA4F606A31A for ; Tue, 1 Dec 2026 02:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=PYjbHHpJ; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=jOB6Uw82 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=T4muj96OKxoDyynstZlFtabHzduGJkU9819DzpNMkSA=; b=PYjbHHpJ3Sh9Kk LaUf5mkh4emU6e2/PTqOAV2Kw8EOHS2fGOqbaKfSL+BxICx+SxgeSX2/BANz1XmfIG57koufjwu58 HnEZ9HOIpVugkBRkt9DngkXvHptmuNiksbGj3YHdfyM2IyCuzFN31qZxDS2S29GXTHONr33NRdvSW lbjO7V6xYwqJnNvg3NLBYBPgiGI4lUHgyAfKa/LKww52h+Xdlq02LS0JLlkTNTk25E57XWIqB+nNl Xz16LeA8WBqrjblbX5bya42mJRDd5lVIKWnPAkT42eryLOmaSsl6vs/kXhzsUB0fnJpPMGp+BJi7j ahDVHlAchlWu89PHgzAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYD3E-00000006DJs-1Hqg; Tue, 01 Dec 2026 01:53:00 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYD38-00000006DF0-1xsk for linux-arm-kernel@lists.infradead.org; Tue, 01 Dec 2026 01:52:55 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4a35a60499eso86127395e9.0 for ; Mon, 30 Nov 2026 17:52:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796089971; x=1796694771; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=T4muj96OKxoDyynstZlFtabHzduGJkU9819DzpNMkSA=; b=jOB6Uw82QZilMgBYfM3QRrL+P5qxWJ6ucWCbxxkT+WZ+AKqmqPH3vNZsvxjimK8dnJ FhNw/fquSfnX8l5hrn3I3KKBuCZdqvRzrTJ/5D9DloSmQ8Baa5vNh3BkWDb/6OkQDiRf HGhOTPFFmYOHWVIpix0htS+5GOow6fcNivvxRFUx4dWOl1ccYVG1NzVA0tr3P4RjaZL/ pF7SQcFeiBwvxqWiuSwBAilE2ipX8t5/Npc0wrGl4WbMWDBsG1wswNaA6RGXkrf3p3KF 26blOxQx0vtIVMD/j0rt4wiqnhddRLYTC/4C++XhPkQvxANpxiJPYFdo2XsF1YnZdaYs Vhsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796089971; x=1796694771; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=T4muj96OKxoDyynstZlFtabHzduGJkU9819DzpNMkSA=; b=yd99aqDh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QY2TYm4tgo PQSVU21EItRoW+49A++QX1BAhjjRcQvkrliRIw== X-Received: by 2002:a05:600c:3113:b0:4a2:267:25b3 with SMTP id 5b1f17b1804b1-4bb8882a4b9mr748148515e9.35.1796089971194; Mon, 30 Nov 2026 17:52:51 -0800 (PST) Received: from NULL.Home.net ([2001:8a0:7280:4000:12d:c3b9:cecc:8966]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884911e3sm1199037055e9.6.2026.11.30.17.52.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 17:52:50 -0800 (PST) From: Eric Curtin To: linux-arm-kernel@lists.infradead.org Cc: Eric Curtin , Vlastimil Babka , David Hildenbrand , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Johannes Weiner , Suren Baghdasaryan , Brendan Jackman , Zi Yan , Andrew Morton , linux-mm@kvack.org Subject: [RFC PATCH v2 04/43] mm: page_frag: Add _MIN/_MAX variants of PAGE_FRAG_CACHE_MAX_SIZE Date: Tue, 1 Dec 2026 01:51:36 +0000 Message-ID: <20261201015240.1017259-5-ericcurtin17@gmail.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201015240.1017259-1-ericcurtin17@gmail.com> References: <20261201015240.1017259-1-ericcurtin17@gmail.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_175254_554051_D8BEC82C X-CRM114-Status: GOOD ( 16.05 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Eric Curtin PAGE_FRAG_CACHE_MAX_SIZE is derived from PAGE_MASK and, with boot-time page size selection, is not a compile-time constant. It is needed both where a constant is required (struct layout, preprocessor conditionals, BUILD_BUG_ON()) and to compute the allocation order at run time. Make PAGE_FRAG_CACHE_MAX_SIZE, and hence PAGE_FRAG_CACHE_MAX_ORDER, follow the runtime PAGE_MASK, and add PAGE_FRAG_CACHE_MAX_SIZE_MIN and PAGE_FRAG_CACHE_MAX_SIZE_MAX, computed from PAGE_MASK_MIN and PAGE_MASK_MAX. Use the _MAX variant for the struct page_frag_cache layout and the _MIN variant for PAGE_FRAG_CACHE_ORDER_MASK and the encoded_page_create() order check. No functional change for compile-time page sizes. Signed-off-by: Ryan Roberts Acked-by: Vlastimil Babka Signed-off-by: Eric Curtin (cherry picked from commit ef68b4f691a7bb68097fb285c111ac88caeb107c) --- include/linux/mm_types_task.h | 6 ++++-- include/linux/page_frag_cache.h | 2 +- mm/page_frag_cache.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/linux/mm_types_task.h b/include/linux/mm_types_task.h index 704c3c31d11d..2f760f472e19 100644 --- a/include/linux/mm_types_task.h +++ b/include/linux/mm_types_task.h @@ -44,7 +44,9 @@ struct page_frag { #endif }; -#define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK_MIN) +#define PAGE_FRAG_CACHE_MAX_SIZE __ALIGN_MASK(32768, ~PAGE_MASK) +#define PAGE_FRAG_CACHE_MAX_SIZE_MIN __ALIGN_MASK(32768, ~PAGE_MASK_MIN) +#define PAGE_FRAG_CACHE_MAX_SIZE_MAX __ALIGN_MASK(32768, ~PAGE_MASK_MAX) #define PAGE_FRAG_CACHE_MAX_ORDER get_order(PAGE_FRAG_CACHE_MAX_SIZE) struct page_frag_cache { /* encoded_page consists of the virtual address, pfmemalloc bit and @@ -55,7 +57,7 @@ struct page_frag_cache { /* we maintain a pagecount bias, so that we dont dirty cache line * containing page->_refcount every time we allocate a fragment. */ -#if (PAGE_SIZE_MAX < PAGE_FRAG_CACHE_MAX_SIZE) && (BITS_PER_LONG <= 32) +#if (PAGE_SIZE_MAX < PAGE_FRAG_CACHE_MAX_SIZE_MAX) && (BITS_PER_LONG <= 32) __u16 offset; __u16 pagecnt_bias; #else diff --git a/include/linux/page_frag_cache.h b/include/linux/page_frag_cache.h index 49a0b0b51446..5ce206c892f7 100644 --- a/include/linux/page_frag_cache.h +++ b/include/linux/page_frag_cache.h @@ -8,7 +8,7 @@ #include #include -#if (PAGE_SIZE_MIN < PAGE_FRAG_CACHE_MAX_SIZE) +#if (PAGE_SIZE_MIN < PAGE_FRAG_CACHE_MAX_SIZE_MIN) /* Use a full byte here to enable assembler optimization as the shift * operation is usually expecting a byte. */ diff --git a/mm/page_frag_cache.c b/mm/page_frag_cache.c index d4419caa0c06..7f1eca0b9955 100644 --- a/mm/page_frag_cache.c +++ b/mm/page_frag_cache.c @@ -23,7 +23,7 @@ static unsigned long encoded_page_create(struct page *page, unsigned int order, bool pfmemalloc) { - BUILD_BUG_ON(order_base_2(PAGE_FRAG_CACHE_MAX_SIZE >> PAGE_SHIFT_MIN) > + BUILD_BUG_ON(order_base_2(PAGE_FRAG_CACHE_MAX_SIZE_MIN >> PAGE_SHIFT_MIN) > PAGE_FRAG_CACHE_ORDER_MASK); BUILD_BUG_ON(PAGE_FRAG_CACHE_PFMEMALLOC_BIT >= PAGE_SIZE_MIN);