On Mon, 12 Feb 2024 10:44:26 +0000
Vincent Donnefort <vdonnef...@google.com> wrote:

> > >  static void
> > >  rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
> > >  {
> > > @@ -5204,6 +5227,9 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
> > >   cpu_buffer->lost_events = 0;
> > >   cpu_buffer->last_overrun = 0;
> > >  
> > > + if (READ_ONCE(cpu_buffer->mapped))  
> > 
> > Isn't the buffer_mutex held when we modify mapped? I believe it's held
> > here. I don't think we need a READ_ONCE() here. Is there a reason for it?
> > 
> > Hmm, looking down, it looks like you take the buffer->mutex after
> > setting mapped, is that necessary? If we take the buffer->mutex we can
> > sync the reset with mapping.  
> 
> The idea was to not take any of the buffer mutex, reader lock if the refcount 
> is
> simply inc/dec. Locks are only used if the meta-page is
> installed/uninstalled.

Does it matter? The inc/dec is only done at initial mapping, right? That's
a very slow path.

> 
> The WRITE_ONCE/READ_ONCE is there only to make sure no compiler optimisation
> could lead a reader to wrongly interpret that refcount while it is inc/dec. 
> That
> is probably not necessary and I'm happy to either drop it completely or 
> replace
> it by taking buffer mutex and reader lock whenever the refcount is inc/dec.

Yeah, probably best to drop it and keep updates within the mutex.

-- Steve


Reply via email to