Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtio-balloon: prioritize most recently used memory when inflating the balloon #2085

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

francescolavra
Copy link
Member

When inflating the memory balloon to decrease host memory usage, the existing code is not effective in finding previously-used memory areas (which usually are memory ranges that have been unmapped by the user program, or pages that have been evicted from the page cache, and correspond to memory ranges that have actually been populated in the host machine); as a result, balloon inflation does not allow the host hypervisor to significantly decrease its memory usage.
This change fixes the above issue by:

  1. introducing a new heap type that implements a buddy memory allocator and using it as physical memory heap
  2. modifying the balloon driver so that it allocates minimum-sized pages when inflating the balloon; this, thanks to the MRU allocation policy of the buddy memory allocator, allows finding previously-used memory areas, which the hypervisor can then release to the host OS

Using a buddy memory allocator as physical memory heap brings the following improvements:

  • lower memory fragmentation: the buddy allocator keeps track of free contiguous memory areas of each power-of-2 size, and when allocating a requested size, uses a minimum-sized free area to satisfy the request
  • higher memory re-use (which maximizes TLB hit rate and minimizes host memory usage): when there are multiple minimum-sized memory areas available to satisfy an allocation request, the buddy allocator selects the most recently used area
  • higher scalability: the buddy allocator does not rely on linear searches on a given memory range to select a free area; therefore, the average CPU use to execute allocation requests does not increase with the size of physical memory

The typical overhead of the buddy allocator is around 0.1%, i.e. 99.9% of the physical memory available for a VM can be used for kernel and user program allocations.

This struct member is unused and can be removed.
This will allow spinlock code to be compiled for both kernel and
non-kernel usage without having to use `#ifdef KERNEL` directives.
This change introduces a new heap type that implements a buddy
memory allocator and is now used as physical memory heap; this
brings the following improvements:
- lower memory fragmentation: the buddy allocator keeps track of
free contiguous memory areas of each power-of-2 size, and when
allocating a requested size, uses a minimum-sized free area to
satisfy the request
- higher memory re-use (which maximizes TLB hit rate and minimizes
host memory usage): when there are multiple minimum-sized memory
areas available to satisfy an allocation request, the buddy
allocator selects the most recently used area
- higher scalability: the buddy allocator does not rely on linear
searches on a given memory range to select a free area; therefore,
the average CPU use to execute allocation requests does not
increase with the size of physical memory

The typical overhead of the buddy allocator is around 0.1%, i.e.
99.9% of the physical memory available for a VM can be used for
kernel and user program allocations.
The size of the bootstrap heap does no longer depend on the size
of physical memory, therefore calculation of the memory size is no
longer done when unneeded, and the bootstrap heap is set up in
common code instead of platform-specific code.
The PAGEHEAP_LOWMEM_PAGESIZE constant now sets the upper limit for
physical memory allocation requests on low-memory guests, and has
been changed to 1 MB to be able to allocate the async queue used by
the scheduler.
The `pages` kernel heap is now a simple wrapper (whose purpose is
to avoid complete exhaustion of physical memory) around the
page-backed heap, and is used by both the pagecache and the mmap
code.
When inflating the memory balloon to decrease host memory usage,
allocating large-sized pages from the physical memory heap is
usually not effective in finding previously-used memory areas
(which usually are memory ranges that have been unmapped by the
user program, or pages that have been evicted from the page cache,
and correspond to memory ranges that have actually been populated
in the host machine); as a result, balloon inflation does not allow
the host hypervisor to significantly decrease its memory usage.
This change fixes the above issue by modifying the balloon driver
so that it allocates minimum-sized pages when inflating the
balloon; this, thanks to the MRU allocation policy of the buddy
memory allocator, allows finding previously-used memory areas,
which the hypervisor can then release to the host OS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant