All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Cc: qemu-devel@nongnu.org,
	"Dmitry Osipenko" <dmitry.osipenko@collabora.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH 4/5] rcu: Wake the RCU thread when draining
Date: Thu, 13 Nov 2025 12:30:43 -0500	[thread overview]
Message-ID: <aRYVw1ydTbZr0OEH@x1.local> (raw)
In-Reply-To: <7c49d808-ccb8-4262-ae6c-2ac746b43b80@rsg.ci.i.u-tokyo.ac.jp>

Hi, Akihiko,

I found that you replied to me and forgot to cc all, I added all of the
people back.

On Sun, Nov 09, 2025 at 06:05:00PM +0900, Akihiko Odaki wrote:
> On 2025/11/08 10:45, Akihiko Odaki wrote:
> > On 2025/11/07 6:52, Peter Xu wrote:
> > > When I was having a closer look, I found some other issues, I'll list it
> > > all here.
> > > 
> > > 1. I found that rcu_gp_event was initialized as "true".  I'm not sure
> > >     whether it should be false.  This has nothing to do with your
> > > series as
> > >     well, only some observation of mine.
> > >      qemu_event_init(&rcu_gp_event, true);
> > 
> > Indeed it makes more sense to initialize it with false.
> > 
> > rcu_read_unlock() sets the event only in grace periods, and
> > wait_for_readers() always reset it when ending those grace periods. By
> > initializing it with false, the event will be false whenever outside
> > grace periods, improving consistency.

Thanks for confirming this. AFAIU this isn't a huge deal, as
wait_for_readers() should be tolerant of false positives.  So I'll leave it
to you on whether to touch it together.

> > 
> > > 
> > > 2. It looks to me your patch here checked the wrong retval of
> > >     qemu_event_timedwait()..
> > > 
> > >          } else if (qatomic_read(&rcu_call_count) >= RCU_CALL_MIN_SIZE ||
> > >                     !sleeps || qemu_event_timedwait(&sync_event, 10)) {
> > >                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > > 
> > >     should it be "!qemu_event_timedwait(&sync_event, 10)"?  Side
> > > note: maybe
> > >     we should cleanup all _timedwait() for QEMU's eventfd, sem, cond,
> > >     ... because they don't return the same retval.. but if you think
> > > sem is
> > >     good, then we don't need eventfd's timedwait() in this series (your
> > >     initial two patches).
> > 
> > You are right here too. This is a stupid mistake.
> 
> No, the original patch is right. qemu_event_timedwait(&sync_event, 10)
> returning true means that the forced variable was set before timing out,
> hence the we need to enter the force quiescent state.

You're correct.  I got misleaded by the comment here:

            /*
             * Now one of the following heuristical conditions is satisfied:
             * - A decent number of callbacks piled up.
             * - It timed out.                <--------------------
             * - force_rcu() was called.
             *
             * Force a quiescent state.
             */

I'm guessing you got misleaded too when I raised the question and when you
were looking.  Maybe it means it would be good to change that line of
comment into:

             * - It timed out continuously 5 times (causing sleeps==0)

> 
> > 
> > > 
> > > 3. I doubt if malloc_trim() feature is broken with your current patchset,
> > >     because now the loop looks like:
> > > 
> > >          for (;;) {
> > >              qemu_event_reset(&sync_event);
> > >              n = qatomic_read(&rcu_call_count);
> > >              if (n) {
> > >                  break;
> > >              }
> > > #if defined(CONFIG_MALLOC_TRIM)
> > >              malloc_trim(4 * 1024 * 1024);
> > > #endif
> > >              qemu_event_wait(&sync_event);
> > >          }
> > > 
> > >    I don't know if n can be zero here at all.. if you use the sem change
> > >    this might trigger but it's not designed for it.  When using sem
> > > we may
> > >    want to periodically trim.  But I'd like to know how you think in
> > > general
> > >    on the sem idea first (e.g. do we need to be prepared for high
> > > freq rcu
> > >    frees).
> > 
> > malloc_trim() is triggered when the RCU thread is idle, and that is not
> > changed with this patch.

You're right, I read it wrong.  Please ignore this comment.

Thanks,

-- 
Peter Xu



  parent reply	other threads:[~2025-11-13 17:31 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-29  6:12 [PATCH 0/5] virtio-gpu: Force RCU when unmapping blob Akihiko Odaki
2025-10-29  6:12 ` [PATCH 1/5] futex: Add qemu_futex_timedwait() Akihiko Odaki
2025-10-30 16:13   ` Alex Bennée
2025-10-29  6:12 ` [PATCH 2/5] qemu-thread: Add qemu_event_timedwait() Akihiko Odaki
2025-10-29  6:12 ` [PATCH 3/5] rcu: Use call_rcu() in synchronize_rcu() Akihiko Odaki
2025-10-29  6:12 ` [PATCH 4/5] rcu: Wake the RCU thread when draining Akihiko Odaki
2025-10-29 18:22   ` Peter Xu
2025-11-03  9:45     ` Akihiko Odaki
2025-11-05 20:43       ` Peter Xu
2025-11-06  1:40         ` Akihiko Odaki
2025-11-06 21:52           ` Peter Xu
2025-11-07  1:47             ` Akihiko Odaki
2025-11-07 14:00               ` Peter Xu
2025-11-08  1:47                 ` Akihiko Odaki
2025-11-13 17:03                   ` Peter Xu
2025-11-14  1:24                     ` Akihiko Odaki
2025-11-14 15:30                       ` Peter Xu
2025-11-15  1:58                         ` Akihiko Odaki
2025-11-15  2:59                           ` Akihiko Odaki
2025-11-17 16:42                             ` Peter Xu
2025-11-17 22:53                               ` Akihiko Odaki
2025-11-17 16:39                           ` Peter Xu
     [not found]             ` <1b318ad8-48b3-4968-86ca-c62aef3b3bd4@rsg.ci.i.u-tokyo.ac.jp>
     [not found]               ` <7c49d808-ccb8-4262-ae6c-2ac746b43b80@rsg.ci.i.u-tokyo.ac.jp>
2025-11-13 17:30                 ` Peter Xu [this message]
2025-11-14  1:12                   ` Akihiko Odaki
2025-10-29  6:12 ` [PATCH 5/5] virtio-gpu: Force RCU when unmapping blob Akihiko Odaki
2025-10-30 11:18   ` Dmitry Osipenko
2025-10-30 11:17 ` [PATCH 0/5] " Dmitry Osipenko
2025-10-30 17:59 ` Alex Bennée
2025-10-31 21:32 ` Alex Bennée

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aRYVw1ydTbZr0OEH@x1.local \
    --to=peterx@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=dmitry.osipenko@collabora.com \
    --cc=mst@redhat.com \
    --cc=odaki@rsg.ci.i.u-tokyo.ac.jp \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.