Skip to contentSkip to conversation

mm: correct return value of migrate_pages() and migrate_huge_pages()

PATCH Superseded Joonsoo Kim 3 participants 9 messages Jul 17, 2012

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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()

mm/migrate.c +2 -0
index be26d5c..f495c58 100644
@@ -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>
#1 lore raw

PATCH v2 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()

Cc Sasha Levin <[email protected]>
Cc Christoph Lameter <[email protected]>
mm/mempolicy.c +3 -1
index 1d771e4..0732729 100644
@@ -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>
#4 lore raw

PATCH v2 3/4 mm: fix return value in __alloc_contig_migrate_range()

In reply to 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.

Cc Michal Nazarewicz <[email protected]>
Cc Marek Szyprowski <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Christoph Lameter <[email protected]>
mm/page_alloc.c +1 -2
index 4403009..02d4519 100644
@@ -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>
#8 lore raw

PATCH v2 4/4 mm: fix possible incorrect return value of move_pages() syscall

In reply to Joonsoo Kim

move_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.

Cc Brice Goglin <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Minchan Kim <[email protected]>
mm/migrate.c +1 -1
index f495c58..eeaf409 100644
@@ -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>
Acked-by on v2 3/4
#5 lore raw

Re: [PATCH 3/4 v2] mm: fix return value in __alloc_contig_migrate_range()

In reply to Joonsoo Kim
Quoted 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.

How about the following message:

------------------- >8 --------------------------------------------------- migrate_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. ------------------- >8 ---------------------------------------------------

Quoted 2 lines
Cc Michal Nazarewicz <[email protected]>
Quoted 4 lines
Cc Marek Szyprowski <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Christoph Lameter <[email protected]>

In fact, now that I look at it, I think that __alloc_contig_migrate_range() should be changed even further. I'll take a closer look at it and send a patch (possibly through Marek ;) ).

Quoted 18 lines
mm/page_alloc.c +1 -2
index 4403009..02d4519 100644
@@ -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 · 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>
#2 lore raw

Re: [PATCH 2/4 v2] mm: fix possible incorrect return value of migrate_pages() syscall

In reply to Joonsoo Kim

mm/mempolicy.c SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode, · line 1389

Quoted 9 lines · Joonsoo Kim
mm/mempolicy.c +2 -0
@@ -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:

Why not have do_migrate_pages() return EBUSY if we do not need the number of failed/retried 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>

#3 lore raw

Re: [PATCH 2/4 v2] mm: fix possible incorrect return value of migrate_pages() syscall

2012/7/17 Christoph Lameter <[email protected]>:

Quoted 9 lines · Joonsoo Kim
Quoted 8 lines
mm/mempolicy.c +2 -0
@@ -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;
 
Quoted 5 lines

mm/mempolicy.c SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode, · line 1389

Quoted 2 lines
mm/mempolicy.c +0 -0
      mmput(mm);
 out:

Why not have do_migrate_pages() return EBUSY if we do not need the number of failed/retried pages?

There is no serious reason.
do_migrate_pages() have two callsites, although another one doesn't use return value.
do_migrate_pages() is commented "Return the number of page ...". And my focus is fixing possible error in migrate_pages() syscall. So, I keep to return the number of failed/retired pages.

If we really think the number of failed/retired pages is useless, in that time, instead that do_migrate_pages() return EBUSY, we can make migrate_pages() return EBUSY. I think it is better to fix all the related codes at one go.

--
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>

#6 lore raw

Re: [PATCH 3/4 v2] mm: fix return value in __alloc_contig_migrate_range()

In reply to Michal Nazarewicz

2012/7/17 Michal Nazarewicz <[email protected]>:

Quoted 14 lines · Joonsoo Kim
Quoted 4 lines

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.

How about the following message:

------------------- >8 --------------------------------------------------- migrate_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.

Quoted 8 lines

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. ------------------- >8 ---------------------------------------------------

It's good.
I will resend patch replacing my comment with yours. Thanks for help.

--
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>

#7 lore raw

PATCH v3 3/4 mm: fix return value in __alloc_contig_migrate_range()

migrate_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
index 4403009..02d4519 100644
@@ -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>