mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Harry Yoo <harry@kernel.org>, Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Hao Li <hao.li@linux.dev>, Christoph Lameter <cl@gentwo.org>,
	 David Rientjes <rientjes@google.com>,
	 Roman Gushchin <roman.gushchin@linux.dev>,
	 Geert Uytterhoeven <geert@linux-m68k.org>,
	Conor Dooley <conor@kernel.org>,
	 Damien Le Moal <dlemoal@kernel.org>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org,
	Alexander Potapenko <glider@google.com>,
	 Andrey Konovalov <andreyknvl@gmail.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	 Vincenzo Frascino <vincenzo.frascino@arm.com>,
	kasan-dev@googlegroups.com,
	 "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Subject: [PATCH v4 00/10] replace CONFIG_SLUB_TINY with a slab_tiny boot parameter
Date: Mon, 16 Nov 2026 07:47:08 +0100	[thread overview]
Message-ID: <20261116-slub_tiny_rework-v4-0-227a4b3636a5@kernel.org> (raw)

CONFIG_SLUB_TINY was introduced to help tiny systems migrate away from
the SLOB implementation so it could be removed. Its main purpose has
been to disable all forms of percpu object caching (cpu slabs back then,
now sheaves), and being a compile-time config option, some extra minor
saving were achieved by code elimination or more agressive merging of
caches with reclaimable and non-reclaimable objects (keeping those
separate helps reduce high-order page fragmentation but not memory
footprint).

However being a config option brings issues such as incompatibility with
other options that has caused troubles in the past and Linus argued for
removing it [1]. Moreover, there is a use case for having full-blown
scalable implementation enabled and being able to disable it with a
boot-time rather than compile-time decision. That use case is the kdump
kernel which shares the same vmlinux but wants to minimize the memory
overhead (which has to be pre-reserved from the production kernel) and
does not mind reduced scalability.

Thus this series reworks the CONFIG_SLUB_TINY to be controlled by a
variable set by a boot-time parameter. The config option itself is
deprecated and only sets the default value of the variable, and all its
interactions with other config options are removed.

The conversion builds mainly on the fact that most SLUB_TINY specific
paths to avoiding percpu object caching are shared with slab_debug
handling, except doing any actual debugging checks.

Thus introduce slab_debug=N (for No-op) option to allow using the
slab_debug checks directly, and extract the underlying static key
handling from CONFIG_SLUB_DEBUG only scope. The decision to create
separate kmalloc-rcl caches is also made to be boot-time.

The parts of CONFIG_SLUB_TINY that can't be transformed to a boot-time
decision are related to dead code elimination and fast path inlining,
and ignoring SLAB_NO_MERGE for performance purposes (currently used in
networking). Those lost memory saving should be all relatively minor
compared to the savings from avoiding percpu caching.

To sum up, after this series:

- CONFIG_SLUB_TINY is a deprecated option that has no interaction with
  other options and only controls the default behavior.

- New slab_tiny boot parameter controls the functionality (and can
  override CONFIG_SLUB_TINY in both directions).

- slab_debug=N can effectively achieve most of slab_tiny and on a
  per-cache basis

- the implementation is simpler with many ifdefs removed

To verify, slab usage was measured from /proc/meminfo after a virtme-ng
boot with 16 cpus and CONFIG_SLUB_TINY enabled.

- before the series: 27700 kB

- after the series: 29804 kB

The difference turns out to be due to last patch making CONFIG_SLUB_TINY
stop blocking several options, but real tiny systems can still disable
those.

- SYSFS support can be disabled globally. When manually disabling it for
  slab only:  28992 kB

- Disabling CONFIG_SLUB_DEBUG on top: 28696 kB

- Disabling KVFREE_RCU_BATCHED on top:  27624 kB

Thus it's possible to achieve the same slab memory footprint with
slab_tiny. One caveat is that disabling KVFREE_RCU_BATCHED is now only
possible by selecting tiny rcu which means CONFIG_SMP=n. I attempted to
make rcu batching boot-time as well, but turns out it's not possible
anymore to switch to call_rcu() with kvfree_rcu_cb because struct
kvfree_rcu_head is now reduced compared to the full rcu_head.

In case some small (but SMP) systems notice this as a regression, we can
make KVFREE_RCU_BATCHED configurable, or come up with some other
solution.

[1] https://lore.kernel.org/all/CAHk-=wh-k04MsoEC0SGKff2Snm6bBF_e+0pHOKwaWv4umZ_SnQ@mail.gmail.com/

Signed-off-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
---
Changes in v4:
- Collect review tags, thanks!
- Fix missing migrate_enable() in the kasan test (Harry, sashiko)
- Handle create_unique_id() properly (sashiko)
- Drop SLAB_RECLAIM_ACCOUNT on cache creation with slab_tiny_enabled,
  achieving full parity with handling pre-series.
