From: sashiko-bot@kernel.org
To: "Sergey Senozhatsky" <senozhatsky@chromium.org>,
"Andrew Morton" <akpm@linux-foundation.org>
Cc: "Nhat Pham" <nphamcs@gmail.com>,
"Yosry Ahmed" <yosry.ahmed@linux.dev>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Brian Geffon" <bgeffon@google.com>,
"Minchan Kim" <minchan@kernel.org>,
"Richard Chang" <richardycc@google.com>,
linux-mm@kvack.org
Subject: Re: [PATCH v2 08/11] zsmalloc: encode 1-based obj_idx so valid obj is never 0
Date: Tue, 10 Nov 2026 18:37:47 +0000 [thread overview]
Message-ID: <sashiko-outbox-207590@kernel.org> (raw)
In-Reply-To: <20261110054836.1515030-9-senozhatsky@chromium.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] zsmalloc: ZS_MIN_ALLOC_SIZE aligns to ZS_SIZE_CLASS_DELTA
instead of ZS_ALIGN
--
commit 0c61b7dd8c43af4f863baff5b649ef0e8a7b35b0
Author: Sergey Senozhatsky <senozhatsky@chromium.org>
zsmalloc: encode 1-based obj_idx so valid obj is never 0
This commit encodes obj_idx + 1 in the object handle so that a valid encoded
object is never 0, and updates ZS_MIN_ALLOC_SIZE so the maximum object index
fits in ZS_OBJ_IDX_MASK.
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index 3a6a7253fd01c..aa436df0cc4da 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
[ ... ]
> @@ -169,9 +170,6 @@
> static_assert(ZS_OBJ_IDX_BITS >= ZS_PAGES_PER_ZSPAGE_BITS,
> "zsmalloc: ZS_MIN_ALLOC_SIZE would exceed ZS_MAX_ALLOC_SIZE");
>
> -/* ZS_MIN_ALLOC_SIZE must be multiple of ZS_ALIGN */
> -#define ZS_MIN_ALLOC_SIZE \
> - MAX(32, (ZS_MAX_PAGES_PER_ZSPAGE << PAGE_SHIFT >> ZS_OBJ_IDX_BITS))
> /* each chunk includes extra space to keep handle */
> #define ZS_MAX_ALLOC_SIZE PAGE_SIZE
>
> @@ -189,6 +187,11 @@ static_assert(ZS_OBJ_IDX_BITS >= ZS_PAGES_PER_ZSPAGE_BITS,
> * (reason above)
> */
> #define ZS_SIZE_CLASS_DELTA (PAGE_SIZE >> CLASS_BITS)
> +#define _ZS_MIN_ALLOC_RAW \
> + DIV_ROUND_UP(ZS_MAX_PAGES_PER_ZSPAGE << PAGE_SHIFT, ZS_OBJ_IDX_MASK)
> +#define ZS_MIN_ALLOC_SIZE \
> + MIN(ZS_MAX_ALLOC_SIZE, \
> + MAX(32UL, ALIGN(_ZS_MIN_ALLOC_RAW, ZS_SIZE_CLASS_DELTA)))
> #define ZS_SIZE_CLASSES (DIV_ROUND_UP(ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE, \
> ZS_SIZE_CLASS_DELTA) + 1)
[Severity: Medium]
Should ZS_MIN_ALLOC_SIZE align _ZS_MIN_ALLOC_RAW to ZS_ALIGN instead of
ZS_SIZE_CLASS_DELTA?
Because _ZS_MIN_ALLOC_RAW uses DIV_ROUND_UP() with a non-zero numerator, it
is always at least 1. On 16KB and 64KB page kernels, ZS_SIZE_CLASS_DELTA is
64 and 256 respectively, so ALIGN(_ZS_MIN_ALLOC_RAW, ZS_SIZE_CLASS_DELTA)
rounds _ZS_MIN_ALLOC_RAW up to 64 or 256 and overrides the 32-byte floor in
MAX(32UL, ...), eliminating small size classes even when ZS_OBJ_IDX_MASK can
index 32-byte objects. As noted in the comment above ZS_SIZE_CLASS_DELTA,
ZS_MIN_ALLOC_SIZE only needs to be a multiple of ZS_ALIGN.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261110054836.1515030-1-senozhatsky@chromium.org?part=8
next prev parent reply other threads:[~2026-11-10 18:37 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-10 5:48 [PATCH v2 00/11] zsmalloc: redesign object alloc API Sergey Senozhatsky
2026-11-10 5:48 ` [PATCH v2 01/11] zram: drop stale comment in write_incompressible_page() Sergey Senozhatsky
2026-11-10 5:48 ` [PATCH v2 02/11] zram: drop get_slot_handle() and set_slot_handle() Sergey Senozhatsky
2026-11-10 5:48 ` [PATCH v2 03/11] zsmalloc: return handle from obj_allocated() Sergey Senozhatsky
2026-11-10 16:28 ` Yosry Ahmed
2026-11-10 17:37 ` Nhat Pham
2026-11-10 5:48 ` [PATCH v2 04/11] zsmalloc: switch handle type to struct zs_handle Sergey Senozhatsky
2026-11-10 16:35 ` Yosry Ahmed
2026-11-11 4:15 ` Sergey Senozhatsky
2026-11-10 17:40 ` Nhat Pham
2026-11-10 5:48 ` [PATCH v2 05/11] zram: check mem_limit before allocating zsmalloc object Sergey Senozhatsky
2026-11-10 18:37 ` sashiko-bot
2026-11-11 4:20 ` Sergey Senozhatsky
2026-11-10 5:48 ` [PATCH v2 06/11] zram: allocate zsmalloc object under slot lock Sergey Senozhatsky
2026-11-10 5:48 ` [PATCH v2 07/11] zswap: do not free the entry if its pool is NULL Sergey Senozhatsky
2026-11-10 16:37 ` Yosry Ahmed
2026-11-10 17:42 ` Nhat Pham
2026-11-10 5:48 ` [PATCH v2 08/11] zsmalloc: encode 1-based obj_idx so valid obj is never 0 Sergey Senozhatsky
2026-11-10 16:44 ` Yosry Ahmed
2026-11-11 4:44 ` Sergey Senozhatsky
2026-11-10 17:57 ` Nhat Pham
2026-11-11 4:45 ` Sergey Senozhatsky
2026-11-10 18:37 ` sashiko-bot [this message]
2026-11-11 4:24 ` Sergey Senozhatsky
2026-11-10 5:48 ` [PATCH v2 09/11] zsmalloc: embed struct zs_handle into zram and zswap entries Sergey Senozhatsky
2026-11-10 16:57 ` Yosry Ahmed
2026-11-10 17:55 ` Nhat Pham
2026-11-10 5:48 ` [PATCH v2 10/11] zsmalloc: fold zs_obj_write() into zs_store() Sergey Senozhatsky
2026-11-10 17:00 ` Yosry Ahmed
2026-11-10 18:01 ` Nhat Pham
2026-11-11 6:05 ` Sergey Senozhatsky
2026-11-10 5:48 ` [PATCH v2 11/11] zsmalloc: populate new zspage outside class->lock in zs_store() Sergey Senozhatsky
2026-11-10 17:03 ` Yosry Ahmed
2026-11-10 18:06 ` Nhat Pham
2026-11-10 16:16 ` [PATCH v2 00/11] zsmalloc: redesign object alloc API Yosry Ahmed
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=sashiko-outbox-207590@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bgeffon@google.com \
--cc=hannes@cmpxchg.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=nphamcs@gmail.com \
--cc=richardycc@google.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=senozhatsky@chromium.org \
--cc=yosry.ahmed@linux.dev \
/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