Patch]Add strict_goal parameter to __alloc_bootmem_core
Subsystems (3)
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.
arch/x86/mm/numa_64.c +1 -1
@@ -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 }
include/linux/bootmem.h +2 -1
@@ -58,7 +58,8 @@ extern void *__alloc_bootmem_core(structunsigned 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);
mm/bootmem.c +17 -12
@@ -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(unvoid *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(unsignlist_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 ); }
On (08/11/07 08:51), Zou Nan hai didst pronounce:
Quoted 7 lines
Resend the patch for more people to review.
If
__alloc_bootmem_corewas 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.
For the sake of the changelog, why?
Quoted 17 lines
This patch introduce a
strict_goalparameter to__alloc_bootmem_core,If
strict_goalis set,__alloc_bootmem_corewill return NULL to indicate it can't allocate memory above that goal.Note we do not scan from
last_successifstrict_goalis set, it will scan from the beginning of the goal instead
We skip this optimization to keep the code simple becausestrict_goalis not supposed to be used in hot path.Signed-off-by Zou Nan hai <[email protected]>Signed-off-by Suresh Siddha <[email protected]>diff -Nraup
a/arch/x86/mm/numa_64.cb/arch/x86/mm/numa_64.c
arch/x86/mm/numa_64.c void __init setup_node_zones(int nodeid) · line 250
Quoted 5 lines
arch/x86/mm/numa_64.c +1
-1@@ -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 );
Magic number alert. That 1 needs to be #defined
#define BOOTMEM_STRICT_GOAL 1
or something. I know it's semi-obvious from the parameter name what it means but even so. The #define will make it easier for someone to convert that parameter into a flags bitmap later like gfp flags if that ever became necessary.
Quoted 20 lines
arch/x86/mm/numa_64.c +0
-0#endif }diff -Nraup
a/include/linux/bootmem.hb/include/linux/bootmem.hinclude/linux/bootmem.h +2
-1@@ -58,7 +58,8 @@ extern void *__alloc_bootmem_core(structunsigned 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.cb/mm/bootmem.c
mm/bootmem.c static void __init free_bootmem_core(boo · line 182
Quoted 5 lines
mm/bootmem.c +1
-1@@ -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)
80 char limit violation there. It's not a hard limit but this doesn't look like a case where the code is much better looking by breaking it.
mm/bootmem.c __alloc_bootmem_core(struct bootmem_data · line 216
Quoted 12 lines
mm/bootmem.c +2
-3{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. +*/
Tabs vs spaces there.
mm/bootmem.c __alloc_bootmem_core(struct bootmem_data · line 224
Quoted 9 lines
mm/bootmem.c +6
-1+ + 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)))
Aside, it's not obvious why there is a check that looks like
!limit || (limit ...)
if it's not one, it's the other surely :/
mm/bootmem.c __alloc_bootmem_core(struct bootmem_data · line 225
Quoted 1 line
mm/bootmem.c +0
-0preferred = bdata->last_success;
Not clear at all why strict_goal is checked here.
mm/bootmem.c __alloc_bootmem_core(struct bootmem_data · line 227
Quoted 4 lines
mm/bootmem.c +2
-2- }else - preferred =0 ; + }else if (strict_goal) +return NULL ;
tabs vs spaces again. Consider using checkpatch.pl. Its report is not something that has to be strictly obeyed in all cases but for simply styling issues like this, it is almost always right.
That aside, this is pretty ugly lookin and it's not clear why setting no goal and asking for strict_goal results in NULL being returned. Maybe I am missing the point and this needs commenting. Minimally, multi-statement lines are frowned upon. For example
if (condition)
x++;
is preferred to
if (condition) x++;
While the current code could be nicer looking, I don't see why it needs to change at all. If goal is specified, preferred should start as a higher value than goal whether strict_goal is set or not. Even if you want to avoid last_success, it's easier to read
/* * Start searching from last_success unless strict_goal is * set or the last allocation was over the upper limit. If * we are being strict about allocating above goal, we will * assume the caller does not mind a more expensive search */ if (!strict_goal && bdata->last_success >= preferred) if (!limit || limit > bdata->last_success) preferred = bdata->last_success;
or something.
mm/bootmem.c restart_scan: · line 255
Quoted 10 lines
mm/bootmem.c +2
-1+ } 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) {
again, not immediately clear why strict_goal is checked here.
mm/bootmem.c void * __init __alloc_bootmem_nopanic(un · line 429
Quoted 9 lines
mm/bootmem.c +1
-1preferred = offset; goto restart_scan; }@@ -421,7 +426,7 @@ void * __init __alloc_bootmem_nopanic(unvoid *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 );
Magic number alert again - use BOOTMEM_ANY_ADDRESS or something. I suck at naming but once you select a, someone with better naming taste will complain and give better suggestions.
Quoted 29 lines
mm/bootmem.c +3
-3if (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(unsignlist_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 ); }
Signature · 4 lines
-- Mel Gorman Part-time Phd Student Linux Technology Center University of Limerick IBM Dublin Software Lab