public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Zou Nan hai <nanhai.zou@intel.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Greg KH <greg@kroah.com>, Dave Jones <davej@redhat.com>,
	Martin Ebourne <fedora@ebourne.me.uk>,
	Suresh Siddha <suresh.b.siddha@intel.com>,
	Andi Kleen <ak@suse.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	Christoph Lameter <clameter@sgi.com>, Mel Gorman <mel@csn.ul.ie>,
	Andy Whitcroft <apw@shadowen.org>
Subject: Patch]Add strict_goal parameter to __alloc_bootmem_core
Date: 08 Nov 2007 08:51:50 +0800	[thread overview]
Message-ID: <1194483110.3046.1469.camel@linux-znh> (raw)

Resend the patch for more people to review.

If __alloc_bootmem_core was given a goal, it will first try to allocate
memory above that goal. If failed, it will try from the low pages.

Sometimes we don't want this behavior, we want the goal to be strict.

This patch introduce a strict_goal parameter to __alloc_bootmem_core, 

If strict_goal is set, __alloc_bootmem_core will return NULL to indicate
it can't allocate memory above that goal.

Note we do not scan from last_success if strict_goal is set, it will
scan from the beginning of the goal instead
We skip this optimization to keep the code simple because strict_goal is
not supposed to be used in hot path.

Signed-off-by: Zou Nan hai <nanhai.zou@intel.com>
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>

diff -Nraup a/arch/x86/mm/numa_64.c b/arch/x86/mm/numa_64.c
--- a/arch/x86/mm/numa_64.c	2007-10-24 11:50:57.000000000 +0800
+++ b/arch/x86/mm/numa_64.c	2007-11-07 13:06:50.000000000 +0800
@@ -247,7 +247,7 @@ void __init setup_node_zones(int nodeid)
 		__alloc_bootmem_core(NODE_DATA(nodeid)->bdata, 
 				memmapsize, SMP_CACHE_BYTES, 
 				round_down(limit - memmapsize, PAGE_SIZE), 
-				limit);
+				limit, 1);
 #endif
 } 
 
diff -Nraup a/include/linux/bootmem.h b/include/linux/bootmem.h
--- a/include/linux/bootmem.h	2007-11-07 13:06:35.000000000 +0800
+++ b/include/linux/bootmem.h	2007-11-07 13:06:04.000000000 +0800
@@ -58,7 +58,8 @@ extern void *__alloc_bootmem_core(struct
 				  unsigned long size,
 				  unsigned long align,
 				  unsigned long goal,
-				  unsigned long limit);
+				  unsigned long limit,
+				  int strict_goal);
 
 #ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
 extern void reserve_bootmem(unsigned long addr, unsigned long size);
diff -Nraup a/mm/bootmem.c b/mm/bootmem.c
--- a/mm/bootmem.c	2007-11-07 13:06:35.000000000 +0800
+++ b/mm/bootmem.c	2007-11-07 13:06:18.000000000 +0800
@@ -179,7 +179,7 @@ static void __init free_bootmem_core(boo
  */
 void * __init
 __alloc_bootmem_core(struct bootmem_data *bdata, unsigned long size,
-	      unsigned long align, unsigned long goal, unsigned long limit)
+	      unsigned long align, unsigned long goal, unsigned long limit, int strict_goal)
 {
 	unsigned long offset, remaining_size, areasize, preferred;
 	unsigned long i, start = 0, incr, eidx, end_pfn;
@@ -212,15 +212,20 @@ __alloc_bootmem_core(struct bootmem_data
 	/*
 	 * We try to allocate bootmem pages above 'goal'
 	 * first, then we try to allocate lower pages.
-	 */
-	if (goal && goal >= bdata->node_boot_start && PFN_DOWN(goal) < end_pfn) {
-		preferred = goal - bdata->node_boot_start;
+	 * if the goal is not strict.
+         */
+
+	preferred = 0;
+	if (goal) {
+		if (goal >= bdata->node_boot_start && PFN_DOWN(goal) < end_pfn) {
+			preferred = goal - bdata->node_boot_start;
 
 		if (bdata->last_success >= preferred)
-			if (!limit || (limit && limit > bdata->last_success))
+			if (!strict_goal && (!limit || (limit && limit > bdata->last_success)))
 				preferred = bdata->last_success;
-	} else
-		preferred = 0;
+		} else if (strict_goal)
+                        return NULL;
+	}
 
 	preferred = PFN_DOWN(ALIGN(preferred, align)) + offset;
 	areasize = (size + PAGE_SIZE-1) / PAGE_SIZE;
@@ -247,7 +252,7 @@ restart_scan:
 		i = ALIGN(j, incr);
 	}
 
-	if (preferred > offset) {
+	if (preferred > offset && !strict_goal) {
 		preferred = offset;
 		goto restart_scan;
 	}
@@ -421,7 +426,7 @@ void * __init __alloc_bootmem_nopanic(un
 	void *ptr;
 
 	list_for_each_entry(bdata, &bdata_list, list) {
-		ptr = __alloc_bootmem_core(bdata, size, align, goal, 0);
+		ptr = __alloc_bootmem_core(bdata, size, align, goal, 0, 0);
 		if (ptr)
 			return ptr;
 	}
@@ -449,7 +454,7 @@ void * __init __alloc_bootmem_node(pg_da
 {
 	void *ptr;
 
-	ptr = __alloc_bootmem_core(pgdat->bdata, size, align, goal, 0);
+	ptr = __alloc_bootmem_core(pgdat->bdata, size, align, goal, 0, 0);
 	if (ptr)
 		return ptr;
 
@@ -468,7 +473,7 @@ void * __init __alloc_bootmem_low(unsign
 
 	list_for_each_entry(bdata, &bdata_list, list) {
 		ptr = __alloc_bootmem_core(bdata, size, align, goal,
-						ARCH_LOW_ADDRESS_LIMIT);
+						ARCH_LOW_ADDRESS_LIMIT, 0);
 		if (ptr)
 			return ptr;
 	}
@@ -485,5 +490,5 @@ void * __init __alloc_bootmem_low_node(p
 				       unsigned long align, unsigned long goal)
 {
 	return __alloc_bootmem_core(pgdat->bdata, size, align, goal,
-				    ARCH_LOW_ADDRESS_LIMIT);
+				    ARCH_LOW_ADDRESS_LIMIT, 0);
 }


             reply	other threads:[~2007-11-08  0:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-08  0:51 Zou Nan hai [this message]
2007-11-08 12:19 ` Patch]Add strict_goal parameter to __alloc_bootmem_core Mel Gorman

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=1194483110.3046.1469.camel@linux-znh \
    --to=nanhai.zou@intel.com \
    --cc=ak@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=apw@shadowen.org \
    --cc=clameter@sgi.com \
    --cc=davej@redhat.com \
    --cc=fedora@ebourne.me.uk \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mel@csn.ul.ie \
    --cc=suresh.b.siddha@intel.com \
    --cc=torvalds@linux-foundation.org \
    /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