Skip to contentSkip to conversation

linux: Buffers/caches in VirtIO Balloon driver stats

PATCH Superseded Tomáš Golembiovský 2 participants 17 messages Sep 21, 2017 – Nov 3, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover linux: Buffers/caches in VirtIO Balloon driver stats

Linux driver part

v2:
- fixed typos

Tomáš Golembiovský (1):
virtio_balloon: include buffers and cached memory statistics

 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
Signature · 7 lines
2.14.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH v2 1/1 virtio_balloon: include buffers and cached memory statistics

Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo.

To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules.

---
 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +11 -0
index f0b3a0b9d42f..c2558ec47a62 100644
@@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 	struct sysinfo i;
 	unsigned int idx = 0;
 	long available;
+	long cached;
 
 	all_vm_events(events);
 	si_meminfo(&i);
 
 	available = si_mem_available();
 
+	cached = global_node_page_state(NR_FILE_PAGES) -
+			total_swapcache_pages() - i.bufferram;
+	if (cached < 0)
+		cached = 0;
+
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
 				pages_to_bytes(events[PSWPIN]));
@@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 				pages_to_bytes(i.totalram));
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
 				pages_to_bytes(available));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS,
+				pages_to_bytes(i.bufferram));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED,
+				pages_to_bytes(cached));
 
 	return idx;
 }
