linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] page_alloc.c: Slightly improve the logic in __alloc_pages_high_priority
@ 2012-03-05 14:18 Kautuk Consul
  2012-03-06  3:16 ` Minchan Kim
  0 siblings, 1 reply; 2+ messages in thread
From: Kautuk Consul @ 2012-03-05 14:18 UTC (permalink / raw)
  To: Andrew Morton, Mel Gorman, KAMEZAWA Hiroyuki, Tejun Heo,
	Minchan Kim
  Cc: linux-mm, linux-kernel, Kautuk Consul

The loop in __alloc_pages_high_priority() seems to be checking for
(!page) and (gfp_mask & __GFP_NOFAIL) multiple times.

In fact, we don't really need to check (gfp_mask & __GFP_NOFAIL)
for every iteration of the loop as the gfp_mask remains constant.

Slightly improve the logic in __alloc_pages_high_priority() to
eliminate these multiple condition checks.

Signed-off-by: Kautuk Consul <consul.kautuk@gmail.com>
---
 mm/page_alloc.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index a13ded1..6bb8b6d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2114,14 +2114,19 @@ __alloc_pages_high_priority(gfp_t gfp_mask, unsigned int order,
 {
 	struct page *page;
 
-	do {
-		page = get_page_from_freelist(gfp_mask, nodemask, order,
+	page = get_page_from_freelist(gfp_mask, nodemask, order,
 			zonelist, high_zoneidx, ALLOC_NO_WATERMARKS,
 			preferred_zone, migratetype);
 
-		if (!page && gfp_mask & __GFP_NOFAIL)
+	if (gfp_mask & __GFP_NOFAIL) {
+		while (!page) {
 			wait_iff_congested(preferred_zone, BLK_RW_ASYNC, HZ/50);
-	} while (!page && (gfp_mask & __GFP_NOFAIL));
+
+			page = get_page_from_freelist(gfp_mask, nodemask, order,
+				zonelist, high_zoneidx, ALLOC_NO_WATERMARKS,
+				preferred_zone, migratetype);
+		}
+	}
 
 	return page;
 }
-- 
1.7.5.4

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] page_alloc.c: Slightly improve the logic in __alloc_pages_high_priority
  2012-03-05 14:18 [PATCH 1/1] page_alloc.c: Slightly improve the logic in __alloc_pages_high_priority Kautuk Consul
@ 2012-03-06  3:16 ` Minchan Kim
  0 siblings, 0 replies; 2+ messages in thread
From: Minchan Kim @ 2012-03-06  3:16 UTC (permalink / raw)
  To: Kautuk Consul
  Cc: Andrew Morton, Mel Gorman, KAMEZAWA Hiroyuki, Tejun Heo,
	Minchan Kim, linux-mm, linux-kernel

Hi Kautuk,

On Mon, Mar 05, 2012 at 09:18:25AM -0500, Kautuk Consul wrote:
> The loop in __alloc_pages_high_priority() seems to be checking for
> (!page) and (gfp_mask & __GFP_NOFAIL) multiple times.
> 
> In fact, we don't really need to check (gfp_mask & __GFP_NOFAIL)
> for every iteration of the loop as the gfp_mask remains constant.
> 
> Slightly improve the logic in __alloc_pages_high_priority() to
> eliminate these multiple condition checks.

Thansk for your effort.

Surely we don't need mutliple condition check but it's not fast-path
and not a problem about readability. So I don't want to increase text
size unnecessary if it doesn't have a benefit.

barrios@barrios:~/linux-2.6$ size mm/page_alloc.o
   text	   data	    bss	    dec	    hex	filename
  32772	   1307	    576	  34655	   875f	mm/page_alloc.o
barrios@barrios:~/linux-2.6$ size mm/page_alloc.o.your_patch 
   text	   data	    bss	    dec	    hex	filename
  32804	   1307	    576	  34687	   877f	mm/page_alloc.o.patch

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-03-06  3:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-05 14:18 [PATCH 1/1] page_alloc.c: Slightly improve the logic in __alloc_pages_high_priority Kautuk Consul
2012-03-06  3:16 ` Minchan Kim

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