From nobody Fri Oct 3 14:29:31 2025 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D2AB8F48 for ; Fri, 29 Aug 2025 16:22:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756484555; cv=none; b=TIj+oo/bIIyK6zDkNnqWqn1dek+GGvuKthbYjLZt6YtpGJzqgzTtw0EuqDqAUnhfZQ0Z+MSh56HSR15RjEMUuyIeB5XsNGdKBm2cULaXpdUw7mzcjmOUgbV+/MsHP3BxyPQBO1mYMkfN/j99wy9KR6ogGAmvR800LTZyEo6mQxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756484555; c=relaxed/simple; bh=MSu69PbcNXgKi3XQhfJcBjW/Ak9uLs0b1wL9tQDBmjk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=po1osMXcD93JQEaIFo9X78fzkp2WicNexYMT8Sukuyz/D8iV1EtEqp5IW6yr+fgWXY5c8pnv6QcQ69iPiQ6Eqr2UZFf1UghTCBahSYDiBoJl90nrn7WVcwa7l4zPBTkY+oV2q9vU1nkRQ/AkL1rWeCs+i/KYleC9bm8KFeh1284= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b=kAScLuHP; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b="kAScLuHP" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-45a1b065d59so16132635e9.1 for ; Fri, 29 Aug 2025 09:22:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1756484550; x=1757089350; darn=vger.kernel.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; bh=17CQ98MuUtL4N4kqO5j7p5dqQdWQb8rW4TV4oJdSx98=; b=kAScLuHP1+xCrzWBLSh9QkGQ0aUDUHx8XhrpTw7zPoS8CV2EJ7v/GmjtbIIBR0TD/S 5DYm7NXPi0IkWACk+4ha3CdJmRp5ao/uV4P+1+JUbWqMWXq7dY67FMiwJN8ErwhZNs9C Wk7OP75Jkkwfcp7PoBIvmVq1h5W9+9RzcsDQlwcfpj5D29sknEvNc/Dg7t5Xl5fvpQaC guU0azq3mNcuoOZHiQrpJqdtQQegIvz+nlR7GdKs67zCJuNlY6nC4EG17vyLOnKCNagz bKWpHrIvU24/G1w5bo6oO8IG4CLTnN/tgMcsnn64T7sF0cRri27Ezdsj6vZA33cuCyy1 KkJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756484550; x=1757089350; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=17CQ98MuUtL4N4kqO5j7p5dqQdWQb8rW4TV4oJdSx98=; b=BgA2aT35nAFEHuCDC0qNve8oxRPeRuzMv80UqzrHY8+ZGGJDrJMX0lq5QVuz/UVOnC oi2RlSHWpkYsfSuZRMTRfLpBXPaDH09yjfwqXlKVykGquLirO9VdkjyEt60V07tQm3UG IFL9Yah+zWRU7WjCxNxx+Ewz59Y/B2+uE6EoVqVL13VYgeHGFEkBZUAgugCcmUdFGFBN 8AlDuZUAJ+ODC4mcXvkSZlzX6i6XnRQ+EmwtefmC0nXPrGGMjjObUefIwPi/XIQzuRyQ LYV8IxTh91Q0NTxC/uW2bLRevkUaQt9xzGBO7+DiGvjvjseKwVtInAcP1s6e1tWmuga3 QdGA== X-Forwarded-Encrypted: i=1; AJvYcCX+JsVOziy2UEwLsS0V7huUxA72CqZqK0bQgN7GIVKrKrC1x2u2HcmKbvECFYpE0qdJZPOVI5w2KlKdFRg=@vger.kernel.org X-Gm-Message-State: AOJu0YxQG4tVN3JXjGdRzVNbpzM/gzxaHU5JvqSl2zMkGB8/4DI8TwFM bPaKZ2TTmaOtNoRT/QJMF7sMP/oE2UD/A8z9xCI4XDeWgPc18a9PS3f8Ti2XYFDSWjw= X-Gm-Gg: ASbGncvOtiVxcJKo8Andl0yqL6N/+2RXJu1WIvnUckybdhidOorB2hkFk9qEvStU19K nH/dG5YfXhAcNEjoOmYU9Hc6FloCAc/maUJnAtNXxlc/rfrehErpJhqQg+WaS3TE9C8HvKzhh6E tfWtAGvhLyYuPUHIknmtWTb0bkqi34vxOFNHCgEvHm5qqvIQRcIM6wEBSv0p9DGTzEFcyAfREND qiDgkqbuq5nYPAQ91JkazRnrh9FxCnst9Wh4erWSC5xyjYijvamYHVeSpjy2L/nnFlPHsVIFmm9 z3l2s7qNSs8MBHxriUWvT+/tIZ8oOuFQSvq9wQJUZJpTEFdBUgMj4nBRW3+zyr16+PQBVcr+ZpV P+2U= X-Google-Smtp-Source: AGHT+IGiYw4FjHPC+6dgPLMR3aSXIAaXkZtWGmpJ4U5RD6XOlfpkT3JB+Sho4Mz3B/jAtL0xXsW3sQ== X-Received: by 2002:a05:600c:4715:b0:458:f70d:ebd7 with SMTP id 5b1f17b1804b1-45b517c2f25mr225292705e9.20.1756484550046; Fri, 29 Aug 2025 09:22:30 -0700 (PDT) Received: from localhost ([2620:10d:c092:600::1:954]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-3cf33fb9431sm3901684f8f.44.2025.08.29.09.22.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Aug 2025 09:22:28 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Yosry Ahmed , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] mm: zswap: interact directly with zsmalloc Date: Fri, 29 Aug 2025 17:15:26 +0100 Message-ID: <20250829162212.208258-2-hannes@cmpxchg.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250829162212.208258-1-hannes@cmpxchg.org> References: <20250829162212.208258-1-hannes@cmpxchg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" zswap goes through the zpool layer to enable runtime-switching of allocator backends for compressed data. However, since zbud and z3fold were removed in 6.15, zsmalloc has been the only option available. As such, the zpool indirection is unnecessary. Make zswap deal with zsmalloc directly. This is comparable to zram, which also directly interacts with zsmalloc and has never supported a different backend. Note that this does not preclude future improvements and experiments with different allocation strategies. Should it become necessary, it's possible to provide an alternate implementation for the zsmalloc API, selectable at compile time. However, zsmalloc is also rather mature and feature rich, with years of widespread production exposure; it's encouraged to make incremental improvements rather than fork it. In any case, the complexity of runtime pluggability seems excessive and unjustified at this time. Switch zswap to zsmalloc to remove the last user of the zpool API. Signed-off-by: Johannes Weiner Acked-by: Nhat Pham Acked-by: Yosry Ahmed --- mm/zswap.c | 202 ++++++++++++++--------------------------------------- 1 file changed, 54 insertions(+), 148 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index e5e1f5687f5e..c88ad61b232c 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -35,6 +34,7 @@ #include #include #include +#include =20 #include "swap.h" #include "internal.h" @@ -107,16 +107,6 @@ static const struct kernel_param_ops zswap_compressor_= param_ops =3D { module_param_cb(compressor, &zswap_compressor_param_ops, &zswap_compressor, 0644); =20 -/* Compressed storage zpool to use */ -static char *zswap_zpool_type =3D CONFIG_ZSWAP_ZPOOL_DEFAULT; -static int zswap_zpool_param_set(const char *, const struct kernel_param *= ); -static const struct kernel_param_ops zswap_zpool_param_ops =3D { - .set =3D zswap_zpool_param_set, - .get =3D param_get_charp, - .free =3D param_free_charp, -}; -module_param_cb(zpool, &zswap_zpool_param_ops, &zswap_zpool_type, 0644); - /* The maximum percentage of memory that the compressed pool can occupy */ static unsigned int zswap_max_pool_percent =3D 20; module_param_named(max_pool_percent, zswap_max_pool_percent, uint, 0644); @@ -161,7 +151,7 @@ struct crypto_acomp_ctx { * needs to be verified that it's still valid in the tree. */ struct zswap_pool { - struct zpool *zpool; + struct zs_pool *zs_pool; struct crypto_acomp_ctx __percpu *acomp_ctx; struct percpu_ref ref; struct list_head list; @@ -193,7 +183,7 @@ static struct shrinker *zswap_shrinker; * logic if referenced is unset. See comments in the shrinker * section for context. * pool - the zswap_pool the entry's data is in - * handle - zpool allocation handle that stores the compressed page data + * handle - zsmalloc allocation handle that stores the compressed page data * objcg - the obj_cgroup that the compressed memory is charged to * lru - handle to the pool's lru used to evict pages. */ @@ -214,7 +204,7 @@ static unsigned int nr_zswap_trees[MAX_SWAPFILES]; static LIST_HEAD(zswap_pools); /* protects zswap_pools list modification */ static DEFINE_SPINLOCK(zswap_pools_lock); -/* pool counter to provide unique names to zpool */ +/* pool counter to provide unique names to zsmalloc */ static atomic_t zswap_pools_count =3D ATOMIC_INIT(0); =20 enum zswap_init_type { @@ -241,32 +231,22 @@ static inline struct xarray *swap_zswap_tree(swp_entr= y_t swp) >> SWAP_ADDRESS_SPACE_SHIFT]; } =20 -#define zswap_pool_debug(msg, p) \ - pr_debug("%s pool %s/%s\n", msg, (p)->tfm_name, \ - zpool_get_type((p)->zpool)) +#define zswap_pool_debug(msg, p) \ + pr_debug("%s pool %s\n", msg, (p)->tfm_name) =20 /********************************* * pool functions **********************************/ static void __zswap_pool_empty(struct percpu_ref *ref); =20 -static struct zswap_pool *zswap_pool_create(char *type, char *compressor) +static struct zswap_pool *zswap_pool_create(char *compressor) { struct zswap_pool *pool; char name[38]; /* 'zswap' + 32 char (max) num + \0 */ - gfp_t gfp =3D __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM; int ret, cpu; =20 - if (!zswap_has_pool) { - /* if either are unset, pool initialization failed, and we - * need both params to be set correctly before trying to - * create a pool. - */ - if (!strcmp(type, ZSWAP_PARAM_UNSET)) - return NULL; - if (!strcmp(compressor, ZSWAP_PARAM_UNSET)) - return NULL; - } + if (!zswap_has_pool && !strcmp(compressor, ZSWAP_PARAM_UNSET)) + return NULL; =20 pool =3D kzalloc(sizeof(*pool), GFP_KERNEL); if (!pool) @@ -274,12 +254,9 @@ static struct zswap_pool *zswap_pool_create(char *type= , char *compressor) =20 /* unique name for each pool specifically required by zsmalloc */ snprintf(name, 38, "zswap%x", atomic_inc_return(&zswap_pools_count)); - pool->zpool =3D zpool_create_pool(type, name, gfp); - if (!pool->zpool) { - pr_err("%s zpool not available\n", type); + pool->zs_pool =3D zs_create_pool(name); + if (!pool->zs_pool) goto error; - } - pr_debug("using %s zpool\n", zpool_get_type(pool->zpool)); =20 strscpy(pool->tfm_name, compressor, sizeof(pool->tfm_name)); =20 @@ -315,52 +292,29 @@ static struct zswap_pool *zswap_pool_create(char *typ= e, char *compressor) error: if (pool->acomp_ctx) free_percpu(pool->acomp_ctx); - if (pool->zpool) - zpool_destroy_pool(pool->zpool); + if (pool->zs_pool) + zs_destroy_pool(pool->zs_pool); kfree(pool); return NULL; } =20 static struct zswap_pool *__zswap_pool_create_fallback(void) { - bool has_comp, has_zpool; - - has_comp =3D crypto_has_acomp(zswap_compressor, 0, 0); - if (!has_comp && strcmp(zswap_compressor, - CONFIG_ZSWAP_COMPRESSOR_DEFAULT)) { + if (!crypto_has_acomp(zswap_compressor, 0, 0) && + strcmp(zswap_compressor, CONFIG_ZSWAP_COMPRESSOR_DEFAULT)) { pr_err("compressor %s not available, using default %s\n", zswap_compressor, CONFIG_ZSWAP_COMPRESSOR_DEFAULT); param_free_charp(&zswap_compressor); zswap_compressor =3D CONFIG_ZSWAP_COMPRESSOR_DEFAULT; - has_comp =3D crypto_has_acomp(zswap_compressor, 0, 0); - } - if (!has_comp) { - pr_err("default compressor %s not available\n", - zswap_compressor); - param_free_charp(&zswap_compressor); - zswap_compressor =3D ZSWAP_PARAM_UNSET; - } - - has_zpool =3D zpool_has_pool(zswap_zpool_type); - if (!has_zpool && strcmp(zswap_zpool_type, - CONFIG_ZSWAP_ZPOOL_DEFAULT)) { - pr_err("zpool %s not available, using default %s\n", - zswap_zpool_type, CONFIG_ZSWAP_ZPOOL_DEFAULT); - param_free_charp(&zswap_zpool_type); - zswap_zpool_type =3D CONFIG_ZSWAP_ZPOOL_DEFAULT; - has_zpool =3D zpool_has_pool(zswap_zpool_type); - } - if (!has_zpool) { - pr_err("default zpool %s not available\n", - zswap_zpool_type); - param_free_charp(&zswap_zpool_type); - zswap_zpool_type =3D ZSWAP_PARAM_UNSET; + if (!crypto_has_acomp(zswap_compressor, 0, 0)) { + pr_err("default compressor %s not available\n", + zswap_compressor); + zswap_compressor =3D ZSWAP_PARAM_UNSET; + return NULL; + } } =20 - if (!has_comp || !has_zpool) - return NULL; - - return zswap_pool_create(zswap_zpool_type, zswap_compressor); + return zswap_pool_create(zswap_compressor); } =20 static void zswap_pool_destroy(struct zswap_pool *pool) @@ -370,7 +324,7 @@ static void zswap_pool_destroy(struct zswap_pool *pool) cpuhp_state_remove_instance(CPUHP_MM_ZSWP_POOL_PREPARE, &pool->node); free_percpu(pool->acomp_ctx); =20 - zpool_destroy_pool(pool->zpool); + zs_destroy_pool(pool->zs_pool); kfree(pool); } =20 @@ -462,7 +416,7 @@ static struct zswap_pool *zswap_pool_current_get(void) } =20 /* type and compressor must be null-terminated */ -static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor) +static struct zswap_pool *zswap_pool_find_get(char *compressor) { struct zswap_pool *pool; =20 @@ -471,8 +425,6 @@ static struct zswap_pool *zswap_pool_find_get(char *typ= e, char *compressor) list_for_each_entry_rcu(pool, &zswap_pools, list) { if (strcmp(pool->tfm_name, compressor)) continue; - if (strcmp(zpool_get_type(pool->zpool), type)) - continue; /* if we can't get it, it's about to be destroyed */ if (!zswap_pool_tryget(pool)) continue; @@ -499,7 +451,7 @@ unsigned long zswap_total_pages(void) =20 rcu_read_lock(); list_for_each_entry_rcu(pool, &zswap_pools, list) - total +=3D zpool_get_total_pages(pool->zpool); + total +=3D zs_get_total_pages(pool->zs_pool); rcu_read_unlock(); =20 return total; @@ -524,33 +476,22 @@ static bool zswap_check_limits(void) * param callbacks **********************************/ =20 -static bool zswap_pool_changed(const char *s, const struct kernel_param *k= p) -{ - /* no change required */ - if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool) - return false; - return true; -} - -/* val must be a null-terminated string */ -static int __zswap_param_set(const char *val, const struct kernel_param *k= p, - char *type, char *compressor) +static int zswap_compressor_param_set(const char *val, const struct kernel= _param *kp) { struct zswap_pool *pool, *put_pool =3D NULL; char *s =3D strstrip((char *)val); + bool create_pool =3D false; int ret =3D 0; - bool new_pool =3D false; =20 mutex_lock(&zswap_init_lock); switch (zswap_init_state) { case ZSWAP_UNINIT: - /* if this is load-time (pre-init) param setting, - * don't create a pool; that's done during init. - */ + /* Handled in zswap_setup() */ ret =3D param_set_charp(s, kp); break; case ZSWAP_INIT_SUCCEED: - new_pool =3D zswap_pool_changed(s, kp); + if (!zswap_has_pool || strcmp(s, *(char **)kp->arg)) + create_pool =3D true; break; case ZSWAP_INIT_FAILED: pr_err("can't set param, initialization failed\n"); @@ -558,30 +499,17 @@ static int __zswap_param_set(const char *val, const s= truct kernel_param *kp, } mutex_unlock(&zswap_init_lock); =20 - /* no need to create a new pool, return directly */ - if (!new_pool) + if (!create_pool) return ret; =20 - if (!type) { - if (!zpool_has_pool(s)) { - pr_err("zpool %s not available\n", s); - return -ENOENT; - } - type =3D s; - } else if (!compressor) { - if (!crypto_has_acomp(s, 0, 0)) { - pr_err("compressor %s not available\n", s); - return -ENOENT; - } - compressor =3D s; - } else { - WARN_ON(1); - return -EINVAL; + if (!crypto_has_acomp(s, 0, 0)) { + pr_err("compressor %s not available\n", s); + return -ENOENT; } =20 spin_lock_bh(&zswap_pools_lock); =20 - pool =3D zswap_pool_find_get(type, compressor); + pool =3D zswap_pool_find_get(s); if (pool) { zswap_pool_debug("using existing", pool); WARN_ON(pool =3D=3D zswap_pool_current()); @@ -591,7 +519,7 @@ static int __zswap_param_set(const char *val, const str= uct kernel_param *kp, spin_unlock_bh(&zswap_pools_lock); =20 if (!pool) - pool =3D zswap_pool_create(type, compressor); + pool =3D zswap_pool_create(s); else { /* * Restore the initial ref dropped by percpu_ref_kill() @@ -616,7 +544,8 @@ static int __zswap_param_set(const char *val, const str= uct kernel_param *kp, list_add_rcu(&pool->list, &zswap_pools); zswap_has_pool =3D true; } else if (pool) { - /* add the possibly pre-existing pool to the end of the pools + /* + * Add the possibly pre-existing pool to the end of the pools * list; if it's new (and empty) then it'll be removed and * destroyed by the put after we drop the lock */ @@ -626,18 +555,8 @@ static int __zswap_param_set(const char *val, const st= ruct kernel_param *kp, =20 spin_unlock_bh(&zswap_pools_lock); =20 - if (!zswap_has_pool && !pool) { - /* if initial pool creation failed, and this pool creation also - * failed, maybe both compressor and zpool params were bad. - * Allow changing this param, so pool creation will succeed - * when the other param is changed. We already verified this - * param is ok in the zpool_has_pool() or crypto_has_acomp() - * checks above. - */ - ret =3D param_set_charp(s, kp); - } - - /* drop the ref from either the old current pool, + /* + * Drop the ref from either the old current pool, * or the new pool we failed to add */ if (put_pool) @@ -646,18 +565,6 @@ static int __zswap_param_set(const char *val, const st= ruct kernel_param *kp, return ret; } =20 -static int zswap_compressor_param_set(const char *val, - const struct kernel_param *kp) -{ - return __zswap_param_set(val, kp, zswap_zpool_type, NULL); -} - -static int zswap_zpool_param_set(const char *val, - const struct kernel_param *kp) -{ - return __zswap_param_set(val, kp, NULL, zswap_compressor); -} - static int zswap_enabled_param_set(const char *val, const struct kernel_param *kp) { @@ -801,13 +708,13 @@ static void zswap_entry_cache_free(struct zswap_entry= *entry) } =20 /* - * Carries out the common pattern of freeing and entry's zpool allocation, + * Carries out the common pattern of freeing an entry's zsmalloc allocatio= n, * freeing the entry itself, and decrementing the number of stored pages. */ static void zswap_entry_free(struct zswap_entry *entry) { zswap_lru_del(&zswap_list_lru, entry); - zpool_free(entry->pool->zpool, entry->handle); + zs_free(entry->pool->zs_pool, entry->handle); zswap_pool_put(entry->pool); if (entry->objcg) { obj_cgroup_uncharge_zswap(entry->objcg, entry->length); @@ -949,7 +856,6 @@ static bool zswap_compress(struct page *page, struct zs= wap_entry *entry, int comp_ret =3D 0, alloc_ret =3D 0; unsigned int dlen =3D PAGE_SIZE; unsigned long handle; - struct zpool *zpool; gfp_t gfp; u8 *dst; bool mapped =3D false; @@ -997,13 +903,14 @@ static bool zswap_compress(struct page *page, struct = zswap_entry *entry, mapped =3D true; } =20 - zpool =3D pool->zpool; gfp =3D GFP_NOWAIT | __GFP_NORETRY | __GFP_HIGHMEM | __GFP_MOVABLE; - alloc_ret =3D zpool_malloc(zpool, dlen, gfp, &handle, page_to_nid(page)); - if (alloc_ret) + handle =3D zs_malloc(pool->zs_pool, dlen, gfp, page_to_nid(page)); + if (IS_ERR_VALUE(handle)) { + alloc_ret =3D PTR_ERR((void *)handle); goto unlock; + } =20 - zpool_obj_write(zpool, handle, dst, dlen); + zs_obj_write(pool->zs_pool, handle, dst, dlen); entry->handle =3D handle; entry->length =3D dlen; =20 @@ -1023,14 +930,14 @@ static bool zswap_compress(struct page *page, struct= zswap_entry *entry, =20 static bool zswap_decompress(struct zswap_entry *entry, struct folio *foli= o) { - struct zpool *zpool =3D entry->pool->zpool; + struct zswap_pool *pool =3D entry->pool; struct scatterlist input, output; struct crypto_acomp_ctx *acomp_ctx; int decomp_ret =3D 0, dlen =3D PAGE_SIZE; u8 *src, *obj; =20 - acomp_ctx =3D acomp_ctx_get_cpu_lock(entry->pool); - obj =3D zpool_obj_read_begin(zpool, entry->handle, acomp_ctx->buffer); + acomp_ctx =3D acomp_ctx_get_cpu_lock(pool); + obj =3D zs_obj_read_begin(pool->zs_pool, entry->handle, acomp_ctx->buffer= ); =20 /* zswap entries of length PAGE_SIZE are not compressed. */ if (entry->length =3D=3D PAGE_SIZE) { @@ -1039,7 +946,7 @@ static bool zswap_decompress(struct zswap_entry *entry= , struct folio *folio) } =20 /* - * zpool_obj_read_begin() might return a kmap address of highmem when + * zs_obj_read_begin() might return a kmap address of highmem when * acomp_ctx->buffer is not used. However, sg_init_one() does not * handle highmem addresses, so copy the object to acomp_ctx->buffer. */ @@ -1059,7 +966,7 @@ static bool zswap_decompress(struct zswap_entry *entry= , struct folio *folio) dlen =3D acomp_ctx->req->dlen; =20 read_done: - zpool_obj_read_end(zpool, entry->handle, obj); + zs_obj_read_end(pool->zs_pool, entry->handle, obj); acomp_ctx_put_unlock(acomp_ctx); =20 if (!decomp_ret && dlen =3D=3D PAGE_SIZE) @@ -1576,7 +1483,7 @@ static bool zswap_store_page(struct page *page, return true; =20 store_failed: - zpool_free(pool->zpool, entry->handle); + zs_free(pool->zs_pool, entry->handle); compress_failed: zswap_entry_cache_free(entry); return false; @@ -1906,8 +1813,7 @@ static int zswap_setup(void) =20 pool =3D __zswap_pool_create_fallback(); if (pool) { - pr_info("loaded using pool %s/%s\n", pool->tfm_name, - zpool_get_type(pool->zpool)); + pr_info("loaded using pool %s\n", pool->tfm_name); list_add(&pool->list, &zswap_pools); zswap_has_pool =3D true; static_branch_enable(&zswap_ever_enabled); --=20 2.51.0 From nobody Fri Oct 3 14:29:31 2025 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C3DD326D77 for ; Fri, 29 Aug 2025 16:22:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756484557; cv=none; b=hnan0KjdZVaLYgdM7PKGOvAcbGJTDKDl1+U/a/g2DPrtFHN9IlxKsfvSz1RCMNrlBEpH0QbWjjzQ5BQ5JdQvkqNxgMo6Bwc8b9xCLY+WYXtd8wFxDI263Ryt0w8mCP3AWapIq+739mIAd2JPgEHHNMtpoKtzDVpU+3vpGvxSS+k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756484557; c=relaxed/simple; bh=iWxUI8Efyya53UaoQNxkY/61GtEmsi6DM2TaxJuY9dw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lMFBCeE62kFBkCYdOF00V0sPAjZNiTyj/sDRSlz68/hAkiTvjlkDJiMIg0hr3cofVz2DJdFhRaizSOePShkrClkEQ1n3C+ABtB7QCO6hg0kgsoSymc7zFnGGLCcpKp2iiKYrV+bcpuxpIlu4J7LATF8mSAAjc6qO2+pKu3t/iRM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b=xbSgAxt+; arc=none smtp.client-ip=209.85.221.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b="xbSgAxt+" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3c46686d1e6so1410436f8f.3 for ; Fri, 29 Aug 2025 09:22:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1756484552; x=1757089352; darn=vger.kernel.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; bh=hKqb+mo8c5YOBYVE1Ay2NJr1wYHFuWGaBFA4CjRh+H0=; b=xbSgAxt+HgT7yHv2cZeOEspY+eBQYV6L3lsnon+SO00YAyU1JIlycMTNpNMH5B3HQt 64XXlxQ5U4pSmr9RA06yK8tAB9ZQfnZ4cSndps6gz+45BZNni+TN+Th2QyhsISw7VpGs z3yJoYBKLnIX24ue41QsUikclmvaeFPcd/cIw1NUPZ4HkBVmraz9HKtRFmTHHXQWDexH 4ZHULSUsXpIsRB6OfGDBScR+NeAVmF2KzECrz82A2ifVgyWpIbK1Y2YapasIA70dWO0S FocnOK4T/10hLtOJg9kIKMqew4I8W0wCpHnq3A1RggRiCaIAa+T8YVHxisf88mmYmmES MjgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756484552; x=1757089352; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hKqb+mo8c5YOBYVE1Ay2NJr1wYHFuWGaBFA4CjRh+H0=; b=c+ccl0288Uuxfve22/4kak98PXlQQicFgnHSKVRkr9smasgD8JSgd7DuzrIJMwKk2r EVa6IpwV765IPyr9KMbUULGTkgWrHAmsjUVb+D3iR6JqCjsx/xxGmz/dYebR4p63zbXn z7hxqfA8ATpi3V6NNux90rq4BdAliozISKJ14m4oVHegcZ+CURoWWflGPauCxXrnDRVz G92bWhWt01KcJ5yEsEmVk1ddnW6WlUZvZ010if1eXnaOa3W/2kjnn7tmlDX8rtaFov/g Aa80JoZfNskhgWf7k1zMUMu4R+CloHxUC12t9Zez3GJiqTFBUXJJYfZuN75V1JI3eWY7 6xcQ== X-Forwarded-Encrypted: i=1; AJvYcCXwdnPToxWZfhPcfpMOmdjE1xX0u8j8ygYnN14ChssHvYGty67Kyz/mgg00tbpnby8fc9WGWQ+K3x38qTY=@vger.kernel.org X-Gm-Message-State: AOJu0YzdtOVIQBxh4W2Mz3yDQZVZdwsipGSMcEH6Tlh7BzLwpq51rmNT SZS3arF7FV+CoLJ0QIp/NSYNWvxc9TYeU2eN3uyXDB+qiy8TYzWGpiLgvQfQ43w6fSQ= X-Gm-Gg: ASbGncsH2KvFHRuLCOao6TohYFejAjsK7LO9MQ+NjhJejWEV9+oe0WdSzBnVC8Tr1HN cuq4BKeQYW40Teu5HUcXCVqGYcQslWrg4YE/yD5OYLCp5LsMbBGfZdTncMMNm0Gb3k+2BpVGH9H PIdKfDzvA3FZV0Rxai1UDvemYf70EEFk8v8OE+cLOW6aqTnERFzwu/M0WjAVzu9duplwIp/5Bjt uGDiIPDB4aSlIlRjw2P+2CpUfdXpMlO1hi8a+rht/z+g3oEF5entumuzBFa3Kxp4RO8o3Rqfh4a zpBSfKzOmCCL4iuLijAX1uioIaqnLEuXqt4O50hTKj8pITr4fjJh+6QSj3KbAQ4XKuIGTKuPVak C3cs= X-Google-Smtp-Source: AGHT+IF5r4ch8VgJ9lf0pLM9LepqQrx7y0p63EHYU7GY0DjIm/bdz0Trn7EVc7AZJrYBUY0yFILr+g== X-Received: by 2002:a5d:584e:0:b0:3d0:bd48:246f with SMTP id ffacd0b85a97d-3d0bd482902mr2019862f8f.31.1756484551871; Fri, 29 Aug 2025 09:22:31 -0700 (PDT) Received: from localhost ([2620:10d:c092:600::1:954]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-45b6f0d3073sm139737085e9.7.2025.08.29.09.22.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Aug 2025 09:22:30 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Yosry Ahmed , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] mm: remove unused zpool layer Date: Fri, 29 Aug 2025 17:15:27 +0100 Message-ID: <20250829162212.208258-3-hannes@cmpxchg.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250829162212.208258-1-hannes@cmpxchg.org> References: <20250829162212.208258-1-hannes@cmpxchg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With zswap using zsmalloc directly, there are no more in-tree users of this code. Remove it. Signed-off-by: Johannes Weiner Acked-by: Nhat Pham Acked-by: SeongJae Park Acked-by: Yosry Ahmed --- Documentation/admin-guide/mm/zswap.rst | 33 +- Documentation/core-api/mm-api.rst | 1 - .../driver-api/crypto/iaa/iaa-crypto.rst | 2 - MAINTAINERS | 2 - arch/loongarch/configs/loongson3_defconfig | 1 - include/linux/zpool.h | 86 ----- mm/Kconfig | 49 +-- mm/Makefile | 1 - mm/zpool.c | 328 ------------------ mm/zsmalloc.c | 79 ----- tools/testing/selftests/zram/README | 1 - 11 files changed, 23 insertions(+), 560 deletions(-) delete mode 100644 include/linux/zpool.h delete mode 100644 mm/zpool.c diff --git a/Documentation/admin-guide/mm/zswap.rst b/Documentation/admin-g= uide/mm/zswap.rst index fd3370aa43fe..283d77217c6f 100644 --- a/Documentation/admin-guide/mm/zswap.rst +++ b/Documentation/admin-guide/mm/zswap.rst @@ -53,26 +53,17 @@ Zswap receives pages for compression from the swap subs= ystem and is able to evict pages from its own compressed pool on an LRU basis and write them ba= ck to the backing swap device in the case that the compressed pool is full. =20 -Zswap makes use of zpool for the managing the compressed memory pool. Each -allocation in zpool is not directly accessible by address. Rather, a hand= le is +Zswap makes use of zsmalloc for the managing the compressed memory pool. = Each +allocation in zsmalloc is not directly accessible by address. Rather, a h= andle is returned by the allocation routine and that handle must be mapped before b= eing accessed. The compressed memory pool grows on demand and shrinks as compr= essed -pages are freed. The pool is not preallocated. By default, a zpool -of type selected in ``CONFIG_ZSWAP_ZPOOL_DEFAULT`` Kconfig option is creat= ed, -but it can be overridden at boot time by setting the ``zpool`` attribute, -e.g. ``zswap.zpool=3Dzsmalloc``. It can also be changed at runtime using t= he sysfs -``zpool`` attribute, e.g.:: - - echo zsmalloc > /sys/module/zswap/parameters/zpool - -The zsmalloc type zpool has a complex compressed page storage method, and = it -can achieve great storage densities. +pages are freed. The pool is not preallocated. =20 When a swap page is passed from swapout to zswap, zswap maintains a mapping -of the swap entry, a combination of the swap type and swap offset, to the = zpool -handle that references that compressed swap page. This mapping is achieved -with a red-black tree per swap type. The swap offset is the search key fo= r the -tree nodes. +of the swap entry, a combination of the swap type and swap offset, to the +zsmalloc handle that references that compressed swap page. This mapping is +achieved with a red-black tree per swap type. The swap offset is the sear= ch +key for the tree nodes. =20 During a page fault on a PTE that is a swap entry, the swapin code calls t= he zswap load function to decompress the page into the page allocated by the = page @@ -96,11 +87,11 @@ It can also be changed at runtime using the sysfs "comp= ressor" =20 echo lzo > /sys/module/zswap/parameters/compressor =20 -When the zpool and/or compressor parameter is changed at runtime, any exis= ting -compressed pages are not modified; they are left in their own zpool. When= a -request is made for a page in an old zpool, it is uncompressed using its -original compressor. Once all pages are removed from an old zpool, the zp= ool -and its compressor are freed. +When the compressor parameter is changed at runtime, any existing compress= ed +pages are not modified; they are left in their own pool. When a request is +made for a page in an old pool, it is uncompressed using its original +compressor. Once all pages are removed from an old pool, the pool and its +compressor are freed. =20 Some of the pages in zswap are same-value filled pages (i.e. contents of t= he page have same value or repetitive pattern). These pages include zero-fill= ed diff --git a/Documentation/core-api/mm-api.rst b/Documentation/core-api/mm-= api.rst index 5063179cfc70..68193a4cfcf5 100644 --- a/Documentation/core-api/mm-api.rst +++ b/Documentation/core-api/mm-api.rst @@ -118,7 +118,6 @@ More Memory Management Functions .. kernel-doc:: mm/memremap.c .. kernel-doc:: mm/hugetlb.c .. kernel-doc:: mm/swap.c -.. kernel-doc:: mm/zpool.c .. kernel-doc:: mm/memcontrol.c .. #kernel-doc:: mm/memory-tiers.c (build warnings) .. kernel-doc:: mm/shmem.c diff --git a/Documentation/driver-api/crypto/iaa/iaa-crypto.rst b/Documenta= tion/driver-api/crypto/iaa/iaa-crypto.rst index 8e50b900d51c..f815d4fd8372 100644 --- a/Documentation/driver-api/crypto/iaa/iaa-crypto.rst +++ b/Documentation/driver-api/crypto/iaa/iaa-crypto.rst @@ -476,7 +476,6 @@ To demonstrate that the following steps work as expecte= d, these # echo 0 > /sys/module/zswap/parameters/enabled # echo 50 > /sys/module/zswap/parameters/max_pool_percent # echo deflate-iaa > /sys/module/zswap/parameters/compressor - # echo zsmalloc > /sys/module/zswap/parameters/zpool # echo 1 > /sys/module/zswap/parameters/enabled # echo 100 > /proc/sys/vm/swappiness # echo never > /sys/kernel/mm/transparent_hugepage/enabled @@ -625,7 +624,6 @@ Now run the following zswap-specific setup commands to = have zswap use echo 0 > /sys/module/zswap/parameters/enabled echo 50 > /sys/module/zswap/parameters/max_pool_percent echo deflate-iaa > /sys/module/zswap/parameters/compressor - echo zsmalloc > /sys/module/zswap/parameters/zpool echo 1 > /sys/module/zswap/parameters/enabled =20 echo 100 > /proc/sys/vm/swappiness diff --git a/MAINTAINERS b/MAINTAINERS index e791f18b61d8..7ceda15372f9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -27877,9 +27877,7 @@ R: Chengming Zhou L: linux-mm@kvack.org S: Maintained F: Documentation/admin-guide/mm/zswap.rst -F: include/linux/zpool.h F: include/linux/zswap.h -F: mm/zpool.c F: mm/zswap.c F: tools/testing/selftests/cgroup/test_zswap.c =20 diff --git a/arch/loongarch/configs/loongson3_defconfig b/arch/loongarch/co= nfigs/loongson3_defconfig index 34eaee0384c9..2b8df0e9e42a 100644 --- a/arch/loongarch/configs/loongson3_defconfig +++ b/arch/loongarch/configs/loongson3_defconfig @@ -106,7 +106,6 @@ CONFIG_CMDLINE_PARTITION=3Dy CONFIG_IOSCHED_BFQ=3Dy CONFIG_BFQ_GROUP_IOSCHED=3Dy CONFIG_BINFMT_MISC=3Dm -CONFIG_ZPOOL=3Dy CONFIG_ZSWAP=3Dy CONFIG_ZSWAP_COMPRESSOR_DEFAULT_ZSTD=3Dy CONFIG_ZSMALLOC=3Dy diff --git a/include/linux/zpool.h b/include/linux/zpool.h deleted file mode 100644 index 369ef068fad8..000000000000 --- a/include/linux/zpool.h +++ /dev/null @@ -1,86 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * zpool memory storage api - * - * Copyright (C) 2014 Dan Streetman - * - * This is a common frontend for the zswap compressed memory storage - * implementations. - */ - -#ifndef _ZPOOL_H_ -#define _ZPOOL_H_ - -struct zpool; - -bool zpool_has_pool(char *type); - -struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t = gfp); - -const char *zpool_get_type(struct zpool *pool); - -void zpool_destroy_pool(struct zpool *pool); - -int zpool_malloc(struct zpool *pool, size_t size, gfp_t gfp, - unsigned long *handle, const int nid); - -void zpool_free(struct zpool *pool, unsigned long handle); - -void *zpool_obj_read_begin(struct zpool *zpool, unsigned long handle, - void *local_copy); - -void zpool_obj_read_end(struct zpool *zpool, unsigned long handle, - void *handle_mem); - -void zpool_obj_write(struct zpool *zpool, unsigned long handle, - void *handle_mem, size_t mem_len); - -u64 zpool_get_total_pages(struct zpool *pool); - - -/** - * struct zpool_driver - driver implementation for zpool - * @type: name of the driver. - * @list: entry in the list of zpool drivers. - * @create: create a new pool. - * @destroy: destroy a pool. - * @malloc: allocate mem from a pool. - * @free: free mem from a pool. - * @sleep_mapped: whether zpool driver can sleep during map. - * @map: map a handle. - * @unmap: unmap a handle. - * @total_size: get total size of a pool. - * - * This is created by a zpool implementation and registered - * with zpool. - */ -struct zpool_driver { - char *type; - struct module *owner; - atomic_t refcount; - struct list_head list; - - void *(*create)(const char *name, gfp_t gfp); - void (*destroy)(void *pool); - - int (*malloc)(void *pool, size_t size, gfp_t gfp, - unsigned long *handle, const int nid); - void (*free)(void *pool, unsigned long handle); - - void *(*obj_read_begin)(void *pool, unsigned long handle, - void *local_copy); - void (*obj_read_end)(void *pool, unsigned long handle, - void *handle_mem); - void (*obj_write)(void *pool, unsigned long handle, - void *handle_mem, size_t mem_len); - - u64 (*total_pages)(void *pool); -}; - -void zpool_register_driver(struct zpool_driver *driver); - -int zpool_unregister_driver(struct zpool_driver *driver); - -bool zpool_can_sleep_mapped(struct zpool *pool); - -#endif diff --git a/mm/Kconfig b/mm/Kconfig index 4108bcd96784..b971d35c43c3 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -9,9 +9,6 @@ menu "Memory Management options" config ARCH_NO_SWAP bool =20 -config ZPOOL - bool - menuconfig SWAP bool "Support for paging of anonymous memory (swap)" depends on MMU && BLOCK && !ARCH_NO_SWAP @@ -26,7 +23,7 @@ config ZSWAP bool "Compressed cache for swap pages" depends on SWAP select CRYPTO - select ZPOOL + select ZSMALLOC help A lightweight compressed cache for swap pages. It takes pages that are in the process of being swapped out and attempts to @@ -125,45 +122,18 @@ config ZSWAP_COMPRESSOR_DEFAULT default "zstd" if ZSWAP_COMPRESSOR_DEFAULT_ZSTD default "" =20 -choice - prompt "Default allocator" - depends on ZSWAP - default ZSWAP_ZPOOL_DEFAULT_ZSMALLOC if MMU - help - Selects the default allocator for the compressed cache for - swap pages. - The default is 'zbud' for compatibility, however please do - read the description of each of the allocators below before - making a right choice. - - The selection made here can be overridden by using the kernel - command line 'zswap.zpool=3D' option. +config ZSMALLOC + tristate =20 -config ZSWAP_ZPOOL_DEFAULT_ZSMALLOC - bool "zsmalloc" - select ZSMALLOC - help - Use the zsmalloc allocator as the default allocator. -endchoice +if ZSMALLOC =20 -config ZSWAP_ZPOOL_DEFAULT - string - depends on ZSWAP - default "zsmalloc" if ZSWAP_ZPOOL_DEFAULT_ZSMALLOC - default "" +menu "Zsmalloc allocator options" + depends on ZSMALLOC =20 -config ZSMALLOC - tristate - prompt "N:1 compression allocator (zsmalloc)" if (ZSWAP || ZRAM) - depends on MMU - help - zsmalloc is a slab-based memory allocator designed to store - pages of various compression levels efficiently. It achieves - the highest storage density with the least amount of fragmentation. +comment "Zsmalloc is a common backend allocator for zswap & zram" =20 config ZSMALLOC_STAT bool "Export zsmalloc statistics" - depends on ZSMALLOC select DEBUG_FS help This option enables code in the zsmalloc to collect various @@ -175,7 +145,6 @@ config ZSMALLOC_CHAIN_SIZE int "Maximum number of physical pages per-zspage" default 8 range 4 16 - depends on ZSMALLOC help This option sets the upper limit on the number of physical pages that a zmalloc page (zspage) can consist of. The optimal zspage @@ -190,6 +159,10 @@ config ZSMALLOC_CHAIN_SIZE =20 For more information, see zsmalloc documentation. =20 +endmenu + +endif + menu "Slab allocator options" =20 config SLUB diff --git a/mm/Makefile b/mm/Makefile index ef54aa615d9d..21abb3353550 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -115,7 +115,6 @@ obj-$(CONFIG_DEBUG_RODATA_TEST) +=3D rodata_test.o obj-$(CONFIG_DEBUG_VM_PGTABLE) +=3D debug_vm_pgtable.o obj-$(CONFIG_PAGE_OWNER) +=3D page_owner.o obj-$(CONFIG_MEMORY_ISOLATION) +=3D page_isolation.o -obj-$(CONFIG_ZPOOL) +=3D zpool.o obj-$(CONFIG_ZSMALLOC) +=3D zsmalloc.o obj-$(CONFIG_GENERIC_EARLY_IOREMAP) +=3D early_ioremap.o obj-$(CONFIG_CMA) +=3D cma.o diff --git a/mm/zpool.c b/mm/zpool.c deleted file mode 100644 index 0a71d03369f1..000000000000 --- a/mm/zpool.c +++ /dev/null @@ -1,328 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * zpool memory storage api - * - * Copyright (C) 2014 Dan Streetman - * - * This is a common frontend for memory storage pool implementations. - * Typically, this is used to store compressed memory. - */ - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include -#include -#include -#include -#include -#include -#include - -struct zpool { - struct zpool_driver *driver; - void *pool; -}; - -static LIST_HEAD(drivers_head); -static DEFINE_SPINLOCK(drivers_lock); - -/** - * zpool_register_driver() - register a zpool implementation. - * @driver: driver to register - */ -void zpool_register_driver(struct zpool_driver *driver) -{ - spin_lock(&drivers_lock); - atomic_set(&driver->refcount, 0); - list_add(&driver->list, &drivers_head); - spin_unlock(&drivers_lock); -} -EXPORT_SYMBOL(zpool_register_driver); - -/** - * zpool_unregister_driver() - unregister a zpool implementation. - * @driver: driver to unregister. - * - * Module usage counting is used to prevent using a driver - * while/after unloading, so if this is called from module - * exit function, this should never fail; if called from - * other than the module exit function, and this returns - * failure, the driver is in use and must remain available. - */ -int zpool_unregister_driver(struct zpool_driver *driver) -{ - int ret =3D 0, refcount; - - spin_lock(&drivers_lock); - refcount =3D atomic_read(&driver->refcount); - WARN_ON(refcount < 0); - if (refcount > 0) - ret =3D -EBUSY; - else - list_del(&driver->list); - spin_unlock(&drivers_lock); - - return ret; -} -EXPORT_SYMBOL(zpool_unregister_driver); - -/* this assumes @type is null-terminated. */ -static struct zpool_driver *zpool_get_driver(const char *type) -{ - struct zpool_driver *driver; - - spin_lock(&drivers_lock); - list_for_each_entry(driver, &drivers_head, list) { - if (!strcmp(driver->type, type)) { - bool got =3D try_module_get(driver->owner); - - if (got) - atomic_inc(&driver->refcount); - spin_unlock(&drivers_lock); - return got ? driver : NULL; - } - } - - spin_unlock(&drivers_lock); - return NULL; -} - -static void zpool_put_driver(struct zpool_driver *driver) -{ - atomic_dec(&driver->refcount); - module_put(driver->owner); -} - -/** - * zpool_has_pool() - Check if the pool driver is available - * @type: The type of the zpool to check (e.g. zsmalloc) - * - * This checks if the @type pool driver is available. This will try to lo= ad - * the requested module, if needed, but there is no guarantee the module w= ill - * still be loaded and available immediately after calling. If this retur= ns - * true, the caller should assume the pool is available, but must be prepa= red - * to handle the @zpool_create_pool() returning failure. However if this - * returns false, the caller should assume the requested pool type is not - * available; either the requested pool type module does not exist, or cou= ld - * not be loaded, and calling @zpool_create_pool() with the pool type will - * fail. - * - * The @type string must be null-terminated. - * - * Returns: true if @type pool is available, false if not - */ -bool zpool_has_pool(char *type) -{ - struct zpool_driver *driver =3D zpool_get_driver(type); - - if (!driver) { - request_module("zpool-%s", type); - driver =3D zpool_get_driver(type); - } - - if (!driver) - return false; - - zpool_put_driver(driver); - return true; -} -EXPORT_SYMBOL(zpool_has_pool); - -/** - * zpool_create_pool() - Create a new zpool - * @type: The type of the zpool to create (e.g. zsmalloc) - * @name: The name of the zpool (e.g. zram0, zswap) - * @gfp: The GFP flags to use when allocating the pool. - * - * This creates a new zpool of the specified type. The gfp flags will be - * used when allocating memory, if the implementation supports it. If the - * ops param is NULL, then the created zpool will not be evictable. - * - * Implementations must guarantee this to be thread-safe. - * - * The @type and @name strings must be null-terminated. - * - * Returns: New zpool on success, NULL on failure. - */ -struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t = gfp) -{ - struct zpool_driver *driver; - struct zpool *zpool; - - pr_debug("creating pool type %s\n", type); - - driver =3D zpool_get_driver(type); - - if (!driver) { - request_module("zpool-%s", type); - driver =3D zpool_get_driver(type); - } - - if (!driver) { - pr_err("no driver for type %s\n", type); - return NULL; - } - - zpool =3D kmalloc(sizeof(*zpool), gfp); - if (!zpool) { - pr_err("couldn't create zpool - out of memory\n"); - zpool_put_driver(driver); - return NULL; - } - - zpool->driver =3D driver; - zpool->pool =3D driver->create(name, gfp); - - if (!zpool->pool) { - pr_err("couldn't create %s pool\n", type); - zpool_put_driver(driver); - kfree(zpool); - return NULL; - } - - pr_debug("created pool type %s\n", type); - - return zpool; -} - -/** - * zpool_destroy_pool() - Destroy a zpool - * @zpool: The zpool to destroy. - * - * Implementations must guarantee this to be thread-safe, - * however only when destroying different pools. The same - * pool should only be destroyed once, and should not be used - * after it is destroyed. - * - * This destroys an existing zpool. The zpool should not be in use. - */ -void zpool_destroy_pool(struct zpool *zpool) -{ - pr_debug("destroying pool type %s\n", zpool->driver->type); - - zpool->driver->destroy(zpool->pool); - zpool_put_driver(zpool->driver); - kfree(zpool); -} - -/** - * zpool_get_type() - Get the type of the zpool - * @zpool: The zpool to check - * - * This returns the type of the pool. - * - * Implementations must guarantee this to be thread-safe. - * - * Returns: The type of zpool. - */ -const char *zpool_get_type(struct zpool *zpool) -{ - return zpool->driver->type; -} - -/** - * zpool_malloc() - Allocate memory - * @zpool: The zpool to allocate from. - * @size: The amount of memory to allocate. - * @gfp: The GFP flags to use when allocating memory. - * @handle: Pointer to the handle to set - * @nid: The preferred node id. - * - * This allocates the requested amount of memory from the pool. - * The gfp flags will be used when allocating memory, if the - * implementation supports it. The provided @handle will be - * set to the allocated object handle. The allocation will - * prefer the NUMA node specified by @nid. - * - * Implementations must guarantee this to be thread-safe. - * - * Returns: 0 on success, negative value on error. - */ -int zpool_malloc(struct zpool *zpool, size_t size, gfp_t gfp, - unsigned long *handle, const int nid) -{ - return zpool->driver->malloc(zpool->pool, size, gfp, handle, nid); -} - -/** - * zpool_free() - Free previously allocated memory - * @zpool: The zpool that allocated the memory. - * @handle: The handle to the memory to free. - * - * This frees previously allocated memory. This does not guarantee - * that the pool will actually free memory, only that the memory - * in the pool will become available for use by the pool. - * - * Implementations must guarantee this to be thread-safe, - * however only when freeing different handles. The same - * handle should only be freed once, and should not be used - * after freeing. - */ -void zpool_free(struct zpool *zpool, unsigned long handle) -{ - zpool->driver->free(zpool->pool, handle); -} - -/** - * zpool_obj_read_begin() - Start reading from a previously allocated hand= le. - * @zpool: The zpool that the handle was allocated from - * @handle: The handle to read from - * @local_copy: A local buffer to use if needed. - * - * This starts a read operation of a previously allocated handle. The pass= ed - * @local_copy buffer may be used if needed by copying the memory into. - * zpool_obj_read_end() MUST be called after the read is completed to undo= any - * actions taken (e.g. release locks). - * - * Returns: A pointer to the handle memory to be read, if @local_copy is u= sed, - * the returned pointer is @local_copy. - */ -void *zpool_obj_read_begin(struct zpool *zpool, unsigned long handle, - void *local_copy) -{ - return zpool->driver->obj_read_begin(zpool->pool, handle, local_copy); -} - -/** - * zpool_obj_read_end() - Finish reading from a previously allocated handl= e. - * @zpool: The zpool that the handle was allocated from - * @handle: The handle to read from - * @handle_mem: The pointer returned by zpool_obj_read_begin() - * - * Finishes a read operation previously started by zpool_obj_read_begin(). - */ -void zpool_obj_read_end(struct zpool *zpool, unsigned long handle, - void *handle_mem) -{ - zpool->driver->obj_read_end(zpool->pool, handle, handle_mem); -} - -/** - * zpool_obj_write() - Write to a previously allocated handle. - * @zpool: The zpool that the handle was allocated from - * @handle: The handle to read from - * @handle_mem: The memory to copy from into the handle. - * @mem_len: The length of memory to be written. - * - */ -void zpool_obj_write(struct zpool *zpool, unsigned long handle, - void *handle_mem, size_t mem_len) -{ - zpool->driver->obj_write(zpool->pool, handle, handle_mem, mem_len); -} - -/** - * zpool_get_total_pages() - The total size of the pool - * @zpool: The zpool to check - * - * This returns the total size in pages of the pool. - * - * Returns: Total size of the zpool in pages. - */ -u64 zpool_get_total_pages(struct zpool *zpool) -{ - return zpool->driver->total_pages(zpool->pool); -} - -MODULE_AUTHOR("Dan Streetman "); -MODULE_DESCRIPTION("Common API for compressed memory storage"); diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 153783d49d34..5bf832f9c05c 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include "zpdesc.h" @@ -433,78 +432,6 @@ static void record_obj(unsigned long handle, unsigned = long obj) *(unsigned long *)handle =3D obj; } =20 -/* zpool driver */ - -#ifdef CONFIG_ZPOOL - -static void *zs_zpool_create(const char *name, gfp_t gfp) -{ - /* - * Ignore global gfp flags: zs_malloc() may be invoked from - * different contexts and its caller must provide a valid - * gfp mask. - */ - return zs_create_pool(name); -} - -static void zs_zpool_destroy(void *pool) -{ - zs_destroy_pool(pool); -} - -static int zs_zpool_malloc(void *pool, size_t size, gfp_t gfp, - unsigned long *handle, const int nid) -{ - *handle =3D zs_malloc(pool, size, gfp, nid); - - if (IS_ERR_VALUE(*handle)) - return PTR_ERR((void *)*handle); - return 0; -} -static void zs_zpool_free(void *pool, unsigned long handle) -{ - zs_free(pool, handle); -} - -static void *zs_zpool_obj_read_begin(void *pool, unsigned long handle, - void *local_copy) -{ - return zs_obj_read_begin(pool, handle, local_copy); -} - -static void zs_zpool_obj_read_end(void *pool, unsigned long handle, - void *handle_mem) -{ - zs_obj_read_end(pool, handle, handle_mem); -} - -static void zs_zpool_obj_write(void *pool, unsigned long handle, - void *handle_mem, size_t mem_len) -{ - zs_obj_write(pool, handle, handle_mem, mem_len); -} - -static u64 zs_zpool_total_pages(void *pool) -{ - return zs_get_total_pages(pool); -} - -static struct zpool_driver zs_zpool_driver =3D { - .type =3D "zsmalloc", - .owner =3D THIS_MODULE, - .create =3D zs_zpool_create, - .destroy =3D zs_zpool_destroy, - .malloc =3D zs_zpool_malloc, - .free =3D zs_zpool_free, - .obj_read_begin =3D zs_zpool_obj_read_begin, - .obj_read_end =3D zs_zpool_obj_read_end, - .obj_write =3D zs_zpool_obj_write, - .total_pages =3D zs_zpool_total_pages, -}; - -MODULE_ALIAS("zpool-zsmalloc"); -#endif /* CONFIG_ZPOOL */ - static inline bool __maybe_unused is_first_zpdesc(struct zpdesc *zpdesc) { return PagePrivate(zpdesc_page(zpdesc)); @@ -2248,9 +2175,6 @@ static int __init zs_init(void) { int rc __maybe_unused; =20 -#ifdef CONFIG_ZPOOL - zpool_register_driver(&zs_zpool_driver); -#endif #ifdef CONFIG_COMPACTION rc =3D set_movable_ops(&zsmalloc_mops, PGTY_zsmalloc); if (rc) @@ -2262,9 +2186,6 @@ static int __init zs_init(void) =20 static void __exit zs_exit(void) { -#ifdef CONFIG_ZPOOL - zpool_unregister_driver(&zs_zpool_driver); -#endif #ifdef CONFIG_COMPACTION set_movable_ops(NULL, PGTY_zsmalloc); #endif diff --git a/tools/testing/selftests/zram/README b/tools/testing/selftests/= zram/README index 110b34834a6f..82921c75681c 100644 --- a/tools/testing/selftests/zram/README +++ b/tools/testing/selftests/zram/README @@ -14,7 +14,6 @@ Statistics for individual zram devices are exported throu= gh sysfs nodes at Kconfig required: CONFIG_ZRAM=3Dy CONFIG_CRYPTO_LZ4=3Dy -CONFIG_ZPOOL=3Dy CONFIG_ZSMALLOC=3Dy =20 ZRAM Testcases --=20 2.51.0 From nobody Fri Oct 3 14:29:31 2025 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 889FB32A3D1 for ; Fri, 29 Aug 2025 16:22:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756484558; cv=none; b=QzK8hs+bkj0ignHntK25gzjbEGfETximr0+Ot0/1pzVDC6ZjiYd8TEtjhHc1Ml95T8VfgNEGr1NsZsn8MSNmnTj7/aOKcLOiPL46RN/SSYgtwKE3IHpP8cFXE9sdZ5A90NefVh3hfp+X5yqIzbseIIgM2BTb/41jWwETZSysmQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756484558; c=relaxed/simple; bh=8TDmGbYj0UyXVqHo1ZkM6vIV2MsOIIoNJgd3bubtTaw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DN9bVj37x0cVQbybWq/Uk3SHj3YzZOgCfCRpQhFP8yym3x6PjEU67qbriWoBgriVV86FmMDFU6LRxvJ70qsOIE0kgzTW6A+z5+jzNYaWOuSBJn8HpFv4mtpdSVkOnsOlEZJx8Bq/ZALLFvs2muBiQUU4UCl/NLoa14EkE51Pr/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b=T7oyloWL; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg-org.20230601.gappssmtp.com header.i=@cmpxchg-org.20230601.gappssmtp.com header.b="T7oyloWL" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-45b77f59bd8so11576685e9.0 for ; Fri, 29 Aug 2025 09:22:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1756484554; x=1757089354; darn=vger.kernel.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; bh=vO3fZfxsRC3wtDo2pgMFNvnPCWzRCeuSrbJiTbqH9x8=; b=T7oyloWLgl5WRMn72ha/BuiW+wHgeTQWoy9FRLHE5/Jd6wRYh4I5wIEV/qfg7lLnm8 dX2LFftgroiy2+9WYsExzaG0BUO5qvPmGNIbskCJjt7vyyl3esYKcwZNqHDT2mk8YDSX 2UkpbyuRSuzKrfCXdsV8R9qcFY7ErviLTQw3b30GtVmdCJ1LGuLfgKj863hhcbjmZu5C 9UHJG7lSVU5oPmBcb9/7eAG2y6ZBbM1NHAf/J3k4eJNmEtD7yT1l9NpB9Q8UGcDDJxFG Wb9COQBjfhD83xee5aStPesBkQ1gqdhItehQ8vv/BSqc4tmpIb2pVeKwwzOUhflvLL++ Twlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756484554; x=1757089354; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vO3fZfxsRC3wtDo2pgMFNvnPCWzRCeuSrbJiTbqH9x8=; b=WACoK1492F78WG8IRLztVMLAerk48jcIvHMYRjo2QclAvfg0v+mWVTqGOjg4Kk2XfT UUiHj86pGI57F2+Y0o6jCi/SNI7kYzKExplI+t+yWiHTBX7M5H/IO+4nE1NVRsSDe8AY LTmMhNNK80/VDFWgX1ISazau5pXEyym1rvDAlgQloYX3cvkIs1UyWYaglV6s8eoS+pwm TKTAWJq0+UTqNs1ZssaZAh+Tiu7wywKpPChtEGV281Symc5xPo/+wn1aMYoyy62/cJZJ SZQMw8OjuxqVnPwKTeAkWogZDiLUBTkJBinJPrM8Y+2DIE4YLv+HymSi7hOfDO3QdNps oyhQ== X-Forwarded-Encrypted: i=1; AJvYcCWrQtBtXUPF4uWUmahS5g+Lo50NA30W3ag0klh6clpc+lhBK3hMrhOlvNHsy/LkbK3GMXk3VNqU3E/Vo0k=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1hCfxIDoPUMvhPGkZ7GlSMFT9t5Cmby1aX+UiRzhajfFYbHwE 7KMu8YmrJ+SyU+ZCKptD8gwfeTlubyVrXweB9mVo0nAj1hHLYVxx6fR70uoLUbqSAFVZC8xO84V QrVGll6k= X-Gm-Gg: ASbGnctSn6JIXL5WqLcpqk7Ce3xP9F7MAF9RlUQlKdq2XDiD4MBUkqRYH7CZb86q5Uh MLIRkSAsBctRbqnmvz3uzvbKDJO5d40wNFALI8lbPiwcIPFnfPvpoBUI0nxmAfA256gjlaCAyOt IX8yubiGYGyF4iC0lkC7/nCD66/gWO8T2slnEqngQ3VF2dBqKZ9bluzLSNawth1u86w7lbPGjYO p2GU2hnjj0XMCfc1OwenwkHn/3RKYJgfnIe0U2TpPhPW2roxD7rBj19RK4EacVhP6GwSTIn7aSg JDkjKo215cQMd81QHo+zvv+W2cvnL0L4WQchhAXM5rNfFf4C6uFUMRZTay4b14ZNTvTYJwgUS3T RR/g= X-Google-Smtp-Source: AGHT+IFvxH2wrrQOL8qFClFcMXg7O03uzVqmqAkC2KXtyit1y23oMAaMh5LuPNjzPv7yownc2pnyxA== X-Received: by 2002:a05:600c:8b0a:b0:45b:733b:1feb with SMTP id 5b1f17b1804b1-45b733b214dmr88676045e9.10.1756484553840; Fri, 29 Aug 2025 09:22:33 -0700 (PDT) Received: from localhost ([2620:10d:c092:600::1:954]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-45b7d9548edsm30431075e9.5.2025.08.29.09.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Aug 2025 09:22:32 -0700 (PDT) From: Johannes Weiner To: Andrew Morton Cc: Yosry Ahmed , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] mm: zpdesc: minor naming and comment corrections Date: Fri, 29 Aug 2025 17:15:28 +0100 Message-ID: <20250829162212.208258-4-hannes@cmpxchg.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250829162212.208258-1-hannes@cmpxchg.org> References: <20250829162212.208258-1-hannes@cmpxchg.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" zpdesc is the page descriptor used by the zsmalloc backend allocator, which in turn is used by zswap and zram. The zpool layer is gone. Signed-off-by: Johannes Weiner Acked-by: Nhat Pham Acked-by: Yosry Ahmed --- mm/zpdesc.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/zpdesc.h b/mm/zpdesc.h index 25bf5ea0beb8..b8258dc78548 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0 */ -/* zpdesc.h: zswap.zpool memory descriptor +/* zpdesc.h: zsmalloc pool memory descriptor * * Written by Alex Shi * Hyeonggon Yoo <42.hyeyoo@gmail.com> @@ -11,14 +11,14 @@ #include =20 /* - * struct zpdesc - Memory descriptor for zpool memory. + * struct zpdesc - Memory descriptor for zsmalloc pool memory. * @flags: Page flags, mostly unused by zsmalloc. * @lru: Indirectly used by page migration. * @movable_ops: Used by page migration. - * @next: Next zpdesc in a zspage in zsmalloc zpool. - * @handle: For huge zspage in zsmalloc zpool. + * @next: Next zpdesc in a zspage in zsmalloc pool. + * @handle: For huge zspage in zsmalloc pool. * @zspage: Points to the zspage this zpdesc is a part of. - * @first_obj_offset: First object offset in zsmalloc zpool. + * @first_obj_offset: First object offset in zsmalloc pool. * @_refcount: The number of references to this zpdesc. * * This struct overlays struct page for now. Do not modify without a good @@ -79,8 +79,8 @@ static_assert(sizeof(struct zpdesc) <=3D sizeof(struct pa= ge)); * zpdesc_folio - The folio allocated for a zpdesc * @zp: The zpdesc. * - * Zpdescs are descriptors for zpool memory. The zpool memory itself is - * allocated as folios that contain the zpool objects, and zpdesc uses spe= cific + * Zpdescs are descriptors for zsmalloc memory. The memory itself is alloc= ated + * as folios that contain the zsmalloc objects, and zpdesc uses specific * fields in the first struct page of the folio - those fields are now acc= essed * by struct zpdesc. * --=20 2.51.0