linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Minchan Kim <minchan.kim@gmail.com>
Cc: Huang Shijie <shijie8@gmail.com>,
	mel@csn.ul.ie, linux-mm@kvack.org,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Subject: Re: [PATCH] mm : add check for the return value
Date: Fri, 8 Jan 2010 14:59:45 -0800	[thread overview]
Message-ID: <20100108145945.d3d5eed6.akpm@linux-foundation.org> (raw)
In-Reply-To: <28c262361001032206m6b102f85wed64ae31fd5b06d5@mail.gmail.com>

On Mon, 4 Jan 2010 15:06:54 +0900
Minchan Kim <minchan.kim@gmail.com> wrote:

> On Mon, Jan 4, 2010 at 2:18 PM, Huang Shijie <shijie8@gmail.com> wrote:
> >
> >> 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.
> 
> >
> > IMHO, "if (unlikely(page == NULL)) " is better then "if (!page)" ,just like
> > the
> > code in rmqueue_bulk().
> >> 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 <shijie8@gmail.com>

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.

Signed-off-by: Huang Shijie <shijie8@gmail.com>
Cc: Minchan Kim <minchan.kim@gmail.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/page_alloc.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff -puN mm/page_alloc.c~mm-add-check-for-the-return-value mm/page_alloc.c
--- a/mm/page_alloc.c~mm-add-check-for-the-return-value
+++ a/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 majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2010-01-08 23:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-04  2:22 [PATCH] mm : add check for the return value Huang Shijie
2010-01-04  3:21 ` Minchan Kim
2010-01-04  4:10   ` shijie8
2010-01-04  4:48     ` Minchan Kim
2010-01-04  5:18       ` Huang Shijie
2010-01-04  6:06         ` Minchan Kim
2010-01-08 22:59           ` Andrew Morton [this message]
2010-01-04  5:52   ` [PATCH] page allocator: fix update NR_FREE_PAGES only as necessary KOSAKI Motohiro
2010-01-04  6:03     ` Minchan Kim
2010-01-04  6:11     ` Huang Shijie
2010-01-04  6:16       ` KOSAKI Motohiro
2010-01-04  9:35         ` Huang Shijie
2010-01-05  7:24           ` KOSAKI Motohiro
2010-01-04  9:58     ` Mel Gorman
2010-01-04 17:46       ` Christoph Lameter
2010-01-05  1:08       ` KOSAKI Motohiro
2010-01-08 23:02     ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100108145945.d3d5eed6.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-mm@kvack.org \
    --cc=mel@csn.ul.ie \
    --cc=minchan.kim@gmail.com \
    --cc=shijie8@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).