linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vitaly Wool <vitaly.wool@konsulko.se>
To: Yosry Ahmed <yosry.ahmed@linux.dev>
Cc: linux-mm@kvack.org, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org, Nhat Pham <nphamcs@gmail.com>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Igor Belousov <igor.b@beldev.am>,
	Minchan Kim <minchan@kernel.org>,
	Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: Re: [PATCH v4] mm: add zblock allocator
Date: Wed, 23 Apr 2025 21:53:48 +0200	[thread overview]
Message-ID: <e764d05a-6a83-4563-9f28-3f1a3e28727b@konsulko.se> (raw)
In-Reply-To: <aAdzjdv674Jn6G63@Asmaa.>

On 4/22/25 12:46, Yosry Ahmed wrote:
> I didn't look too closely but I generally agree that we should improve
> zsmalloc where possible rather than add a new allocator. We are trying
> not to repeat the zbud/z3fold or slub/slob stories here. Zsmalloc is
> getting a lot of mileage from both zswap and zram, and is more-or-less
> battle-tested. Let's work toward building upon that instead of starting
> over.

The thing here is, zblock is using a very different approach to small 
object allocation. The idea is: we have an array of descriptors which 
correspond to multi-page blocks divided in chunks of equal size 
(block_size[i]). For each object of size x we find the descriptor n such as:
	block_size[n-1] < n < block_size[n]
and then we store that object in an empty slot in one of the blocks. 
Thus, the density is high, the search is fast (rbtree based) and there 
are no objects spanning over 2 pages, so no extra memcpy involved.

And with the latest zblock, we see that it has a clear advantage in 
performance over zsmalloc, retaining roughly the same allocation density 
for 4K pages and scoring better on 16K pages. E. g. on a kernel compilation:

* zsmalloc/zstd/make -j32 bzImage
	real	8m0.594s
	user	39m37.783s
	sys	8m24.262s
	Zswap:            200600 kB <-- after build completion
	Zswapped:         854072 kB <-- after build completion
	zswpin 309774
	zswpout 1538332

* zblock/zstd/make -j32 bzImage
	real	7m35.546s
	user	38m03.475s
	sys	7m47.407s
	Zswap:            250940 kB <-- after build completion
	Zswapped:         870660 kB <-- after build completion
	zswpin 248606
	zswpout 1277319

So what we see here is that zblock is definitely faster and at least not 
worse with regard to allocation density under heavy load. It has 
slightly worse _idle_ allocation density but since it will quickly catch 
up under load it is not really important. What is important is that its 
characteristics don't deteriorate over time. Overall, zblock is simple 
and efficient and there is /raison d'etre/ for it.

Now, it is indeed possible to partially rework zsmalloc using zblock's 
algorithm but this will be a rather substantial change, equal or bigger 
in effort to implementing the approach described above from scratch (and 
this is what we did), and with such drastic changes most of the testing 
that has been done with zsmalloc would be invalidated, and we'll be out 
in the wild anyway. So even though I see your point, I don't think it 
applies in this particular case.

~Vitaly


  reply	other threads:[~2025-04-23 19:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-12 15:42 Vitaly Wool
2025-04-12 19:25 ` Igor Belousov
2025-04-16 12:09 ` Johannes Weiner
2025-04-16 20:10   ` Vitaly
2025-04-17 14:16     ` Johannes Weiner
2025-04-18  7:43       ` Vitaly Wool
2025-04-18 10:52   ` David Hildenbrand
2025-04-18 10:56     ` Vitaly Wool
2025-04-18 11:03       ` David Hildenbrand
2025-04-22 10:46 ` Yosry Ahmed
2025-04-23 19:53   ` Vitaly Wool [this message]
2025-04-30 12:27     ` Yosry Ahmed
2025-05-01 12:41       ` Vitaly Wool
2025-05-01 23:43         ` Sergey Senozhatsky
2025-05-06 13:04         ` Yosry Ahmed
2025-06-11 17:11           ` Vitaly Wool
2025-05-01 23:49     ` Sergey Senozhatsky
2025-05-03  8:27       ` Vitaly
2025-05-04  9:26 ` Andrew Morton
2025-07-20  2:56 ` Andrew Morton

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=e764d05a-6a83-4563-9f28-3f1a3e28727b@konsulko.se \
    --to=vitaly.wool@konsulko.se \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=igor.b@beldev.am \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=nphamcs@gmail.com \
    --cc=senozhatsky@chromium.org \
    --cc=shakeel.butt@linux.dev \
    --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