mm: correct return value of migrate_pages()
Subsystems (4)
PATCH 1/3 mm: correct return value of migrate_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.
mm/migrate.c +1 -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 ();
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 2/3 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 -EIO
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 = -EIO ;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 3/3 mm: fix return value in __alloc_contig_migrate_range()
In reply to Joonsoo Kimmigrate_pages() would return positive value in some failure case, so 'ret > 0 ? 0 : ret' may be wrong.
This fix it and remove one dead statement.
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 1/1 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
@@ -1171,7 +1171,7 @@ set_status: }up_read (&mm->mmap_sem); -return err; +return err >0 ? -EIO : 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>
Quoted 3 lines · Joonsoo Kim
migrate_pages()should return number of pages not migrated or error code. Whenunmap_and_movereturn-EAGAIN, outer loop is re-execution without initialisingnr_failed. This makesnr_failedover-counted.
The itention of the nr_failed was only to give an indication as to how many attempts where made. The failed pages where on a separate queue that seems to have vanished.
Quoted 1 line
So this patch correct it by initialising
nr_failedin outer loop.
Well yea it makes sense since retry is initialized there as well.
--
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: [PATCH 2/3] mm: fix possible incorrect return value of migrate_pages() syscall
In reply to Joonsoo KimOn Tue, 17 Jul 2012, Joonsoo Kim wrote
Quoted 5 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-EIO
Pages are not migrated because they are busy not because there is an error. So lets return EBUSY.
--
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: [PATCH 3/3] mm: fix return value in __alloc_contig_migrate_range()
In reply to Joonsoo KimQuoted 3 lines · Joonsoo Kim
migrate_pages()would return positive value in some failure case, so 'ret > 0 ? 0 : ret' may be wrong.
This fix it and remove one dead statement.
--
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: [PATCH 4] mm: fix possible incorrect return value of move_pages() syscall
In reply to Joonsoo KimQuoted 15 lines · Joonsoo Kim
move_pages()syscall may return success in case thatdo_move_page_to_node_arrayreturn positive value which means migration failed. This patch changes return value ofdo_move_page_to_node_array
for not returning positive value. It can fix the problem.Signed-off-by Joonsoo Kim <[email protected]>Cc Brice Goglin <[email protected]>Cc Christoph Lameter <[email protected]>Cc Minchan Kim <[email protected]>mm/migrate.c +0
-0
mm/migrate.c set_status: · line 1175
Quoted 6 lines
mm/migrate.c +1
-1@@ -1171,7 +1171,7 @@ set_status: }up_read (&mm->mmap_sem); -return err; +return err >0 ? -EIO : err; }
Please use EBUSY.
--
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>
2012/7/17 Christoph Lameter <[email protected]>:
Quoted 10 lines · Joonsoo Kim
Quoted 4 lines
migrate_pages()should return number of pages not migrated or error code. Whenunmap_and_movereturn-EAGAIN, outer loop is re-execution without initialisingnr_failed. This makesnr_failedover-counted.The itention of the
nr_failedwas only to give an indication as to how many attempts where made. The failed pages where on a separate queue that seems to have vanished.
Quoted 5 lines
Quoted 1 line
So this patch correct it by initialising
nr_failedin outer loop.Well yea it makes sense since retry is initialized there as well.
Thanks for comment.
Additinally, I find that migrate_huge_pages() is needed identical fix as migrate_pages().
@@ -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();When I resend with this, could I include "Acked-by: Christoph Lameter <[email protected]>"?
--
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>
Quoted 10 lines · JoonSoo Kim
for (pass = 0; pass < 10 && retry; pass++) { retry = 0;+
nr_failed= 0;list_for_each_entry_safe(page, page2, from, lru) { cond_resched();When I resend with this, could I include "Acked-by: Christoph Lameter <[email protected]>"?
Sure.
--
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>
Quoted 8 lines · Joonsoo Kim
migrate_pages()should return number of pages not migrated or error code. Whenunmap_and_movereturn-EAGAIN, outer loop is re-execution without initialisingnr_failed. This makesnr_failedover-counted.So this patch correct it by initialising
nr_failedin outer loop.Signed-off-by Joonsoo Kim <[email protected]>Cc Christoph Lameter <[email protected]>
Actually, it makes me wonder if there is any code that uses this information. If not, it would be best in my opinion to make it return zero or negative error code, but that would have to be checked.
Quoted 12 lines
mm/migrate.c +1
-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 ();
Signature · 4 lines
Best regards, _ _ .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michal "mina86" Nazarewicz (o o) ooo +-<mina86-mina86.com>-<jid:mina86-jabber.org>--ooO--(_)--Ooo--
Re: [PATCH 2/3] mm: fix possible incorrect return value of migrate_pages() syscall
In reply to Joonsoo KimQuoted 11 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-EIOAdditionally, Correct comment above
do_migrate_pages()Signed-off-by Joonsoo Kim <[email protected]>Cc Sasha Levin <[email protected]>Cc Christoph Lameter <[email protected]>
Quoted 22 lines
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 = -EIO ;mmput (mm); out:
Signature · 4 lines
Best regards, _ _ .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michal "mina86" Nazarewicz (o o) ooo +-<mina86-mina86.com>-<jid:mina86-jabber.org>--ooO--(_)--Ooo--
Re: [PATCH 3/3] mm: fix return value in __alloc_contig_migrate_range()
In reply to Joonsoo KimQuoted 9 lines · Joonsoo Kim
migrate_pages()would return positive value in some failure case, so 'ret > 0 ? 0 : ret' may be wrong.
This fix it and remove one dead statement.Signed-off-by Joonsoo Kim <[email protected]>Cc Michal Nazarewicz <[email protected]>Cc Marek Szyprowski <[email protected]>Cc Minchan Kim <[email protected]>Cc Christoph Lameter <[email protected]>
Have you actually encountered this problem? If migrate_pages() fails with a positive value, the code that you are removing kicks in and -EBUSY is assigned to ret (now that I look at it, I think that in the current code the "return ret > 0 ? 0 : ret;" statement could be reduced to "return ret;"). Your code seems to be cleaner, but the commit message does not look accurate to me.
Quoted 21 lines
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 · 4 lines
Best regards, _ _ .o. | Liege of Serenly Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michal "mina86" Nazarewicz (o o) ooo +-<mina86-mina86.com>-<jid:mina86-jabber.org>--ooO--(_)--Ooo--
2012/7/17 Michal Nazarewicz <[email protected]>:
Quoted 1 line
Thanks.
Quoted 3 lines
Actually, it makes me wonder if there is any code that uses this information. If not, it would be best in my opinion to make it return zero or negative error code, but that would have to be checked.
I think that, too.
I looked at every callsites for migrate_pages() and there is no place which really need fail count.
This function sometimes makes caller error-prone,
so I think changing return value is preferable.
How do you think, Christoph?
--
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: [PATCH 2/3] mm: fix possible incorrect return value of migrate_pages() syscall
In reply to Michal Nazarewicz2012/7/17 Michal Nazarewicz <[email protected]>:
Quoted 7 lines
Quoted 6 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-EIO
Quoted 7 lines
Quoted 5 lines
Additionally, Correct comment above
do_migrate_pages()Signed-off-by Joonsoo Kim <[email protected]>Cc Sasha Levin <[email protected]>Cc Christoph Lameter <[email protected]>
Thanks.
When I resend with changing -EIO to -EBUSY,
could I include "Acked-by: Michal Nazarewicz <[email protected]>"?
--
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>
Quoted 11 lines · JoonSoo Kim
Quoted 3 lines
Actually, it makes me wonder if there is any code that uses this information. If not, it would be best in my opinion to make it return zero or negative error code, but that would have to be checked.
I think that, too.
I looked at every callsites formigrate_pages()and there is no place which really need fail count.
This function sometimes makes caller error-prone,
so I think changing return value is preferable.How do you think, Christoph?
We could do that. I am not aware of anything using that information either. However, the condition in which some pages where migrated and others are not is not like a classic error. In many situations the moving of the pages is done for performance reasons. This just means that the best performant memory locations could not be used for some pages. A situation like that may be ok for an application.
--
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: [PATCH 3/3] mm: fix return value in __alloc_contig_migrate_range()
In reply to Michal Nazarewicz2012/7/17 Michal Nazarewicz <[email protected]>:
Quoted 12 lines
Quoted 9 lines · Joonsoo Kim
migrate_pages()would return positive value in some failure case, so 'ret > 0 ? 0 : ret' may be wrong.
This fix it and remove one dead statement.Signed-off-by Joonsoo Kim <[email protected]>Cc Michal Nazarewicz <[email protected]>Cc Marek Szyprowski <[email protected]>Cc Minchan Kim <[email protected]>Cc Christoph Lameter <[email protected]>
Quoted 7 lines
Have you actually encountered this problem? If
migrate_pages()fails with a positive value, the code that you are removing kicks in and-EBUSYis assigned to ret (now that I look at it, I think that in the current code the "return ret > 0 ? 0 : ret;" statement could be reduced to "return ret;"). Your code seems to be cleaner, but the commit message does not look accurate to me.
I don't encounter this problem yet.
If migrate_pages() with offlining false meets KSM page, then migration failed. In this case, failed page is removed from cc.migratepage list and return failed count.
So it can be possible exiting loop without testing ++tries == 5 and ret is over the zero.
Is there any point which I missing?
Is there any possible scenario "migrate_pages return > 0 and cc.migratepages is empty"?
I'm not expert for MM, so please comment my humble opinion.
--
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: [PATCH 2/3] mm: fix possible incorrect return value of migrate_pages() syscall
In reply to JoonSoo KimQuoted 14 lines · JoonSoo Kim
2012/7/17 Michal Nazarewicz <[email protected]>:
Quoted 13 lines
Quoted 11 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-EIOAdditionally, Correct comment above
do_migrate_pages()Signed-off-by Joonsoo Kim <[email protected]>Cc Sasha Levin <[email protected]>Cc Christoph Lameter <[email protected]>
Quoted 6 lines
Quoted 1 line
Thanks.
When I resend with changing
-EIOto-EBUSY,
could I include "Acked-by: Michal Nazarewicz <[email protected]>"?
Sure thing.
Signature · 10 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo-- -- 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: [PATCH 3/3] mm: fix return value in __alloc_contig_migrate_range()
In reply to JoonSoo KimQuoted 21 lines · JoonSoo Kim
2012/7/17 Michal Nazarewicz <[email protected]>:
Quoted 12 lines
Quoted 9 lines · Joonsoo Kim
migrate_pages()would return positive value in some failure case, so 'ret > 0 ? 0 : ret' may be wrong.
This fix it and remove one dead statement.Signed-off-by Joonsoo Kim <[email protected]>Cc Michal Nazarewicz <[email protected]>Cc Marek Szyprowski <[email protected]>Cc Minchan Kim <[email protected]>Cc Christoph Lameter <[email protected]>Quoted 7 lines
Have you actually encountered this problem? If
migrate_pages()fails with a positive value, the code that you are removing kicks in and-EBUSYis assigned to ret (now that I look at it, I think that in the current code the "return ret > 0 ? 0 : ret;" statement could be reduced to "return ret;"). Your code seems to be cleaner, but the commit message does not look accurate to me.
Quoted 5 lines
I don't encounter this problem yet.
If
migrate_pages()with offlining false meets KSM page, then migration failed. In this case, failed page is removed from cc.migratepage list and return failed count.
Good point.
Signature · 10 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +----<email/xmpp: [email protected]>--------------ooO--(_)--Ooo-- -- 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>