Skip to contentSkip to conversation

hv_balloon: hide ballooned out memory in stats

PATCH Applied Vitaly Kuznetsov 3 participants 9 messages Dec 2, 2020 – Dec 13, 2020

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

cover hv_balloon: hide ballooned out memory in stats

It was noticed that 'free' information on a Hyper-V guest reports ballooned out memory in 'total' and this contradicts what other ballooning drivers (e.g. virtio-balloon/virtio-mem/xen balloon) do.

Vitaly Kuznetsov (2):
hv_balloon: simplify math in alloc_balloon_pages()
hv_balloon: do adjust_managed_page_count() when
ballooning/un-ballooning

 drivers/hv/hv_balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/2 hv_balloon: simplify math in alloc_balloon_pages()

'alloc_unit' in alloc_balloon_pages() is either '512' for 2M allocations or '1' for 4k allocations. So

1 << get_order(alloc_unit << PAGE_SHIFT)

equals to 'alloc_unit' and the for loop basically sets all them offline. Simplify the math to improve the readability.

---
 drivers/hv/hv_balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hv/hv_balloon.c +1 -1
index eb56e09ae15f..da3b6bd2367c 100644
@@ -1238,7 +1238,7 @@ static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm,
 			split_page(pg, get_order(alloc_unit << PAGE_SHIFT));
 
 		/* mark all pages offline */
-		for (j = 0; j < (1 << get_order(alloc_unit << PAGE_SHIFT)); j++)
+		for (j = 0; j < alloc_unit; j++)
 			__SetPageOffline(pg + j);
 
 		bl_resp->range_count++;
Signature · 1 line
2.26.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] hv_balloon: simplify math in alloc_balloon_pages()

Quoted 19 lines · Vitaly Kuznetsov

'alloc_unit' in alloc_balloon_pages() is either '512' for 2M allocations or '1' for 4k allocations. So

1 << get_order(alloc_unit << PAGE_SHIFT)

equals to 'alloc_unit' and the for loop basically sets all them offline. Simplify the math to improve the readability.

---
 drivers/hv/hv_balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hv/hv_balloon.c +0 -0
index eb56e09ae15f..da3b6bd2367c 100644

drivers/hv/hv_balloon.c static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm, · line 1244

Quoted 8 lines
drivers/hv/hv_balloon.c +1 -1
@@ -1238,7 +1238,7 @@ static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm,
 			split_page(pg, get_order(alloc_unit << PAGE_SHIFT));
 
 		/* mark all pages offline */
-		for (j = 0; j < (1 << get_order(alloc_unit << PAGE_SHIFT)); j++)
+		for (j = 0; j < alloc_unit; j++)
 			__SetPageOffline(pg + j);
 
 		bl_resp->range_count++;

Right, alloc_unit is multiples of 4k pages, such that it can directly be used for page ranges in deflation/inflation paths.

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw

PATCH 2/2 hv_balloon: do adjust_managed_page_count() when ballooning/un-ballooning

In reply to Vitaly Kuznetsov

Unlike virtio_balloon/virtio_mem/xen balloon drivers, Hyper-V balloon driver does not adjust managed pages count when ballooning/un-ballooning and this leads to incorrect stats being reported, e.g. unexpected 'free' output.

Note, the calculation in post_status() seems to remain correct: ballooned out pages are never 'available' and we manually add dm->num_pages_ballooned to 'commited'.

---
 drivers/hv/hv_balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hv/hv_balloon.c +4 -1
index da3b6bd2367c..8c471823a5af 100644
@@ -1198,6 +1198,7 @@ static void free_balloon_pages(struct hv_dynmem_device *dm,
 		__ClearPageOffline(pg);
 		__free_page(pg);
 		dm->num_pages_ballooned--;
+		adjust_managed_page_count(pg, 1);
 	}
 }
 
@@ -1238,8 +1239,10 @@ static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm,
 			split_page(pg, get_order(alloc_unit << PAGE_SHIFT));
 
 		/* mark all pages offline */
