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

From
Michael S. Tsirkin <mst@redhat.com>
Date
2025-03-12 20:57:23
Also in
cgroups, linux-fsdevel, linux-hyperv, linux-mm, lkml, xen-devel
Reply to
Nico Pache, 2025-03-12
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 [off-list ref] wrote:
quoted
On Tue, Mar 11, 2025 at 06:06:59PM -0600, Nico Pache wrote:
quoted
Update the NR_BALLOON_PAGES counter when pages are added to or
removed from the VMware balloon.

Signed-off-by: Nico Pache <redacted>
---
 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.
quoted
quoted
              }

              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!
quoted
quoted
              vmballoon_enqueue_page_list(b, &ctl.pages, &ctl.n_pages,
                                          ctl.page_size);

--
2.48.1
  
Thread (20 messages) 20 messages, 4 authors, last reply 2025-03-13
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