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

Dynamic allocation / ballooning memory? #76

Open
adamierymenko opened this issue Jan 5, 2023 · 3 comments
Open

Dynamic allocation / ballooning memory? #76

adamierymenko opened this issue Jan 5, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@adamierymenko
Copy link

Another obvious idea: implement support for minimum and maximum memory and dynamic allocation / ballooning.

@adamierymenko adamierymenko changed the title Ballooning memory? Dynamic allocation / ballooning memory? Jan 5, 2023
@LekKit LekKit added the enhancement New feature or request label Jan 6, 2023
@LekKit
Copy link
Owner

LekKit commented Jan 6, 2023

That's a great idea to implement free page reporting, and that's part of recent versions of Virtio and VMWare balloon devices. I'll look into that (At last a good virtio device with no direct HW replacements, lol). There are also other good memory saving techniques in RVVM: KSM (Page merging, could also reclaim free pages in some cases) and transparent caches (Guest caches may be reclaimed by host).

Be aware however that explicit ballooning on host demand (Initial usecase of Virtio Balloon device) isn't that great of a concept: You force the guest to use less memory, and it most likely will start swapping / will OOM. It is much better to have large amount of virtual memory (zram/swap) on the host - from efficiency standpoint. Otherwise you'll just make pressure on the guest and make it suffer.

@ZLangJIT
Copy link

ZLangJIT commented Oct 1, 2024

#147 (comment)

virtio-balloon is a guest device, and has two separate modes of operation:

* Actual "ballooning" (as implied by the original devie name), where host forces the guest to "reserve" it's physical pages and then reclaims those pages on the host. It's a weird, old mode which is unlikely to ever be implemented in RVVM because it's just badly designed

* Free page reporting: A newer mode, where guests gets to report pages which are **actually** unused, then the VM can zero them without any harm for the guest.

The needed host-specific functionality is already implemented in src/vma_ops.c, specifically vma_clean() function. It works on any OS including Windows. It is also already used to release unused JIT heap space. So it's a matter of writing a virtio-balloon device emulation driver.

It is mostly redundant feature if we consider KSM, but it surely will help non-Linux hosts.

which is what makes it capable of returning unused paged back to the os

eg, its current memory usage without baloon would be its peak usage for the lifetime of the processes due to the vm being unable to tell which parts of any memory it has been requested have been unused (eg freed)

eg free(malloc(10000))

  • when malloc gets done the vm knows only that it has to commit however much more memory to satisfy the kernel request of more memory should it have no memory available to reuse
  • when free gets done the vm does not know if this freed memory will be reused or not so it just keeps it around and and kernel will reuse it as reusable memory instead of requesting more memory
  • when balloon free gets done the vm is notified that this memory will no longer be reused and thus can return it back to the host, which itself may reuse it for further allocations as per free

@ZLangJIT
Copy link

ZLangJIT commented Oct 7, 2024

this may be useful
https://youtu.be/Fq47WCCm-HM

a detailed overview of traditional mem balloon and virtio mem balloon / virtio-pmem / virtio-mem ect (what it is, what it does, how they work, ect)

also details free page hinting and many other features related to guest<->host memory management

some parts can be very detailed and others can lack detail for simplification

virtio related #149

might also be related to #147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

3 participants