Skip to contentSkip to conversation

mm : add check for the return value

PATCH In review Huang Shijie 6 participants 17 messages Jan 4, 2010 – Jan 8, 2010

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

PATCH 1/1 mm : add check for the return value

When the `page' returned by __rmqueue() is NULL, the origin code still adds -(1 << order) to zone's NR_FREE_PAGES item.

The patch fixes it.

---
 mm/page_alloc.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
mm/page_alloc.c +7 -3
index 4e9f5cc..620921d 100644
@@ -1222,10 +1222,14 @@ again:
 		}
 		spin_lock_irqsave(&zone->lock, flags);
 		page = __rmqueue(zone, order, migratetype);
-		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
-		spin_unlock(&zone->lock);
-		if (!page)
+		if (likely(page)) {
+			__mod_zone_page_state(zone, NR_FREE_PAGES,
+						-(1 << order));
+			spin_unlock(&zone->lock);
+		} else {
+			spin_unlock(&zone->lock);
 			goto failed;
+		}
 	}
 
 	__count_zone_vm_events(PGALLOC, zone, 1 << order);
Signature · 7 lines
1.6.5.2

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

Hi, Huang.

Quoted 22 lines · On Mon, 4 Jan 2010 10:22:10 +0800 Huang Shijie <[email protected]> wrote:

When the `page' returned by __rmqueue() is NULL, the origin code still adds -(1 << order) to zone's NR_FREE_PAGES item.

The patch fixes it.

---
 mm/page_alloc.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
mm/page_alloc.c +1 -3
index 4e9f5cc..620921d 100644
@@ -1222,10 +1222,14 @@ again:
 		}
 		spin_lock_irqsave(&zone->lock, flags);
 		page = __rmqueue(zone, order, migratetype);
-		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
-		spin_unlock(&zone->lock);
-		if (!page)
+		if (likely(page)) {

mm/page_alloc.c again: · line 1235

Quoted 10 lines
mm/page_alloc.c +6 -0
+			__mod_zone_page_state(zone, NR_FREE_PAGES,
+						-(1 << order));
+			spin_unlock(&zone->lock);
+		} else {
+			spin_unlock(&zone->lock);
 			goto failed;
+		}
 	}
 
 	__count_zone_vm_events(PGALLOC, zone, 1 << order);

I think it's not desirable to add new branch in hot-path even though we could avoid that.

How about this?

mm/page_alloc.c +3 -0
index 4e4b5b3..87976ad 100644
@@ -1244,6 +1244,9 @@ again:
        return page;
 
 failed:
+       spin_lock(&zone->lock);
+       __mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
+       spin_unlock(&zone->lock);
        local_irq_restore(flags);
        put_cpu();
        return NULL;
Quoted 8 lines
Signature · 7 lines
1.6.5.2

--
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>
Signature · 8 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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author
#2 lore raw
Quoted 11 lines

I think it's not desirable to add new branch in hot-path even though we could avoid that.

How about this?

mm/page_alloc.c +0 -0
index 4e4b5b3..87976ad 100644

mm/page_alloc.c again: · line 1247

Quoted 4 lines
mm/page_alloc.c +0 -0
@@ -1244,6 +1244,9 @@ again:
         return page;
 
  failed:
 

you miss anther place where also uses "goto failed".

Quoted 8 lines
mm/page_alloc.c +3 -0
+       spin_lock(&zone->lock);
+       __mod_zone_page_state(zone, NR_FREE_PAGES, 1<<  order);
+       spin_unlock(&zone->lock);
         local_irq_restore(flags);
         put_cpu();
         return NULL;

I also thought over your method before I sent the patch, but there already exits a "if (!page)" , I not sure whether my patch adds too much delay in hot-path.

--
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
Quoted 13 lines · On Mon, 04 Jan 2010 12:10:16 +0800 shijie8 <[email protected]> wrote:
Quoted 13 lines

I think it's not desirable to add new branch in hot-path even though we could avoid that.

How about this?

mm/page_alloc.c +0 -0
index 4e4b5b3..87976ad 100644
@@ -1244,6 +1244,9 @@ again:
         return page;
 
