Skip to content

stackdepot: store compressed frames in stack records

Matt Fleming linux-mm lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v3 Latest10 patches 0 repliesNew

Changes in v3 from the cover letter

- Drop the trie backend, the stackdepot.trie_enabled boot parameter and the trie KUnit tests.
- Drop STACK_DEPOT_FLAG_COUNTABLE. page_owner reads traces with stack_depot_fetch_into() instead.
- Remove stack_depot_fetch() now that it has no users.
- stack_depot_print() and stack_depot_snprint() decompress one frame at a time instead of copying 16-frame chunks.
- Store compressed frames directly in hash records, using the u16 size and u16 flags header layout from v2's COUNTABLE patch.
- The GDB helper decodes compressed frames instead of rejecting trie handles.
- v2's patch 1 landed as 8f56ea8e0706 ("stackdepot: stop preallocating after the final pool").

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10stackdepot: add caller-owned stack trace fetchinginclude/linux/stackdepot.h lib/Kconfig.debug lib/stackdepot.c +2 more+171 -00 replies
2/10mm/kmemleak: use stack_depot_fetch_into() for leak reportsmm/kmemleak.c+2 -20 replies
3/10kmsan: use stack_depot_fetch_into() for origin reportsmm/kmsan/kmsan_test.c mm/kmsan/report.c+18 -140 replies
4/10mm/slub: use stack_depot_fetch_into() for owner trackingmm/slub.c+7 -50 replies
5/10drm/locking: print deadlock backtraces with stack_depot_snprint()drivers/gpu/drm/drm_modeset_lock.c+1 -40 replies
6/10mm/page_owner: Read stack traces with stack_depot_fetch_into()mm/page_owner.c+4 -40 replies
7/10stackdepot: Remove stack_depot_fetch()include/linux/stackdepot.h lib/stackdepot.c lib/tests/stackdepot_kunit.c+66 -490 replies
8/10stackdepot: add architecture hooks for compact frame storagearch/arm64/include/asm/stackdepot.h arch/um/include/asm/Kbuild arch/x86/include/asm/stackdepot.h +3 more+181 -00 replies
9/10stackdepot: Store compressed frames in stack recordsinclude/linux/stackdepot.h lib/stackdepot.c lib/tests/stackdepot_kunit.c+199 -130 replies
10/10scripts/gdb: Decode compressed stack depot framesscripts/gdb/linux/constants.py.in scripts/gdb/linux/stackdepot.py+24 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 00/10] stackdepot: store compressed frames in stack records

From: Matt Fleming <[email protected]>

Hi,

Cloudflare runs KASAN on pre-production servers, and on some of them stack depot keeps running out of pools even with stack_depot_max_pools raised to 65,536. Once the depot is full, new persistent traces get no handle and later KASAN reports lose the allocation and free history.

v2 of this series [1] tackled that with a trie that shares common frame prefixes. Marco asked how much of the saving came from compressed frames alone [2]. It turns out we can get a decent saving with just frame compression and none of the trie complexity.

When every frame of a persistent record can be compressed with the arch hooks, the record stores 32-bit frames instead of unsigned longs. Evictable records are always allocated at maximum size, so they stay uncompressed.

On our production KASAN hosts this reduced stack depot pools per 1000 stacks by 41.5% on x86-64 and 27.1% on arm64. arm64 saves less because we run a lot of BPF programs, and their code lives outside the +/-2 GiB range around _text that can be compressed.

Compressed records aren't contiguous unsigned long arrays, so callers can no longer borrow stack depot's storage. Patches 1-7 move every stack_depot_fetch() user to stack_depot_fetch_into() or the print helpers and then remove stack_depot_fetch(). Patch 8 adds the arch hooks, patch 9 stores compressed frames, and patch 10 teaches the GDB helper to decode them.

Changes in v3:
- Drop the trie backend, the stackdepot.trie_enabled boot parameter and the trie KUnit tests.
- Drop STACK_DEPOT_FLAG_COUNTABLE. page_owner reads traces with stack_depot_fetch_into() instead.
- Remove stack_depot_fetch() now that it has no users.
- stack_depot_print() and stack_depot_snprint() decompress one frame at a time instead of copying 16-frame chunks.
- Store compressed frames directly in hash records, using the u16 size and u16 flags header layout from v2's COUNTABLE patch.
- The GDB helper decodes compressed frames instead of rejecting trie handles.
- v2's patch 1 landed as 8f56ea8e0706 ("stackdepot: stop preallocating after the final pool").

Thanks to Caleb, who wrote v1 and v2.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/r/CANpmjNMP=NdD8ZE9rPwikUBcLwc8V=J648X05YGPn41yAZ5hmw@mail.gmail.com/

Caleb Kan (6):
stackdepot: add caller-owned stack trace fetching mm/kmemleak: use stack_depot_fetch_into() for leak reports
kmsan: use stack_depot_fetch_into() for origin reports mm/slub: use stack_depot_fetch_into() for owner tracking drm/locking: print deadlock backtraces with stack_depot_snprint()
stackdepot: add architecture hooks for compact frame storage

Matt Fleming (4):
mm/page_owner: Read stack traces with stack_depot_fetch_into()
stackdepot: Remove stack_depot_fetch()
stackdepot: Store compressed frames in stack records scripts/gdb: Decode compressed stack depot frames

 arch/arm64/include/asm/stackdepot.h |  37 ++++
 arch/um/include/asm/Kbuild          |   1 +
 arch/x86/include/asm/stackdepot.h   |  37 ++++
 drivers/gpu/drm/drm_modeset_lock.c  |   5 +-
 include/asm-generic/Kbuild          |   1 +
 include/asm-generic/stackdepot.h    |  19 ++
 include/linux/stackdepot.h          |  45 +++-
 lib/Kconfig.debug                   |  16 ++
 lib/stackdepot.c                    | 164 ++++++++++++---
 lib/tests/Makefile                  |   1 +
 lib/tests/stackdepot_kunit.c        | 312 ++++++++++++++++++++++++++++
 mm/kmemleak.c                       |   4 +-
 mm/kmsan/kmsan_test.c               |   4 +-
 mm/kmsan/report.c                   |  28 +--
 mm/page_owner.c                     |   8 +-
 mm/slub.c                           |  12 +-
 scripts/gdb/linux/constants.py.in   |   5 +
 scripts/gdb/linux/stackdepot.py     |  23 +-
 18 files changed, 650 insertions(+), 72 deletions(-)
 create mode 100644 arch/arm64/include/asm/stackdepot.h
 create mode 100644 arch/x86/include/asm/stackdepot.h
 create mode 100644 include/asm-generic/stackdepot.h
 create mode 100644 lib/tests/stackdepot_kunit.c
Signature · 1 line
2.43.0