From: Leonardo Bras <leobras@redhat.com>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Leonardo Bras <leobras@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Frederic Weisbecker <frederic@kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [RFC PATCH 1/1] kvm: Note an RCU quiescent state on guest exit
Date: Wed, 15 May 2024 01:45:33 -0300 [thread overview]
Message-ID: <ZkQ97QcEw34aYOB1@LeoBras> (raw)
In-Reply-To: <68c39823-6b1d-4368-bd1e-a521ade8889b@paulmck-laptop>
On Tue, May 14, 2024 at 03:54:16PM -0700, Paul E. McKenney wrote:
> On Mon, May 13, 2024 at 06:47:13PM -0300, Leonardo Bras Soares Passos wrote:
> > On Mon, May 13, 2024 at 4:40 PM Sean Christopherson <seanjc@google.com> wrote:
> > >
> > > On Fri, May 10, 2024, Leonardo Bras wrote:
> > > > As of today, KVM notes a quiescent state only in guest entry, which is good
> > > > as it avoids the guest being interrupted for current RCU operations.
> > > >
> > > > While the guest vcpu runs, it can be interrupted by a timer IRQ that will
> > > > check for any RCU operations waiting for this CPU. In case there are any of
> > > > such, it invokes rcu_core() in order to sched-out the current thread and
> > > > note a quiescent state.
> > > >
> > > > This occasional schedule work will introduce tens of microsseconds of
> > > > latency, which is really bad for vcpus running latency-sensitive
> > > > applications, such as real-time workloads.
> > > >
> > > > So, note a quiescent state in guest exit, so the interrupted guests is able
> > > > to deal with any pending RCU operations before being required to invoke
> > > > rcu_core(), and thus avoid the overhead of related scheduler work.
> > >
> > > Are there any downsides to this? E.g. extra latency or anything? KVM will note
> > > a context switch on the next VM-Enter, so even if there is extra latency or
> > > something, KVM will eventually take the hit in the common case no matter what.
> > > But I know some setups are sensitive to handling select VM-Exits as soon as possible.
> > >
> > > I ask mainly because it seems like a no brainer to me to have both VM-Entry and
> > > VM-Exit note the context switch, which begs the question of why KVM isn't already
> > > doing that. I assume it was just oversight when commit 126a6a542446 ("kvm,rcu,nohz:
> > > use RCU extended quiescent state when running KVM guest") handled the VM-Entry
> > > case?
> >
> > I don't know, by the lore I see it happening in guest entry since the
> > first time it was introduced at
> > https://lore.kernel.org/all/1423167832-17609-5-git-send-email-riel@redhat.com/
> >
> > Noting a quiescent state is cheap, but it may cost a few accesses to
> > possibly non-local cachelines. (Not an expert in this, Paul please let
> > me know if I got it wrong).
>
> Yes, it is cheap, especially if interrupts are already disabled.
> (As in the scheduler asks RCU to do the same amount of work on its
> context-switch fastpath.)
Thanks!
>
> > I don't have a historic context on why it was just implemented on
> > guest_entry, but it would make sense when we don't worry about latency
> > to take the entry-only approach:
> > - It saves the overhead of calling rcu_virt_note_context_switch()
> > twice per guest entry in the loop
> > - KVM will probably run guest entry soon after guest exit (in loop),
> > so there is no need to run it twice
> > - Eventually running rcu_core() may be cheaper than noting quiescent
> > state every guest entry/exit cycle
> >
> > Upsides of the new strategy:
> > - Noting a quiescent state in guest exit avoids calling rcu_core() if
> > there was a grace period request while guest was running, and timer
> > interrupt hits the cpu.
> > - If the loop re-enter quickly there is a high chance that guest
> > entry's rcu_virt_note_context_switch() will be fast (local cacheline)
> > as there is low probability of a grace period request happening
> > between exit & re-entry.
> > - It allows us to use the rcu patience strategy to avoid rcu_core()
> > running if any grace period request happens between guest exit and
> > guest re-entry, which is very important for low latency workloads
> > running on guests as it reduces maximum latency in long runs.
> >
> > What do you think?
>
> Try both on the workload of interest with appropriate tracing and
> see what happens? The hardware's opinion overrides mine. ;-)
That's a great approach!
But in this case I think noting a quiescent state in guest exit is
necessary to avoid a scenario in which a VM takes longer than RCU
patience, and it ends up running rcuc in a nohz_full cpu, even if guest
exit was quite brief.
IIUC Sean's question is more on the tone of "Why KVM does not note a
quiescent state in guest exit already, if it does in guest entry", and I
just came with a few arguments to try finding a possible rationale, since
I could find no discussion on that topic in the lore for the original
commit.
Since noting a quiescent state in guest exit is cheap enough, avoids rcuc
schedules when grace period starts during guest execution, and enables a
much more rational usage of RCU patience, it's a safe to assume it's a
better way of dealing with RCU compared to current implementation.
Sean, what do you think?
Thanks!
Leo
>
> Thanx, Paul
>
next prev parent reply other threads:[~2024-05-15 4:45 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-11 2:05 [RFC PATCH 1/1] kvm: Note an RCU quiescent state on guest exit Leonardo Bras
2024-05-11 2:11 ` Leonardo Bras
2024-05-11 14:55 ` Paul E. McKenney
2024-05-11 20:31 ` Leonardo Bras
2024-05-12 21:44 ` Marcelo Tosatti
2024-05-13 1:06 ` Marcelo Tosatti
2024-05-13 3:14 ` Leonardo Bras
2024-05-13 19:14 ` Marcelo Tosatti
2024-05-13 19:40 ` Sean Christopherson
2024-05-13 21:47 ` Leonardo Bras Soares Passos
2024-05-14 22:54 ` Paul E. McKenney
2024-05-15 4:45 ` Leonardo Bras [this message]
2024-05-15 14:57 ` Paul E. McKenney
2024-06-20 7:03 ` Leonardo Bras
2024-06-20 17:26 ` Paul E. McKenney
2024-06-25 2:31 ` Leonardo Bras
2024-06-25 2:34 ` Leonardo Bras
2024-07-10 23:18 ` Leonardo Bras
2024-07-12 15:57 ` Paolo Bonzini
2024-07-12 20:02 ` Leonardo Bras
2024-07-29 11:28 ` Leonardo Bras Soares Passos
2024-08-27 19:50 ` Leonardo Bras Soares Passos
2024-09-03 18:07 ` Sean Christopherson
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=ZkQ97QcEw34aYOB1@LeoBras \
--to=leobras@redhat.com \
--cc=frederic@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=paulmck@kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox