Re: [PATCH 1/2] kvm: leverage change to adjust slots->used_slots in update_memslots()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 21, 2018 at 12:31:31PM +0200, Paolo Bonzini wrote:
>On 21/08/2018 00:53, Wei Yang wrote:
>> On Mon, Aug 20, 2018 at 04:44:25PM -0400, Konrad Rzeszutek Wilk wrote:
>>> On Mon, Aug 20, 2018 at 08:23:29PM +0000, Wei Yang wrote:
>>>> On Mon, Aug 20, 2018 at 09:47:20AM -0400, Konrad Rzeszutek Wilk wrote:
>>>>> On Sun, Aug 19, 2018 at 08:17:45AM +0800, Wei Yang wrote:
>>>>>> update_memslots() is only called by __kvm_set_memory_region(), in which
>>>>>> change is calculated to indicate the following behavior. With this
>>>>>
>>>>> What is the 'following behavior' you mention?
>>>>
>>>> Ah, 'following behavior' means what need to do in update_memslots() to
>>>> used_slots.
>>>>
>>>> For example, if change equals KVM_MR_CREATE, it means update_memslots()
>>>> will add a new slot and used_slots need to increase by one.
>>>>
>>>> With this information, we don't need to do the calculation in
>>>> update_memslots() again, but just do an addition.
>>>
>>> Could you update the commit ot have this description please?
>>>>
>> 
>> Sure.
>> 
>> Per comments from Paolo in patch 2, only this one is necessary in next
>> spin, right?
>
>I don't know... Encoding the delta in bits 0-7 is not something I would
>really do unless it's super important for performance.

The original idea is just pass the change to update_memslots() and
adjust used_slots based on change instead of re-calculate it.

While I did a step further to encode the adjustment in change.

How about something like this:

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 3d233ebfbee9..efecb0489dbc 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -808,13 +808,15 @@ static void update_memslots(struct kvm_memslots *slots,
	struct kvm_memory_slot *mslots = slots->memslots;

	WARN_ON(mslots[i].id != id);
-       if (!new->npages) {
-               WARN_ON(!mslots[i].npages);
-               if (mslots[i].npages)
-                       slots->used_slots--;
-       } else {
-               if (!mslots[i].npages)
-                       slots->used_slots++;
+       switch (change) {
+       case KVM_MR_CREATE:
+               slots->used_slots++;
+               break;
+       case KVM_MR_DELETE:
+               slots->used_slots--;
+               break;
+       default:
+               break;
        }

>
>Paolo

-- 
Wei Yang
Help you, Help me



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux