Re: [PATCH 1/8] perf/hw_breakpoint: Optimize list of per-task breakpoints

Dmitry Vyukov
2022-06-09T13:05:57Z

On Thu, 9 Jun 2022 at 14:53, Marco Elver <elver@google.com> wrote:
>
> On Thu, Jun 09, 2022 at 02:30PM +0200, Dmitry Vyukov wrote:
> [...]
> > > + rcu_read_lock();
> >
> > Why do we need rcu_read_lock() here?
> > The patch does not change anything with respect to locking, so all
> > accesses to the container should still be protected by nr_bp_mutex.
> > Similarly for the rcu variant of for_each below.
> [...]
> > > + head = rhltable_lookup(&task_bps_ht, &bp->hw.target, task_bps_ht_params);
> > > + if (!head)
> > > + goto out;
> > > +
> > > + rhl_for_each_entry_rcu(iter, pos, head, hw.bp_list) {
>
> It's part of rhashtable's interface requirements:
>
> /**
> * rhltable_lookup - search hash list table
> * @hlt: hash table
> * @key: the pointer to the key
> * @params: hash table parameters
> *
> * Computes the hash value for the key and traverses the bucket chain looking
> * for a entry with an identical key. All matching entries are returned
> * in a list.
> *
> * This must only be called under the RCU read lock.
> *
> * Returns the list of entries that match the given key.
> */
>
> Beyond that, even though there might not appear to be any concurrent
> rhashtable modifications, it'll be allowed in patch 6/8. Furthermore,
> rhashtable actually does concurrent background compactions since I
> selected 'automatic_shrinking = true' (so we don't leak tons of memory
> after starting and killing those 1000s of tasks) -- there's this
> call_rcu() in lib/rhashtable.c that looks like that's when it's used.
> This work is done in a deferred work by rht_deferred_worker().

I see. Thanks.

Reviewed-by: Dmitry Vyukov <dvyukov@google.com>