linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC 0/5] track memory used by balloon drivers
@ 2025-03-12  0:06 Nico Pache
  2025-03-12  0:06 ` [RFC 1/5] meminfo: add a per node counter for " Nico Pache
                   ` (4 more replies)
  0 siblings, 5 replies; 20+ messages in thread
From: Nico Pache @ 2025-03-12  0:06 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups
  Cc: kys, haiyangz, wei.liu, decui, jerrin.shaji-george,
	bcm-kernel-feedback-list, arnd, gregkh, mst, david, jasowang,
	xuanzhuo, eperezma, jgross, sstabellini, oleksandr_tyshchenko,
	akpm, hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song,
	nphamcs, yosry.ahmed, kanchana.p.sridhar, alexander.atanasov

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
Signed-off-by: Nico Pache <npache@redhat.com>

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(-)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC 1/5] meminfo: add a per node counter for balloon drivers
  2025-03-12  0:06 [RFC 0/5] track memory used by balloon drivers Nico Pache
@ 2025-03-12  0:06 ` Nico Pache
  2025-03-12  4:20   ` Shakeel Butt
  2025-03-12 22:19   ` David Hildenbrand
  2025-03-12  0:06 ` [RFC 2/5] virtio_balloon: update the NR_BALLOON_PAGES state Nico Pache
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 20+ messages in thread
From: Nico Pache @ 2025-03-12  0:06 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups
  Cc: kys, haiyangz, wei.liu, decui, jerrin.shaji-george,
	bcm-kernel-feedback-list, arnd, gregkh, mst, david, jasowang,
	xuanzhuo, eperezma, jgross, sstabellini, oleksandr_tyshchenko,
	akpm, hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song,
	nphamcs, yosry.ahmed, kanchana.p.sridhar, alexander.atanasov

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

Signed-off-by: Nico Pache <npache@redhat.com>
---
 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(-)

diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 8ba9b1472390..83be312159c9 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -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);
 
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 9540b41894da..71d3ff19267a 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -223,6 +223,7 @@ enum node_stat_item {
 #ifdef CONFIG_HUGETLB_PAGE
 	NR_HUGETLB,
 #endif
+	NR_BALLOON_PAGES,
 	NR_VM_NODE_STAT_ITEMS
 };
 
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4de6acb9b8ec..182b44646bfa 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -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		},
diff --git a/mm/show_mem.c b/mm/show_mem.c
index 43afb56abbd3..6af13bcd2ab3 100644
--- a/mm/show_mem.c
+++ b/mm/show_mem.c
@@ -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) {
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 16bfe1c694dd..d3b11891a942 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -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",
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC 2/5] virtio_balloon: update the NR_BALLOON_PAGES state
  2025-03-12  0:06 [RFC 0/5] track memory used by balloon drivers Nico Pache
  2025-03-12  0:06 ` [RFC 1/5] meminfo: add a per node counter for " Nico Pache
@ 2025-03-12  0:06 ` Nico Pache
  2025-03-12  6:55   ` Michael S. Tsirkin
  2025-03-12  0:06 ` [RFC 3/5] hv_balloon: " Nico Pache
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 20+ messages in thread
From: Nico Pache @ 2025-03-12  0:06 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups
  Cc: kys, haiyangz, wei.liu, decui, jerrin.shaji-george,
	bcm-kernel-feedback-list, arnd, gregkh, mst, david, jasowang,
	xuanzhuo, eperezma, jgross, sstabellini, oleksandr_tyshchenko,
	akpm, hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song,
	nphamcs, yosry.ahmed, kanchana.p.sridhar, alexander.atanasov

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

Signed-off-by: Nico Pache <npache@redhat.com>
---
 drivers/virtio/virtio_balloon.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 89da052f4f68..406414dbb477 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -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;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC 3/5] hv_balloon: update the NR_BALLOON_PAGES state
  2025-03-12  0:06 [RFC 0/5] track memory used by balloon drivers Nico Pache
  2025-03-12  0:06 ` [RFC 1/5] meminfo: add a per node counter for " Nico Pache
  2025-03-12  0:06 ` [RFC 2/5] virtio_balloon: update the NR_BALLOON_PAGES state Nico Pache
@ 2025-03-12  0:06 ` Nico Pache
  2025-03-12  0:06 ` [RFC 4/5] vmx_balloon: " Nico Pache
  2025-03-12  0:07 ` [RFC 5/5] xen: balloon: " Nico Pache
  4 siblings, 0 replies; 20+ messages in thread
From: Nico Pache @ 2025-03-12  0:06 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups
  Cc: kys, haiyangz, wei.liu, decui, jerrin.shaji-george,
	bcm-kernel-feedback-list, arnd, gregkh, mst, david, jasowang,
	xuanzhuo, eperezma, jgross, sstabellini, oleksandr_tyshchenko,
	akpm, hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song,
	nphamcs, yosry.ahmed, kanchana.p.sridhar, alexander.atanasov

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

Signed-off-by: Nico Pache <npache@redhat.com>
---
 drivers/hv/hv_balloon.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
index fec2f18679e3..2b4080e51f97 100644
--- a/drivers/hv/hv_balloon.c
+++ b/drivers/hv/hv_balloon.c
@@ -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
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC 4/5] vmx_balloon: update the NR_BALLOON_PAGES state
  2025-03-12  0:06 [RFC 0/5] track memory used by balloon drivers Nico Pache
                   ` (2 preceding siblings ...)
  2025-03-12  0:06 ` [RFC 3/5] hv_balloon: " Nico Pache
@ 2025-03-12  0:06 ` Nico Pache
  2025-03-12  6:56   ` Michael S. Tsirkin
  2025-03-12  0:07 ` [RFC 5/5] xen: balloon: " Nico Pache
  4 siblings, 1 reply; 20+ messages in thread
From: Nico Pache @ 2025-03-12  0:06 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups
  Cc: kys, haiyangz, wei.liu, decui, jerrin.shaji-george,
	bcm-kernel-feedback-list, arnd, gregkh, mst, david, jasowang,
	xuanzhuo, eperezma, jgross, sstabellini, oleksandr_tyshchenko,
	akpm, hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song,
	nphamcs, yosry.ahmed, kanchana.p.sridhar, alexander.atanasov

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

Signed-off-by: Nico Pache <npache@redhat.com>
---
 drivers/misc/vmw_balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index c817d8c21641..2c70b08c6fb3 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -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);
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC 5/5] xen: balloon: update the NR_BALLOON_PAGES state
  2025-03-12  0:06 [RFC 0/5] track memory used by balloon drivers Nico Pache
                   ` (3 preceding siblings ...)
  2025-03-12  0:06 ` [RFC 4/5] vmx_balloon: " Nico Pache
@ 2025-03-12  0:07 ` Nico Pache
  4 siblings, 0 replies; 20+ messages in thread
From: Nico Pache @ 2025-03-12  0:07 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups
  Cc: kys, haiyangz, wei.liu, decui, jerrin.shaji-george,
	bcm-kernel-feedback-list, arnd, gregkh, mst, david, jasowang,
	xuanzhuo, eperezma, jgross, sstabellini, oleksandr_tyshchenko,
	akpm, hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song,
	nphamcs, yosry.ahmed, kanchana.p.sridhar, alexander.atanasov

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

Signed-off-by: Nico Pache <npache@redhat.com>
---
 drivers/xen/balloon.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 163f7f1d70f1..65d4e7fa1eb8 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -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;
 }
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers
  2025-03-12  0:06 ` [RFC 1/5] meminfo: add a per node counter for " Nico Pache
@ 2025-03-12  4:20   ` Shakeel Butt
  2025-03-12 20:14     ` Nico Pache
  2025-03-12 22:19   ` David Hildenbrand
  1 sibling, 1 reply; 20+ messages in thread
From: Shakeel Butt @ 2025-03-12  4:20 UTC (permalink / raw)
  To: Nico Pache
  Cc: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh, mst,
	david, jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	muchun.song, nphamcs, yosry.ahmed, kanchana.p.sridhar,
	alexander.atanasov

On Tue, Mar 11, 2025 at 06:06:56PM -0600, Nico Pache wrote:
> Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and
> expose it through /proc/meminfo and other memory reporting interfaces.
> 
> Signed-off-by: Nico Pache <npache@redhat.com>
> ---
>  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(-)
> 
> diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
> index 8ba9b1472390..83be312159c9 100644
> --- a/fs/proc/meminfo.c
> +++ b/fs/proc/meminfo.c
> @@ -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);
>  
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index 9540b41894da..71d3ff19267a 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -223,6 +223,7 @@ enum node_stat_item {
>  #ifdef CONFIG_HUGETLB_PAGE
>  	NR_HUGETLB,
>  #endif
> +	NR_BALLOON_PAGES,
>  	NR_VM_NODE_STAT_ITEMS
>  };
>  
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 4de6acb9b8ec..182b44646bfa 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -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.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 2/5] virtio_balloon: update the NR_BALLOON_PAGES state
  2025-03-12  0:06 ` [RFC 2/5] virtio_balloon: update the NR_BALLOON_PAGES state Nico Pache
@ 2025-03-12  6:55   ` Michael S. Tsirkin
  0 siblings, 0 replies; 20+ messages in thread
From: Michael S. Tsirkin @ 2025-03-12  6:55 UTC (permalink / raw)
  To: Nico Pache
  Cc: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh,
	david, jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	shakeel.butt, muchun.song, nphamcs, yosry.ahmed,
	kanchana.p.sridhar, alexander.atanasov

On Tue, Mar 11, 2025 at 06:06:57PM -0600, Nico Pache wrote:
> Update the NR_BALLOON_PAGES counter when pages are added to or
> removed from the virtio balloon.
> 
> Signed-off-by: Nico Pache <npache@redhat.com>
> ---
>  drivers/virtio/virtio_balloon.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 89da052f4f68..406414dbb477 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -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.


> @@ -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,

>  	}
>  
>  	num_freed_pages = vb->num_pfns;
> -- 
> 2.48.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 4/5] vmx_balloon: update the NR_BALLOON_PAGES state
  2025-03-12  0:06 ` [RFC 4/5] vmx_balloon: " Nico Pache
@ 2025-03-12  6:56   ` Michael S. Tsirkin
  2025-03-12 20:11     ` Nico Pache
  0 siblings, 1 reply; 20+ messages in thread
From: Michael S. Tsirkin @ 2025-03-12  6:56 UTC (permalink / raw)
  To: Nico Pache
  Cc: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh,
	david, jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	shakeel.butt, muchun.song, nphamcs, yosry.ahmed,
	kanchana.p.sridhar, alexander.atanasov

On Tue, Mar 11, 2025 at 06:06:59PM -0600, Nico Pache wrote:
> Update the NR_BALLOON_PAGES counter when pages are added to or
> removed from the VMware balloon.
> 
> Signed-off-by: Nico Pache <npache@redhat.com>
> ---
>  drivers/misc/vmw_balloon.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
> index c817d8c21641..2c70b08c6fb3 100644
> --- a/drivers/misc/vmw_balloon.c
> +++ b/drivers/misc/vmw_balloon.c
> @@ -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.

>  		}
>  
>  		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);
> -


unrelated change

>  		vmballoon_enqueue_page_list(b, &ctl.pages, &ctl.n_pages,
>  					    ctl.page_size);
>  
> -- 
> 2.48.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 4/5] vmx_balloon: update the NR_BALLOON_PAGES state
  2025-03-12  6:56   ` Michael S. Tsirkin
@ 2025-03-12 20:11     ` Nico Pache
  2025-03-12 20:57       ` Michael S. Tsirkin
  2025-03-12 22:17       ` David Hildenbrand
  0 siblings, 2 replies; 20+ messages in thread
From: Nico Pache @ 2025-03-12 20:11 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh,
	david, jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	shakeel.butt, muchun.song, nphamcs, yosry.ahmed,
	kanchana.p.sridhar, alexander.atanasov

On Wed, Mar 12, 2025 at 12:57 AM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Tue, Mar 11, 2025 at 06:06:59PM -0600, Nico Pache wrote:
> > Update the NR_BALLOON_PAGES counter when pages are added to or
> > removed from the VMware balloon.
> >
> > Signed-off-by: Nico Pache <npache@redhat.com>
> > ---
> >  drivers/misc/vmw_balloon.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
> > index c817d8c21641..2c70b08c6fb3 100644
> > --- a/drivers/misc/vmw_balloon.c
> > +++ b/drivers/misc/vmw_balloon.c
> > @@ -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.
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.

>
> >               }
> >
> >               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);
> > -
>
>
> unrelated change
Fixed, Thanks for reviewing!
>
> >               vmballoon_enqueue_page_list(b, &ctl.pages, &ctl.n_pages,
> >                                           ctl.page_size);
> >
> > --
> > 2.48.1
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers
  2025-03-12  4:20   ` Shakeel Butt
@ 2025-03-12 20:14     ` Nico Pache
  0 siblings, 0 replies; 20+ messages in thread
