* [PATCH v2 0/4] track memory used by balloon drivers
@ 2025-03-14 21:37 Nico Pache
2025-03-14 21:37 ` [PATCH v2 1/4] meminfo: add a per node counter for " Nico Pache
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Nico Pache @ 2025-03-14 21:37 UTC (permalink / raw)
To: linux-hyperv, linux-kernel, xen-devel, linux-fsdevel, linux-mm,
virtualization
Cc: alexander.atanasov, muchun.song, roman.gushchin, mhocko, kys,
haiyangz, wei.liu, decui, jgross, sstabellini,
oleksandr_tyshchenko, akpm, mst, david, yosry.ahmed, hannes,
nphamcs, chengming.zhou, kanchana.p.sridhar, llong, shakeel.butt
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, Pseries-cmm, and Xen) to maintain this counter. The
virtio, Vmware, and pseries-cmm balloon drivers utilize the balloon_compaction
interface to allocate and free balloon pages. Other balloon drivers will have to
maintain this counter manually.
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.
V2 changes:
- Add counter to the balloon_compaction interface
- Dropped patches for virtio and VMware as they use balloon_compaction interface
Tested: virtio_balloon, run stress-ng, inflate balloon, oom prints
Signed-off-by: Nico Pache <npache@redhat.com>
Nico Pache (4):
meminfo: add a per node counter for balloon drivers
balloon_compaction: update the NR_BALLOON_PAGES state
hv_balloon: update the NR_BALLOON_PAGES state
xen: balloon: update the NR_BALLOON_PAGES state
drivers/hv/hv_balloon.c | 2 ++
drivers/xen/balloon.c | 4 ++++
fs/proc/meminfo.c | 2 ++
include/linux/mmzone.h | 1 +
mm/balloon_compaction.c | 2 ++
mm/show_mem.c | 4 +++-
mm/vmstat.c | 1 +
7 files changed, 15 insertions(+), 1 deletion(-)
--
2.48.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 1/4] meminfo: add a per node counter for balloon drivers
2025-03-14 21:37 [PATCH v2 0/4] track memory used by balloon drivers Nico Pache
@ 2025-03-14 21:37 ` Nico Pache
2025-03-15 1:06 ` Andrew Morton
2025-03-14 21:37 ` [PATCH v2 2/4] balloon_compaction: update the NR_BALLOON_PAGES state Nico Pache
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Nico Pache @ 2025-03-14 21:37 UTC (permalink / raw)
To: linux-hyperv, linux-kernel, xen-devel, linux-fsdevel, linux-mm,
virtualization
Cc: alexander.atanasov, muchun.song, roman.gushchin, mhocko, kys,
haiyangz, wei.liu, decui, jgross, sstabellini,
oleksandr_tyshchenko, akpm, mst, david, yosry.ahmed, hannes,
nphamcs, chengming.zhou, kanchana.p.sridhar, llong, shakeel.butt
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/show_mem.c | 4 +++-
mm/vmstat.c | 1 +
4 files changed, 7 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/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 [flat|nested] 9+ messages in thread
* [PATCH v2 2/4] balloon_compaction: update the NR_BALLOON_PAGES state
2025-03-14 21:37 [PATCH v2 0/4] track memory used by balloon drivers Nico Pache
2025-03-14 21:37 ` [PATCH v2 1/4] meminfo: add a per node counter for " Nico Pache
@ 2025-03-14 21:37 ` Nico Pache
2025-03-14 21:37 ` [PATCH v2 3/4] hv_balloon: " Nico Pache
2025-03-14 21:37 ` [PATCH v2 4/4] xen: balloon: " Nico Pache
3 siblings, 0 replies; 9+ messages in thread
From: Nico Pache @ 2025-03-14 21:37 UTC (permalink / raw)
To: linux-hyperv, linux-kernel, xen-devel, linux-fsdevel, linux-mm,
virtualization
Cc: alexander.atanasov, muchun.song, roman.gushchin, mhocko, kys,
haiyangz, wei.liu, decui, jgross, sstabellini,
oleksandr_tyshchenko, akpm, mst, david, yosry.ahmed, hannes,
nphamcs, chengming.zhou, kanchana.p.sridhar, llong, shakeel.butt
Update the NR_BALLOON_PAGES counter when pages are added or removed using
the balloon compaction interface.
The virtio, Vmware, and pseries-cmm balloon drivers utilize the
balloon_compaction interface to allocate and free balloon pages. Other
balloon drivers will have to maintain this counter manually.
Signed-off-by: Nico Pache <npache@redhat.com>
---
mm/balloon_compaction.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index 6597ebea8ae2..d3e00731e262 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -24,6 +24,7 @@ static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info,
balloon_page_insert(b_dev_info, page);
unlock_page(page);
__count_vm_event(BALLOON_INFLATE);
+ inc_node_page_state(page, NR_BALLOON_PAGES);
}
/**
@@ -103,6 +104,7 @@ size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
__count_vm_event(BALLOON_DEFLATE);
list_add(&page->lru, pages);
unlock_page(page);
+ dec_node_page_state(page, NR_BALLOON_PAGES);
n_pages++;
}
spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
--
2.48.1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2 3/4] hv_balloon: update the NR_BALLOON_PAGES state
2025-03-14 21:37 [PATCH v2 0/4] track memory used by balloon drivers Nico Pache
2025-03-14 21:37 ` [PATCH v2 1/4] meminfo: add a per node counter for " Nico Pache
2025-03-14 21:37 ` [PATCH v2 2/4] balloon_compaction: update the NR_BALLOON_PAGES state Nico Pache
@ 2025-03-14 21:37 ` Nico Pache
2025-03-15 4:09 ` Michael Kelley
2025-03-14 21:37 ` [PATCH v2 4/4] xen: balloon: " Nico Pache
3 siblings, 1 reply; 9+ messages in thread
From: Nico Pache @ 2025-03-14 21:37 UTC (permalink / raw)
To: linux-hyperv, linux-kernel, xen-devel, linux-fsdevel, linux-mm,
virtualization
Cc: alexander.atanasov, muchun.song, roman.gushchin, mhocko, kys,
haiyangz, wei.liu, decui, jgross, sstabellini,
oleksandr_tyshchenko, akpm, mst, david, yosry.ahmed, hannes,
nphamcs, chengming.zhou, kanchana.p.sridhar, llong, shakeel.butt
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 [flat|nested] 9+ messages in thread
* [PATCH v2 4/4] xen: balloon: update the NR_BALLOON_PAGES state
2025-03-14 21:37 [PATCH v2 0/4] track memory used by balloon drivers Nico Pache
` (2 preceding siblings ...)
2025-03-14 21:37 ` [PATCH v2 3/4] hv_balloon: " Nico Pache
@ 2025-03-14 21:37 ` Nico Pache
2025-03-18 10:16 ` Jürgen Groß
3 siblings, 1 reply; 9+ messages in thread
From: Nico Pache @ 2025-03-14 21:37 UTC (permalink / raw)
To: linux-hyperv, linux-kernel, xen-devel, linux-fsdevel, linux-mm,
virtualization
Cc: alexander.atanasov, muchun.song, roman.gushchin, mhocko, kys,
haiyangz, wei.liu, decui, jgross, sstabellini,
oleksandr_tyshchenko, akpm, mst, david, yosry.ahmed, hannes,
nphamcs, chengming.zhou, kanchana.p.sridhar, llong, shakeel.butt
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 [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/4] meminfo: add a per node counter for balloon drivers
2025-03-14 21:37 ` [PATCH v2 1/4] meminfo: add a per node counter for " Nico Pache
@ 2025-03-15 1:06 ` Andrew Morton
2025-03-17 22:37 ` Nico Pache
0 siblings, 1 reply; 9+ messages in thread
From: Andrew Morton @ 2025-03-15 1:06 UTC (permalink / raw)
To: Nico Pache
Cc: linux-hyperv, linux-kernel, xen-devel, linux-fsdevel, linux-mm,
virtualization, alexander.atanasov, muchun.song, roman.gushchin,
mhocko, kys, haiyangz, wei.liu, decui, jgross, sstabellini,
oleksandr_tyshchenko, mst, david, yosry.ahmed, hannes, nphamcs,
chengming.zhou, kanchana.p.sridhar, llong, shakeel.butt
On Fri, 14 Mar 2025 15:37:54 -0600 Nico Pache <npache@redhat.com> wrote:
> Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and
> expose it through /proc/meminfo and other memory reporting interfaces.
>
> ...
>
> --- 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));
Please update Documentation/filesystems/proc.rst for this.
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: [PATCH v2 3/4] hv_balloon: update the NR_BALLOON_PAGES state
2025-03-14 21:37 ` [PATCH v2 3/4] hv_balloon: " Nico Pache
@ 2025-03-15 4:09 ` Michael Kelley
0 siblings, 0 replies; 9+ messages in thread
From: Michael Kelley @ 2025-03-15 4:09 UTC (permalink / raw)
To: Nico Pache, linux-hyperv, linux-kernel, xen-devel, linux-fsdevel,
linux-mm, virtualization
Cc: alexander.atanasov, muchun.song, roman.gushchin, mhocko, kys,
haiyangz, wei.liu, decui, jgross, sstabellini,
oleksandr_tyshchenko, akpm, mst, david, yosry.ahmed, hannes,
nphamcs, chengming.zhou, kanchana.p.sridhar, llong, shakeel.butt
From: Nico Pache <npache@redhat.com> Sent: Friday, March 14, 2025 2:38 PM
>
> 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
>
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 <mhklinux@outlook.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 1/4] meminfo: add a per node counter for balloon drivers
2025-03-15 1:06 ` Andrew Morton
@ 2025-03-17 22:37 ` Nico Pache
0 siblings, 0 replies; 9+ messages in thread
From: Nico Pache @ 2025-03-17 22:37 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-hyperv, linux-kernel, xen-devel, linux-fsdevel, linux-mm,
virtualization, alexander.atanasov, muchun.song, roman.gushchin,
mhocko, kys, haiyangz, wei.liu, decui, jgross, sstabellini,
oleksandr_tyshchenko, mst, david, yosry.ahmed, hannes, nphamcs,
chengming.zhou, kanchana.p.sridhar, llong, shakeel.butt
On 3/14/25 7:06 PM, Andrew Morton wrote:
> On Fri, 14 Mar 2025 15:37:54 -0600 Nico Pache <npache@redhat.com> wrote:
>
>> Add NR_BALLOON_PAGES counter to track memory used by balloon drivers and
>> expose it through /proc/meminfo and other memory reporting interfaces.
>>
>> ...
>>
>> --- 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));
>
> Please update Documentation/filesystems/proc.rst for this.
@Andrew
Can you please squash the following?
From b1b379a32752e64c60b5e3b6365c93db8e1daf9f Mon Sep 17 00:00:00 2001
From: Nico Pache <npache@redhat.com>
Date: Mon, 17 Mar 2025 16:07:18 -0600
Subject: [PATCH] Documentation: document Balloon Meminfo entry
Add a Balloon entry to the Meminfo documention.
Signed-off-by: Nico Pache <npache@redhat.com>
---
Documentation/filesystems/proc.rst | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst
index 09f0aed5a08b..2868bb74f76e 100644
--- a/Documentation/filesystems/proc.rst
+++ b/Documentation/filesystems/proc.rst
@@ -1060,6 +1060,7 @@ Example output. You may not have all of these fields.
FilePmdMapped: 0 kB
CmaTotal: 0 kB
CmaFree: 0 kB
+ Balloon: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
@@ -1228,6 +1229,8 @@ CmaTotal
Memory reserved for the Contiguous Memory Allocator (CMA)
CmaFree
Free remaining memory in the CMA reserves
+Balloon
+ Memory returned to Host by VM Balloon Drivers
HugePages_Total, HugePages_Free, HugePages_Rsvd, HugePages_Surp, Hugepagesize,
Hugetlb
See Documentation/admin-guide/mm/hugetlbpage.rst.
DirectMap4k, DirectMap2M, DirectMap1G
--
2.48.1
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2 4/4] xen: balloon: update the NR_BALLOON_PAGES state
2025-03-14 21:37 ` [PATCH v2 4/4] xen: balloon: " Nico Pache
@ 2025-03-18 10:16 ` Jürgen Groß
0 siblings, 0 replies; 9+ messages in thread
From: Jürgen Groß @ 2025-03-18 10:16 UTC (permalink / raw)
To: Nico Pache, linux-hyperv, linux-kernel, xen-devel, linux-fsdevel,
linux-mm, virtualization
Cc: alexander.atanasov, muchun.song, roman.gushchin, mhocko, kys,
haiyangz, wei.liu, decui, sstabellini, oleksandr_tyshchenko,
akpm, mst, david, yosry.ahmed, hannes, nphamcs, chengming.zhou,
kanchana.p.sridhar, llong, shakeel.butt
[-- Attachment #1.1.1: Type: text/plain, Size: 251 bytes --]
On 14.03.25 22:37, Nico Pache wrote:
> 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>
Reviewed-by: Juergen Gross <jgross@suse.com>
Juergen
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3743 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 495 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-03-18 10:16 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-14 21:37 [PATCH v2 0/4] track memory used by balloon drivers Nico Pache
2025-03-14 21:37 ` [PATCH v2 1/4] meminfo: add a per node counter for " Nico Pache
2025-03-15 1:06 ` Andrew Morton
2025-03-17 22:37 ` Nico Pache
2025-03-14 21:37 ` [PATCH v2 2/4] balloon_compaction: update the NR_BALLOON_PAGES state Nico Pache
2025-03-14 21:37 ` [PATCH v2 3/4] hv_balloon: " Nico Pache
2025-03-15 4:09 ` Michael Kelley
2025-03-14 21:37 ` [PATCH v2 4/4] xen: balloon: " Nico Pache
2025-03-18 10:16 ` Jürgen Groß
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox