Building the Linux kernel with Clang and LLVM
 help / color / mirror / Atom feed
* [PATCH v2 0/2] mm/zsmalloc: optimize zs_store() fast path
@ 2026-12-02  4:39 Jenhao Chen
  2026-12-02  4:39 ` [PATCH v2 1/2] mm/zsmalloc: outline slow path in zs_store() Jenhao Chen
  2026-12-02  4:39 ` [PATCH v2 2/2] mm/zsmalloc: pass payload location to obj_write() Jenhao Chen
  0 siblings, 2 replies; 3+ messages in thread
From: Jenhao Chen @ 2026-12-02  4:39 UTC (permalink / raw)
  To: Sergey Senozhatsky, Minchan Kim, Andrew Morton
  Cc: linux-mm, linux-kernel, llvm, Johannes Weiner, Yosry Ahmed,
	Nhat Pham, Chengming Zhou, Brian Geffon, minchan, liumartin,
	benwei

This two-patch series optimizes the zs_store() fast path on top of the
stabilized zsmalloc changes in mm-new / next-20261201 (mm tree commit
5973b750e388):

1. Outline zs_store()'s new-zspage allocation path into a 6-arg noinline
   zs_store_slow(), matching free_page_chain().  This keeps alloc_zspage()
   and its zpdescs[] array off the fast path, enables sibling tail calls
   on x86_64, and shrinks zs_store() by 19-73%.

2. Pass size_class and a payload struct obj_loc directly from obj_malloc()
   to obj_write() and mark both __always_inline, eliminating the
   location_to_obj() -> obj_to_location() / class->size * obj_idx /
   ZsHugePage() round-trip and two out-of-line calls per store.

Cumulative results (base -> patch 2; 4K pages, chain size 8):
- arm64  Clang 22 -O2:  -5.2% insns/pair, net .text +858 B
- arm64  Clang 22 AFDO: -6.4% insns/pair, zs_store -56%, net .text +930 B
- x86_64 Clang 22 -O2:  -5.9% insns/pair, -6.0% pair / -7.3% zs_store()
  cycles, -5.0% pool growth, net .text +430 B
- x86_64 Clang 22 AFDO: -6.9% insns/pair, -4.7% pair / -6.9% zs_store()
  cycles, -4.3% pool growth, zs_store -45%, net .text +446 B
- x86_64 GCC 15   -O2:  -4.1% insns/pair, zs_store() cycles neutral,
  -3.1% pool growth, zs_store -56%, net .text +372 B

Verified byte-for-byte read-back via zs_obj_read_sg_begin()/end() across
1,024 regular objects (384..3136 B, including page-spanning slots) plus
4096 B huge objects, and clean builds across default, CONFIG_COMPACTION=n,
and CONFIG_DEBUG_VM=y.

Changes in v2:
- Rebased onto next-20261201 (Sergey's object alloc API redesign and
  Wenchao's ZS_OBJ_CLASS_BITS lockless zs_free()).
- Split into 2 patches separating slow-path outlining from the payload
  location handoff and inlining.
- Outlined the full slow path into a 6-arg noinline zs_store_slow()
  instead of only marking alloc_zspage() noinline.
- Passed size_class and struct obj_loc directly to obj_write() instead of
  relying on compiler CSE across lock calls.
- Dropped __always_inline on obj_free(): on next-20261201, Clang 22
  already inlines obj_free(), while forcing it inline on GCC 15 spills
  handle across _raw_spin_lock and regresses zs_free() (~+5 cycles).
- Added bloat-o-meter / net .text deltas and cold pool growth numbers.
- Link to v1: https://lore.kernel.org/r/20261030121700.260975-1-jenhaochen@google.com

Jenhao Chen (2):
  mm/zsmalloc: outline slow path in zs_store()
  mm/zsmalloc: pass payload location to obj_write()

 mm/zsmalloc.c | 126 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 77 insertions(+), 49 deletions(-)

-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-02  4:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  4:39 [PATCH v2 0/2] mm/zsmalloc: optimize zs_store() fast path Jenhao Chen
2026-12-02  4:39 ` [PATCH v2 1/2] mm/zsmalloc: outline slow path in zs_store() Jenhao Chen
2026-12-02  4:39 ` [PATCH v2 2/2] mm/zsmalloc: pass payload location to obj_write() Jenhao Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox