[PATCH v3 00/24] mm: balloon infrastructure cleanups

David Hildenbrand (Red Hat) posted 24 patches 2 weeks, 4 days ago
.../admin-guide/mm/memory-hotplug.rst         |   8 +-
Documentation/core-api/mm-api.rst             |   2 +-
MAINTAINERS                                   |  13 +-
arch/powerpc/platforms/pseries/Kconfig        |   2 +-
arch/powerpc/platforms/pseries/cmm.c          |  53 +----
drivers/misc/Kconfig                          |   2 +-
drivers/misc/vmw_balloon.c                    | 105 +++------
drivers/virtio/Kconfig                        |   2 +-
drivers/virtio/virtio_balloon.c               |  64 ++----
include/linux/balloon.h                       |  77 +++++++
include/linux/balloon_compaction.h            | 160 --------------
include/linux/vm_event_item.h                 |   8 +-
mm/Kconfig                                    |  23 +-
mm/Makefile                                   |   2 +-
mm/{balloon_compaction.c => balloon.c}        | 200 ++++++++++++------
mm/memory_hotplug.c                           |   4 +-
mm/migrate.c                                  |   2 +-
mm/vmscan.c                                   |   1 -
mm/vmstat.c                                   |   8 +-
19 files changed, 319 insertions(+), 417 deletions(-)
create mode 100644 include/linux/balloon.h
delete mode 100644 include/linux/balloon_compaction.h
rename mm/{balloon_compaction.c => balloon.c} (58%)
[PATCH v3 00/24] mm: balloon infrastructure cleanups
Posted by David Hildenbrand (Red Hat) 2 weeks, 4 days ago
I started with wanting to remove the dependency of the balloon
infrastructure on the page lock, but ended up performing various other
cleanups, some of which I had on my todo list for years.

This series heavily cleans up and simplifies our balloon infrastructure,
including our balloon page migration functionality.

With this series, we no longer make use of the page lock for PageOffline
pages as part of the balloon infrastructure (preparing for memdescs
where PageOffline pages won't have any such lock), and simplifies
migration handling such that refcounting can more easily be adjusted
later (long-term focus is for PageOffline pages to not have a refcount
either).

Plenty of related cleanups.

Heavily compile-tested and heavily runtime-tested with virtio-balloon.
PPC CMM and the VMware balloon are untested and I'd appreciate a helping
hand from people that have suitable environments.

Not CCing maintainers for the vmscan.c and migrate.c change as they
are rather trivial and I don't want to patchbomb them.

--

v2 -> v3:
* "mm/balloon_compaction: centralize basic page migration handling"
  -> Remove newline
  -> Talk about "page" instead of "old page"
  -> avoid the switch statement
* "mm/balloon_compaction: move internal helpers to balloon_compaction.c"
  -> No need to carry over the "inline"
* "fixup mm: rename CONFIG_BALLOON_COMPACTION to CONFIG_BALLOON_MIGRATION
  -> Remove some more "balloon page compaction" thingies
*  "MAINTAINERS: move memory balloon infrastructure to "MEMORY MANAGEMENT -
    BALLOON"
   -> CC the virt list and use the proper mail address
* "mm/balloon_compaction: improve comments for WARN_ON_ONCE(!b_dev_info)
   -> Added

v1 -> v2:
* Rebased to latest mm/mm-unstable without any conflicts
* Minor patch description/subject and comment fixups
* Retested

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jerrin Shaji George <jerrin.shaji-george@broadcom.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: "Eugenio Pérez" <eperezma@redhat.com>
Cc: Zi Yan <ziy@nvidia.com>

David Hildenbrand (Red Hat) (24):
  vmw_balloon: adjust BALLOON_DEFLATE when deflating while migrating
  vmw_balloon: remove vmballoon_compaction_init()
  powerpc/pseries/cmm: remove cmm_balloon_compaction_init()
  mm/balloon_compaction: improve comments for WARN_ON_ONCE(!b_dev_info)
  mm/balloon_compaction: centralize basic page migration handling
  mm/balloon_compaction: centralize adjust_managed_page_count() handling
  vmw_balloon: stop using the balloon_dev_info lock
  mm/balloon_compaction: use a device-independent balloon (list) lock
  mm/balloon_compaction: remove dependency on page lock
  mm/balloon_compaction: make balloon_mops static
  mm/balloon_compaction: drop fs.h include from balloon_compaction.h
  drivers/virtio/virtio_balloon: stop using balloon_page_push/pop()
  mm/balloon_compaction: remove balloon_page_push/pop()
  mm/balloon_compaction: fold balloon_mapping_gfp_mask() into
    balloon_page_alloc()
  mm/balloon_compaction: move internal helpers to balloon_compaction.c
  mm/balloon_compaction: assert that the balloon_pages_lock is held
  mm/balloon_compaction: mark remaining functions for having proper
    kerneldoc
  mm/balloon_compaction: remove "extern" from functions
  mm/vmscan: drop inclusion of balloon_compaction.h
  mm: rename balloon_compaction.(c|h) to balloon.(c|h)
  mm/kconfig: make BALLOON_COMPACTION depend on MIGRATION
  mm: rename CONFIG_BALLOON_COMPACTION to CONFIG_BALLOON_MIGRATION
  mm: rename CONFIG_MEMORY_BALLOON -> CONFIG_BALLOON
  MAINTAINERS: move memory balloon infrastructure to "MEMORY MANAGEMENT
    - BALLOON"

 .../admin-guide/mm/memory-hotplug.rst         |   8 +-
 Documentation/core-api/mm-api.rst             |   2 +-
 MAINTAINERS                                   |  13 +-
 arch/powerpc/platforms/pseries/Kconfig        |   2 +-
 arch/powerpc/platforms/pseries/cmm.c          |  53 +----
 drivers/misc/Kconfig                          |   2 +-
 drivers/misc/vmw_balloon.c                    | 105 +++------
 drivers/virtio/Kconfig                        |   2 +-
 drivers/virtio/virtio_balloon.c               |  64 ++----
 include/linux/balloon.h                       |  77 +++++++
 include/linux/balloon_compaction.h            | 160 --------------
 include/linux/vm_event_item.h                 |   8 +-
 mm/Kconfig                                    |  23 +-
 mm/Makefile                                   |   2 +-
 mm/{balloon_compaction.c => balloon.c}        | 200 ++++++++++++------
 mm/memory_hotplug.c                           |   4 +-
 mm/migrate.c                                  |   2 +-
 mm/vmscan.c                                   |   1 -
 mm/vmstat.c                                   |   8 +-
 19 files changed, 319 insertions(+), 417 deletions(-)
 create mode 100644 include/linux/balloon.h
 delete mode 100644 include/linux/balloon_compaction.h
 rename mm/{balloon_compaction.c => balloon.c} (58%)


base-commit: f8ed52ac0cfbddff992bb9600941bfe51e1e385a
-- 
2.52.0

Re: [PATCH v3 00/24] mm: balloon infrastructure cleanups
Posted by Andrew Morton 2 weeks, 4 days ago
On Tue, 20 Jan 2026 00:01:08 +0100 "David Hildenbrand (Red Hat)" <david@kernel.org> wrote:

> I started with wanting to remove the dependency of the balloon
> infrastructure on the page lock, but ended up performing various other
> cleanups, some of which I had on my todo list for years.
> 
> This series heavily cleans up and simplifies our balloon infrastructure,
> including our balloon page migration functionality.

Updated, thanks.

fwiw, below is how v3 altered mm.git:

--- a/include/linux/balloon.h~b
+++ a/include/linux/balloon.h
@@ -22,9 +22,9 @@
  *
  * As the page isolation scanning step a compaction thread does is a lockless
  * procedure (from a page standpoint), it might bring some racy situations while
- * performing balloon page compaction. In order to sort out these racy scenarios
- * and safely perform balloon's page compaction and migration we must, always,
- * ensure following these simple rules:
+ * performing balloon page migration. In order to sort out these racy scenarios
+ * and safely perform balloon's page migration we must, always, ensure following
+ * these simple rules:
  *
  *   i. Inflation/deflation must set/clear page->private under the
  *      balloon_pages_lock
@@ -47,8 +47,8 @@
  * Balloon device information descriptor.
  * This struct is used to allow the common balloon page migration interface
  * procedures to find the proper balloon device holding memory pages they'll
- * have to cope for page compaction / migration, as well as it serves the
- * balloon driver as a page book-keeper for its registered balloon devices.
+ * have to cope for page migration, as well as it serves the balloon driver as
+ * a page book-keeper for its registered balloon devices.
  */
 struct balloon_dev_info {
 	unsigned long isolated_pages;	/* # of isolated pages for migration */
--- a/mm/balloon.c~b
+++ a/mm/balloon.c
@@ -16,7 +16,7 @@
  */
 static DEFINE_SPINLOCK(balloon_pages_lock);
 
-static inline struct balloon_dev_info *balloon_page_device(struct page *page)
+static struct balloon_dev_info *balloon_page_device(struct page *page)
 {
 	return (struct balloon_dev_info *)page_private(page);
 }
@@ -29,7 +29,7 @@ static inline struct balloon_dev_info *b
  *
  * Caller must ensure the balloon_pages_lock is held.
  */
-static inline void balloon_page_insert(struct balloon_dev_info *balloon,
+static void balloon_page_insert(struct balloon_dev_info *balloon,
 				       struct page *page)
 {
 	lockdep_assert_held(&balloon_pages_lock);
@@ -48,7 +48,7 @@ static inline void balloon_page_insert(s
  *
  * Caller must ensure the balloon_pages_lock is held.
  */
-static inline void balloon_page_finalize(struct page *page)
+static void balloon_page_finalize(struct page *page)
 {
 	lockdep_assert_held(&balloon_pages_lock);
 	if (IS_ENABLED(CONFIG_BALLOON_MIGRATION))
@@ -262,7 +262,11 @@ static void balloon_page_putback(struct
 	struct balloon_dev_info *b_dev_info = balloon_page_device(page);
 	unsigned long flags;
 
-	/* Isolated balloon pages cannot get deflated. */
+	/*
+	 * When we isolated the page, the page was still inflated in a balloon
+	 * device. As isolated balloon pages cannot get deflated, we still have
+	 * a balloon device here.
+	 */
 	if (WARN_ON_ONCE(!b_dev_info))
 		return;
 
@@ -279,18 +283,22 @@ static int balloon_page_migrate(struct p
 	unsigned long flags;
 	int rc;
 
-	/* Isolated balloon pages cannot get deflated. */
+	/*
+	 * When we isolated the page, the page was still inflated in a balloon
+	 * device. As isolated balloon pages cannot get deflated, we still have
+	 * a balloon device here.
+	 */
 	if (WARN_ON_ONCE(!b_dev_info))
 		return -EAGAIN;
 
 	rc = b_dev_info->migratepage(b_dev_info, newpage, page, mode);
-	switch (rc) {
-	case 0:
-		spin_lock_irqsave(&balloon_pages_lock, flags);
+	if (rc < 0 && rc != -ENOENT)
+		return rc;
 
+	spin_lock_irqsave(&balloon_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);
 
@@ -303,18 +311,12 @@ static int balloon_page_migrate(struct p
 			adjust_managed_page_count(page, 1);
 			adjust_managed_page_count(newpage, -1);
 		}
-		break;
-	case -ENOENT:
-		spin_lock_irqsave(&balloon_pages_lock, flags);
-
+	} else {
 		/* Old page was deflated but new page not inflated. */
 		__count_vm_event(BALLOON_DEFLATE);
 
 		if (b_dev_info->adjust_managed_page_count)
 			adjust_managed_page_count(page, 1);
-		break;
-	default:
-		return rc;
 	}
 
 	b_dev_info->isolated_pages--;
_