On Mon, Oct 24, 2016 at 2:22 PM, William Tu via iovisor-dev
<iovisor-dev@lists.iovisor.org> wrote:
> Hi,
>
> Is there an easy way to clear all entries in a BPF hash map?
>
> My use case:
> When my BPF userspace program and kernel BPF is running, I want to
> dynamically adding a new BPF hash map. IIUC, there is no way to do
> that. So at beginning when loading the BPF, I pre-allocate a pool of
> hash maps and always lookup all of them. At certain point, my
> userspace BPF program wants to invalidate a particular map by clearing
> all its entries. I pinned all maps as PIN_GLOBAL_NS so I think
> userspace calling close() then open() won't clear all entries. Is
> there a better way to do it? If there is a BPF_FUNC_map_delete_all,
> then it will be great. Thanks!

there is no delete_all, since it would be easily confused as 'atomic' delete.
There cannot be an atomic delete, so user space have to walk the map
with get_next and delete all elements.
Such loop in user space is slightly slower than similar loop
in kernel would have been, but it demonstrates the point that delete_all is
not atomic either way. Also if speed of delete all matters it means the
interaction between user and kernel space are not going to scale anyway
as size of maps grows, number of events in kernel is increasing and so on.

what do you mean by 'add a new hash map' ?
The was a discussion to add 'map inside the map' concept,
so that 1st map_lookup returns a pointer to another map which
can be used in 2nd map operation.
Will it solve your use case?
_______________________________________________
iovisor-dev mailing list
iovisor-dev@lists.iovisor.org
https://lists.iovisor.org/mailman/listinfo/iovisor-dev

Reply via email to