- Add memory footprint measurements to the cover letter (Harry)
- Link to v3: https://patch.msgid.link/20261105-slub_tiny_rework-v3-0-0484ce59eabb@kernel.org

Changes in v3:
- Rebase to v7.4-rc1
- Add SLAB_DEBUG_NOOP to SLAB_MERGE_SAME (sashiko)
- Prevent premature slab free in slab and kasan kunit tests by new
  patches 1 and 2 (sashiko)
- Link to v2: https://patch.msgid.link/20261024-slub_tiny_rework-v2-0-bf1419ab5ffd@kernel.org

Changes in v2:
- Rebase to current mainline (with slab/for-7.4 merged)
- Stop triggering nohash pointers due to slab_debug=N (Harry)
- Stop preventing slab merging dues to SLAB_DEBUG_NOOP (Harry)
- Link to v1: https://patch.msgid.link/20260923-slub_tiny_rework-v1-0-a0e66d536eb5@kernel.org

---
Vlastimil Babka (SUSE) (10):
      slab, kunit: pin test slabs by an extra allocation
      kasan, kunit: pin test slabs by an extra allocation
      mm, slab: refactor slab_min/max_order handling
      mm, slab: introduce slab_debug=N
      mm, slab: rework KMALLOC_RECLAIM handling of SLUB_TINY
      mm, slab: make SLUB_TINY handling dynamic for sizing decisions
      mm, slab: convert CONFIG_SLUB_TINY checks to kmem_cache_debug()
      mm, slab: remove remaining compile-time checks for CONFIG_SLUB_TINY
      mm, slab: add slab_tiny boot param
      mm, slab: deprecate CONFIG_SLUB_TINY and reduce its Kconfig effects

 Documentation/admin-guide/kernel-parameters.txt |   4 +
 Documentation/admin-guide/mm/slab.rst           |  18 ++-
 include/linux/slab.h                            |  17 +--
 lib/Kconfig.kasan                               |   2 +-
 lib/tests/slub_kunit.c                          |  36 ++++-
 mm/Kconfig                                      |  16 +--
 mm/Kconfig.debug                                |   2 +-
 mm/kasan/kasan_test_c.c                         |  25 +++-
 mm/slab.h                                       |  32 ++---
 mm/slab_common.c                                |  28 ++--
 mm/slub.c                                       | 176 ++++++++++++------------
 11 files changed, 207 insertions(+), 149 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20260911-slub_tiny_rework-8f2634dd17a7


             reply	other threads:[~2026-11-16  6:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  6:47 Vlastimil Babka (SUSE) [this message]
2026-11-16  6:47 ` [PATCH v4 01/10] slab, kunit: pin test slabs by an extra allocation Vlastimil Babka (SUSE)
2026-11-16  6:47 ` [PATCH v4 02/10] kasan, " Vlastimil Babka (SUSE)
2026-11-16  6:47 ` [PATCH v4 03/10] mm, slab: refactor slab_min/max_order handling Vlastimil Babka (SUSE)
2026-11-16  6:47 ` [PATCH v4 04/10] mm, slab: introduce slab_debug=N Vlastimil Babka (SUSE)
2026-11-16  6:47 ` [PATCH v4 05/10] mm, slab: rework KMALLOC_RECLAIM handling of SLUB_TINY Vlastimil Babka (SUSE)
2026-11-16  6:47 ` [PATCH v4 06/10] mm, slab: make SLUB_TINY handling dynamic for sizing decisions Vlastimil Babka (SUSE)
2026-11-16  6:47 ` [PATCH v4 07/10] mm, slab: convert CONFIG_SLUB_TINY checks to kmem_cache_debug() Vlastimil Babka (SUSE)
2026-11-16  6:47 ` [PATCH v4 08/10] mm, slab: remove remaining compile-time checks for CONFIG_SLUB_TINY Vlastimil Babka (SUSE)
2026-11-16  6:47 ` [PATCH v4 09/10] mm, slab: add slab_tiny boot param Vlastimil Babka (SUSE)
2026-11-16  6:47 ` [PATCH v4 10/10] mm, slab: deprecate CONFIG_SLUB_TINY and reduce its Kconfig effects Vlastimil Babka (SUSE)

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=20261116-slub_tiny_rework-v4-0-227a4b3636a5@kernel.org \
    --to=vbabka@kernel.org \
    --cc=andreyknvl@gmail.com \
    --cc=cl@gentwo.org \
    --cc=conor@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=dvyukov@google.com \
    --cc=geert@linux-m68k.org \
    --cc=glider@google.com \
    --cc=hao.li@linux.dev \
    --cc=harry@kernel.org \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=ryabinin.a.a@gmail.com \
    --cc=vincenzo.frascino@arm.com \
    /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®