Skip to content

Commit fa81416

Browse files
davidhildenbrandgregkh
authored andcommitted
mm/migrate: remove MIGRATEPAGE_UNMAP
[ Upstream commit 95c2908f1a4fd608b1cdbb5acef3572e5d769e1c ] migrate_folio_unmap() is the only user of MIGRATEPAGE_UNMAP. We want to remove MIGRATEPAGE_* completely. It's rather weird to have a generic MIGRATEPAGE_UNMAP, documented to be returned from address-space callbacks, when it's only used for an internal helper. Let's start by having only a single "success" return value for migrate_folio_unmap() -- 0 -- by moving the "folio was already freed" check into the single caller. There is a remaining comment for PG_isolated, which we renamed to PG_movable_ops_isolated recently and forgot to update. While we might still run into that case with zsmalloc, it's something we want to get rid of soon. So let's just focus that optimization on real folios only for now by excluding movable_ops pages. Note that concurrent freeing can happen at any time and this "already freed" check is not relevant for correctness. [[email protected]: no need to pass "reason" to migrate_folio_unmap(), per Lance] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: David Hildenbrand <[email protected]> Reviewed-by: Zi Yan <[email protected]> Reviewed-by: Lance Yang <[email protected]> Cc: Alistair Popple <[email protected]> Cc: Al Viro <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Benjamin LaHaise <[email protected]> Cc: Byungchul Park <[email protected]> Cc: Chris Mason <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Dave Kleikamp <[email protected]> Cc: David Sterba <[email protected]> Cc: Eugenio Pé rez <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Gregory Price <[email protected]> Cc: "Huang, Ying" <[email protected]> Cc: Jan Kara <[email protected]> Cc: Jason Wang <[email protected]> Cc: Jerrin Shaji George <[email protected]> Cc: Josef Bacik <[email protected]> Cc: Joshua Hahn <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Mathew Brost <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: "Michael S. Tsirkin" <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Muchun Song <[email protected]> Cc: Nicholas Piggin <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: Rakie Kim <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Cc: Xuan Zhuo <[email protected]> Cc: Dave Kleikamp <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Stable-dep-of: 4ba5a8a7faa6 ("vmw_balloon: indicate success when effectively deflating during migration") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7de6d6d commit fa81416

2 files changed

Lines changed: 22 additions & 24 deletions

File tree

include/linux/migrate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ struct migration_target_control;
1818
* - zero on page migration success;
1919
*/
2020
#define MIGRATEPAGE_SUCCESS 0
21-
#define MIGRATEPAGE_UNMAP 1
2221

2322
/**
2423
* struct movable_operations - Driver page migration

mm/migrate.c

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ static void migrate_folio_done(struct folio *src,
11891189
static int migrate_folio_unmap(new_folio_t get_new_folio,
11901190
free_folio_t put_new_folio, unsigned long private,
11911191
struct folio *src, struct folio **dstp, enum migrate_mode mode,
1192-
enum migrate_reason reason, struct list_head *ret)
1192+
struct list_head *ret)
11931193
{
11941194
struct folio *dst;
11951195
int rc = -EAGAIN;
@@ -1198,16 +1198,6 @@ static int migrate_folio_unmap(new_folio_t get_new_folio,
11981198
bool locked = false;
11991199
bool dst_locked = false;
12001200

1201-
if (folio_ref_count(src) == 1) {
1202-
/* Folio was freed from under us. So we are done. */
1203-
folio_clear_active(src);
1204-
folio_clear_unevictable(src);
1205-
/* free_pages_prepare() will clear PG_isolated. */
1206-
list_del(&src->lru);
1207-
migrate_folio_done(src, reason);
1208-
return MIGRATEPAGE_SUCCESS;
1209-
}
1210-
12111201
dst = get_new_folio(src, private);
12121202
if (!dst)
12131203
return -ENOMEM;
@@ -1297,7 +1287,7 @@ static int migrate_folio_unmap(new_folio_t get_new_folio,
12971287

12981288
if (unlikely(page_has_movable_ops(&src->page))) {
12991289
__migrate_folio_record(dst, old_page_state, anon_vma);
1300-
return MIGRATEPAGE_UNMAP;
1290+
return 0;
13011291
}
13021292

13031293
/*
@@ -1327,7 +1317,7 @@ static int migrate_folio_unmap(new_folio_t get_new_folio,
13271317

13281318
if (!folio_mapped(src)) {
13291319
__migrate_folio_record(dst, old_page_state, anon_vma);
1330-
return MIGRATEPAGE_UNMAP;
1320+
return 0;
13311321
}
13321322

13331323
out:
@@ -1870,14 +1860,27 @@ static int migrate_pages_batch(struct list_head *from,
18701860
continue;
18711861
}
18721862

1863+
/*
1864+
* If we are holding the last folio reference, the folio
1865+
* was freed from under us, so just drop our reference.
1866+
*/
1867+
if (likely(!page_has_movable_ops(&folio->page)) &&
1868+
folio_ref_count(folio) == 1) {
1869+
folio_clear_active(folio);
1870+
folio_clear_unevictable(folio);
1871+
list_del(&folio->lru);
1872+
migrate_folio_done(folio, reason);
1873+
stats->nr_succeeded += nr_pages;
1874+
stats->nr_thp_succeeded += is_thp;
1875+
continue;
1876+
}
1877+
18731878
rc = migrate_folio_unmap(get_new_folio, put_new_folio,
1874-
private, folio, &dst, mode, reason,
1875-
ret_folios);
1879+
private, folio, &dst, mode, ret_folios);
18761880
/*
18771881
* The rules are:
1878-
* Success: folio will be freed
1879-
* Unmap: folio will be put on unmap_folios list,
1880-
* dst folio put on dst_folios list
1882+
* 0: folio will be put on unmap_folios list,
1883+
* dst folio put on dst_folios list
18811884
* -EAGAIN: stay on the from list
18821885
* -ENOMEM: stay on the from list
18831886
* Other errno: put on ret_folios list
@@ -1927,11 +1930,7 @@ static int migrate_pages_batch(struct list_head *from,
19271930
thp_retry += is_thp;
19281931
nr_retry_pages += nr_pages;
19291932
break;
1930-
case MIGRATEPAGE_SUCCESS:
1931-
stats->nr_succeeded += nr_pages;
1932-
stats->nr_thp_succeeded += is_thp;
1933-
break;
1934-
case MIGRATEPAGE_UNMAP:
1933+
case 0:
19351934
list_move_tail(&folio->lru, &unmap_folios);
19361935
list_add_tail(&dst->lru, &dst_folios);
19371936
break;

0 commit comments

Comments
 (0)