Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Curtin <ericcurtin17@gmail.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Ryan Roberts <ryan.roberts@arm.com>,
	Minchan Kim <minchan@kernel.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org
Subject: [RFC PATCH v2 35/43] mm/zsmalloc: Size static limits for the worst-case page size
Date: Tue,  1 Dec 2026 01:52:07 +0000	[thread overview]
Message-ID: <20261201015240.1017259-36-ericcurtin17@gmail.com> (raw)
In-Reply-To: <20261201015240.1017259-1-ericcurtin17@gmail.com>

From: Ryan Roberts <ryan.roberts@arm.com>

zsmalloc uses PAGE_SIZE and PAGE_SHIFT in constants and in the size of
an array in struct zs_pool, none of which are compile-time constants
with arm64 boot-time page size selection.

Take the worst case where a constant is needed: _PFN_BITS uses
PAGE_SHIFT_MIN, since the smallest page gives the most PFN bits,
ZS_OBJS_PER_PAGE_BITS uses PAGE_SHIFT_MAX, and the 24-bit first object
offset check in set_first_obj_offset() uses PAGE_SIZE_MAX.
ZS_SIZE_CLASSES now depends on the runtime page size, so the size_class
array in struct zs_pool becomes a pointer that zs_create_pool()
allocates with kcalloc() and zs_destroy_pool() frees.

Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit dca1629b5374efd825c6a5bc6d4f210dae3b861f)
---
 mm/zsmalloc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 7ef80e0da626..09d131da22ac 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -72,13 +72,13 @@
 #else
 /*
  * If this definition of MAX_PHYSMEM_BITS is used, ZS_OBJ_PFN_SHIFT will
- * just be PAGE_SHIFT
+ * just be PAGE_SHIFT_MIN
  */
 #define MAX_POSSIBLE_PHYSMEM_BITS BITS_PER_LONG
 #endif
 #endif
 
-#define _PFN_BITS		(MAX_POSSIBLE_PHYSMEM_BITS - PAGE_SHIFT)
+#define _PFN_BITS		(MAX_POSSIBLE_PHYSMEM_BITS - PAGE_SHIFT_MIN)
 
 /*
  * Head in allocated object should have OBJ_ALLOCATED_TAG
@@ -137,7 +137,7 @@
  * possible object size: log2(PAGE_SIZE / 32) = PAGE_SHIFT - 5.
  * 32 is the hard floor of ZS_MIN_ALLOC_SIZE.
  */
-#define ZS_OBJS_PER_PAGE_BITS	(PAGE_SHIFT - 5)
+#define ZS_OBJS_PER_PAGE_BITS	(PAGE_SHIFT_MAX - 5)
 
 /*
  * Bits to index any object in the densest possible zspage.  Below this,
@@ -270,7 +270,7 @@ static struct kmem_cache *zspage_cachep;
 struct zs_pool {
 	const char *name;
 
-	struct size_class *size_class[ZS_SIZE_CLASSES];
+	struct size_class **size_class;
 
 	atomic_long_t pages_allocated;
 
@@ -502,7 +502,7 @@ static inline unsigned int get_first_obj_offset(struct zpdesc *zpdesc)
 static inline void set_first_obj_offset(struct zpdesc *zpdesc, unsigned int offset)
 {
 	/* With 24 bits available, we can support offsets into 16 MiB pages. */
-	BUILD_BUG_ON(PAGE_SIZE > SZ_16M);
+	BUILD_BUG_ON(PAGE_SIZE_MAX > SZ_16M);
 	VM_WARN_ON_ONCE(!PageZsmalloc(zpdesc_page(zpdesc)));
 	VM_WARN_ON_ONCE(offset & ~FIRST_OBJ_PAGE_TYPE_MASK);
 	zpdesc->first_obj_offset &= ~FIRST_OBJ_PAGE_TYPE_MASK;
@@ -2151,6 +2151,13 @@ struct zs_pool *zs_create_pool(const char *name)
 	rwlock_init(&pool->lock);
 	atomic_set(&pool->compaction_in_progress, 0);
 
+	pool->size_class = kcalloc(ZS_SIZE_CLASSES,
+					sizeof(*pool->size_class), GFP_KERNEL);
+	if (!pool->size_class) {
+		kfree(pool);
+		return NULL;
+	}
+
 	pool->name = kstrdup(name, GFP_KERNEL);
 	if (!pool->name)
 		goto err;
@@ -2276,6 +2283,7 @@ void zs_destroy_pool(struct zs_pool *pool)
 		kfree(class);
 	}
 
+	kfree(pool->size_class);
 	kfree(pool->name);
 	kfree(pool);
 }


  parent reply	other threads:[~2026-12-01  1:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 02/43] vmlinux.lds: Align page-aligned sections to PAGE_SIZE_MAX Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 03/43] mm: page_frag: Use PAGE_SIZE_MIN/MAX limits in page_frag_cache Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 04/43] mm: page_frag: Add _MIN/_MAX variants of PAGE_FRAG_CACHE_MAX_SIZE Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 05/43] mm: Avoid split pmd ptl if pmd level is run-time folded Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 06/43] mm/vmstat: Use THREAD_SIZE_MAX for the KSTACK_* counters Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 07/43] fork: Permit boot-time THREAD_SIZE determination Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 21/43] arm64: Test PAGE_SIZE instead of CONFIG_ARM64_*K_PAGES Eric Curtin
2026-12-01  1:51 ` [RFC PATCH v2 25/43] arm64: Size and align the zero page and FDT ptes for PAGE_SIZE_MAX Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 30/43] arm64: Support runtime folding of the pmd level Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 34/43] mm/damon/lru_sort: Initialise the stub access pattern at boot Eric Curtin
2026-12-01  1:52 ` Eric Curtin [this message]
2026-12-01  1:52 ` [RFC PATCH v2 38/43] mm: Use fixed sizes for shmem str_dup and swap cache PFN bits Eric Curtin
2026-12-01  1:52 ` [RFC PATCH v2 43/43] arm64: Enable boot-time page size selection Eric Curtin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201015240.1017259-36-ericcurtin17@gmail.com \
    --to=ericcurtin17@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=senozhatsky@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox