Re: [PATCH bpf-next 1/3] bpf: implement relay map basis

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux