Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

virtio_balloon: export 'available' memory to balloon statistics

Add a new field, VIRTIO_BALLOON_S_AVAIL, to virtio_balloon memory
statistics protocol, corresponding to 'Available' in /proc/meminfo.

It indicates to the hypervisor how big the balloon can be inflated
without pushing the guest system to swap.

Signed-off-by: Igor Redko <redkoi@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Igor Redko and committed by
Linus Torvalds
5057dcd0 d02bd27b

+8 -1
+6
drivers/virtio/virtio_balloon.c
··· 30 30 #include <linux/balloon_compaction.h> 31 31 #include <linux/oom.h> 32 32 #include <linux/wait.h> 33 + #include <linux/mm.h> 33 34 34 35 /* 35 36 * Balloon device works in 4K page units. So each page is pointed to by ··· 230 229 unsigned long events[NR_VM_EVENT_ITEMS]; 231 230 struct sysinfo i; 232 231 int idx = 0; 232 + long available; 233 233 234 234 all_vm_events(events); 235 235 si_meminfo(&i); 236 + 237 + available = si_mem_available(); 236 238 237 239 update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN, 238 240 pages_to_bytes(events[PSWPIN])); ··· 247 243 pages_to_bytes(i.freeram)); 248 244 update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMTOT, 249 245 pages_to_bytes(i.totalram)); 246 + update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL, 247 + pages_to_bytes(available)); 250 248 } 251 249 252 250 /*
+2 -1
include/uapi/linux/virtio_balloon.h
··· 51 51 #define VIRTIO_BALLOON_S_MINFLT 3 /* Number of minor faults */ 52 52 #define VIRTIO_BALLOON_S_MEMFREE 4 /* Total amount of free memory */ 53 53 #define VIRTIO_BALLOON_S_MEMTOT 5 /* Total amount of memory */ 54 - #define VIRTIO_BALLOON_S_NR 6 54 + #define VIRTIO_BALLOON_S_AVAIL 6 /* Available memory as in /proc */ 55 + #define VIRTIO_BALLOON_S_NR 7 55 56 56 57 /* 57 58 * Memory statistics structure.