-		for (j = 0; j < alloc_unit; j++)
+		for (j = 0; j < alloc_unit; j++) {
 			__SetPageOffline(pg + j);
+			adjust_managed_page_count(pg + j, -1);
+		}
 
 		bl_resp->range_count++;
 		bl_resp->range_array[i].finfo.start_page =
Signature · 1 line
2.26.2
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] hv_balloon: do adjust_managed_page_count() when ballooning/un-ballooning

Quoted 29 lines · Vitaly Kuznetsov

Unlike virtio_balloon/virtio_mem/xen balloon drivers, Hyper-V balloon driver does not adjust managed pages count when ballooning/un-ballooning and this leads to incorrect stats being reported, e.g. unexpected 'free' output.

Note, the calculation in post_status() seems to remain correct: ballooned out pages are never 'available' and we manually add dm->num_pages_ballooned to 'commited'.

---
 drivers/hv/hv_balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hv/hv_balloon.c +1 -0
index da3b6bd2367c..8c471823a5af 100644
@@ -1198,6 +1198,7 @@ static void free_balloon_pages(struct hv_dynmem_device *dm,
 		__ClearPageOffline(pg);
 		__free_page(pg);
 		dm->num_pages_ballooned--;
+		adjust_managed_page_count(pg, 1);
 	}
 }
 
@@ -1238,8 +1239,10 @@ static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm,
 			split_page(pg, get_order(alloc_unit << PAGE_SHIFT));

drivers/hv/hv_balloon.c static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm, · line 1248

Quoted 10 lines
drivers/hv/hv_balloon.c +3 -1
 
 		/* mark all pages offline */
-		for (j = 0; j < alloc_unit; j++)
+		for (j = 0; j < alloc_unit; j++) {
 			__SetPageOffline(pg + j);
+			adjust_managed_page_count(pg + j, -1);
+		}
 
 		bl_resp->range_count++;
 		bl_resp->range_array[i].finfo.start_page =

I assume this has been properly tested such that it does not change the system behavior regarding when/how HyperV decides to add/remove memory.

LGTM

Signature · 3 lines
Thanks,

David / dhildenb
#5 lore raw

Re: [PATCH 2/2] hv_balloon: do adjust_managed_page_count() when ballooning/un-ballooning

Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Vitaly Kuznetsov

Unlike virtio_balloon/virtio_mem/xen balloon drivers, Hyper-V balloon driver does not adjust managed pages count when ballooning/un-ballooning and this leads to incorrect stats being reported, e.g. unexpected 'free' output.

Note, the calculation in post_status() seems to remain correct: ballooned out pages are never 'available' and we manually add dm->num_pages_ballooned to 'commited'.

---
 drivers/hv/hv_balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hv/hv_balloon.c +4 -1
index da3b6bd2367c..8c471823a5af 100644
@@ -1198,6 +1198,7 @@ static void free_balloon_pages(struct hv_dynmem_device *dm,
 		__ClearPageOffline(pg);
 		__free_page(pg);
 		dm->num_pages_ballooned--;
+		adjust_managed_page_count(pg, 1);
 	}
 }
 
@@ -1238,8 +1239,10 @@ static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm,
 			split_page(pg, get_order(alloc_unit << PAGE_SHIFT));
 
 		/* mark all pages offline */
-		for (j = 0; j < alloc_unit; j++)
+		for (j = 0; j < alloc_unit; j++) {
 			__SetPageOffline(pg + j);
+			adjust_managed_page_count(pg + j, -1);
+		}
 
Quoted 7 lines

drivers/hv/hv_balloon.c static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm, · line 1248

Quoted 3 lines
drivers/hv/hv_balloon.c +0 -0
 		bl_resp->range_count++;
 		bl_resp->range_array[i].finfo.start_page =

I assume this has been properly tested such that it does not change the system behavior regarding when/how HyperV decides to add/remove memory.

