From: Peter Xu <peterx@redhat.com>
To: David Hildenbrand <david@redhat.com>
Cc: qemu-devel@nongnu.org, Juraj Marcin <jmarcin@redhat.com>,
Prasad Pandit <ppandit@redhat.com>,
Julia Suvorova <jusual@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Fabiano Rosas <farosas@suse.de>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Zhiyi Guo <zhguo@redhat.com>
Subject: Re: [PATCH 3/4] KVM: Dynamic sized kvm memslots array
Date: Wed, 4 Sep 2024 17:58:27 -0400 [thread overview]
Message-ID: <ZtjYA0loqvXqHE3r@x1n> (raw)
In-Reply-To: <ZtjVTz5MDHyEHl9j@x1n>
On Wed, Sep 04, 2024 at 05:46:55PM -0400, Peter Xu wrote:
> On Wed, Sep 04, 2024 at 11:38:28PM +0200, David Hildenbrand wrote:
> > On 04.09.24 23:34, Peter Xu wrote:
> > > On Wed, Sep 04, 2024 at 11:23:33PM +0200, David Hildenbrand wrote:
> > > >
> > > > > >
> > > > > > Then, you can remove the parameter from kvm_slots_grow() completely and just call it
> > > > > > kvm_slots_double() and simplify a bit:
> > > > > >
> > > > > > static bool kvm_slots_double(KVMMemoryListener *kml)
> > > > > > {
> > > > > > unsigned int i, nr_slots_new, cur = kml->nr_slots_allocated;
> > > > > > KVMSlot *slots;
> > > > > >
> > > > > > nr_slots_new = MIN(cur * 2, kvm_state->nr_slots_max);
> > > > > > if (nr_slots_new == kvm_state->nr_slots_max) {
> > > > > > /* We reached the maximum */
> > > > > > return false;
> > > > > > }
> > > > > >
> > > > > > assert(kml->slots);
> > > > > > slots = g_renew(KVMSlot, kml->slots, nr_slots_new);
> > > > > > /*
> > > > > > * g_renew() doesn't initialize extended buffers, however kvm
> > > > > > * memslots require fields to be zero-initialized. E.g. pointers,
> > > > > > * memory_size field, etc.
> > > > > > */
> > > > > > memset(&slots[cur], 0x0, sizeof(slots[0]) * (nr_slots_new - cur));
> > > > > >
> > > > > > for (i = cur; i < nr_slots_new; i++) {
> > > > > > slots[i].slot = i;
> > > > > > }
> > > > > >
> > > > > > kml->slots = slots;
> > > > > > kml->nr_slots_allocated = nr_slots_new;
> > > > > > trace_kvm_slots_grow(cur, nr_slots_new);
> > > > > >
> > > > > > return true;
> > > > > > }
> > > > >
> > > > > Personally I still think it cleaner to allow setting whatever size.
> > > >
> > > > Why would one need that? If any, at some point we would want to shrink or
> > > > rather "compact".
> > > >
> > > > >
> > > > > We only have one place growing so far, which is pretty trivial to double
> > > > > there, IMO. I'll wait for a second opinion, or let me know if you have
> > > > > strong feelings..
> > > >
> > > > I think the simplicity of kvm_slots_double() speaks for itself, but I won't
> > > > fight for it.
> > >
> > > Using kvm_slots_double() won't be able to share the same code when
> > > initialize (to e.g. avoid hard-coded initialize of "slots[i].slot").
> >
> > I don't see that as any problem and if you really care you could factor
> > exactly that part out in a helper. Anyhow, I learned that I am not good at
> > convincing you, so do what you think is best. The code itself should get the
> > job done.
>
> It's only about that's the simplest for all of us, and I noticed it only
> because I already planned to switch to kvm_slots_double(); that's normally
> what I do when I don't strongly insist something. So you succeeded already
> making me go there. :)
>
> It's just that as you said it either requires more changes, or I'll need to
> duplicate some code which I want to avoid.
>
> >
> > Acked-by: David Hildenbrand <david@redhat.com>
>
> Thanks a lot for the late night reviews, David. I'll attach all your tags
> when repost, though just to mention there'll be slight touch ups here and
> there due to reordering. Feel free to double check when it's there.
So I plan to squash this in, assuming this looks better to you:
===8<===
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 78f2d8b80f..020fd16ab8 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -216,6 +216,11 @@ static bool kvm_slots_grow(KVMMemoryListener *kml, unsigned int nr_slots_new)
return true;
}
+static bool kvm_slots_double(KVMMemoryListener *kml)
+{
+ return kvm_slots_grow(kml, kml->nr_slots_allocated * 2);
+}
+
unsigned int kvm_get_max_memslots(void)
{
KVMState *s = KVM_STATE(current_accel());
@@ -254,7 +259,7 @@ retry:
}
/* If no free slots, try to grow first by doubling */
- if (kvm_slots_grow(kml, kml->nr_slots_allocated * 2)) {
+ if (kvm_slots_double(kml)) {
goto retry;
}
===8<===
Please let me know if otherwise.
--
Peter Xu
next prev parent reply other threads:[~2024-09-04 21:59 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-04 19:16 [PATCH 0/4] KVM: Dynamic sized memslots array Peter Xu
2024-09-04 19:16 ` [PATCH 1/4] KVM: Rename KVMState->nr_slots to nr_slots_max Peter Xu
2024-09-04 20:36 ` David Hildenbrand
2024-09-04 19:16 ` [PATCH 2/4] KVM: Define KVM_MEMSLOTS_NUM_MAX_DEFAULT Peter Xu
2024-09-04 20:39 ` David Hildenbrand
2024-09-04 20:56 ` Peter Xu
2024-09-04 19:16 ` [PATCH 3/4] KVM: Dynamic sized kvm memslots array Peter Xu
2024-09-04 20:43 ` David Hildenbrand
2024-09-04 20:51 ` David Hildenbrand
2024-09-04 20:55 ` Peter Xu
2024-09-04 21:07 ` David Hildenbrand
2024-09-04 21:20 ` Peter Xu
2024-09-04 21:23 ` David Hildenbrand
2024-09-04 21:34 ` Peter Xu
2024-09-04 21:38 ` David Hildenbrand
2024-09-04 21:46 ` Peter Xu
2024-09-04 21:58 ` Peter Xu [this message]
2024-09-04 19:16 ` [PATCH 4/4] KVM: Rename KVMMemoryListener.nr_used_slots to nr_slots_used Peter Xu
2024-09-04 20:40 ` David Hildenbrand
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=ZtjYA0loqvXqHE3r@x1n \
--to=peterx@redhat.com \
--cc=david@redhat.com \
--cc=farosas@suse.de \
--cc=jmarcin@redhat.com \
--cc=jusual@redhat.com \
--cc=pbonzini@redhat.com \
--cc=ppandit@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=vkuznets@redhat.com \
--cc=zhguo@redhat.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;
as well as URLs for NNTP newsgroup(s).