All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denys Vlasenko <dvlasenk@redhat.com>
To: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Suravee Suthikulpanit" <Suravee.Suthikulpanit@amd.com>
Cc: Joerg Roedel <joro@8bytes.org>,
	tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com,
	x86@kernel.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: SVM: refactor avic VM ID allocation
Date: Fri, 18 Aug 2017 17:22:30 +0200	[thread overview]
Message-ID: <4ca2cb8a-3743-fe42-2542-797493fd819f@redhat.com> (raw)
In-Reply-To: <c352062c-fb9f-4468-297d-42a87b53fc8c@redhat.com>

On 08/17/2017 04:33 PM, Paolo Bonzini wrote:
> On 15/08/2017 22:12, Radim Krčmář wrote:
>> 2017-08-11 22:11+0200, Denys Vlasenko:
>>> With lightly tweaked defconfig:
>>>
>>>     text    data     bss      dec     hex filename
>>> 11259661 5109408 2981888 19350957 12745ad vmlinux.before
>>> 11259661 5109408  884736 17253805 10745ad vmlinux.after
>>>
>>> Only compile-tested.
>>>
>>> Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
>>> Cc: Joerg Roedel <joro@8bytes.org>
>>> Cc: pbonzini@redhat.com
>>> Cc: rkrcmar@redhat.com
>>> Cc: tglx@linutronix.de
>>> Cc: mingo@redhat.com
>>> Cc: hpa@zytor.com
>>> Cc: x86@kernel.org
>>> Cc: kvm@vger.kernel.org
>>> Cc: linux-kernel@vger.kernel.org
>>> ---
>>
>> Ah, I suspected my todo wasn't this short;  thanks for the patch!
>>
>>> @@ -1468,6 +1433,22 @@ static int avic_vm_init(struct kvm *kvm)
>>>  	clear_page(page_address(l_page));
>>>
>>>  	spin_lock_irqsave(&svm_vm_data_hash_lock, flags);
>>> + again:
>>> +	vm_id = next_vm_id = (next_vm_id + 1) & AVIC_VM_ID_MASK;
>>> +	if (vm_id == 0) { /* id is 1-based, zero is not okay */
>>
>> Suravee, did the reserved zero mean something?
>>
>>> +		next_vm_id_wrapped = 1;
>>> +		goto again;
>>> +	}
>>> +	/* Is it still in use? Only possible if wrapped at least once */
>>> +	if (next_vm_id_wrapped) {
>>> +		hash_for_each_possible(svm_vm_data_hash, ka, hnode, vm_id) {
>>> +			struct kvm *k2 = container_of(ka, struct kvm, arch);
>>> +			struct kvm_arch *vd2 = &k2->arch;
>>> +			if (vd2->avic_vm_id == vm_id)
>>> +				goto again;
>>
>> Although hitting the case where all 2^24 ids are already used is
>> practically impossible, I don't like the loose end ...
>
> I think even the case where 2^16 ids are used deserves a medal.  Why
> don't we just make the bitmap 8 KiB and call it a day? :)

Well, the RAM is cheap, but a 4-byte variable is still thousands of times
smaller than a 8K bitmap.

Since a 256 element hash table is used here, you need to have ~one hundred
VMs to start seeing (very small) degradation in speed of creation of new VMs
compared to bitmap approach, and that is only after 16777216 VMs
were created since reboot.

If you want to spend RAM on speeding this up, you can increase hash table size
instead. That would speed up avic_ga_log_notifier() too.

  reply	other threads:[~2017-08-18 15:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-11 20:11 [PATCH] KVM: SVM: delete avic_vm_id_bitmap (2 megabyte static array) Denys Vlasenko
2017-08-15 20:12 ` [PATCH] KVM: SVM: refactor avic VM ID allocation Radim Krčmář
2017-08-17 14:33   ` Paolo Bonzini
2017-08-18 15:22     ` Denys Vlasenko [this message]
2017-08-18 16:05       ` Paolo Bonzini

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=4ca2cb8a-3743-fe42-2542-797493fd819f@redhat.com \
    --to=dvlasenk@redhat.com \
    --cc=Suravee.Suthikulpanit@amd.com \
    --cc=hpa@zytor.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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.