From: Nico Pache @ 2025-03-12 20:14 UTC (permalink / raw)
  To: Shakeel Butt
  Cc: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh, mst,
	david, jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	muchun.song, nphamcs, yosry.ahmed, kanchana.p.sridhar,
	alexander.atanasov

On Tue, Mar 11, 2025 at 10:21 PM Shakeel Butt <shakeel.butt@linux.dev> wrote:
>
> On Tue, Mar 11, 2025 at 06:06:56PM -0600, Nico Pache wrote:
> > Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and
> > expose it through /proc/meminfo and other memory reporting interfaces.
> >
> > Signed-off-by: Nico Pache <npache@redhat.com>
> > ---
> >  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(-)
> >
> > diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
> > index 8ba9b1472390..83be312159c9 100644
> > --- a/fs/proc/meminfo.c
> > +++ b/fs/proc/meminfo.c
> > @@ -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);
> >
> > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> > index 9540b41894da..71d3ff19267a 100644
> > --- a/include/linux/mmzone.h
> > +++ b/include/linux/mmzone.h
> > @@ -223,6 +223,7 @@ enum node_stat_item {
> >  #ifdef CONFIG_HUGETLB_PAGE
> >       NR_HUGETLB,
> >  #endif
> > +     NR_BALLOON_PAGES,
> >       NR_VM_NODE_STAT_ITEMS
> >  };
> >
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index 4de6acb9b8ec..182b44646bfa 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -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!
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 4/5] vmx_balloon: update the NR_BALLOON_PAGES state
  2025-03-12 20:11     ` Nico Pache
@ 2025-03-12 20:57       ` Michael S. Tsirkin
  2025-03-12 22:17       ` David Hildenbrand
  1 sibling, 0 replies; 20+ messages in thread
From: Michael S. Tsirkin @ 2025-03-12 20:57 UTC (permalink / raw)
  To: Nico Pache
  Cc: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh,
	david, jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	shakeel.butt, muchun.song, nphamcs, yosry.ahmed,
	kanchana.p.sridhar, alexander.atanasov

On Wed, Mar 12, 2025 at 02:11:09PM -0600, Nico Pache wrote:
> On Wed, Mar 12, 2025 at 12:57 AM Michael S. Tsirkin <mst@redhat.com> wrote:
> >
> > On Tue, Mar 11, 2025 at 06:06:59PM -0600, Nico Pache wrote:
> > > Update the NR_BALLOON_PAGES counter when pages are added to or
> > > removed from the VMware balloon.
> > >
> > > Signed-off-by: Nico Pache <npache@redhat.com>
> > > ---
> > >  drivers/misc/vmw_balloon.c | 5 ++++-
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
> > > index c817d8c21641..2c70b08c6fb3 100644
> > > --- a/drivers/misc/vmw_balloon.c
> > > +++ b/drivers/misc/vmw_balloon.c
> > > @@ -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.
> 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.


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

> >
> > >               }
> > >
> > >               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);
> > > -
> >
> >
> > unrelated change
> Fixed, Thanks for reviewing!
> >
> > >               vmballoon_enqueue_page_list(b, &ctl.pages, &ctl.n_pages,
> > >                                           ctl.page_size);
> > >
> > > --
> > > 2.48.1
> >


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 4/5] vmx_balloon: update the NR_BALLOON_PAGES state
  2025-03-12 20:11     ` Nico Pache
  2025-03-12 20:57       ` Michael S. Tsirkin
@ 2025-03-12 22:17       ` David Hildenbrand
  1 sibling, 0 replies; 20+ messages in thread
From: David Hildenbrand @ 2025-03-12 22:17 UTC (permalink / raw)
  To: Nico Pache, Michael S. Tsirkin
  Cc: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh,
	jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	shakeel.butt, muchun.song, nphamcs, yosry.ahmed,
	kanchana.p.sridhar, alexander.atanasov

