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

From: Michal Nazarewicz
Date: Tue Jul 17 2012 - 09:25:30 EST


On Tue, 17 Jul 2012 14:33:34 +0200, Joonsoo Kim <js1304@xxxxxxxxx> wrote:
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 ---------------------------------------------------

Signed-off-by: Joonsoo Kim <js1304@xxxxxxxxx>
Cc: Michal Nazarewicz <mina86@xxxxxxxxxx>

Acked-by: Michal Nazarewicz <mina86@xxxxxxxxxx>

Cc: Marek Szyprowski <m.szyprowski@xxxxxxxxxxx>
Cc: Minchan Kim <minchan@xxxxxxxxxx>
Cc: Christoph Lameter <cl@xxxxxxxxx>
Acked-by: Christoph Lameter <cl@xxxxxxxxx>

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 ;) ).

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 4403009..02d4519 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -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;
}
/*


--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, MichaÅ âmina86â Nazarewicz (o o)
ooo +----<email/xmpp: mpn@xxxxxxxxxx>--------------ooO--(_)--Ooo--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/