RE: [PATCH v2 3/4] hv_balloon: update the NR_BALLOON_PAGES state

From
Michael Kelley <hidden>
Date
2025-03-15 04:09:29
Also in
linux-fsdevel, linux-mm, lkml, virtualization, xen-devel
Reply to
Nico Pache, 2025-03-14
From: Nico Pache <redacted> Sent: Friday, March 14, 2025 2:38 PM
quoted hunk ↗ jump to hunk
Update the NR_BALLOON_PAGES counter when pages are added to or
removed from the Hyper-V balloon.

Signed-off-by: Nico Pache <redacted>
---
 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
As is evident from the code, the hv_balloon driver already has accounting
for the number of pages that have been ballooned out of the VM. This
accounting and other details of the hv_balloon driver state is available in
/sys/kernel/debug/hv-balloon when CONFIG_DEBUGFS=y. But it seems OK
to also report the # of pages ballooned through /proc/meminfo, which
works even if CONFIG_DEBUGFS=n.

Reviewed-by: Michael Kelley <redacted>
Thread (9 messages) 9 messages, 4 authors, last reply 2025-03-18
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help