export 'available' memory to virtio balloon statistics
Subsystems (6)
PATCH 1/2 calculate 'available' memory in the separate function
In reply to Denis V. LunevFrom: Igor Redko <[email protected]>
Factor out calculation of the available memory counter into a separate exportable function, in order to be able to use it in other parts of the kernel.
In particular, it appears a relevant metric to report to the hypervisor via virtio-balloon statistics interface (in a followup patch).
--- fs/proc/meminfo.c | 31 +------------------------------ include/linux/mm.h | 1 + mm/page_alloc.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 30 deletions(-)
fs/proc/meminfo.c +1 -30
@@ -29,10 +29,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)unsigned long committed;long cached;long available; -unsigned long pagecache; -unsigned long wmark_low =0 ;unsigned long pages[NR_LRU_LISTS ]; -struct zone *zone;int lru;/*
@@ -51,33 +48,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)for (lru =LRU_BASE ; lru <NR_LRU_LISTS ; lru++) pages[lru] =global_page_state (NR_LRU_BASE + lru); -for_each_zone (zone) - wmark_low += zone->watermark[WMARK_LOW ]; - -/* -* Estimate the amount of memory available for userspace allocations, -* without causing swapping. -*/ - available = i.freeram - totalreserve_pages; - -/* -* Not all the page cache can be freed, otherwise the system will -* start swapping. Assume at least half of the page cache, or the -* low watermark worth of cache, needs to stay. -*/ - pagecache = pages[LRU_ACTIVE_FILE ] + pages[LRU_INACTIVE_FILE ]; - pagecache -=min (pagecache /2 , wmark_low); - available += pagecache; - -/* -* Part of the reclaimable slab consists of items that are in use, -* and cannot be freed. Cap this estimate at the low watermark. -*/ - available +=global_page_state (NR_SLAB_RECLAIMABLE ) - -min (global_page_state (NR_SLAB_RECLAIMABLE ) /2 , wmark_low); - -if (available <0 ) - available =0 ; + available =si_mem_available ();/* * Tagged format, for easy grepping and expansion.
include/linux/mm.h +1 -0
@@ -1862,6 +1862,7 @@ extern int __meminit init_per_zone_wmark_min(void);extern void mem_init (void );extern void __init mmap_init (void );extern void show_mem (unsigned int flags); +extern long si_mem_available (void );extern void si_meminfo (struct sysinfo * val);extern void si_meminfo_node (struct sysinfo *val,int nid);
mm/page_alloc.c +43 -0
49 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH 2/2 virtio_balloon: export 'available' memory to balloon statistics
In reply to Denis V. LunevFrom: Igor Redko <[email protected]>
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.
--- drivers/virtio/virtio_balloon.c | 6 ++++++ include/uapi/linux/virtio_balloon.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +6 -0
@@ -30,6 +30,7 @@#include <linux/balloon_compaction.h> #include <linux/oom.h> #include <linux/wait.h> +#include <linux/mm.h> /* * Balloon device works in 4K page units. So each page is pointed to by
@@ -229,10 +230,13 @@ static void update_balloon_stats(struct virtio_balloon *vb)unsigned long events[NR_VM_EVENT_ITEMS ];struct sysinfo i;int idx =0 ; +long available;all_vm_events (events);si_meminfo (&i); + available =si_mem_available (); +update_stat (vb, idx++,VIRTIO_BALLOON_S_SWAP_IN ,pages_to_bytes (events[PSWPIN ])); update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT,
@@ -243,6 +247,8 @@ static void update_balloon_stats(struct virtio_balloon *vb) pages_to_bytes(i.freeram));update_stat (vb, idx++,VIRTIO_BALLOON_S_MEMTOT ,pages_to_bytes (i.totalram)); +update_stat (vb, idx++,VIRTIO_BALLOON_S_AVAIL , +pages_to_bytes (available)); }/*
include/uapi/linux/virtio_balloon.h +2 -1
@@ -51,7 +51,8 @@ struct virtio_balloon_config {#define VIRTIO_BALLOON_S_MINFLT 3/* Number of minor faults */ #define VIRTIO_BALLOON_S_MEMFREE 4/* Total amount of free memory */ #define VIRTIO_BALLOON_S_MEMTOT 5/* Total amount of memory */ -#define VIRTIO_BALLOON_S_NR 6 +#define VIRTIO_BALLOON_S_AVAIL 6/* Available memory as in /proc */ +#define VIRTIO_BALLOON_S_NR 7/* * Memory statistics structure.
Signature · 1 line
2.5.0
PATCH 2/2 virtio_balloon: export 'available' memory to balloon statistics
In reply to Denis V. LunevFrom: Igor Redko <[email protected]>
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.
--- drivers/virtio/virtio_balloon.c | 6 ++++++ include/uapi/linux/virtio_balloon.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +6 -0
@@ -30,6 +30,7 @@#include <linux/balloon_compaction.h> #include <linux/oom.h> #include <linux/wait.h> +#include <linux/mm.h> /* * Balloon device works in 4K page units. So each page is pointed to by
@@ -229,10 +230,13 @@ static void update_balloon_stats(struct virtio_balloon *vb)unsigned long events[NR_VM_EVENT_ITEMS ];struct sysinfo i;int idx =0 ; +long available;all_vm_events (events);si_meminfo (&i); + available =si_mem_available (); +update_stat (vb, idx++,VIRTIO_BALLOON_S_SWAP_IN ,pages_to_bytes (events[PSWPIN ])); update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT,
@@ -243,6 +247,8 @@ static void update_balloon_stats(struct virtio_balloon *vb) pages_to_bytes(i.freeram));update_stat (vb, idx++,VIRTIO_BALLOON_S_MEMTOT ,pages_to_bytes (i.totalram)); +update_stat (vb, idx++,VIRTIO_BALLOON_S_AVAIL , +pages_to_bytes (available)); }/*
include/uapi/linux/virtio_balloon.h +2 -1
@@ -51,7 +51,8 @@ struct virtio_balloon_config {#define VIRTIO_BALLOON_S_MINFLT 3/* Number of minor faults */ #define VIRTIO_BALLOON_S_MEMFREE 4/* Total amount of free memory */ #define VIRTIO_BALLOON_S_MEMTOT 5/* Total amount of memory */ -#define VIRTIO_BALLOON_S_NR 6 +#define VIRTIO_BALLOON_S_AVAIL 6/* Available memory as in /proc */ +#define VIRTIO_BALLOON_S_NR 7/* * Memory statistics structure.
Signature · 1 line
2.5.0
cover export 'available' memory to virtio 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. This metric would be very useful in VM orchestration software to improve memory management of different VMs under overcommit.
Igor Redko (2):
calculate 'available' memory in the separate function
virtio_balloon: export 'available' memory to balloon statistics
drivers/virtio/virtio_balloon.c | 6 ++++++ fs/proc/meminfo.c | 31 +------------------------- include/linux/mm.h | 1 + include/uapi/linux/virtio_balloon.h | 3 ++- mm/page_alloc.c | 43 +++++++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 31 deletions(-)
Signature · 1 line
2.5.0
PATCH 1/2 calculate 'available' memory in the separate function
From: Igor Redko <[email protected]>
Factor out calculation of the available memory counter into a separate exportable function, in order to be able to use it in other parts of the kernel.
In particular, it appears a relevant metric to report to the hypervisor via virtio-balloon statistics interface (in a followup patch).
--- fs/proc/meminfo.c | 31 +------------------------------ include/linux/mm.h | 1 + mm/page_alloc.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 30 deletions(-)
fs/proc/meminfo.c +1 -30
@@ -29,10 +29,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)unsigned long committed;long cached;long available; -unsigned long pagecache; -unsigned long wmark_low =0 ;unsigned long pages[NR_LRU_LISTS ]; -struct zone *zone;int lru;/*
@@ -51,33 +48,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)for (lru =LRU_BASE ; lru <NR_LRU_LISTS ; lru++) pages[lru] =global_page_state (NR_LRU_BASE + lru); -for_each_zone (zone) - wmark_low += zone->watermark[WMARK_LOW ]; - -/* -* Estimate the amount of memory available for userspace allocations, -* without causing swapping. -*/ - available = i.freeram - totalreserve_pages; - -/* -* Not all the page cache can be freed, otherwise the system will -* start swapping. Assume at least half of the page cache, or the -* low watermark worth of cache, needs to stay. -*/ - pagecache = pages[LRU_ACTIVE_FILE ] + pages[LRU_INACTIVE_FILE ]; - pagecache -=min (pagecache /2 , wmark_low); - available += pagecache; - -/* -* Part of the reclaimable slab consists of items that are in use, -* and cannot be freed. Cap this estimate at the low watermark. -*/ - available +=global_page_state (NR_SLAB_RECLAIMABLE ) - -min (global_page_state (NR_SLAB_RECLAIMABLE ) /2 , wmark_low); - -if (available <0 ) - available =0 ; + available =si_mem_available ();/* * Tagged format, for easy grepping and expansion.
include/linux/mm.h +1 -0
@@ -1862,6 +1862,7 @@ extern int __meminit init_per_zone_wmark_min(void);extern void mem_init (void );extern void __init mmap_init (void );extern void show_mem (unsigned int flags); +extern long si_mem_available (void );extern void si_meminfo (struct sysinfo * val);extern void si_meminfo_node (struct sysinfo *val,int nid);
mm/page_alloc.c +43 -0
49 lines not on this page · raw message
Signature · 1 line
2.5.0
Michael S. Tsirkin
maintainerRe: [PATCH 2/2] virtio_balloon: export 'available' memory to balloon statistics
In reply to Denis V. LunevQuoted 5 lines · Denis V. Lunev
From: Igor Redko <[email protected]>
Add a new field,
VIRTIO_BALLOON_S_AVAIL, tovirtio_balloonmemory statistics protocol, corresponding to 'Available' in/proc/meminfo.
Quoted 8 lines
It indicates to the hypervisor how big the balloon can be inflated without pushing the guest system to swap.
Signed-off-by Igor Redko <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Michael S. Tsirkin <[email protected]>CC Andrew Morton <[email protected]>
Oops - I missed the fact that this affects host/guest ABI.
Can you please submit ABI update proposal to virtio tc? Spec patch would be even better.
This is important to ensure there are no conflicts with other features being developed in parallel.
Quoted 56 lines
--- drivers/virtio/virtio_balloon.c | 6 ++++++ include/uapi/linux/virtio_balloon.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-)drivers/virtio/virtio_balloon.c +6
-0@@ -30,6 +30,7 @@#include <linux/balloon_compaction.h> #include <linux/oom.h> #include <linux/wait.h> +#include <linux/mm.h> /* * Balloon device works in 4K page units. So each page is pointed to by @@ -229,10 +230,13 @@ static void update_balloon_stats(struct virtio_balloon *vb)unsigned long events[NR_VM_EVENT_ITEMS ];struct sysinfo i;int idx =0 ; +long available;all_vm_events (events);si_meminfo (&i); + available =si_mem_available (); +update_stat (vb, idx++,VIRTIO_BALLOON_S_SWAP_IN ,pages_to_bytes (events[PSWPIN ])); update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT,@@ -243,6 +247,8 @@ static void update_balloon_stats(struct virtio_balloon *vb) pages_to_bytes(i.freeram));update_stat (vb, idx++,VIRTIO_BALLOON_S_MEMTOT ,pages_to_bytes (i.totalram)); +update_stat (vb, idx++,VIRTIO_BALLOON_S_AVAIL , +pages_to_bytes (available)); }/* include/uapi/linux/virtio_balloon.h +2
-1@@ -51,7 +51,8 @@ struct virtio_balloon_config {#define VIRTIO_BALLOON_S_MINFLT 3/* Number of minor faults */ #define VIRTIO_BALLOON_S_MEMFREE 4/* Total amount of free memory */ #define VIRTIO_BALLOON_S_MEMTOT 5/* Total amount of memory */ -#define VIRTIO_BALLOON_S_NR 6 +#define VIRTIO_BALLOON_S_AVAIL 6/* Available memory as in /proc */ +#define VIRTIO_BALLOON_S_NR 7/* * Memory statistics structure. Signature · 1 line
2.5.0
Michael S. Tsirkin
maintainerRe: [PATCH 2/2] virtio_balloon: export 'available' memory to balloon statistics
In reply to Denis V. LunevQuoted 5 lines · Denis V. Lunev
From: Igor Redko <[email protected]>
Add a new field,
VIRTIO_BALLOON_S_AVAIL, tovirtio_balloonmemory statistics protocol, corresponding to 'Available' in/proc/meminfo.
Quoted 8 lines
It indicates to the hypervisor how big the balloon can be inflated without pushing the guest system to swap.
Signed-off-by Igor Redko <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Michael S. Tsirkin <[email protected]>CC Andrew Morton <[email protected]>
Oops - I missed the fact that this affects host/guest ABI.
Can you please submit ABI update proposal to virtio tc? Spec patch would be even better.
This is important to ensure there are no conflicts with other features being developed in parallel.
Quoted 56 lines
--- drivers/virtio/virtio_balloon.c | 6 ++++++ include/uapi/linux/virtio_balloon.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-)drivers/virtio/virtio_balloon.c +6
-0@@ -30,6 +30,7 @@#include <linux/balloon_compaction.h> #include <linux/oom.h> #include <linux/wait.h> +#include <linux/mm.h> /* * Balloon device works in 4K page units. So each page is pointed to by @@ -229,10 +230,13 @@ static void update_balloon_stats(struct virtio_balloon *vb)unsigned long events[NR_VM_EVENT_ITEMS ];struct sysinfo i;int idx =0 ; +long available;all_vm_events (events);si_meminfo (&i); + available =si_mem_available (); +update_stat (vb, idx++,VIRTIO_BALLOON_S_SWAP_IN ,pages_to_bytes (events[PSWPIN ])); update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT,@@ -243,6 +247,8 @@ static void update_balloon_stats(struct virtio_balloon *vb) pages_to_bytes(i.freeram));update_stat (vb, idx++,VIRTIO_BALLOON_S_MEMTOT ,pages_to_bytes (i.totalram)); +update_stat (vb, idx++,VIRTIO_BALLOON_S_AVAIL , +pages_to_bytes (available)); }/* include/uapi/linux/virtio_balloon.h +2
-1@@ -51,7 +51,8 @@ struct virtio_balloon_config {#define VIRTIO_BALLOON_S_MINFLT 3/* Number of minor faults */ #define VIRTIO_BALLOON_S_MEMFREE 4/* Total amount of free memory */ #define VIRTIO_BALLOON_S_MEMTOT 5/* Total amount of memory */ -#define VIRTIO_BALLOON_S_NR 6 +#define VIRTIO_BALLOON_S_AVAIL 6/* Available memory as in /proc */ +#define VIRTIO_BALLOON_S_NR 7/* * Memory statistics structure. Signature · 1 line
2.5.0
Re: [PATCH 2/2] virtio_balloon: export 'available' memory to balloon statistics
Quoted 14 lines · Michael S. Tsirkin
Quoted 5 lines · Denis V. Lunev
From: Igor Redko <[email protected]>
Add a new field,
VIRTIO_BALLOON_S_AVAIL, tovirtio_balloonmemory statistics protocol, corresponding to 'Available' in/proc/meminfo.Quoted 8 lines
It indicates to the hypervisor how big the balloon can be inflated without pushing the guest system to swap.
Signed-off-by Igor Redko <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Michael S. Tsirkin <[email protected]>CC Andrew Morton <[email protected]>
Quoted 7 lines
Oops - I missed the fact that this affects host/guest ABI.
Can you please submit ABI update proposal to virtio tc? Spec patch would be even better.
This is important to ensure there are no conflicts with other features being developed in parallel.
hmmm
From my point of view ABI remains untouched.
The guest can send any amount of <tag>;<value>
pairs and unknown tags are properly ignored
by the host.
That is why I think that this change is safe.
Re: [PATCH 2/2] virtio_balloon: export 'available' memory to balloon statistics
In reply to Michael S. TsirkinQuoted 14 lines · Michael S. Tsirkin
Quoted 5 lines · Denis V. Lunev
From: Igor Redko <[email protected]>
Add a new field,
VIRTIO_BALLOON_S_AVAIL, tovirtio_balloonmemory statistics protocol, corresponding to 'Available' in/proc/meminfo.Quoted 8 lines
It indicates to the hypervisor how big the balloon can be inflated without pushing the guest system to swap.
Signed-off-by Igor Redko <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Michael S. Tsirkin <[email protected]>CC Andrew Morton <[email protected]>
Quoted 7 lines
Oops - I missed the fact that this affects host/guest ABI.
Can you please submit ABI update proposal to virtio tc? Spec patch would be even better.
This is important to ensure there are no conflicts with other features being developed in parallel.
hmmm
From my point of view ABI remains untouched.
The guest can send any amount of <tag>;<value>
pairs and unknown tags are properly ignored
by the host.
That is why I think that this change is safe.
Michael S. Tsirkin
maintainerRe: [PATCH 2/2] virtio_balloon: export 'available' memory to balloon statistics
Quoted 20 lines · Denis V. Lunev
Quoted 19 lines · Michael S. Tsirkin
Quoted 5 lines · Denis V. Lunev
From: Igor Redko <[email protected]>
Add a new field,
VIRTIO_BALLOON_S_AVAIL, tovirtio_balloonmemory statistics protocol, corresponding to 'Available' in/proc/meminfo.Quoted 8 lines
It indicates to the hypervisor how big the balloon can be inflated without pushing the guest system to swap.
Signed-off-by Igor Redko <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Michael S. Tsirkin <[email protected]>CC Andrew Morton <[email protected]>Oops - I missed the fact that this affects host/guest ABI.
Can you please submit ABI update proposal to virtio tc? Spec patch would be even better.
Quoted 6 lines
Quoted 2 lines
This is important to ensure there are no conflicts with other features being developed in parallel.
hmmm
From my point of view ABI remains untouched.
Anything exposed by guest to host is ABI.
Once we add stuff there, we never can remove it
as some host might rely on it.
Quoted 5 lines
The guest can send any amount of <tag>;<value>
pairs and unknown tags are properly ignored
by the host.That is why I think that this change is safe.
What happens if someone uses the tag you
used for VIRTIO_BALLOON_S_AVAIL, for some
other purpose?
Any tools using VIRTIO_BALLOON_S_AVAIL will be confused.
Really, it's not hard to get a tag number from virtio TC, so please just do this.
Signature · 1 line
MST
Re: [PATCH 2/2] virtio_balloon: export 'available' memory to balloon statistics
Quoted 34 lines · Michael S. Tsirkin
Quoted 17 lines · Denis V. Lunev
Quoted 16 lines · Michael S. Tsirkin
Quoted 5 lines · Denis V. Lunev
From: Igor Redko <[email protected]>
Add a new field,
VIRTIO_BALLOON_S_AVAIL, tovirtio_balloonmemory statistics protocol, corresponding to 'Available' in/proc/meminfo.Quoted 8 lines
It indicates to the hypervisor how big the balloon can be inflated without pushing the guest system to swap.
Signed-off-by Igor Redko <[email protected]>Reviewed-by Roman Kagan <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Michael S. Tsirkin <[email protected]>CC Andrew Morton <[email protected]>Oops - I missed the fact that this affects host/guest ABI.
Quoted 8 lines
Quoted 5 lines
Can you please submit ABI update proposal to virtio tc? Spec patch would be even better.
This is important to ensure there are no conflicts with other features being developed in parallel.
hmmm
From my point of view ABI remains untouched.
Anything exposed by guest to host is ABI.
Once we add stuff there, we never can remove it
as some host might rely on it.Quoted 4 lines
The guest can send any amount of <tag>;<value>
pairs and unknown tags are properly ignored
by the host.
Quoted 5 lines
Quoted 1 line
That is why I think that this change is safe.
What happens if someone uses the tag you
used forVIRTIO_BALLOON_S_AVAIL, for some
other purpose?
Any tools usingVIRTIO_BALLOON_S_AVAILwill be confused.
actually this constant resides in QEMU only, values are reported above using JSON and
string tags.
Quoted 3 lines
Really, it's not hard to get a tag number from virtio TC, so please just do this.
ok. So do you propose to negotiate maximum allowed tag to send at the driver start time?
we will have to guard this exchange with proper flag in feature space then. This could be done but from my point of view this looks like serious over-complication. Do we have somebody who can judge?
Den