* [PATCH] Clean up the bootmem allocator
@ 2006-06-26 13:11 Franck Bui-Huu
2006-06-26 17:58 ` Dave Hansen
0 siblings, 1 reply; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-26 13:11 UTC (permalink / raw)
To: Andrew Morton, Mel Gorman, Dave Hansen; +Cc: Linux Kernel Mailing List
This patch does _only_ some cleanup in the bootmem allocator by:
- following the kernel coding style conventions
- using pfn/page conversion macros
- removing some not needed parentheses
- removing some useless included headers
- limiting to 80 column width
It also removes __init tags in the header file and hopefully make it
easier to read.
Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
---
include/linux/bootmem.h | 101 ++++++++++++++----------
mm/bootmem.c | 195 ++++++++++++++++++++++++++---------------------
2 files changed, 167 insertions(+), 129 deletions(-)
diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
index da2d107..dd733ee 100644
--- a/include/linux/bootmem.h
+++ b/include/linux/bootmem.h
@@ -41,45 +41,64 @@ typedef struct bootmem_data {
struct list_head list;
} bootmem_data_t;
-extern unsigned long __init bootmem_bootmap_pages (unsigned long);
-extern unsigned long __init init_bootmem (unsigned long addr, unsigned long memend);
-extern void __init free_bootmem (unsigned long addr, unsigned long size);
-extern void * __init __alloc_bootmem (unsigned long size, unsigned long align, unsigned long goal);
-extern void * __init __alloc_bootmem_nopanic (unsigned long size, unsigned long align, unsigned long goal);
-extern void * __init __alloc_bootmem_low(unsigned long size,
- unsigned long align,
- unsigned long goal);
-extern void * __init __alloc_bootmem_low_node(pg_data_t *pgdat,
- unsigned long size,
- unsigned long align,
- unsigned long goal);
-extern void * __init __alloc_bootmem_core(struct bootmem_data *bdata,
- unsigned long size, unsigned long align, unsigned long goal,
- unsigned long limit);
+extern unsigned long bootmem_bootmap_pages(unsigned long);
+extern unsigned long init_bootmem(unsigned long addr, unsigned long memend);
+extern void free_bootmem(unsigned long addr, unsigned long size);
+extern void * __alloc_bootmem(unsigned long size,
+ unsigned long align,
+ unsigned long goal);
+extern void * __alloc_bootmem_nopanic(unsigned long size,
+ unsigned long align,
+ unsigned long goal);
+extern void * __alloc_bootmem_low(unsigned long size,
+ unsigned long align,
+ unsigned long goal);
+extern void * __alloc_bootmem_low_node(pg_data_t *pgdat,
+ unsigned long size,
+ unsigned long align,
+ unsigned long goal);
+extern void * __alloc_bootmem_core(struct bootmem_data *bdata,
+ unsigned long size,
+ unsigned long align,
+ unsigned long goal,
+ unsigned long limit);
+
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
-extern void __init reserve_bootmem (unsigned long addr, unsigned long size);
+extern void reserve_bootmem(unsigned long addr, unsigned long size);
#define alloc_bootmem(x) \
- __alloc_bootmem((x), SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
+ __alloc_bootmem(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
#define alloc_bootmem_low(x) \
- __alloc_bootmem_low((x), SMP_CACHE_BYTES, 0)
+ __alloc_bootmem_low(x, SMP_CACHE_BYTES, 0)
#define alloc_bootmem_pages(x) \
- __alloc_bootmem((x), PAGE_SIZE, __pa(MAX_DMA_ADDRESS))
+ __alloc_bootmem(x, PAGE_SIZE, __pa(MAX_DMA_ADDRESS))
#define alloc_bootmem_low_pages(x) \
- __alloc_bootmem_low((x), PAGE_SIZE, 0)
+ __alloc_bootmem_low(x, PAGE_SIZE, 0)
#endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */
-extern unsigned long __init free_all_bootmem (void);
-extern void * __init __alloc_bootmem_node (pg_data_t *pgdat, unsigned long size, unsigned long align, unsigned long goal);
-extern unsigned long __init init_bootmem_node (pg_data_t *pgdat, unsigned long freepfn, unsigned long startpfn, unsigned long endpfn);
-extern void __init reserve_bootmem_node (pg_data_t *pgdat, unsigned long physaddr, unsigned long size);
-extern void __init free_bootmem_node (pg_data_t *pgdat, unsigned long addr, unsigned long size);
-extern unsigned long __init free_all_bootmem_node (pg_data_t *pgdat);
+
+extern unsigned long free_all_bootmem(void);
+extern unsigned long free_all_bootmem_node(pg_data_t *pgdat);
+extern void * __alloc_bootmem_node(pg_data_t *pgdat,
+ unsigned long size,
+ unsigned long align,
+ unsigned long goal);
+extern unsigned long init_bootmem_node(pg_data_t *pgdat,
+ unsigned long freepfn,
+ unsigned long startpfn,
+ unsigned long endpfn);
+extern void reserve_bootmem_node(pg_data_t *pgdat,
+ unsigned long physaddr,
+ unsigned long size);
+extern void free_bootmem_node(pg_data_t *pgdat,
+ unsigned long addr,
+ unsigned long size);
+
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
#define alloc_bootmem_node(pgdat, x) \
- __alloc_bootmem_node((pgdat), (x), SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
+ __alloc_bootmem_node(pgdat, x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
#define alloc_bootmem_pages_node(pgdat, x) \
- __alloc_bootmem_node((pgdat), (x), PAGE_SIZE, __pa(MAX_DMA_ADDRESS))
+ __alloc_bootmem_node(pgdat, x, PAGE_SIZE, __pa(MAX_DMA_ADDRESS))
#define alloc_bootmem_low_pages_node(pgdat, x) \
- __alloc_bootmem_low_node((pgdat), (x), PAGE_SIZE, 0)
+ __alloc_bootmem_low_node(pgdat, x, PAGE_SIZE, 0)
#endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */
#ifdef CONFIG_HAVE_ARCH_ALLOC_REMAP
@@ -89,19 +108,19 @@ static inline void *alloc_remap(int nid,
{
return NULL;
}
-#endif
+#endif /* CONFIG_HAVE_ARCH_ALLOC_REMAP */
-extern unsigned long __initdata nr_kernel_pages;
-extern unsigned long __initdata nr_all_pages;
+extern unsigned long nr_kernel_pages;
+extern unsigned long nr_all_pages;
-extern void *__init alloc_large_system_hash(const char *tablename,
- unsigned long bucketsize,
- unsigned long numentries,
- int scale,
- int flags,
- unsigned int *_hash_shift,
- unsigned int *_hash_mask,
- unsigned long limit);
+extern void *alloc_large_system_hash(const char *tablename,
+ unsigned long bucketsize,
+ unsigned long numentries,
+ int scale,
+ int flags,
+ unsigned int *_hash_shift,
+ unsigned int *_hash_mask,
+ unsigned long limit);
#define HASH_HIGHMEM 0x00000001 /* Consider highmem? */
#define HASH_EARLY 0x00000002 /* Allocating during early boot? */
@@ -114,7 +133,7 @@ #define HASHDIST_DEFAULT 1
#else
#define HASHDIST_DEFAULT 0
#endif
-extern int __initdata hashdist; /* Distribute hashes across NUMA nodes? */
+extern int hashdist; /* Distribute hashes across NUMA nodes? */
#endif /* _LINUX_BOOTMEM_H */
diff --git a/mm/bootmem.c b/mm/bootmem.c
index d213fed..a8fb272 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -8,17 +8,14 @@
* free memory collector. It's used to deal with reserved
* system memory and memory holes as well.
*/
-
-#include <linux/mm.h>
-#include <linux/kernel_stat.h>
-#include <linux/swap.h>
-#include <linux/interrupt.h>
#include <linux/init.h>
-#include <linux/bootmem.h>
#include <linux/mmzone.h>
+#include <linux/bootmem.h>
+#include <linux/pfn.h>
#include <linux/module.h>
-#include <asm/dma.h>
+
#include <asm/io.h>
+
#include "internal.h"
/*
@@ -43,7 +40,7 @@ unsigned long saved_max_pfn;
#endif
/* return the number of _pages_ that will be allocated for the boot bitmap */
-unsigned long __init bootmem_bootmap_pages (unsigned long pages)
+unsigned long __init bootmem_bootmap_pages(unsigned long pages)
{
unsigned long mapsize;
@@ -56,7 +53,7 @@ unsigned long __init bootmem_bootmap_pag
/*
* link bdata in order
*/
-static void link_bootmem(bootmem_data_t *bdata)
+static void __init link_bootmem(bootmem_data_t *bdata)
{
bootmem_data_t *ent;
if (list_empty(&bdata_list)) {
@@ -71,22 +68,32 @@ static void link_bootmem(bootmem_data_t
}
}
list_add_tail(&bdata->list, &bdata_list);
- return;
}
+/*
+ * Given an initialised bdata, it returns the size of the boot bitmap
+ */
+static unsigned long __init get_mapsize(bootmem_data_t *bdata)
+{
+ unsigned long mapsize;
+ unsigned long start = PFN_DOWN(bdata->node_boot_start);
+ unsigned long end = bdata->node_low_pfn;
+
+ mapsize = ((end - start) + 7) / 8;
+ return ALIGN(mapsize, sizeof(long));
+}
/*
* Called once to set up the allocator itself.
*/
-static unsigned long __init init_bootmem_core (pg_data_t *pgdat,
+static unsigned long __init init_bootmem_core(pg_data_t *pgdat,
unsigned long mapstart, unsigned long start, unsigned long end)
{
bootmem_data_t *bdata = pgdat->bdata;
- unsigned long mapsize = ((end - start)+7)/8;
+ unsigned long mapsize;
- mapsize = ALIGN(mapsize, sizeof(long));
- bdata->node_bootmem_map = phys_to_virt(mapstart << PAGE_SHIFT);
- bdata->node_boot_start = (start << PAGE_SHIFT);
+ bdata->node_bootmem_map = phys_to_virt(PFN_PHYS(mapstart));
+ bdata->node_boot_start = PFN_PHYS(start);
bdata->node_low_pfn = end;
link_bootmem(bdata);
@@ -94,6 +101,7 @@ static unsigned long __init init_bootmem
* Initially all pages are reserved - setup_arch() has to
* register free RAM areas explicitly.
*/
+ mapsize = get_mapsize(bdata);
memset(bdata->node_bootmem_map, 0xff, mapsize);
return mapsize;
@@ -104,22 +112,22 @@ static unsigned long __init init_bootmem
* might be used for boot-time allocations - or it might get added
* to the free page pool later on.
*/
-static void __init reserve_bootmem_core(bootmem_data_t *bdata, unsigned long addr, unsigned long size)
+static void __init reserve_bootmem_core(bootmem_data_t *bdata, unsigned long addr,
+ unsigned long size)
{
+ unsigned long sidx, eidx;
unsigned long i;
+
/*
* round up, partially reserved pages are considered
* fully reserved.
*/
- unsigned long sidx = (addr - bdata->node_boot_start)/PAGE_SIZE;
- unsigned long eidx = (addr + size - bdata->node_boot_start +
- PAGE_SIZE-1)/PAGE_SIZE;
- unsigned long end = (addr + size + PAGE_SIZE-1)/PAGE_SIZE;
-
BUG_ON(!size);
- BUG_ON(sidx >= eidx);
- BUG_ON((addr >> PAGE_SHIFT) >= bdata->node_low_pfn);
- BUG_ON(end > bdata->node_low_pfn);
+ BUG_ON(PFN_DOWN(addr) >= bdata->node_low_pfn);
+ BUG_ON(PFN_UP(addr + size) > bdata->node_low_pfn);
+
+ sidx = PFN_DOWN(addr - bdata->node_boot_start);
+ eidx = PFN_UP(addr + size - bdata->node_boot_start);
for (i = sidx; i < eidx; i++)
if (test_and_set_bit(i, bdata->node_bootmem_map)) {
@@ -129,20 +137,18 @@ #endif
}
}
-static void __init free_bootmem_core(bootmem_data_t *bdata, unsigned long addr, unsigned long size)
+static void __init free_bootmem_core(bootmem_data_t *bdata, unsigned long addr,
+ unsigned long size)
{
+ unsigned long sidx, eidx;
unsigned long i;
- unsigned long start;
+
/*
* round down end of usable mem, partially free pages are
* considered reserved.
*/
- unsigned long sidx;
- unsigned long eidx = (addr + size - bdata->node_boot_start)/PAGE_SIZE;
- unsigned long end = (addr + size)/PAGE_SIZE;
-
BUG_ON(!size);
- BUG_ON(end > bdata->node_low_pfn);
+ BUG_ON(PFN_DOWN(addr + size) > bdata->node_low_pfn);
if (addr < bdata->last_success)
bdata->last_success = addr;
@@ -150,8 +156,8 @@ static void __init free_bootmem_core(boo
/*
* Round up the beginning of the address.
*/
- start = (addr + PAGE_SIZE-1) / PAGE_SIZE;
- sidx = start - (bdata->node_boot_start/PAGE_SIZE);
+ sidx = PFN_UP(addr) - PFN_DOWN(bdata->node_boot_start);
+ eidx = PFN_DOWN(addr + size - bdata->node_boot_start);
for (i = sidx; i < eidx; i++) {
if (unlikely(!test_and_clear_bit(i, bdata->node_bootmem_map)))
@@ -176,11 +182,13 @@ void * __init
__alloc_bootmem_core(struct bootmem_data *bdata, unsigned long size,
unsigned long align, unsigned long goal, unsigned long limit)
{
- unsigned long offset, remaining_size, areasize, preferred;
- unsigned long i, start = 0, incr, eidx, end_pfn = bdata->node_low_pfn;
+ unsigned long offset, areasize, preferred;
+ unsigned long i, start, incr, eidx;
+ unsigned long end_pfn;
+ unsigned long remaining_size;
void *ret;
- if(!size) {
+ if (!size) {
printk("__alloc_bootmem_core(): zero-sized request\n");
BUG();
}
@@ -189,23 +197,22 @@ __alloc_bootmem_core(struct bootmem_data
if (limit && bdata->node_boot_start >= limit)
return NULL;
- limit >>=PAGE_SHIFT;
+ end_pfn = bdata->node_low_pfn;
+ limit = PFN_DOWN(limit);
if (limit && end_pfn > limit)
end_pfn = limit;
- eidx = end_pfn - (bdata->node_boot_start >> PAGE_SHIFT);
+ eidx = end_pfn - PFN_DOWN(bdata->node_boot_start);
offset = 0;
- if (align &&
- (bdata->node_boot_start & (align - 1UL)) != 0)
- offset = (align - (bdata->node_boot_start & (align - 1UL)));
- offset >>= PAGE_SHIFT;
+ if (align && (bdata->node_boot_start & (align - 1UL)) != 0)
+ offset = align - (bdata->node_boot_start & (align - 1UL));
+ offset = PFN_DOWN(offset);
/*
* We try to allocate bootmem pages above 'goal'
* first, then we try to allocate lower pages.
*/
- if (goal && (goal >= bdata->node_boot_start) &&
- ((goal >> PAGE_SHIFT) < end_pfn)) {
+ if (goal && goal >= bdata->node_boot_start && PFN_DOWN(goal) < end_pfn) {
preferred = goal - bdata->node_boot_start;
if (bdata->last_success >= preferred)
@@ -214,11 +221,11 @@ __alloc_bootmem_core(struct bootmem_data
} else
preferred = 0;
- preferred = ALIGN(preferred, align) >> PAGE_SHIFT;
- preferred += offset;
- areasize = (size+PAGE_SIZE-1)/PAGE_SIZE;
+ preferred = PFN_DOWN(ALIGN(preferred, align)) + offset;
+ areasize = (size + PAGE_SIZE-1) / PAGE_SIZE;
incr = align >> PAGE_SHIFT ? : 1;
+ start = 0;
restart_scan:
for (i = preferred; i < eidx; i += incr) {
unsigned long j;
@@ -231,7 +238,7 @@ restart_scan:
for (j = i + 1; j < i + areasize; ++j) {
if (j >= eidx)
goto fail_block;
- if (test_bit (j, bdata->node_bootmem_map))
+ if (test_bit(j, bdata->node_bootmem_map))
goto fail_block;
}
start = i;
@@ -247,7 +254,7 @@ restart_scan:
return NULL;
found:
- bdata->last_success = start << PAGE_SHIFT;
+ bdata->last_success = PFN_PHYS(start);
BUG_ON(start >= eidx);
/*
@@ -259,19 +266,21 @@ found:
bdata->last_offset && bdata->last_pos+1 == start) {
offset = ALIGN(bdata->last_offset, align);
BUG_ON(offset > PAGE_SIZE);
- remaining_size = PAGE_SIZE-offset;
+ remaining_size = PAGE_SIZE - offset;
if (size < remaining_size) {
areasize = 0;
/* last_pos unchanged */
- bdata->last_offset = offset+size;
- ret = phys_to_virt(bdata->last_pos*PAGE_SIZE + offset +
- bdata->node_boot_start);
+ bdata->last_offset = offset + size;
+ ret = phys_to_virt(bdata->last_pos * PAGE_SIZE +
+ offset +
+ bdata->node_boot_start);
} else {
remaining_size = size - remaining_size;
- areasize = (remaining_size+PAGE_SIZE-1)/PAGE_SIZE;
- ret = phys_to_virt(bdata->last_pos*PAGE_SIZE + offset +
- bdata->node_boot_start);
- bdata->last_pos = start+areasize-1;
+ areasize = (remaining_size + PAGE_SIZE-1) / PAGE_SIZE;
+ ret = phys_to_virt(bdata->last_pos * PAGE_SIZE +
+ offset +
+ bdata->node_boot_start);
+ bdata->last_pos = start + areasize - 1;
bdata->last_offset = remaining_size;
}
bdata->last_offset &= ~PAGE_MASK;
@@ -284,7 +293,7 @@ found:
/*
* Reserve the area now:
*/
- for (i = start; i < start+areasize; i++)
+ for (i = start; i < start + areasize; i++)
if (unlikely(test_and_set_bit(i, bdata->node_bootmem_map)))
BUG();
memset(ret, 0, size);
@@ -305,8 +314,8 @@ static unsigned long __init free_all_boo
count = 0;
/* first extant page of the node */
- pfn = bdata->node_boot_start >> PAGE_SHIFT;
- idx = bdata->node_low_pfn - (bdata->node_boot_start >> PAGE_SHIFT);
+ pfn = PFN_DOWN(bdata->node_boot_start);
+ idx = bdata->node_low_pfn - pfn;
map = bdata->node_bootmem_map;
/* Check physaddr is O(LOG2(BITS_PER_LONG)) page aligned */
if (bdata->node_boot_start == 0 ||
@@ -335,7 +344,7 @@ static unsigned long __init free_all_boo
}
}
} else {
- i+=BITS_PER_LONG;
+ i += BITS_PER_LONG;
}
pfn += BITS_PER_LONG;
}
@@ -347,9 +356,10 @@ static unsigned long __init free_all_boo
*/
page = virt_to_page(bdata->node_bootmem_map);
count = 0;
- for (i = 0; i < ((bdata->node_low_pfn-(bdata->node_boot_start >> PAGE_SHIFT))/8 + PAGE_SIZE-1)/PAGE_SIZE; i++,page++) {
- count++;
+ idx = (get_mapsize(bdata) + PAGE_SIZE-1) >> PAGE_SHIFT;
+ for (i = 0; i < idx; i++, page++) {
__free_pages_bootmem(page, 0);
+ count++;
}
total += count;
bdata->node_bootmem_map = NULL;
@@ -357,64 +367,72 @@ static unsigned long __init free_all_boo
return total;
}
-unsigned long __init init_bootmem_node (pg_data_t *pgdat, unsigned long freepfn, unsigned long startpfn, unsigned long endpfn)
+unsigned long __init init_bootmem_node(pg_data_t *pgdat, unsigned long freepfn,
+ unsigned long startpfn, unsigned long endpfn)
{
- return(init_bootmem_core(pgdat, freepfn, startpfn, endpfn));
+ return init_bootmem_core(pgdat, freepfn, startpfn, endpfn);
}
-void __init reserve_bootmem_node (pg_data_t *pgdat, unsigned long physaddr, unsigned long size)
+void __init reserve_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
+ unsigned long size)
{
reserve_bootmem_core(pgdat->bdata, physaddr, size);
}
-void __init free_bootmem_node (pg_data_t *pgdat, unsigned long physaddr, unsigned long size)
+void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
+ unsigned long size)
{
free_bootmem_core(pgdat->bdata, physaddr, size);
}
-unsigned long __init free_all_bootmem_node (pg_data_t *pgdat)
+unsigned long __init free_all_bootmem_node(pg_data_t *pgdat)
{
- return(free_all_bootmem_core(pgdat));
+ return free_all_bootmem_core(pgdat);
}
-unsigned long __init init_bootmem (unsigned long start, unsigned long pages)
+unsigned long __init init_bootmem(unsigned long start, unsigned long pages)
{
max_low_pfn = pages;
min_low_pfn = start;
- return(init_bootmem_core(NODE_DATA(0), start, 0, pages));
+ return init_bootmem_core(NODE_DATA(0), start, 0, pages);
}
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
-void __init reserve_bootmem (unsigned long addr, unsigned long size)
+void __init reserve_bootmem(unsigned long addr, unsigned long size)
{
reserve_bootmem_core(NODE_DATA(0)->bdata, addr, size);
}
#endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */
-void __init free_bootmem (unsigned long addr, unsigned long size)
+void __init free_bootmem(unsigned long addr, unsigned long size)
{
free_bootmem_core(NODE_DATA(0)->bdata, addr, size);
}
-unsigned long __init free_all_bootmem (void)
+unsigned long __init free_all_bootmem(void)
{
- return(free_all_bootmem_core(NODE_DATA(0)));
+ return free_all_bootmem_core(NODE_DATA(0));
}
-void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align, unsigned long goal)
+void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align,
+ unsigned long goal)
{
bootmem_data_t *bdata;
void *ptr;
- list_for_each_entry(bdata, &bdata_list, list)
- if ((ptr = __alloc_bootmem_core(bdata, size, align, goal, 0)))
- return(ptr);
+ list_for_each_entry(bdata, &bdata_list, list) {
+ ptr = __alloc_bootmem_core(bdata, size, align, goal, 0);
+ if (ptr)
+ return ptr;
+ }
return NULL;
}
-void * __init __alloc_bootmem(unsigned long size, unsigned long align, unsigned long goal)
+void * __init __alloc_bootmem(unsigned long size, unsigned long align,
+ unsigned long goal)
{
void *mem = __alloc_bootmem_nopanic(size,align,goal);
+
if (mem)
return mem;
/*
@@ -426,8 +444,8 @@ void * __init __alloc_bootmem(unsigned l
}
-void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size, unsigned long align,
- unsigned long goal)
+void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size,
+ unsigned long align, unsigned long goal)
{
void *ptr;
@@ -440,16 +458,17 @@ void * __init __alloc_bootmem_node(pg_da
#define LOW32LIMIT 0xffffffff
-void * __init __alloc_bootmem_low(unsigned long size, unsigned long align, unsigned long goal)
+void * __init __alloc_bootmem_low(unsigned long size, unsigned long align,
+ unsigned long goal)
{
bootmem_data_t *bdata;
void *ptr;
- list_for_each_entry(bdata, &bdata_list, list)
- if ((ptr = __alloc_bootmem_core(bdata, size,
- align, goal, LOW32LIMIT)))
- return(ptr);
-
+ list_for_each_entry(bdata, &bdata_list, list) {
+ ptr = __alloc_bootmem_core(bdata, size, align, goal, LOW32LIMIT);
+ if (ptr)
+ return ptr;
+ }
/*
* Whoops, we cannot satisfy the allocation request.
*/
--
1.4.0.g64e8
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH] Clean up the bootmem allocator
2006-06-26 13:11 [PATCH] Clean up the bootmem allocator Franck Bui-Huu
@ 2006-06-26 17:58 ` Dave Hansen
2006-06-26 18:10 ` Andrew Morton
` (9 more replies)
0 siblings, 10 replies; 21+ messages in thread
From: Dave Hansen @ 2006-06-26 17:58 UTC (permalink / raw)
To: Franck; +Cc: Andrew Morton, Mel Gorman, Linux Kernel Mailing List
On Mon, 2006-06-26 at 15:11 +0200, Franck Bui-Huu wrote:
> This patch does _only_ some cleanup in the bootmem allocator by:
...
> include/linux/bootmem.h | 101 ++++++++++++++----------
> mm/bootmem.c | 195 ++++++++++++++++++++++++++---------------------
> 2 files changed, 167 insertions(+), 129 deletions(-)
I'm always suspicious of "cleanups" which add more code than they remove ;)
> - following the kernel coding style conventions
Above everything else, this probably needs to be in its very own patch,
where it is trivially verifiable.
> - using pfn/page conversion macros
> - removing some not needed parentheses
> - removing some useless included headers
> - limiting to 80 column width
In general, I think there is some good stuff in here. However, instead
of concentrating on "kernel coding style conventions" and numeric (80
column) guidelines, I really hope that people consider _readability_
when modifying this code. I don't think this patch makes the code much
more readable.
That said, there are some nice helper function in here. Would you be
able to break this patch up into maybe 10 or 15 smaller patches? I have
the feeling it will be easier to find the good bits then.
> It also removes __init tags in the header file and hopefully make it
> easier to read.
I think I kinda like when these are present in headers. I usually
stumble across the header declarations before I do the ones in the .c
files, and it is always nice to see the header visually _matching_
the .c file, and how the variable is intended to be used
-- Dave
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Clean up the bootmem allocator
2006-06-26 17:58 ` Dave Hansen
@ 2006-06-26 18:10 ` Andrew Morton
2006-06-27 8:23 ` Franck Bui-Huu
` (8 subsequent siblings)
9 siblings, 0 replies; 21+ messages in thread
From: Andrew Morton @ 2006-06-26 18:10 UTC (permalink / raw)
To: Dave Hansen; +Cc: vagabon.xyz, mel, linux-kernel
On Mon, 26 Jun 2006 10:58:11 -0700
Dave Hansen <haveblue@us.ibm.com> wrote:
> > It also removes __init tags in the header file and hopefully make it
> > easier to read.
>
> I think I kinda like when these are present in headers. I usually
> stumble across the header declarations before I do the ones in the .c
> files, and it is always nice to see the header visually _matching_
> the .c file, and how the variable is intended to be used
__init in headers is pretty useless because the compiler doesn't check it,
and they get out of sync relatively frequently. So it you see an __init
in a header file, it's quite unreliable and you need to check the
definition anyway.
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH] Clean up the bootmem allocator
2006-06-26 17:58 ` Dave Hansen
2006-06-26 18:10 ` Andrew Morton
@ 2006-06-27 8:23 ` Franck Bui-Huu
2006-06-27 12:53 ` [PATCH 0/7] " Franck Bui-Huu
` (7 subsequent siblings)
9 siblings, 0 replies; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-27 8:23 UTC (permalink / raw)
To: Dave Hansen; +Cc: Franck, Andrew Morton, Mel Gorman, Linux Kernel Mailing List
Dave Hansen wrote:
> On Mon, 2006-06-26 at 15:11 +0200, Franck Bui-Huu wrote:
>> This patch does _only_ some cleanup in the bootmem allocator by:
> ...
>> include/linux/bootmem.h | 101 ++++++++++++++----------
>> mm/bootmem.c | 195 ++++++++++++++++++++++++++---------------------
>> 2 files changed, 167 insertions(+), 129 deletions(-)
>
> I'm always suspicious of "cleanups" which add more code than they remove ;)
>
it's mainly due to the "80 columns limit" changes
>> - following the kernel coding style conventions
>
> Above everything else, this probably needs to be in its very own patch,
> where it is trivially verifiable.
>
>> - using pfn/page conversion macros
>> - removing some not needed parentheses
>> - removing some useless included headers
>> - limiting to 80 column width
>
> In general, I think there is some good stuff in here. However, instead
> of concentrating on "kernel coding style conventions" and numeric (80
> column) guidelines, I really hope that people consider _readability_
> when modifying this code. I don't think this patch makes the code much
> more readable.
>
well, IMHO using pfn/page conversion macros makes the code more readable.
> That said, there are some nice helper function in here. Would you be
> able to break this patch up into maybe 10 or 15 smaller patches? I have
> the feeling it will be easier to find the good bits then.
>
ok I'll split that.
>> It also removes __init tags in the header file and hopefully make it
>> easier to read.
>
> I think I kinda like when these are present in headers. I usually
> stumble across the header declarations before I do the ones in the .c
> files, and it is always nice to see the header visually _matching_
> the .c file, and how the variable is intended to be used
>
see Andrew's comments...
Franck
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 0/7] Clean up the bootmem allocator
2006-06-26 17:58 ` Dave Hansen
2006-06-26 18:10 ` Andrew Morton
2006-06-27 8:23 ` Franck Bui-Huu
@ 2006-06-27 12:53 ` Franck Bui-Huu
2006-06-27 12:53 ` [PATCH 1/7] bootmem: remove useless __init in header file Franck Bui-Huu
` (6 subsequent siblings)
9 siblings, 0 replies; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-27 12:53 UTC (permalink / raw)
To: Dave Hansen; +Cc: Franck, Andrew Morton, Mel Gorman, Linux Kernel Mailing List
ok here is the clean up broken up into 7 smaller patches.
Franck
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 1/7] bootmem: remove useless __init in header file
2006-06-26 17:58 ` Dave Hansen
` (2 preceding siblings ...)
2006-06-27 12:53 ` [PATCH 0/7] " Franck Bui-Huu
@ 2006-06-27 12:53 ` Franck Bui-Huu
2006-06-27 17:17 ` Dave Hansen
2006-06-27 12:53 ` [PATCH 2/7] bootmem: mark link_bootmem() as part of the __init section Franck Bui-Huu
` (5 subsequent siblings)
9 siblings, 1 reply; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-27 12:53 UTC (permalink / raw)
To: Dave Hansen; +Cc: Franck, Andrew Morton, Mel Gorman, Linux Kernel Mailing List
__init in headers is pretty useless because the compiler doesn't check it,
and they get out of sync relatively frequently. So if you see an __init
in a header file, it's quite unreliable and you need to check the
definition anyway.
Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
---
include/linux/bootmem.h | 52 ++++++++++++++++++++++++-----------------------
1 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
index da2d107..1dee668 100644
--- a/include/linux/bootmem.h
+++ b/include/linux/bootmem.h
@@ -41,23 +41,23 @@ typedef struct bootmem_data {
struct list_head list;
} bootmem_data_t;
-extern unsigned long __init bootmem_bootmap_pages (unsigned long);
-extern unsigned long __init init_bootmem (unsigned long addr, unsigned long memend);
-extern void __init free_bootmem (unsigned long addr, unsigned long size);
-extern void * __init __alloc_bootmem (unsigned long size, unsigned long align, unsigned long goal);
-extern void * __init __alloc_bootmem_nopanic (unsigned long size, unsigned long align, unsigned long goal);
-extern void * __init __alloc_bootmem_low(unsigned long size,
+extern unsigned long bootmem_bootmap_pages (unsigned long);
+extern unsigned long init_bootmem (unsigned long addr, unsigned long memend);
+extern void free_bootmem (unsigned long addr, unsigned long size);
+extern void * __alloc_bootmem (unsigned long size, unsigned long align, unsigned long goal);
+extern void * __alloc_bootmem_nopanic (unsigned long size, unsigned long align, unsigned long goal);
+extern void * __alloc_bootmem_low(unsigned long size,
unsigned long align,
unsigned long goal);
-extern void * __init __alloc_bootmem_low_node(pg_data_t *pgdat,
+extern void * __alloc_bootmem_low_node(pg_data_t *pgdat,
unsigned long size,
unsigned long align,
unsigned long goal);
-extern void * __init __alloc_bootmem_core(struct bootmem_data *bdata,
+extern void * __alloc_bootmem_core(struct bootmem_data *bdata,
unsigned long size, unsigned long align, unsigned long goal,
unsigned long limit);
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
-extern void __init reserve_bootmem (unsigned long addr, unsigned long size);
+extern void reserve_bootmem (unsigned long addr, unsigned long size);
#define alloc_bootmem(x) \
__alloc_bootmem((x), SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
#define alloc_bootmem_low(x) \
@@ -67,12 +67,12 @@ #define alloc_bootmem_pages(x) \
#define alloc_bootmem_low_pages(x) \
__alloc_bootmem_low((x), PAGE_SIZE, 0)
#endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */
-extern unsigned long __init free_all_bootmem (void);
-extern void * __init __alloc_bootmem_node (pg_data_t *pgdat, unsigned long size, unsigned long align, unsigned long goal);
-extern unsigned long __init init_bootmem_node (pg_data_t *pgdat, unsigned long freepfn, unsigned long startpfn, unsigned long endpfn);
-extern void __init reserve_bootmem_node (pg_data_t *pgdat, unsigned long physaddr, unsigned long size);
-extern void __init free_bootmem_node (pg_data_t *pgdat, unsigned long addr, unsigned long size);
-extern unsigned long __init free_all_bootmem_node (pg_data_t *pgdat);
+extern unsigned long free_all_bootmem (void);
+extern void * __alloc_bootmem_node (pg_data_t *pgdat, unsigned long size, unsigned long align, unsigned long goal);
+extern unsigned long init_bootmem_node (pg_data_t *pgdat, unsigned long freepfn, unsigned long startpfn, unsigned long endpfn);
+extern void reserve_bootmem_node (pg_data_t *pgdat, unsigned long physaddr, unsigned long size);
+extern void free_bootmem_node (pg_data_t *pgdat, unsigned long addr, unsigned long size);
+extern unsigned long free_all_bootmem_node (pg_data_t *pgdat);
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
#define alloc_bootmem_node(pgdat, x) \
__alloc_bootmem_node((pgdat), (x), SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
@@ -91,17 +91,17 @@ static inline void *alloc_remap(int nid,
}
#endif
-extern unsigned long __initdata nr_kernel_pages;
-extern unsigned long __initdata nr_all_pages;
+extern unsigned long nr_kernel_pages;
+extern unsigned long nr_all_pages;
-extern void *__init alloc_large_system_hash(const char *tablename,
- unsigned long bucketsize,
- unsigned long numentries,
- int scale,
- int flags,
- unsigned int *_hash_shift,
- unsigned int *_hash_mask,
- unsigned long limit);
+extern void * alloc_large_system_hash(const char *tablename,
+ unsigned long bucketsize,
+ unsigned long numentries,
+ int scale,
+ int flags,
+ unsigned int *_hash_shift,
+ unsigned int *_hash_mask,
+ unsigned long limit);
#define HASH_HIGHMEM 0x00000001 /* Consider highmem? */
#define HASH_EARLY 0x00000002 /* Allocating during early boot? */
@@ -114,7 +114,7 @@ #define HASHDIST_DEFAULT 1
#else
#define HASHDIST_DEFAULT 0
#endif
-extern int __initdata hashdist; /* Distribute hashes across NUMA nodes? */
+extern int hashdist; /* Distribute hashes across NUMA nodes? */
#endif /* _LINUX_BOOTMEM_H */
--
1.4.0.g64e8
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 2/7] bootmem: mark link_bootmem() as part of the __init section
2006-06-26 17:58 ` Dave Hansen
` (3 preceding siblings ...)
2006-06-27 12:53 ` [PATCH 1/7] bootmem: remove useless __init in header file Franck Bui-Huu
@ 2006-06-27 12:53 ` Franck Bui-Huu
2006-06-27 17:17 ` Dave Hansen
2006-06-27 12:54 ` [PATCH 3/7] bootmem: remove useless parentheses in bootmem header file Franck Bui-Huu
` (4 subsequent siblings)
9 siblings, 1 reply; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-27 12:53 UTC (permalink / raw)
To: Dave Hansen; +Cc: Franck, Andrew Morton, Mel Gorman, Linux Kernel Mailing List
Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
---
mm/bootmem.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/mm/bootmem.c b/mm/bootmem.c
index d213fed..d0a34fe 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -56,7 +56,7 @@ unsigned long __init bootmem_bootmap_pag
/*
* link bdata in order
*/
-static void link_bootmem(bootmem_data_t *bdata)
+static void __init link_bootmem(bootmem_data_t *bdata)
{
bootmem_data_t *ent;
if (list_empty(&bdata_list)) {
--
1.4.0.g64e8
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 3/7] bootmem: remove useless parentheses in bootmem header file
2006-06-26 17:58 ` Dave Hansen
` (4 preceding siblings ...)
2006-06-27 12:53 ` [PATCH 2/7] bootmem: mark link_bootmem() as part of the __init section Franck Bui-Huu
@ 2006-06-27 12:54 ` Franck Bui-Huu
2006-06-27 12:54 ` [PATCH 4/7] bootmem: limit to 80 columns width Franck Bui-Huu
` (3 subsequent siblings)
9 siblings, 0 replies; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-27 12:54 UTC (permalink / raw)
To: Dave Hansen; +Cc: Franck, Andrew Morton, Mel Gorman, Linux Kernel Mailing List
Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
---
include/linux/bootmem.h | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
index 1dee668..0e821ca 100644
--- a/include/linux/bootmem.h
+++ b/include/linux/bootmem.h
@@ -59,13 +59,13 @@ extern void * __alloc_bootmem_core(struc
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
extern void reserve_bootmem (unsigned long addr, unsigned long size);
#define alloc_bootmem(x) \
- __alloc_bootmem((x), SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
+ __alloc_bootmem(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
#define alloc_bootmem_low(x) \
- __alloc_bootmem_low((x), SMP_CACHE_BYTES, 0)
+ __alloc_bootmem_low(x, SMP_CACHE_BYTES, 0)
#define alloc_bootmem_pages(x) \
- __alloc_bootmem((x), PAGE_SIZE, __pa(MAX_DMA_ADDRESS))
+ __alloc_bootmem(x, PAGE_SIZE, __pa(MAX_DMA_ADDRESS))
#define alloc_bootmem_low_pages(x) \
- __alloc_bootmem_low((x), PAGE_SIZE, 0)
+ __alloc_bootmem_low(x, PAGE_SIZE, 0)
#endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */
extern unsigned long free_all_bootmem (void);
extern void * __alloc_bootmem_node (pg_data_t *pgdat, unsigned long size, unsigned long align, unsigned long goal);
@@ -75,11 +75,11 @@ extern void free_bootmem_node (pg_data_t
extern unsigned long free_all_bootmem_node (pg_data_t *pgdat);
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
#define alloc_bootmem_node(pgdat, x) \
- __alloc_bootmem_node((pgdat), (x), SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
+ __alloc_bootmem_node(pgdat, x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
#define alloc_bootmem_pages_node(pgdat, x) \
- __alloc_bootmem_node((pgdat), (x), PAGE_SIZE, __pa(MAX_DMA_ADDRESS))
+ __alloc_bootmem_node(pgdat, x, PAGE_SIZE, __pa(MAX_DMA_ADDRESS))
#define alloc_bootmem_low_pages_node(pgdat, x) \
- __alloc_bootmem_low_node((pgdat), (x), PAGE_SIZE, 0)
+ __alloc_bootmem_low_node(pgdat, x, PAGE_SIZE, 0)
#endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */
#ifdef CONFIG_HAVE_ARCH_ALLOC_REMAP
--
1.4.0.g64e8
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 4/7] bootmem: limit to 80 columns width
2006-06-26 17:58 ` Dave Hansen
` (5 preceding siblings ...)
2006-06-27 12:54 ` [PATCH 3/7] bootmem: remove useless parentheses in bootmem header file Franck Bui-Huu
@ 2006-06-27 12:54 ` Franck Bui-Huu
2006-06-27 12:54 ` [PATCH 5/7] bootmem: remove useless headers inclusions Franck Bui-Huu
` (2 subsequent siblings)
9 siblings, 0 replies; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-27 12:54 UTC (permalink / raw)
To: Dave Hansen; +Cc: Franck, Andrew Morton, Mel Gorman, Linux Kernel Mailing List
Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
---
include/linux/bootmem.h | 42 +++++++++++++++++++++++++++++-------------
mm/bootmem.c | 28 ++++++++++++++++++----------
2 files changed, 47 insertions(+), 23 deletions(-)
diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
index 0e821ca..f55719b 100644
--- a/include/linux/bootmem.h
+++ b/include/linux/bootmem.h
@@ -44,18 +44,24 @@ typedef struct bootmem_data {
extern unsigned long bootmem_bootmap_pages (unsigned long);
extern unsigned long init_bootmem (unsigned long addr, unsigned long memend);
extern void free_bootmem (unsigned long addr, unsigned long size);
-extern void * __alloc_bootmem (unsigned long size, unsigned long align, unsigned long goal);
-extern void * __alloc_bootmem_nopanic (unsigned long size, unsigned long align, unsigned long goal);
+extern void * __alloc_bootmem (unsigned long size,
+ unsigned long align,
+ unsigned long goal);
+extern void * __alloc_bootmem_nopanic (unsigned long size,
+ unsigned long align,
+ unsigned long goal);
extern void * __alloc_bootmem_low(unsigned long size,
- unsigned long align,
- unsigned long goal);
+ unsigned long align,
+ unsigned long goal);
extern void * __alloc_bootmem_low_node(pg_data_t *pgdat,
- unsigned long size,
- unsigned long align,
- unsigned long goal);
+ unsigned long size,
+ unsigned long align,
+ unsigned long goal);
extern void * __alloc_bootmem_core(struct bootmem_data *bdata,
- unsigned long size, unsigned long align, unsigned long goal,
- unsigned long limit);
+ unsigned long size,
+ unsigned long align,
+ unsigned long goal,
+ unsigned long limit);
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
extern void reserve_bootmem (unsigned long addr, unsigned long size);
#define alloc_bootmem(x) \
@@ -68,10 +74,20 @@ #define alloc_bootmem_low_pages(x) \
__alloc_bootmem_low(x, PAGE_SIZE, 0)
#endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */
extern unsigned long free_all_bootmem (void);
-extern void * __alloc_bootmem_node (pg_data_t *pgdat, unsigned long size, unsigned long align, unsigned long goal);
-extern unsigned long init_bootmem_node (pg_data_t *pgdat, unsigned long freepfn, unsigned long startpfn, unsigned long endpfn);
-extern void reserve_bootmem_node (pg_data_t *pgdat, unsigned long physaddr, unsigned long size);
-extern void free_bootmem_node (pg_data_t *pgdat, unsigned long addr, unsigned long size);
+extern void * __alloc_bootmem_node (pg_data_t *pgdat,
+ unsigned long size,
+ unsigned long align,
+ unsigned long goal);
+extern unsigned long init_bootmem_node (pg_data_t *pgdat,
+ unsigned long freepfn,
+ unsigned long startpfn,
+ unsigned long endpfn);
+extern void reserve_bootmem_node (pg_data_t *pgdat,
+ unsigned long physaddr,
+ unsigned long size);
+extern void free_bootmem_node (pg_data_t *pgdat,
+ unsigned long addr,
+ unsigned long size);
extern unsigned long free_all_bootmem_node (pg_data_t *pgdat);
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
#define alloc_bootmem_node(pgdat, x) \
diff --git a/mm/bootmem.c b/mm/bootmem.c
index d0a34fe..ac6a51c 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -104,7 +104,8 @@ static unsigned long __init init_bootmem
* might be used for boot-time allocations - or it might get added
* to the free page pool later on.
*/
-static void __init reserve_bootmem_core(bootmem_data_t *bdata, unsigned long addr, unsigned long size)
+static void __init reserve_bootmem_core(bootmem_data_t *bdata, unsigned long addr,
+ unsigned long size)
{
unsigned long i;
/*
@@ -129,7 +130,8 @@ #endif
}
}
-static void __init free_bootmem_core(bootmem_data_t *bdata, unsigned long addr, unsigned long size)
+static void __init free_bootmem_core(bootmem_data_t *bdata, unsigned long addr,
+ unsigned long size)
{
unsigned long i;
unsigned long start;
@@ -357,17 +359,20 @@ static unsigned long __init free_all_boo
return total;
}
-unsigned long __init init_bootmem_node (pg_data_t *pgdat, unsigned long freepfn, unsigned long startpfn, unsigned long endpfn)
+unsigned long __init init_bootmem_node (pg_data_t *pgdat, unsigned long freepfn,
+ unsigned long startpfn, unsigned long endpfn)
{
return(init_bootmem_core(pgdat, freepfn, startpfn, endpfn));
}
-void __init reserve_bootmem_node (pg_data_t *pgdat, unsigned long physaddr, unsigned long size)
+void __init reserve_bootmem_node (pg_data_t *pgdat, unsigned long physaddr,
+ unsigned long size)
{
reserve_bootmem_core(pgdat->bdata, physaddr, size);
}
-void __init free_bootmem_node (pg_data_t *pgdat, unsigned long physaddr, unsigned long size)
+void __init free_bootmem_node (pg_data_t *pgdat, unsigned long physaddr,
+ unsigned long size)
{
free_bootmem_core(pgdat->bdata, physaddr, size);
}
@@ -401,7 +406,8 @@ unsigned long __init free_all_bootmem (v
return(free_all_bootmem_core(NODE_DATA(0)));
}
-void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align, unsigned long goal)
+void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align,
+ unsigned long goal)
{
bootmem_data_t *bdata;
void *ptr;
@@ -412,7 +418,8 @@ void * __init __alloc_bootmem_nopanic(un
return NULL;
}
-void * __init __alloc_bootmem(unsigned long size, unsigned long align, unsigned long goal)
+void * __init __alloc_bootmem(unsigned long size, unsigned long align,
+ unsigned long goal)
{
void *mem = __alloc_bootmem_nopanic(size,align,goal);
if (mem)
@@ -426,8 +433,8 @@ void * __init __alloc_bootmem(unsigned l
}
-void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size, unsigned long align,
- unsigned long goal)
+void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size,
+ unsigned long align, unsigned long goal)
{
void *ptr;
@@ -440,7 +447,8 @@ void * __init __alloc_bootmem_node(pg_da
#define LOW32LIMIT 0xffffffff
-void * __init __alloc_bootmem_low(unsigned long size, unsigned long align, unsigned long goal)
+void * __init __alloc_bootmem_low(unsigned long size, unsigned long align,
+ unsigned long goal)
{
bootmem_data_t *bdata;
void *ptr;
--
1.4.0.g64e8
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 5/7] bootmem: remove useless headers inclusions
2006-06-26 17:58 ` Dave Hansen
` (6 preceding siblings ...)
2006-06-27 12:54 ` [PATCH 4/7] bootmem: limit to 80 columns width Franck Bui-Huu
@ 2006-06-27 12:54 ` Franck Bui-Huu
2006-06-27 12:54 ` [PATCH 6/7] bootmem: use pfn/page conversion macros Franck Bui-Huu
2006-06-27 12:54 ` [PATCH 7/7] bootmem: miscellaneous coding style fixes Franck Bui-Huu
9 siblings, 0 replies; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-27 12:54 UTC (permalink / raw)
To: Dave Hansen; +Cc: Franck, Andrew Morton, Mel Gorman, Linux Kernel Mailing List
Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
---
include/linux/bootmem.h | 5 +----
mm/bootmem.c | 10 +++-------
2 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
index f55719b..fe48c5e 100644
--- a/include/linux/bootmem.h
+++ b/include/linux/bootmem.h
@@ -4,11 +4,8 @@
#ifndef _LINUX_BOOTMEM_H
#define _LINUX_BOOTMEM_H
-#include <asm/pgtable.h>
-#include <asm/dma.h>
-#include <linux/cache.h>
-#include <linux/init.h>
#include <linux/mmzone.h>
+#include <asm/dma.h>
/*
* simple boot-time physical memory area allocator.
diff --git a/mm/bootmem.c b/mm/bootmem.c
index ac6a51c..86213da 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -8,17 +8,13 @@
* free memory collector. It's used to deal with reserved
* system memory and memory holes as well.
*/
-
-#include <linux/mm.h>
-#include <linux/kernel_stat.h>
-#include <linux/swap.h>
-#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/bootmem.h>
-#include <linux/mmzone.h>
#include <linux/module.h>
-#include <asm/dma.h>
+
+#include <asm/bug.h>
#include <asm/io.h>
+
#include "internal.h"
/*
--
1.4.0.g64e8
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 6/7] bootmem: use pfn/page conversion macros
2006-06-26 17:58 ` Dave Hansen
` (7 preceding siblings ...)
2006-06-27 12:54 ` [PATCH 5/7] bootmem: remove useless headers inclusions Franck Bui-Huu
@ 2006-06-27 12:54 ` Franck Bui-Huu
2006-06-27 19:26 ` Dave Hansen
2006-06-27 12:54 ` [PATCH 7/7] bootmem: miscellaneous coding style fixes Franck Bui-Huu
9 siblings, 1 reply; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-27 12:54 UTC (permalink / raw)
To: Dave Hansen; +Cc: Franck, Andrew Morton, Mel Gorman, Linux Kernel Mailing List
It also creates get_mapsize() helper in order to make the code
more readable when it calculates the boot bitmap size.
Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
---
mm/bootmem.c | 82 ++++++++++++++++++++++++++++++++--------------------------
1 files changed, 45 insertions(+), 37 deletions(-)
diff --git a/mm/bootmem.c b/mm/bootmem.c
index 86213da..3368a14 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -9,6 +9,7 @@
* system memory and memory holes as well.
*/
#include <linux/init.h>
+#include <linux/pfn.h>
#include <linux/bootmem.h>
#include <linux/module.h>
@@ -70,6 +71,18 @@ static void __init link_bootmem(bootmem_
return;
}
+/*
+ * Given an initialised bdata, it returns the size of the boot bitmap
+ */
+static unsigned long __init get_mapsize(bootmem_data_t *bdata)
+{
+ unsigned long mapsize;
+ unsigned long start = PFN_DOWN(bdata->node_boot_start);
+ unsigned long end = bdata->node_low_pfn;
+
+ mapsize = ((end - start) + 7) / 8;
+ return ALIGN(mapsize, sizeof(long));
+}
/*
* Called once to set up the allocator itself.
@@ -78,11 +91,10 @@ static unsigned long __init init_bootmem
unsigned long mapstart, unsigned long start, unsigned long end)
{
bootmem_data_t *bdata = pgdat->bdata;
- unsigned long mapsize = ((end - start)+7)/8;
+ unsigned long mapsize;
- mapsize = ALIGN(mapsize, sizeof(long));
- bdata->node_bootmem_map = phys_to_virt(mapstart << PAGE_SHIFT);
- bdata->node_boot_start = (start << PAGE_SHIFT);
+ bdata->node_bootmem_map = phys_to_virt(PFN_PHYS(mapstart));
+ bdata->node_boot_start = PFN_PHYS(start);
bdata->node_low_pfn = end;
link_bootmem(bdata);
@@ -90,6 +102,7 @@ static unsigned long __init init_bootmem
* Initially all pages are reserved - setup_arch() has to
* register free RAM areas explicitly.
*/
+ mapsize = get_mapsize(bdata);
memset(bdata->node_bootmem_map, 0xff, mapsize);
return mapsize;
@@ -103,20 +116,19 @@ static unsigned long __init init_bootmem
static void __init reserve_bootmem_core(bootmem_data_t *bdata, unsigned long addr,
unsigned long size)
{
+ unsigned long sidx, eidx;
unsigned long i;
+
/*
* round up, partially reserved pages are considered
* fully reserved.
*/
- unsigned long sidx = (addr - bdata->node_boot_start)/PAGE_SIZE;
- unsigned long eidx = (addr + size - bdata->node_boot_start +
- PAGE_SIZE-1)/PAGE_SIZE;
- unsigned long end = (addr + size + PAGE_SIZE-1)/PAGE_SIZE;
-
BUG_ON(!size);
- BUG_ON(sidx >= eidx);
- BUG_ON((addr >> PAGE_SHIFT) >= bdata->node_low_pfn);
- BUG_ON(end > bdata->node_low_pfn);
+ BUG_ON(PFN_DOWN(addr) >= bdata->node_low_pfn);
+ BUG_ON(PFN_UP(addr + size) > bdata->node_low_pfn);
+
+ sidx = PFN_DOWN(addr - bdata->node_boot_start);
+ eidx = PFN_UP(addr + size - bdata->node_boot_start);
for (i = sidx; i < eidx; i++)
if (test_and_set_bit(i, bdata->node_bootmem_map)) {
@@ -129,18 +141,15 @@ #endif
static void __init free_bootmem_core(bootmem_data_t *bdata, unsigned long addr,
unsigned long size)
{
+ unsigned long sidx, eidx;
unsigned long i;
- unsigned long start;
+
/*
* round down end of usable mem, partially free pages are
* considered reserved.
*/
- unsigned long sidx;
- unsigned long eidx = (addr + size - bdata->node_boot_start)/PAGE_SIZE;
- unsigned long end = (addr + size)/PAGE_SIZE;
-
BUG_ON(!size);
- BUG_ON(end > bdata->node_low_pfn);
+ BUG_ON(PFN_DOWN(addr + size) > bdata->node_low_pfn);
if (addr < bdata->last_success)
bdata->last_success = addr;
@@ -148,8 +157,8 @@ static void __init free_bootmem_core(boo
/*
* Round up the beginning of the address.
*/
- start = (addr + PAGE_SIZE-1) / PAGE_SIZE;
- sidx = start - (bdata->node_boot_start/PAGE_SIZE);
+ sidx = PFN_UP(addr) - PFN_DOWN(bdata->node_boot_start);
+ eidx = PFN_DOWN(addr + size - bdata->node_boot_start);
for (i = sidx; i < eidx; i++) {
if (unlikely(!test_and_clear_bit(i, bdata->node_bootmem_map)))
@@ -175,7 +184,7 @@ __alloc_bootmem_core(struct bootmem_data
unsigned long align, unsigned long goal, unsigned long limit)
{
unsigned long offset, remaining_size, areasize, preferred;
- unsigned long i, start = 0, incr, eidx, end_pfn = bdata->node_low_pfn;
+ unsigned long i, start = 0, incr, eidx, end_pfn;
void *ret;
if(!size) {
@@ -187,23 +196,22 @@ __alloc_bootmem_core(struct bootmem_data
if (limit && bdata->node_boot_start >= limit)
return NULL;
- limit >>=PAGE_SHIFT;
+ end_pfn = bdata->node_low_pfn;
+ limit = PFN_DOWN(limit);
if (limit && end_pfn > limit)
end_pfn = limit;
- eidx = end_pfn - (bdata->node_boot_start >> PAGE_SHIFT);
+ eidx = end_pfn - PFN_DOWN(bdata->node_boot_start);
offset = 0;
- if (align &&
- (bdata->node_boot_start & (align - 1UL)) != 0)
- offset = (align - (bdata->node_boot_start & (align - 1UL)));
- offset >>= PAGE_SHIFT;
+ if (align && (bdata->node_boot_start & (align - 1UL)) != 0)
+ offset = align - (bdata->node_boot_start & (align - 1UL));
+ offset = PFN_DOWN(offset);
/*
* We try to allocate bootmem pages above 'goal'
* first, then we try to allocate lower pages.
*/
- if (goal && (goal >= bdata->node_boot_start) &&
- ((goal >> PAGE_SHIFT) < end_pfn)) {
+ if (goal && goal >= bdata->node_boot_start && PFN_DOWN(goal) < end_pfn) {
preferred = goal - bdata->node_boot_start;
if (bdata->last_success >= preferred)
@@ -212,9 +220,8 @@ __alloc_bootmem_core(struct bootmem_data
} else
preferred = 0;
- preferred = ALIGN(preferred, align) >> PAGE_SHIFT;
- preferred += offset;
- areasize = (size+PAGE_SIZE-1)/PAGE_SIZE;
+ preferred = PFN_DOWN(ALIGN(preferred, align)) + offset;
+ areasize = (size + PAGE_SIZE-1) / PAGE_SIZE;
incr = align >> PAGE_SHIFT ? : 1;
restart_scan:
@@ -245,7 +252,7 @@ restart_scan:
return NULL;
found:
- bdata->last_success = start << PAGE_SHIFT;
+ bdata->last_success = PFN_PHYS(start);
BUG_ON(start >= eidx);
/*
@@ -303,8 +310,8 @@ static unsigned long __init free_all_boo
count = 0;
/* first extant page of the node */
- pfn = bdata->node_boot_start >> PAGE_SHIFT;
- idx = bdata->node_low_pfn - (bdata->node_boot_start >> PAGE_SHIFT);
+ pfn = PFN_DOWN(bdata->node_boot_start);
+ idx = bdata->node_low_pfn - pfn;
map = bdata->node_bootmem_map;
/* Check physaddr is O(LOG2(BITS_PER_LONG)) page aligned */
if (bdata->node_boot_start == 0 ||
@@ -345,9 +352,10 @@ static unsigned long __init free_all_boo
*/
page = virt_to_page(bdata->node_bootmem_map);
count = 0;
- for (i = 0; i < ((bdata->node_low_pfn-(bdata->node_boot_start >> PAGE_SHIFT))/8 + PAGE_SIZE-1)/PAGE_SIZE; i++,page++) {
- count++;
+ idx = (get_mapsize(bdata) + PAGE_SIZE-1) >> PAGE_SHIFT;
+ for (i = 0; i < idx; i++, page++) {
__free_pages_bootmem(page, 0);
+ count++;
}
total += count;
bdata->node_bootmem_map = NULL;
--
1.4.0.g64e8
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH 7/7] bootmem: miscellaneous coding style fixes
2006-06-26 17:58 ` Dave Hansen
` (8 preceding siblings ...)
2006-06-27 12:54 ` [PATCH 6/7] bootmem: use pfn/page conversion macros Franck Bui-Huu
@ 2006-06-27 12:54 ` Franck Bui-Huu
2006-06-27 17:26 ` Dave Hansen
9 siblings, 1 reply; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-27 12:54 UTC (permalink / raw)
To: Dave Hansen; +Cc: Franck, Andrew Morton, Mel Gorman, Linux Kernel Mailing List
Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
---
include/linux/bootmem.h | 29 +++++++++-------
mm/bootmem.c | 84 ++++++++++++++++++++++++++---------------------
2 files changed, 62 insertions(+), 51 deletions(-)
diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
index fe48c5e..a532d00 100644
--- a/include/linux/bootmem.h
+++ b/include/linux/bootmem.h
@@ -38,13 +38,13 @@ typedef struct bootmem_data {
struct list_head list;
} bootmem_data_t;
-extern unsigned long bootmem_bootmap_pages (unsigned long);
-extern unsigned long init_bootmem (unsigned long addr, unsigned long memend);
-extern void free_bootmem (unsigned long addr, unsigned long size);
-extern void * __alloc_bootmem (unsigned long size,
+extern unsigned long bootmem_bootmap_pages(unsigned long);
+extern unsigned long init_bootmem(unsigned long addr, unsigned long memend);
+extern void free_bootmem(unsigned long addr, unsigned long size);
+extern void * __alloc_bootmem(unsigned long size,
unsigned long align,
unsigned long goal);
-extern void * __alloc_bootmem_nopanic (unsigned long size,
+extern void * __alloc_bootmem_nopanic(unsigned long size,
unsigned long align,
unsigned long goal);
extern void * __alloc_bootmem_low(unsigned long size,
@@ -59,8 +59,9 @@ extern void * __alloc_bootmem_core(struc
unsigned long align,
unsigned long goal,
unsigned long limit);
+
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
-extern void reserve_bootmem (unsigned long addr, unsigned long size);
+extern void reserve_bootmem(unsigned long addr, unsigned long size);
#define alloc_bootmem(x) \
__alloc_bootmem(x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
#define alloc_bootmem_low(x) \
@@ -70,22 +71,24 @@ #define alloc_bootmem_pages(x) \
#define alloc_bootmem_low_pages(x) \
__alloc_bootmem_low(x, PAGE_SIZE, 0)
#endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */
-extern unsigned long free_all_bootmem (void);
-extern void * __alloc_bootmem_node (pg_data_t *pgdat,
+
+extern unsigned long free_all_bootmem(void);
+extern unsigned long free_all_bootmem_node(pg_data_t *pgdat);
+extern void * __alloc_bootmem_node(pg_data_t *pgdat,
unsigned long size,
unsigned long align,
unsigned long goal);
-extern unsigned long init_bootmem_node (pg_data_t *pgdat,
+extern unsigned long init_bootmem_node(pg_data_t *pgdat,
unsigned long freepfn,
unsigned long startpfn,
unsigned long endpfn);
-extern void reserve_bootmem_node (pg_data_t *pgdat,
+extern void reserve_bootmem_node(pg_data_t *pgdat,
unsigned long physaddr,
unsigned long size);
-extern void free_bootmem_node (pg_data_t *pgdat,
+extern void free_bootmem_node(pg_data_t *pgdat,
unsigned long addr,
unsigned long size);
-extern unsigned long free_all_bootmem_node (pg_data_t *pgdat);
+
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
#define alloc_bootmem_node(pgdat, x) \
__alloc_bootmem_node(pgdat, x, SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
@@ -102,7 +105,7 @@ static inline void *alloc_remap(int nid,
{
return NULL;
}
-#endif
+#endif /* CONFIG_HAVE_ARCH_ALLOC_REMAP */
extern unsigned long nr_kernel_pages;
extern unsigned long nr_all_pages;
diff --git a/mm/bootmem.c b/mm/bootmem.c
index 3368a14..0956c18 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -40,7 +40,7 @@ unsigned long saved_max_pfn;
#endif
/* return the number of _pages_ that will be allocated for the boot bitmap */
-unsigned long __init bootmem_bootmap_pages (unsigned long pages)
+unsigned long __init bootmem_bootmap_pages(unsigned long pages)
{
unsigned long mapsize;
@@ -50,12 +50,14 @@ unsigned long __init bootmem_bootmap_pag
return mapsize;
}
+
/*
* link bdata in order
*/
static void __init link_bootmem(bootmem_data_t *bdata)
{
bootmem_data_t *ent;
+
if (list_empty(&bdata_list)) {
list_add(&bdata->list, &bdata_list);
return;
@@ -68,7 +70,6 @@ static void __init link_bootmem(bootmem_
}
}
list_add_tail(&bdata->list, &bdata_list);
- return;
}
/*
@@ -87,7 +88,7 @@ static unsigned long __init get_mapsize(
/*
* Called once to set up the allocator itself.
*/
-static unsigned long __init init_bootmem_core (pg_data_t *pgdat,
+static unsigned long __init init_bootmem_core(pg_data_t *pgdat,
unsigned long mapstart, unsigned long start, unsigned long end)
{
bootmem_data_t *bdata = pgdat->bdata;
@@ -184,10 +185,10 @@ __alloc_bootmem_core(struct bootmem_data
unsigned long align, unsigned long goal, unsigned long limit)
{
unsigned long offset, remaining_size, areasize, preferred;
- unsigned long i, start = 0, incr, eidx, end_pfn;
+ unsigned long i, start, incr, eidx, end_pfn;
void *ret;
- if(!size) {
+ if (!size) {
printk("__alloc_bootmem_core(): zero-sized request\n");
BUG();
}
@@ -224,6 +225,7 @@ __alloc_bootmem_core(struct bootmem_data
areasize = (size + PAGE_SIZE-1) / PAGE_SIZE;
incr = align >> PAGE_SHIFT ? : 1;
+ start = 0;
restart_scan:
for (i = preferred; i < eidx; i += incr) {
unsigned long j;
@@ -236,7 +238,7 @@ restart_scan:
for (j = i + 1; j < i + areasize; ++j) {
if (j >= eidx)
goto fail_block;
- if (test_bit (j, bdata->node_bootmem_map))
+ if (test_bit(j, bdata->node_bootmem_map))
goto fail_block;
}
start = i;
@@ -264,19 +266,21 @@ found:
bdata->last_offset && bdata->last_pos+1 == start) {
offset = ALIGN(bdata->last_offset, align);
BUG_ON(offset > PAGE_SIZE);
- remaining_size = PAGE_SIZE-offset;
+ remaining_size = PAGE_SIZE - offset;
if (size < remaining_size) {
areasize = 0;
/* last_pos unchanged */
- bdata->last_offset = offset+size;
- ret = phys_to_virt(bdata->last_pos*PAGE_SIZE + offset +
- bdata->node_boot_start);
+ bdata->last_offset = offset + size;
+ ret = phys_to_virt(bdata->last_pos * PAGE_SIZE +
+ offset +
+ bdata->node_boot_start);
} else {
remaining_size = size - remaining_size;
- areasize = (remaining_size+PAGE_SIZE-1)/PAGE_SIZE;
- ret = phys_to_virt(bdata->last_pos*PAGE_SIZE + offset +
- bdata->node_boot_start);
- bdata->last_pos = start+areasize-1;
+ areasize = (remaining_size + PAGE_SIZE-1) / PAGE_SIZE;
+ ret = phys_to_virt(bdata->last_pos * PAGE_SIZE +
+ offset +
+ bdata->node_boot_start);
+ bdata->last_pos = start + areasize - 1;
bdata->last_offset = remaining_size;
}
bdata->last_offset &= ~PAGE_MASK;
@@ -289,7 +293,7 @@ found:
/*
* Reserve the area now:
*/
- for (i = start; i < start+areasize; i++)
+ for (i = start; i < start + areasize; i++)
if (unlikely(test_and_set_bit(i, bdata->node_bootmem_map)))
BUG();
memset(ret, 0, size);
@@ -340,7 +344,7 @@ static unsigned long __init free_all_boo
}
}
} else {
- i+=BITS_PER_LONG;
+ i += BITS_PER_LONG;
}
pfn += BITS_PER_LONG;
}
@@ -363,51 +367,51 @@ static unsigned long __init free_all_boo
return total;
}
-unsigned long __init init_bootmem_node (pg_data_t *pgdat, unsigned long freepfn,
+unsigned long __init init_bootmem_node(pg_data_t *pgdat, unsigned long freepfn,
unsigned long startpfn, unsigned long endpfn)
{
- return(init_bootmem_core(pgdat, freepfn, startpfn, endpfn));
+ return init_bootmem_core(pgdat, freepfn, startpfn, endpfn);
}
-void __init reserve_bootmem_node (pg_data_t *pgdat, unsigned long physaddr,
- unsigned long size)
+void __init reserve_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
+ unsigned long size)
{
reserve_bootmem_core(pgdat->bdata, physaddr, size);
}
-void __init free_bootmem_node (pg_data_t *pgdat, unsigned long physaddr,
- unsigned long size)
+void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
+ unsigned long size)
{
free_bootmem_core(pgdat->bdata, physaddr, size);
}
-unsigned long __init free_all_bootmem_node (pg_data_t *pgdat)
+unsigned long __init free_all_bootmem_node(pg_data_t *pgdat)
{
- return(free_all_bootmem_core(pgdat));
+ return free_all_bootmem_core(pgdat);
}
-unsigned long __init init_bootmem (unsigned long start, unsigned long pages)
+unsigned long __init init_bootmem(unsigned long start, unsigned long pages)
{
max_low_pfn = pages;
min_low_pfn = start;
- return(init_bootmem_core(NODE_DATA(0), start, 0, pages));
+ return init_bootmem_core(NODE_DATA(0), start, 0, pages);
}
#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
-void __init reserve_bootmem (unsigned long addr, unsigned long size)
+void __init reserve_bootmem(unsigned long addr, unsigned long size)
{
reserve_bootmem_core(NODE_DATA(0)->bdata, addr, size);
}
#endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */
-void __init free_bootmem (unsigned long addr, unsigned long size)
+void __init free_bootmem(unsigned long addr, unsigned long size)
{
free_bootmem_core(NODE_DATA(0)->bdata, addr, size);
}
-unsigned long __init free_all_bootmem (void)
+unsigned long __init free_all_bootmem(void)
{
- return(free_all_bootmem_core(NODE_DATA(0)));
+ return free_all_bootmem_core(NODE_DATA(0));
}
void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align,
@@ -416,9 +420,11 @@ void * __init __alloc_bootmem_nopanic(un
bootmem_data_t *bdata;
void *ptr;
- list_for_each_entry(bdata, &bdata_list, list)
- if ((ptr = __alloc_bootmem_core(bdata, size, align, goal, 0)))
- return(ptr);
+ list_for_each_entry(bdata, &bdata_list, list) {
+ ptr = __alloc_bootmem_core(bdata, size, align, goal, 0);
+ if (ptr)
+ return ptr;
+ }
return NULL;
}
@@ -426,6 +432,7 @@ void * __init __alloc_bootmem(unsigned l
unsigned long goal)
{
void *mem = __alloc_bootmem_nopanic(size,align,goal);
+
if (mem)
return mem;
/*
@@ -444,7 +451,7 @@ void * __init __alloc_bootmem_node(pg_da
ptr = __alloc_bootmem_core(pgdat->bdata, size, align, goal, 0);
if (ptr)
- return (ptr);
+ return ptr;
return __alloc_bootmem(size, align, goal);
}
@@ -457,10 +464,11 @@ void * __init __alloc_bootmem_low(unsign
bootmem_data_t *bdata;
void *ptr;
- list_for_each_entry(bdata, &bdata_list, list)
- if ((ptr = __alloc_bootmem_core(bdata, size,
- align, goal, LOW32LIMIT)))
- return(ptr);
+ list_for_each_entry(bdata, &bdata_list, list) {
+ ptr = __alloc_bootmem_core(bdata, size, align, goal, LOW32LIMIT);
+ if (ptr)
+ return ptr;
+ }
/*
* Whoops, we cannot satisfy the allocation request.
--
1.4.0.g64e8
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH 1/7] bootmem: remove useless __init in header file
2006-06-27 12:53 ` [PATCH 1/7] bootmem: remove useless __init in header file Franck Bui-Huu
@ 2006-06-27 17:17 ` Dave Hansen
2006-06-27 19:18 ` Franck Bui-Huu
0 siblings, 1 reply; 21+ messages in thread
From: Dave Hansen @ 2006-06-27 17:17 UTC (permalink / raw)
To: Franck; +Cc: Andrew Morton, Mel Gorman, Linux Kernel Mailing List
On Tue, 2006-06-27 at 14:53 +0200, Franck Bui-Huu wrote:
> +extern void * __alloc_bootmem (unsigned long size, unsigned long align, unsigned long goal);
> +extern void * __alloc_bootmem_nopanic (unsigned long size, unsigned long align, unsigned long goal);
Since we're being picky about kernel coding style, doesn't the '*' go
next to the function name? ;)
-- Dave
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 2/7] bootmem: mark link_bootmem() as part of the __init section
2006-06-27 12:53 ` [PATCH 2/7] bootmem: mark link_bootmem() as part of the __init section Franck Bui-Huu
@ 2006-06-27 17:17 ` Dave Hansen
2006-06-27 19:18 ` Franck Bui-Huu
0 siblings, 1 reply; 21+ messages in thread
From: Dave Hansen @ 2006-06-27 17:17 UTC (permalink / raw)
To: Franck; +Cc: Andrew Morton, Mel Gorman, Linux Kernel Mailing List
On Tue, 2006-06-27 at 14:53 +0200, Franck Bui-Huu wrote:
> Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
> ---
> mm/bootmem.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/mm/bootmem.c b/mm/bootmem.c
> index d213fed..d0a34fe 100644
> --- a/mm/bootmem.c
> +++ b/mm/bootmem.c
> @@ -56,7 +56,7 @@ unsigned long __init bootmem_bootmap_pag
> /*
> * link bdata in order
> */
> -static void link_bootmem(bootmem_data_t *bdata)
> +static void __init link_bootmem(bootmem_data_t *bdata)
> {
> bootmem_data_t *ent;
> if (list_empty(&bdata_list)) {
Looks sane. Just curious, did you do any wider audit in bootmem.c for
more of these?
-- Dave
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 7/7] bootmem: miscellaneous coding style fixes
2006-06-27 12:54 ` [PATCH 7/7] bootmem: miscellaneous coding style fixes Franck Bui-Huu
@ 2006-06-27 17:26 ` Dave Hansen
2006-06-27 19:22 ` Franck Bui-Huu
0 siblings, 1 reply; 21+ messages in thread
From: Dave Hansen @ 2006-06-27 17:26 UTC (permalink / raw)
To: Franck; +Cc: Andrew Morton, Mel Gorman, Linux Kernel Mailing List
On Tue, 2006-06-27 at 14:54 +0200, Franck Bui-Huu wrote:
> }
> +
> /*
> * link bdata in order
> */
> static void __init link_bootmem(bootmem_data_t *bdata)
> {
> bootmem_data_t *ent;
> +
> if (list_empty(&bdata_list)) {
I'd discourage you from including too many of these in your patches.
One or two is probably OK. But, there are a bunch of them, and it isn't
clear CodingStyle to have spacing like this either way. I'd drop them.
-- Dave
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 2/7] bootmem: mark link_bootmem() as part of the __init section
2006-06-27 17:17 ` Dave Hansen
@ 2006-06-27 19:18 ` Franck Bui-Huu
0 siblings, 0 replies; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-27 19:18 UTC (permalink / raw)
To: Dave Hansen; +Cc: Andrew Morton, Mel Gorman, Linux Kernel Mailing List
2006/6/27, Dave Hansen <haveblue@us.ibm.com>:
> On Tue, 2006-06-27 at 14:53 +0200, Franck Bui-Huu wrote:
> > Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com>
> > ---
> > mm/bootmem.c | 2 +-
> > 1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/mm/bootmem.c b/mm/bootmem.c
> > index d213fed..d0a34fe 100644
> > --- a/mm/bootmem.c
> > +++ b/mm/bootmem.c
> > @@ -56,7 +56,7 @@ unsigned long __init bootmem_bootmap_pag
> > /*
> > * link bdata in order
> > */
> > -static void link_bootmem(bootmem_data_t *bdata)
> > +static void __init link_bootmem(bootmem_data_t *bdata)
> > {
> > bootmem_data_t *ent;
> > if (list_empty(&bdata_list)) {
>
> Looks sane. Just curious, did you do any wider audit in bootmem.c for
> more of these?
>
I checked that all functions in bootmem.c belong to the __init section.
--
Franck
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 1/7] bootmem: remove useless __init in header file
2006-06-27 17:17 ` Dave Hansen
@ 2006-06-27 19:18 ` Franck Bui-Huu
0 siblings, 0 replies; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-27 19:18 UTC (permalink / raw)
To: Dave Hansen; +Cc: Andrew Morton, Mel Gorman, Linux Kernel Mailing List
2006/6/27, Dave Hansen <haveblue@us.ibm.com>:
> On Tue, 2006-06-27 at 14:53 +0200, Franck Bui-Huu wrote:
> > +extern void * __alloc_bootmem (unsigned long size, unsigned long align, unsigned long goal);
> > +extern void * __alloc_bootmem_nopanic (unsigned long size, unsigned long align, unsigned long goal);
>
> Since we're being picky about kernel coding style, doesn't the '*' go
> next to the function name? ;)
>
yeah, I noticed that but I wouldn't be too paranoid. But since you ask
for, I'll do that too :)
thanks
--
Franck
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 7/7] bootmem: miscellaneous coding style fixes
2006-06-27 17:26 ` Dave Hansen
@ 2006-06-27 19:22 ` Franck Bui-Huu
2006-06-27 22:35 ` Randy.Dunlap
0 siblings, 1 reply; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-27 19:22 UTC (permalink / raw)
To: Dave Hansen; +Cc: Andrew Morton, Mel Gorman, Linux Kernel Mailing List
2006/6/27, Dave Hansen <haveblue@us.ibm.com>:
> On Tue, 2006-06-27 at 14:54 +0200, Franck Bui-Huu wrote:
> > }
> > +
> > /*
> > * link bdata in order
> > */
> > static void __init link_bootmem(bootmem_data_t *bdata)
> > {
> > bootmem_data_t *ent;
> > +
> > if (list_empty(&bdata_list)) {
>
> I'd discourage you from including too many of these in your patches.
> One or two is probably OK. But, there are a bunch of them, and it isn't
> clear CodingStyle to have spacing like this either way. I'd drop them.
>
IMHO they make the code obviously more readable and obviously do not
add any new bugs. So why drop them ?
--
Franck
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 6/7] bootmem: use pfn/page conversion macros
2006-06-27 12:54 ` [PATCH 6/7] bootmem: use pfn/page conversion macros Franck Bui-Huu
@ 2006-06-27 19:26 ` Dave Hansen
2006-06-29 7:53 ` Franck Bui-Huu
0 siblings, 1 reply; 21+ messages in thread
From: Dave Hansen @ 2006-06-27 19:26 UTC (permalink / raw)
To: Franck; +Cc: Andrew Morton, Mel Gorman, Linux Kernel Mailing List
On Tue, 2006-06-27 at 14:54 +0200, Franck Bui-Huu wrote:
> static void __init free_bootmem_core(bootmem_data_t *bdata, unsigned
> long addr,
> unsigned long size)
> {
> + unsigned long sidx, eidx;
> unsigned long i;
> - unsigned long start;
> +
> /*
> * round down end of usable mem, partially free pages are
> * considered reserved.
> */
> - unsigned long sidx;
> - unsigned long eidx = (addr + size -
> bdata->node_boot_start)/PAGE_SIZE;
> - unsigned long end = (addr + size)/PAGE_SIZE;
> -
> BUG_ON(!size);
> - BUG_ON(end > bdata->node_low_pfn);
> + BUG_ON(PFN_DOWN(addr + size) > bdata->node_low_pfn);
In general, I like these kinds of conversions. But, in this case, I
think it makes the code harder to read. Those intermediate variables
are really nice and I think they make the code much more readable.
Do you really prefer:
BUG_ON(PFN_DOWN(addr + size) > bdata->node_low_pfn)
over
BUG_ON(end > bdata->node_low_pfn);
Also, these do a bit more than just conversions to using the pfn/page
macros. With this much churn, it is more than possible that bugs can
creep in. How about a bit more restrictive conversion to the PFN_
macros, first?
Oh, and if you're going to chew through it later, feel free to make
things like sidx into decent variable names. ;)
Is everybody else OK with this code churn? It doesn't appear that there
is too much in -mm pending in this area.
-- Dave
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 7/7] bootmem: miscellaneous coding style fixes
2006-06-27 19:22 ` Franck Bui-Huu
@ 2006-06-27 22:35 ` Randy.Dunlap
0 siblings, 0 replies; 21+ messages in thread
From: Randy.Dunlap @ 2006-06-27 22:35 UTC (permalink / raw)
To: Franck Bui-Huu; +Cc: haveblue, akpm, mel, linux-kernel
On Tue, 27 Jun 2006 21:22:29 +0200 Franck Bui-Huu wrote:
> 2006/6/27, Dave Hansen <haveblue@us.ibm.com>:
> > On Tue, 2006-06-27 at 14:54 +0200, Franck Bui-Huu wrote:
> > > }
> > > +
> > > /*
> > > * link bdata in order
> > > */
> > > static void __init link_bootmem(bootmem_data_t *bdata)
> > > {
> > > bootmem_data_t *ent;
> > > +
> > > if (list_empty(&bdata_list)) {
> >
> > I'd discourage you from including too many of these in your patches.
> > One or two is probably OK. But, there are a bunch of them, and it isn't
> > clear CodingStyle to have spacing like this either way. I'd drop them.
> >
>
> IMHO they make the code obviously more readable and obviously do not
> add any new bugs. So why drop them ?
I'd say the change is preferred even if it's not in CodingStyle.
---
~Randy
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH 6/7] bootmem: use pfn/page conversion macros
2006-06-27 19:26 ` Dave Hansen
@ 2006-06-29 7:53 ` Franck Bui-Huu
0 siblings, 0 replies; 21+ messages in thread
From: Franck Bui-Huu @ 2006-06-29 7:53 UTC (permalink / raw)
To: Dave Hansen; +Cc: Franck, Andrew Morton, Mel Gorman, Linux Kernel Mailing List
Dave Hansen wrote:
> On Tue, 2006-06-27 at 14:54 +0200, Franck Bui-Huu wrote:
>> static void __init free_bootmem_core(bootmem_data_t *bdata, unsigned
>> long addr,
>> unsigned long size)
>> {
>> + unsigned long sidx, eidx;
>> unsigned long i;
>> - unsigned long start;
>> +
>> /*
>> * round down end of usable mem, partially free pages are
>> * considered reserved.
>> */
>> - unsigned long sidx;
>> - unsigned long eidx = (addr + size -
>> bdata->node_boot_start)/PAGE_SIZE;
>> - unsigned long end = (addr + size)/PAGE_SIZE;
>> -
>> BUG_ON(!size);
>> - BUG_ON(end > bdata->node_low_pfn);
>> + BUG_ON(PFN_DOWN(addr + size) > bdata->node_low_pfn);
>
> In general, I like these kinds of conversions. But, in this case, I
> think it makes the code harder to read. Those intermediate variables
> are really nice and I think they make the code much more readable.
>
> Do you really prefer:
>
> BUG_ON(PFN_DOWN(addr + size) > bdata->node_low_pfn)
>
> over
>
> BUG_ON(end > bdata->node_low_pfn);
>
It depends of the context. Generally, I think you're right but in that
case I prefer the first case. Why ? because "addr + size" is not a
complex expression, it's quite easy to understand what it means. And
secondly the place where "end" is defined made me think that it was
used all along the function but its use was very punctual.
> Also, these do a bit more than just conversions to using the pfn/page
> macros. With this much churn, it is more than possible that bugs can
> creep in. How about a bit more restrictive conversion to the PFN_
> macros, first?
>
> Oh, and if you're going to chew through it later, feel free to make
> things like sidx into decent variable names. ;)
>
> Is everybody else OK with this code churn? It doesn't appear that there
> is too much in -mm pending in this area.
>
It seems that bootmem allocator doesn't get a lot of interest...
Should we stop this work ?
Franck
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2006-06-29 7:49 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-26 13:11 [PATCH] Clean up the bootmem allocator Franck Bui-Huu
2006-06-26 17:58 ` Dave Hansen
2006-06-26 18:10 ` Andrew Morton
2006-06-27 8:23 ` Franck Bui-Huu
2006-06-27 12:53 ` [PATCH 0/7] " Franck Bui-Huu
2006-06-27 12:53 ` [PATCH 1/7] bootmem: remove useless __init in header file Franck Bui-Huu
2006-06-27 17:17 ` Dave Hansen
2006-06-27 19:18 ` Franck Bui-Huu
2006-06-27 12:53 ` [PATCH 2/7] bootmem: mark link_bootmem() as part of the __init section Franck Bui-Huu
2006-06-27 17:17 ` Dave Hansen
2006-06-27 19:18 ` Franck Bui-Huu
2006-06-27 12:54 ` [PATCH 3/7] bootmem: remove useless parentheses in bootmem header file Franck Bui-Huu
2006-06-27 12:54 ` [PATCH 4/7] bootmem: limit to 80 columns width Franck Bui-Huu
2006-06-27 12:54 ` [PATCH 5/7] bootmem: remove useless headers inclusions Franck Bui-Huu
2006-06-27 12:54 ` [PATCH 6/7] bootmem: use pfn/page conversion macros Franck Bui-Huu
2006-06-27 19:26 ` Dave Hansen
2006-06-29 7:53 ` Franck Bui-Huu
2006-06-27 12:54 ` [PATCH 7/7] bootmem: miscellaneous coding style fixes Franck Bui-Huu
2006-06-27 17:26 ` Dave Hansen
2006-06-27 19:22 ` Franck Bui-Huu
2006-06-27 22:35 ` Randy.Dunlap
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox