diff options
author | SeongJae Park <sj@kernel.org> | 2024-02-28 16:17:08 -0800 |
---|---|---|
committer | SeongJae Park <sj@kernel.org> | 2024-05-18 08:31:22 -0700 |
commit | 33b06a4b024a00420ad8e09499ee1720e19e50e8 (patch) | |
tree | 29aae1e5a19b06a6e116ea628e49418887a64971 | |
parent | 456b3116c202bb51256981d13b120fc22abbdb25 (diff) | |
download | linux-damon/next.tar.gz |
drivers/virtio/virtio_balloon: integrate ACMA and ballooningdamon/next
Let the host effectively inflate the balloon in access/contiguity-aware
way when the guest kernel is compiled with specific kernel config. When
the config is enabled and the host requests balloon size change,
virtio-balloon adjusts ACMA's max-mem parameter instead of allocating
guest pages and put it into the balloon. As a result, the host can use
the requested amount of guest memory, so from the host's perspective,
the ballooning just works, but in transparent and
access/contiguity-aware way.
Signed-off-by: SeongJae Park <sj@kernel.org>
-rw-r--r-- | drivers/virtio/virtio_balloon.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 1f5b3dd31fcfc..a954d75789aed 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c @@ -472,6 +472,32 @@ static void virtballoon_changed(struct virtio_device *vdev) struct virtio_balloon *vb = vdev->priv; unsigned long flags; +#ifdef CONFIG_ACMA_BALLOON + s64 target; + u32 num_pages; + + + /* Legacy balloon config space is LE, unlike all other devices. */ + virtio_cread_le(vb->vdev, struct virtio_balloon_config, num_pages, + &num_pages); + + /* + * Aligned up to guest page size to avoid inflating and deflating + * balloon endlessly. + */ + target = ALIGN(num_pages, VIRTIO_BALLOON_PAGES_PER_PAGE); + + /* + * If the given new max mem size is larger than current acma's max mem + * size, same to normal max mem adjustment. + * If the given new max mem size is smaller than current acma's max mem + * size, strong aggressiveness is applied while memory for meeting the + * new max mem is met is stolen. + */ + acma_set_max_mem_aggressive(totalram_pages() - target); + return; +#endif + spin_lock_irqsave(&vb->stop_update_lock, flags); if (!vb->stop_update) { start_update_balloon_size(vb); |