From: Sergey Senozhatsky <senozhatsky@chromium.org>
To: Andrew Morton <akpm@linux-foundation.org>,
Yosry Ahmed <yosry.ahmed@linux.dev>,
Nhat Pham <nphamcs@gmail.com>
Cc: 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: [PATCHv2 2/2] zsmalloc: simplify read begin/end logic
Date: Wed, 7 Jan 2026 14:21:45 +0900 [thread overview]
Message-ID: <20260107052145.3586917-2-senozhatsky@chromium.org> (raw)
In-Reply-To: <20260107052145.3586917-1-senozhatsky@chromium.org>
From: Yosry Ahmed <yosry.ahmed@linux.dev>
When we switched from using class->size (for spans detection)
to actual compressed object size, we had to compensate for
the fact that class->size implicitly took inlined handle
into consideration. In fact, instead of adjusting the size
of compressed object (adding handle offset for non-huge size
classes), we can move some lines around and simplify the
code: there are already paths in read_begin/end that compensate
for inlined object handle offset.
Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
---
mm/zsmalloc.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index 119c196a287a..cc3d9501ae21 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -1088,7 +1088,7 @@ void *zs_obj_read_begin(struct zs_pool *pool, unsigned long handle,
off = offset_in_page(class->size * obj_idx);
if (!ZsHugePage(zspage))
- mem_len += ZS_HANDLE_SIZE;
+ off += ZS_HANDLE_SIZE;
if (off + mem_len <= PAGE_SIZE) {
/* this object is contained entirely within a page */
@@ -1110,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);
@@ -1133,11 +1130,9 @@ void zs_obj_read_end(struct zs_pool *pool, unsigned long handle,
off = offset_in_page(class->size * obj_idx);
if (!ZsHugePage(zspage))
- mem_len += ZS_HANDLE_SIZE;
+ off += ZS_HANDLE_SIZE;
if (off + mem_len <= PAGE_SIZE) {
- if (!ZsHugePage(zspage))
- off += ZS_HANDLE_SIZE;
handle_mem -= off;
kunmap_local(handle_mem);
}
--
2.52.0.351.gbe84eed79e-goog
next prev parent reply other threads:[~2026-01-07 5:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-07 5:21 [PATCHv2 1/2] zsmalloc: use actual object size to detect spans Sergey Senozhatsky
2026-01-07 5:21 ` Sergey Senozhatsky [this message]
2026-01-07 18:17 ` [PATCHv2 2/2] zsmalloc: simplify read begin/end logic Andrew Morton
2026-01-08 1:14 ` Sergey Senozhatsky
2026-01-07 19:03 ` Yosry Ahmed
2026-01-08 1:17 ` Sergey Senozhatsky
2026-01-07 18:57 ` [PATCHv2 1/2] zsmalloc: use actual object size to detect spans 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=20260107052145.3586917-2-senozhatsky@chromium.org \
--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