qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 0/3] Hyper-V Dynamic Memory Protocol driver (hv-balloon)


From: David Hildenbrand
Subject: Re: [PATCH 0/3] Hyper-V Dynamic Memory Protocol driver (hv-balloon)
Date: Fri, 25 Sep 2020 08:49:39 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0

On 25.09.20 00:37, Maciej S. Szmigiero wrote:
> On 23.09.2020 14:48, David Hildenbrand wrote:
> (...)
>>>
>>> I know that this a source of significant hot removal slowdown, especially
>>> when a "ripple effect" happens on removal:
>>> 1) There are 3 extra DIMMs plugged into the guest: A, B, C.
>>>    A and B are nearly empty, but C is nearly full.
>>>
>>> 2) The host does not know anything which DIMM is empty and which is full,
>>>    so it requests the guest to unplug the stick C,
>>
>> In theory, the host can simply track inflation requests. In practice,
>> guests tend to sometimes re-access balloon-inflated memory (e.g., simple
>> kexec-style reboot under Linux, kdump on older Linux versions), so it's
>> not completely safe to do.
> 
> You are describing Linux situation here, while this driver targets
> Windows.

Yeah, this stuff is also broken with Linux under Hyper-V IIRC (I
remember fixing kdump/makedumpfile to not touch inflated pages).

> 
> I think the issues you describe (kexec, etc.) are probably fixable once
> somebody is determined enough to do so.
> 
> I mean, either the old kernel needs to transfer information about
> "forbidden" memory areas to the new kernel or the new kernel needs to
> query these somehow (probably only if is receives a "do it" flag from
> the old kernel).

One idea is to notify the host like "I'll reuse any page again". But
doing that via virtio while your dying isn't always possible. So the new
kernel would have to do it - but then virtio-balloon would have to be up
and running extremely early during boot, before any possibly-inflated
page gets touched - also a head scratcher. Then, what if your new kernel
doesn't support virtio-balloon ... not easy.

[...]

> But that's just really ugly - realistically the virtio-balloon
> protocol will need to be changed in such case.

Yes, and there were RFCs already.

https://lkml.kernel.org/r/1589276501-16026-1-git-send-email-teawater@gmail.com

[...]

> 
>>>
>>> If the KVM slot limit starts to be a problem in practice then we can
>>> think what can be done about it.
>>> It's always one obstacle less.
>>
>> I'm not a friend of leaving the challenging/fundamental problems to be
>> sported out in the future (e.g., resizing initial boot memory, dealing
>> with fundamental limits - like KVM memory slots or VMA). But I get how
>> it's easier to get something running this way :)
> 
> Constraints can be removed step-by-step, when they actually start tobite.

Not if they are fundamental. Try implementing vfio support for memory
ballooning, you're going to have a hard time.

> 
> It is unrealistic to have a perfect guest resize solution in a single
> patch series upfront, the issue is just too complex.

I disagree, but that's a different discussion. :)

> 
>>>
>>> I see that the same KVM slot limit probably applies also for virtio-mem,
>>> since it uses memory-backend-ram as its backing memory device, too,
>>> right?
>>
>> Yes, one memory backend per virtio-mem device. You usually have one
>> device per NUMA node.
> 
> So if you want to dynamically manage most of the guest memory these
> virtio-mem devices + their backends will be very large
> (circa 1/4 guest size each for a 4-node machine).

Right, or even bigger, depending on the setup.

> 
> That means in practice they won't ever be able to be hot-removed before
> the VM is rebooted since there will very likely be at least single stuck
> page in each of these backing devices preventing their removal.
> (If hot-removal support is ever enabled for virtio-mem, it looks like it
> is not possible yet even on a VM reboot).

Yeah, hot-removing a virtio-mem device is not one of the important use
cases (it's completely blocked). If you want to unplug memory, adjust
the requested size.

There are plans to support it in the future (for example during reboot),
but I barely see a need for it currently (especially once we support
resizeable memory backends upstream).

> 
> And I can see that removing a single RAM block in virio-mem is done 
> by discarding it via MADV_DONTNEED, just like in ballooning.
> Only the minimum block size is 2 MB and not 4 KB so all consecutive
> 512 pages in a block will need to be free in order to discard it.

Right, that was a decision to avoid issues known from base-page-size
based ballooning (like fragmenting guest memory, big tracking bitmaps,
incompatibility with vfio, breaking THP and degrading performance,
incompatibility with hugetlbfs ...)

[...]

> 
> During a reboot, virtual DIMM config optimization can be used for now,
> while the best, long-term, solution would be to actually do what the
> Hyper-V hypervisor does in this case: resize the boot memory to match
> the target guest size.
> 
> This way the whole issue of the guest seeing only the boot memory part,
> not the dynamic part, during its boot will no longer be there.
> 

Yeah, I had the same thought back when designing virtio-mem (and looking
into similar handling), but decided that it's impossible to get right -
at least in NUMA setups (and regarding migration). But I can see that
Hyper-V Dynamic Memory doesn't care too much about NUMA at all (and
NUMA-aware ballooning has its own set of issues).

