Skip to content

Commit 1d71d50

Browse files
davidhildenbrandgregkh
authored andcommitted
mm/balloon_compaction: convert balloon_page_delete() to balloon_page_finalize()
[ Upstream commit 15504b1 ] Let's move the removal of the page from the balloon list into the single caller, to remove the dependency on the PG_isolated flag and clarify locking requirements. Note that for now, balloon_page_delete() was used on two paths: (1) Removing a page from the balloon for deflation through balloon_page_list_dequeue() (2) Removing an isolated page from the balloon for migration in the per-driver migration handlers. Isolated pages were already removed from the balloon list during isolation. So instead of relying on the flag, we can just distinguish both cases directly and handle it accordingly in the caller. We'll shuffle the operations a bit such that they logically make more sense (e.g., remove from the list before clearing flags). In balloon migration functions we can now move the balloon_page_finalize() out of the balloon lock and perform the finalization just before dropping the balloon reference. Document that the page lock is currently required when modifying the movability aspects of a page; hopefully we can soon decouple this from the page lock. Link: https://lkml.kernel.org/r/20250704102524.326966-3-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Alistair Popple <apopple@nvidia.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Brendan Jackman <jackmanb@google.com> Cc: Byungchul Park <byungchul@sk.com> Cc: Chengming Zhou <chengming.zhou@linux.dev> Cc: Christian Brauner <brauner@kernel.org> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Eugenio Pé rez <eperezma@redhat.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Gregory Price <gourry@gourry.net> Cc: Harry Yoo <harry.yoo@oracle.com> Cc: "Huang, Ying" <ying.huang@linux.alibaba.com> Cc: Jan Kara <jack@suse.cz> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Jason Wang <jasowang@redhat.com> Cc: Jerrin Shaji George <jerrin.shaji-george@broadcom.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: John Hubbard <jhubbard@nvidia.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Joshua Hahn <joshua.hahnjy@gmail.com> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Mathew Brost <matthew.brost@intel.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Miaohe Lin <linmiaohe@huawei.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: "Michael S. Tsirkin" <mst@redhat.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Minchan Kim <minchan@kernel.org> Cc: Naoya Horiguchi <nao.horiguchi@gmail.com> Cc: Nicholas Piggin <npiggin@gmail.com> Cc: Oscar Salvador <osalvador@suse.de> Cc: Peter Xu <peterx@redhat.com> Cc: Qi Zheng <zhengqi.arch@bytedance.com> Cc: Rakie Kim <rakie.kim@sk.com> Cc: Rik van Riel <riel@surriel.com> Cc: Sergey Senozhatsky <senozhatsky@chromium.org> Cc: Shakeel Butt <shakeel.butt@linux.dev> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com> Cc: xu xin <xu.xin16@zte.com.cn> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Stable-dep-of: 0da2ba3 ("powerpc/pseries/cmm: adjust BALLOON_MIGRATE when migrating pages") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 451b0ed commit 1d71d50

5 files changed

Lines changed: 21 additions & 34 deletions

File tree

arch/powerpc/platforms/pseries/cmm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
532532

533533
spin_lock_irqsave(&b_dev_info->pages_lock, flags);
534534
balloon_page_insert(b_dev_info, newpage);
535-
balloon_page_delete(page);
536535
b_dev_info->isolated_pages--;
537536
spin_unlock_irqrestore(&b_dev_info->pages_lock, flags);
538537

