Re: [RFC][PATCH 07/13] mm/migrate: make migrate_pages() return nr_succeeded

2021-02-09 Thread Dave Hansen
On 1/29/21 1:04 PM, Yang Shi wrote:
>> @@ -1527,7 +1527,7 @@ retry:
>> nr_succeeded += nr_subpages;
> It seems the above line is missed. The THP accounting change was
> merged in v5.9 before I submitted this patch.

Thanks for reporting that.  Ying found and reported that too.  It's
fixed up in my most recent version.



Re: [RFC][PATCH 07/13] mm/migrate: make migrate_pages() return nr_succeeded

2021-01-29 Thread Yang Shi
On Mon, Jan 25, 2021 at 4:41 PM Dave Hansen  wrote:
>
>
> From: Yang Shi 
>
> The migrate_pages() returns the number of pages that were not migrated,
> or an error code.  When returning an error code, there is no way to know
> how many pages were migrated or not migrated.
>
> In the following patch, migrate_pages() is used to demote pages to PMEM
> node, we need account how many pages are reclaimed (demoted) since page
> reclaim behavior depends on this.  Add *nr_succeeded parameter to make
> migrate_pages() return how many pages are demoted successfully for all
> cases.
>
> Signed-off-by: Yang Shi 
> Signed-off-by: Dave Hansen 
> Cc: David Rientjes 
> Cc: Huang Ying 
> Cc: Dan Williams 
> Cc: David Hildenbrand 
> Cc: osalvador 
> ---
>
>  b/include/linux/migrate.h |5 +++--
>  b/mm/compaction.c |3 ++-
>  b/mm/gup.c|4 +++-
>  b/mm/memory-failure.c |4 +++-
>  b/mm/memory_hotplug.c |4 +++-
>  b/mm/mempolicy.c  |8 ++--
>  b/mm/migrate.c|   17 ++---
>  b/mm/page_alloc.c |9 ++---
>  8 files changed, 36 insertions(+), 18 deletions(-)
>
> diff -puN include/linux/migrate.h~migrate_pages-add-success-return 
> include/linux/migrate.h
> --- a/include/linux/migrate.h~migrate_pages-add-success-return  2021-01-25 
> 16:23:12.931866701 -0800
> +++ b/include/linux/migrate.h   2021-01-25 16:23:12.954866701 -0800
> @@ -40,7 +40,8 @@ extern int migrate_page(struct address_s
> struct page *newpage, struct page *page,
> enum migrate_mode mode);
>  extern int migrate_pages(struct list_head *l, new_page_t new, free_page_t 
> free,
> -   unsigned long private, enum migrate_mode mode, int reason);
> +   unsigned long private, enum migrate_mode mode, int reason,
> +   unsigned int *nr_succeeded);
>  extern struct page *alloc_migration_target(struct page *page, unsigned long 
> private);
>  extern int isolate_movable_page(struct page *page, isolate_mode_t mode);
>  extern void putback_movable_page(struct page *page);
> @@ -58,7 +59,7 @@ extern int migrate_page_move_mapping(str
>  static inline void putback_movable_pages(struct list_head *l) {}
>  static inline int migrate_pages(struct list_head *l, new_page_t new,
> free_page_t free, unsigned long private, enum migrate_mode 
> mode,
> -   int reason)
> +   int reason, unsigned int *nr_succeeded)
> { return -ENOSYS; }
>  static inline struct page *alloc_migration_target(struct page *page,
> unsigned long private)
> diff -puN mm/compaction.c~migrate_pages-add-success-return mm/compaction.c
> --- a/mm/compaction.c~migrate_pages-add-success-return  2021-01-25 
> 16:23:12.933866701 -0800
> +++ b/mm/compaction.c   2021-01-25 16:23:12.956866701 -0800
> @@ -2199,6 +2199,7 @@ compact_zone(struct compact_control *cc,
> unsigned long last_migrated_pfn;
> const bool sync = cc->mode != MIGRATE_ASYNC;
> bool update_cached;
> +   unsigned int nr_succeeded = 0;
>
> /*
>  * These counters track activities during zone compaction.  Initialize
> @@ -2317,7 +2318,7 @@ compact_zone(struct compact_control *cc,
>
> err = migrate_pages(&cc->migratepages, compaction_alloc,
> compaction_free, (unsigned long)cc, cc->mode,
> -   MR_COMPACTION);
> +   MR_COMPACTION, &nr_succeeded);
>
> trace_mm_compaction_migratepages(cc->nr_migratepages, err,
> &cc->migratepages);
> diff -puN mm/gup.c~migrate_pages-add-success-return mm/gup.c
> --- a/mm/gup.c~migrate_pages-add-success-return 2021-01-25 16:23:12.935866701 
> -0800
> +++ b/mm/gup.c  2021-01-25 16:23:12.957866701 -0800
> @@ -1599,6 +1599,7 @@ static long check_and_migrate_cma_pages(
> unsigned long step;
> bool drain_allow = true;
> bool migrate_allow = true;
> +   unsigned int nr_succeeded = 0;
> LIST_HEAD(cma_page_list);
> long ret = nr_pages;
> struct migration_target_control mtc = {
> @@ -1654,7 +1655,8 @@ check_again:
> put_page(pages[i]);
>
> if (migrate_pages(&cma_page_list, alloc_migration_target, 
> NULL,
> -   (unsigned long)&mtc, MIGRATE_SYNC, MR_CONTIG_RANGE)) {
> +   (unsigned long)&mtc, MIGRATE_SYNC, MR_CONTIG_RANGE,
> + &nr_succeeded)) {
> /*
>  * some of the pages failed migration. Do 
> get_user_pages
>  * without migration.
> diff -puN mm/memory-failure.c~migrate_pages-add-success-return 
> mm/memory-failure.c
> --- a/mm/memory-failure.c~migrate_pages-add-success-return  2021-01-25 
> 16:23:12.939866701 -0800
> +++ b/mm/memory-failure.c 

[RFC][PATCH 07/13] mm/migrate: make migrate_pages() return nr_succeeded

2021-01-25 Thread Dave Hansen


From: Yang Shi 

The migrate_pages() returns the number of pages that were not migrated,
or an error code.  When returning an error code, there is no way to know
how many pages were migrated or not migrated.

In the following patch, migrate_pages() is used to demote pages to PMEM
node, we need account how many pages are reclaimed (demoted) since page
reclaim behavior depends on this.  Add *nr_succeeded parameter to make
migrate_pages() return how many pages are demoted successfully for all
cases.

Signed-off-by: Yang Shi 
Signed-off-by: Dave Hansen 
Cc: David Rientjes 
Cc: Huang Ying 
Cc: Dan Williams 
Cc: David Hildenbrand 
Cc: osalvador 
---

 b/include/linux/migrate.h |5 +++--
 b/mm/compaction.c |3 ++-
 b/mm/gup.c|4 +++-
 b/mm/memory-failure.c |4 +++-
 b/mm/memory_hotplug.c |4 +++-
 b/mm/mempolicy.c  |8 ++--
 b/mm/migrate.c|   17 ++---
 b/mm/page_alloc.c |9 ++---
 8 files changed, 36 insertions(+), 18 deletions(-)

diff -puN include/linux/migrate.h~migrate_pages-add-success-return 
include/linux/migrate.h
--- a/include/linux/migrate.h~migrate_pages-add-success-return  2021-01-25 
16:23:12.931866701 -0800
+++ b/include/linux/migrate.h   2021-01-25 16:23:12.954866701 -0800
@@ -40,7 +40,8 @@ extern int migrate_page(struct address_s
struct page *newpage, struct page *page,
enum migrate_mode mode);
 extern int migrate_pages(struct list_head *l, new_page_t new, free_page_t free,
-   unsigned long private, enum migrate_mode mode, int reason);
+   unsigned long private, enum migrate_mode mode, int reason,
+   unsigned int *nr_succeeded);
 extern struct page *alloc_migration_target(struct page *page, unsigned long 
private);
 extern int isolate_movable_page(struct page *page, isolate_mode_t mode);
 extern void putback_movable_page(struct page *page);
@@ -58,7 +59,7 @@ extern int migrate_page_move_mapping(str
 static inline void putback_movable_pages(struct list_head *l) {}
 static inline int migrate_pages(struct list_head *l, new_page_t new,
free_page_t free, unsigned long private, enum migrate_mode mode,
-   int reason)
+   int reason, unsigned int *nr_succeeded)
{ return -ENOSYS; }
 static inline struct page *alloc_migration_target(struct page *page,
unsigned long private)
diff -puN mm/compaction.c~migrate_pages-add-success-return mm/compaction.c
--- a/mm/compaction.c~migrate_pages-add-success-return  2021-01-25 
16:23:12.933866701 -0800
+++ b/mm/compaction.c   2021-01-25 16:23:12.956866701 -0800
@@ -2199,6 +2199,7 @@ compact_zone(struct compact_control *cc,
unsigned long last_migrated_pfn;
const bool sync = cc->mode != MIGRATE_ASYNC;
bool update_cached;
+   unsigned int nr_succeeded = 0;
 
/*
 * These counters track activities during zone compaction.  Initialize
@@ -2317,7 +2318,7 @@ compact_zone(struct compact_control *cc,
 
err = migrate_pages(&cc->migratepages, compaction_alloc,
compaction_free, (unsigned long)cc, cc->mode,
-   MR_COMPACTION);
+   MR_COMPACTION, &nr_succeeded);
 
trace_mm_compaction_migratepages(cc->nr_migratepages, err,
&cc->migratepages);
diff -puN mm/gup.c~migrate_pages-add-success-return mm/gup.c
--- a/mm/gup.c~migrate_pages-add-success-return 2021-01-25 16:23:12.935866701 
-0800
+++ b/mm/gup.c  2021-01-25 16:23:12.957866701 -0800
@@ -1599,6 +1599,7 @@ static long check_and_migrate_cma_pages(
unsigned long step;
bool drain_allow = true;
bool migrate_allow = true;
+   unsigned int nr_succeeded = 0;
LIST_HEAD(cma_page_list);
long ret = nr_pages;
struct migration_target_control mtc = {
@@ -1654,7 +1655,8 @@ check_again:
put_page(pages[i]);
 
if (migrate_pages(&cma_page_list, alloc_migration_target, NULL,
-   (unsigned long)&mtc, MIGRATE_SYNC, MR_CONTIG_RANGE)) {
+   (unsigned long)&mtc, MIGRATE_SYNC, MR_CONTIG_RANGE,
+ &nr_succeeded)) {
/*
 * some of the pages failed migration. Do get_user_pages
 * without migration.
diff -puN mm/memory-failure.c~migrate_pages-add-success-return 
mm/memory-failure.c
--- a/mm/memory-failure.c~migrate_pages-add-success-return  2021-01-25 
16:23:12.939866701 -0800
+++ b/mm/memory-failure.c   2021-01-25 16:23:12.959866701 -0800
@@ -1783,6 +1783,7 @@ static int __soft_offline_page(struct pa
unsigned long pfn = page_to_pfn(page);
struct page *hpage = compound_head(page);
char const *msg_page[] = {"page", "hugepage"};
+