Skip to contentSkip to conversation

mm: fix special case -1 order check in compact_finished

PATCH In review Michal Hocko 4 participants 7 messages May 30, 2011 – Jun 2, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: fix special case -1 order check in compact_finished

56de7263 (mm: compaction: direct compact when a high-order allocation fails) introduced a check for cc->order == -1 in compact_finished. We should continue compacting in that case because the request came from userspace and there is no particular order to compact for.

The check is, however, done after zone_watermark_ok which uses order as a right hand argument for shifts. Not only watermark check is pointless if we can break out without it but it also uses 1 << -1 which is not well defined (at least from C standard). Let's move the -1 check above zone_watermark_ok.

---
 compaction.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
mm/compaction.c +7 -7
Index: linus_tree/mm/compaction.c
===================================================================
@@ -420,13 +420,6 @@ static int compact_finished(struct zone
 	if (cc->free_pfn <= cc->migrate_pfn)
 		return COMPACT_COMPLETE;
 
-	/* Compaction run is not finished if the watermark is not met */
-	watermark = low_wmark_pages(zone);
-	watermark += (1 << cc->order);
-
-	if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0))
-		return COMPACT_CONTINUE;
-
 	/*
 	 * order == -1 is expected when compacting via
 	 * /proc/sys/vm/compact_memory
@@ -434,6 +427,13 @@ static int compact_finished(struct zone
 	if (cc->order == -1)
 		return COMPACT_CONTINUE;
 
+	/* Compaction run is not finished if the watermark is not met */
+	watermark = low_wmark_pages(zone);
+	watermark += (1 << cc->order);
+
+	if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0))
+		return COMPACT_CONTINUE;
+
 	/* Direct compactor: Is a suitable page free? */
 	for (order = cc->order; order < MAX_ORDER; order++) {
 		/* Job done if page is free of the right migratetype */
Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Michal Hocko

56de7263 (mm: compaction: direct compact when a high-order allocation fails) introduced a check for cc->order == -1 in compact_finished. We should continue compacting in that case because the request came from userspace and there is no particular order to compact for.

Quoted 8 lines

The check is, however, done after zone_watermark_ok which uses order as a right hand argument for shifts. Not only watermark check is pointless if we can break out without it but it also uses 1 << -1 which is not well defined (at least from C standard). Let's move the -1 check above zone_watermark_ok.

Signature · 9 lines
Mel Gorman
SUSE Labs

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw
In reply to Michal Hocko

Sorry for breaking thread.
I resend.

Quoted 38 lines · Michal Hocko

56de7263 (mm: compaction: direct compact when a high-order allocation fails) introduced a check for cc->order == -1 in compact_finished. We should continue compacting in that case because the request came from userspace and there is no particular order to compact for.

The check is, however, done after zone_watermark_ok which uses order as a right hand argument for shifts. Not only watermark check is pointless if we can break out without it but it also uses 1 << -1 which is not well defined (at least from C standard). Let's move the -1 check above zone_watermark_ok.

---
 compaction.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Index: linus_tree/mm/compaction.c
===================================================================

mm/compaction.c +0 -7
@@ -420,13 +420,6 @@ static int compact_finished(struct zone
 	if (cc->free_pfn <= cc->migrate_pfn)
 		return COMPACT_COMPLETE;
 
-	/* Compaction run is not finished if the watermark is not met */
-	watermark = low_wmark_pages(zone);
-	watermark += (1 << cc->order);
-
-	if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0))
-		return COMPACT_CONTINUE;
-
 	/*
 	 * order == -1 is expected when compacting via
 	 * /proc/sys/vm/compact_memory
@@ -434,6 +427,13 @@ static int compact_finished(struct zone
 	if (cc->order == -1)
 		return COMPACT_CONTINUE;
 

mm/compaction.c static int compact_finished(struct zone · line 439

Quoted 10 lines
mm/compaction.c +7 -0
+	/* Compaction run is not finished if the watermark is not met */
+	watermark = low_wmark_pages(zone);
+	watermark += (1 << cc->order);
+
+	if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0))
+		return COMPACT_CONTINUE;
+
 	/* Direct compactor: Is a suitable page free? */
 	for (order = cc->order; order < MAX_ORDER; order++) {
 		/* Job done if page is free of the right migratetype */

It looks good to me.
Let's think about another place, compaction_suitable.
It has same problem so we can move the check right before zone_watermark_ok. As I look it more, I thought we need free pages for compaction so we would be better to give up early if we can't get enough free pages. But I changed my mind. It's a totally user request and we can get free pages in migration progress(ex, other big memory hogger might free his big rss).
So my conclusion is that we should do *best effort* than early give up. If you agree with me, how about resending patch with compaction_suitable fix?

Quoted 14 lines
Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw

PATCH v2 1/1 mm: compaction: fix special case -1 order checks

Quoted 6 lines · Minchan Kim

Review

Quoted 3 lines
(quoted diff) +0 -0
 	/* Direct compactor: Is a suitable page free? */
 	for (order = cc->order; order < MAX_ORDER; order++) {
 		/* Job done if page is free of the right migratetype */

It looks good to me.
Let's think about another place, compaction_suitable.

Good spotted.

Quoted 6 lines

It has same problem so we can move the check right before zone_watermark_ok. As I look it more, I thought we need free pages for compaction so we would be better to give up early if we can't get enough free pages. But I changed my mind. It's a totally user request and we can get free pages in migration progress(ex, other big memory hogger might free his big rss).
So my conclusion is that we should do *best effort* than early give up.

Agreed

Quoted 1 line

If you agree with me, how about resending patch with compaction_suitable fix?

Here we go. Thanks

---
mm: compaction: fix special case -1 order checks

56de7263 (mm: compaction: direct compact when a high-order allocation fails) introduced a check for cc->order == -1 in compact_finished. We should continue compacting in that case because the request came from userspace and there is no particular order to compact for. Similar check has been added by 82478fb7 (mm: compaction:
prevent division-by-zero during user-requested compaction) for compaction_suitable.

The check is, however, done after zone_watermark_ok which uses order as a right hand argument for shifts. Not only watermark check is pointless if we can break out without it but it also uses 1 << -1 which is not well defined (at least from C standard). Let's move the -1 check above zone_watermark_ok.

[Minchan Kim <[email protected]> - caught compaction_suitable]
Cc Mel Gorman <[email protected]>
---
 compaction.c |   14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
mm/compaction.c +14 -14
Index: linus_tree/mm/compaction.c
===================================================================
@@ -420,13 +420,6 @@ static int compact_finished(struct zone
 	if (cc->free_pfn <= cc->migrate_pfn)
 		return COMPACT_COMPLETE;
 
-	/* Compaction run is not finished if the watermark is not met */
-	watermark = low_wmark_pages(zone);
-	watermark += (1 << cc->order);
-
-	if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0))
-		return COMPACT_CONTINUE;
-
 	/*
 	 * order == -1 is expected when compacting via
 	 * /proc/sys/vm/compact_memory
@@ -434,6 +427,13 @@ static int compact_finished(struct zone
 	if (cc->order == -1)
 		return COMPACT_CONTINUE;
 
+	/* Compaction run is not finished if the watermark is not met */
+	watermark = low_wmark_pages(zone);
+	watermark += (1 << cc->order);
+
+	if (!zone_watermark_ok(zone, cc->order, watermark, 0, 0))
+		return COMPACT_CONTINUE;
+
 	/* Direct compactor: Is a suitable page free? */
 	for (order = cc->order; order < MAX_ORDER; order++) {
 		/* Job done if page is free of the right migratetype */
@@ -461,6 +461,13 @@ unsigned long compaction_suitable(struct
 	unsigned long watermark;
 
 	/*
+	 * order == -1 is expected when compacting via
+	 * /proc/sys/vm/compact_memory
+	 */
+	if (order == -1)
+		return COMPACT_CONTINUE;
+
+	/*
 	 * Watermarks for order-0 must be met for compaction. Note the 2UL.
 	 * This is because during migration, copies of pages need to be
 	 * allocated and for a short time, the footprint is higher
@@ -470,13 +477,6 @@ unsigned long compaction_suitable(struct
 		return COMPACT_SKIPPED;
 
 	/*
-	 * order == -1 is expected when compacting via
-	 * /proc/sys/vm/compact_memory
-	 */
-	if (order == -1)
-		return COMPACT_CONTINUE;
-
-	/*
 	 * fragmentation index determines if allocation failures are due to
 	 * low memory or external fragmentation
 	 *
Signature · 13 lines
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v2 1/1
#4 lore raw

Re: [PATCH v2] mm: compaction: fix special case -1 order checks

Quoted 34 lines · Michal Hocko
Quoted 6 lines · Minchan Kim

mm/compaction.c static int compact_finished(struct zone · line 439

Quoted 3 lines
mm/compaction.c +0 -0
 	/* Direct compactor: Is a suitable page free? */
 	for (order = cc->order; order < MAX_ORDER; order++) {
 		/* Job done if page is free of the right migratetype */

It looks good to me.
Let's think about another place, compaction_suitable.

Good spotted.

Quoted 6 lines

It has same problem so we can move the check right before zone_watermark_ok. As I look it more, I thought we need free pages for compaction so we would be better to give up early if we can't get enough free pages. But I changed my mind. It's a totally user request and we can get free pages in migration progress(ex, other big memory hogger might free his big rss).
So my conclusion is that we should do *best effort* than early give up.

Agreed

Quoted 1 line

If you agree with me, how about resending patch with compaction_suitable fix?

Here we go. Thanks

---
mm: compaction: fix special case -1 order checks

56de7263 (mm: compaction: direct compact when a high-order allocation fails) introduced a check for cc->order == -1 in compact_finished. We should continue compacting in that case because the request came from userspace and there is no particular order to compact for. Similar check has been added by 82478fb7 (mm: compaction:
prevent division-by-zero during user-requested compaction) for compaction_suitable.

Quoted 8 lines

The check is, however, done after zone_watermark_ok which uses order as a right hand argument for shifts. Not only watermark check is pointless if we can break out without it but it also uses 1 << -1 which is not well defined (at least from C standard). Let's move the -1 check above zone_watermark_ok.

[Minchan Kim <[email protected]> - caught compaction_suitable]

Thanks.

Signature · 9 lines
Kind regards
Minchan Kim

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 1/1
#6 lore raw
In reply to Michal Hocko
Quoted 5 lines · On Mon, 30 May 2011 14:38:31 +0200 Michal Hocko <[email protected]> wrote:

56de7263 (mm: compaction: direct compact when a high-order allocation fails) introduced a check for cc->order == -1 in compact_finished. We should continue compacting in that case because the request came from userspace and there is no particular order to compact for.

Quoted 8 lines

The check is, however, done after zone_watermark_ok which uses order as a right hand argument for shifts. Not only watermark check is pointless if we can break out without it but it also uses 1 << -1 which is not well defined (at least from C standard). Let's move the -1 check above zone_watermark_ok.

Acked-by on v2 1/1
#5 lore raw

Re: [PATCH v2] mm: compaction: fix special case -1 order checks

In reply to Michal Hocko
Quoted 17 lines · Michal Hocko

<SNIP>
mm: compaction: fix special case -1 order checks

56de7263 (mm: compaction: direct compact when a high-order allocation fails) introduced a check for cc->order == -1 in compact_finished. We should continue compacting in that case because the request came from userspace and there is no particular order to compact for. Similar check has been added by 82478fb7 (mm: compaction:
prevent division-by-zero during user-requested compaction) for compaction_suitable.

The check is, however, done after zone_watermark_ok which uses order as a right hand argument for shifts. Not only watermark check is pointless if we can break out without it but it also uses 1 << -1 which is not well defined (at least from C standard). Let's move the -1 check above zone_watermark_ok.

Quoted 3 lines
[Minchan Kim <[email protected]> - caught compaction_suitable]
Cc Mel Gorman <[email protected]>
Signature · 9 lines
Mel Gorman
SUSE Labs

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>