mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Yosry Ahmed <yosry@kernel.org>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
	 Andrew Morton <akpm@linux-foundation.org>,
	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-kernel@vger.kernel.org, linux-block@vger.kernel.org,
	 linux-mm@kvack.org
Subject: Re: [PATCH v2 08/11] zsmalloc: encode 1-based obj_idx so valid obj is never 0
Date: Wed, 11 Nov 2026 13:44:49 +0900	[thread overview]
Message-ID: <avPyH5Dbb0MI-JXQ@google.com> (raw)
In-Reply-To: <avNJ0p1v6FZ-wnQE@google.com>

On (26/11/10 16:44), Yosry Ahmed wrote:
[..]
> > Store obj_idx + 1 in obj, so that a valid obj is never 0, and adjust
> > ZS_MIN_ALLOC_SIZE so that the largest index still fits.  Unlike a
> > separate tag bit, this doesn't take any bits from obj.  zsmalloc did
> > the same before handles moved to handle_cachep, see
> > commit 67296874eb1c ("staging: zsmalloc: Ensure handle is never 0 on
> > success").
> > 
> > Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> > ---
> >  mm/zsmalloc.c | 19 +++++++++++++------
> >  1 file changed, 13 insertions(+), 6 deletions(-)
> > 
> > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> > index 3a6a7253fd01..aa436df0cc4d 100644
> > --- a/mm/zsmalloc.c
> > +++ b/mm/zsmalloc.c
> > @@ -61,7 +61,8 @@
> >   * Object location (<PFN>, <obj_idx>) is encoded as
> >   * a single (unsigned long) handle value.
> >   *
> > - * Note that object index <obj_idx> starts from 0.
> > + * Note that object index <obj_idx> starts from 0, and is encoded as
> > + * <obj_idx> + 1 so that a valid encoded obj value is never 0.
> 
> Well, this may be a stupid question, but why not make obj_idx start at
> 1?

I didn't write that code!  I just resurrected 67296874eb1c! Just joking.

We use idx to calculate offset, we need it to start from 0:
	off = offset_in_page(class->size * obj_idx)

  reply	other threads:[~2026-11-11  4:44 UTC|newest]

Thread overview: 30+ 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  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 [this message]
2026-11-10 17:57   ` Nhat Pham
2026-11-11  4:45     ` 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-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=avPyH5Dbb0MI-JXQ@google.com \
    --to=senozhatsky@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=bgeffon@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=nphamcs@gmail.com \
    --cc=richardycc@google.com \
    --cc=yosry.ahmed@linux.dev \
    --cc=yosry@kernel.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

all inboxes | Powered by JetHome®