On 12.03.25 21:11, Nico Pache wrote:
> On Wed, Mar 12, 2025 at 12:57 AM Michael S. Tsirkin <mst@redhat.com> wrote:
>>
>> On Tue, Mar 11, 2025 at 06:06:59PM -0600, Nico Pache wrote:
>>> Update the NR_BALLOON_PAGES counter when pages are added to or
>>> removed from the VMware balloon.
>>>
>>> Signed-off-by: Nico Pache <npache@redhat.com>
>>> ---
>>>   drivers/misc/vmw_balloon.c | 5 ++++-
>>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
>>> index c817d8c21641..2c70b08c6fb3 100644
>>> --- a/drivers/misc/vmw_balloon.c
>>> +++ b/drivers/misc/vmw_balloon.c
>>> @@ -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.
> 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.

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.

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers
  2025-03-12  0:06 ` [RFC 1/5] meminfo: add a per node counter for " Nico Pache
  2025-03-12  4:20   ` Shakeel Butt
@ 2025-03-12 22:19   ` David Hildenbrand
  2025-03-12 23:04     ` Nico Pache
  2025-03-13  7:20     ` Michael S. Tsirkin
  1 sibling, 2 replies; 20+ messages in thread
From: David Hildenbrand @ 2025-03-12 22:19 UTC (permalink / raw)
  To: Nico Pache, linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups
  Cc: kys, haiyangz, wei.liu, decui, jerrin.shaji-george,
	bcm-kernel-feedback-list, arnd, gregkh, mst, jasowang, xuanzhuo,
	eperezma, jgross, sstabellini, oleksandr_tyshchenko, akpm, hannes,
	mhocko, roman.gushchin, shakeel.butt, muchun.song, nphamcs,
	yosry.ahmed, kanchana.p.sridhar, alexander.atanasov

On 12.03.25 01:06, Nico Pache wrote:
> 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?

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers
  2025-03-12 22:19   ` David Hildenbrand
@ 2025-03-12 23:04     ` Nico Pache
  2025-03-13  8:22       ` David Hildenbrand
  2025-03-13  7:20     ` Michael S. Tsirkin
  1 sibling, 1 reply; 20+ messages in thread
From: Nico Pache @ 2025-03-12 23:04 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh, mst,
	jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	shakeel.butt, muchun.song, nphamcs, yosry.ahmed,
	kanchana.p.sridhar, alexander.atanasov

On Wed, Mar 12, 2025 at 4:19 PM David Hildenbrand <david@redhat.com> wrote:
>
> On 12.03.25 01:06, Nico Pache wrote:
> > 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?

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
>
> --
> Cheers,
>
> David / dhildenb
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers
  2025-03-12 22:19   ` David Hildenbrand
  2025-03-12 23:04     ` Nico Pache
@ 2025-03-13  7:20     ` Michael S. Tsirkin
  2025-03-13  8:17       ` David Hildenbrand
  1 sibling, 1 reply; 20+ messages in thread
From: Michael S. Tsirkin @ 2025-03-13  7:20 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Nico Pache, linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh,
	jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	shakeel.butt, muchun.song, nphamcs, yosry.ahmed,
	kanchana.p.sridhar, alexander.atanasov

On Wed, Mar 12, 2025 at 11:19:06PM +0100, David Hildenbrand wrote:
> On 12.03.25 01:06, Nico Pache wrote:
> > 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?


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

> -- 
> Cheers,
> 
> David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers
  2025-03-13  7:20     ` Michael S. Tsirkin
@ 2025-03-13  8:17       ` David Hildenbrand
  0 siblings, 0 replies; 20+ messages in thread
From: David Hildenbrand @ 2025-03-13  8:17 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Nico Pache, linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh,
	jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	shakeel.butt, muchun.song, nphamcs, yosry.ahmed,
	kanchana.p.sridhar, alexander.atanasov

On 13.03.25 08:20, Michael S. Tsirkin wrote:
> On Wed, Mar 12, 2025 at 11:19:06PM +0100, David Hildenbrand wrote:
>> On 12.03.25 01:06, Nico Pache wrote:
>>> 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?
> 
> 
> 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.

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers
  2025-03-12 23:04     ` Nico Pache
@ 2025-03-13  8:22       ` David Hildenbrand
  2025-03-13 17:35         ` Nico Pache
  0 siblings, 1 reply; 20+ messages in thread
From: David Hildenbrand @ 2025-03-13  8:22 UTC (permalink / raw)
  To: Nico Pache
  Cc: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh, mst,
	jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	shakeel.butt, muchun.song, nphamcs, yosry.ahmed,
	kanchana.p.sridhar, alexander.atanasov

