Subject: Re: [PATCH v2 04/23] mm/balloon_compaction: centralize basic page migration handling

From: "David Hildenbrand (Red Hat)" <[email-masked]>
Date: Mon, 19 Jan 2026 23:22:08 +0100

On 1/15/26 10:19, David Hildenbrand (Red Hat) wrote:
> Let's update the balloon page references, the balloon page list, the
> BALLOON_MIGRATE counter and the isolated-pages counter in
> balloon_page_migrate(), after letting the balloon->migratepage()
> callback deal with the actual inflation+deflation.
> 
> Note that we now perform the balloon list modifications outside of any
> implementation-specific locks: which is fine, there is nothing special
> about these page actions that the lock would be protecting.
> 
> The old page is already no longer in the list (isolated) and the new page
> is not yet in the list.
> 
> Let's use -ENOENT to communicate the special "inflation of new page
> failed after already deflating the old page" to balloon_page_migrate() so
> it can handle it accordingly.
> 
> While at it, rename balloon->b_dev_info to make it match the other
> functions. Also, drop the comment above balloon_page_migrate(), which
> seems unnecessary.
> 
> Signed-off-by: David Hildenbrand (Red Hat) <[email-masked]>
> ---

Andrew, the following on top:

 From 4c8b4f0aba5859a4ec71c7449a98b10e0547237f Mon Sep 17 00:00:00 2001
From: "David Hildenbrand (Red Hat)" <[email-masked]>
Date: Mon, 19 Jan 2026 23:20:41 +0100
Subject: [PATCH] fixup: mm/balloon_compaction: centralize basic page migration
  handling

Remove newline, talk about "page" instead of "old page" and avoid the
switch.

Signed-off-by: David Hildenbrand (Red Hat) <[email-masked]>
---
  mm/balloon_compaction.c | 22 +++++++---------------
  1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index 5444c61bb9e76..b859411811d0b 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -247,29 +247,21 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
  		return -EAGAIN;
  
  	rc = b_dev_info->migratepage(b_dev_info, newpage, page, mode);
-	switch (rc) {
-	case 0:
-		spin_lock_irqsave(&b_dev_info->pages_lock, flags);
+	if (rc < 0 && rc != -ENOENT)
+		return rc;
  
+	spin_lock_irqsave(&b_dev_info->pages_lock, flags);
+	if (!rc) {
  		/* Insert the new page into the balloon list. */
  		get_page(newpage);
-
  		balloon_page_insert(b_dev_info, newpage);
-		__count_vm_event(BALLOON_MIGRATE);
-		break;
-	case -ENOENT:
-		spin_lock_irqsave(&b_dev_info->pages_lock, flags);
-
-		/* Old page was deflated but new page not inflated. */
-		__count_vm_event(BALLOON_DEFLATE);
-		break;
-	default:
-		return rc;
  	}
-
  	b_dev_info->isolated_pages--;
  	spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
  
+	/* If -ENOENT, page was deflated but new page not inflated. */
+	__count_vm_event(rc ? BALLOON_DEFLATE : BALLOON_MIGRATE);
+
  	/* Free the now-deflated page we isolated in balloon_page_isolate(). */
  	balloon_page_finalize(page);
  	put_page(page);
-- 
2.52.0

-- 
Cheers

David