mm: correct return value of migrate_pages() and migrate_huge_pages()
Subsystems (4)
PATCH RESEND v3 1/4 mm: correct return value of migrate_pages() and migrate_huge_pages()
migrate_pages() should return number of pages not migrated or error code. When unmap_and_move return -EAGAIN, outer loop is re-execution without initialising nr_failed. This makes nr_failed over-counted.
So this patch correct it by initialising nr_failed in outer loop.
migrate_huge_pages() is identical case as migrate_pages()
---
[Patch 2/4]: add "Acked-by: Michal Nazarewicz <[email protected]>" [Patch 3/4]: commit log is changed according to Michal Nazarewicz's suggestion. There is no other change from v2.
Just resend as ping for Andrew.
mm/migrate.c +2 -0
@@ -982,6 +982,7 @@ int migrate_pages(struct list_head *from,for (pass =0 ; pass <10 && retry; pass++) { retry =0 ; + nr_failed =0 ;list_for_each_entry_safe (page, page2, from, lru) {cond_resched ();
@@ -1029,6 +1030,7 @@ int migrate_huge_pages(struct list_head *from,for (pass =0 ; pass <10 && retry; pass++) { retry =0 ; + nr_failed =0 ;list_for_each_entry_safe (page, page2, from, lru) {cond_resched ();
Signature · 7 lines
1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH RESEND v3 2/4 mm: fix possible incorrect return value of migrate_pages() syscall
do_migrate_pages() can return the number of pages not migrated. Because migrate_pages() syscall return this value directly, migrate_pages() syscall may return the number of pages not migrated. In fail case in migrate_pages() syscall, we should return error value. So change err to -EBUSY
Additionally, Correct comment above do_migrate_pages()
mm/mempolicy.c +3 -1
@@ -948,7 +948,7 @@ static int migrate_to_node(struct mm_struct *mm, int source, int dest,* Move pages between the two nodesets so as to preserve the physical * layout as much as possible. * -* Returns the number of page that could not be moved. +* Returns error or the number of pages not migrated. */ int do_migrate_pages (struct mm_struct *mm,const nodemask_t *from,const nodemask_t *to,int flags)
@@ -1382,6 +1382,8 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode, err =do_migrate_pages (mm, old, new,capable (CAP_SYS_NICE ) ?MPOL_MF_MOVE_ALL :MPOL_MF_MOVE ); +if (err >0 ) + err = -EBUSY ;mmput (mm); out:
Signature · 7 lines
1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH RESEND v3 3/4 mm: fix return value in __alloc_contig_migrate_range()
In reply to Joonsoo Kimmigrate_pages() can return positive value while at the same time emptying the list of pages it was called with. Such situation means that it went through all the pages on the list some of which failed to be migrated.
If that happens, __alloc_contig_migrate_range()'s loop may finish without "++tries == 5" never being checked. This in turn means that at the end of the function, ret may have a positive value, which should be treated as an error.
This patch changes __alloc_contig_migrate_range() so that the return statement converts positive ret value into -EBUSY error.
mm/page_alloc.c +1 -2
@@ -5673,7 +5673,6 @@ static int __alloc_contig_migrate_range(unsigned long start, unsigned long end) } tries =0 ; }else if (++tries ==5 ) { - ret = ret <0 ? ret : -EBUSY ;break ; }
@@ -5683,7 +5682,7 @@ static int __alloc_contig_migrate_range(unsigned long start, unsigned long end) }putback_lru_pages (&cc.migratepages); -return ret >0 ?0 : ret; +return ret <=0 ? ret : -EBUSY ; }/*
Signature · 7 lines
1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH RESEND v3 4/4 mm: fix possible incorrect return value of move_pages() syscall
In reply to Joonsoo Kimmove_pages() syscall may return success in case that do_move_page_to_node_array return positive value which means migration failed. This patch changes return value of do_move_page_to_node_array
for not returning positive value. It can fix the problem.
mm/migrate.c +1 -1
@@ -1172,7 +1172,7 @@ set_status: }up_read (&mm->mmap_sem); -return err; +return err >0 ? -EBUSY : err; }/*
Signature · 7 lines
1.7.9.5 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RESEND PATCH 4/4 v3] mm: fix possible incorrect return value of move_pages() syscall
Quoted 2 lines · Joonsoo Kim
move_pages()syscall may return success in case thatdo_move_page_to_node_arrayreturn positive value which means migration failed.
Nope. It only means that the migration for some pages has failed. This may still be considered successful for the app if it moves 10000 pages and one failed.
This patch would break the move_pages() syscall because an error code return from do_move_pages_to_node_array() will cause the status byte for each page move to not be updated anymore. Application will not be able to tell anymore which pages were successfully moved and which are not.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RESEND PATCH 2/4 v3] mm: fix possible incorrect return value of migrate_pages() syscall
In reply to Joonsoo KimQuoted 5 lines · Joonsoo Kim
do_migrate_pages()can return the number of pages not migrated. Becausemigrate_pages()syscall return this value directly,migrate_pages()syscall may return the number of pages not migrated. In fail case inmigrate_pages()syscall, we should return error value. So change err to-EBUSY
Lets leave this alone. This would change the migrate_pages semantics because a successful move of N out of M pages would be marked as a total failure although pages were in fact moved.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RESEND PATCH 4/4 v3] mm: fix possible incorrect return value of move_pages() syscall
In reply to Christoph Lameter2012/7/28 Christoph Lameter <[email protected]>:
Quoted 5 lines · Joonsoo Kim
Quoted 3 lines
move_pages()syscall may return success in case thatdo_move_page_to_node_arrayreturn positive value which means migration failed.
Quoted 8 lines
Nope. It only means that the migration for some pages has failed. This may still be considered successful for the app if it moves 10000 pages and one failed.
This patch would break the
move_pages()syscall because an error code return fromdo_move_pages_to_node_array()will cause the status byte for each page move to not be updated anymore. Application will not be able to tell anymore which pages were successfully moved and which are not.
In case of returning non-zero, valid status is not required according to man page.
So, this patch would not break the move_pages() syscall. But, I agree that returning positive value only means that the migration for some pages has failed.
This is my mistake, so please drop this patch.
Thanks for review.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RESEND PATCH 2/4 v3] mm: fix possible incorrect return value of migrate_pages() syscall
In reply to Christoph Lameter2012/7/28 Christoph Lameter <[email protected]>:
Quoted 8 lines · Joonsoo Kim
Quoted 6 lines
do_migrate_pages()can return the number of pages not migrated. Becausemigrate_pages()syscall return this value directly,migrate_pages()syscall may return the number of pages not migrated. In fail case inmigrate_pages()syscall, we should return error value. So change err to-EBUSY
Quoted 4 lines
Lets leave this alone. This would change the
migrate_pagessemantics because a successful move of N out of M pages would be marked as a total failure although pages were in fact moved.
Okay.
Then, do we need to fix man-page of migrate_pages() syscall? According to man-page, only returning 0 or -1 is valid. Without this patch, it can return positive value.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RESEND PATCH 4/4 v3] mm: fix possible incorrect return value of move_pages() syscall
In reply to JoonSoo KimQuoted 10 lines · JoonSoo Kim
2012/7/28 Christoph Lameter <[email protected]>:
Quoted 9 lines · Joonsoo Kim
Quoted 3 lines
move_pages()syscall may return success in case thatdo_move_page_to_node_arrayreturn positive value which means migration failed.Nope. It only means that the migration for some pages has failed. This may still be considered successful for the app if it moves 10000 pages and one failed.
Quoted 7 lines
Quoted 4 lines
This patch would break the
move_pages()syscall because an error code return fromdo_move_pages_to_node_array()will cause the status byte for each page move to not be updated anymore. Application will not be able to tell anymore which pages were successfully moved and which are not.In case of returning non-zero, valid status is not required according to man page.
Cannot find a statement like that in the man page. The return code description is incorrect. It should that that is returns the number of pages not moved otherwise an error code (Michael please fix the manpage).
Quoted 1 line
So, this patch would not break the
move_pages()syscall.
It changes the way the system call is behaving right now.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RESEND PATCH 2/4 v3] mm: fix possible incorrect return value of migrate_pages() syscall
In reply to JoonSoo KimQuoted 14 lines · JoonSoo Kim
2012/7/28 Christoph Lameter <[email protected]>:
Quoted 8 lines · Joonsoo Kim
Quoted 6 lines
do_migrate_pages()can return the number of pages not migrated. Becausemigrate_pages()syscall return this value directly,migrate_pages()syscall may return the number of pages not migrated. In fail case inmigrate_pages()syscall, we should return error value. So change err to-EBUSYQuoted 4 lines
Lets leave this alone. This would change the
migrate_pagessemantics because a successful move of N out of M pages would be marked as a total failure although pages were in fact moved.
Quoted 4 lines
Okay.
Then, do we need to fix man-page ofmigrate_pages()syscall? According to man-page, only returning 0 or -1 is valid. Without this patch, it can return positive value.
Yes the manpage needs updating to say that it can return the number of pages not migrated.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RESEND PATCH 4/4 v3] mm: fix possible incorrect return value of move_pages() syscall
In reply to Christoph Lameter2012/7/31 Christoph Lameter <[email protected]>:
Quoted 17 lines · JoonSoo Kim
Quoted 16 lines
2012/7/28 Christoph Lameter <[email protected]>:
Quoted 13 lines · Joonsoo Kim
Quoted 3 lines
move_pages()syscall may return success in case thatdo_move_page_to_node_arrayreturn positive value which means migration failed.Nope. It only means that the migration for some pages has failed. This may still be considered successful for the app if it moves 10000 pages and one failed.
This patch would break the
move_pages()syscall because an error code return fromdo_move_pages_to_node_array()will cause the status byte for each page move to not be updated anymore. Application will not be able to tell anymore which pages were successfully moved and which are not.
Quoted 6 lines
Quoted 2 lines
In case of returning non-zero, valid status is not required according to man page.
Cannot find a statement like that in the man page. The return code description is incorrect. It should that that is returns the number of pages not moved otherwise an error code (Michael please fix the manpage).
In man page, there is following statement.
"status is an array of integers that return the status of each page. The array only contains valid values if move_pages() did not return an error."
And current implementation of move_pages() syscall doesn't return the number of pages not moved, just return 0 when it encounter some failed pages. So, if u want to fix the man page, u should fix do_pages_move() first.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RESEND PATCH 4/4 v3] mm: fix possible incorrect return value of move_pages() syscall
Quoted 7 lines · JoonSoo Kim
In man page, there is following statement.
"status is an array of integers that return the status of each page. The array only contains valid values ifmove_pages()did not return an error."And current implementation of
move_pages()syscall doesn't return the number of pages not moved, just return 0 when it encounter some failed pages. So, if u want to fix the man page, u should fixdo_pages_move()first.
Hmm... Yeah actually that is sufficient since the status is readily obtainable from the status array. It would be better though if the function would return the number of pages not moved in the same way as migrate_pages().
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RESEND PATCH 4/4 v3] mm: fix possible incorrect return value of move_pages() syscall
In reply to Christoph LameterQuoted 17 lines · Christoph Lameter
Quoted 15 lines · JoonSoo Kim
2012/7/28 Christoph Lameter <[email protected]>:
Quoted 13 lines · Joonsoo Kim
Quoted 3 lines
move_pages()syscall may return success in case thatdo_move_page_to_node_arrayreturn positive value which means migration failed.Nope. It only means that the migration for some pages has failed. This may still be considered successful for the app if it moves 10000 pages and one failed.
This patch would break the
move_pages()syscall because an error code return fromdo_move_pages_to_node_array()will cause the status byte for each page move to not be updated anymore. Application will not be able to tell anymore which pages were successfully moved and which are not.
Quoted 6 lines
Quoted 2 lines
In case of returning non-zero, valid status is not required according to man page.
Cannot find a statement like that in the man page. The return code description is incorrect. It should that that is returns the number of pages not moved otherwise an error code (Michael please fix the manpage).
Hi Christoph,
Is the patch below acceptable? (I've attached the complete page as well.)
See you in San Diego (?),
Michael
man2/migrate_pages.2 +0 -0
@@ -29,7 +29,7 @@ migrate_pages \- move all pages in a process to
another set of nodes
Link with \fI\-lnuma\fP.
.SH DESCRIPTION
.BR migrate_pages ()
-moves all pages of the process
+attempts to move all pages of the process
.I pid
that are in memory nodes
.I old_nodes
@@ -87,7 +87,8 @@ privilege.
.SH "RETURN VALUE"
On success
.BR migrate_pages ()
-returns zero.
+returns the number of pages that cold not be moved
+(i.e., a return of zero means that all pages were successfully moved).
On error, it returns \-1, and sets
.I errno
to indicate the error.
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Author of "The Linux Programming Interface", http://blog.man7.org/
Re: [RESEND PATCH 4/4 v3] mm: fix possible incorrect return value of move_pages() syscall
Quoted 1 line · Michael Kerrisk
Is the patch below acceptable? (I've attached the complete page as well.)
Yes looks good.
Quoted 1 line
See you in San Diego (?),
Yup. I will be there too.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [RESEND PATCH 4/4 v3] mm: fix possible incorrect return value of move_pages() syscall
Quoted 5 lines · Christoph Lameter
Quoted 1 line · Michael Kerrisk
Is the patch below acceptable? (I've attached the complete page as well.)
Yes looks good.
Thanks for checking it!
Quoted 3 lines
Quoted 1 line
See you in San Diego (?),
Yup. I will be there too.
See you then!
Cheers,
Michael
Signature · 9 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Author of "The Linux Programming Interface", http://blog.man7.org/ -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>