Quoted 3 lines

mm/page_alloc.c again: · line 1247

Quoted 2 lines
mm/page_alloc.c +0 -0
  failed:
 

you miss anther place where also uses "goto failed".

Yes. It was just for showing my intention. :)

Quoted 11 lines
Quoted 8 lines
mm/page_alloc.c +3 -0
+       spin_lock(&zone->lock);
+       __mod_zone_page_state(zone, NR_FREE_PAGES, 1<<  order);
+       spin_unlock(&zone->lock);
         local_irq_restore(flags);
         put_cpu();
         return NULL;

I also thought over your method before I sent the patch, but there already exits a
"if (!page)" , I not sure whether my patch adds too much delay in hot-path.

Tend to agree. I don't object your patch.

I think the branch itself could not a big deal but 'likely'.

Why I suggest is that now 'if (!page)' don't have 'likely'. As you know, 'likely' make the code relocate for reducing code footprint.

Why? It was just mistake or doesn't need it?

I think Mel does know it.

Signature · 8 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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#4 lore raw
Quoted 9 lines

I think the branch itself could not a big deal but 'likely'.

Why I suggest is that now 'if (!page)' don't have 'likely'. As you know, 'likely' make the code relocate for reducing code footprint.

Why? It was just mistake or doesn't need it?

I think the CPU will CACHE the `likely' code, and make it runs fast.

IMHO, "if (unlikely(page == NULL)) " is better then "if (!page)" ,just like the code in rmqueue_bulk().

Quoted 3 lines

I think Mel does know it.

wait for Mel's response.

--
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 1/1 page allocator: fix update NR_FREE_PAGES only as necessary

In reply to Minchan Kim
Quoted 48 lines

Hi, Huang.

Quoted 22 lines · On Mon, 4 Jan 2010 10:22:10 +0800 Huang Shijie <[email protected]> wrote:

When the `page' returned by __rmqueue() is NULL, the origin code still adds -(1 << order) to zone's NR_FREE_PAGES item.

The patch fixes it.

---
 mm/page_alloc.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
mm/page_alloc.c +1 -3
index 4e9f5cc..620921d 100644
@@ -1222,10 +1222,14 @@ again:
 		}
 		spin_lock_irqsave(&zone->lock, flags);
 		page = __rmqueue(zone, order, migratetype);
-		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
-		spin_unlock(&zone->lock);
-		if (!page)
+		if (likely(page)) {

mm/page_alloc.c again: · line 1235

Quoted 10 lines
mm/page_alloc.c +6 -0
+			__mod_zone_page_state(zone, NR_FREE_PAGES,
+						-(1 << order));
+			spin_unlock(&zone->lock);
+		} else {
+			spin_unlock(&zone->lock);
 			goto failed;
+		}
 	}
 
 	__count_zone_vm_events(PGALLOC, zone, 1 << order);

I think it's not desirable to add new branch in hot-path even though we could avoid that.

How about this?

mm/page_alloc.c +0 -0
index 4e4b5b3..87976ad 100644

mm/page_alloc.c again: · line 1252

Quoted 9 lines
mm/page_alloc.c +3 -0
@@ -1244,6 +1244,9 @@ again:
        return page;
 
 failed:
+       spin_lock(&zone->lock);
+       __mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
+       spin_unlock(&zone->lock);
        local_irq_restore(flags);
        put_cpu();
        return NULL;

Why can't we write following? __mod_zone_page_state() only require irq disabling, it doesn't need spin lock. I think.

From 72011ff2b0bba6544ae35c6ee52715c8c824a34b Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <[email protected]>
Date: Mon, 4 Jan 2010 14:38:20 +0900
Subject: [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary

commit f2260e6b (page allocator: update NR_FREE_PAGES only as necessary) made one minor regression.
if __rmqueue() was failed, NR_FREE_PAGES stat go wrong. this patch fixes it.

Cc Mel Gorman <[email protected]>
Cc Huang Shijie <[email protected]>
Cc Minchan Kim <[email protected]>
---
 mm/page_alloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/page_alloc.c +1 -1
index 11ae66e..ecf75a1 100644
@@ -1227,10 +1227,10 @@ again:
 		}
 		spin_lock_irqsave(&zone->lock, flags);
 		page = __rmqueue(zone, order, migratetype);
