Re: [PATCH 2/2] Drivers: hv: Add Hyper-V balloon driver

Andrew Morton
2012-10-10T23:56:20Z

On Wed, 10 Oct 2012 16:34:37 -0700
Jeremy Fitzhardinge <jeremy@goop.org> wrote:

> On 10/09/2012 06:14 PM, Andrew Morton wrote:
> > On Wed, 10 Oct 2012 00:09:12 +0000 KY Srinivasan <kys@microsoft.com> wrote:
> >
> >>>> + if (!pg) {
> >>>> + *alloc_error = true;
> >>>> + return i * alloc_unit;
> >>>> + }
> >>>> +
> >>>> + totalram_pages -= alloc_unit;
> >>> Well, I'd consider totalram_pages to be an mm-private thing which drivers
> >>> shouldn't muck with. Why is this done?
> >> By modifying the totalram_pages, the information presented in /proc/meminfo
> >> correctly reflects what is currently assigned to the guest (MemTotal).
> > eh? /proc/meminfo:MemTotal tells you the total memory in the machine.
> > The only thing which should change it after boot is memory hotplug.
> [...]
> > Why on earth do balloon drivers do this? If the amount of memory which
> > is consumed by balloons is interesting then it should be exported via a
> > standalone metric, not by mucking with totalram_pages.
>
> Balloon drivers are trying to fake a form of page-by-page memory
> hotplug. When they allocate memory from the kernel, they're actually
> giving the pages back to the hypervisor to redistribute to other
> guests. They reduce totalram_pages to try and reflect that the memory
> is no longer the kernel (in Xen, at least, the pfns will no longer have
> any physical page underlying them).
>
> I agree this is pretty ugly; it would be nice to have some better
> interface to indicate what's going on. At one point I tried to use the
> memory hotplug interfaces for larger-scale dynamic transfers of memory
> between a domain and the host, but when I last looked at it, it was too
> coarse grained and heavyweight to replace the balloon mechanism.
>

urgh.

I suppose the least we can do here would be to stop directly dinking
with totalram_pages and create some sort of interface for this
operation. That interface would run the memory hotplug notifier so
that code which cares about changes in the amount of physical memory
can take appropriate steps. The implications would be that the balloon
drivers would need to call this interface at low frequency (ie: batch
the pages) and in some reasonably lock-free context.

I guess that's solving a non-problem at this stage.