Skip to content

Commit 5ac9588

Browse files
Yang Shitorvalds
authored andcommitted
mm/migrate: enable returning precise migrate_pages() success count
Under normal circumstances, migrate_pages() returns the number of pages migrated. In error conditions, it returns an error code. When returning an error code, there is no way to know how many pages were migrated or not migrated. Make migrate_pages() return how many pages are demoted successfully for all cases, including when encountering errors. Page reclaim behavior will depend on this in subsequent patches. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Yang Shi <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Signed-off-by: "Huang, Ying" <[email protected]> Suggested-by: Oscar Salvador <[email protected]> [optional parameter] Reviewed-by: Yang Shi <[email protected]> Reviewed-by: Zi Yan <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Wei Xu <[email protected]> Cc: Dan Williams <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: David Rientjes <[email protected]> Cc: Greg Thelen <[email protected]> Cc: Keith Busch <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 884a6e5 commit 5ac9588

File tree

8 files changed

+18
-12
lines changed

8 files changed

+18
-12
lines changed

include/linux/migrate.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ extern int migrate_page(struct address_space *mapping,
4141
struct page *newpage, struct page *page,
4242
enum migrate_mode mode);
4343
extern int migrate_pages(struct list_head *l, new_page_t new, free_page_t free,
44-
unsigned long private, enum migrate_mode mode, int reason);
44+
unsigned long private, enum migrate_mode mode, int reason,
45+
unsigned int *ret_succeeded);
4546
extern struct page *alloc_migration_target(struct page *page, unsigned long private);
4647
extern int isolate_movable_page(struct page *page, isolate_mode_t mode);
4748

@@ -56,7 +57,7 @@ extern int migrate_page_move_mapping(struct address_space *mapping,
5657
static inline void putback_movable_pages(struct list_head *l) {}
5758
static inline int migrate_pages(struct list_head *l, new_page_t new,
5859
free_page_t free, unsigned long private, enum migrate_mode mode,
59-
int reason)
60+
int reason, unsigned int *ret_succeeded)
6061
{ return -ENOSYS; }
6162
static inline struct page *alloc_migration_target(struct page *page,
6263
unsigned long private)

mm/compaction.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2398,7 +2398,7 @@ compact_zone(struct compact_control *cc, struct capture_control *capc)
23982398

23992399
err = migrate_pages(&cc->migratepages, compaction_alloc,
24002400
compaction_free, (unsigned long)cc, cc->mode,
2401-
MR_COMPACTION);
2401+
MR_COMPACTION, NULL);
24022402

24032403
trace_mm_compaction_migratepages(cc->nr_migratepages, err,
24042404
&cc->migratepages);

mm/gup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages,
17721772
if (!list_empty(&movable_page_list)) {
17731773
ret = migrate_pages(&movable_page_list, alloc_migration_target,
17741774
NULL, (unsigned long)&mtc, MIGRATE_SYNC,
1775-
MR_LONGTERM_PIN);
1775+
MR_LONGTERM_PIN, NULL);
17761776
if (ret && !list_empty(&movable_page_list))
17771777
putback_movable_pages(&movable_page_list);
17781778
}

mm/memory-failure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,7 @@ static int __soft_offline_page(struct page *page)
20992099

