* [PATCH v1 00/23] mm: balloon infrastructure cleanups
@ 2025-10-21 12:59 David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 01/23] vmw_balloon: adjust BALLOON_DEFLATE when deflating while migrating David Hildenbrand
` (16 more replies)
0 siblings, 17 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
This is based on mm/mm-unstable with two PPC CMM fixes I sent out
separately earlier today [1] applied first.
[1] https://lkml.kernel.org/r/20251021100606.148294-1-david@redhat.com
---
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.
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 (23):
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: 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 memory_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 | 12 +-
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} | 194 +++++++++++++-----
mm/memory_hotplug.c | 4 +-
mm/migrate.c | 2 +-
mm/vmscan.c | 1 -
mm/vmstat.c | 8 +-
19 files changed, 314 insertions(+), 415 deletions(-)
create mode 100644 include/linux/balloon.h
delete mode 100644 include/linux/balloon_compaction.h
rename mm/{balloon_compaction.c => balloon.c} (59%)
--
2.51.0
^ permalink raw reply [flat|nested] 39+ messages in thread
* [PATCH v1 01/23] vmw_balloon: adjust BALLOON_DEFLATE when deflating while migrating
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-22 1:03 ` SeongJae Park
2025-10-21 12:59 ` [PATCH v1 02/23] vmw_balloon: remove vmballoon_compaction_init() David Hildenbrand
` (15 subsequent siblings)
16 siblings, 1 reply; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
When we're effectively deflating the balloon while migrating a page
because inflating the new page failed, we're not adjusting
BALLOON_DEFLATE.
Let's do that. This is a preparation for factoring out this handling to
the core code, making it work in a similar way first.
As this (deflating while migrating because of inflation error) is a
corner case that I don't really expect to happen in practice
and the stats are not that crucial, this likely doesn't classify as a fix.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
drivers/misc/vmw_balloon.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index cc1d18b3df5ca..2cc34c4968fac 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -1818,6 +1818,8 @@ static int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
if (status == VMW_BALLOON_SUCCESS) {
balloon_page_insert(&b->b_dev_info, newpage);
__count_vm_event(BALLOON_MIGRATE);
+ } else {
+ __count_vm_event(BALLOON_DEFLATE);
}
/*
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 02/23] vmw_balloon: remove vmballoon_compaction_init()
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 01/23] vmw_balloon: adjust BALLOON_DEFLATE when deflating while migrating David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 03/23] powerpc/pseries/cmm: remove cmm_balloon_compaction_init() David Hildenbrand
` (14 subsequent siblings)
16 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
Now that there is not a lot of logic left, let's just inline setting up
the migration function and drop all these excessive comments that are
not really required (or true) anymore.
To avoid #ifdef in the caller we can instead use IS_ENABLED() and make
the compiler happy by only providing the function declaration.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
drivers/misc/vmw_balloon.c | 30 +++++-------------------------
1 file changed, 5 insertions(+), 25 deletions(-)
diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 2cc34c4968fac..07e60a4b846aa 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -1833,27 +1833,10 @@ static int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
up_read(&b->conf_sem);
return ret;
}
-
-/**
- * vmballoon_compaction_init() - initialized compaction for the balloon.
- *
- * @b: pointer to the balloon.
- *
- * If during the initialization a failure occurred, this function does not
- * perform cleanup. The caller must call vmballoon_compaction_deinit() in this
- * case.
- *
- * Return: zero on success or error code on failure.
- */
-static __init void vmballoon_compaction_init(struct vmballoon *b)
-{
- b->b_dev_info.migratepage = vmballoon_migratepage;
-}
-
#else /* CONFIG_BALLOON_COMPACTION */
-static inline void vmballoon_compaction_init(struct vmballoon *b)
-{
-}
+int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
+ struct page *newpage, struct page *page,
+ enum migrate_mode mode);
#endif /* CONFIG_BALLOON_COMPACTION */
static int __init vmballoon_init(void)
@@ -1873,12 +1856,9 @@ static int __init vmballoon_init(void)
if (error)
return error;
- /*
- * Initialization of compaction must be done after the call to
- * balloon_devinfo_init() .
- */
balloon_devinfo_init(&balloon.b_dev_info);
- vmballoon_compaction_init(&balloon);
+ if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
+ balloon.b_dev_info.migratepage = vmballoon_migratepage;
INIT_LIST_HEAD(&balloon.huge_pages);
spin_lock_init(&balloon.comm_lock);
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 03/23] powerpc/pseries/cmm: remove cmm_balloon_compaction_init()
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 01/23] vmw_balloon: adjust BALLOON_DEFLATE when deflating while migrating David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 02/23] vmw_balloon: remove vmballoon_compaction_init() David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 20:43 ` Michael S. Tsirkin
2025-10-21 12:59 ` [PATCH v1 04/23] mm/balloon_compaction: centralize basic page migration handling David Hildenbrand
` (13 subsequent siblings)
16 siblings, 1 reply; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
Now that there is not a lot of logic left, let's just inline setting up
the migration function.
To avoid #ifdef in the caller we can instead use IS_ENABLED() and make
the compiler happy by only providing the function declaration.
Now that the function is gone, drop the "out_balloon_compaction" label.
Note that before commit 68f2736a8583 ("mm: Convert all PageMovable users
to movable_operations"), now not anymore.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
arch/powerpc/platforms/pseries/cmm.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c
index 310dab4bc8679..67c7309c36147 100644
--- a/arch/powerpc/platforms/pseries/cmm.c
+++ b/arch/powerpc/platforms/pseries/cmm.c
@@ -548,15 +548,9 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
return 0;
}
-
-static void cmm_balloon_compaction_init(void)
-{
- b_dev_info.migratepage = cmm_migratepage;
-}
#else /* CONFIG_BALLOON_COMPACTION */
-static void cmm_balloon_compaction_init(void)
-{
-}
+int cmm_migratepage(struct balloon_dev_info *b_dev_info, struct page *newpage,
+ struct page *page, enum migrate_mode mode);
#endif /* CONFIG_BALLOON_COMPACTION */
/**
@@ -573,11 +567,12 @@ static int cmm_init(void)
return -EOPNOTSUPP;
balloon_devinfo_init(&b_dev_info);
- cmm_balloon_compaction_init();
+ if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
+ b_dev_info.migratepage = cmm_migratepage;
rc = register_oom_notifier(&cmm_oom_nb);
if (rc < 0)
- goto out_balloon_compaction;
+ return rc;
if ((rc = register_reboot_notifier(&cmm_reboot_nb)))
goto out_oom_notifier;
@@ -606,7 +601,6 @@ static int cmm_init(void)
unregister_reboot_notifier(&cmm_reboot_nb);
out_oom_notifier:
unregister_oom_notifier(&cmm_oom_nb);
-out_balloon_compaction:
return rc;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 04/23] mm/balloon_compaction: centralize basic page migration handling
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (2 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 03/23] powerpc/pseries/cmm: remove cmm_balloon_compaction_init() David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 20:50 ` Michael S. Tsirkin
2025-10-21 12:59 ` [PATCH v1 05/23] mm/balloon_compaction: centralize adjust_managed_page_count() handling David Hildenbrand
` (12 subsequent siblings)
16 siblings, 1 reply; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
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 mach the other
functions. Also, drop the comment above balloon_page_migrate(), which
seems unnecessary.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
arch/powerpc/platforms/pseries/cmm.c | 16 ---------
drivers/misc/vmw_balloon.c | 49 +++++-----------------------
drivers/virtio/virtio_balloon.c | 12 -------
mm/balloon_compaction.c | 37 ++++++++++++++++++---
4 files changed, 41 insertions(+), 73 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c
index 67c7309c36147..07b21d2bc8a78 100644
--- a/arch/powerpc/platforms/pseries/cmm.c
+++ b/arch/powerpc/platforms/pseries/cmm.c
@@ -501,8 +501,6 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
struct page *newpage, struct page *page,
enum migrate_mode mode)
{
- unsigned long flags;
-
/*
* loan/"inflate" the newpage first.
*
@@ -517,9 +515,6 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
return -EBUSY;
}
- /* balloon page list reference */
- get_page(newpage);
-
/*
* When we migrate a page to a different zone, we have to fixup the
* count of both involved zones as we adjusted the managed page count
@@ -530,22 +525,11 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
adjust_managed_page_count(newpage, -1);
}
- spin_lock_irqsave(&b_dev_info->pages_lock, flags);
- balloon_page_insert(b_dev_info, newpage);
- __count_vm_event(BALLOON_MIGRATE);
- b_dev_info->isolated_pages--;
- spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
-
/*
* activate/"deflate" the old page. We ignore any errors just like the
* other callers.
*/
plpar_page_set_active(page);
-
- balloon_page_finalize(page);
- /* balloon page list reference */
- put_page(page);
-
return 0;
}
#else /* CONFIG_BALLOON_COMPACTION */
diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 07e60a4b846aa..52b8c0f1eead7 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -1724,18 +1724,17 @@ static inline void vmballoon_debugfs_exit(struct vmballoon *b)
* @page: a ballooned page that should be migrated.
* @mode: migration mode, ignored.
*
- * This function is really open-coded, but that is according to the interface
- * that balloon_compaction provides.
- *
* Return: zero on success, -EAGAIN when migration cannot be performed
- * momentarily, and -EBUSY if migration failed and should be retried
- * with that specific page.
+ * momentarily, -EBUSY if migration failed and should be retried
+ * with that specific page, and -ENOENT when deflating @page
+ * succeeded but inflating @newpage failed, effectively deflating
+ * the balloon.
*/
static int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
struct page *newpage, struct page *page,
enum migrate_mode mode)
{
- unsigned long status, flags;
+ unsigned long status;
struct vmballoon *b;
int ret = 0;
@@ -1773,14 +1772,6 @@ static int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
goto out_unlock;
}
- /*
- * The page is isolated, so it is safe to delete it without holding
- * @pages_lock . We keep holding @comm_lock since we will need it in a
- * second.
- */
- balloon_page_finalize(page);
- put_page(page);
-
/* Inflate */
vmballoon_add_page(b, 0, newpage);
status = vmballoon_lock_op(b, 1, VMW_BALLOON_4K_PAGE,
@@ -1799,36 +1790,12 @@ static int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
* change.
*/
atomic64_dec(&b->size);
- } else {
/*
- * Success. Take a reference for the page, and we will add it to
- * the list after acquiring the lock.
+ * Tell the core that we're deflating the old page and don't
+ * need the new page.
*/
- get_page(newpage);
- }
-
- /* Update the balloon list under the @pages_lock */
- spin_lock_irqsave(&b->b_dev_info.pages_lock, flags);
-
- /*
- * On inflation success, we already took a reference for the @newpage.
- * If we succeed just insert it to the list and update the statistics
- * under the lock.
- */
- if (status == VMW_BALLOON_SUCCESS) {
- balloon_page_insert(&b->b_dev_info, newpage);
- __count_vm_event(BALLOON_MIGRATE);
- } else {
- __count_vm_event(BALLOON_DEFLATE);
+ ret = -ENOENT;
}
-
- /*
- * We deflated successfully, so regardless to the inflation success, we
- * need to reduce the number of isolated_pages.
- */
- b->b_dev_info.isolated_pages--;
- spin_unlock_irqrestore(&b->b_dev_info.pages_lock, flags);
-
out_unlock:
up_read(&b->conf_sem);
return ret;
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 1b93d8c643612..8969271581bca 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -827,7 +827,6 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
{
struct virtio_balloon *vb = container_of(vb_dev_info,
struct virtio_balloon, vb_dev_info);
- unsigned long flags;
/*
* In order to avoid lock contention while migrating pages concurrently
@@ -840,8 +839,6 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
if (!mutex_trylock(&vb->balloon_lock))
return -EAGAIN;
- get_page(newpage); /* balloon reference */
-
/*
* When we migrate a page to a different zone and adjusted the
* managed page count when inflating, we have to fixup the count of
@@ -854,11 +851,6 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
}
/* balloon's page migration 1st step -- inflate "newpage" */
- spin_lock_irqsave(&vb_dev_info->pages_lock, flags);
- balloon_page_insert(vb_dev_info, newpage);
- vb_dev_info->isolated_pages--;
- __count_vm_event(BALLOON_MIGRATE);
- spin_unlock_irqrestore(&vb_dev_info->pages_lock, flags);
vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE;
set_page_pfns(vb, vb->pfns, newpage);
tell_host(vb, vb->inflate_vq);
@@ -869,10 +861,6 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
tell_host(vb, vb->deflate_vq);
mutex_unlock(&vb->balloon_lock);
-
- balloon_page_finalize(page);
- put_page(page); /* balloon reference */
-
return 0;
}
#endif /* CONFIG_BALLOON_COMPACTION */
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index 03c5dbabb1565..5444c61bb9e76 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -232,20 +232,49 @@ static void balloon_page_putback(struct page *page)
spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
}
-/* move_to_new_page() counterpart for a ballooned page */
static int balloon_page_migrate(struct page *newpage, struct page *page,
enum migrate_mode mode)
{
- struct balloon_dev_info *balloon = balloon_page_device(page);
+ struct balloon_dev_info *b_dev_info = balloon_page_device(page);
+ unsigned long flags;
+ int rc;
VM_BUG_ON_PAGE(!PageLocked(page), page);
VM_BUG_ON_PAGE(!PageLocked(newpage), newpage);
/* Isolated balloon pages cannot get deflated. */
- if (WARN_ON_ONCE(!balloon))
+ if (WARN_ON_ONCE(!b_dev_info))
return -EAGAIN;
- return balloon->migratepage(balloon, newpage, page, mode);
+ rc = b_dev_info->migratepage(b_dev_info, newpage, page, mode);
+ switch (rc) {
+ case 0:
+ spin_lock_irqsave(&b_dev_info->pages_lock, flags);
+
+ /* 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);
+
+ /* Free the now-deflated page we isolated in balloon_page_isolate(). */
+ balloon_page_finalize(page);
+ put_page(page);
+
+ return 0;
}
const struct movable_operations balloon_mops = {
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 05/23] mm/balloon_compaction: centralize adjust_managed_page_count() handling
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (3 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 04/23] mm/balloon_compaction: centralize basic page migration handling David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 06/23] vmw_balloon: stop using the balloon_dev_info lock David Hildenbrand
` (11 subsequent siblings)
16 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
Let's centralize it, by allowing for the driver to enable this handling
through a new flag (bool for now) in the balloon device info.
Note that we now adjust the counter when adding/removing a page into the
balloon list: when removing a page to deflate it, it will now happen
before the driver communicated with hypervisor, not afterwards.
This shouldn't make a difference in practice.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
arch/powerpc/platforms/pseries/cmm.c | 13 +------------
drivers/virtio/virtio_balloon.c | 19 ++-----------------
include/linux/balloon_compaction.h | 2 ++
mm/balloon_compaction.c | 17 +++++++++++++++++
4 files changed, 22 insertions(+), 29 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c
index 07b21d2bc8a78..9ed71683ae402 100644
--- a/arch/powerpc/platforms/pseries/cmm.c
+++ b/arch/powerpc/platforms/pseries/cmm.c
@@ -165,7 +165,6 @@ static long cmm_alloc_pages(long nr)
balloon_page_enqueue(&b_dev_info, page);
atomic_long_inc(&loaned_pages);
- adjust_managed_page_count(page, -1);
nr--;
}
@@ -190,7 +189,6 @@ static long cmm_free_pages(long nr)
if (!page)
break;
plpar_page_set_active(page);
- adjust_managed_page_count(page, 1);
__free_page(page);
atomic_long_dec(&loaned_pages);
nr--;
@@ -515,16 +513,6 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
return -EBUSY;
}
- /*
- * When we migrate a page to a different zone, we have to fixup the
- * count of both involved zones as we adjusted the managed page count
- * when inflating.
- */
- if (page_zone(page) != page_zone(newpage)) {
- adjust_managed_page_count(page, 1);
- adjust_managed_page_count(newpage, -1);
- }
-
/*
* activate/"deflate" the old page. We ignore any errors just like the
* other callers.
@@ -551,6 +539,7 @@ static int cmm_init(void)
return -EOPNOTSUPP;
balloon_devinfo_init(&b_dev_info);
+ b_dev_info.adjust_managed_page_count = true;
if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
b_dev_info.migratepage = cmm_migratepage;
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 8969271581bca..f7d6a4a6e54f5 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -274,9 +274,6 @@ static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
vb->num_pages += VIRTIO_BALLOON_PAGES_PER_PAGE;
- if (!virtio_has_feature(vb->vdev,
- VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
- adjust_managed_page_count(page, -1);
vb->num_pfns += VIRTIO_BALLOON_PAGES_PER_PAGE;
}
@@ -295,9 +292,6 @@ static void release_pages_balloon(struct virtio_balloon *vb,
struct page *page, *next;
list_for_each_entry_safe(page, next, pages, lru) {
- if (!virtio_has_feature(vb->vdev,
- VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
- adjust_managed_page_count(page, 1);
list_del(&page->lru);
put_page(page); /* balloon reference */
}
@@ -839,17 +833,6 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
if (!mutex_trylock(&vb->balloon_lock))
return -EAGAIN;
- /*
- * When we migrate a page to a different zone and adjusted the
- * managed page count when inflating, we have to fixup the count of
- * both involved zones.
- */
- if (!virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM) &&
- page_zone(page) != page_zone(newpage)) {
- adjust_managed_page_count(page, 1);
- adjust_managed_page_count(newpage, -1);
- }
-
/* balloon's page migration 1st step -- inflate "newpage" */
vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE;
set_page_pfns(vb, vb->pfns, newpage);
@@ -958,6 +941,8 @@ static int virtballoon_probe(struct virtio_device *vdev)
if (err)
goto out_free_vb;
+ if (!virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
+ vb->vb_dev_info.adjust_managed_page_count = true;
#ifdef CONFIG_BALLOON_COMPACTION
vb->vb_dev_info.migratepage = virtballoon_migratepage;
#endif
diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
index 7cfe48769239e..3109d3c43d306 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -56,6 +56,7 @@ struct balloon_dev_info {
struct list_head pages; /* Pages enqueued & handled to Host */
int (*migratepage)(struct balloon_dev_info *, struct page *newpage,
struct page *page, enum migrate_mode mode);
+ bool adjust_managed_page_count;
};
extern struct page *balloon_page_alloc(void);
@@ -73,6 +74,7 @@ static inline void balloon_devinfo_init(struct balloon_dev_info *balloon)
spin_lock_init(&balloon->pages_lock);
INIT_LIST_HEAD(&balloon->pages);
balloon->migratepage = NULL;
+ balloon->adjust_managed_page_count = false;
}
#ifdef CONFIG_BALLOON_COMPACTION
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index 5444c61bb9e76..fd9ec47cf4670 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -23,6 +23,8 @@ static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info,
BUG_ON(!trylock_page(page));
balloon_page_insert(b_dev_info, page);
unlock_page(page);
+ if (b_dev_info->adjust_managed_page_count)
+ adjust_managed_page_count(page, -1);
__count_vm_event(BALLOON_INFLATE);
inc_node_page_state(page, NR_BALLOON_PAGES);
}
@@ -95,6 +97,8 @@ size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
continue;
list_del(&page->lru);
+ if (b_dev_info->adjust_managed_page_count)
+ adjust_managed_page_count(page, 1);
balloon_page_finalize(page);
__count_vm_event(BALLOON_DEFLATE);
list_add(&page->lru, pages);
@@ -256,12 +260,25 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
balloon_page_insert(b_dev_info, newpage);
__count_vm_event(BALLOON_MIGRATE);
+
+ if (b_dev_info->adjust_managed_page_count &&
+ page_zone(page) != page_zone(newpage)) {
+ /*
+ * When we migrate a page to a different zone we
+ * have to fixup the count of both involved zones.
+ */
+ adjust_managed_page_count(page, 1);
+ adjust_managed_page_count(newpage, -1);
+ }
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);
+
+ if (b_dev_info->adjust_managed_page_count)
+ adjust_managed_page_count(page, 1);
break;
default:
return rc;
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 06/23] vmw_balloon: stop using the balloon_dev_info lock
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (4 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 05/23] mm/balloon_compaction: centralize adjust_managed_page_count() handling David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 20:57 ` Michael S. Tsirkin
2025-10-21 12:59 ` [PATCH v1 07/23] mm/balloon_compaction: use a device-independent balloon (list) lock David Hildenbrand
` (10 subsequent siblings)
16 siblings, 1 reply; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
Let's not piggy-back on the existing lock and use a separate lock for the
huge page list.
This is a preparation for changing the locking used to protect
balloon_dev_info.
While at it, talk about "page migration" instead of "page compaction".
We'll change that in core code soon as well.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
drivers/misc/vmw_balloon.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 52b8c0f1eead7..53e9335b6718c 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -354,10 +354,15 @@ struct vmballoon {
/**
* @huge_pages - list of the inflated 2MB pages.
*
- * Protected by @b_dev_info.pages_lock .
+ * Protected by @huge_pages_lock.
*/
struct list_head huge_pages;
+ /**
+ * @huge_pages_lock: lock for the list of inflated 2MB pages.
+ */
+ spinlock_t huge_pages_lock;
+
/**
* @vmci_doorbell.
*
@@ -987,7 +992,6 @@ static void vmballoon_enqueue_page_list(struct vmballoon *b,
unsigned int *n_pages,
enum vmballoon_page_size_type page_size)
{
- unsigned long flags;
struct page *page;
if (page_size == VMW_BALLOON_4K_PAGE) {
@@ -995,9 +999,9 @@ static void vmballoon_enqueue_page_list(struct vmballoon *b,
} else {
/*
* Keep the huge pages in a local list which is not available
- * for the balloon compaction mechanism.
+ * for the balloon page migration.
*/
- spin_lock_irqsave(&b->b_dev_info.pages_lock, flags);
+ spin_lock(&b->huge_pages_lock);
list_for_each_entry(page, pages, lru) {
vmballoon_mark_page_offline(page, VMW_BALLOON_2M_PAGE);
@@ -1006,7 +1010,7 @@ static void vmballoon_enqueue_page_list(struct vmballoon *b,
list_splice_init(pages, &b->huge_pages);
__count_vm_events(BALLOON_INFLATE, *n_pages *
vmballoon_page_in_frames(VMW_BALLOON_2M_PAGE));
- spin_unlock_irqrestore(&b->b_dev_info.pages_lock, flags);
+ spin_unlock(&b->huge_pages_lock);
}
*n_pages = 0;
@@ -1033,7 +1037,6 @@ static void vmballoon_dequeue_page_list(struct vmballoon *b,
{
struct page *page, *tmp;
unsigned int i = 0;
- unsigned long flags;
/* In the case of 4k pages, use the compaction infrastructure */
if (page_size == VMW_BALLOON_4K_PAGE) {
@@ -1043,7 +1046,7 @@ static void vmballoon_dequeue_page_list(struct vmballoon *b,
}
/* 2MB pages */
- spin_lock_irqsave(&b->b_dev_info.pages_lock, flags);
+ spin_lock(&b->huge_pages_lock);
list_for_each_entry_safe(page, tmp, &b->huge_pages, lru) {
vmballoon_mark_page_online(page, VMW_BALLOON_2M_PAGE);
@@ -1054,7 +1057,7 @@ static void vmballoon_dequeue_page_list(struct vmballoon *b,
__count_vm_events(BALLOON_DEFLATE,
i * vmballoon_page_in_frames(VMW_BALLOON_2M_PAGE));
- spin_unlock_irqrestore(&b->b_dev_info.pages_lock, flags);
+ spin_unlock(&b->huge_pages_lock);
*n_pages = i;
}
@@ -1828,6 +1831,7 @@ static int __init vmballoon_init(void)
balloon.b_dev_info.migratepage = vmballoon_migratepage;
INIT_LIST_HEAD(&balloon.huge_pages);
+ spin_lock_init(&balloon.huge_pages_lock);
spin_lock_init(&balloon.comm_lock);
init_rwsem(&balloon.conf_sem);
balloon.vmci_doorbell = VMCI_INVALID_HANDLE;
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 07/23] mm/balloon_compaction: use a device-independent balloon (list) lock
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (5 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 06/23] vmw_balloon: stop using the balloon_dev_info lock David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 20:52 ` Michael S. Tsirkin
2025-10-21 12:59 ` [PATCH v1 08/23] mm/balloon_compaction: remove dependency on page lock David Hildenbrand
` (9 subsequent siblings)
16 siblings, 1 reply; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
In order to remove the dependency on the page lock for balloon
pages, we need a lock that is independent of the page.
It's crucial that we can handle the scenario where balloon deflation
(clearing page->private) can race with page isolation (using
page->private to obtain the balloon_dev_info where the lock currently
resides).
The current lock in balloon_dev_info is therefore not suitable.
Fortunately, we never really have more than a single balloon device
per VM, so we can just keep it simple and use a static lock to protect
all balloon devices.
Based on this change we will remove the dependency on the page lock
next.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
include/linux/balloon_compaction.h | 6 ++---
mm/balloon_compaction.c | 36 +++++++++++++++++-------------
2 files changed, 23 insertions(+), 19 deletions(-)
diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
index 3109d3c43d306..e2d9eb40e1fbb 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -21,10 +21,10 @@
* i. Setting the PG_movable_ops flag and page->private with the following
* lock order
* +-page_lock(page);
- * +--spin_lock_irq(&b_dev_info->pages_lock);
+ * +--spin_lock_irq(&balloon_pages_lock);
*
* ii. isolation or dequeueing procedure must remove the page from balloon
- * device page list under b_dev_info->pages_lock.
+ * device page list under &balloon_pages_lock
*
* The functions provided by this interface are placed to help on coping with
* the aforementioned balloon page corner case, as well as to ensure the simple
@@ -52,7 +52,6 @@
*/
struct balloon_dev_info {
unsigned long isolated_pages; /* # of isolated pages for migration */
- spinlock_t pages_lock; /* Protection to pages list */
struct list_head pages; /* Pages enqueued & handled to Host */
int (*migratepage)(struct balloon_dev_info *, struct page *newpage,
struct page *page, enum migrate_mode mode);
@@ -71,7 +70,6 @@ extern size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
static inline void balloon_devinfo_init(struct balloon_dev_info *balloon)
{
balloon->isolated_pages = 0;
- spin_lock_init(&balloon->pages_lock);
INIT_LIST_HEAD(&balloon->pages);
balloon->migratepage = NULL;
balloon->adjust_managed_page_count = false;
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index fd9ec47cf4670..97e838795354d 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -11,6 +11,12 @@
#include <linux/export.h>
#include <linux/balloon_compaction.h>
+/*
+ * Lock protecting the balloon_dev_info of all devices. We don't really
+ * expect more than one device.
+ */
+static DEFINE_SPINLOCK(balloon_pages_lock);
+
static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info,
struct page *page)
{
@@ -47,13 +53,13 @@ size_t balloon_page_list_enqueue(struct balloon_dev_info *b_dev_info,
unsigned long flags;
size_t n_pages = 0;
- spin_lock_irqsave(&b_dev_info->pages_lock, flags);
+ spin_lock_irqsave(&balloon_pages_lock, flags);
list_for_each_entry_safe(page, tmp, pages, lru) {
list_del(&page->lru);
balloon_page_enqueue_one(b_dev_info, page);
n_pages++;
}
- spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
+ spin_unlock_irqrestore(&balloon_pages_lock, flags);
return n_pages;
}
EXPORT_SYMBOL_GPL(balloon_page_list_enqueue);
@@ -83,7 +89,7 @@ size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
unsigned long flags;
size_t n_pages = 0;
- spin_lock_irqsave(&b_dev_info->pages_lock, flags);
+ spin_lock_irqsave(&balloon_pages_lock, flags);
list_for_each_entry_safe(page, tmp, &b_dev_info->pages, lru) {
if (n_pages == n_req_pages)
break;
@@ -106,7 +112,7 @@ size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
dec_node_page_state(page, NR_BALLOON_PAGES);
n_pages++;
}
- spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
+ spin_unlock_irqrestore(&balloon_pages_lock, flags);
return n_pages;
}
@@ -149,9 +155,9 @@ void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
{
unsigned long flags;
- spin_lock_irqsave(&b_dev_info->pages_lock, flags);
+ spin_lock_irqsave(&balloon_pages_lock, flags);
balloon_page_enqueue_one(b_dev_info, page);
- spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
+ spin_unlock_irqrestore(&balloon_pages_lock, flags);
}
EXPORT_SYMBOL_GPL(balloon_page_enqueue);
@@ -191,11 +197,11 @@ struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info)
* BUG() here, otherwise the balloon driver may get stuck in
* an infinite loop while attempting to release all its pages.
*/
- spin_lock_irqsave(&b_dev_info->pages_lock, flags);
+ spin_lock_irqsave(&balloon_pages_lock, flags);
if (unlikely(list_empty(&b_dev_info->pages) &&
!b_dev_info->isolated_pages))
BUG();
- spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
+ spin_unlock_irqrestore(&balloon_pages_lock, flags);
return NULL;
}
return list_first_entry(&pages, struct page, lru);
@@ -213,10 +219,10 @@ static bool balloon_page_isolate(struct page *page, isolate_mode_t mode)
if (!b_dev_info)
return false;
- spin_lock_irqsave(&b_dev_info->pages_lock, flags);
+ spin_lock_irqsave(&balloon_pages_lock, flags);
list_del(&page->lru);
b_dev_info->isolated_pages++;
- spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
+ spin_unlock_irqrestore(&balloon_pages_lock, flags);
return true;
}
@@ -230,10 +236,10 @@ static void balloon_page_putback(struct page *page)
if (WARN_ON_ONCE(!b_dev_info))
return;
- spin_lock_irqsave(&b_dev_info->pages_lock, flags);
+ spin_lock_irqsave(&balloon_pages_lock, flags);
list_add(&page->lru, &b_dev_info->pages);
b_dev_info->isolated_pages--;
- spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
+ spin_unlock_irqrestore(&balloon_pages_lock, flags);
}
static int balloon_page_migrate(struct page *newpage, struct page *page,
@@ -253,7 +259,7 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
rc = b_dev_info->migratepage(b_dev_info, newpage, page, mode);
switch (rc) {
case 0:
- spin_lock_irqsave(&b_dev_info->pages_lock, flags);
+ spin_lock_irqsave(&balloon_pages_lock, flags);
/* Insert the new page into the balloon list. */
get_page(newpage);
@@ -272,7 +278,7 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
}
break;
case -ENOENT:
- spin_lock_irqsave(&b_dev_info->pages_lock, flags);
+ spin_lock_irqsave(&balloon_pages_lock, flags);
/* Old page was deflated but new page not inflated. */
__count_vm_event(BALLOON_DEFLATE);
@@ -285,7 +291,7 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
}
b_dev_info->isolated_pages--;
- spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
+ spin_unlock_irqrestore(&balloon_pages_lock, flags);
/* Free the now-deflated page we isolated in balloon_page_isolate(). */
balloon_page_finalize(page);
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 08/23] mm/balloon_compaction: remove dependency on page lock
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (6 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 07/23] mm/balloon_compaction: use a device-independent balloon (list) lock David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 09/23] mm/balloon_compaction: make balloon_mops static David Hildenbrand
` (8 subsequent siblings)
16 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
Let's stop using the page lock in balloon code and instead use only the
balloon_device_lock.
As soon as we set the PG_movable_ops flag, we might now get isolation
callbacks for that page as we are no longer holding the page lock. In
there, we'll simply synchronize using the balloon_device_lock.
So in balloon_page_isolate() lookup the balloon_dev_info through
page->private under balloon_device_lock.
It's crucial that we update page->private under the balloon_device_lock,
so the isolation callback can properly deal with concurrent deflation.
Consequently, make sure that balloon_page_finalize() is called under
balloon_device_lock as we remove a page from the list and clear
page->private. balloon_page_insert() is already called with the
balloon_device_lock held.
Note that the core will still lock the pages, for example in
isolate_movable_ops_page(). The lock is there still relevant for
handling the PageMovableOpsIsolated flag, but that can be later changed
to use an atomic test-and-set instead, or moved into the movable_ops
backends.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
include/linux/balloon_compaction.h | 27 +++++++++++----------
mm/balloon_compaction.c | 38 ++++++++++--------------------
2 files changed, 26 insertions(+), 39 deletions(-)
diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
index e2d9eb40e1fbb..ad594af6ed100 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -12,24 +12,26 @@
* is derived from the page type (PageOffline()) combined with the
* PG_movable_ops flag (PageMovableOps()).
*
+ * Once the page type and the PG_movable_ops are set, migration code
+ * can initiate page isolation by invoking the
+ * movable_operations()->isolate_page() callback
+ *
+ * As long as page->private is set, the page is either on the balloon list
+ * or isolated for migration. If page->private is not set, the page is
+ * either still getting inflated, or was deflated to be freed by the balloon
+ * driver soon. Isolation is impossible in both cases.
+ *
* 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:
*
- * i. Setting the PG_movable_ops flag and page->private with the following
- * lock order
- * +-page_lock(page);
- * +--spin_lock_irq(&balloon_pages_lock);
+ * i. Inflation/deflation must set/clear page->private under the
+ * balloon_pages_lock
*
* ii. isolation or dequeueing procedure must remove the page from balloon
- * device page list under &balloon_pages_lock
- *
- * The functions provided by this interface are placed to help on coping with
- * the aforementioned balloon page corner case, as well as to ensure the simple
- * set of exposed rules are satisfied while we are dealing with balloon pages
- * compaction / migration.
+ * device page list under balloon_pages_lock
*
* Copyright (C) 2012, Red Hat, Inc. Rafael Aquini <aquini@redhat.com>
*/
@@ -93,8 +95,7 @@ static inline struct balloon_dev_info *balloon_page_device(struct page *page)
* @balloon : pointer to balloon device
* @page : page to be assigned as a 'balloon page'
*
- * Caller must ensure the page is locked and the spin_lock protecting balloon
- * pages list is held before inserting a page into the balloon device.
+ * Caller must ensure the balloon_pages_lock is held.
*/
static inline void balloon_page_insert(struct balloon_dev_info *balloon,
struct page *page)
@@ -119,7 +120,7 @@ static inline gfp_t balloon_mapping_gfp_mask(void)
* balloon list for release to the page allocator
* @page: page to be released to the page allocator
*
- * Caller must ensure that the page is locked.
+ * Caller must ensure the balloon_pages_lock is held.
*/
static inline void balloon_page_finalize(struct page *page)
{
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index 97e838795354d..28ef0cb6b3bbc 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -20,15 +20,7 @@ static DEFINE_SPINLOCK(balloon_pages_lock);
static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info,
struct page *page)
{
- /*
- * Block others from accessing the 'page' when we get around to
- * establishing additional references. We should be the only one
- * holding a reference to the 'page' at this point. If we are not, then
- * memory corruption is possible and we should stop execution.
- */
- BUG_ON(!trylock_page(page));
balloon_page_insert(b_dev_info, page);
- unlock_page(page);
if (b_dev_info->adjust_managed_page_count)
adjust_managed_page_count(page, -1);
__count_vm_event(BALLOON_INFLATE);
@@ -93,22 +85,12 @@ size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
list_for_each_entry_safe(page, tmp, &b_dev_info->pages, lru) {
if (n_pages == n_req_pages)
break;
-
- /*
- * Block others from accessing the 'page' while we get around to
- * establishing additional references and preparing the 'page'
- * to be released by the balloon driver.
- */
- if (!trylock_page(page))
- continue;
-
list_del(&page->lru);
if (b_dev_info->adjust_managed_page_count)
adjust_managed_page_count(page, 1);
balloon_page_finalize(page);
__count_vm_event(BALLOON_DEFLATE);
list_add(&page->lru, pages);
- unlock_page(page);
dec_node_page_state(page, NR_BALLOON_PAGES);
n_pages++;
}
@@ -213,13 +195,19 @@ EXPORT_SYMBOL_GPL(balloon_page_dequeue);
static bool balloon_page_isolate(struct page *page, isolate_mode_t mode)
{
- struct balloon_dev_info *b_dev_info = balloon_page_device(page);
+ struct balloon_dev_info *b_dev_info;
unsigned long flags;
- if (!b_dev_info)
- return false;
-
spin_lock_irqsave(&balloon_pages_lock, flags);
+ b_dev_info = balloon_page_device(page);
+ if (!b_dev_info) {
+ /*
+ * The page already got deflated and removed from the
+ * balloon list.
+ */
+ spin_unlock_irqrestore(&balloon_pages_lock, flags);
+ return false;
+ }
list_del(&page->lru);
b_dev_info->isolated_pages++;
spin_unlock_irqrestore(&balloon_pages_lock, flags);
@@ -249,9 +237,6 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
unsigned long flags;
int rc;
- VM_BUG_ON_PAGE(!PageLocked(page), page);
- VM_BUG_ON_PAGE(!PageLocked(newpage), newpage);
-
/* Isolated balloon pages cannot get deflated. */
if (WARN_ON_ONCE(!b_dev_info))
return -EAGAIN;
@@ -291,10 +276,11 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
}
b_dev_info->isolated_pages--;
- spin_unlock_irqrestore(&balloon_pages_lock, flags);
/* Free the now-deflated page we isolated in balloon_page_isolate(). */
balloon_page_finalize(page);
+ spin_unlock_irqrestore(&balloon_pages_lock, flags);
+
put_page(page);
return 0;
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 09/23] mm/balloon_compaction: make balloon_mops static
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (7 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 08/23] mm/balloon_compaction: remove dependency on page lock David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 10/23] mm/balloon_compaction: drop fs.h include from balloon_compaction.h David Hildenbrand
` (7 subsequent siblings)
16 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
There is no need to expose this anymore, so let's just make it static.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
include/linux/balloon_compaction.h | 1 -
mm/balloon_compaction.c | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
index ad594af6ed100..7db66c2c86cdc 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -78,7 +78,6 @@ static inline void balloon_devinfo_init(struct balloon_dev_info *balloon)
}
#ifdef CONFIG_BALLOON_COMPACTION
-extern const struct movable_operations balloon_mops;
/*
* balloon_page_device - get the b_dev_info descriptor for the balloon device
* that enqueues the given page.
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index 28ef0cb6b3bbc..c44e0b62203cc 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -286,7 +286,7 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
return 0;
}
-const struct movable_operations balloon_mops = {
+static const struct movable_operations balloon_mops = {
.migrate_page = balloon_page_migrate,
.isolate_page = balloon_page_isolate,
.putback_page = balloon_page_putback,
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 10/23] mm/balloon_compaction: drop fs.h include from balloon_compaction.h
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (8 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 09/23] mm/balloon_compaction: make balloon_mops static David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 11/23] drivers/virtio/virtio_balloon: stop using balloon_page_push/pop() David Hildenbrand
` (6 subsequent siblings)
16 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
Ever since commit 68f2736a8583 ("mm: Convert all PageMovable users to
movable_operations") we no longer store an inode in balloon_dev_info,
so we can stop including "fs.h".
Signed-off-by: David Hildenbrand <david@redhat.com>
---
include/linux/balloon_compaction.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
index 7db66c2c86cdc..1452ea0635245 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -42,7 +42,6 @@
#include <linux/migrate.h>
#include <linux/gfp.h>
#include <linux/err.h>
-#include <linux/fs.h>
#include <linux/list.h>
/*
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 11/23] drivers/virtio/virtio_balloon: stop using balloon_page_push/pop()
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (9 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 10/23] mm/balloon_compaction: drop fs.h include from balloon_compaction.h David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 20:59 ` Michael S. Tsirkin
2025-10-21 12:59 ` [PATCH v1 12/23] mm/balloon_compaction: remove balloon_page_push/pop() David Hildenbrand
` (5 subsequent siblings)
16 siblings, 1 reply; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
Let's stop using these function so we can remove them. They look like
belonging to the balloon API for managing the device balloon list when
really they are just simple helpers only used by virtio-balloon.
Let's just inline them and switch to a proper
list_for_each_entry_safe().
Signed-off-by: David Hildenbrand <david@redhat.com>
---
drivers/virtio/virtio_balloon.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index f7d6a4a6e54f5..4b22de6a5f845 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -242,8 +242,8 @@ static void set_page_pfns(struct virtio_balloon *vb,
static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
{
unsigned int num_allocated_pages;
+ struct page *page, *next;
unsigned int num_pfns;
- struct page *page;
LIST_HEAD(pages);
/* We can only do one array worth at a time. */
@@ -262,14 +262,15 @@ static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
break;
}
- balloon_page_push(&pages, page);
+ list_add(&page->lru, &pages);
}
mutex_lock(&vb->balloon_lock);
vb->num_pfns = 0;
- while ((page = balloon_page_pop(&pages))) {
+ list_for_each_entry_safe(page, next, &pages, lru) {
+ list_del(&page->lru);
balloon_page_enqueue(&vb->vb_dev_info, page);
set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
@@ -474,15 +475,19 @@ static inline s64 towards_target(struct virtio_balloon *vb)
static unsigned long return_free_pages_to_mm(struct virtio_balloon *vb,
unsigned long num_to_return)
{
- struct page *page;
- unsigned long num_returned;
+ unsigned long num_returned = 0;
+ struct page *page, *next;
+
+ if (unlikely(!num_to_return))
+ return 0;
spin_lock_irq(&vb->free_page_list_lock);
- for (num_returned = 0; num_returned < num_to_return; num_returned++) {
- page = balloon_page_pop(&vb->free_page_list);
- if (!page)
- break;
+
+ list_for_each_entry_safe(page, next, &vb->free_page_list, lru) {
+ list_del(&page->lru);
__free_pages(page, VIRTIO_BALLOON_HINT_BLOCK_ORDER);
+ if (++num_returned == num_to_return)
+ break;
}
vb->num_free_page_blocks -= num_returned;
spin_unlock_irq(&vb->free_page_list_lock);
@@ -717,7 +722,7 @@ static int get_free_page_and_send(struct virtio_balloon *vb)
}
virtqueue_kick(vq);
spin_lock_irq(&vb->free_page_list_lock);
- balloon_page_push(&vb->free_page_list, page);
+ list_add(&page->lru, &vb->free_page_list);
vb->num_free_page_blocks++;
spin_unlock_irq(&vb->free_page_list_lock);
} else {
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 12/23] mm/balloon_compaction: remove balloon_page_push/pop()
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (10 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 11/23] drivers/virtio/virtio_balloon: stop using balloon_page_push/pop() David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 13/23] mm/balloon_compaction: fold balloon_mapping_gfp_mask() into balloon_page_alloc() David Hildenbrand
` (4 subsequent siblings)
16 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
Let's remove these helpers as they are unused now.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
include/linux/balloon_compaction.h | 30 ------------------------------
mm/balloon_compaction.c | 5 ++---
2 files changed, 2 insertions(+), 33 deletions(-)
diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
index 1452ea0635245..e5451cf1f6589 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -126,34 +126,4 @@ static inline void balloon_page_finalize(struct page *page)
set_page_private(page, 0);
/* PageOffline is sticky until the page is freed to the buddy. */
}
-
-/*
- * balloon_page_push - insert a page into a page list.
- * @head : pointer to list
- * @page : page to be added
- *
- * Caller must ensure the page is private and protect the list.
- */
-static inline void balloon_page_push(struct list_head *pages, struct page *page)
-{
- list_add(&page->lru, pages);
-}
-
-/*
- * balloon_page_pop - remove a page from a page list.
- * @head : pointer to list
- * @page : page to be added
- *
- * Caller must ensure the page is private and protect the list.
- */
-static inline struct page *balloon_page_pop(struct list_head *pages)
-{
- struct page *page = list_first_entry_or_null(pages, struct page, lru);
-
- if (!page)
- return NULL;
-
- list_del(&page->lru);
- return page;
-}
#endif /* _LINUX_BALLOON_COMPACTION_H */
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index c44e0b62203cc..90b2d61a593b7 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -128,9 +128,8 @@ EXPORT_SYMBOL_GPL(balloon_page_alloc);
* Drivers must call this function to properly enqueue a new allocated balloon
* page before definitively removing the page from the guest system.
*
- * Drivers must not call balloon_page_enqueue on pages that have been pushed to
- * a list with balloon_page_push before removing them with balloon_page_pop. To
- * enqueue a list of pages, use balloon_page_list_enqueue instead.
+ * Drivers must not enqueue pages while page->lru is still in
+ * use, and must not use page->lru until a page was unqueued again.
*/
void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
struct page *page)
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 13/23] mm/balloon_compaction: fold balloon_mapping_gfp_mask() into balloon_page_alloc()
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (11 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 12/23] mm/balloon_compaction: remove balloon_page_push/pop() David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 14/23] mm/balloon_compaction: move internal helpers to memory_compaction.c David Hildenbrand
` (3 subsequent siblings)
16 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
Let's just remove balloon_mapping_gfp_mask().
Signed-off-by: David Hildenbrand <david@redhat.com>
---
include/linux/balloon_compaction.h | 7 -------
mm/balloon_compaction.c | 12 ++++++++----
2 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
index e5451cf1f6589..d1d4739398978 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -106,13 +106,6 @@ static inline void balloon_page_insert(struct balloon_dev_info *balloon,
list_add(&page->lru, &balloon->pages);
}
-static inline gfp_t balloon_mapping_gfp_mask(void)
-{
- if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
- return GFP_HIGHUSER_MOVABLE;
- return GFP_HIGHUSER;
-}
-
/*
* balloon_page_finalize - prepare a balloon page that was removed from the
* balloon list for release to the page allocator
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index 90b2d61a593b7..709c57c00b481 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -112,10 +112,14 @@ EXPORT_SYMBOL_GPL(balloon_page_list_dequeue);
*/
struct page *balloon_page_alloc(void)
{
- struct page *page = alloc_page(balloon_mapping_gfp_mask() |
- __GFP_NOMEMALLOC | __GFP_NORETRY |
- __GFP_NOWARN);
- return page;
+ gfp_t gfp_flags = __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;
+
+ if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
+ gfp_flags |= GFP_HIGHUSER_MOVABLE;
+ else
+ gfp_flags |= GFP_HIGHUSER;
+
+ return alloc_page(gfp_flags);
}
EXPORT_SYMBOL_GPL(balloon_page_alloc);
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 14/23] mm/balloon_compaction: move internal helpers to memory_compaction.c
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (12 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 13/23] mm/balloon_compaction: fold balloon_mapping_gfp_mask() into balloon_page_alloc() David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 15:36 ` Zi Yan
2025-10-21 12:59 ` [PATCH v1 15/23] mm/balloon_compaction: assert that the balloon_pages_lock is held David Hildenbrand
` (2 subsequent siblings)
16 siblings, 1 reply; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
Let's move the helpers that are not required by drivers anymore.
While at it, drop the doc of balloon_page_device() as it is trivial.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
include/linux/balloon_compaction.h | 44 ------------------------------
mm/balloon_compaction.c | 38 ++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 44 deletions(-)
diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
index d1d4739398978..eec8994056a44 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -75,48 +75,4 @@ static inline void balloon_devinfo_init(struct balloon_dev_info *balloon)
balloon->migratepage = NULL;
balloon->adjust_managed_page_count = false;
}
-
-#ifdef CONFIG_BALLOON_COMPACTION
-/*
- * balloon_page_device - get the b_dev_info descriptor for the balloon device
- * that enqueues the given page.
- */
-static inline struct balloon_dev_info *balloon_page_device(struct page *page)
-{
- return (struct balloon_dev_info *)page_private(page);
-}
-#endif /* CONFIG_BALLOON_COMPACTION */
-
-/*
- * balloon_page_insert - insert a page into the balloon's page list and make
- * the page->private assignment accordingly.
- * @balloon : pointer to balloon device
- * @page : page to be assigned as a 'balloon page'
- *
- * Caller must ensure the balloon_pages_lock is held.
- */
-static inline void balloon_page_insert(struct balloon_dev_info *balloon,
- struct page *page)
-{
- __SetPageOffline(page);
- if (IS_ENABLED(CONFIG_BALLOON_COMPACTION)) {
- SetPageMovableOps(page);
- set_page_private(page, (unsigned long)balloon);
- }
- list_add(&page->lru, &balloon->pages);
-}
-
-/*
- * balloon_page_finalize - prepare a balloon page that was removed from the
- * balloon list for release to the page allocator
- * @page: page to be released to the page allocator
- *
- * Caller must ensure the balloon_pages_lock is held.
- */
-static inline void balloon_page_finalize(struct page *page)
-{
- if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
- set_page_private(page, 0);
- /* PageOffline is sticky until the page is freed to the buddy. */
-}
#endif /* _LINUX_BALLOON_COMPACTION_H */
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index 709c57c00b481..717bc43732d09 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -17,6 +17,44 @@
*/
static DEFINE_SPINLOCK(balloon_pages_lock);
+static inline struct balloon_dev_info *balloon_page_device(struct page *page)
+{
+ return (struct balloon_dev_info *)page_private(page);
+}
+
+/*
+ * balloon_page_insert - insert a page into the balloon's page list and make
+ * the page->private assignment accordingly.
+ * @balloon : pointer to balloon device
+ * @page : page to be assigned as a 'balloon page'
+ *
+ * Caller must ensure the balloon_pages_lock is held.
+ */
+static inline void balloon_page_insert(struct balloon_dev_info *balloon,
+ struct page *page)
+{
+ __SetPageOffline(page);
+ if (IS_ENABLED(CONFIG_BALLOON_COMPACTION)) {
+ SetPageMovableOps(page);
+ set_page_private(page, (unsigned long)balloon);
+ }
+ list_add(&page->lru, &balloon->pages);
+}
+
+/*
+ * balloon_page_finalize - prepare a balloon page that was removed from the
+ * balloon list for release to the page allocator
+ * @page: page to be released to the page allocator
+ *
+ * Caller must ensure the balloon_pages_lock is held.
+ */
+static inline void balloon_page_finalize(struct page *page)
+{
+ if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
+ set_page_private(page, 0);
+ /* PageOffline is sticky until the page is freed to the buddy. */
+}
+
static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info,
struct page *page)
{
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 15/23] mm/balloon_compaction: assert that the balloon_pages_lock is held
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (13 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 14/23] mm/balloon_compaction: move internal helpers to memory_compaction.c David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 16/23] mm/balloon_compaction: mark remaining functions for having proper kerneldoc David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 17/23] mm/balloon_compaction: remove "extern" from functions David Hildenbrand
16 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
Let's add some sanity checks for holding the balloon_pages_lock when
we're effectively inflating/deflating a page.
Signed-off-by: David Hildenbrand <david@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 717bc43732d09..f6e0582bd7ffe 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -33,6 +33,7 @@ static inline struct balloon_dev_info *balloon_page_device(struct page *page)
static inline void balloon_page_insert(struct balloon_dev_info *balloon,
struct page *page)
{
+ lockdep_assert_held(&balloon_pages_lock);
__SetPageOffline(page);
if (IS_ENABLED(CONFIG_BALLOON_COMPACTION)) {
SetPageMovableOps(page);
@@ -50,6 +51,7 @@ static inline void balloon_page_insert(struct balloon_dev_info *balloon,
*/
static inline void balloon_page_finalize(struct page *page)
{
+ lockdep_assert_held(&balloon_pages_lock);
if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
set_page_private(page, 0);
/* PageOffline is sticky until the page is freed to the buddy. */
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 16/23] mm/balloon_compaction: mark remaining functions for having proper kerneldoc
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (14 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 15/23] mm/balloon_compaction: assert that the balloon_pages_lock is held David Hildenbrand
@ 2025-10-21 12:59 ` David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 17/23] mm/balloon_compaction: remove "extern" from functions David Hildenbrand
16 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 12:59 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, David Hildenbrand, Andrew Morton,
Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka,
Mike Rapoport, Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S. Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
Looks like all we are missing for proper kerneldoc is another "*".
Signed-off-by: David Hildenbrand <david@redhat.com>
---
mm/balloon_compaction.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index f6e0582bd7ffe..f41e4a179a431 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -22,7 +22,7 @@ static inline struct balloon_dev_info *balloon_page_device(struct page *page)
return (struct balloon_dev_info *)page_private(page);
}
-/*
+/**
* balloon_page_insert - insert a page into the balloon's page list and make
* the page->private assignment accordingly.
* @balloon : pointer to balloon device
@@ -42,7 +42,7 @@ static inline void balloon_page_insert(struct balloon_dev_info *balloon,
list_add(&page->lru, &balloon->pages);
}
-/*
+/**
* balloon_page_finalize - prepare a balloon page that was removed from the
* balloon list for release to the page allocator
* @page: page to be released to the page allocator
@@ -140,7 +140,7 @@ size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
}
EXPORT_SYMBOL_GPL(balloon_page_list_dequeue);
-/*
+/**
* balloon_page_alloc - allocates a new page for insertion into the balloon
* page list.
*
@@ -163,7 +163,7 @@ struct page *balloon_page_alloc(void)
}
EXPORT_SYMBOL_GPL(balloon_page_alloc);
-/*
+/**
* balloon_page_enqueue - inserts a new page into the balloon page list.
*
* @b_dev_info: balloon device descriptor where we will insert a new page
@@ -186,7 +186,7 @@ void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
}
EXPORT_SYMBOL_GPL(balloon_page_enqueue);
-/*
+/**
* balloon_page_dequeue - removes a page from balloon's page list and returns
* its address to allow the driver to release the page.
* @b_dev_info: balloon device descriptor where we will grab a page from.
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 17/23] mm/balloon_compaction: remove "extern" from functions
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
` (15 preceding siblings ...)
2025-10-21 12:59 ` [PATCH v1 16/23] mm/balloon_compaction: mark remaining functions for having proper kerneldoc David Hildenbrand
@ 2025-10-21 15:00 ` David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 18/23] mm/vmscan: drop inclusion of balloon_compaction.h David Hildenbrand
` (5 more replies)
16 siblings, 6 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 15:00 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, Andrew Morton, Oscar Salvador,
Lorenzo Stoakes, Liam R . Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S . Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan, David Hildenbrand
Adding "extern" to functions is frowned-upon. Let's just get rid of it
for all functions here.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
include/linux/balloon_compaction.h | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
index eec8994056a44..7757e0e314fdb 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -59,14 +59,14 @@ struct balloon_dev_info {
bool adjust_managed_page_count;
};
-extern struct page *balloon_page_alloc(void);
-extern void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
- struct page *page);
-extern struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info);
-extern size_t balloon_page_list_enqueue(struct balloon_dev_info *b_dev_info,
- struct list_head *pages);
-extern size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
- struct list_head *pages, size_t n_req_pages);
+struct page *balloon_page_alloc(void);
+void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
+ struct page *page);
+struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info);
+size_t balloon_page_list_enqueue(struct balloon_dev_info *b_dev_info,
+ struct list_head *pages);
+size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
+ struct list_head *pages, size_t n_req_pages);
static inline void balloon_devinfo_init(struct balloon_dev_info *balloon)
{
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 18/23] mm/vmscan: drop inclusion of balloon_compaction.h
2025-10-21 15:00 ` [PATCH v1 17/23] mm/balloon_compaction: remove "extern" from functions David Hildenbrand
@ 2025-10-21 15:00 ` David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 19/23] mm: rename balloon_compaction.(c|h) to balloon.(c|h) David Hildenbrand
` (4 subsequent siblings)
5 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 15:00 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, Andrew Morton, Oscar Salvador,
Lorenzo Stoakes, Liam R . Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S . Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan, David Hildenbrand
Before commit b1123ea6d3b3 ("mm: balloon: use general non-lru movable page
feature"), the include was required because of isolated_balloon_page().
It's no longer required, so let's remove it.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
mm/vmscan.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index c922bad2b8fd4..b96448b562823 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -63,7 +63,6 @@
#include <asm/div64.h>
#include <linux/swapops.h>
-#include <linux/balloon_compaction.h>
#include <linux/sched/sysctl.h>
#include "internal.h"
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 19/23] mm: rename balloon_compaction.(c|h) to balloon.(c|h)
2025-10-21 15:00 ` [PATCH v1 17/23] mm/balloon_compaction: remove "extern" from functions David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 18/23] mm/vmscan: drop inclusion of balloon_compaction.h David Hildenbrand
@ 2025-10-21 15:00 ` David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 20/23] mm/kconfig: make BALLOON_COMPACTION depend on MIGRATION David Hildenbrand
` (3 subsequent siblings)
5 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 15:00 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, Andrew Morton, Oscar Salvador,
Lorenzo Stoakes, Liam R . Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S . Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan, David Hildenbrand
Even without CONFIG_BALLOON_COMPACTION this infrastructure implements
basic list and page management for a memory balloon.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
Documentation/core-api/mm-api.rst | 2 +-
MAINTAINERS | 4 ++--
arch/powerpc/platforms/pseries/cmm.c | 2 +-
drivers/misc/vmw_balloon.c | 2 +-
drivers/virtio/virtio_balloon.c | 2 +-
include/linux/{balloon_compaction.h => balloon.h} | 11 +++++------
mm/Makefile | 2 +-
mm/{balloon_compaction.c => balloon.c} | 7 +++----
8 files changed, 15 insertions(+), 17 deletions(-)
rename include/linux/{balloon_compaction.h => balloon.h} (92%)
rename mm/{balloon_compaction.c => balloon.c} (98%)
diff --git a/Documentation/core-api/mm-api.rst b/Documentation/core-api/mm-api.rst
index 68193a4cfcf52..aabdd3cba58e8 100644
--- a/Documentation/core-api/mm-api.rst
+++ b/Documentation/core-api/mm-api.rst
@@ -130,5 +130,5 @@ More Memory Management Functions
.. kernel-doc:: mm/vmscan.c
.. kernel-doc:: mm/memory_hotplug.c
.. kernel-doc:: mm/mmu_notifier.c
-.. kernel-doc:: mm/balloon_compaction.c
+.. kernel-doc:: mm/balloon.c
.. kernel-doc:: mm/huge_memory.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 46126ce2f968e..878e53d0f65ed 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -27062,9 +27062,9 @@ M: David Hildenbrand <david@redhat.com>
L: virtualization@lists.linux.dev
S: Maintained
F: drivers/virtio/virtio_balloon.c
-F: include/linux/balloon_compaction.h
+F: include/linux/balloon.h
F: include/uapi/linux/virtio_balloon.h
-F: mm/balloon_compaction.c
+F: mm/balloon.c
VIRTIO BLOCK AND SCSI DRIVERS
M: "Michael S. Tsirkin" <mst@redhat.com>
diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c
index 9ed71683ae402..c5aee15e192ea 100644
--- a/arch/powerpc/platforms/pseries/cmm.c
+++ b/arch/powerpc/platforms/pseries/cmm.c
@@ -19,7 +19,7 @@
#include <linux/stringify.h>
#include <linux/swap.h>
#include <linux/device.h>
-#include <linux/balloon_compaction.h>
+#include <linux/balloon.h>
#include <asm/firmware.h>
#include <asm/hvcall.h>
#include <asm/mmu.h>
diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 53e9335b6718c..7fd3f709108c2 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -29,7 +29,7 @@
#include <linux/rwsem.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
-#include <linux/balloon_compaction.h>
+#include <linux/balloon.h>
#include <linux/vmw_vmci_defs.h>
#include <linux/vmw_vmci_api.h>
#include <asm/hypervisor.h>
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 4b22de6a5f845..5434a7739d588 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -13,7 +13,7 @@
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/module.h>
-#include <linux/balloon_compaction.h>
+#include <linux/balloon.h>
#include <linux/oom.h>
#include <linux/wait.h>
#include <linux/mm.h>
diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon.h
similarity index 92%
rename from include/linux/balloon_compaction.h
rename to include/linux/balloon.h
index 7757e0e314fdb..82585542300d6 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon.h
@@ -1,8 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
- * include/linux/balloon_compaction.h
- *
- * Common interface definitions for making balloon pages movable by compaction.
+ * Common interface for implementing a memory balloon, including support
+ * for migration of pages inflated in a memory balloon.
*
* Balloon page migration makes use of the general "movable_ops page migration"
* feature.
@@ -35,8 +34,8 @@
*
* Copyright (C) 2012, Red Hat, Inc. Rafael Aquini <aquini@redhat.com>
*/
-#ifndef _LINUX_BALLOON_COMPACTION_H
-#define _LINUX_BALLOON_COMPACTION_H
+#ifndef _LINUX_BALLOON_H
+#define _LINUX_BALLOON_H
#include <linux/pagemap.h>
#include <linux/page-flags.h>
#include <linux/migrate.h>
@@ -75,4 +74,4 @@ static inline void balloon_devinfo_init(struct balloon_dev_info *balloon)
balloon->migratepage = NULL;
balloon->adjust_managed_page_count = false;
}
-#endif /* _LINUX_BALLOON_COMPACTION_H */
+#endif /* _LINUX_BALLOON_H */
diff --git a/mm/Makefile b/mm/Makefile
index 21abb33535501..ab012157b5109 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -121,7 +121,7 @@ obj-$(CONFIG_CMA) += cma.o
obj-$(CONFIG_NUMA) += numa.o
obj-$(CONFIG_NUMA_MEMBLKS) += numa_memblks.o
obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
-obj-$(CONFIG_MEMORY_BALLOON) += balloon_compaction.o
+obj-$(CONFIG_MEMORY_BALLOON) += balloon.o
obj-$(CONFIG_PAGE_EXTENSION) += page_ext.o
obj-$(CONFIG_PAGE_TABLE_CHECK) += page_table_check.o
obj-$(CONFIG_CMA_DEBUGFS) += cma_debug.o
diff --git a/mm/balloon_compaction.c b/mm/balloon.c
similarity index 98%
rename from mm/balloon_compaction.c
rename to mm/balloon.c
index f41e4a179a431..5734dae81e318 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon.c
@@ -1,15 +1,14 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
- * mm/balloon_compaction.c
- *
- * Common interface for making balloon pages movable by compaction.
+ * Common interface for implementing a memory balloon, including support
+ * for migration of pages inflated in a memory balloon.
*
* Copyright (C) 2012, Red Hat, Inc. Rafael Aquini <aquini@redhat.com>
*/
#include <linux/mm.h>
#include <linux/slab.h>
#include <linux/export.h>
-#include <linux/balloon_compaction.h>
+#include <linux/balloon.h>
/*
* Lock protecting the balloon_dev_info of all devices. We don't really
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 20/23] mm/kconfig: make BALLOON_COMPACTION depend on MIGRATION
2025-10-21 15:00 ` [PATCH v1 17/23] mm/balloon_compaction: remove "extern" from functions David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 18/23] mm/vmscan: drop inclusion of balloon_compaction.h David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 19/23] mm: rename balloon_compaction.(c|h) to balloon.(c|h) David Hildenbrand
@ 2025-10-21 15:00 ` David Hildenbrand
2025-10-21 17:13 ` Randy Dunlap
2025-10-21 15:00 ` [PATCH v1 21/23] mm: rename CONFIG_BALLOON_COMPACTION to CONFIG_BALLOON_MIGRATION David Hildenbrand
` (2 subsequent siblings)
5 siblings, 1 reply; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 15:00 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, Andrew Morton, Oscar Salvador,
Lorenzo Stoakes, Liam R . Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S . Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan, David Hildenbrand
Migration support for balloon memory depends on MIGRATION not
COMPACTION. Compaction is simply another user of page migration.
The last dependency on compaction.c was effectively removed with
commit 3d388584d599 ("mm: convert "movable" flag in page->mapping to a
page flag"). Ever since, everything for handling movable_ops page
migration resides in core migration code.
So let's change the dependency and adjust the description +
help text.
We'll rename BALLOON_COMPACTION separately next.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
mm/Kconfig | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/mm/Kconfig b/mm/Kconfig
index e47321051d765..3aff4d05a2d8c 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -599,17 +599,14 @@ config MEMORY_BALLOON
#
# support for memory balloon compaction
config BALLOON_COMPACTION
- bool "Allow for balloon memory compaction/migration"
+ bool "Allow for balloon memory migration"
default y
- depends on COMPACTION && MEMORY_BALLOON
- help
- Memory fragmentation introduced by ballooning might reduce
- significantly the number of 2MB contiguous memory blocks that can be
- used within a guest, thus imposing performance penalties associated
- with the reduced number of transparent huge pages that could be used
- by the guest workload. Allowing the compaction & migration for memory
- pages enlisted as being part of memory balloon devices avoids the
- scenario aforementioned and helps improving memory defragmentation.
+ depends on MIGRATION && MEMORY_BALLOON
+ help
+ Allow for migration of pages inflated in a memory balloon such that
+ they can be allocated from memory areas only available for movable
+ allocations (e.g., ZONE_MOVABLE, CMA) and such that they can get
+ migrated for memory defragmentation purposes by memory compaction.
#
# support for memory compaction
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 21/23] mm: rename CONFIG_BALLOON_COMPACTION to CONFIG_BALLOON_MIGRATION
2025-10-21 15:00 ` [PATCH v1 17/23] mm/balloon_compaction: remove "extern" from functions David Hildenbrand
` (2 preceding siblings ...)
2025-10-21 15:00 ` [PATCH v1 20/23] mm/kconfig: make BALLOON_COMPACTION depend on MIGRATION David Hildenbrand
@ 2025-10-21 15:00 ` David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 22/23] mm: rename CONFIG_MEMORY_BALLOON -> CONFIG_BALLOON David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 23/23] MAINTAINERS: move memory balloon infrastructure to "MEMORY MANAGEMENT - BALLOON" David Hildenbrand
5 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 15:00 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, Andrew Morton, Oscar Salvador,
Lorenzo Stoakes, Liam R . Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S . Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan, David Hildenbrand
While compaction depends on migration, the other direction is not the
case. So let's make it clearer that this is all about migration of
balloon pages.
Adjust all comments/docs in the core to talk about "migration" instead
of "compaction".
While at it add some "/* CONFIG_BALLOON_MIGRATION */".
Signed-off-by: David Hildenbrand <david@redhat.com>
---
Documentation/admin-guide/mm/memory-hotplug.rst | 8 ++++----
arch/powerpc/platforms/pseries/cmm.c | 8 ++++----
drivers/misc/vmw_balloon.c | 8 ++++----
drivers/virtio/virtio_balloon.c | 6 +++---
include/linux/balloon.h | 2 +-
include/linux/vm_event_item.h | 4 ++--
mm/Kconfig | 4 ++--
mm/balloon.c | 10 +++++-----
mm/memory_hotplug.c | 4 ++--
mm/migrate.c | 2 +-
mm/vmstat.c | 4 ++--
11 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/Documentation/admin-guide/mm/memory-hotplug.rst b/Documentation/admin-guide/mm/memory-hotplug.rst
index 33c886f3d1983..8d5f57d1ef48b 100644
--- a/Documentation/admin-guide/mm/memory-hotplug.rst
+++ b/Documentation/admin-guide/mm/memory-hotplug.rst
@@ -603,11 +603,11 @@ ZONE_MOVABLE, especially when fine-tuning zone ratios:
memory for metadata and page tables in the direct map; having a lot of offline
memory blocks is not a typical case, though.
-- Memory ballooning without balloon compaction is incompatible with
- ZONE_MOVABLE. Only some implementations, such as virtio-balloon and
- pseries CMM, fully support balloon compaction.
+- Memory ballooning without support for balloon memory migration is incompatible
+ with ZONE_MOVABLE. Only some implementations, such as virtio-balloon and
+ pseries CMM, fully support balloon memory migration.
- Further, the CONFIG_BALLOON_COMPACTION kernel configuration option might be
+ Further, the CONFIG_BALLOON_MIGRATION kernel configuration option might be
disabled. In that case, balloon inflation will only perform unmovable
allocations and silently create a zone imbalance, usually triggered by
inflation requests from the hypervisor.
diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c
index c5aee15e192ea..9278f6573e17b 100644
--- a/arch/powerpc/platforms/pseries/cmm.c
+++ b/arch/powerpc/platforms/pseries/cmm.c
@@ -494,7 +494,7 @@ static struct notifier_block cmm_mem_nb = {
.priority = CMM_MEM_HOTPLUG_PRI
};
-#ifdef CONFIG_BALLOON_COMPACTION
+#ifdef CONFIG_BALLOON_MIGRATION
static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
struct page *newpage, struct page *page,
enum migrate_mode mode)
@@ -520,10 +520,10 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
plpar_page_set_active(page);
return 0;
}
-#else /* CONFIG_BALLOON_COMPACTION */
+#else /* CONFIG_BALLOON_MIGRATION */
int cmm_migratepage(struct balloon_dev_info *b_dev_info, struct page *newpage,
struct page *page, enum migrate_mode mode);
-#endif /* CONFIG_BALLOON_COMPACTION */
+#endif /* CONFIG_BALLOON_MIGRATION */
/**
* cmm_init - Module initialization
@@ -540,7 +540,7 @@ static int cmm_init(void)
balloon_devinfo_init(&b_dev_info);
b_dev_info.adjust_managed_page_count = true;
- if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
+ if (IS_ENABLED(CONFIG_BALLOON_MIGRATION))
b_dev_info.migratepage = cmm_migratepage;
rc = register_oom_notifier(&cmm_oom_nb);
diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 7fd3f709108c2..216a163959684 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -1719,7 +1719,7 @@ static inline void vmballoon_debugfs_exit(struct vmballoon *b)
#endif /* CONFIG_DEBUG_FS */
-#ifdef CONFIG_BALLOON_COMPACTION
+#ifdef CONFIG_BALLOON_MIGRATION
/**
* vmballoon_migratepage() - migrates a balloon page.
* @b_dev_info: balloon device information descriptor.
@@ -1803,11 +1803,11 @@ static int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
up_read(&b->conf_sem);
return ret;
}
-#else /* CONFIG_BALLOON_COMPACTION */
+#else /* CONFIG_BALLOON_MIGRATION */
int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
struct page *newpage, struct page *page,
enum migrate_mode mode);
-#endif /* CONFIG_BALLOON_COMPACTION */
+#endif /* CONFIG_BALLOON_MIGRATION */
static int __init vmballoon_init(void)
{
@@ -1827,7 +1827,7 @@ static int __init vmballoon_init(void)
return error;
balloon_devinfo_init(&balloon.b_dev_info);
- if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
+ if (IS_ENABLED(CONFIG_BALLOON_MIGRATION))
balloon.b_dev_info.migratepage = vmballoon_migratepage;
INIT_LIST_HEAD(&balloon.huge_pages);
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 5434a7739d588..1a3001f35d3e6 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -802,7 +802,7 @@ static void report_free_page_func(struct work_struct *work)
}
}
-#ifdef CONFIG_BALLOON_COMPACTION
+#ifdef CONFIG_BALLOON_MIGRATION
/*
* virtballoon_migratepage - perform the balloon page migration on behalf of
* a compaction thread. (called under page lock)
@@ -851,7 +851,7 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
mutex_unlock(&vb->balloon_lock);
return 0;
}
-#endif /* CONFIG_BALLOON_COMPACTION */
+#endif /* CONFIG_BALLOON_MIGRATION */
static unsigned long shrink_free_pages(struct virtio_balloon *vb,
unsigned long pages_to_free)
@@ -948,7 +948,7 @@ static int virtballoon_probe(struct virtio_device *vdev)
if (!virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
vb->vb_dev_info.adjust_managed_page_count = true;
-#ifdef CONFIG_BALLOON_COMPACTION
+#ifdef CONFIG_BALLOON_MIGRATION
vb->vb_dev_info.migratepage = virtballoon_migratepage;
#endif
if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
diff --git a/include/linux/balloon.h b/include/linux/balloon.h
index 82585542300d6..e8da95ca4ad48 100644
--- a/include/linux/balloon.h
+++ b/include/linux/balloon.h
@@ -45,7 +45,7 @@
/*
* Balloon device information descriptor.
- * This struct is used to allow the common balloon compaction interface
+ * 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.
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index 92f80b4d69a6d..fca34d3473b6b 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -125,9 +125,9 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
#ifdef CONFIG_MEMORY_BALLOON
BALLOON_INFLATE,
BALLOON_DEFLATE,
-#ifdef CONFIG_BALLOON_COMPACTION
+#ifdef CONFIG_BALLOON_MIGRATION
BALLOON_MIGRATE,
-#endif
+#endif /* CONFIG_BALLOON_MIGRATION */
#endif
#ifdef CONFIG_DEBUG_TLBFLUSH
NR_TLB_REMOTE_FLUSH, /* cpu tried to flush others' tlbs */
diff --git a/mm/Kconfig b/mm/Kconfig
index 3aff4d05a2d8c..c058a65080d1e 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -597,8 +597,8 @@ config MEMORY_BALLOON
bool
#
-# support for memory balloon compaction
-config BALLOON_COMPACTION
+# support for memory balloon page migration
+config BALLOON_MIGRATION
bool "Allow for balloon memory migration"
default y
depends on MIGRATION && MEMORY_BALLOON
diff --git a/mm/balloon.c b/mm/balloon.c
index 5734dae81e318..8a21c6b9a7f0a 100644
--- a/mm/balloon.c
+++ b/mm/balloon.c
@@ -34,7 +34,7 @@ static inline void balloon_page_insert(struct balloon_dev_info *balloon,
{
lockdep_assert_held(&balloon_pages_lock);
__SetPageOffline(page);
- if (IS_ENABLED(CONFIG_BALLOON_COMPACTION)) {
+ if (IS_ENABLED(CONFIG_BALLOON_MIGRATION)) {
SetPageMovableOps(page);
set_page_private(page, (unsigned long)balloon);
}
@@ -51,7 +51,7 @@ static inline void balloon_page_insert(struct balloon_dev_info *balloon,
static inline void balloon_page_finalize(struct page *page)
{
lockdep_assert_held(&balloon_pages_lock);
- if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
+ if (IS_ENABLED(CONFIG_BALLOON_MIGRATION))
set_page_private(page, 0);
/* PageOffline is sticky until the page is freed to the buddy. */
}
@@ -153,7 +153,7 @@ struct page *balloon_page_alloc(void)
{
gfp_t gfp_flags = __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN;
- if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
+ if (IS_ENABLED(CONFIG_BALLOON_MIGRATION))
gfp_flags |= GFP_HIGHUSER_MOVABLE;
else
gfp_flags |= GFP_HIGHUSER;
@@ -232,7 +232,7 @@ struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info)
}
EXPORT_SYMBOL_GPL(balloon_page_dequeue);
-#ifdef CONFIG_BALLOON_COMPACTION
+#ifdef CONFIG_BALLOON_MIGRATION
static bool balloon_page_isolate(struct page *page, isolate_mode_t mode)
@@ -340,4 +340,4 @@ static int __init balloon_init(void)
}
core_initcall(balloon_init);
-#endif /* CONFIG_BALLOON_COMPACTION */
+#endif /* CONFIG_BALLOON_MIGRATION */
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 94a8f6e8811ab..44bfac61139b7 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -946,8 +946,8 @@ static struct zone *default_kernel_zone_for_pfn(int nid, unsigned long start_pfn
* We rely on "present pages" instead of "managed pages", as the latter is
* highly unreliable and dynamic in virtualized environments, and does not
* consider boot time allocations. For example, memory ballooning adjusts the
- * managed pages when inflating/deflating the balloon, and balloon compaction
- * can even migrate inflated pages between zones.
+ * managed pages when inflating/deflating the balloon, and balloon page
+ * migration can even migrate inflated pages between zones.
*
* Using "present pages" is better but some things to keep in mind are:
*
diff --git a/mm/migrate.c b/mm/migrate.c
index ceee354ef2152..cf5e9b13ff28d 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -88,7 +88,7 @@ static const struct movable_operations *page_movable_ops(struct page *page)
* back to the buddy.
*/
if (PageOffline(page))
- /* Only balloon compaction sets PageOffline pages movable. */
+ /* Only balloon page migration sets PageOffline pages movable. */
return offline_movable_ops;
if (PageZsmalloc(page))
return zsmalloc_movable_ops;
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 98855f31294dd..8843a8c4914c4 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1434,9 +1434,9 @@ const char * const vmstat_text[] = {
#ifdef CONFIG_MEMORY_BALLOON
[I(BALLOON_INFLATE)] = "balloon_inflate",
[I(BALLOON_DEFLATE)] = "balloon_deflate",
-#ifdef CONFIG_BALLOON_COMPACTION
+#ifdef CONFIG_BALLOON_MIGRATION
[I(BALLOON_MIGRATE)] = "balloon_migrate",
-#endif
+#endif /* CONFIG_BALLOON_MIGRATION */
#endif /* CONFIG_MEMORY_BALLOON */
#ifdef CONFIG_DEBUG_TLBFLUSH
[I(NR_TLB_REMOTE_FLUSH)] = "nr_tlb_remote_flush",
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 22/23] mm: rename CONFIG_MEMORY_BALLOON -> CONFIG_BALLOON
2025-10-21 15:00 ` [PATCH v1 17/23] mm/balloon_compaction: remove "extern" from functions David Hildenbrand
` (3 preceding siblings ...)
2025-10-21 15:00 ` [PATCH v1 21/23] mm: rename CONFIG_BALLOON_COMPACTION to CONFIG_BALLOON_MIGRATION David Hildenbrand
@ 2025-10-21 15:00 ` David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 23/23] MAINTAINERS: move memory balloon infrastructure to "MEMORY MANAGEMENT - BALLOON" David Hildenbrand
5 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 15:00 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, Andrew Morton, Oscar Salvador,
Lorenzo Stoakes, Liam R . Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S . Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan, David Hildenbrand
Let's make it consistent with the naming of the files but also with the
naming of CONFIG_BALLOON_MIGRATION.
While at it, add a "/* CONFIG_BALLOON */".
Signed-off-by: David Hildenbrand <david@redhat.com>
---
arch/powerpc/platforms/pseries/Kconfig | 2 +-
drivers/misc/Kconfig | 2 +-
drivers/virtio/Kconfig | 2 +-
include/linux/vm_event_item.h | 4 ++--
mm/Kconfig | 4 ++--
mm/Makefile | 2 +-
mm/vmstat.c | 4 ++--
7 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig
index 3e042218d6cd8..f7052b131a4c5 100644
--- a/arch/powerpc/platforms/pseries/Kconfig
+++ b/arch/powerpc/platforms/pseries/Kconfig
@@ -120,7 +120,7 @@ config PPC_SMLPAR
config CMM
tristate "Collaborative memory management"
depends on PPC_SMLPAR
- select MEMORY_BALLOON
+ select BALLOON
default y
help
Select this option, if you want to enable the kernel interface
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index b9c11f67315f0..47da8dfcffc2b 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -411,7 +411,7 @@ config DS1682
config VMWARE_BALLOON
tristate "VMware Balloon Driver"
depends on VMWARE_VMCI && X86 && HYPERVISOR_GUEST
- select MEMORY_BALLOON
+ select BALLOON
help
This is VMware physical memory management driver which acts
like a "balloon" that can be inflated to reclaim physical pages
diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index 6db5235a7693d..ce5bc0d9ea287 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -112,7 +112,7 @@ config VIRTIO_PMEM
config VIRTIO_BALLOON
tristate "Virtio balloon driver"
depends on VIRTIO
- select MEMORY_BALLOON
+ select BALLOON
select PAGE_REPORTING
help
This driver supports increasing and decreasing the amount
diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h
index fca34d3473b6b..22a139f82d75f 100644
--- a/include/linux/vm_event_item.h
+++ b/include/linux/vm_event_item.h
@@ -122,13 +122,13 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
THP_SWPOUT,
THP_SWPOUT_FALLBACK,
#endif
-#ifdef CONFIG_MEMORY_BALLOON
+#ifdef CONFIG_BALLOON
BALLOON_INFLATE,
BALLOON_DEFLATE,
#ifdef CONFIG_BALLOON_MIGRATION
BALLOON_MIGRATE,
#endif /* CONFIG_BALLOON_MIGRATION */
-#endif
+#endif /* CONFIG_BALLOON */
#ifdef CONFIG_DEBUG_TLBFLUSH
NR_TLB_REMOTE_FLUSH, /* cpu tried to flush others' tlbs */
NR_TLB_REMOTE_FLUSH_RECEIVED,/* cpu received ipi for flush */
diff --git a/mm/Kconfig b/mm/Kconfig
index c058a65080d1e..73e352bb82653 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -593,7 +593,7 @@ config SPLIT_PMD_PTLOCKS
#
# support for memory balloon
-config MEMORY_BALLOON
+config BALLOON
bool
#
@@ -601,7 +601,7 @@ config MEMORY_BALLOON
config BALLOON_MIGRATION
bool "Allow for balloon memory migration"
default y
- depends on MIGRATION && MEMORY_BALLOON
+ depends on MIGRATION && BALLOON
help
Allow for migration of pages inflated in a memory balloon such that
they can be allocated from memory areas only available for movable
diff --git a/mm/Makefile b/mm/Makefile
index ab012157b5109..315aec23d78f5 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -121,7 +121,7 @@ obj-$(CONFIG_CMA) += cma.o
obj-$(CONFIG_NUMA) += numa.o
obj-$(CONFIG_NUMA_MEMBLKS) += numa_memblks.o
obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
-obj-$(CONFIG_MEMORY_BALLOON) += balloon.o
+obj-$(CONFIG_BALLOON) += balloon.o
obj-$(CONFIG_PAGE_EXTENSION) += page_ext.o
obj-$(CONFIG_PAGE_TABLE_CHECK) += page_table_check.o
obj-$(CONFIG_CMA_DEBUGFS) += cma_debug.o
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 8843a8c4914c4..542378df0bf75 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -1431,13 +1431,13 @@ const char * const vmstat_text[] = {
[I(THP_SWPOUT)] = "thp_swpout",
[I(THP_SWPOUT_FALLBACK)] = "thp_swpout_fallback",
#endif
-#ifdef CONFIG_MEMORY_BALLOON
+#ifdef CONFIG_BALLOON
[I(BALLOON_INFLATE)] = "balloon_inflate",
[I(BALLOON_DEFLATE)] = "balloon_deflate",
#ifdef CONFIG_BALLOON_MIGRATION
[I(BALLOON_MIGRATE)] = "balloon_migrate",
#endif /* CONFIG_BALLOON_MIGRATION */
-#endif /* CONFIG_MEMORY_BALLOON */
+#endif /* CONFIG_BALLOON */
#ifdef CONFIG_DEBUG_TLBFLUSH
[I(NR_TLB_REMOTE_FLUSH)] = "nr_tlb_remote_flush",
[I(NR_TLB_REMOTE_FLUSH_RECEIVED)] = "nr_tlb_remote_flush_received",
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* [PATCH v1 23/23] MAINTAINERS: move memory balloon infrastructure to "MEMORY MANAGEMENT - BALLOON"
2025-10-21 15:00 ` [PATCH v1 17/23] mm/balloon_compaction: remove "extern" from functions David Hildenbrand
` (4 preceding siblings ...)
2025-10-21 15:00 ` [PATCH v1 22/23] mm: rename CONFIG_MEMORY_BALLOON -> CONFIG_BALLOON David Hildenbrand
@ 2025-10-21 15:00 ` David Hildenbrand
5 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 15:00 UTC (permalink / raw)
To: linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, Andrew Morton, Oscar Salvador,
Lorenzo Stoakes, Liam R . Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S . Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan, David Hildenbrand
Nowadays, there is nothing virtio-balloon special anymore about these
files, the basic infrastructure is used by multiple memory balloon
drivers.
For now we'll route it through Andrew's tree, maybe in some future it
makes sense to route this through a separate tree.
Signed-off-by: David Hildenbrand <david@redhat.com>
---
MAINTAINERS | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 878e53d0f65ed..17fbf5c1ea2fb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -16225,6 +16225,16 @@ T: quilt git://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new
F: mm/
F: tools/mm/
+MEMORY MANAGEMENT - BALLOON
+M: Andrew Morton <akpm@linux-foundation.org>
+M: David Hildenbrand <david@redhat.com>
+L: linux-mm@kvack.org
+S: Maintained
+W: http://www.linux-mm.org
+T: git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
+F: include/linux/balloon.h
+F: mm/balloon.c
+
MEMORY MANAGEMENT - CORE
M: Andrew Morton <akpm@linux-foundation.org>
M: David Hildenbrand <david@redhat.com>
@@ -27062,9 +27072,7 @@ M: David Hildenbrand <david@redhat.com>
L: virtualization@lists.linux.dev
S: Maintained
F: drivers/virtio/virtio_balloon.c
-F: include/linux/balloon.h
F: include/uapi/linux/virtio_balloon.h
-F: mm/balloon.c
VIRTIO BLOCK AND SCSI DRIVERS
M: "Michael S. Tsirkin" <mst@redhat.com>
--
2.51.0
^ permalink raw reply related [flat|nested] 39+ messages in thread
* Re: [PATCH v1 14/23] mm/balloon_compaction: move internal helpers to memory_compaction.c
2025-10-21 12:59 ` [PATCH v1 14/23] mm/balloon_compaction: move internal helpers to memory_compaction.c David Hildenbrand
@ 2025-10-21 15:36 ` Zi Yan
2025-10-21 15:37 ` David Hildenbrand
0 siblings, 1 reply; 39+ messages in thread
From: Zi Yan @ 2025-10-21 15:36 UTC (permalink / raw)
To: David Hildenbrand
Cc: linux-kernel, linux-mm, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Michael S. Tsirkin,
Jason Wang, Xuan Zhuo, Eugenio Pérez
On 21 Oct 2025, at 8:59, David Hildenbrand wrote:
> Let's move the helpers that are not required by drivers anymore.
>
> While at it, drop the doc of balloon_page_device() as it is trivial.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> include/linux/balloon_compaction.h | 44 ------------------------------
> mm/balloon_compaction.c | 38 ++++++++++++++++++++++++++
> 2 files changed, 38 insertions(+), 44 deletions(-)
>
In the email subject, s/memory_compaction/balloon_compaction/
--
Best Regards,
Yan, Zi
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 14/23] mm/balloon_compaction: move internal helpers to memory_compaction.c
2025-10-21 15:36 ` Zi Yan
@ 2025-10-21 15:37 ` David Hildenbrand
0 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 15:37 UTC (permalink / raw)
To: Zi Yan
Cc: linux-kernel, linux-mm, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Michael S. Tsirkin,
Jason Wang, Xuan Zhuo, Eugenio Pérez
On 21.10.25 17:36, Zi Yan wrote:
> On 21 Oct 2025, at 8:59, David Hildenbrand wrote:
>
>> Let's move the helpers that are not required by drivers anymore.
>>
>> While at it, drop the doc of balloon_page_device() as it is trivial.
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>> include/linux/balloon_compaction.h | 44 ------------------------------
>> mm/balloon_compaction.c | 38 ++++++++++++++++++++++++++
>> 2 files changed, 38 insertions(+), 44 deletions(-)
>>
>
> In the email subject, s/memory_compaction/balloon_compaction/
Indeed, thanks!
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 20/23] mm/kconfig: make BALLOON_COMPACTION depend on MIGRATION
2025-10-21 15:00 ` [PATCH v1 20/23] mm/kconfig: make BALLOON_COMPACTION depend on MIGRATION David Hildenbrand
@ 2025-10-21 17:13 ` Randy Dunlap
2025-10-21 18:43 ` David Hildenbrand
0 siblings, 1 reply; 39+ messages in thread
From: Randy Dunlap @ 2025-10-21 17:13 UTC (permalink / raw)
To: David Hildenbrand, linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, Andrew Morton, Oscar Salvador,
Lorenzo Stoakes, Liam R . Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S . Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
On 10/21/25 8:00 AM, David Hildenbrand wrote:
> Migration support for balloon memory depends on MIGRATION not
> COMPACTION. Compaction is simply another user of page migration.
>
> The last dependency on compaction.c was effectively removed with
> commit 3d388584d599 ("mm: convert "movable" flag in page->mapping to a
> page flag"). Ever since, everything for handling movable_ops page
> migration resides in core migration code.
>
> So let's change the dependency and adjust the description +
> help text.
>
> We'll rename BALLOON_COMPACTION separately next.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> mm/Kconfig | 17 +++++++----------
> 1 file changed, 7 insertions(+), 10 deletions(-)
>
> diff --git a/mm/Kconfig b/mm/Kconfig
> index e47321051d765..3aff4d05a2d8c 100644
> --- a/mm/Kconfig
> +++ b/mm/Kconfig
> @@ -599,17 +599,14 @@ config MEMORY_BALLOON
> #
> # support for memory balloon compaction
> config BALLOON_COMPACTION
> - bool "Allow for balloon memory compaction/migration"
> + bool "Allow for balloon memory migration"
> default y
> - depends on COMPACTION && MEMORY_BALLOON
> - help
> - Memory fragmentation introduced by ballooning might reduce
> - significantly the number of 2MB contiguous memory blocks that can be
> - used within a guest, thus imposing performance penalties associated
> - with the reduced number of transparent huge pages that could be used
> - by the guest workload. Allowing the compaction & migration for memory
> - pages enlisted as being part of memory balloon devices avoids the
> - scenario aforementioned and helps improving memory defragmentation.
> + depends on MIGRATION && MEMORY_BALLOON
> + help
> + Allow for migration of pages inflated in a memory balloon such that
> + they can be allocated from memory areas only available for movable
> + allocations (e.g., ZONE_MOVABLE, CMA) and such that they can get
nit:
s/get/be/
> + migrated for memory defragmentation purposes by memory compaction.
>
> #
> # support for memory compaction
--
~Randy
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 20/23] mm/kconfig: make BALLOON_COMPACTION depend on MIGRATION
2025-10-21 17:13 ` Randy Dunlap
@ 2025-10-21 18:43 ` David Hildenbrand
0 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-21 18:43 UTC (permalink / raw)
To: Randy Dunlap, linux-kernel
Cc: linux-mm, linuxppc-dev, Broadcom internal kernel review list,
linux-doc, virtualization, Andrew Morton, Oscar Salvador,
Lorenzo Stoakes, Liam R . Howlett, Vlastimil Babka, Mike Rapoport,
Suren Baghdasaryan, Michal Hocko, Jonathan Corbet,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy, Arnd Bergmann, Greg Kroah-Hartman,
Jerrin Shaji George, Michael S . Tsirkin, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
On 21.10.25 19:13, Randy Dunlap wrote:
>
>
> On 10/21/25 8:00 AM, David Hildenbrand wrote:
>> Migration support for balloon memory depends on MIGRATION not
>> COMPACTION. Compaction is simply another user of page migration.
>>
>> The last dependency on compaction.c was effectively removed with
>> commit 3d388584d599 ("mm: convert "movable" flag in page->mapping to a
>> page flag"). Ever since, everything for handling movable_ops page
>> migration resides in core migration code.
>>
>> So let's change the dependency and adjust the description +
>> help text.
>>
>> We'll rename BALLOON_COMPACTION separately next.
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>> mm/Kconfig | 17 +++++++----------
>> 1 file changed, 7 insertions(+), 10 deletions(-)
>>
>> diff --git a/mm/Kconfig b/mm/Kconfig
>> index e47321051d765..3aff4d05a2d8c 100644
>> --- a/mm/Kconfig
>> +++ b/mm/Kconfig
>> @@ -599,17 +599,14 @@ config MEMORY_BALLOON
>> #
>> # support for memory balloon compaction
>> config BALLOON_COMPACTION
>> - bool "Allow for balloon memory compaction/migration"
>> + bool "Allow for balloon memory migration"
>> default y
>> - depends on COMPACTION && MEMORY_BALLOON
>> - help
>> - Memory fragmentation introduced by ballooning might reduce
>> - significantly the number of 2MB contiguous memory blocks that can be
>> - used within a guest, thus imposing performance penalties associated
>> - with the reduced number of transparent huge pages that could be used
>> - by the guest workload. Allowing the compaction & migration for memory
>> - pages enlisted as being part of memory balloon devices avoids the
>> - scenario aforementioned and helps improving memory defragmentation.
>> + depends on MIGRATION && MEMORY_BALLOON
>> + help
>> + Allow for migration of pages inflated in a memory balloon such that
>> + they can be allocated from memory areas only available for movable
>> + allocations (e.g., ZONE_MOVABLE, CMA) and such that they can get
>
> nit:
> s/get/be/
Thanks!
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 03/23] powerpc/pseries/cmm: remove cmm_balloon_compaction_init()
2025-10-21 12:59 ` [PATCH v1 03/23] powerpc/pseries/cmm: remove cmm_balloon_compaction_init() David Hildenbrand
@ 2025-10-21 20:43 ` Michael S. Tsirkin
2025-10-22 8:37 ` David Hildenbrand
0 siblings, 1 reply; 39+ messages in thread
From: Michael S. Tsirkin @ 2025-10-21 20:43 UTC (permalink / raw)
To: David Hildenbrand
Cc: linux-kernel, linux-mm, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
On Tue, Oct 21, 2025 at 02:59:08PM +0200, David Hildenbrand wrote:
> Now that there is not a lot of logic left, let's just inline setting up
> the migration function.
>
> To avoid #ifdef in the caller we can instead use IS_ENABLED() and make
> the compiler happy by only providing the function declaration.
>
> Now that the function is gone, drop the "out_balloon_compaction" label.
> Note that before commit 68f2736a8583 ("mm: Convert all PageMovable users
> to movable_operations"), now not anymore.
What does this sentence mean?
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> arch/powerpc/platforms/pseries/cmm.c | 16 +++++-----------
> 1 file changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c
> index 310dab4bc8679..67c7309c36147 100644
> --- a/arch/powerpc/platforms/pseries/cmm.c
> +++ b/arch/powerpc/platforms/pseries/cmm.c
> @@ -548,15 +548,9 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
>
> return 0;
> }
> -
> -static void cmm_balloon_compaction_init(void)
> -{
> - b_dev_info.migratepage = cmm_migratepage;
> -}
> #else /* CONFIG_BALLOON_COMPACTION */
> -static void cmm_balloon_compaction_init(void)
> -{
> -}
> +int cmm_migratepage(struct balloon_dev_info *b_dev_info, struct page *newpage,
> + struct page *page, enum migrate_mode mode);
> #endif /* CONFIG_BALLOON_COMPACTION */
>
> /**
> @@ -573,11 +567,12 @@ static int cmm_init(void)
> return -EOPNOTSUPP;
>
> balloon_devinfo_init(&b_dev_info);
> - cmm_balloon_compaction_init();
> + if (IS_ENABLED(CONFIG_BALLOON_COMPACTION))
> + b_dev_info.migratepage = cmm_migratepage;
>
> rc = register_oom_notifier(&cmm_oom_nb);
> if (rc < 0)
> - goto out_balloon_compaction;
> + return rc;
>
> if ((rc = register_reboot_notifier(&cmm_reboot_nb)))
> goto out_oom_notifier;
> @@ -606,7 +601,6 @@ static int cmm_init(void)
> unregister_reboot_notifier(&cmm_reboot_nb);
> out_oom_notifier:
> unregister_oom_notifier(&cmm_oom_nb);
> -out_balloon_compaction:
> return rc;
> }
>
> --
> 2.51.0
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 04/23] mm/balloon_compaction: centralize basic page migration handling
2025-10-21 12:59 ` [PATCH v1 04/23] mm/balloon_compaction: centralize basic page migration handling David Hildenbrand
@ 2025-10-21 20:50 ` Michael S. Tsirkin
2025-10-22 8:37 ` David Hildenbrand
0 siblings, 1 reply; 39+ messages in thread
From: Michael S. Tsirkin @ 2025-10-21 20:50 UTC (permalink / raw)
To: David Hildenbrand
Cc: linux-kernel, linux-mm, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
On Tue, Oct 21, 2025 at 02:59:09PM +0200, David Hildenbrand 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 mach the other
match
> functions. Also, drop the comment above balloon_page_migrate(), which
> seems unnecessary.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> arch/powerpc/platforms/pseries/cmm.c | 16 ---------
> drivers/misc/vmw_balloon.c | 49 +++++-----------------------
> drivers/virtio/virtio_balloon.c | 12 -------
> mm/balloon_compaction.c | 37 ++++++++++++++++++---
> 4 files changed, 41 insertions(+), 73 deletions(-)
>
> diff --git a/arch/powerpc/platforms/pseries/cmm.c b/arch/powerpc/platforms/pseries/cmm.c
> index 67c7309c36147..07b21d2bc8a78 100644
> --- a/arch/powerpc/platforms/pseries/cmm.c
> +++ b/arch/powerpc/platforms/pseries/cmm.c
> @@ -501,8 +501,6 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
> struct page *newpage, struct page *page,
> enum migrate_mode mode)
> {
> - unsigned long flags;
> -
> /*
> * loan/"inflate" the newpage first.
> *
> @@ -517,9 +515,6 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
> return -EBUSY;
> }
>
> - /* balloon page list reference */
> - get_page(newpage);
> -
> /*
> * When we migrate a page to a different zone, we have to fixup the
> * count of both involved zones as we adjusted the managed page count
> @@ -530,22 +525,11 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
> adjust_managed_page_count(newpage, -1);
> }
>
> - spin_lock_irqsave(&b_dev_info->pages_lock, flags);
> - balloon_page_insert(b_dev_info, newpage);
> - __count_vm_event(BALLOON_MIGRATE);
> - b_dev_info->isolated_pages--;
> - spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
> -
> /*
> * activate/"deflate" the old page. We ignore any errors just like the
> * other callers.
> */
> plpar_page_set_active(page);
> -
> - balloon_page_finalize(page);
> - /* balloon page list reference */
> - put_page(page);
> -
> return 0;
> }
> #else /* CONFIG_BALLOON_COMPACTION */
> diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
> index 07e60a4b846aa..52b8c0f1eead7 100644
> --- a/drivers/misc/vmw_balloon.c
> +++ b/drivers/misc/vmw_balloon.c
> @@ -1724,18 +1724,17 @@ static inline void vmballoon_debugfs_exit(struct vmballoon *b)
> * @page: a ballooned page that should be migrated.
> * @mode: migration mode, ignored.
> *
> - * This function is really open-coded, but that is according to the interface
> - * that balloon_compaction provides.
> - *
> * Return: zero on success, -EAGAIN when migration cannot be performed
> - * momentarily, and -EBUSY if migration failed and should be retried
> - * with that specific page.
> + * momentarily, -EBUSY if migration failed and should be retried
> + * with that specific page, and -ENOENT when deflating @page
> + * succeeded but inflating @newpage failed, effectively deflating
> + * the balloon.
> */
> static int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
> struct page *newpage, struct page *page,
> enum migrate_mode mode)
> {
> - unsigned long status, flags;
> + unsigned long status;
> struct vmballoon *b;
> int ret = 0;
>
> @@ -1773,14 +1772,6 @@ static int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
> goto out_unlock;
> }
>
> - /*
> - * The page is isolated, so it is safe to delete it without holding
> - * @pages_lock . We keep holding @comm_lock since we will need it in a
> - * second.
> - */
> - balloon_page_finalize(page);
> - put_page(page);
> -
> /* Inflate */
> vmballoon_add_page(b, 0, newpage);
> status = vmballoon_lock_op(b, 1, VMW_BALLOON_4K_PAGE,
> @@ -1799,36 +1790,12 @@ static int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
> * change.
> */
> atomic64_dec(&b->size);
> - } else {
> /*
> - * Success. Take a reference for the page, and we will add it to
> - * the list after acquiring the lock.
> + * Tell the core that we're deflating the old page and don't
> + * need the new page.
> */
> - get_page(newpage);
> - }
> -
> - /* Update the balloon list under the @pages_lock */
> - spin_lock_irqsave(&b->b_dev_info.pages_lock, flags);
> -
> - /*
> - * On inflation success, we already took a reference for the @newpage.
> - * If we succeed just insert it to the list and update the statistics
> - * under the lock.
> - */
> - if (status == VMW_BALLOON_SUCCESS) {
> - balloon_page_insert(&b->b_dev_info, newpage);
> - __count_vm_event(BALLOON_MIGRATE);
> - } else {
> - __count_vm_event(BALLOON_DEFLATE);
> + ret = -ENOENT;
> }
> -
> - /*
> - * We deflated successfully, so regardless to the inflation success, we
> - * need to reduce the number of isolated_pages.
> - */
> - b->b_dev_info.isolated_pages--;
> - spin_unlock_irqrestore(&b->b_dev_info.pages_lock, flags);
> -
> out_unlock:
> up_read(&b->conf_sem);
> return ret;
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 1b93d8c643612..8969271581bca 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -827,7 +827,6 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
> {
> struct virtio_balloon *vb = container_of(vb_dev_info,
> struct virtio_balloon, vb_dev_info);
> - unsigned long flags;
>
> /*
> * In order to avoid lock contention while migrating pages concurrently
> @@ -840,8 +839,6 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
> if (!mutex_trylock(&vb->balloon_lock))
> return -EAGAIN;
>
> - get_page(newpage); /* balloon reference */
> -
> /*
> * When we migrate a page to a different zone and adjusted the
> * managed page count when inflating, we have to fixup the count of
> @@ -854,11 +851,6 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
> }
>
> /* balloon's page migration 1st step -- inflate "newpage" */
> - spin_lock_irqsave(&vb_dev_info->pages_lock, flags);
> - balloon_page_insert(vb_dev_info, newpage);
> - vb_dev_info->isolated_pages--;
> - __count_vm_event(BALLOON_MIGRATE);
> - spin_unlock_irqrestore(&vb_dev_info->pages_lock, flags);
> vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE;
> set_page_pfns(vb, vb->pfns, newpage);
> tell_host(vb, vb->inflate_vq);
> @@ -869,10 +861,6 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
> tell_host(vb, vb->deflate_vq);
>
> mutex_unlock(&vb->balloon_lock);
> -
> - balloon_page_finalize(page);
> - put_page(page); /* balloon reference */
> -
> return 0;
> }
> #endif /* CONFIG_BALLOON_COMPACTION */
> diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
> index 03c5dbabb1565..5444c61bb9e76 100644
> --- a/mm/balloon_compaction.c
> +++ b/mm/balloon_compaction.c
> @@ -232,20 +232,49 @@ static void balloon_page_putback(struct page *page)
> spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
> }
>
> -/* move_to_new_page() counterpart for a ballooned page */
> static int balloon_page_migrate(struct page *newpage, struct page *page,
> enum migrate_mode mode)
> {
> - struct balloon_dev_info *balloon = balloon_page_device(page);
> + struct balloon_dev_info *b_dev_info = balloon_page_device(page);
> + unsigned long flags;
> + int rc;
>
> VM_BUG_ON_PAGE(!PageLocked(page), page);
> VM_BUG_ON_PAGE(!PageLocked(newpage), newpage);
>
> /* Isolated balloon pages cannot get deflated. */
> - if (WARN_ON_ONCE(!balloon))
> + if (WARN_ON_ONCE(!b_dev_info))
> return -EAGAIN;
>
> - return balloon->migratepage(balloon, newpage, page, mode);
> + rc = b_dev_info->migratepage(b_dev_info, newpage, page, mode);
> + switch (rc) {
> + case 0:
> + spin_lock_irqsave(&b_dev_info->pages_lock, flags);
> +
> + /* 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);
> +
> + /* Free the now-deflated page we isolated in balloon_page_isolate(). */
> + balloon_page_finalize(page);
> + put_page(page);
> +
> + return 0;
> }
>
> const struct movable_operations balloon_mops = {
> --
> 2.51.0
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 07/23] mm/balloon_compaction: use a device-independent balloon (list) lock
2025-10-21 12:59 ` [PATCH v1 07/23] mm/balloon_compaction: use a device-independent balloon (list) lock David Hildenbrand
@ 2025-10-21 20:52 ` Michael S. Tsirkin
2025-10-22 8:42 ` David Hildenbrand
0 siblings, 1 reply; 39+ messages in thread
From: Michael S. Tsirkin @ 2025-10-21 20:52 UTC (permalink / raw)
To: David Hildenbrand
Cc: linux-kernel, linux-mm, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
On Tue, Oct 21, 2025 at 02:59:12PM +0200, David Hildenbrand wrote:
> In order to remove the dependency on the page lock for balloon
> pages, we need a lock that is independent of the page.
>
> It's crucial that we can handle the scenario where balloon deflation
> (clearing page->private) can race with page isolation (using
> page->private to obtain the balloon_dev_info where the lock currently
> resides).
>
> The current lock in balloon_dev_info is therefore not suitable.
>
> Fortunately, we never really have more than a single balloon device
> per VM, so we can just keep it simple and use a static lock to protect
> all balloon devices.
>
> Based on this change we will remove the dependency on the page lock
> next.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> include/linux/balloon_compaction.h | 6 ++---
> mm/balloon_compaction.c | 36 +++++++++++++++++-------------
> 2 files changed, 23 insertions(+), 19 deletions(-)
>
> diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
> index 3109d3c43d306..e2d9eb40e1fbb 100644
> --- a/include/linux/balloon_compaction.h
> +++ b/include/linux/balloon_compaction.h
> @@ -21,10 +21,10 @@
> * i. Setting the PG_movable_ops flag and page->private with the following
> * lock order
> * +-page_lock(page);
> - * +--spin_lock_irq(&b_dev_info->pages_lock);
> + * +--spin_lock_irq(&balloon_pages_lock);
> *
> * ii. isolation or dequeueing procedure must remove the page from balloon
> - * device page list under b_dev_info->pages_lock.
> + * device page list under &balloon_pages_lock
Using &balloon_pages_lock with an & is kinda weird here.
> *
> * The functions provided by this interface are placed to help on coping with
> * the aforementioned balloon page corner case, as well as to ensure the simple
> @@ -52,7 +52,6 @@
> */
> struct balloon_dev_info {
> unsigned long isolated_pages; /* # of isolated pages for migration */
> - spinlock_t pages_lock; /* Protection to pages list */
> struct list_head pages; /* Pages enqueued & handled to Host */
> int (*migratepage)(struct balloon_dev_info *, struct page *newpage,
> struct page *page, enum migrate_mode mode);
> @@ -71,7 +70,6 @@ extern size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
> static inline void balloon_devinfo_init(struct balloon_dev_info *balloon)
> {
> balloon->isolated_pages = 0;
> - spin_lock_init(&balloon->pages_lock);
> INIT_LIST_HEAD(&balloon->pages);
> balloon->migratepage = NULL;
> balloon->adjust_managed_page_count = false;
> diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
> index fd9ec47cf4670..97e838795354d 100644
> --- a/mm/balloon_compaction.c
> +++ b/mm/balloon_compaction.c
> @@ -11,6 +11,12 @@
> #include <linux/export.h>
> #include <linux/balloon_compaction.h>
>
> +/*
> + * Lock protecting the balloon_dev_info of all devices. We don't really
> + * expect more than one device.
> + */
> +static DEFINE_SPINLOCK(balloon_pages_lock);
> +
> static void balloon_page_enqueue_one(struct balloon_dev_info *b_dev_info,
> struct page *page)
> {
> @@ -47,13 +53,13 @@ size_t balloon_page_list_enqueue(struct balloon_dev_info *b_dev_info,
> unsigned long flags;
> size_t n_pages = 0;
>
> - spin_lock_irqsave(&b_dev_info->pages_lock, flags);
> + spin_lock_irqsave(&balloon_pages_lock, flags);
> list_for_each_entry_safe(page, tmp, pages, lru) {
> list_del(&page->lru);
> balloon_page_enqueue_one(b_dev_info, page);
> n_pages++;
> }
> - spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
> + spin_unlock_irqrestore(&balloon_pages_lock, flags);
> return n_pages;
> }
> EXPORT_SYMBOL_GPL(balloon_page_list_enqueue);
> @@ -83,7 +89,7 @@ size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
> unsigned long flags;
> size_t n_pages = 0;
>
> - spin_lock_irqsave(&b_dev_info->pages_lock, flags);
> + spin_lock_irqsave(&balloon_pages_lock, flags);
> list_for_each_entry_safe(page, tmp, &b_dev_info->pages, lru) {
> if (n_pages == n_req_pages)
> break;
> @@ -106,7 +112,7 @@ size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
> dec_node_page_state(page, NR_BALLOON_PAGES);
> n_pages++;
> }
> - spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
> + spin_unlock_irqrestore(&balloon_pages_lock, flags);
>
> return n_pages;
> }
> @@ -149,9 +155,9 @@ void balloon_page_enqueue(struct balloon_dev_info *b_dev_info,
> {
> unsigned long flags;
>
> - spin_lock_irqsave(&b_dev_info->pages_lock, flags);
> + spin_lock_irqsave(&balloon_pages_lock, flags);
> balloon_page_enqueue_one(b_dev_info, page);
> - spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
> + spin_unlock_irqrestore(&balloon_pages_lock, flags);
> }
> EXPORT_SYMBOL_GPL(balloon_page_enqueue);
>
> @@ -191,11 +197,11 @@ struct page *balloon_page_dequeue(struct balloon_dev_info *b_dev_info)
> * BUG() here, otherwise the balloon driver may get stuck in
> * an infinite loop while attempting to release all its pages.
> */
> - spin_lock_irqsave(&b_dev_info->pages_lock, flags);
> + spin_lock_irqsave(&balloon_pages_lock, flags);
> if (unlikely(list_empty(&b_dev_info->pages) &&
> !b_dev_info->isolated_pages))
> BUG();
> - spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
> + spin_unlock_irqrestore(&balloon_pages_lock, flags);
> return NULL;
> }
> return list_first_entry(&pages, struct page, lru);
> @@ -213,10 +219,10 @@ static bool balloon_page_isolate(struct page *page, isolate_mode_t mode)
> if (!b_dev_info)
> return false;
>
> - spin_lock_irqsave(&b_dev_info->pages_lock, flags);
> + spin_lock_irqsave(&balloon_pages_lock, flags);
> list_del(&page->lru);
> b_dev_info->isolated_pages++;
> - spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
> + spin_unlock_irqrestore(&balloon_pages_lock, flags);
>
> return true;
> }
> @@ -230,10 +236,10 @@ static void balloon_page_putback(struct page *page)
> if (WARN_ON_ONCE(!b_dev_info))
> return;
>
> - spin_lock_irqsave(&b_dev_info->pages_lock, flags);
> + spin_lock_irqsave(&balloon_pages_lock, flags);
> list_add(&page->lru, &b_dev_info->pages);
> b_dev_info->isolated_pages--;
> - spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
> + spin_unlock_irqrestore(&balloon_pages_lock, flags);
> }
>
> static int balloon_page_migrate(struct page *newpage, struct page *page,
> @@ -253,7 +259,7 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
> rc = b_dev_info->migratepage(b_dev_info, newpage, page, mode);
> switch (rc) {
> case 0:
> - spin_lock_irqsave(&b_dev_info->pages_lock, flags);
> + spin_lock_irqsave(&balloon_pages_lock, flags);
>
> /* Insert the new page into the balloon list. */
> get_page(newpage);
> @@ -272,7 +278,7 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
> }
> break;
> case -ENOENT:
> - spin_lock_irqsave(&b_dev_info->pages_lock, flags);
> + spin_lock_irqsave(&balloon_pages_lock, flags);
>
> /* Old page was deflated but new page not inflated. */
> __count_vm_event(BALLOON_DEFLATE);
> @@ -285,7 +291,7 @@ static int balloon_page_migrate(struct page *newpage, struct page *page,
> }
>
> b_dev_info->isolated_pages--;
> - spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
> + spin_unlock_irqrestore(&balloon_pages_lock, flags);
>
> /* Free the now-deflated page we isolated in balloon_page_isolate(). */
> balloon_page_finalize(page);
> --
> 2.51.0
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 06/23] vmw_balloon: stop using the balloon_dev_info lock
2025-10-21 12:59 ` [PATCH v1 06/23] vmw_balloon: stop using the balloon_dev_info lock David Hildenbrand
@ 2025-10-21 20:57 ` Michael S. Tsirkin
2025-10-22 8:40 ` David Hildenbrand
0 siblings, 1 reply; 39+ messages in thread
From: Michael S. Tsirkin @ 2025-10-21 20:57 UTC (permalink / raw)
To: David Hildenbrand
Cc: linux-kernel, linux-mm, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
On Tue, Oct 21, 2025 at 02:59:11PM +0200, David Hildenbrand wrote:
> Let's not piggy-back on the existing lock and use a separate lock for the
> huge page list.
which is fine but it is worth documenting that we are also
no longer disabling interrupts while taking this lock.
> This is a preparation for changing the locking used to protect
> balloon_dev_info.
>
> While at it, talk about "page migration" instead of "page compaction".
> We'll change that in core code soon as well.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> drivers/misc/vmw_balloon.c | 20 ++++++++++++--------
> 1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
> index 52b8c0f1eead7..53e9335b6718c 100644
> --- a/drivers/misc/vmw_balloon.c
> +++ b/drivers/misc/vmw_balloon.c
> @@ -354,10 +354,15 @@ struct vmballoon {
> /**
> * @huge_pages - list of the inflated 2MB pages.
> *
> - * Protected by @b_dev_info.pages_lock .
> + * Protected by @huge_pages_lock.
> */
> struct list_head huge_pages;
>
> + /**
> + * @huge_pages_lock: lock for the list of inflated 2MB pages.
> + */
> + spinlock_t huge_pages_lock;
> +
> /**
> * @vmci_doorbell.
> *
> @@ -987,7 +992,6 @@ static void vmballoon_enqueue_page_list(struct vmballoon *b,
> unsigned int *n_pages,
> enum vmballoon_page_size_type page_size)
> {
> - unsigned long flags;
> struct page *page;
>
> if (page_size == VMW_BALLOON_4K_PAGE) {
> @@ -995,9 +999,9 @@ static void vmballoon_enqueue_page_list(struct vmballoon *b,
> } else {
> /*
> * Keep the huge pages in a local list which is not available
> - * for the balloon compaction mechanism.
> + * for the balloon page migration.
> */
> - spin_lock_irqsave(&b->b_dev_info.pages_lock, flags);
> + spin_lock(&b->huge_pages_lock);
>
> list_for_each_entry(page, pages, lru) {
> vmballoon_mark_page_offline(page, VMW_BALLOON_2M_PAGE);
> @@ -1006,7 +1010,7 @@ static void vmballoon_enqueue_page_list(struct vmballoon *b,
> list_splice_init(pages, &b->huge_pages);
> __count_vm_events(BALLOON_INFLATE, *n_pages *
> vmballoon_page_in_frames(VMW_BALLOON_2M_PAGE));
> - spin_unlock_irqrestore(&b->b_dev_info.pages_lock, flags);
> + spin_unlock(&b->huge_pages_lock);
> }
>
> *n_pages = 0;
> @@ -1033,7 +1037,6 @@ static void vmballoon_dequeue_page_list(struct vmballoon *b,
> {
> struct page *page, *tmp;
> unsigned int i = 0;
> - unsigned long flags;
>
> /* In the case of 4k pages, use the compaction infrastructure */
> if (page_size == VMW_BALLOON_4K_PAGE) {
> @@ -1043,7 +1046,7 @@ static void vmballoon_dequeue_page_list(struct vmballoon *b,
> }
>
> /* 2MB pages */
> - spin_lock_irqsave(&b->b_dev_info.pages_lock, flags);
> + spin_lock(&b->huge_pages_lock);
> list_for_each_entry_safe(page, tmp, &b->huge_pages, lru) {
> vmballoon_mark_page_online(page, VMW_BALLOON_2M_PAGE);
>
> @@ -1054,7 +1057,7 @@ static void vmballoon_dequeue_page_list(struct vmballoon *b,
>
> __count_vm_events(BALLOON_DEFLATE,
> i * vmballoon_page_in_frames(VMW_BALLOON_2M_PAGE));
> - spin_unlock_irqrestore(&b->b_dev_info.pages_lock, flags);
> + spin_unlock(&b->huge_pages_lock);
> *n_pages = i;
> }
>
> @@ -1828,6 +1831,7 @@ static int __init vmballoon_init(void)
> balloon.b_dev_info.migratepage = vmballoon_migratepage;
>
> INIT_LIST_HEAD(&balloon.huge_pages);
> + spin_lock_init(&balloon.huge_pages_lock);
> spin_lock_init(&balloon.comm_lock);
> init_rwsem(&balloon.conf_sem);
> balloon.vmci_doorbell = VMCI_INVALID_HANDLE;
> --
> 2.51.0
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 11/23] drivers/virtio/virtio_balloon: stop using balloon_page_push/pop()
2025-10-21 12:59 ` [PATCH v1 11/23] drivers/virtio/virtio_balloon: stop using balloon_page_push/pop() David Hildenbrand
@ 2025-10-21 20:59 ` Michael S. Tsirkin
2025-10-22 8:43 ` David Hildenbrand
0 siblings, 1 reply; 39+ messages in thread
From: Michael S. Tsirkin @ 2025-10-21 20:59 UTC (permalink / raw)
To: David Hildenbrand
Cc: linux-kernel, linux-mm, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
On Tue, Oct 21, 2025 at 02:59:16PM +0200, David Hildenbrand wrote:
> Let's stop using these function
these functions
> so we can remove them. They look like
> belonging to the balloon API for managing the device balloon list when
> really they are just simple helpers only used by virtio-balloon.
>
> Let's just inline them and switch to a proper
> list_for_each_entry_safe().
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> drivers/virtio/virtio_balloon.c | 25 +++++++++++++++----------
> 1 file changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index f7d6a4a6e54f5..4b22de6a5f845 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -242,8 +242,8 @@ static void set_page_pfns(struct virtio_balloon *vb,
> static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
> {
> unsigned int num_allocated_pages;
> + struct page *page, *next;
> unsigned int num_pfns;
> - struct page *page;
> LIST_HEAD(pages);
>
> /* We can only do one array worth at a time. */
> @@ -262,14 +262,15 @@ static unsigned int fill_balloon(struct virtio_balloon *vb, size_t num)
> break;
> }
>
> - balloon_page_push(&pages, page);
> + list_add(&page->lru, &pages);
> }
>
> mutex_lock(&vb->balloon_lock);
>
> vb->num_pfns = 0;
>
> - while ((page = balloon_page_pop(&pages))) {
> + list_for_each_entry_safe(page, next, &pages, lru) {
> + list_del(&page->lru);
> balloon_page_enqueue(&vb->vb_dev_info, page);
>
> set_page_pfns(vb, vb->pfns + vb->num_pfns, page);
> @@ -474,15 +475,19 @@ static inline s64 towards_target(struct virtio_balloon *vb)
> static unsigned long return_free_pages_to_mm(struct virtio_balloon *vb,
> unsigned long num_to_return)
> {
> - struct page *page;
> - unsigned long num_returned;
> + unsigned long num_returned = 0;
> + struct page *page, *next;
> +
> + if (unlikely(!num_to_return))
> + return 0;
>
> spin_lock_irq(&vb->free_page_list_lock);
> - for (num_returned = 0; num_returned < num_to_return; num_returned++) {
> - page = balloon_page_pop(&vb->free_page_list);
> - if (!page)
> - break;
> +
> + list_for_each_entry_safe(page, next, &vb->free_page_list, lru) {
> + list_del(&page->lru);
> __free_pages(page, VIRTIO_BALLOON_HINT_BLOCK_ORDER);
> + if (++num_returned == num_to_return)
> + break;
> }
> vb->num_free_page_blocks -= num_returned;
> spin_unlock_irq(&vb->free_page_list_lock);
> @@ -717,7 +722,7 @@ static int get_free_page_and_send(struct virtio_balloon *vb)
> }
> virtqueue_kick(vq);
> spin_lock_irq(&vb->free_page_list_lock);
> - balloon_page_push(&vb->free_page_list, page);
> + list_add(&page->lru, &vb->free_page_list);
> vb->num_free_page_blocks++;
> spin_unlock_irq(&vb->free_page_list_lock);
> } else {
> --
> 2.51.0
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 01/23] vmw_balloon: adjust BALLOON_DEFLATE when deflating while migrating
2025-10-21 12:59 ` [PATCH v1 01/23] vmw_balloon: adjust BALLOON_DEFLATE when deflating while migrating David Hildenbrand
@ 2025-10-22 1:03 ` SeongJae Park
0 siblings, 0 replies; 39+ messages in thread
From: SeongJae Park @ 2025-10-22 1:03 UTC (permalink / raw)
To: David Hildenbrand
Cc: SeongJae Park, linux-kernel, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Michael S. Tsirkin,
Jason Wang, Xuan Zhuo, Eugenio Pérez, Zi Yan
On Tue, 21 Oct 2025 14:59:06 +0200 David Hildenbrand <david@redhat.com> wrote:
> When we're effectively deflating the balloon while migrating a page
> because inflating the new page failed, we're not adjusting
> BALLOON_DEFLATE.
>
> Let's do that. This is a preparation for factoring out this handling to
> the core code, making it work in a similar way first.
>
> As this (deflating while migrating because of inflation error) is a
> corner case that I don't really expect to happen in practice
> and the stats are not that crucial, this likely doesn't classify as a fix.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 03/23] powerpc/pseries/cmm: remove cmm_balloon_compaction_init()
2025-10-21 20:43 ` Michael S. Tsirkin
@ 2025-10-22 8:37 ` David Hildenbrand
0 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-22 8:37 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: linux-kernel, linux-mm, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
On 21.10.25 22:43, Michael S. Tsirkin wrote:
> On Tue, Oct 21, 2025 at 02:59:08PM +0200, David Hildenbrand wrote:
>> Now that there is not a lot of logic left, let's just inline setting up
>> the migration function.
>>
>> To avoid #ifdef in the caller we can instead use IS_ENABLED() and make
>> the compiler happy by only providing the function declaration.
>>
>> Now that the function is gone, drop the "out_balloon_compaction" label.
>> Note that before commit 68f2736a8583 ("mm: Convert all PageMovable users
>> to movable_operations"), now not anymore.
>
> What does this sentence mean?
Should have been "... we actually had to undo something, now not anymore."
Thanks!
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 04/23] mm/balloon_compaction: centralize basic page migration handling
2025-10-21 20:50 ` Michael S. Tsirkin
@ 2025-10-22 8:37 ` David Hildenbrand
0 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-22 8:37 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: linux-kernel, linux-mm, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
On 21.10.25 22:50, Michael S. Tsirkin wrote:
> On Tue, Oct 21, 2025 at 02:59:09PM +0200, David Hildenbrand 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 mach the other
>
> match
Thanks!
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 06/23] vmw_balloon: stop using the balloon_dev_info lock
2025-10-21 20:57 ` Michael S. Tsirkin
@ 2025-10-22 8:40 ` David Hildenbrand
0 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-22 8:40 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: linux-kernel, linux-mm, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
On 21.10.25 22:57, Michael S. Tsirkin wrote:
> On Tue, Oct 21, 2025 at 02:59:11PM +0200, David Hildenbrand wrote:
>> Let's not piggy-back on the existing lock and use a separate lock for the
>> huge page list.
>
> which is fine but it is worth documenting that we are also
> no longer disabling interrupts while taking this lock.
Indeed, I'll add
"Now that we use a separate lock, there is no need to disable
interrupts, so use the non-irqsave variants."
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 07/23] mm/balloon_compaction: use a device-independent balloon (list) lock
2025-10-21 20:52 ` Michael S. Tsirkin
@ 2025-10-22 8:42 ` David Hildenbrand
0 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-22 8:42 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: linux-kernel, linux-mm, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
On 21.10.25 22:52, Michael S. Tsirkin wrote:
> On Tue, Oct 21, 2025 at 02:59:12PM +0200, David Hildenbrand wrote:
>> In order to remove the dependency on the page lock for balloon
>> pages, we need a lock that is independent of the page.
>>
>> It's crucial that we can handle the scenario where balloon deflation
>> (clearing page->private) can race with page isolation (using
>> page->private to obtain the balloon_dev_info where the lock currently
>> resides).
>>
>> The current lock in balloon_dev_info is therefore not suitable.
>>
>> Fortunately, we never really have more than a single balloon device
>> per VM, so we can just keep it simple and use a static lock to protect
>> all balloon devices.
>>
>> Based on this change we will remove the dependency on the page lock
>> next.
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>> include/linux/balloon_compaction.h | 6 ++---
>> mm/balloon_compaction.c | 36 +++++++++++++++++-------------
>> 2 files changed, 23 insertions(+), 19 deletions(-)
>>
>> diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
>> index 3109d3c43d306..e2d9eb40e1fbb 100644
>> --- a/include/linux/balloon_compaction.h
>> +++ b/include/linux/balloon_compaction.h
>> @@ -21,10 +21,10 @@
>> * i. Setting the PG_movable_ops flag and page->private with the following
>> * lock order
>> * +-page_lock(page);
>> - * +--spin_lock_irq(&b_dev_info->pages_lock);
>> + * +--spin_lock_irq(&balloon_pages_lock);
>> *
>> * ii. isolation or dequeueing procedure must remove the page from balloon
>> - * device page list under b_dev_info->pages_lock.
>> + * device page list under &balloon_pages_lock
>
> Using &balloon_pages_lock with an & is kinda weird here.
Indeed, fixed, thanks!
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 39+ messages in thread
* Re: [PATCH v1 11/23] drivers/virtio/virtio_balloon: stop using balloon_page_push/pop()
2025-10-21 20:59 ` Michael S. Tsirkin
@ 2025-10-22 8:43 ` David Hildenbrand
0 siblings, 0 replies; 39+ messages in thread
From: David Hildenbrand @ 2025-10-22 8:43 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: linux-kernel, linux-mm, linuxppc-dev,
Broadcom internal kernel review list, linux-doc, virtualization,
Andrew Morton, Oscar Salvador, Lorenzo Stoakes, Liam R. Howlett,
Vlastimil Babka, Mike Rapoport, Suren Baghdasaryan, Michal Hocko,
Jonathan Corbet, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy, Arnd Bergmann,
Greg Kroah-Hartman, Jerrin Shaji George, Jason Wang, Xuan Zhuo,
Eugenio Pérez, Zi Yan
On 21.10.25 22:59, Michael S. Tsirkin wrote:
> On Tue, Oct 21, 2025 at 02:59:16PM +0200, David Hildenbrand wrote:
>> Let's stop using these function
>
> these functions
Fixed, thanks!
--
Cheers
David / dhildenb
^ permalink raw reply [flat|nested] 39+ messages in thread
end of thread, other threads:[~2025-10-22 8:43 UTC | newest]
Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-21 12:59 [PATCH v1 00/23] mm: balloon infrastructure cleanups David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 01/23] vmw_balloon: adjust BALLOON_DEFLATE when deflating while migrating David Hildenbrand
2025-10-22 1:03 ` SeongJae Park
2025-10-21 12:59 ` [PATCH v1 02/23] vmw_balloon: remove vmballoon_compaction_init() David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 03/23] powerpc/pseries/cmm: remove cmm_balloon_compaction_init() David Hildenbrand
2025-10-21 20:43 ` Michael S. Tsirkin
2025-10-22 8:37 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 04/23] mm/balloon_compaction: centralize basic page migration handling David Hildenbrand
2025-10-21 20:50 ` Michael S. Tsirkin
2025-10-22 8:37 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 05/23] mm/balloon_compaction: centralize adjust_managed_page_count() handling David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 06/23] vmw_balloon: stop using the balloon_dev_info lock David Hildenbrand
2025-10-21 20:57 ` Michael S. Tsirkin
2025-10-22 8:40 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 07/23] mm/balloon_compaction: use a device-independent balloon (list) lock David Hildenbrand
2025-10-21 20:52 ` Michael S. Tsirkin
2025-10-22 8:42 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 08/23] mm/balloon_compaction: remove dependency on page lock David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 09/23] mm/balloon_compaction: make balloon_mops static David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 10/23] mm/balloon_compaction: drop fs.h include from balloon_compaction.h David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 11/23] drivers/virtio/virtio_balloon: stop using balloon_page_push/pop() David Hildenbrand
2025-10-21 20:59 ` Michael S. Tsirkin
2025-10-22 8:43 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 12/23] mm/balloon_compaction: remove balloon_page_push/pop() David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 13/23] mm/balloon_compaction: fold balloon_mapping_gfp_mask() into balloon_page_alloc() David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 14/23] mm/balloon_compaction: move internal helpers to memory_compaction.c David Hildenbrand
2025-10-21 15:36 ` Zi Yan
2025-10-21 15:37 ` David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 15/23] mm/balloon_compaction: assert that the balloon_pages_lock is held David Hildenbrand
2025-10-21 12:59 ` [PATCH v1 16/23] mm/balloon_compaction: mark remaining functions for having proper kerneldoc David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 17/23] mm/balloon_compaction: remove "extern" from functions David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 18/23] mm/vmscan: drop inclusion of balloon_compaction.h David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 19/23] mm: rename balloon_compaction.(c|h) to balloon.(c|h) David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 20/23] mm/kconfig: make BALLOON_COMPACTION depend on MIGRATION David Hildenbrand
2025-10-21 17:13 ` Randy Dunlap
2025-10-21 18:43 ` David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 21/23] mm: rename CONFIG_BALLOON_COMPACTION to CONFIG_BALLOON_MIGRATION David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 22/23] mm: rename CONFIG_MEMORY_BALLOON -> CONFIG_BALLOON David Hildenbrand
2025-10-21 15:00 ` [PATCH v1 23/23] MAINTAINERS: move memory balloon infrastructure to "MEMORY MANAGEMENT - BALLOON" David Hildenbrand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).