include/uapi/linux/virtio_balloon.h +3 -1
index 343d7ddefe04..d5dc8a56a497 100644
@@ -52,7 +52,9 @@ struct virtio_balloon_config {
 #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_AVAIL    6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR       7
+#define VIRTIO_BALLOON_S_BUFFERS  7   /* Buffers memory as in /proc */
+#define VIRTIO_BALLOON_S_CACHED   8   /* Cached memory as in /proc */
+#define VIRTIO_BALLOON_S_NR       9
 
 /*
  * Memory statistics structure.
mm/swap_state.c +1 -0
index 71ce2d1ccbf7..f3a4ff7d6c52 100644
@@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void)
 	rcu_read_unlock();
 	return ret;
 }
+EXPORT_SYMBOL_GPL(total_swapcache_pages);
 
 static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);
 
Signature · 7 lines
2.14.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

Quoted 8 lines · Tomáš Golembiovský

Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo.

To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules.

Does 'Buffers' actually make sense? It's a temporary storage - wouldn't it be significantly out of date by the time host receives it?

Quoted 61 lines
---
 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +11 -0
index f0b3a0b9d42f..c2558ec47a62 100644
@@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 	struct sysinfo i;
 	unsigned int idx = 0;
 	long available;
+	long cached;
 
 	all_vm_events(events);
 	si_meminfo(&i);
 
 	available = si_mem_available();
 
+	cached = global_node_page_state(NR_FILE_PAGES) -
+			total_swapcache_pages() - i.bufferram;
+	if (cached < 0)
+		cached = 0;
+
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
 				pages_to_bytes(events[PSWPIN]));
@@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 				pages_to_bytes(i.totalram));
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
 				pages_to_bytes(available));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS,
+				pages_to_bytes(i.bufferram));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED,
+				pages_to_bytes(cached));
 
 	return idx;
 }
include/uapi/linux/virtio_balloon.h +3 -1
index 343d7ddefe04..d5dc8a56a497 100644
@@ -52,7 +52,9 @@ struct virtio_balloon_config {
 #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_AVAIL    6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR       7
+#define VIRTIO_BALLOON_S_BUFFERS  7   /* Buffers memory as in /proc */
+#define VIRTIO_BALLOON_S_CACHED   8   /* Cached memory as in /proc */
+#define VIRTIO_BALLOON_S_NR       9
 
 /*
  * Memory statistics structure.
mm/swap_state.c +0 -0
index 71ce2d1ccbf7..f3a4ff7d6c52 100644

mm/swap_state.c unsigned long total_swapcache_pages(void) · line 100

Quoted 6 lines
mm/swap_state.c +1 -0
@@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void)
 	rcu_read_unlock();
 	return ret;
 }
+EXPORT_SYMBOL_GPL(total_swapcache_pages);
 
 static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);

Need an ack from MM crowd on that.

Quoted 2 lines
Signature · 1 line
2.14.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#3 lore raw

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

In reply to Tomáš Golembiovský
Quoted 8 lines · Tomáš Golembiovský

Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo.

To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules.

Does 'Buffers' actually make sense? It's a temporary storage - wouldn't it be significantly out of date by the time host receives it?

Quoted 61 lines
---
 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +11 -0
index f0b3a0b9d42f..c2558ec47a62 100644
@@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 	struct sysinfo i;
 	unsigned int idx = 0;
 	long available;
+	long cached;
 
 	all_vm_events(events);
 	si_meminfo(&i);
 
 	available = si_mem_available();
 
+	cached = global_node_page_state(NR_FILE_PAGES) -
+			total_swapcache_pages() - i.bufferram;
+	if (cached < 0)
+		cached = 0;
+
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
 				pages_to_bytes(events[PSWPIN]));
@@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 				pages_to_bytes(i.totalram));
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
 				pages_to_bytes(available));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS,
+				pages_to_bytes(i.bufferram));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED,
+				pages_to_bytes(cached));
 
 	return idx;
 }
include/uapi/linux/virtio_balloon.h +3 -1
index 343d7ddefe04..d5dc8a56a497 100644
@@ -52,7 +52,9 @@ struct virtio_balloon_config {
 #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_AVAIL    6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR       7
+#define VIRTIO_BALLOON_S_BUFFERS  7   /* Buffers memory as in /proc */
+#define VIRTIO_BALLOON_S_CACHED   8   /* Cached memory as in /proc */
+#define VIRTIO_BALLOON_S_NR       9
 
 /*
  * Memory statistics structure.
mm/swap_state.c +0 -0
index 71ce2d1ccbf7..f3a4ff7d6c52 100644

mm/swap_state.c unsigned long total_swapcache_pages(void) · line 100

Quoted 6 lines
mm/swap_state.c +1 -0
@@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void)
 	rcu_read_unlock();
 	return ret;
 }
+EXPORT_SYMBOL_GPL(total_swapcache_pages);
 
 static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);

Need an ack from MM crowd on that.

Quoted 2 lines
Signature · 1 line
2.14.1
#4 lore raw

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

Quoted 5 lines · On Thu, 19 Oct 2017 16:12:20 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 4 lines · Tomáš Golembiovský

Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo.

Quoted 8 lines
Quoted 4 lines

To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules.

Does 'Buffers' actually make sense? It's a temporary storage - wouldn't it be significantly out of date by the time host receives it?

That would be best answered by somebody from kernel. But my personal opinion is that it would not be out of date. The amount of memory dedicated to Buffers does not seem to fluctuate too much.

Tomas

Quoted 72 lines
Quoted 61 lines
---
 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +11 -0
index f0b3a0b9d42f..c2558ec47a62 100644
@@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 	struct sysinfo i;
 	unsigned int idx = 0;
 	long available;
+	long cached;
 
 	all_vm_events(events);
 	si_meminfo(&i);
 
 	available = si_mem_available();
 
+	cached = global_node_page_state(NR_FILE_PAGES) -
+			total_swapcache_pages() - i.bufferram;
+	if (cached < 0)
+		cached = 0;
+
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
 				pages_to_bytes(events[PSWPIN]));
@@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 				pages_to_bytes(i.totalram));
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
 				pages_to_bytes(available));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS,
+				pages_to_bytes(i.bufferram));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED,
+				pages_to_bytes(cached));
 
 	return idx;
 }
include/uapi/linux/virtio_balloon.h +3 -1
index 343d7ddefe04..d5dc8a56a497 100644
@@ -52,7 +52,9 @@ struct virtio_balloon_config {
 #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_AVAIL    6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR       7
+#define VIRTIO_BALLOON_S_BUFFERS  7   /* Buffers memory as in /proc */
+#define VIRTIO_BALLOON_S_CACHED   8   /* Cached memory as in /proc */
+#define VIRTIO_BALLOON_S_NR       9
 
 /*
  * Memory statistics structure.
mm/swap_state.c +0 -0
index 71ce2d1ccbf7..f3a4ff7d6c52 100644

mm/swap_state.c unsigned long total_swapcache_pages(void) · line 100

Quoted 6 lines
mm/swap_state.c +1 -0
@@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void)
 	rcu_read_unlock();
 	return ret;
 }
+EXPORT_SYMBOL_GPL(total_swapcache_pages);
 
 static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);

Need an ack from MM crowd on that.

Quoted 2 lines
Signature · 1 line
2.14.1
Signature · 1 line
Tomáš Golembiovský <[email protected]>
#5 lore raw

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

ping

+Gil, +Amnon... could you maybe aid in reviewing the patch, please?

Tomas

Quoted 100 lines · On Sun, 22 Oct 2017 20:05:57 +0200 Tomáš Golembiovský <[email protected]>…
Quoted 5 lines · On Thu, 19 Oct 2017 16:12:20 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 4 lines · Tomáš Golembiovský

Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo.

Quoted 8 lines
Quoted 4 lines

To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules.

Does 'Buffers' actually make sense? It's a temporary storage - wouldn't it be significantly out of date by the time host receives it?

That would be best answered by somebody from kernel. But my personal opinion is that it would not be out of date. The amount of memory dedicated to Buffers does not seem to fluctuate too much.

Tomas

Quoted 72 lines
Quoted 61 lines
---
 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +11 -0
index f0b3a0b9d42f..c2558ec47a62 100644
@@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 	struct sysinfo i;
 	unsigned int idx = 0;
 	long available;
+	long cached;
 
 	all_vm_events(events);
 	si_meminfo(&i);
 
 	available = si_mem_available();
 
+	cached = global_node_page_state(NR_FILE_PAGES) -
+			total_swapcache_pages() - i.bufferram;
+	if (cached < 0)
+		cached = 0;
+
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
 				pages_to_bytes(events[PSWPIN]));
@@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 				pages_to_bytes(i.totalram));
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
 				pages_to_bytes(available));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS,
+				pages_to_bytes(i.bufferram));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED,
+				pages_to_bytes(cached));
 
 	return idx;
 }
include/uapi/linux/virtio_balloon.h +3 -1
index 343d7ddefe04..d5dc8a56a497 100644
@@ -52,7 +52,9 @@ struct virtio_balloon_config {
 #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_AVAIL    6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR       7
+#define VIRTIO_BALLOON_S_BUFFERS  7   /* Buffers memory as in /proc */
+#define VIRTIO_BALLOON_S_CACHED   8   /* Cached memory as in /proc */
+#define VIRTIO_BALLOON_S_NR       9
 
 /*
  * Memory statistics structure.
mm/swap_state.c +0 -0
index 71ce2d1ccbf7..f3a4ff7d6c52 100644

mm/swap_state.c unsigned long total_swapcache_pages(void) · line 100

Quoted 6 lines
mm/swap_state.c +1 -0
@@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void)
 	rcu_read_unlock();
 	return ret;
 }
+EXPORT_SYMBOL_GPL(total_swapcache_pages);
 
 static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);  

Need an ack from MM crowd on that.

Quoted 2 lines
mm/swap_state.c +0 -1
-- 

2.14.1

Signature · 1 line
Tomáš Golembiovský <[email protected]>
Signature · 7 lines
Tomáš Golembiovský <[email protected]>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#6 lore raw

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

Quoted 33 lines · Tomáš Golembiovský

ping

+Gil, +Amnon... could you maybe aid in reviewing the patch, please?

Tomas

Quoted 23 lines · On Sun, 22 Oct 2017 20:05:57 +0200 Tomáš Golembiovský <[email protected]>…
Quoted 5 lines · On Thu, 19 Oct 2017 16:12:20 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 4 lines · Tomáš Golembiovský

Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo.

Quoted 8 lines
Quoted 4 lines

To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules.

Does 'Buffers' actually make sense? It's a temporary storage - wouldn't it be significantly out of date by the time host receives it?

That would be best answered by somebody from kernel. But my personal opinion is that it would not be out of date. The amount of memory dedicated to Buffers does not seem to fluctuate too much.

Tomas

I would be inclined to say, just report
global_node_page_state(NR_FILE_PAGES).
Maybe subtract buffer ram.

It's not clear host cares about the distinction,
it's all memory that can shrink in response to
memory pressure such as inflating the balloon.

This statistic is portable as well I think, most guests have storage cache.

Quoted 70 lines
Quoted 70 lines
Quoted 70 lines
Quoted 61 lines
---
 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +11 -0
index f0b3a0b9d42f..c2558ec47a62 100644
@@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 	struct sysinfo i;
 	unsigned int idx = 0;
 	long available;
+	long cached;
 
 	all_vm_events(events);
 	si_meminfo(&i);
 
 	available = si_mem_available();
 
+	cached = global_node_page_state(NR_FILE_PAGES) -
+			total_swapcache_pages() - i.bufferram;
+	if (cached < 0)
+		cached = 0;
+
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
 				pages_to_bytes(events[PSWPIN]));
@@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 				pages_to_bytes(i.totalram));
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
 				pages_to_bytes(available));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS,
+				pages_to_bytes(i.bufferram));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED,
+				pages_to_bytes(cached));
 
 	return idx;
 }
include/uapi/linux/virtio_balloon.h +3 -1
index 343d7ddefe04..d5dc8a56a497 100644
@@ -52,7 +52,9 @@ struct virtio_balloon_config {
 #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_AVAIL    6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR       7
+#define VIRTIO_BALLOON_S_BUFFERS  7   /* Buffers memory as in /proc */
+#define VIRTIO_BALLOON_S_CACHED   8   /* Cached memory as in /proc */
+#define VIRTIO_BALLOON_S_NR       9
 
 /*
  * Memory statistics structure.
mm/swap_state.c +0 -0
index 71ce2d1ccbf7..f3a4ff7d6c52 100644

mm/swap_state.c unsigned long total_swapcache_pages(void) · line 100

Quoted 6 lines
mm/swap_state.c +1 -0
@@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void)
 	rcu_read_unlock();
 	return ret;
 }
+EXPORT_SYMBOL_GPL(total_swapcache_pages);
 
 static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);  

Need an ack from MM crowd on that.

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
mm/swap_state.c +0 -1
-- 

2.14.1

Signature · 1 line
Tomáš Golembiovský <[email protected]>
Signature · 1 line
Tomáš Golembiovský <[email protected]>

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#7 lore raw

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

In reply to Tomáš Golembiovský
Quoted 33 lines · Tomáš Golembiovský

ping

+Gil, +Amnon... could you maybe aid in reviewing the patch, please?

Tomas

Quoted 23 lines · On Sun, 22 Oct 2017 20:05:57 +0200 Tomáš Golembiovský <[email protected]>…
Quoted 5 lines · On Thu, 19 Oct 2017 16:12:20 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 4 lines · Tomáš Golembiovský

Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo.

Quoted 8 lines
Quoted 4 lines

To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules.

Does 'Buffers' actually make sense? It's a temporary storage - wouldn't it be significantly out of date by the time host receives it?

That would be best answered by somebody from kernel. But my personal opinion is that it would not be out of date. The amount of memory dedicated to Buffers does not seem to fluctuate too much.

Tomas

I would be inclined to say, just report
global_node_page_state(NR_FILE_PAGES).
Maybe subtract buffer ram.

It's not clear host cares about the distinction,
it's all memory that can shrink in response to
memory pressure such as inflating the balloon.

This statistic is portable as well I think, most guests have storage cache.

Quoted 80 lines
Quoted 76 lines
Quoted 72 lines
Quoted 61 lines
---
 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +11 -0
index f0b3a0b9d42f..c2558ec47a62 100644
@@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 	struct sysinfo i;
 	unsigned int idx = 0;
 	long available;
+	long cached;
 
 	all_vm_events(events);
 	si_meminfo(&i);
 
 	available = si_mem_available();
 
+	cached = global_node_page_state(NR_FILE_PAGES) -
+			total_swapcache_pages() - i.bufferram;
+	if (cached < 0)
+		cached = 0;
+
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
 				pages_to_bytes(events[PSWPIN]));
@@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 				pages_to_bytes(i.totalram));
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
 				pages_to_bytes(available));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS,
+				pages_to_bytes(i.bufferram));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED,
+				pages_to_bytes(cached));
 
 	return idx;
 }
include/uapi/linux/virtio_balloon.h +3 -1
index 343d7ddefe04..d5dc8a56a497 100644
@@ -52,7 +52,9 @@ struct virtio_balloon_config {
 #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_AVAIL    6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR       7
+#define VIRTIO_BALLOON_S_BUFFERS  7   /* Buffers memory as in /proc */
+#define VIRTIO_BALLOON_S_CACHED   8   /* Cached memory as in /proc */
+#define VIRTIO_BALLOON_S_NR       9
 
 /*
  * Memory statistics structure.
mm/swap_state.c +0 -0
index 71ce2d1ccbf7..f3a4ff7d6c52 100644

mm/swap_state.c unsigned long total_swapcache_pages(void) · line 100

Quoted 6 lines
mm/swap_state.c +1 -0
@@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void)
 	rcu_read_unlock();
 	return ret;
 }
+EXPORT_SYMBOL_GPL(total_swapcache_pages);
 
 static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);  

Need an ack from MM crowd on that.

Quoted 2 lines
mm/swap_state.c +0 -1
-- 

2.14.1

Signature · 1 line
Tomáš Golembiovský <[email protected]>
Signature · 1 line
Tomáš Golembiovský <[email protected]>
#8 lore raw

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

Quoted 35 lines · On Tue, 31 Oct 2017 18:15:48 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 33 lines · Tomáš Golembiovský

ping

+Gil, +Amnon... could you maybe aid in reviewing the patch, please?

Tomas

Quoted 23 lines · On Sun, 22 Oct 2017 20:05:57 +0200 Tomáš Golembiovský <[email protected]>…
Quoted 5 lines · On Thu, 19 Oct 2017 16:12:20 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 4 lines · Tomáš Golembiovský

Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo.

Quoted 8 lines
Quoted 4 lines

To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules.

Does 'Buffers' actually make sense? It's a temporary storage - wouldn't it be significantly out of date by the time host receives it?

That would be best answered by somebody from kernel. But my personal opinion is that it would not be out of date. The amount of memory dedicated to Buffers does not seem to fluctuate too much.

Tomas

Quoted 7 lines

I would be inclined to say, just report
global_node_page_state(NR_FILE_PAGES).
Maybe subtract buffer ram.

It's not clear host cares about the distinction,
it's all memory that can shrink in response to
memory pressure such as inflating the balloon.

So in procfs terms we'd be sending sum Cached+SwapCahced. Martin, would that be good enough?

I wonder whether it would still make sense to send Buffers as a separate value though. Maybe we should forget about having some granularity here and just report all the disk caches as one value.

Tomas

Quoted 85 lines

This statistic is portable as well I think, most guests have storage cache.

Quoted 80 lines
Quoted 76 lines
Quoted 72 lines
Quoted 61 lines
---
 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +11 -0
index f0b3a0b9d42f..c2558ec47a62 100644
@@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 	struct sysinfo i;
 	unsigned int idx = 0;
 	long available;
+	long cached;
 
 	all_vm_events(events);
 	si_meminfo(&i);
 
 	available = si_mem_available();
 
+	cached = global_node_page_state(NR_FILE_PAGES) -
+			total_swapcache_pages() - i.bufferram;
+	if (cached < 0)
+		cached = 0;
+
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
 				pages_to_bytes(events[PSWPIN]));
@@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 				pages_to_bytes(i.totalram));
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
 				pages_to_bytes(available));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS,
+				pages_to_bytes(i.bufferram));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED,
+				pages_to_bytes(cached));
 
 	return idx;
 }
include/uapi/linux/virtio_balloon.h +3 -1
index 343d7ddefe04..d5dc8a56a497 100644
@@ -52,7 +52,9 @@ struct virtio_balloon_config {
 #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_AVAIL    6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR       7
+#define VIRTIO_BALLOON_S_BUFFERS  7   /* Buffers memory as in /proc */
+#define VIRTIO_BALLOON_S_CACHED   8   /* Cached memory as in /proc */
+#define VIRTIO_BALLOON_S_NR       9
 
 /*
  * Memory statistics structure.
mm/swap_state.c +0 -0
index 71ce2d1ccbf7..f3a4ff7d6c52 100644

mm/swap_state.c unsigned long total_swapcache_pages(void) · line 100

Quoted 6 lines
mm/swap_state.c +1 -0
@@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void)
 	rcu_read_unlock();
 	return ret;
 }
+EXPORT_SYMBOL_GPL(total_swapcache_pages);
 
 static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);  

Need an ack from MM crowd on that.

Quoted 2 lines
mm/swap_state.c +0 -1
-- 

2.14.1

Signature · 1 line
Tomáš Golembiovský <[email protected]>
Signature · 1 line
Tomáš Golembiovský <[email protected]>
Signature · 7 lines
Tomáš Golembiovský <[email protected]>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#9 lore raw

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

In reply to Michael S. Tsirkin
Quoted 35 lines · On Tue, 31 Oct 2017 18:15:48 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 33 lines · Tomáš Golembiovský

ping

+Gil, +Amnon... could you maybe aid in reviewing the patch, please?

Tomas

Quoted 23 lines · On Sun, 22 Oct 2017 20:05:57 +0200 Tomáš Golembiovský <[email protected]>…
Quoted 5 lines · On Thu, 19 Oct 2017 16:12:20 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 4 lines · Tomáš Golembiovský

Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo.

Quoted 8 lines
Quoted 4 lines

To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules.

Does 'Buffers' actually make sense? It's a temporary storage - wouldn't it be significantly out of date by the time host receives it?

That would be best answered by somebody from kernel. But my personal opinion is that it would not be out of date. The amount of memory dedicated to Buffers does not seem to fluctuate too much.

Tomas

Quoted 7 lines

I would be inclined to say, just report
global_node_page_state(NR_FILE_PAGES).
Maybe subtract buffer ram.

It's not clear host cares about the distinction,
it's all memory that can shrink in response to
memory pressure such as inflating the balloon.

So in procfs terms we'd be sending sum Cached+SwapCahced. Martin, would that be good enough?

I wonder whether it would still make sense to send Buffers as a separate value though. Maybe we should forget about having some granularity here and just report all the disk caches as one value.

Tomas

Quoted 85 lines

This statistic is portable as well I think, most guests have storage cache.

Quoted 80 lines
Quoted 76 lines
Quoted 72 lines
Quoted 61 lines
---
 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +11 -0
index f0b3a0b9d42f..c2558ec47a62 100644
@@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 	struct sysinfo i;
 	unsigned int idx = 0;
 	long available;
+	long cached;
 
 	all_vm_events(events);
 	si_meminfo(&i);
 
 	available = si_mem_available();
 
+	cached = global_node_page_state(NR_FILE_PAGES) -
+			total_swapcache_pages() - i.bufferram;
+	if (cached < 0)
+		cached = 0;
+
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
 				pages_to_bytes(events[PSWPIN]));
@@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 				pages_to_bytes(i.totalram));
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
 				pages_to_bytes(available));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS,
+				pages_to_bytes(i.bufferram));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED,
+				pages_to_bytes(cached));
 
 	return idx;
 }
include/uapi/linux/virtio_balloon.h +3 -1
index 343d7ddefe04..d5dc8a56a497 100644
@@ -52,7 +52,9 @@ struct virtio_balloon_config {
 #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_AVAIL    6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR       7
+#define VIRTIO_BALLOON_S_BUFFERS  7   /* Buffers memory as in /proc */
+#define VIRTIO_BALLOON_S_CACHED   8   /* Cached memory as in /proc */
+#define VIRTIO_BALLOON_S_NR       9
 
 /*
  * Memory statistics structure.
mm/swap_state.c +0 -0
index 71ce2d1ccbf7..f3a4ff7d6c52 100644

mm/swap_state.c unsigned long total_swapcache_pages(void) · line 100

Quoted 6 lines
mm/swap_state.c +1 -0
@@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void)
 	rcu_read_unlock();
 	return ret;
 }
+EXPORT_SYMBOL_GPL(total_swapcache_pages);
 
 static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);  

Need an ack from MM crowd on that.

Quoted 2 lines
mm/swap_state.c +0 -1
-- 

2.14.1

Signature · 1 line
Tomáš Golembiovský <[email protected]>
Signature · 1 line
Tomáš Golembiovský <[email protected]>
Signature · 5 lines
Tomáš Golembiovský <[email protected]>
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#10 lore raw

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

In reply to Tomáš Golembiovský

ping

+Gil, +Amnon... could you maybe aid in reviewing the patch, please?

Tomas

Quoted 100 lines · On Sun, 22 Oct 2017 20:05:57 +0200 Tomáš Golembiovský <[email protected]>…
Quoted 5 lines · On Thu, 19 Oct 2017 16:12:20 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 4 lines · Tomáš Golembiovský

Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo.

Quoted 8 lines
Quoted 4 lines

To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules.

Does 'Buffers' actually make sense? It's a temporary storage - wouldn't it be significantly out of date by the time host receives it?

That would be best answered by somebody from kernel. But my personal opinion is that it would not be out of date. The amount of memory dedicated to Buffers does not seem to fluctuate too much.

Tomas

Quoted 72 lines
Quoted 61 lines
---
 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +11 -0
index f0b3a0b9d42f..c2558ec47a62 100644
@@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 	struct sysinfo i;
 	unsigned int idx = 0;
 	long available;
+	long cached;
 
 	all_vm_events(events);
 	si_meminfo(&i);
 
 	available = si_mem_available();
 
+	cached = global_node_page_state(NR_FILE_PAGES) -
+			total_swapcache_pages() - i.bufferram;
+	if (cached < 0)
+		cached = 0;
+
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
 				pages_to_bytes(events[PSWPIN]));
@@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 				pages_to_bytes(i.totalram));
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
 				pages_to_bytes(available));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS,
+				pages_to_bytes(i.bufferram));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED,
+				pages_to_bytes(cached));
 
 	return idx;
 }
include/uapi/linux/virtio_balloon.h +3 -1
index 343d7ddefe04..d5dc8a56a497 100644
@@ -52,7 +52,9 @@ struct virtio_balloon_config {
 #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_AVAIL    6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR       7
+#define VIRTIO_BALLOON_S_BUFFERS  7   /* Buffers memory as in /proc */
+#define VIRTIO_BALLOON_S_CACHED   8   /* Cached memory as in /proc */
+#define VIRTIO_BALLOON_S_NR       9
 
 /*
  * Memory statistics structure.
mm/swap_state.c +0 -0
index 71ce2d1ccbf7..f3a4ff7d6c52 100644

mm/swap_state.c unsigned long total_swapcache_pages(void) · line 100

Quoted 6 lines
mm/swap_state.c +1 -0
@@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void)
 	rcu_read_unlock();
 	return ret;
 }
+EXPORT_SYMBOL_GPL(total_swapcache_pages);
 
 static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);  

Need an ack from MM crowd on that.

Quoted 2 lines
mm/swap_state.c +0 -1
-- 

2.14.1

Signature · 1 line
Tomáš Golembiovský <[email protected]>
Signature · 5 lines
Tomáš Golembiovský <[email protected]>
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#11 lore raw

Re: [PATCH v2 1/1] virtio_balloon: include buffers and cached memory statistics

In reply to Michael S. Tsirkin
Quoted 5 lines · On Thu, 19 Oct 2017 16:12:20 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 4 lines · Tomáš Golembiovský

Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo.

Quoted 8 lines
Quoted 4 lines

To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules.

Does 'Buffers' actually make sense? It's a temporary storage - wouldn't it be significantly out of date by the time host receives it?

That would be best answered by somebody from kernel. But my personal opinion is that it would not be out of date. The amount of memory dedicated to Buffers does not seem to fluctuate too much.

Tomas

Quoted 72 lines
Quoted 61 lines
---
 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +11 -0
index f0b3a0b9d42f..c2558ec47a62 100644
@@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 	struct sysinfo i;
 	unsigned int idx = 0;
 	long available;
+	long cached;
 
 	all_vm_events(events);
 	si_meminfo(&i);
 
 	available = si_mem_available();
 
+	cached = global_node_page_state(NR_FILE_PAGES) -
+			total_swapcache_pages() - i.bufferram;
+	if (cached < 0)
+		cached = 0;
+
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
 				pages_to_bytes(events[PSWPIN]));
@@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 				pages_to_bytes(i.totalram));
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
 				pages_to_bytes(available));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS,
+				pages_to_bytes(i.bufferram));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED,
+				pages_to_bytes(cached));
 
 	return idx;
 }
include/uapi/linux/virtio_balloon.h +3 -1
index 343d7ddefe04..d5dc8a56a497 100644
@@ -52,7 +52,9 @@ struct virtio_balloon_config {
 #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_AVAIL    6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR       7
+#define VIRTIO_BALLOON_S_BUFFERS  7   /* Buffers memory as in /proc */
+#define VIRTIO_BALLOON_S_CACHED   8   /* Cached memory as in /proc */
+#define VIRTIO_BALLOON_S_NR       9
 
 /*
  * Memory statistics structure.
mm/swap_state.c +0 -0
index 71ce2d1ccbf7..f3a4ff7d6c52 100644

mm/swap_state.c unsigned long total_swapcache_pages(void) · line 100

Quoted 6 lines
mm/swap_state.c +1 -0
@@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void)
 	rcu_read_unlock();
 	return ret;
 }
+EXPORT_SYMBOL_GPL(total_swapcache_pages);
 
 static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);

Need an ack from MM crowd on that.

Quoted 2 lines
Signature · 1 line
2.14.1
Signature · 5 lines
Tomáš Golembiovský <[email protected]>
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#12 lore raw

PATCH v2 1/1 virtio_balloon: include buffers and cached memory statistics

In reply to Tomáš Golembiovský

Add a new fields, VIRTIO_BALLOON_S_BUFFERS and VIRTIO_BALLOON_S_CACHED, to virtio_balloon memory statistics protocol. The values correspond to 'Buffers' and 'Cached' in /proc/meminfo.

To be able to compute the value of 'Cached' memory it is necessary to export total_swapcache_pages() to modules.

---
 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/virtio/virtio_balloon.c +11 -0
index f0b3a0b9d42f..c2558ec47a62 100644
@@ -244,12 +244,19 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 	struct sysinfo i;
 	unsigned int idx = 0;
 	long available;
+	long cached;
 
 	all_vm_events(events);
 	si_meminfo(&i);
 
 	available = si_mem_available();
 
+	cached = global_node_page_state(NR_FILE_PAGES) -
+			total_swapcache_pages() - i.bufferram;
+	if (cached < 0)
+		cached = 0;
+
+
 #ifdef CONFIG_VM_EVENT_COUNTERS
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN,
 				pages_to_bytes(events[PSWPIN]));
@@ -264,6 +271,10 @@ static unsigned int update_balloon_stats(struct virtio_balloon *vb)
 				pages_to_bytes(i.totalram));
 	update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
 				pages_to_bytes(available));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_BUFFERS,
+				pages_to_bytes(i.bufferram));
+	update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHED,
+				pages_to_bytes(cached));
 
 	return idx;
 }
include/uapi/linux/virtio_balloon.h +3 -1
index 343d7ddefe04..d5dc8a56a497 100644
@@ -52,7 +52,9 @@ struct virtio_balloon_config {
 #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_AVAIL    6   /* Available memory as in /proc */
-#define VIRTIO_BALLOON_S_NR       7
+#define VIRTIO_BALLOON_S_BUFFERS  7   /* Buffers memory as in /proc */
+#define VIRTIO_BALLOON_S_CACHED   8   /* Cached memory as in /proc */
+#define VIRTIO_BALLOON_S_NR       9
 
 /*
  * Memory statistics structure.
mm/swap_state.c +1 -0
index 71ce2d1ccbf7..f3a4ff7d6c52 100644
@@ -95,6 +95,7 @@ unsigned long total_swapcache_pages(void)
 	rcu_read_unlock();
 	return ret;
 }
+EXPORT_SYMBOL_GPL(total_swapcache_pages);
 
 static atomic_t swapin_readahead_hits = ATOMIC_INIT(4);
 
Signature · 6 lines
2.14.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#13 lore raw
In reply to Tomáš Golembiovský
Quoted 5 lines · On Thu, 21 Sep 2017 14:55:40 +0200 Tomáš Golembiovský <[email protected]>…

Linux driver part

v2:
- fixed typos

Quoted 11 lines

Tomáš Golembiovský (1):
virtio_balloon: include buffers and cached memory statistics

 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
Signature · 1 line
2.14.1

ping

Signature · 1 line
Tomáš Golembiovský <[email protected]>
#14 lore raw
Quoted 16 lines · On Thu, 5 Oct 2017 15:51:18 +0200 Tomáš Golembiovský <[email protected]>…
Quoted 13 lines · On Thu, 21 Sep 2017 14:55:40 +0200 Tomáš Golembiovský <[email protected]>…

Linux driver part

v2:
- fixed typos

Tomáš Golembiovský (1):
virtio_balloon: include buffers and cached memory statistics

 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
Quoted 5 lines
Quoted 3 lines
Signature · 1 line
2.14.1

ping

ping

Signature · 1 line
Tomáš Golembiovský <[email protected]>
#15 lore raw
In reply to Tomáš Golembiovský
Quoted 16 lines · On Thu, 5 Oct 2017 15:51:18 +0200 Tomáš Golembiovský <[email protected]>…
Quoted 13 lines · On Thu, 21 Sep 2017 14:55:40 +0200 Tomáš Golembiovský <[email protected]>…

Linux driver part

v2:
- fixed typos

Tomáš Golembiovský (1):
virtio_balloon: include buffers and cached memory statistics

 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
Quoted 5 lines
Quoted 3 lines
Signature · 1 line
2.14.1

ping

ping

Signature · 5 lines
Tomáš Golembiovský <[email protected]>
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
#16 lore raw
In reply to Tomáš Golembiovský
Quoted 5 lines · On Thu, 21 Sep 2017 14:55:40 +0200 Tomáš Golembiovský <[email protected]>…

Linux driver part

v2:
- fixed typos

Quoted 11 lines

Tomáš Golembiovský (1):
virtio_balloon: include buffers and cached memory statistics

 drivers/virtio/virtio_balloon.c     | 11 +++++++++++
 include/uapi/linux/virtio_balloon.h |  4 +++-
 mm/swap_state.c                     |  1 +
 3 files changed, 15 insertions(+), 1 deletion(-)
Signature · 1 line
2.14.1

ping

Signature · 5 lines
Tomáš Golembiovský <[email protected]>
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization