Skip to contentSkip to conversation

track memory used by balloon drivers

RFC Superseded Nico Pache 4 participants 20 messages Mar 12, 2025 – Mar 13, 2025

Subsystems (15)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nico Pache

author
#0 lore raw

cover track memory used by balloon drivers

This series introduces a way to track memory used by balloon drivers.

Add a NR_BALLOON_PAGES counter to track how many pages are reclaimed by the balloon drivers. First add the accounting, then updates the balloon drivers (virtio, Hyper-V, VMware, and Xen) to maintain this counter.

This makes the information visible in memory reporting interfaces like /proc/meminfo, show_mem, and OOM reporting.

This provides admins visibility into their VM balloon sizes without requiring different virtualization tooling. Furthermore, this information is helpful when debugging an OOM inside a VM.

Tested: virtio_balloon, run stress-ng, inflate balloon, oom prints

Nico Pache (5):
meminfo: add a per node counter for balloon drivers
virtio_balloon: update the NR_BALLOON_PAGES state
hv_balloon: update the NR_BALLOON_PAGES state
vmx_balloon: update the NR_BALLOON_PAGES state
xen: balloon: update the NR_BALLOON_PAGES state

 drivers/hv/hv_balloon.c         | 2 ++
 drivers/misc/vmw_balloon.c      | 5 ++++-
 drivers/virtio/virtio_balloon.c | 4 ++++
 drivers/xen/balloon.c           | 4 ++++
 fs/proc/meminfo.c               | 2 ++
 include/linux/mmzone.h          | 1 +
 mm/memcontrol.c                 | 1 +
 mm/show_mem.c                   | 4 +++-
 mm/vmstat.c                     | 1 +
 9 files changed, 22 insertions(+), 2 deletions(-)
Signature · 1 line
2.48.1
author
#1 lore raw

RFC 1/5 meminfo: add a per node counter for balloon drivers

Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and expose it through /proc/meminfo and other memory reporting interfaces.

---
 fs/proc/meminfo.c      | 2 ++
 include/linux/mmzone.h | 1 +
 mm/memcontrol.c        | 1 +
 mm/show_mem.c          | 4 +++-
 mm/vmstat.c            | 1 +
 5 files changed, 8 insertions(+), 1 deletion(-)
fs/proc/meminfo.c +2 -0
index 8ba9b1472390..83be312159c9 100644
@@ -162,6 +162,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 	show_val_kb(m, "Unaccepted:     ",
 		    global_zone_page_state(NR_UNACCEPTED));
 #endif
+	show_val_kb(m, "Balloon:        ",
+		    global_node_page_state(NR_BALLOON_PAGES));
 
 	hugetlb_report_meminfo(m);
 
include/linux/mmzone.h +1 -0
index 9540b41894da..71d3ff19267a 100644
@@ -223,6 +223,7 @@ enum node_stat_item {
 #ifdef CONFIG_HUGETLB_PAGE
 	NR_HUGETLB,
 #endif
+	NR_BALLOON_PAGES,
 	NR_VM_NODE_STAT_ITEMS
 };
 