@@ -542,6 +541,7 @@ static int cmm_migratepage(struct balloon_dev_info *b_dev_info,
542541
*/
543542
plpar_page_set_active(page);
544543

544+
balloon_page_finalize(page);
545545
/* balloon page list reference */
546546
put_page(page);
547547

drivers/misc/vmw_balloon.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,8 +1778,7 @@ static int vmballoon_migratepage(struct balloon_dev_info *b_dev_info,
17781778
* @pages_lock . We keep holding @comm_lock since we will need it in a
17791779
* second.
17801780
*/
1781-
balloon_page_delete(page);
1782-
1781+
balloon_page_finalize(page);
17831782
put_page(page);
17841783

17851784
/* Inflate */

drivers/virtio/virtio_balloon.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,15 +866,13 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info,
866866
tell_host(vb, vb->inflate_vq);
867867

868868
/* balloon's page migration 2nd step -- deflate "page" */
869-
spin_lock_irqsave(&vb_dev_info->pages_lock, flags);
870-
balloon_page_delete(page);
871-
spin_unlock_irqrestore(&vb_dev_info->pages_lock, flags);
872869
vb->num_pfns = VIRTIO_BALLOON_PAGES_PER_PAGE;
873870
set_page_pfns(vb, vb->pfns, page);
874871
tell_host(vb, vb->deflate_vq);
875872

876873
mutex_unlock(&vb->balloon_lock);
877874

875+
balloon_page_finalize(page);
878876
put_page(page); /* balloon reference */
879877

880878
return MIGRATEPAGE_SUCCESS;

include/linux/balloon_compaction.h

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,6 @@ static inline void balloon_page_insert(struct balloon_dev_info *balloon,
9797
list_add(&page->lru, &balloon->pages);
9898
}
9999

100-
/*
101-
* balloon_page_delete - delete a page from balloon's page list and clear
102-
* the page->private assignement accordingly.
103-
* @page : page to be released from balloon's page list
104-
*
105-
* Caller must ensure the page is locked and the spin_lock protecting balloon
106-
* pages list is held before deleting a page from the balloon device.
107-
*/
108-
static inline void balloon_page_delete(struct page *page)
109-
{
110-
__ClearPageOffline(page);
111-
__ClearPageMovable(page);
112-
set_page_private(page, 0);
113-
/*
114-
* No touch page.lru field once @page has been isolated
115-
* because VM is using the field.
116-
*/
117-
if (!PageIsolated(page))
118-
list_del(&page->lru);
119-
}
120-
121100
/*
122101
* balloon_page_device - get the b_dev_info descriptor for the balloon device
123102
* that enqueues the given page.
@@ -141,19 +120,29 @@ static inline void balloon_page_insert(struct balloon_dev_info *balloon,
141120
list_add(&page->lru, &balloon->pages);
142121
}
143122

144-
static inline void balloon_page_delete(struct page *page)
145-
{
146-
__ClearPageOffline(page);
147-
list_del(&page->lru);
148-
}
149-
150123
static inline gfp_t balloon_mapping_gfp_mask(void)
151124
{
152125
return GFP_HIGHUSER;
153126
}
154127

155128
#endif /* CONFIG_BALLOON_COMPACTION */
156129

130+
/*
131+
* balloon_page_finalize - prepare a balloon page that was removed from the
132+
* balloon list for release to the page allocator
133+
* @page: page to be released to the page allocator
134+
*
135+
* Caller must ensure that the page is locked.
136+
*/
137+
static inline void balloon_page_finalize(struct page *page)
138+
{
139+
if (IS_ENABLED(CONFIG_BALLOON_COMPACTION)) {
140+
__ClearPageMovable(page);
141+
set_page_private(page, 0);
142+
}
143+
__ClearPageOffline(page);
144+
}
145+
157146
/*
158147
* balloon_page_push - insert a page into a page list.
159148
* @head : pointer to list

mm/balloon_compaction.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ size_t balloon_page_list_dequeue(struct balloon_dev_info *b_dev_info,
9393
if (!trylock_page(page))
9494
continue;
9595

96-
balloon_page_delete(page);
96+
list_del(&page->lru);
97+
balloon_page_finalize(page);
9798
__count_vm_event(BALLOON_DEFLATE);
9899
list_add(&page->lru, pages);
99100
unlock_page(page);

0 commit comments

Comments
 (0)