linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [RFC/PATCH bpf-next 0/3] bpf: Add slab iterator and kfunc (v1)
@ 2024-09-25 22:30 Namhyung Kim
  2024-09-25 22:30 ` [RFC/PATCH bpf-next 1/3] bpf: Add slab iterator Namhyung Kim
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Namhyung Kim @ 2024-09-25 22:30 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	LKML, bpf, Andrew Morton, Christoph Lameter, Pekka Enberg,
	David Rientjes, Joonsoo Kim, Vlastimil Babka, Roman Gushchin,
	Hyeonggon Yoo, linux-mm

Hello,

I'm proposing a new iterator and a kfunc for the slab memory allocator
to get information of each kmem_cache like in /proc/slabinfo or
/sys/kernel/slab.  Maybe I need to call it kmem_cache iter but slab
was short and easier to call. :)

My use case is `perf lock contention` tool which shows contended locks
but many of them are not global locks and don't have symbols.  If it
can tranlate the address of the lock in a slab object to the name of
the slab, it'd be much more useful.

I'm not aware of type information in slab yet, but I was told there's
a work to associate BTF ID with it.  It'd be definitely helpful to my
use case.  Probably we need another kfunc to get the start address of
the object or the offset in the object from an address if the type
info is available.  But I want to start with a simple thing first.

The slab_iter iterates kmem_cache objects under slab_mutex and will be
useful for userspace to prepare some work for specific slabs like
setting up filters in advance.  And the bpf_get_slab_cache() kfunc
will return a pointer to a slab from the address of a lock.  And the
test code is to read from the iterator and make sure it finds a slab
cache of the task_struct for the current task.

The code is available at 'bpf/slab-iter-v1' branch in
https://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Thanks,
Namhyung


Namhyung Kim (3):
  bpf: Add slab iterator
  mm/bpf: Add bpf_get_slab_cache() kfunc
  selftests/bpf: Add a test for slab_iter

 include/linux/btf_ids.h                       |   1 +
 kernel/bpf/Makefile                           |   1 +
 kernel/bpf/helpers.c                          |   1 +
 kernel/bpf/slab_iter.c                        | 131 ++++++++++++++++++
 mm/slab_common.c                              |  14 ++
 .../selftests/bpf/prog_tests/slab_iter.c      |  64 +++++++++
 tools/testing/selftests/bpf/progs/bpf_iter.h  |   7 +
 tools/testing/selftests/bpf/progs/slab_iter.c |  62 +++++++++
 8 files changed, 281 insertions(+)
 create mode 100644 kernel/bpf/slab_iter.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/slab_iter.c
 create mode 100644 tools/testing/selftests/bpf/progs/slab_iter.c

-- 
2.46.0.792.g87dc391469-goog



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

end of thread, other threads:[~2024-09-27 13:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-25 22:30 [RFC/PATCH bpf-next 0/3] bpf: Add slab iterator and kfunc (v1) Namhyung Kim
2024-09-25 22:30 ` [RFC/PATCH bpf-next 1/3] bpf: Add slab iterator Namhyung Kim
2024-09-25 22:30 ` [RFC/PATCH bpf-next 2/3] mm/bpf: Add bpf_get_slab_cache() kfunc Namhyung Kim
2024-09-25 22:30 ` [RFC/PATCH bpf-next 3/3] selftests/bpf: Add a test for slab_iter Namhyung Kim
2024-09-26  0:16 ` [RFC/PATCH bpf-next 0/3] bpf: Add slab iterator and kfunc (v1) Roman Gushchin
2024-09-26 18:04   ` Namhyung Kim
2024-09-27 13:47   ` Vlastimil Babka

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