lkml.org 
[lkml]   [2022]   [Aug]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v1 2/2] Drivers: virtio: balloon: Report inflated memory
Date
Update the value in page_alloc on balloon fill/leak.

Cc: David Hildenbrand <david@redhat.com>
Cc: Wei Liu <wei.liu@kernel.org>
Cc: Nadav Amit <namit@vmware.com>

Signed-off-by: Alexander Atanasov <alexander.atanasov@virtuozzo.com>
---
drivers/virtio/virtio_balloon.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

Firts user, other balloons i will do if it is accepted to avoid too much emails.


diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index b9737da6c4dd..e2693ffbd48b 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -208,6 +208,16 @@ static void set_page_pfns(struct virtio_balloon *vb,
page_to_balloon_pfn(page) + i);
}

+static void update_meminfo(struct virtio_balloon *vb)
+{
+ long inflated_kb = vb->num_pages << (VIRTIO_BALLOON_PFN_SHIFT - 10);
+
+ if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
+ inflated_kb = -inflated_kb;
+
+ atomic_long_set(&mem_balloon_inflated_kb, inflated_kb);
+}
+
static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
{
unsigned int num_allocated_pages;
@@ -250,6 +260,7 @@ static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
}

num_allocated_pages = vb->num_pfns;
+ update_meminfo(vb);
/* Did we get any? */
if (vb->num_pfns != 0)
tell_host(vb, vb->inflate_vq);
@@ -296,6 +307,7 @@ static unsigned int leak_balloon(struct virtio_balloon *vb, size_t num)
}

num_freed_pages = vb->num_pfns;
+ update_meminfo(vb);
/*
* Note that if
* virtio_has_feature(vdev, VIRTIO_BALLOON_F_MUST_TELL_HOST);
@@ -1089,6 +1101,7 @@ static void virtballoon_remove(struct virtio_device *vdev)

kern_unmount(balloon_mnt);
#endif
+ update_meminfo(0);
kfree(vb);
}

--
2.31.1
\
 
 \ /
  Last update: 2022-08-09 11:55    [W:0.210 / U:0.812 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site