The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v6 0/4] mm/zsmalloc: reduce lock contention in zs_free()
@ 2026-06-26  1:49 Wenchao Hao
  2026-06-26  1:50 ` [PATCH v6 1/4] mm/zsmalloc: encode class index in obj value for lockless class lookup Wenchao Hao
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Wenchao Hao @ 2026-06-26  1:49 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel, linux-mm, Minchan Kim,
	Sergey Senozhatsky
  Cc: Nhat Pham, Joshua Hahn, Barry Song, Wenchao Hao

From: Wenchao Hao <haowenchao@xiaomi.com>

This series reduces lock contention in zs_free(), which dominates the
unmap path under memory pressure on Android (LMK kills) and on x86
servers running zswap-heavy workloads.

The current zs_free() takes pool->lock (rwlock, read side) just to
look up the size_class for a handle, then takes class->lock and holds
it across __free_zspage() which can call into the buddy allocator and
acquire zone->lock.  Two costs follow:

  * pool->lock reader-counter cacheline bouncing among concurrent
    zs_free() callers.
  * class->lock held across folio_put(), so any zone->lock wait
    fans out to every other zs_free() on the same class.

The series tackles both:

  Patch 1: encode size_class index into obj alongside PFN and obj_idx,
           so zs_free() can locate the class without pool->lock.
  Patch 2: drop pool->lock from zs_free() on 64-bit; 32-bit unchanged.
  Patch 3: move zspage page-freeing out of class->lock.
  Patch 4: document the three free_zspage helper variants that result
           from the split in patch 3.

Performance results:

Test: each process independently mmap 256MB, write data, madvise
MADV_PAGEOUT to swap out via zram (lzo-rle), then concurrent munmap.

Raspberry Pi 4B (4-core ARM64 Cortex-A72):

  mode        Base       Patched     Speedup
  single      59.0ms     56.0ms      1.05x
  multi 2p    94.6ms     66.7ms      1.42x
  multi 4p    202.9ms    110.6ms     1.83x

x86 (20-core Intel i7-12700, 16 concurrent processes):

  mode        Base       Patched     Speedup
  single      11.7ms     9.8ms       1.19x
  multi 2p    24.1ms     17.2ms      1.40x
  multi 4p    63.0ms     45.3ms      1.39x

[1] https://lore.kernel.org/linux-mm/20260508061910.3882831-1-haowenchao@xiaomi.com/
[2] https://lore.kernel.org/linux-mm/20260527115930.3138213-1-haowenchao@xiaomi.com/
[3] https://lore.kernel.org/linux-mm/20260605084242.1549811-1-haowenchao22@gmail.com/
[4] https://lore.kernel.org/linux-mm/20260609113520.3507783-1-haowenchao22@gmail.com/
[5] https://lore.kernel.org/all/20260616031309.3036234-1-haowenchao22@gmail.com/

Changes since v5:
- 2/4: rename obj_handle_class_lock() to obj_class_get_and_lock().
- Pick up Reviewed-by from Barry Song on 2/4, 3/4, 4/4.

Changes since v4:
- 1/4: rename macros to make their intent clearer, following the
  kernel's *_BITS convention (Nhat Pham, Barry Song).
- 3/4: drop the unused pool argument from __free_zspage_lockless().

Changes since v3:
- 1/4: gate ZS_OBJ_CLASS_BITS on a new spare-bit check so unsuitable
  configs (e.g. UML, no sparsemem) fall back to plain obj layout
  instead of breaking the build.  (sashiko AI review)
- 2/4: annotate handle_to_obj()/record_obj() with READ_ONCE/WRITE_ONCE
  to silence KCSAN; sync the #if predicate with patch 1.  (sashiko AI review)
- 4/4: clarify when async_free_zspage() runs; pick up Reviewed-by.  (Nhat Pham)
- Drop Reviewed-by from Nhat Pham on 1/4 and 2/4: substantial logic
  changes since v3, please re-review.

Changes since v2:
- 3/4: drop likely() hint and tidy up else-branch braces, per review
  nits from Nhat Pham and Joshua Hahn.
- 4/4 (new): document free_zspage helper variants in a single comment
  block, per Nhat Pham.
- Pick up Reviewed-by tags from Nhat Pham (1/4, 2/4, 3/4) and
  Joshua Hahn (3/4).
- Fix patch 1/4 and 2/4 From: to match Signed-off-by, per Barry Song.

Changes since v1:
- Rename obj-encoding macros for clarity.
- Make 32-bit / 64-bit handling transparent at call sites
  (no #ifdef in callers).
- Extract a helper to keep zs_free() unified.

Wenchao Hao (3):
  mm/zsmalloc: encode class index in obj value for lockless class lookup
  mm/zsmalloc: drop pool->lock from zs_free on 64-bit systems
  mm/zsmalloc: document free_zspage helper variants

Xueyuan Chen (1):
  mm/zsmalloc: drop class lock before freeing zspage

 mm/zsmalloc.c | 225 ++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 190 insertions(+), 35 deletions(-)

--
2.34.1

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

end of thread, other threads:[~2026-07-07  7:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-26  1:49 [PATCH v6 0/4] mm/zsmalloc: reduce lock contention in zs_free() Wenchao Hao
2026-06-26  1:50 ` [PATCH v6 1/4] mm/zsmalloc: encode class index in obj value for lockless class lookup Wenchao Hao
2026-06-26  1:50 ` [PATCH v6 2/4] mm/zsmalloc: drop pool->lock from zs_free on 64-bit systems Wenchao Hao
2026-06-30  2:50   ` Andrew Morton
2026-06-26  1:50 ` [PATCH v6 3/4] mm/zsmalloc: drop class lock before freeing zspage Wenchao Hao
2026-06-26  1:50 ` [PATCH v6 4/4] mm/zsmalloc: document free_zspage helper variants Wenchao Hao
2026-06-28  4:36 ` [PATCH v6 0/4] mm/zsmalloc: reduce lock contention in zs_free() Andrew Morton
2026-07-07  7:18 ` Sergey Senozhatsky

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