linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Yosry Ahmed <yosry.ahmed@linux.dev>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Nhat Pham <nphamcs@gmail.com>, Minchan Kim <minchan@kernel.org>,
	 Johannes Weiner <hannes@cmpxchg.org>,
	Brian Geffon <bgeffon@google.com>,
	linux-kernel@vger.kernel.org,  linux-mm@kvack.org
Subject: Re: [PATCH] zsmalloc: use actual object size to detect spans
Date: Wed, 7 Jan 2026 09:59:30 +0900	[thread overview]
Message-ID: <og2yztajena3ywyvus6xgc5vlrrecjaynyezygpsrt64kjkqlv@agceajv57eet> (raw)
In-Reply-To: <qh2p3k5c2ulb5g2zmckhrm4o2eoruatb5lnumkrwrvmsxwcn3s@nh5vx4kjn5in>

On (26/01/07 00:23), Yosry Ahmed wrote:
> Instead of modifying mem_len, can we modify 'off' like zs_obj_write()
> and zs_obj_read_end()? I think this can actually be done as a prequel to
> this patch. Arguably, it makes more sense as we avoid unnecessarily
> copying the handle (completely untested):
> 
> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
> index 5bf832f9c05c..48c288da43b8 100644
> --- a/mm/zsmalloc.c
> +++ b/mm/zsmalloc.c
> @@ -1087,6 +1087,9 @@ void *zs_obj_read_begin(struct zs_pool *pool, unsigned long handle,
>         class = zspage_class(pool, zspage);
>         off = offset_in_page(class->size * obj_idx);
> 
> +       if (!ZsHugePage(zspage))
> +               off += ZS_HANDLE_SIZE;
> +
>         if (off + class->size <= PAGE_SIZE) {
>                 /* this object is contained entirely within a page */
>                 addr = kmap_local_zpdesc(zpdesc);
> @@ -1107,9 +1110,6 @@ void *zs_obj_read_begin(struct zs_pool *pool, unsigned long handle,
>                                  0, sizes[1]);
>         }
> 
> -       if (!ZsHugePage(zspage))
> -               addr += ZS_HANDLE_SIZE;
> -
>         return addr;
>  }
>  EXPORT_SYMBOL_GPL(zs_obj_read_begin);
> @@ -1129,9 +1129,10 @@ void zs_obj_read_end(struct zs_pool *pool, unsigned long handle,
>         class = zspage_class(pool, zspage);
>         off = offset_in_page(class->size * obj_idx);
> 
> +       if (!ZsHugePage(zspage))
> +               off += ZS_HANDLE_SIZE;
> +
>         if (off + class->size <= PAGE_SIZE) {
> -               if (!ZsHugePage(zspage))
> -                       off += ZS_HANDLE_SIZE;
>                 handle_mem -= off;
>                 kunmap_local(handle_mem);
>         }
> 
> ---
> Does this work?

Sounds interesting.  Let me try it out.

> > +
> > +	if (off + mem_len <= PAGE_SIZE) {
> >  		/* this object is contained entirely within a page */
> >  		addr = kmap_local_zpdesc(zpdesc);
> >  		addr += off;
> 
> In the else case below (spanning object), should we also use mem_len
> instead of class->size to determine the copy size?

Good catch.

> > @@ -1115,7 +1119,7 @@ void *zs_obj_read_begin(struct zs_pool *pool, unsigned long handle,
> >  EXPORT_SYMBOL_GPL(zs_obj_read_begin);
> >  
> >  void zs_obj_read_end(struct zs_pool *pool, unsigned long handle,
> > -		     void *handle_mem)
> > +		     size_t mem_len, void *handle_mem)
> >  {
> >  	struct zspage *zspage;
> >  	struct zpdesc *zpdesc;
> > @@ -1129,7 +1133,11 @@ void zs_obj_read_end(struct zs_pool *pool, unsigned long handle,
> >  	class = zspage_class(pool, zspage);
> >  	off = offset_in_page(class->size * obj_idx);
> >  
> > -	if (off + class->size <= PAGE_SIZE) {
> > +	/* Normal classes have inlined handle */
> > +	if (!ZsHugePage(zspage))
> > +		mem_len += ZS_HANDLE_SIZE;
> > +
> > +	if (off + mem_len <= PAGE_SIZE) {
> >  		if (!ZsHugePage(zspage))
> >  			off += ZS_HANDLE_SIZE;
> 
> With the proposed prequel patch, I think we won't need to handle
> ZS_HANDLE_SIZE twice here. WDYT? Did I miss sth?

Let me look more closely.


  reply	other threads:[~2026-01-07  0:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-06  4:25 Sergey Senozhatsky
2026-01-07  0:23 ` Yosry Ahmed
2026-01-07  0:59   ` Sergey Senozhatsky [this message]
2026-01-07  1:37     ` Sergey Senozhatsky
2026-01-07  1:56       ` Yosry Ahmed
2026-01-07  2:06         ` Sergey Senozhatsky
2026-01-07  2:10           ` Yosry Ahmed
2026-01-07  2:20             ` Sergey Senozhatsky
2026-01-07  2:22               ` Sergey Senozhatsky
2026-01-07  5:19               ` Yosry Ahmed
2026-01-07  5:30                 ` Sergey Senozhatsky
2026-01-07  7:12                   ` Sergey Senozhatsky
2026-01-07  3:03             ` Sergey Senozhatsky
2026-01-07  5:22               ` Yosry Ahmed
2026-01-07  5:38                 ` Sergey Senozhatsky

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=og2yztajena3ywyvus6xgc5vlrrecjaynyezygpsrt64kjkqlv@agceajv57eet \
    --to=senozhatsky@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=bgeffon@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=nphamcs@gmail.com \
    --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