mm/memcontrol.c +1 -0
index 4de6acb9b8ec..182b44646bfa 100644
@@ -1377,6 +1377,7 @@ static const struct memory_stat memory_stats[] = {
 #ifdef CONFIG_HUGETLB_PAGE
 	{ "hugetlb",			NR_HUGETLB			},
 #endif
+	{ "nr_balloon_pages",		NR_BALLOON_PAGES		},
 
 	/* The memory events */
 	{ "workingset_refault_anon",	WORKINGSET_REFAULT_ANON		},
mm/show_mem.c +3 -1
index 43afb56abbd3..6af13bcd2ab3 100644
@@ -260,6 +260,7 @@ static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_z
 			" pagetables:%lukB"
 			" sec_pagetables:%lukB"
 			" all_unreclaimable? %s"
+			" Balloon:%lukB"
 			"\n",
 			pgdat->node_id,
 			K(node_page_state(pgdat, NR_ACTIVE_ANON)),
@@ -285,7 +286,8 @@ static void show_free_areas(unsigned int filter, nodemask_t *nodemask, int max_z
 #endif
 			K(node_page_state(pgdat, NR_PAGETABLE)),
 			K(node_page_state(pgdat, NR_SECONDARY_PAGETABLE)),
-			str_yes_no(pgdat->kswapd_failures >= MAX_RECLAIM_RETRIES));
+			str_yes_no(pgdat->kswapd_failures >= MAX_RECLAIM_RETRIES),
+			K(node_page_state(pgdat, NR_BALLOON_PAGES)));
 	}
 
 	for_each_populated_zone(zone) {
mm/vmstat.c +1 -0
index 16bfe1c694dd..d3b11891a942 100644
@@ -1276,6 +1276,7 @@ const char * const vmstat_text[] = {
 #ifdef CONFIG_HUGETLB_PAGE
 	"nr_hugetlb",
 #endif
+	"nr_balloon_pages",
 	/* system-wide enum vm_stat_item counters */
 	"nr_dirty_threshold",
 	"nr_dirty_background_threshold",
Signature · 1 line
2.48.1
author
#11 lore raw

RFC 2/5 virtio_balloon: update the NR_BALLOON_PAGES state

In reply to Nico Pache

Update the NR_BALLOON_PAGES counter when pages are added to or removed from the virtio balloon.

---
 drivers/virtio/virtio_balloon.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/virtio/virtio_balloon.c +4 -0
index 89da052f4f68..406414dbb477 100644
@@ -274,6 +274,8 @@ static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
 
 		set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
 		vb->num_pages += VIRTIO_BALLOON_PAGES_PER_PAGE;
+		mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+			VIRTIO_BALLOON_PAGES_PER_PAGE);
 		if (!virtio_has_feature(vb->vdev,
 					VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
 			adjust_managed_page_count(page, -1);
@@ -324,6 +326,8 @@ static unsigned int leak_balloon(struct virtio_balloon *vb, size_t num)
 		set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
 		list_add(&page->lru, &pages);
 		vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE;
+		mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+			-VIRTIO_BALLOON_PAGES_PER_PAGE);
 	}
 
 	num_freed_pages = vb->num_pfns;
Signature · 1 line
2.48.1
author
#13 lore raw

RFC 3/5 hv_balloon: update the NR_BALLOON_PAGES state

In reply to Nico Pache

Update the NR_BALLOON_PAGES counter when pages are added to or removed from the Hyper-V balloon.

---
 drivers/hv/hv_balloon.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/hv/hv_balloon.c +2 -0
index fec2f18679e3..2b4080e51f97 100644
@@ -1192,6 +1192,7 @@ static void free_balloon_pages(struct hv_dynmem_device *dm,
 		__ClearPageOffline(pg);
 		__free_page(pg);
 		dm->num_pages_ballooned--;
+		mod_node_page_state(page_pgdat(pg), NR_BALLOON_PAGES, -1);
 		adjust_managed_page_count(pg, 1);
 	}
 }
@@ -1221,6 +1222,7 @@ static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm,
 			return i * alloc_unit;
 
 		dm->num_pages_ballooned += alloc_unit;
+		mod_node_page_state(page_pgdat(pg), NR_BALLOON_PAGES, alloc_unit);
 
 		/*
 		 * If we allocatted 2M pages; split them so we
Signature · 1 line
2.48.1
author
#14 lore raw

RFC 4/5 vmx_balloon: update the NR_BALLOON_PAGES state

In reply to Nico Pache

Update the NR_BALLOON_PAGES counter when pages are added to or removed from the VMware balloon.

---
 drivers/misc/vmw_balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/misc/vmw_balloon.c +4 -1
index c817d8c21641..2c70b08c6fb3 100644
@@ -673,6 +673,8 @@ static int vmballoon_alloc_page_list(struct vmballoon *b,
 
 			vmballoon_stats_page_inc(b, VMW_BALLOON_PAGE_STAT_ALLOC,
 						 ctl->page_size);
+			mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+				vmballoon_page_in_frames(ctl->page_size));
 		}
 
 		if (page) {
@@ -915,6 +917,8 @@ static void vmballoon_release_page_list(struct list_head *page_list,
 	list_for_each_entry_safe(page, tmp, page_list, lru) {
 		list_del(&page->lru);
 		__free_pages(page, vmballoon_page_order(page_size));
+		mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+			-vmballoon_page_in_frames(page_size));
 	}
 
 	if (n_pages)
@@ -1129,7 +1133,6 @@ static void vmballoon_inflate(struct vmballoon *b)
 
 		/* Update the balloon size */
 		atomic64_add(ctl.n_pages * page_in_frames, &b->size);
-
 		vmballoon_enqueue_page_list(b, &ctl.pages, &ctl.n_pages,
 					    ctl.page_size);
 
Signature · 1 line
2.48.1
author
#19 lore raw

RFC 5/5 xen: balloon: update the NR_BALLOON_PAGES state

In reply to Nico Pache

Update the NR_BALLOON_PAGES counter when pages are added to or removed from the Xen balloon.

---
 drivers/xen/balloon.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/xen/balloon.c +4 -0
index 163f7f1d70f1..65d4e7fa1eb8 100644
@@ -157,6 +157,8 @@ static void balloon_append(struct page *page)
 		list_add(&page->lru, &ballooned_pages);
 		balloon_stats.balloon_low++;
 	}
+	inc_node_page_state(page, NR_BALLOON_PAGES);
+
 	wake_up(&balloon_wq);
 }
 
@@ -179,6 +181,8 @@ static struct page *balloon_retrieve(bool require_lowmem)
 		balloon_stats.balloon_low--;
 
 	__ClearPageOffline(page);
+	dec_node_page_state(page, NR_BALLOON_PAGES);
+
 	return page;
 }
 
Signature · 1 line
2.48.1
maintainer
#2 lore raw

Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers

In reply to Nico Pache
Quoted 42 lines · Nico Pache

Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and expose it through /proc/meminfo and other memory reporting interfaces.

---
 fs/proc/meminfo.c      | 2 ++
 include/linux/mmzone.h | 1 +
 mm/memcontrol.c        | 1 +
 mm/show_mem.c          | 4 +++-
 mm/vmstat.c            | 1 +
 5 files changed, 8 insertions(+), 1 deletion(-)
fs/proc/meminfo.c +2 -0
index 8ba9b1472390..83be312159c9 100644
@@ -162,6 +162,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 	show_val_kb(m, "Unaccepted:     ",
 		    global_zone_page_state(NR_UNACCEPTED));
 #endif
+	show_val_kb(m, "Balloon:        ",
+		    global_node_page_state(NR_BALLOON_PAGES));
 
 	hugetlb_report_meminfo(m);
 
include/linux/mmzone.h +1 -0
index 9540b41894da..71d3ff19267a 100644
@@ -223,6 +223,7 @@ enum node_stat_item {
 #ifdef CONFIG_HUGETLB_PAGE
 	NR_HUGETLB,
 #endif
+	NR_BALLOON_PAGES,
 	NR_VM_NODE_STAT_ITEMS
 };
 
mm/memcontrol.c +0 -0
index 4de6acb9b8ec..182b44646bfa 100644

mm/memcontrol.c static const struct memory_stat memory_stats[] = { · line 1380

Quoted 4 lines
mm/memcontrol.c +1 -0
@@ -1377,6 +1377,7 @@ static const struct memory_stat memory_stats[] = {
 #ifdef CONFIG_HUGETLB_PAGE
 	{ "hugetlb",			NR_HUGETLB			},
 #endif
+	{ "nr_balloon_pages",		NR_BALLOON_PAGES		},

Please remove the above counter from memcontrol.c as I don't think this memory is accounted towards memcg.

#12 lore raw

Re: [RFC 2/5] virtio_balloon: update the NR_BALLOON_PAGES state

In reply to Nico Pache
Quoted 13 lines · Nico Pache

Update the NR_BALLOON_PAGES counter when pages are added to or removed from the virtio balloon.

---
 drivers/virtio/virtio_balloon.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/virtio/virtio_balloon.c +0 -0
index 89da052f4f68..406414dbb477 100644

drivers/virtio/virtio_balloon.c static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num) · line 281

Quoted 8 lines
drivers/virtio/virtio_balloon.c +2 -0
@@ -274,6 +274,8 @@ static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
 
 		set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
 		vb->num_pages += VIRTIO_BALLOON_PAGES_PER_PAGE;
+		mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+			VIRTIO_BALLOON_PAGES_PER_PAGE);
 		if (!virtio_has_feature(vb->vdev,
 					VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
 			adjust_managed_page_count(page, -1);

This means the counter is in virtio balloon page units, which runs counter to the declared goal of making the interface hypervisor-agnostic.

drivers/virtio/virtio_balloon.c static unsigned int leak_balloon(struct virtio_balloon *vb, size_t num) · line 330

Quoted 6 lines
drivers/virtio/virtio_balloon.c +2 -0
@@ -324,6 +326,8 @@ static unsigned int leak_balloon(struct virtio_balloon *vb, size_t num)
 		set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
 		list_add(&page->lru, &pages);
 		vb->num_pages -= VIRTIO_BALLOON_PAGES_PER_PAGE;
+		mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+			-VIRTIO_BALLOON_PAGES_PER_PAGE);

Same.

Thanks,

Quoted 5 lines
drivers/virtio/virtio_balloon.c +0 -0
 	}
 
 	num_freed_pages = vb->num_pfns;
Signature · 1 line
2.48.1
#15 lore raw

Re: [RFC 4/5] vmx_balloon: update the NR_BALLOON_PAGES state

In reply to Nico Pache
Quoted 13 lines · Nico Pache

Update the NR_BALLOON_PAGES counter when pages are added to or removed from the VMware balloon.

---
 drivers/misc/vmw_balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/misc/vmw_balloon.c +0 -0
index c817d8c21641..2c70b08c6fb3 100644