21002100
if (isolate_page(hpage, &pagelist)) {
21012101
ret = migrate_pages(&pagelist, alloc_migration_target, NULL,
2102-
(unsigned long)&mtc, MIGRATE_SYNC, MR_MEMORY_FAILURE);
2102+
(unsigned long)&mtc, MIGRATE_SYNC, MR_MEMORY_FAILURE, NULL);
21032103
if (!ret) {
21042104
bool release = !huge;
21052105

mm/memory_hotplug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ do_migrate_range(unsigned long start_pfn, unsigned long end_pfn)
14691469
if (nodes_empty(nmask))
14701470
node_set(mtc.nid, nmask);
14711471
ret = migrate_pages(&source, alloc_migration_target, NULL,
1472-
(unsigned long)&mtc, MIGRATE_SYNC, MR_MEMORY_HOTPLUG);
1472+
(unsigned long)&mtc, MIGRATE_SYNC, MR_MEMORY_HOTPLUG, NULL);
14731473
if (ret) {
14741474
list_for_each_entry(page, &source, lru) {
14751475
if (__ratelimit(&migrate_rs)) {

mm/mempolicy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,
10841084

10851085
if (!list_empty(&pagelist)) {
10861086
err = migrate_pages(&pagelist, alloc_migration_target, NULL,
1087-
(unsigned long)&mtc, MIGRATE_SYNC, MR_SYSCALL);
1087+
(unsigned long)&mtc, MIGRATE_SYNC, MR_SYSCALL, NULL);
10881088
if (err)
10891089
putback_movable_pages(&pagelist);
10901090
}
@@ -1338,7 +1338,7 @@ static long do_mbind(unsigned long start, unsigned long len,
13381338
if (!list_empty(&pagelist)) {
13391339
WARN_ON_ONCE(flags & MPOL_MF_LAZY);
13401340
nr_failed = migrate_pages(&pagelist, new_page, NULL,
1341-
start, MIGRATE_SYNC, MR_MEMPOLICY_MBIND);
1341+
start, MIGRATE_SYNC, MR_MEMPOLICY_MBIND, NULL);
13421342
if (nr_failed)
13431343
putback_movable_pages(&pagelist);
13441344
}

mm/migrate.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,8 @@ static inline int try_split_thp(struct page *page, struct page **page2,
14291429
* @mode: The migration mode that specifies the constraints for
14301430
* page migration, if any.
14311431
* @reason: The reason for page migration.
1432+
* @ret_succeeded: Set to the number of pages migrated successfully if
1433+
* the caller passes a non-NULL pointer.
14321434
*
14331435
* The function returns after 10 attempts or if no pages are movable any more
14341436
* because the list has become empty or no retryable pages exist any more.
@@ -1439,7 +1441,7 @@ static inline int try_split_thp(struct page *page, struct page **page2,
14391441
*/
14401442
int migrate_pages(struct list_head *from, new_page_t get_new_page,
14411443
free_page_t put_new_page, unsigned long private,
1442-
enum migrate_mode mode, int reason)
1444+
enum migrate_mode mode, int reason, unsigned int *ret_succeeded)
14431445
{
14441446
int retry = 1;
14451447
int thp_retry = 1;
@@ -1594,6 +1596,9 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page,
15941596
if (!swapwrite)
15951597
current->flags &= ~PF_SWAPWRITE;
15961598

1599+
if (ret_succeeded)
1600+
*ret_succeeded = nr_succeeded;
1601+
15971602
return rc;
15981603
}
15991604

@@ -1663,7 +1668,7 @@ static int do_move_pages_to_node(struct mm_struct *mm,
16631668
};
16641669

16651670
err = migrate_pages(pagelist, alloc_migration_target, NULL,
1666-
(unsigned long)&mtc, MIGRATE_SYNC, MR_SYSCALL);
1671+
(unsigned long)&mtc, MIGRATE_SYNC, MR_SYSCALL, NULL);
16671672
if (err)
16681673
putback_movable_pages(pagelist);
16691674
return err;
@@ -2178,7 +2183,7 @@ int migrate_misplaced_page(struct page *page, struct vm_area_struct *vma,
21782183

21792184
list_add(&page->lru, &migratepages);
21802185
nr_remaining = migrate_pages(&migratepages, *new, NULL, node,
2181-
MIGRATE_ASYNC, MR_NUMA_MISPLACED);
2186+
MIGRATE_ASYNC, MR_NUMA_MISPLACED, NULL);
21822187
if (nr_remaining) {
21832188
if (!list_empty(&migratepages)) {
21842189
list_del(&page->lru);

mm/page_alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8990,7 +8990,7 @@ static int __alloc_contig_migrate_range(struct compact_control *cc,
89908990
cc->nr_migratepages -= nr_reclaimed;
89918991

89928992
ret = migrate_pages(&cc->migratepages, alloc_migration_target,
8993-
NULL, (unsigned long)&mtc, cc->mode, MR_CONTIG_RANGE);
8993+
NULL, (unsigned long)&mtc, cc->mode, MR_CONTIG_RANGE, NULL);
89948994

89958995
/*
89968996
* On -ENOMEM, migrate_pages() bails out right away. It is pointless

0 commit comments

Comments
 (0)