From: "Christian König" <christian.koenig@amd.com>
To: "T.J. Mercier" <tjmercier@google.com>,
sumit.semwal@linaro.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, martin.lau@linux.dev,
skhan@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
linux-doc@vger.kernel.org, bpf@vger.kernel.org,
linux-kselftest@vger.kernel.org, android-mm@google.com,
simona@ffwll.ch, corbet@lwn.net, eddyz87@gmail.com,
song@kernel.org, yonghong.song@linux.dev,
john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
jolsa@kernel.org, mykolal@fb.com
Subject: Re: [PATCH 0/4] Replace CONFIG_DMABUF_SYSFS_STATS with BPF
Date: Tue, 15 Apr 2025 11:03:04 +0200 [thread overview]
Message-ID: <1d94316f-3336-4d40-bd18-e4703c7037e8@amd.com> (raw)
In-Reply-To: <20250414225227.3642618-1-tjmercier@google.com>
Am 15.04.25 um 00:52 schrieb T.J. Mercier:
> Until CONFIG_DMABUF_SYSFS_STATS was added [1] it was only possible to
> perform per-buffer accounting with debugfs which is not suitable for
> production environments. Eventually we discovered the overhead with
> per-buffer sysfs file creation/removal was significantly impacting
> allocation and free times, and exacerbated kernfs lock contention. [2]
> dma_buf_stats_setup() is responsible for 39% of single-page buffer
> creation duration, or 74% of single-page dma_buf_export() duration when
> stressing dmabuf allocations and frees.
>
> I prototyped a change from per-buffer to per-exporter statistics with a
> RCU protected list of exporter allocations that accommodates most (but
> not all) of our use-cases and avoids almost all of the sysfs overhead.
> While that adds less overhead than per-buffer sysfs, and less even than
> the maintenance of the dmabuf debugfs_list, it's still *additional*
> overhead on top of the debugfs_list and doesn't give us per-buffer info.
>
> This series uses the existing dmabuf debugfs_list to implement a BPF
> dmabuf iterator, which adds no overhead to buffer allocation/free and
> provides per-buffer info.
Really interesting suggestion. I was expecting something like cgroups, but bpf is certainly an option as well.
How do you then use bpf to account the buffers? E.g. are you interacting with cgroups or have sysfs procedure to expose the list or how does that work?
Additional to that why using DMA-buf for accounting in the first place? See DMA-buf is for sharing buffers and only a minimal fraction of buffers usually need to get shared. Everything else is just massive overhead.
> While the kernel must have CONFIG_DEBUG_FS for
> the dmabuf_iter to be available, debugfs does not need to be mounted.
> The BPF program loaded by userspace that extracts per-buffer information
> gets to define its own interface which avoids the lack of ABI stability
> with debugfs (even if it were mounted).
I think we can make the buffer list independent of CONFIG_DEBUG_FS.
> As this is a replacement for our use of CONFIG_DMABUF_SYSFS_STATS, the
> last patch is a RFC for removing it from the kernel. Please see my
> suggestion there regarding the timeline for that.
Oh, yes please!
Regards,
Christian.
>
> [1] https://lore.kernel.org/linux-media/20201210044400.1080308-1-hridya@google.com/
> [2] https://lore.kernel.org/all/20220516171315.2400578-1-tjmercier@google.com/
>
> T.J. Mercier (4):
> dma-buf: Rename and expose debugfs symbols
> bpf: Add dmabuf iterator
> selftests/bpf: Add test for dmabuf_iter
> RFC: dma-buf: Remove DMA-BUF statistics
>
> .../ABI/testing/sysfs-kernel-dmabuf-buffers | 24 ---
> Documentation/driver-api/dma-buf.rst | 5 -
> drivers/dma-buf/Kconfig | 15 --
> drivers/dma-buf/Makefile | 1 -
> drivers/dma-buf/dma-buf-sysfs-stats.c | 202 ------------------
> drivers/dma-buf/dma-buf-sysfs-stats.h | 35 ---
> drivers/dma-buf/dma-buf.c | 40 +---
> include/linux/btf_ids.h | 1 +
> include/linux/dma-buf.h | 6 +
> kernel/bpf/Makefile | 3 +
> kernel/bpf/dmabuf_iter.c | 130 +++++++++++
> tools/testing/selftests/bpf/config | 1 +
> .../selftests/bpf/prog_tests/dmabuf_iter.c | 116 ++++++++++
> .../testing/selftests/bpf/progs/dmabuf_iter.c | 31 +++
> 14 files changed, 299 insertions(+), 311 deletions(-)
> delete mode 100644 Documentation/ABI/testing/sysfs-kernel-dmabuf-buffers
> delete mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.c
> delete mode 100644 drivers/dma-buf/dma-buf-sysfs-stats.h
> create mode 100644 kernel/bpf/dmabuf_iter.c
> create mode 100644 tools/testing/selftests/bpf/prog_tests/dmabuf_iter.c
> create mode 100644 tools/testing/selftests/bpf/progs/dmabuf_iter.c
>
next prev parent reply other threads:[~2025-04-15 9:03 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-14 22:52 [PATCH 0/4] Replace CONFIG_DMABUF_SYSFS_STATS with BPF T.J. Mercier
2025-04-14 22:52 ` [PATCH 1/4] dma-buf: Rename and expose debugfs symbols T.J. Mercier
2025-04-14 22:52 ` [PATCH 2/4] bpf: Add dmabuf iterator T.J. Mercier
2025-04-16 2:48 ` kernel test robot
2025-04-16 16:28 ` T.J. Mercier
2025-04-16 22:02 ` Song Liu
2025-04-16 22:51 ` T.J. Mercier
2025-04-16 23:08 ` Song Liu
2025-04-16 23:40 ` T.J. Mercier
2025-04-17 1:25 ` Song Liu
2025-04-17 2:09 ` T.J. Mercier
2025-04-17 4:56 ` Song Liu
2025-04-17 16:04 ` T.J. Mercier
2025-04-17 20:26 ` Song Liu
2025-04-18 15:25 ` T.J. Mercier
2025-04-21 18:12 ` Song Liu
2025-04-21 17:58 ` Song Liu
2025-04-21 20:40 ` T.J. Mercier
2025-04-21 23:38 ` Alexei Starovoitov
2025-04-22 19:57 ` T.J. Mercier
2025-04-22 23:00 ` Alexei Starovoitov
2025-04-23 17:16 ` T.J. Mercier
2025-04-14 22:52 ` [PATCH 3/4] selftests/bpf: Add test for dmabuf_iter T.J. Mercier
2025-04-21 18:08 ` Song Liu
2025-04-14 22:52 ` [RFC PATCH 4/4] RFC: dma-buf: Remove DMA-BUF statistics T.J. Mercier
2025-04-15 9:03 ` Christian König [this message]
2025-04-15 18:13 ` [PATCH 0/4] Replace CONFIG_DMABUF_SYSFS_STATS with BPF T.J. Mercier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1d94316f-3336-4d40-bd18-e4703c7037e8@amd.com \
--to=christian.koenig@amd.com \
--cc=andrii@kernel.org \
--cc=android-mm@google.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=daniel@iogearbox.net \
--cc=dri-devel@lists.freedesktop.org \
--cc=eddyz87@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=sdf@fomichev.me \
--cc=simona@ffwll.ch \
--cc=skhan@linuxfoundation.org \
--cc=song@kernel.org \
--cc=sumit.semwal@linaro.org \
--cc=tjmercier@google.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox