From: Philo Lu <lulie@linux.alibaba.com>
To: Hou Tao <houtao@huaweicloud.com>, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
yonghong.song@linux.dev, kpsingh@kernel.org, sdf@google.com,
haoluo@google.com, jolsa@kernel.org, rostedt@goodmis.org,
mhiramat@kernel.org, mathieu.desnoyers@efficios.com,
linux-trace-kernel@vger.kernel.org, xuanzhuo@linux.alibaba.com,
dust.li@linux.alibaba.com, alibuda@linux.alibaba.com,
guwen@linux.alibaba.com, hengqi@linux.alibaba.com,
shung-hsi.yu@suse.com
Subject: Re: [PATCH bpf-next 1/3] bpf: implement relay map basis
Date: Mon, 25 Dec 2023 19:36:33 +0800 [thread overview]
Message-ID: <6a8538dc-d05c-41c9-bab5-6fbb5c6eea2f@linux.alibaba.com> (raw)
In-Reply-To: <87b4f7fc-cc98-496c-bbff-6e3890278e35@linux.alibaba.com>
On 2023/12/23 21:02, Philo Lu wrote:
>
>
> On 2023/12/23 19:22, Hou Tao wrote:
>> Hi,
>>
>> On 12/22/2023 8:21 PM, Philo Lu wrote:
>>> BPF_MAP_TYPE_RELAY is implemented based on relay interface, which
>>> creates per-cpu buffer to transfer data. Each buffer is essentially a
>>> list of fix-sized sub-buffers, and is exposed to user space as files in
>>> debugfs. attr->max_entries is used as subbuf size and attr->map_extra is
>>> used as subbuf num. Currently, the default value of subbuf num is 8.
>>>
>>> The data can be accessed by read or mmap via these files. For example,
>>> if there are 2 cpus, files could be `/sys/kernel/debug/mydir/my_rmap0`
>>> and `/sys/kernel/debug/mydir/my_rmap1`.
>>>
>>> Buffer-only mode is used to create the relay map, which just allocates
>>> the buffer without creating user-space files. Then user can setup the
>>> files with map_update_elem, thus allowing user to define the directory
>>> name in debugfs. map_update_elem is implemented in the following patch.
>>>
>>> A new map flag named BPF_F_OVERWRITE is introduced to set overwrite mode
>>> of relay map.
>>
>> Beside adding a new map type, could we consider only use kfuncs to
>> support the creation of rchan and the write of rchan ? I think
>> bpf_cpumask will be a good reference.
>
> This is a good question. TBH, I have thought of implement it with
> helpers (I'm not very familiar with kfuncs, but I think they could be
> similar?), but I was stumped by how to close the channel. We can create
> a relay channel, hold it with a map, but it could be difficult for the
> bpf program to close the channel with relay_close(). And I think it
> could be the difference compared with bpf_cpumask.
I've learned more about kfunc and kptr, and find that kptr can be
automatically released with a given map. Then, it is technically
feasible to use relay interface with kfuncs. Specificially, creating a
relay channel and getting the pointer with kfunc, transferring it as a
kptr into a map, and then it lives with the map.
Though I'm not sure if this is better than map-based implementation, as
mostly it will be used with a map (I haven't thought of a case without a
map yet). And with kfunc, it will be a little more complex to create a
relay channel.
Thanks.
next prev parent reply other threads:[~2023-12-25 11:36 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-22 12:21 [PATCH bpf-next 0/3] bpf: introduce BPF_MAP_TYPE_RELAY Philo Lu
2023-12-22 12:21 ` [PATCH bpf-next 1/3] bpf: implement relay map basis Philo Lu
2023-12-22 14:45 ` Jiri Olsa
2023-12-23 2:54 ` Philo Lu
2023-12-22 23:07 ` kernel test robot
2023-12-23 0:11 ` kernel test robot
2023-12-23 11:22 ` Hou Tao
2023-12-23 13:02 ` Philo Lu
2023-12-25 11:36 ` Philo Lu [this message]
2023-12-25 13:06 ` Hou Tao
2023-12-22 12:21 ` [PATCH bpf-next 2/3] bpf: implement map_update_elem to init relay file Philo Lu
2023-12-22 14:45 ` Jiri Olsa
2023-12-23 2:55 ` Philo Lu
2023-12-23 11:28 ` Hou Tao
2023-12-23 13:19 ` Philo Lu
2023-12-22 12:21 ` [PATCH bpf-next 3/3] bpf: introduce bpf_relay_output helper Philo Lu
2023-12-22 14:46 ` Jiri Olsa
2023-12-23 2:56 ` Philo Lu
2023-12-22 14:45 ` [PATCH bpf-next 0/3] bpf: introduce BPF_MAP_TYPE_RELAY Jiri Olsa
2023-12-23 2:57 ` Philo Lu
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=6a8538dc-d05c-41c9-bab5-6fbb5c6eea2f@linux.alibaba.com \
--to=lulie@linux.alibaba.com \
--cc=alibuda@linux.alibaba.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dust.li@linux.alibaba.com \
--cc=guwen@linux.alibaba.com \
--cc=haoluo@google.com \
--cc=hengqi@linux.alibaba.com \
--cc=houtao@huaweicloud.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=sdf@google.com \
--cc=shung-hsi.yu@suse.com \
--cc=song@kernel.org \
--cc=xuanzhuo@linux.alibaba.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