-		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
 		spin_unlock(&zone->lock);
 		if (!page)
 			goto failed;
+		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
 	}
 
 	__count_zone_vm_events(PGALLOC, zone, 1 << order);
Signature · 10 lines
1.6.5.2




--
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>
Reviewed-by on v1 1/1
#8 lore raw

Re: [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary

Quoted 50 lines · On Mon, 4 Jan 2010 14:52:36 +0900 (JST) KOSAKI Motohiro…
Quoted 50 lines

Hi, Huang.

Quoted 22 lines · On Mon, 4 Jan 2010 10:22:10 +0800 Huang Shijie <[email protected]> wrote:

When the `page' returned by __rmqueue() is NULL, the origin code still adds -(1 << order) to zone's NR_FREE_PAGES item.

The patch fixes it.

---
 mm/page_alloc.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
mm/page_alloc.c +1 -3
index 4e9f5cc..620921d 100644
@@ -1222,10 +1222,14 @@ again:
 		}
 		spin_lock_irqsave(&zone->lock, flags);
 		page = __rmqueue(zone, order, migratetype);
-		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
-		spin_unlock(&zone->lock);
-		if (!page)
+		if (likely(page)) {

mm/page_alloc.c again: · line 1235

Quoted 10 lines
mm/page_alloc.c +6 -0
+			__mod_zone_page_state(zone, NR_FREE_PAGES,
+						-(1 << order));
+			spin_unlock(&zone->lock);
+		} else {
+			spin_unlock(&zone->lock);
 			goto failed;
+		}
 	}
 
 	__count_zone_vm_events(PGALLOC, zone, 1 << order);

I think it's not desirable to add new branch in hot-path even though we could avoid that.

How about this?

mm/page_alloc.c +0 -0
index 4e4b5b3..87976ad 100644
@@ -1244,6 +1244,9 @@ again:
        return page;
 
Quoted 10 lines

mm/page_alloc.c again: · line 1252

Quoted 7 lines
mm/page_alloc.c +3 -0
 failed:
+       spin_lock(&zone->lock);
+       __mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
+       spin_unlock(&zone->lock);
        local_irq_restore(flags);
        put_cpu();
        return NULL;

Why can't we write following? __mod_zone_page_state() only require irq disabling, it doesn't need spin lock. I think.

That's true. I missed that :)

Quoted 13 lines

From 72011ff2b0bba6544ae35c6ee52715c8c824a34b Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <[email protected]>
Date: Mon, 4 Jan 2010 14:38:20 +0900
Subject: [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary

commit f2260e6b (page allocator: update NR_FREE_PAGES only as necessary) made one minor regression.
if __rmqueue() was failed, NR_FREE_PAGES stat go wrong. this patch fixes it.

Quoted 4 lines
Cc Mel Gorman <[email protected]>
Cc Huang Shijie <[email protected]>
Cc Minchan Kim <[email protected]>
Signature · 8 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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#5 lore raw
In reply to Huang Shijie
Quoted 11 lines · Huang Shijie
Quoted 9 lines

I think the branch itself could not a big deal but 'likely'.

Why I suggest is that now 'if (!page)' don't have 'likely'. As you know, 'likely' make the code relocate for reducing code footprint.

Why? It was just mistake or doesn't need it?

I think the CPU will CACHE the `likely' code, and make it runs fast.

I think so.

Quoted 9 lines

IMHO, "if (unlikely(page == NULL)) " is better then "if (!page)" ,just like the
code in rmqueue_bulk().

Quoted 3 lines

I think Mel does know it.

wait for Mel's response.

Yes.
Regardless of Kosaki's patch, there is a issue about likely/unlinkely usage.

Quoted 1 line
Signature · 8 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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#9 lore raw

Re: [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary

In reply to KOSAKI Motohiro
Quoted 6 lines

Why can't we write following? __mod_zone_page_state() only require irq disabling, it doesn't need spin lock. I think.

struct per_cpu_pageset {
.................................................

#ifdef CONFIG_SMP
    s8 stat_threshold;
    s8 vm_stat_diff[NR_VM_ZONE_STAT_ITEMS];

#endif
} ____cacheline_aligned_in_smp;

The field 'stat_threshold' is in the CONFIG_SMP macro, does it not need the spinlock? I will read the code more carefully. I saw the macro, so I thought it need the spinlock. :)

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

#10 lore raw

Re: [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary

Quoted 11 lines
Quoted 6 lines

Why can't we write following? __mod_zone_page_state() only require irq disabling, it doesn't need spin lock. I think.

struct per_cpu_pageset {
.................................................

#ifdef CONFIG_SMP
     s8 stat_threshold;
     s8 vm_stat_diff[NR_VM_ZONE_STAT_ITEMS];
Quoted 6 lines

#endif
} ____cacheline_aligned_in_smp;

The field 'stat_threshold' is in the CONFIG_SMP macro, does it not need the spinlock? I will read the code more carefully.
I saw the macro, so I thought it need the spinlock. :)

Generally, per-cpu data isn't accessed from another cpu. it only need to care process-context vs irq-context race.

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

#11 lore raw

Re: [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary

Quoted 9 lines
Quoted 9 lines
struct per_cpu_pageset {
   .................................................
#ifdef CONFIG_SMP
      s8 stat_threshold;
      s8 vm_stat_diff[NR_VM_ZONE_STAT_ITEMS];

#endif
} ____cacheline_aligned_in_smp;

Quoted 9 lines
Quoted 4 lines

The field 'stat_threshold' is in the CONFIG_SMP macro, does it not need the spinlock? I will read the code more carefully.
I saw the macro, so I thought it need the spinlock. :)

Generally, per-cpu data isn't accessed from another cpu. it only need to care process-context vs irq-context race.

If the __mod_zone_page_state() can be used without caring about the spinlock, I think there are several places we can move __mod_zone_page_state() out the guard area of spinlock to release the pressure of the zone->lock,such as in rmqueue_bulk().

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

#13 lore raw

Re: [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary

In reply to KOSAKI Motohiro
Quoted 50 lines · KOSAKI Motohiro
Quoted 50 lines

Hi, Huang.

Quoted 22 lines · On Mon, 4 Jan 2010 10:22:10 +0800 Huang Shijie <[email protected]> wrote:

When the `page' returned by __rmqueue() is NULL, the origin code still adds -(1 << order) to zone's NR_FREE_PAGES item.

The patch fixes it.

---
 mm/page_alloc.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
mm/page_alloc.c +1 -3
index 4e9f5cc..620921d 100644
@@ -1222,10 +1222,14 @@ again:
 		}
 		spin_lock_irqsave(&zone->lock, flags);
 		page = __rmqueue(zone, order, migratetype);
-		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
-		spin_unlock(&zone->lock);
-		if (!page)
+		if (likely(page)) {

mm/page_alloc.c again: · line 1235

Quoted 10 lines
mm/page_alloc.c +6 -0
+			__mod_zone_page_state(zone, NR_FREE_PAGES,
+						-(1 << order));
+			spin_unlock(&zone->lock);
+		} else {
+			spin_unlock(&zone->lock);
 			goto failed;
+		}
 	}
 
 	__count_zone_vm_events(PGALLOC, zone, 1 << order);

I think it's not desirable to add new branch in hot-path even though we could avoid that.

How about this?

mm/page_alloc.c +0 -0
index 4e4b5b3..87976ad 100644
@@ -1244,6 +1244,9 @@ again:
        return page;
 
Quoted 11 lines

mm/page_alloc.c again: · line 1252

Quoted 7 lines
mm/page_alloc.c +3 -0
 failed:
+       spin_lock(&zone->lock);
+       __mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
+       spin_unlock(&zone->lock);
        local_irq_restore(flags);
        put_cpu();
        return NULL;

Why can't we write following? __mod_zone_page_state() only require irq disabling, it doesn't need spin lock. I think.

Adding Christoph to be sure but yes, as this is a per-cpu variable it should be safe to update with __mod_zone_page_state() as long as interrupts and preempt are disabled. If true, then this is a neater fix and is also needed for -stable 2.6.31 and 2.6.32.

Well spotted and thanks.

Quoted 40 lines

From 72011ff2b0bba6544ae35c6ee52715c8c824a34b Mon Sep 17 00:00:00 2001
From: KOSAKI Motohiro <[email protected]>
Date: Mon, 4 Jan 2010 14:38:20 +0900
Subject: [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary

commit f2260e6b (page allocator: update NR_FREE_PAGES only as necessary) made one minor regression.
if __rmqueue() was failed, NR_FREE_PAGES stat go wrong. this patch fixes it.

Cc Mel Gorman <[email protected]>
Cc Huang Shijie <[email protected]>
Cc Minchan Kim <[email protected]>
---
 mm/page_alloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/page_alloc.c +1 -1
index 11ae66e..ecf75a1 100644
@@ -1227,10 +1227,10 @@ again:
 		}
 		spin_lock_irqsave(&zone->lock, flags);
 		page = __rmqueue(zone, order, migratetype);
-		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
 		spin_unlock(&zone->lock);
 		if (!page)
 			goto failed;
+		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
 	}
 
 	__count_zone_vm_events(PGALLOC, zone, 1 << order);
Signature · 1 line
1.6.5.2
Signature · 9 lines
Mel Gorman
Part-time Phd Student                          Linux Technology Center
University of Limerick                         IBM Dublin Software Lab

--
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>
Reviewed-by
#14 lore raw

Re: [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary

Quoted 2 lines · Mel Gorman
Quoted 2 lines

Why can't we write following? __mod_zone_page_state() only require irq disabling, it doesn't need spin lock. I think.

Correct.

Quoted 28 lines
Quoted 28 lines

commit f2260e6b (page allocator: update NR_FREE_PAGES only as necessary) made one minor regression.
if __rmqueue() was failed, NR_FREE_PAGES stat go wrong. this patch fixes it.

Cc Mel Gorman <[email protected]>
Cc Huang Shijie <[email protected]>
Cc Minchan Kim <[email protected]>
---
 mm/page_alloc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
mm/page_alloc.c +1 -1
index 11ae66e..ecf75a1 100644
@@ -1227,10 +1227,10 @@ again:
 		}
 		spin_lock_irqsave(&zone->lock, flags);
 		page = __rmqueue(zone, order, migratetype);
-		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
 		spin_unlock(&zone->lock);
 		if (!page)
 			goto failed;
+		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
 	}
 
Quoted 1 line

mm/page_alloc.c again: · line 1236

Quoted 1 line
mm/page_alloc.c +0 -0
 	__count_zone_vm_events(PGALLOC, zone, 1 << order);

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

#15 lore raw

Re: [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary

In reply to Mel Gorman
Quoted 19 lines
Quoted 7 lines
Quoted 7 lines
mm/page_alloc.c +0 -0
index 4e4b5b3..87976ad 100644
@@ -1244,6 +1244,9 @@ again:
        return page;
 
Quoted 11 lines

mm/page_alloc.c again: · line 1252

Quoted 7 lines
mm/page_alloc.c +3 -0
 failed:
+       spin_lock(&zone->lock);
+       __mod_zone_page_state(zone, NR_FREE_PAGES, 1 << order);
+       spin_unlock(&zone->lock);
        local_irq_restore(flags);
        put_cpu();
        return NULL;

Why can't we write following? __mod_zone_page_state() only require irq disabling, it doesn't need spin lock. I think.

Quoted 6 lines

Adding Christoph to be sure but yes, as this is a per-cpu variable it should be safe to update with __mod_zone_page_state() as long as interrupts and preempt are disabled. If true, then this is a neater fix and is also needed for -stable 2.6.31 and 2.6.32.

Well spotted and thanks.

Yes, it should be sent to -stable tree. I hope this fix also solve recent mysterious allocation failure problem ;-)

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

#12 lore raw

Re: [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary

In reply to Huang Shijie
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
struct per_cpu_pageset {
   .................................................
#ifdef CONFIG_SMP
      s8 stat_threshold;
      s8 vm_stat_diff[NR_VM_ZONE_STAT_ITEMS];

#endif
} ____cacheline_aligned_in_smp;

The field 'stat_threshold' is in the CONFIG_SMP macro, does it not need the spinlock? I will read the code more carefully.
I saw the macro, so I thought it need the spinlock. :)

Quoted 8 lines
Quoted 3 lines

Generally, per-cpu data isn't accessed from another cpu. it only need to care process-context vs irq-context race.

If the __mod_zone_page_state() can be used without caring about the spinlock, I think there
are several places we can move __mod_zone_page_state() out the guard area of spinlock to
release the pressure of the zone->lock,such as in rmqueue_bulk().

Welcome to your patch :)

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

maintainer
#6 lore raw
In reply to Minchan Kim
Quoted 19 lines · On Mon, 4 Jan 2010 15:06:54 +0900 Minchan Kim <[email protected]> wrote:
Quoted 11 lines · Huang Shijie
Quoted 9 lines

I think the branch itself could not a big deal but 'likely'.

Why I suggest is that now 'if (!page)' don't have 'likely'. As you know, 'likely' make the code relocate for reducing code footprint.

Why? It was just mistake or doesn't need it?

I think the CPU will CACHE the `likely' code, and make it runs fast.

I think so.

Quoted 4 lines

IMHO, "if (unlikely(page == NULL)) " is better then "if (!page)" ,just like the
code in rmqueue_bulk().

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

I think Mel does know it.

wait for Mel's response.

Yes.
Regardless of Kosaki's patch, there is a issue about likely/unlinkely usage.

All of this code is in the (order != 0) path, so it's relatively rarely executed. We've added a small expense to a rarely-executed code path. I think I'll apply the original patch as-is.

From: Huang Shijie <[email protected]>

When the `page' returned by __rmqueue() is NULL, the origin code still adds -(1 << order) to zone's NR_FREE_PAGES item.

The patch fixes it.

Cc Minchan Kim <[email protected]>
Cc Mel Gorman <[email protected]>
Cc KOSAKI Motohiro <[email protected]>

---

 mm/page_alloc.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
mm/page_alloc.c renamed from mm/page_alloc.c~mm-add-check-for-the-return-value +7 -3
diff -puN mm/page_alloc.c~mm-add-check-for-the-return-value mm/page_alloc.c
@@ -1219,10 +1219,14 @@ again:
 		}
 		spin_lock_irqsave(&zone->lock, flags);
 		page = __rmqueue(zone, order, migratetype);
-		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
-		spin_unlock(&zone->lock);
-		if (!page)
+		if (likely(page)) {
+			__mod_zone_page_state(zone, NR_FREE_PAGES,
+						-(1 << order));
+			spin_unlock(&zone->lock);
+		} else {
+			spin_unlock(&zone->lock);
 			goto failed;
+		}
 	}
 
 	__count_zone_vm_events(PGALLOC, zone, 1 << order);

_

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

maintainer
#16 lore raw

Re: [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary

In reply to KOSAKI Motohiro
Quoted 4 lines · On Mon, 4 Jan 2010 14:52:36 +0900 (JST) KOSAKI Motohiro…
mm/page_alloc.c +0 -0
@@ -1227,10 +1227,10 @@ again:
 		}

mm/page_alloc.c again: · line 1236

Quoted 10 lines
mm/page_alloc.c +1 -1
 		spin_lock_irqsave(&zone->lock, flags);
 		page = __rmqueue(zone, order, migratetype);
-		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
 		spin_unlock(&zone->lock);
 		if (!page)
 			goto failed;
+		__mod_zone_page_state(zone, NR_FREE_PAGES, -(1 << order));
 	}
 
 	__count_zone_vm_events(PGALLOC, zone, 1 << order);

hm, yes, OK, obviously better.

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