linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] mm/page_owner: add options 'print_handle' and 'print_stack' for 'show_stacks'
@ 2025-09-24 17:40 Mauricio Faria de Oliveira
  2025-09-24 17:40 ` [PATCH 1/3] mm/page_owner: add option 'print_handle' " Mauricio Faria de Oliveira
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Mauricio Faria de Oliveira @ 2025-09-24 17:40 UTC (permalink / raw)
  To: Andrew Morton, Vlastimil Babka
  Cc: Oscar Salvador, Suren Baghdasaryan, Michal Hocko,
	Brendan Jackman, Johannes Weiner, Zi Yan, linux-mm, linux-kernel,
	kernel-dev

Problem:

The use case of monitoring the memory usage per stack trace (or tracking
a particular stack trace) requires uniquely identifying each stack trace.

This has to be done for every stack trace on every sample of monitoring,
even if tracking only one stack trace (to identify it among all others).

Therefore, an approach like, for example, hashing the stack traces from
'show_stacks' for calculating unique identifiers can become expensive.

Solution:

Fortunately, the kernel can provide a unique identifier for stack traces
in page_owner, which is the handle number in stackdepot.

Additionally, with that information, the stack traces themselves are not
needed until the time when the memory usage should be associated with a
stack trace (say, to look at a few top consumers), using handle numbers.

This eliminates hashing and reduces filtering related to stack traces in
userspace, and reduces text emitted/copied by the kernel.

Changes:

This patchset adds 2 options to configure the output of 'show_stacks':
 - print_handle: print the handle number of the stack traces (disabled)
 - print_stack: print the stack traces (enabled)

Now, it is possible to sample with handles/without stacks, and do one last
sample with handles and stacks to associate the handles with their stacks.

Tested on next-20250922.

Results:

Numbers on a freshly booted system (gains should be higher after load,
as more stack traces would be present); average time of 10 runs:

 - Baseline: 
   average = 0.165
   # cat /sys/kernel/debug/page_owner_stacks/show_stacks >file

 - Enable handles:
   average = 0.165 (same)
   # echo 1 >/sys/kernel/debug/page_owner_stacks/print_handle
   # cat /sys/kernel/debug/page_owner_stacks/show_stacks >file

 - Enable handles, remove stack traces in userspace (example):
   average = 0.167 (+1.2%)
   # echo 1 >/sys/kernel/debug/page_owner_stacks/print_handle
   # grep -v '^ ' /sys/kernel/debug/page_owner_stacks/show_stacks >file

 - Enable handles, disable stack traces in kernel:
   average = 0.041 (-75.2%)
   # echo 1 >/sys/kernel/debug/page_owner_stacks/print_handle
   # echo 0 >/sys/kernel/debug/page_owner_stacks/print_stack
   # cat /sys/kernel/debug/page_owner_stacks/show_stacks >file

Mauricio Faria de Oliveira (3):
  mm/page_owner: add option 'print_handle' for 'show_stacks'
  mm/page_owner: add option 'print_stack' for 'show_stacks'
  mm/page_owner: update Documentation with print_handle and print_stack

 Documentation/mm/page_owner.rst | 15 ++++++++++++++-
 mm/page_owner.c                 | 18 ++++++++++++++----
 2 files changed, 28 insertions(+), 5 deletions(-)

-- 
2.48.1



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

end of thread, other threads:[~2025-10-01 17:37 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-24 17:40 [PATCH 0/3] mm/page_owner: add options 'print_handle' and 'print_stack' for 'show_stacks' Mauricio Faria de Oliveira
2025-09-24 17:40 ` [PATCH 1/3] mm/page_owner: add option 'print_handle' " Mauricio Faria de Oliveira
2025-09-25 20:28   ` Joshua Hahn
2025-09-25 22:25     ` Mauricio Faria de Oliveira
2025-09-24 17:40 ` [PATCH 2/3] mm/page_owner: add option 'print_stack' " Mauricio Faria de Oliveira
2025-09-24 17:40 ` [PATCH 3/3] mm/page_owner: update Documentation with 'print_handle' and 'print_stack' Mauricio Faria de Oliveira
2025-09-25 16:08 ` [PATCH 0/3] mm/page_owner: add options 'print_handle' and 'print_stack' for 'show_stacks' Michal Hocko
2025-09-25 19:38   ` Mauricio Faria de Oliveira
2025-09-26  6:55     ` Michal Hocko
2025-09-26 16:47       ` Mauricio Faria de Oliveira
2025-09-30 14:02         ` Michal Hocko
2025-09-30 14:32           ` Mauricio Faria de Oliveira
2025-10-01 10:58           ` Vlastimil Babka
2025-10-01 17:37             ` Mauricio Faria de Oliveira

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