aboutsummaryrefslogtreecommitdiffstats
path: root/patches/damon/next/drivers-virtio-virtio_balloon-integrate-ACMA-and-bal.patch
blob: 3518643c217e8d586d87d67cccd2c0c9559c9a74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
From bc4456c66d21bafbd5a794918117efa36557be16 Mon Sep 17 00:00:00 2001
From: SeongJae Park <sj@kernel.org>
Date: Wed, 28 Feb 2024 16:17:08 -0800
Subject: [PATCH] drivers/virtio/virtio_balloon: integrate ACMA and ballooning

This is just an idea.

Signed-off-by: SeongJae Park <sj@kernel.org>
---
 drivers/virtio/virtio_balloon.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 1f5b3dd31fcf..a954d75789ae 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);
-- 
2.39.2