I'm always reluctant to confirm 'proper testing' as no matter how small and 'obvious' the change is, regressions keep happening :-) But yes, this was tested on a Hyper-V host and 'stress' and I observed 'free' when the balloon was both inflated and deflated, values looked sane.

Quoted 3 lines

LGTM

Thanks!

Signature · 1 line
Vitaly
#6 lore raw

Re: [PATCH 2/2] hv_balloon: do adjust_managed_page_count() when ballooning/un-ballooning

Quoted 47 lines · Vitaly Kuznetsov
Quoted 37 lines · David Hildenbrand
Quoted 36 lines · Vitaly Kuznetsov

Unlike virtio_balloon/virtio_mem/xen balloon drivers, Hyper-V balloon driver does not adjust managed pages count when ballooning/un-ballooning and this leads to incorrect stats being reported, e.g. unexpected 'free' output.

Note, the calculation in post_status() seems to remain correct: ballooned out pages are never 'available' and we manually add dm->num_pages_ballooned to 'commited'.

---
 drivers/hv/hv_balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hv/hv_balloon.c +4 -1
index da3b6bd2367c..8c471823a5af 100644
@@ -1198,6 +1198,7 @@ static void free_balloon_pages(struct hv_dynmem_device *dm,
 		__ClearPageOffline(pg);
 		__free_page(pg);
 		dm->num_pages_ballooned--;
+		adjust_managed_page_count(pg, 1);
 	}
 }
 
@@ -1238,8 +1239,10 @@ static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm,
 			split_page(pg, get_order(alloc_unit << PAGE_SHIFT));
 
 		/* mark all pages offline */
-		for (j = 0; j < alloc_unit; j++)
+		for (j = 0; j < alloc_unit; j++) {
 			__SetPageOffline(pg + j);
+			adjust_managed_page_count(pg + j, -1);
+		}
 
Quoted 7 lines

drivers/hv/hv_balloon.c static unsigned int alloc_balloon_pages(struct hv_dynmem_device *dm, · line 1248

Quoted 3 lines
drivers/hv/hv_balloon.c +0 -0
 		bl_resp->range_count++;
 		bl_resp->range_array[i].finfo.start_page =

I assume this has been properly tested such that it does not change the system behavior regarding when/how HyperV decides to add/remove memory.

Quoted 4 lines

I'm always reluctant to confirm 'proper testing' as no matter how small and 'obvious' the change is, regressions keep happening :-) But yes, this was tested on a Hyper-V host and 'stress' and I observed 'free' when the balloon was both inflated and deflated, values looked sane.

That;s what I wanted to hear ;)

Signature · 3 lines
Thanks,

David / dhildenb
maintainer
#7 lore raw
In reply to Vitaly Kuznetsov
Quoted 8 lines · Vitaly Kuznetsov

It was noticed that 'free' information on a Hyper-V guest reports ballooned out memory in 'total' and this contradicts what other ballooning drivers (e.g. virtio-balloon/virtio-mem/xen balloon) do.

Vitaly Kuznetsov (2):
hv_balloon: simplify math in alloc_balloon_pages()
hv_balloon: do adjust_managed_page_count() when
ballooning/un-ballooning

LGTM.

I will wait for a few more days before applying this series to hyperv-next.

Wei.

maintainer Applied
#8 lore raw
Quoted 10 lines · Wei Liu
Quoted 8 lines · Vitaly Kuznetsov

It was noticed that 'free' information on a Hyper-V guest reports ballooned out memory in 'total' and this contradicts what other ballooning drivers (e.g. virtio-balloon/virtio-mem/xen balloon) do.

Vitaly Kuznetsov (2):
hv_balloon: simplify math in alloc_balloon_pages()
hv_balloon: do adjust_managed_page_count() when
ballooning/un-ballooning

Quoted 4 lines

LGTM.

I will wait for a few more days before applying this series to hyperv-next.

Applied to hyperv-next.

Wei.