[RFC PATCH v2 04/43] mm: page_frag: Add _MIN/_MAX variants of PAGE_FRAG_CACHE_MAX_SIZE
Eric Curtin
ericcurtin17 at gmail.com
Mon Nov 30 17:51:36 PST 2026
From: Eric Curtin <eric.curtin at docker.com>
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 <ryan.roberts at arm.com>
Acked-by: Vlastimil Babka <vbabka at suse.cz>
Signed-off-by: Eric Curtin <eric.curtin at docker.com>
(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 <linux/mm_types_task.h>
#include <linux/types.h>
-#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);
More information about the linux-arm-kernel
mailing list