[...]

> 
> So the virtio-mem trade-off is between the size of the boot memory and
> the dynamically managed part(s).
> And also the block size, as as far I can see, a single stuck page in
> a block will prevent it from being discarded.

Yes. It's really something in-between memory ballooning and DIMM-based
memory hot(un)plug. The block size will be comparatively large in some
setups (esp., with vfio). You're definitely not able to squeeze out the
page of your guest - we have virtio-balloon for that if one really wants
to do that - not the target use case of virtio-mem.

> 
> Of course, we are talking about Linux guests here - Windows guest
> will see just the boot memory part.

Yes, until we have support for it.
[...]

> Even if we switched virtio-balloon to bigger allocations and made the
> protocol return page ranges the allocation is still done by simply
> using an ordinary alloc_pages()-equivalent API.
> I don't see any exported Windows kernel API for allocating balloon
> memory.
> 
> The same goes for adding new RAM.
> 
> The above alone means that supporting virtio-mem semantics on current
> Windows versions is likely not possible.

All I can say is, that there are (unofficial?) APIs :) (e.g., the ones
used by DM). But yeah, that's what you get with closed-source operating
systems - and personally, I think, it shouldn't be us that have to suffer.

> 
>>>
>>> People are running Windows guests using QEMU, too.
>>>
>>> That's why there are dozen or so Hyper-V enlightenments implemented,
>>> even though they duplicate KVM PV stuff or that there is kvmvapic
>>> with its Windows guest live-patching.
>>
>> IIRC the Hyper-V enlightenment stuff is properly publicly documented -
> 
> They are only documented from the guest perspective - basically what
> the guest of a Hyper-V hypervisor can possibly use.
> 
> There is nothing in the Hyper-V TLFS which of the functionality it
> documents is supported or required by any Windows version or how
> Windows guests actually make use of these features.
> 
> Not to mention that the documented interface could say the guest can
> expect values A or B or C for parameter X, which is technically true, 
> however the actual Hyper-V hypervisor always uses A and that's what
> Windows will expect.
>  

Interesting, thanks.

>> whereby last time I checked, the hv-balloon is completely undocumented
>> and has to be reverse engineered from the Linux implementation. Please
>> correct me if I'm wrong - I am not able to spot references in your cover
>> letter as well - I'd be interested into that!
> 
> The DM protocol is rather straightforward - the Linux driver contains
> well-commented definitions of its messages.
> 
> For a hot add the host simply provides the start page frame number and
> the count of pages to add and in response receives the number of pages
> the guest was actually able to hot add.
> 
> For a balloon request the host provides a count of pages it wants the
> guest to free and the guest responds with page ranges it has managed
> to release.
> The reverse happens for an unballoon request.
> 
> The protocol consists of just a few simple messages, well described
> in the Linux driver.
> 
> The VMBus part of the protocol works in the same way as in other VMBus
> devices.
> 

Yeah, but then there are things like

https://lkml.kernel.org/r/20200107130950.2983-1-Tianyu.Lan@microsoft.com

that left me clueless - it seems like we're missing some things, maybe
there is more (I am pretty sure there is more ... :) )? (I do some work
on the Linux hv_balloon driver every now of then when working on
optimizing the other balloon drivers / virtio-mem).

>>>
>>> Not to mention many, many devices like e1000 or VMware vmxnet3 even
>>> though virtio-net exists or PIIX IDE even though virtio-{blk,scsi} exist.
>>> Or the applesmc driver, which is cleanly designed to help run just
>>> one proprietary OS.
>>
>> IIRC we need the devices either to bootstrap - e.g., use e1000 until we
>> can install virtio-net once the guest is up and running, or to support
>> older, unmodified guests. I'd like to stress that what you are proposing
>> is different in that sense. Your Windows VM will work just fine without
>> a hv-balloon device.
> 
> There are also "accelerator" devices like kvmvapic or proprietary devices
> where an older open standard exists, like sii3112 SATA, even though
> IDE / AHCI can be used to bootstrap the guest.
> The sii3112 driver was only added in 2017, although the hardware that
> it emulates comes from early 21st century.
> 
>> Again, just my personal opinion, I don't make any decisions around here :)
>>
> 
> Thanks for taking the time to provide your feedback and insight,

I'll try to give your series a look. I can definitely say that

1) I dislike that an external entity has to do vDIMM adaptions /
ballooning adaptions when rebooting or when wanting to resize a guest.

2) I am not sure ignoring the kvm memory slot limit is a good idea. (or
the fundamental issue of resizing boot memory - ever)

Once you have the current approach upstream (vDIMMs, ballooning), there
is no easy way to change that later (requires deprecating, etc.).

But we talked about that already.

-- 
Thanks,

David / dhildenb




reply via email to

[Prev in Thread] Current Thread [Next in Thread]