drivers/misc/vmw_balloon.c static int vmballoon_alloc_page_list(struct vmballoon *b, · line 677

Quoted 5 lines
drivers/misc/vmw_balloon.c +2 -0
@@ -673,6 +673,8 @@ static int vmballoon_alloc_page_list(struct vmballoon *b,
 
 			vmballoon_stats_page_inc(b, VMW_BALLOON_PAGE_STAT_ALLOC,
 						 ctl->page_size);
+			mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+				vmballoon_page_in_frames(ctl->page_size));

same issue as virtio I think - this counts frames not pages.

Quoted 13 lines
drivers/misc/vmw_balloon.c +2 -0
 		}
 
 		if (page) {
@@ -915,6 +917,8 @@ static void vmballoon_release_page_list(struct list_head *page_list,
 	list_for_each_entry_safe(page, tmp, page_list, lru) {
 		list_del(&page->lru);
 		__free_pages(page, vmballoon_page_order(page_size));
+		mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+			-vmballoon_page_in_frames(page_size));
 	}
 
 	if (n_pages)

drivers/misc/vmw_balloon.c static void vmballoon_inflate(struct vmballoon *b) · line 1132

Quoted 4 lines
drivers/misc/vmw_balloon.c +0 -1
@@ -1129,7 +1133,6 @@ static void vmballoon_inflate(struct vmballoon *b)
 
 		/* Update the balloon size */
 		atomic64_add(ctl.n_pages * page_in_frames, &b->size);
-

unrelated change

Quoted 5 lines
drivers/misc/vmw_balloon.c +0 -0
 		vmballoon_enqueue_page_list(b, &ctl.pages, &ctl.n_pages,
 					    ctl.page_size);
 
Signature · 1 line
2.48.1
author
#16 lore raw

Re: [RFC 4/5] vmx_balloon: update the NR_BALLOON_PAGES state

Quoted 16 lines · Michael S. Tsirkin
Quoted 14 lines · Nico Pache

Update the NR_BALLOON_PAGES counter when pages are added to or removed from the VMware balloon.

---
 drivers/misc/vmw_balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/misc/vmw_balloon.c +0 -0
index c817d8c21641..2c70b08c6fb3 100644
@@ -673,6 +673,8 @@ static int vmballoon_alloc_page_list(struct vmballoon *b,
 
Quoted 7 lines

drivers/misc/vmw_balloon.c static int vmballoon_alloc_page_list(struct vmballoon *b, · line 677

Quoted 4 lines
drivers/misc/vmw_balloon.c +2 -0
                      vmballoon_stats_page_inc(b, VMW_BALLOON_PAGE_STAT_ALLOC,
                                               ctl->page_size);
+                     mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+                             vmballoon_page_in_frames(ctl->page_size));

same issue as virtio I think - this counts frames not pages.

I agree with the viritio issue since PAGE_SIZE can be larger than VIRTIO_BALLOON_PFN_SHIFT, resulting in multiple virtio_balloon pages for each page. I fixed that one, thanks!

For the Vmware one, the code is littered with mentions of counting in 4k or 2M but as far as I can tell from looking at the code it actually operates in PAGE_SIZE or PMD size chunks and this count would be correct.
Perhaps I am missing something though.

Quoted 15 lines
Quoted 15 lines
drivers/misc/vmw_balloon.c +2 -0
              }
 
              if (page) {
@@ -915,6 +917,8 @@ static void vmballoon_release_page_list(struct list_head *page_list,
      list_for_each_entry_safe(page, tmp, page_list, lru) {
              list_del(&page->lru);
              __free_pages(page, vmballoon_page_order(page_size));
+             mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+                     -vmballoon_page_in_frames(page_size));
      }
 
      if (n_pages)
@@ -1129,7 +1133,6 @@ static void vmballoon_inflate(struct vmballoon *b)
 
Quoted 6 lines

drivers/misc/vmw_balloon.c static void vmballoon_inflate(struct vmballoon *b) · line 1132

Quoted 3 lines
drivers/misc/vmw_balloon.c +0 -1
              /* Update the balloon size */
              atomic64_add(ctl.n_pages * page_in_frames, &b->size);
-

unrelated change

Fixed, Thanks for reviewing!

Quoted 7 lines
Quoted 6 lines
drivers/misc/vmw_balloon.c +0 -1
              vmballoon_enqueue_page_list(b, &ctl.pages, &ctl.n_pages,
                                          ctl.page_size);
 
--

2.48.1

author
#3 lore raw

Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers

In reply to Shakeel Butt
Quoted 39 lines · Shakeel Butt
Quoted 37 lines · Nico Pache

Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and expose it through /proc/meminfo and other memory reporting interfaces.

---
 fs/proc/meminfo.c      | 2 ++
 include/linux/mmzone.h | 1 +
 mm/memcontrol.c        | 1 +
 mm/show_mem.c          | 4 +++-
 mm/vmstat.c            | 1 +
 5 files changed, 8 insertions(+), 1 deletion(-)
fs/proc/meminfo.c +2 -0
index 8ba9b1472390..83be312159c9 100644
@@ -162,6 +162,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
      show_val_kb(m, "Unaccepted:     ",
                  global_zone_page_state(NR_UNACCEPTED));
 #endif
+     show_val_kb(m, "Balloon:        ",
+                 global_node_page_state(NR_BALLOON_PAGES));
 
      hugetlb_report_meminfo(m);
 
include/linux/mmzone.h +1 -0
index 9540b41894da..71d3ff19267a 100644
@@ -223,6 +223,7 @@ enum node_stat_item {
 #ifdef CONFIG_HUGETLB_PAGE
      NR_HUGETLB,
 #endif
+     NR_BALLOON_PAGES,
      NR_VM_NODE_STAT_ITEMS
 };
 
Quoted 12 lines

mm/memcontrol.c static const struct memory_stat memory_stats[] = { · line 1380

Quoted 9 lines
mm/memcontrol.c +1 -0
index 4de6acb9b8ec..182b44646bfa 100644
@@ -1377,6 +1377,7 @@ static const struct memory_stat memory_stats[] = {
 #ifdef CONFIG_HUGETLB_PAGE
      { "hugetlb",                    NR_HUGETLB                      },
 #endif
+     { "nr_balloon_pages",           NR_BALLOON_PAGES                },

Please remove the above counter from memcontrol.c as I don't think this memory is accounted towards memcg.

Fixed-- Thank you!

Quoted 1 line
#17 lore raw

Re: [RFC 4/5] vmx_balloon: update the NR_BALLOON_PAGES state

In reply to Nico Pache
Quoted 28 lines · Nico Pache
Quoted 16 lines · Michael S. Tsirkin
Quoted 14 lines · Nico Pache

Update the NR_BALLOON_PAGES counter when pages are added to or removed from the VMware balloon.

---
 drivers/misc/vmw_balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/misc/vmw_balloon.c +0 -0
index c817d8c21641..2c70b08c6fb3 100644
@@ -673,6 +673,8 @@ static int vmballoon_alloc_page_list(struct vmballoon *b,
 
Quoted 7 lines

drivers/misc/vmw_balloon.c static int vmballoon_alloc_page_list(struct vmballoon *b, · line 677

Quoted 4 lines
drivers/misc/vmw_balloon.c +2 -0
                      vmballoon_stats_page_inc(b, VMW_BALLOON_PAGE_STAT_ALLOC,
                                               ctl->page_size);
+                     mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+                             vmballoon_page_in_frames(ctl->page_size));

same issue as virtio I think - this counts frames not pages.

I agree with the viritio issue since PAGE_SIZE can be larger than VIRTIO_BALLOON_PFN_SHIFT, resulting in multiple virtio_balloon pages for each page. I fixed that one, thanks!

Quoted 5 lines

For the Vmware one, the code is littered with mentions of counting in 4k or 2M but as far as I can tell from looking at the code it actually operates in PAGE_SIZE or PMD size chunks and this count would be correct.
Perhaps I am missing something though.

Can't say for sure. This needs an ack from the maintainer.

Quoted 29 lines
Quoted 15 lines
Quoted 15 lines
drivers/misc/vmw_balloon.c +2 -0
              }
 
              if (page) {
@@ -915,6 +917,8 @@ static void vmballoon_release_page_list(struct list_head *page_list,
      list_for_each_entry_safe(page, tmp, page_list, lru) {
              list_del(&page->lru);
              __free_pages(page, vmballoon_page_order(page_size));
+             mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+                     -vmballoon_page_in_frames(page_size));
      }
 
      if (n_pages)
@@ -1129,7 +1133,6 @@ static void vmballoon_inflate(struct vmballoon *b)
 
Quoted 6 lines

drivers/misc/vmw_balloon.c static void vmballoon_inflate(struct vmballoon *b) · line 1132

Quoted 3 lines
drivers/misc/vmw_balloon.c +0 -1
              /* Update the balloon size */
              atomic64_add(ctl.n_pages * page_in_frames, &b->size);
-

unrelated change

Fixed, Thanks for reviewing!

Quoted 7 lines
Quoted 6 lines
drivers/misc/vmw_balloon.c +0 -1
              vmballoon_enqueue_page_list(b, &ctl.pages, &ctl.n_pages,
                                          ctl.page_size);
 
--

2.48.1

#18 lore raw

Re: [RFC 4/5] vmx_balloon: update the NR_BALLOON_PAGES state

In reply to Nico Pache
Quoted 28 lines · Nico Pache
Quoted 16 lines · Michael S. Tsirkin
Quoted 14 lines · Nico Pache

Update the NR_BALLOON_PAGES counter when pages are added to or removed from the VMware balloon.

---
  drivers/misc/vmw_balloon.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/misc/vmw_balloon.c +0 -0
index c817d8c21641..2c70b08c6fb3 100644
@@ -673,6 +673,8 @@ static int vmballoon_alloc_page_list(struct vmballoon *b,
 
Quoted 7 lines

drivers/misc/vmw_balloon.c static int vmballoon_alloc_page_list(struct vmballoon *b, · line 677

Quoted 4 lines
drivers/misc/vmw_balloon.c +2 -0
                       vmballoon_stats_page_inc(b, VMW_BALLOON_PAGE_STAT_ALLOC,
                                                ctl->page_size);
+                     mod_node_page_state(page_pgdat(page), NR_BALLOON_PAGES,
+                             vmballoon_page_in_frames(ctl->page_size));

same issue as virtio I think - this counts frames not pages.

I agree with the viritio issue since PAGE_SIZE can be larger than VIRTIO_BALLOON_PFN_SHIFT, resulting in multiple virtio_balloon pages for each page. I fixed that one, thanks!

Quoted 5 lines

For the Vmware one, the code is littered with mentions of counting in 4k or 2M but as far as I can tell from looking at the code it actually operates in PAGE_SIZE or PMD size chunks and this count would be correct.
Perhaps I am missing something though.

vmballoon_page_in_frames() documents to "Return: the number of 4k frames.", because it supports either 4k or 2M chunks IIRC.

I think the catch is that PAGE_SIZE will in these configs always be 4k. Otherwise things like vmballoon_mark_page_offline() wouldn't work as expected.

So I think this is correct.

Signature · 3 lines
Cheers,

David / dhildenb
#4 lore raw

Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers

In reply to Nico Pache
Quoted 2 lines · Nico Pache

Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and expose it through /proc/meminfo and other memory reporting interfaces.

In balloon_page_enqueue_one(), we perform a

__count_vm_event(BALLOON_INFLATE)

and in balloon_page_list_dequeue

__count_vm_event(BALLOON_DEFLATE);

Should we maybe simply do the per-node accounting similarly there?

Signature · 3 lines
Cheers,

David / dhildenb
author
#5 lore raw

Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers

Quoted 7 lines · David Hildenbrand
Quoted 2 lines · Nico Pache

Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and expose it through /proc/meminfo and other memory reporting interfaces.

In balloon_page_enqueue_one(), we perform a

Quoted 8 lines

__count_vm_event(BALLOON_INFLATE)

and in balloon_page_list_dequeue

__count_vm_event(BALLOON_DEFLATE);

Should we maybe simply do the per-node accounting similarly there?

I think the issue is that some balloon drivers use the balloon_compaction interface while others use their own.

This would require unifying all the drivers under a single api which may be tricky if they all have different behavior

Quoted 6 lines

--
Cheers,

David / dhildenb

#9 lore raw

Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers

In reply to David Hildenbrand
Quoted 6 lines · David Hildenbrand
Quoted 2 lines · Nico Pache

Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and expose it through /proc/meminfo and other memory reporting interfaces.

In balloon_page_enqueue_one(), we perform a

Quoted 8 lines

__count_vm_event(BALLOON_INFLATE)

and in balloon_page_list_dequeue

__count_vm_event(BALLOON_DEFLATE);

Should we maybe simply do the per-node accounting similarly there?

BTW should virtio mem be tied into this too, in some way? or is it too different?

Quoted 4 lines
Signature · 3 lines
Cheers,

David / dhildenb
#10 lore raw

Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers

Quoted 11 lines · Michael S. Tsirkin
Quoted 10 lines · David Hildenbrand
Quoted 2 lines · Nico Pache

Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and expose it through /proc/meminfo and other memory reporting interfaces.

In balloon_page_enqueue_one(), we perform a

__count_vm_event(BALLOON_INFLATE)

and in balloon_page_list_dequeue

Quoted 8 lines
Quoted 4 lines

__count_vm_event(BALLOON_DEFLATE);

Should we maybe simply do the per-node accounting similarly there?

BTW should virtio mem be tied into this too, in some way? or is it too different?

No, we should limit it to actual balloon drivers that e.g., never completely remove memory.

Signature · 3 lines
Cheers,

David / dhildenb
#6 lore raw

Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers

In reply to Nico Pache
Quoted 15 lines · Nico Pache
Quoted 14 lines · David Hildenbrand
Quoted 2 lines · Nico Pache

Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and expose it through /proc/meminfo and other memory reporting interfaces.

In balloon_page_enqueue_one(), we perform a

__count_vm_event(BALLOON_INFLATE)

and in balloon_page_list_dequeue

__count_vm_event(BALLOON_DEFLATE);

Quoted 7 lines
Quoted 1 line

Should we maybe simply do the per-node accounting similarly there?

I think the issue is that some balloon drivers use the balloon_compaction interface while others use their own.

This would require unifying all the drivers under a single api which may be tricky if they all have different behavior

Why would that be required? Simply implement it in the balloon compaction logic, and in addition separately in the ones that don't implement it.

That's the same as how we handle PageOffline today.

In summary, we have

virtio-balloon: balloon compaction
hv-balloon: no balloon compaction
xen-balloon: no balloon compaction
vmx-balloon: balloon compaction
pseries-cmm: balloon compaction

So you'd handle 3 balloon drivers in one go.

(this series didn't touch pseries-cmm)

Signature · 3 lines
Cheers,

David / dhildenb
author
#7 lore raw

Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers

Quoted 22 lines · David Hildenbrand
Quoted 20 lines · Nico Pache
Quoted 7 lines · David Hildenbrand
Quoted 2 lines · Nico Pache

Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and expose it through /proc/meminfo and other memory reporting interfaces.

In balloon_page_enqueue_one(), we perform a

Quoted 8 lines

__count_vm_event(BALLOON_INFLATE)

and in balloon_page_list_dequeue

__count_vm_event(BALLOON_DEFLATE);

Should we maybe simply do the per-node accounting similarly there?

I think the issue is that some balloon drivers use the balloon_compaction interface while others use their own.

Quoted 6 lines
Quoted 2 lines

This would require unifying all the drivers under a single api which may be tricky if they all have different behavior

Why would that be required? Simply implement it in the balloon compaction logic, and in addition separately in the ones that don't implement it.

Ah ok that makes sense!

Quoted 10 lines

That's the same as how we handle PageOffline today.

In summary, we have

virtio-balloon: balloon compaction
hv-balloon: no balloon compaction
xen-balloon: no balloon compaction
vmx-balloon: balloon compaction
pseries-cmm: balloon compaction

I'm having a hard time verifying this... it looks like only vmx-balloon uses the balloon_compaction balloon_page_list_enqueue function that calls balloon_page_enqueue_one.

Quoted 4 lines

So you'd handle 3 balloon drivers in one go.

(this series didn't touch pseries-cmm)

Ah I didn't realize that was a balloon driver. Ill add that one to the todo.

Quoted 6 lines

--
Cheers,

David / dhildenb

#8 lore raw

Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers

Quoted 43 lines · Nico Pache
Quoted 22 lines · David Hildenbrand
Quoted 20 lines · Nico Pache
Quoted 7 lines · David Hildenbrand
Quoted 2 lines · Nico Pache

Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and expose it through /proc/meminfo and other memory reporting interfaces.

In balloon_page_enqueue_one(), we perform a

Quoted 8 lines

__count_vm_event(BALLOON_INFLATE)

and in balloon_page_list_dequeue

__count_vm_event(BALLOON_DEFLATE);

Should we maybe simply do the per-node accounting similarly there?

I think the issue is that some balloon drivers use the balloon_compaction interface while others use their own.

Quoted 6 lines
Quoted 2 lines

This would require unifying all the drivers under a single api which may be tricky if they all have different behavior

Why would that be required? Simply implement it in the balloon compaction logic, and in addition separately in the ones that don't implement it.

Ah ok that makes sense!

Quoted 10 lines

That's the same as how we handle PageOffline today.

In summary, we have

virtio-balloon: balloon compaction
hv-balloon: no balloon compaction
xen-balloon: no balloon compaction
vmx-balloon: balloon compaction
pseries-cmm: balloon compaction

Quoted 3 lines

I'm having a hard time verifying this... it looks like only vmx-balloon uses the balloon_compaction balloon_page_list_enqueue function that calls balloon_page_enqueue_one.

Also check balloon_page_enqueue, which ends up calling balloon_page_enqueue_one.

Quoted 6 lines
Quoted 5 lines

So you'd handle 3 balloon drivers in one go.

(this series didn't touch pseries-cmm)

Ah I didn't realize that was a balloon driver. Ill add that one to the todo.

Well, by implementing it in the compaction code that todo would be done :)

Signature · 3 lines
Cheers,

David / dhildenb