On 13.03.25 00:04, Nico Pache wrote:
> On Wed, Mar 12, 2025 at 4:19 PM David Hildenbrand <david@redhat.com> wrote:
>>
>> On 12.03.25 01:06, Nico Pache wrote:
>>> 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?
> 
> 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)

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers
  2025-03-13  8:22       ` David Hildenbrand
@ 2025-03-13 17:35         ` Nico Pache
  2025-03-13 22:33           ` David Hildenbrand
  0 siblings, 1 reply; 20+ messages in thread
From: Nico Pache @ 2025-03-13 17:35 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh, mst,
	jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	shakeel.butt, muchun.song, nphamcs, yosry.ahmed,
	kanchana.p.sridhar, alexander.atanasov

On Thu, Mar 13, 2025 at 2:22 AM David Hildenbrand <david@redhat.com> wrote:
>
> On 13.03.25 00:04, Nico Pache wrote:
> > On Wed, Mar 12, 2025 at 4:19 PM David Hildenbrand <david@redhat.com> wrote:
> >>
> >> On 12.03.25 01:06, Nico Pache wrote:
> >>> 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?
> >
> > 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.

Ah ok that makes sense!

>
> 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.

>
> 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.
>
> --
> Cheers,
>
> David / dhildenb
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC 1/5] meminfo: add a per node counter for balloon drivers
  2025-03-13 17:35         ` Nico Pache
@ 2025-03-13 22:33           ` David Hildenbrand
  0 siblings, 0 replies; 20+ messages in thread
From: David Hildenbrand @ 2025-03-13 22:33 UTC (permalink / raw)
  To: Nico Pache
  Cc: linux-hyperv, linux-kernel, virtualization, xen-devel,
	linux-fsdevel, linux-mm, cgroups, kys, haiyangz, wei.liu, decui,
	jerrin.shaji-george, bcm-kernel-feedback-list, arnd, gregkh, mst,
	jasowang, xuanzhuo, eperezma, jgross, sstabellini,
	oleksandr_tyshchenko, akpm, hannes, mhocko, roman.gushchin,
	shakeel.butt, muchun.song, nphamcs, yosry.ahmed,
	kanchana.p.sridhar, alexander.atanasov

On 13.03.25 18:35, Nico Pache wrote:
> On Thu, Mar 13, 2025 at 2:22 AM David Hildenbrand <david@redhat.com> wrote:
>>
>> On 13.03.25 00:04, Nico Pache wrote:
>>> On Wed, Mar 12, 2025 at 4:19 PM David Hildenbrand <david@redhat.com> wrote:
>>>>
>>>> On 12.03.25 01:06, Nico Pache wrote:
>>>>> 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?
>>>
>>> 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.
> 
> Ah ok that makes sense!
> 
>>
>> 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.

Also check balloon_page_enqueue, which ends up calling 
balloon_page_enqueue_one.

> 
>>
>> 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 :)

-- 
Cheers,

David / dhildenb


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2025-03-13 22:33 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-12  0:06 [RFC 0/5] track memory used by balloon drivers Nico Pache
2025-03-12  0:06 ` [RFC 1/5] meminfo: add a per node counter for " Nico Pache
2025-03-12  4:20   ` Shakeel Butt
2025-03-12 20:14     ` Nico Pache
2025-03-12 22:19   ` David Hildenbrand
2025-03-12 23:04     ` Nico Pache
2025-03-13  8:22       ` David Hildenbrand
2025-03-13 17:35         ` Nico Pache
2025-03-13 22:33           ` David Hildenbrand
2025-03-13  7:20     ` Michael S. Tsirkin
2025-03-13  8:17       ` David Hildenbrand
2025-03-12  0:06 ` [RFC 2/5] virtio_balloon: update the NR_BALLOON_PAGES state Nico Pache
2025-03-12  6:55   ` Michael S. Tsirkin
2025-03-12  0:06 ` [RFC 3/5] hv_balloon: " Nico Pache
2025-03-12  0:06 ` [RFC 4/5] vmx_balloon: " Nico Pache
2025-03-12  6:56   ` Michael S. Tsirkin
2025-03-12 20:11     ` Nico Pache
2025-03-12 20:57       ` Michael S. Tsirkin
2025-03-12 22:17       ` David Hildenbrand
2025-03-12  0:07 ` [RFC 5/5] xen: balloon: " Nico Pache

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).