On Thu, Jul 06, 2023 at 10:48:16AM -0700, Alexei Starovoitov wrote: > On Thu, Jul 6, 2023 at 10:42 AM Anton Protopopov <aspsk@xxxxxxxxxxxxx> wrote: > > > > > > > > Don't you want to do: > > > val = bpf_map_lookup_elem(map, ...); > > > cnt = bpf_map_sum_elem_count(map); > > > > > > and that's the main use case ? > > > > Not sure I understand what this ^ use case is... > > > > Our primary use case is to [periodically] get the number of elements from the > > user space. We can do this using an iterator as you've suggested and what is > > tested in the added selftest. > > Hmm. During the last office hours John explained that he needs to raise > alarm to user space when the map is close to full capacity. > Currently he's doing it with his own per-map counters implemented > in a bpf prog. > I'd expect the alarm to be done inline with updates to the counters. > If you scan maps from user space every second or so there is a chance > the spike in usage will be missed. > > If we're adding map counters they should be usable not only via iterators. In some use cases this is ok to miss a spike in favour of not checking counters too often. But yes, for other use cases this makes sense to add support for const map ptr, so I will do this. > > John, > did I describe your use case correctly?