[PATCH] sparsemem memory model
Sparsemem abstracts the use of discontiguous mem_maps[]. This kind of
mem_map[] is needed by discontiguous memory machines (like in the old
CONFIG_DISCONTIGMEM case) as well as memory hotplug systems. Sparsemem
replaces DISCONTIGMEM when enabled, and it is hoped that it can eventually
become a complete replacement.
A significant advantage over DISCONTIGMEM is that it's completely separated
from CONFIG_NUMA. When producing this patch, it became apparent in that NUMA
and DISCONTIG are often confused.
Another advantage is that sparse doesn't require each NUMA node's ranges to be
contiguous. It can handle overlapping ranges between nodes with no problems,
where DISCONTIGMEM currently throws away that memory.
Sparsemem uses an array to provide different pfn_to_page() translations for
each SECTION_SIZE area of physical memory. This is what allows the mem_map[]
to be chopped up.
In order to do quick pfn_to_page() operations, the section number of the page
is encoded in page->flags. Part of the sparsemem infrastructure enables
sharing of these bits more dynamically (at compile-time) between the
page_zone() and sparsemem operations. However, on 32-bit architectures, the
number of bits is quite limited, and may require growing the size of the
page->flags type in certain conditions. Several things might force this to
occur: a decrease in the SECTION_SIZE (if you want to hotplug smaller areas of
memory), an increase in the physical address space, or an increase in the
number of used page->flags.
One thing to note is that, once sparsemem is present, the NUMA node
information no longer needs to be stored in the page->flags. It might provide
speed increases on certain platforms and will be stored there if there is
room. But, if out of room, an alternate (theoretically slower) mechanism is
used.
This patch introduces CONFIG_FLATMEM. It is used in almost all cases where
there used to be an #ifndef DISCONTIG, because SPARSEMEM and DISCONTIGMEM
often have to compile out the same areas of code.
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Martin Bligh <mbligh@aracnet.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>
Signed-off-by: Bob Picco <bob.picco@hp.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-23 01:07:54 -06:00
|
|
|
/*
|
|
|
|
* sparse memory mappings.
|
|
|
|
*/
|
|
|
|
#include <linux/config.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/mmzone.h>
|
|
|
|
#include <linux/bootmem.h>
|
2005-10-29 19:16:55 -06:00
|
|
|
#include <linux/highmem.h>
|
[PATCH] sparsemem memory model
Sparsemem abstracts the use of discontiguous mem_maps[]. This kind of
mem_map[] is needed by discontiguous memory machines (like in the old
CONFIG_DISCONTIGMEM case) as well as memory hotplug systems. Sparsemem
replaces DISCONTIGMEM when enabled, and it is hoped that it can eventually
become a complete replacement.
A significant advantage over DISCONTIGMEM is that it's completely separated
from CONFIG_NUMA. When producing this patch, it became apparent in that NUMA
and DISCONTIG are often confused.
Another advantage is that sparse doesn't require each NUMA node's ranges to be
contiguous. It can handle overlapping ranges between nodes with no problems,
where DISCONTIGMEM currently throws away that memory.
Sparsemem uses an array to provide different pfn_to_page() translations for
each SECTION_SIZE area of physical memory. This is what allows the mem_map[]
to be chopped up.
In order to do quick pfn_to_page() operations, the section number of the page
is encoded in page->flags. Part of the sparsemem infrastructure enables
sharing of these bits more dynamically (at compile-time) between the
page_zone() and sparsemem operations. However, on 32-bit architectures, the
number of bits is quite limited, and may require growing the size of the
page->flags type in certain conditions. Several things might force this to
occur: a decrease in the SECTION_SIZE (if you want to hotplug smaller areas of
memory), an increase in the physical address space, or an increase in the
number of used page->flags.
One thing to note is that, once sparsemem is present, the NUMA node
information no longer needs to be stored in the page->flags. It might provide
speed increases on certain platforms and will be stored there if there is
room. But, if out of room, an alternate (theoretically slower) mechanism is
used.
This patch introduces CONFIG_FLATMEM. It is used in almost all cases where
there used to be an #ifndef DISCONTIG, because SPARSEMEM and DISCONTIGMEM
often have to compile out the same areas of code.
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Martin Bligh <mbligh@aracnet.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>
Signed-off-by: Bob Picco <bob.picco@hp.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-23 01:07:54 -06:00
|
|
|
#include <linux/module.h>
|
2005-09-03 16:54:29 -06:00
|
|
|
#include <linux/spinlock.h>
|
2005-10-29 19:16:55 -06:00
|
|
|
#include <linux/vmalloc.h>
|
[PATCH] sparsemem memory model
Sparsemem abstracts the use of discontiguous mem_maps[]. This kind of
mem_map[] is needed by discontiguous memory machines (like in the old
CONFIG_DISCONTIGMEM case) as well as memory hotplug systems. Sparsemem
replaces DISCONTIGMEM when enabled, and it is hoped that it can eventually
become a complete replacement.
A significant advantage over DISCONTIGMEM is that it's completely separated
from CONFIG_NUMA. When producing this patch, it became apparent in that NUMA
and DISCONTIG are often confused.
Another advantage is that sparse doesn't require each NUMA node's ranges to be
contiguous. It can handle overlapping ranges between nodes with no problems,
where DISCONTIGMEM currently throws away that memory.
Sparsemem uses an array to provide different pfn_to_page() translations for
each SECTION_SIZE area of physical memory. This is what allows the mem_map[]
to be chopped up.
In order to do quick pfn_to_page() operations, the section number of the page
is encoded in page->flags. Part of the sparsemem infrastructure enables
sharing of these bits more dynamically (at compile-time) between the
page_zone() and sparsemem operations. However, on 32-bit architectures, the
number of bits is quite limited, and may require growing the size of the
page->flags type in certain conditions. Several things might force this to
occur: a decrease in the SECTION_SIZE (if you want to hotplug smaller areas of
memory), an increase in the physical address space, or an increase in the
number of used page->flags.
One thing to note is that, once sparsemem is present, the NUMA node
information no longer needs to be stored in the page->flags. It might provide
speed increases on certain platforms and will be stored there if there is
room. But, if out of room, an alternate (theoretically slower) mechanism is
used.
This patch introduces CONFIG_FLATMEM. It is used in almost all cases where
there used to be an #ifndef DISCONTIG, because SPARSEMEM and DISCONTIGMEM
often have to compile out the same areas of code.
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Martin Bligh <mbligh@aracnet.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>
Signed-off-by: Bob Picco <bob.picco@hp.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-23 01:07:54 -06:00
|
|
|
#include <asm/dma.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Permanent SPARSEMEM data:
|
|
|
|
*
|
|
|
|
* 1) mem_section - memory sections, mem_map's for valid memory
|
|
|
|
*/
|
2005-09-03 16:54:28 -06:00
|
|
|
#ifdef CONFIG_SPARSEMEM_EXTREME
|
2005-09-03 16:54:26 -06:00
|
|
|
struct mem_section *mem_section[NR_SECTION_ROOTS]
|
|
|
|
____cacheline_maxaligned_in_smp;
|
2005-09-03 16:54:28 -06:00
|
|
|
#else
|
|
|
|
struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT]
|
|
|
|
____cacheline_maxaligned_in_smp;
|
|
|
|
#endif
|
|
|
|
EXPORT_SYMBOL(mem_section);
|
|
|
|
|
|
|
|
#ifdef CONFIG_SPARSEMEM_EXTREME
|
2005-09-03 16:54:29 -06:00
|
|
|
static struct mem_section *sparse_index_alloc(int nid)
|
|
|
|
{
|
|
|
|
struct mem_section *section = NULL;
|
|
|
|
unsigned long array_size = SECTIONS_PER_ROOT *
|
|
|
|
sizeof(struct mem_section);
|
|
|
|
|
|
|
|
section = alloc_bootmem_node(NODE_DATA(nid), array_size);
|
|
|
|
|
|
|
|
if (section)
|
|
|
|
memset(section, 0, array_size);
|
|
|
|
|
|
|
|
return section;
|
2005-09-03 16:54:28 -06:00
|
|
|
}
|
2005-09-03 16:54:26 -06:00
|
|
|
|
2005-09-03 16:54:29 -06:00
|
|
|
static int sparse_index_init(unsigned long section_nr, int nid)
|
2005-09-03 16:54:26 -06:00
|
|
|
{
|
2005-09-03 16:54:29 -06:00
|
|
|
static spinlock_t index_init_lock = SPIN_LOCK_UNLOCKED;
|
|
|
|
unsigned long root = SECTION_NR_TO_ROOT(section_nr);
|
|
|
|
struct mem_section *section;
|
|
|
|
int ret = 0;
|
2005-09-03 16:54:26 -06:00
|
|
|
|
|
|
|
if (mem_section[root])
|
2005-09-03 16:54:29 -06:00
|
|
|
return -EEXIST;
|
2005-09-03 16:54:28 -06:00
|
|
|
|
2005-09-03 16:54:29 -06:00
|
|
|
section = sparse_index_alloc(nid);
|
|
|
|
/*
|
|
|
|
* This lock keeps two different sections from
|
|
|
|
* reallocating for the same index
|
|
|
|
*/
|
|
|
|
spin_lock(&index_init_lock);
|
2005-09-03 16:54:28 -06:00
|
|
|
|
2005-09-03 16:54:29 -06:00
|
|
|
if (mem_section[root]) {
|
|
|
|
ret = -EEXIST;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
mem_section[root] = section;
|
|
|
|
out:
|
|
|
|
spin_unlock(&index_init_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#else /* !SPARSEMEM_EXTREME */
|
|
|
|
static inline int sparse_index_init(unsigned long section_nr, int nid)
|
|
|
|
{
|
|
|
|
return 0;
|
2005-09-03 16:54:26 -06:00
|
|
|
}
|
2005-09-03 16:54:29 -06:00
|
|
|
#endif
|
|
|
|
|
2005-10-29 19:16:51 -06:00
|
|
|
/*
|
|
|
|
* Although written for the SPARSEMEM_EXTREME case, this happens
|
|
|
|
* to also work for the flat array case becase
|
|
|
|
* NR_SECTION_ROOTS==NR_MEM_SECTIONS.
|
|
|
|
*/
|
|
|
|
int __section_nr(struct mem_section* ms)
|
|
|
|
{
|
|
|
|
unsigned long root_nr;
|
|
|
|
struct mem_section* root;
|
|
|
|
|
|
|
|
for (root_nr = 0;
|
|
|
|
root_nr < NR_MEM_SECTIONS;
|
|
|
|
root_nr += SECTIONS_PER_ROOT) {
|
|
|
|
root = __nr_to_section(root_nr);
|
|
|
|
|
|
|
|
if (!root)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ((ms >= root) && (ms < (root + SECTIONS_PER_ROOT)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (root_nr * SECTIONS_PER_ROOT) + (ms - root);
|
|
|
|
}
|
|
|
|
|
[PATCH] sparsemem memory model
Sparsemem abstracts the use of discontiguous mem_maps[]. This kind of
mem_map[] is needed by discontiguous memory machines (like in the old
CONFIG_DISCONTIGMEM case) as well as memory hotplug systems. Sparsemem
replaces DISCONTIGMEM when enabled, and it is hoped that it can eventually
become a complete replacement.
A significant advantage over DISCONTIGMEM is that it's completely separated
from CONFIG_NUMA. When producing this patch, it became apparent in that NUMA
and DISCONTIG are often confused.
Another advantage is that sparse doesn't require each NUMA node's ranges to be
contiguous. It can handle overlapping ranges between nodes with no problems,
where DISCONTIGMEM currently throws away that memory.
Sparsemem uses an array to provide different pfn_to_page() translations for
each SECTION_SIZE area of physical memory. This is what allows the mem_map[]
to be chopped up.
In order to do quick pfn_to_page() operations, the section number of the page
is encoded in page->flags. Part of the sparsemem infrastructure enables
sharing of these bits more dynamically (at compile-time) between the
page_zone() and sparsemem operations. However, on 32-bit architectures, the
number of bits is quite limited, and may require growing the size of the
page->flags type in certain conditions. Several things might force this to
occur: a decrease in the SECTION_SIZE (if you want to hotplug smaller areas of
memory), an increase in the physical address space, or an increase in the
number of used page->flags.
One thing to note is that, once sparsemem is present, the NUMA node
information no longer needs to be stored in the page->flags. It might provide
speed increases on certain platforms and will be stored there if there is
room. But, if out of room, an alternate (theoretically slower) mechanism is
used.
This patch introduces CONFIG_FLATMEM. It is used in almost all cases where
there used to be an #ifndef DISCONTIG, because SPARSEMEM and DISCONTIGMEM
often have to compile out the same areas of code.
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Martin Bligh <mbligh@aracnet.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>
Signed-off-by: Bob Picco <bob.picco@hp.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-23 01:07:54 -06:00
|
|
|
/* Record a memory area against a node. */
|
|
|
|
void memory_present(int nid, unsigned long start, unsigned long end)
|
|
|
|
{
|
|
|
|
unsigned long pfn;
|
|
|
|
|
|
|
|
start &= PAGE_SECTION_MASK;
|
|
|
|
for (pfn = start; pfn < end; pfn += PAGES_PER_SECTION) {
|
|
|
|
unsigned long section = pfn_to_section_nr(pfn);
|
2005-09-03 16:54:26 -06:00
|
|
|
struct mem_section *ms;
|
|
|
|
|
|
|
|
sparse_index_init(section, nid);
|
|
|
|
|
|
|
|
ms = __nr_to_section(section);
|
|
|
|
if (!ms->section_mem_map)
|
|
|
|
ms->section_mem_map = SECTION_MARKED_PRESENT;
|
[PATCH] sparsemem memory model
Sparsemem abstracts the use of discontiguous mem_maps[]. This kind of
mem_map[] is needed by discontiguous memory machines (like in the old
CONFIG_DISCONTIGMEM case) as well as memory hotplug systems. Sparsemem
replaces DISCONTIGMEM when enabled, and it is hoped that it can eventually
become a complete replacement.
A significant advantage over DISCONTIGMEM is that it's completely separated
from CONFIG_NUMA. When producing this patch, it became apparent in that NUMA
and DISCONTIG are often confused.
Another advantage is that sparse doesn't require each NUMA node's ranges to be
contiguous. It can handle overlapping ranges between nodes with no problems,
where DISCONTIGMEM currently throws away that memory.
Sparsemem uses an array to provide different pfn_to_page() translations for
each SECTION_SIZE area of physical memory. This is what allows the mem_map[]
to be chopped up.
In order to do quick pfn_to_page() operations, the section number of the page
is encoded in page->flags. Part of the sparsemem infrastructure enables
sharing of these bits more dynamically (at compile-time) between the
page_zone() and sparsemem operations. However, on 32-bit architectures, the
number of bits is quite limited, and may require growing the size of the
page->flags type in certain conditions. Several things might force this to
occur: a decrease in the SECTION_SIZE (if you want to hotplug smaller areas of
memory), an increase in the physical address space, or an increase in the
number of used page->flags.
One thing to note is that, once sparsemem is present, the NUMA node
information no longer needs to be stored in the page->flags. It might provide
speed increases on certain platforms and will be stored there if there is
room. But, if out of room, an alternate (theoretically slower) mechanism is
used.
This patch introduces CONFIG_FLATMEM. It is used in almost all cases where
there used to be an #ifndef DISCONTIG, because SPARSEMEM and DISCONTIGMEM
often have to compile out the same areas of code.
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Martin Bligh <mbligh@aracnet.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>
Signed-off-by: Bob Picco <bob.picco@hp.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-23 01:07:54 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only used by the i386 NUMA architecures, but relatively
|
|
|
|
* generic code.
|
|
|
|
*/
|
|
|
|
unsigned long __init node_memmap_size_bytes(int nid, unsigned long start_pfn,
|
|
|
|
unsigned long end_pfn)
|
|
|
|
{
|
|
|
|
unsigned long pfn;
|
|
|
|
unsigned long nr_pages = 0;
|
|
|
|
|
|
|
|
for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
|
|
|
|
if (nid != early_pfn_to_nid(pfn))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (pfn_valid(pfn))
|
|
|
|
nr_pages += PAGES_PER_SECTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nr_pages * sizeof(struct page);
|
|
|
|
}
|
|
|
|
|
2005-06-23 01:08:00 -06:00
|
|
|
/*
|
|
|
|
* Subtle, we encode the real pfn into the mem_map such that
|
|
|
|
* the identity pfn - section_mem_map will return the actual
|
|
|
|
* physical page frame number.
|
|
|
|
*/
|
|
|
|
static unsigned long sparse_encode_mem_map(struct page *mem_map, unsigned long pnum)
|
|
|
|
{
|
|
|
|
return (unsigned long)(mem_map - (section_nr_to_pfn(pnum)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need this if we ever free the mem_maps. While not implemented yet,
|
|
|
|
* this function is included for parity with its sibling.
|
|
|
|
*/
|
|
|
|
static __attribute((unused))
|
|
|
|
struct page *sparse_decode_mem_map(unsigned long coded_mem_map, unsigned long pnum)
|
|
|
|
{
|
|
|
|
return ((struct page *)coded_mem_map) + section_nr_to_pfn(pnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sparse_init_one_section(struct mem_section *ms,
|
|
|
|
unsigned long pnum, struct page *mem_map)
|
|
|
|
{
|
|
|
|
if (!valid_section(ms))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
ms->section_mem_map |= sparse_encode_mem_map(mem_map, pnum);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct page *sparse_early_mem_map_alloc(unsigned long pnum)
|
|
|
|
{
|
|
|
|
struct page *map;
|
|
|
|
int nid = early_pfn_to_nid(section_nr_to_pfn(pnum));
|
2005-09-03 16:54:26 -06:00
|
|
|
struct mem_section *ms = __nr_to_section(pnum);
|
2005-06-23 01:08:00 -06:00
|
|
|
|
|
|
|
map = alloc_remap(nid, sizeof(struct page) * PAGES_PER_SECTION);
|
|
|
|
if (map)
|
|
|
|
return map;
|
|
|
|
|
|
|
|
map = alloc_bootmem_node(NODE_DATA(nid),
|
|
|
|
sizeof(struct page) * PAGES_PER_SECTION);
|
|
|
|
if (map)
|
|
|
|
return map;
|
|
|
|
|
|
|
|
printk(KERN_WARNING "%s: allocation failed\n", __FUNCTION__);
|
2005-09-03 16:54:26 -06:00
|
|
|
ms->section_mem_map = 0;
|
2005-06-23 01:08:00 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-10-29 19:16:55 -06:00
|
|
|
static struct page *__kmalloc_section_memmap(unsigned long nr_pages)
|
|
|
|
{
|
|
|
|
struct page *page, *ret;
|
|
|
|
unsigned long memmap_size = sizeof(struct page) * nr_pages;
|
|
|
|
|
|
|
|
page = alloc_pages(GFP_KERNEL, get_order(memmap_size));
|
|
|
|
if (page)
|
|
|
|
goto got_map_page;
|
|
|
|
|
|
|
|
ret = vmalloc(memmap_size);
|
|
|
|
if (ret)
|
|
|
|
goto got_map_ptr;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
got_map_page:
|
|
|
|
ret = (struct page *)pfn_to_kaddr(page_to_pfn(page));
|
|
|
|
got_map_ptr:
|
|
|
|
memset(ret, 0, memmap_size);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vaddr_in_vmalloc_area(void *addr)
|
|
|
|
{
|
|
|
|
if (addr >= (void *)VMALLOC_START &&
|
|
|
|
addr < (void *)VMALLOC_END)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __kfree_section_memmap(struct page *memmap, unsigned long nr_pages)
|
|
|
|
{
|
|
|
|
if (vaddr_in_vmalloc_area(memmap))
|
|
|
|
vfree(memmap);
|
|
|
|
else
|
|
|
|
free_pages((unsigned long)memmap,
|
|
|
|
get_order(sizeof(struct page) * nr_pages));
|
|
|
|
}
|
|
|
|
|
[PATCH] sparsemem memory model
Sparsemem abstracts the use of discontiguous mem_maps[]. This kind of
mem_map[] is needed by discontiguous memory machines (like in the old
CONFIG_DISCONTIGMEM case) as well as memory hotplug systems. Sparsemem
replaces DISCONTIGMEM when enabled, and it is hoped that it can eventually
become a complete replacement.
A significant advantage over DISCONTIGMEM is that it's completely separated
from CONFIG_NUMA. When producing this patch, it became apparent in that NUMA
and DISCONTIG are often confused.
Another advantage is that sparse doesn't require each NUMA node's ranges to be
contiguous. It can handle overlapping ranges between nodes with no problems,
where DISCONTIGMEM currently throws away that memory.
Sparsemem uses an array to provide different pfn_to_page() translations for
each SECTION_SIZE area of physical memory. This is what allows the mem_map[]
to be chopped up.
In order to do quick pfn_to_page() operations, the section number of the page
is encoded in page->flags. Part of the sparsemem infrastructure enables
sharing of these bits more dynamically (at compile-time) between the
page_zone() and sparsemem operations. However, on 32-bit architectures, the
number of bits is quite limited, and may require growing the size of the
page->flags type in certain conditions. Several things might force this to
occur: a decrease in the SECTION_SIZE (if you want to hotplug smaller areas of
memory), an increase in the physical address space, or an increase in the
number of used page->flags.
One thing to note is that, once sparsemem is present, the NUMA node
information no longer needs to be stored in the page->flags. It might provide
speed increases on certain platforms and will be stored there if there is
room. But, if out of room, an alternate (theoretically slower) mechanism is
used.
This patch introduces CONFIG_FLATMEM. It is used in almost all cases where
there used to be an #ifndef DISCONTIG, because SPARSEMEM and DISCONTIGMEM
often have to compile out the same areas of code.
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Martin Bligh <mbligh@aracnet.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>
Signed-off-by: Bob Picco <bob.picco@hp.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-23 01:07:54 -06:00
|
|
|
/*
|
|
|
|
* Allocate the accumulated non-linear sections, allocate a mem_map
|
|
|
|
* for each and record the physical to section mapping.
|
|
|
|
*/
|
|
|
|
void sparse_init(void)
|
|
|
|
{
|
|
|
|
unsigned long pnum;
|
|
|
|
struct page *map;
|
|
|
|
|
|
|
|
for (pnum = 0; pnum < NR_MEM_SECTIONS; pnum++) {
|
2005-06-23 01:08:00 -06:00
|
|
|
if (!valid_section_nr(pnum))
|
[PATCH] sparsemem memory model
Sparsemem abstracts the use of discontiguous mem_maps[]. This kind of
mem_map[] is needed by discontiguous memory machines (like in the old
CONFIG_DISCONTIGMEM case) as well as memory hotplug systems. Sparsemem
replaces DISCONTIGMEM when enabled, and it is hoped that it can eventually
become a complete replacement.
A significant advantage over DISCONTIGMEM is that it's completely separated
from CONFIG_NUMA. When producing this patch, it became apparent in that NUMA
and DISCONTIG are often confused.
Another advantage is that sparse doesn't require each NUMA node's ranges to be
contiguous. It can handle overlapping ranges between nodes with no problems,
where DISCONTIGMEM currently throws away that memory.
Sparsemem uses an array to provide different pfn_to_page() translations for
each SECTION_SIZE area of physical memory. This is what allows the mem_map[]
to be chopped up.
In order to do quick pfn_to_page() operations, the section number of the page
is encoded in page->flags. Part of the sparsemem infrastructure enables
sharing of these bits more dynamically (at compile-time) between the
page_zone() and sparsemem operations. However, on 32-bit architectures, the
number of bits is quite limited, and may require growing the size of the
page->flags type in certain conditions. Several things might force this to
occur: a decrease in the SECTION_SIZE (if you want to hotplug smaller areas of
memory), an increase in the physical address space, or an increase in the
number of used page->flags.
One thing to note is that, once sparsemem is present, the NUMA node
information no longer needs to be stored in the page->flags. It might provide
speed increases on certain platforms and will be stored there if there is
room. But, if out of room, an alternate (theoretically slower) mechanism is
used.
This patch introduces CONFIG_FLATMEM. It is used in almost all cases where
there used to be an #ifndef DISCONTIG, because SPARSEMEM and DISCONTIGMEM
often have to compile out the same areas of code.
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Martin Bligh <mbligh@aracnet.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>
Signed-off-by: Bob Picco <bob.picco@hp.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-23 01:07:54 -06:00
|
|
|
continue;
|
|
|
|
|
2005-06-23 01:08:00 -06:00
|
|
|
map = sparse_early_mem_map_alloc(pnum);
|
2005-09-03 16:54:26 -06:00
|
|
|
if (!map)
|
|
|
|
continue;
|
|
|
|
sparse_init_one_section(__nr_to_section(pnum), pnum, map);
|
[PATCH] sparsemem memory model
Sparsemem abstracts the use of discontiguous mem_maps[]. This kind of
mem_map[] is needed by discontiguous memory machines (like in the old
CONFIG_DISCONTIGMEM case) as well as memory hotplug systems. Sparsemem
replaces DISCONTIGMEM when enabled, and it is hoped that it can eventually
become a complete replacement.
A significant advantage over DISCONTIGMEM is that it's completely separated
from CONFIG_NUMA. When producing this patch, it became apparent in that NUMA
and DISCONTIG are often confused.
Another advantage is that sparse doesn't require each NUMA node's ranges to be
contiguous. It can handle overlapping ranges between nodes with no problems,
where DISCONTIGMEM currently throws away that memory.
Sparsemem uses an array to provide different pfn_to_page() translations for
each SECTION_SIZE area of physical memory. This is what allows the mem_map[]
to be chopped up.
In order to do quick pfn_to_page() operations, the section number of the page
is encoded in page->flags. Part of the sparsemem infrastructure enables
sharing of these bits more dynamically (at compile-time) between the
page_zone() and sparsemem operations. However, on 32-bit architectures, the
number of bits is quite limited, and may require growing the size of the
page->flags type in certain conditions. Several things might force this to
occur: a decrease in the SECTION_SIZE (if you want to hotplug smaller areas of
memory), an increase in the physical address space, or an increase in the
number of used page->flags.
One thing to note is that, once sparsemem is present, the NUMA node
information no longer needs to be stored in the page->flags. It might provide
speed increases on certain platforms and will be stored there if there is
room. But, if out of room, an alternate (theoretically slower) mechanism is
used.
This patch introduces CONFIG_FLATMEM. It is used in almost all cases where
there used to be an #ifndef DISCONTIG, because SPARSEMEM and DISCONTIGMEM
often have to compile out the same areas of code.
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Martin Bligh <mbligh@aracnet.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Yasunori Goto <y-goto@jp.fujitsu.com>
Signed-off-by: Bob Picco <bob.picco@hp.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-23 01:07:54 -06:00
|
|
|
}
|
|
|
|
}
|
2005-06-23 01:08:00 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* returns the number of sections whose mem_maps were properly
|
|
|
|
* set. If this is <=0, then that means that the passed-in
|
|
|
|
* map was not consumed and must be freed.
|
|
|
|
*/
|
2005-10-29 19:16:55 -06:00
|
|
|
int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
|
|
|
|
int nr_pages)
|
2005-06-23 01:08:00 -06:00
|
|
|
{
|
2005-10-29 19:16:55 -06:00
|
|
|
unsigned long section_nr = pfn_to_section_nr(start_pfn);
|
|
|
|
struct pglist_data *pgdat = zone->zone_pgdat;
|
|
|
|
struct mem_section *ms;
|
|
|
|
struct page *memmap;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
2005-06-23 01:08:00 -06:00
|
|
|
|
2005-10-29 19:16:55 -06:00
|
|
|
/*
|
|
|
|
* no locking for this, because it does its own
|
|
|
|
* plus, it does a kmalloc
|
|
|
|
*/
|
|
|
|
sparse_index_init(section_nr, pgdat->node_id);
|
|
|
|
memmap = __kmalloc_section_memmap(nr_pages);
|
|
|
|
|
|
|
|
pgdat_resize_lock(pgdat, &flags);
|
2005-06-23 01:08:00 -06:00
|
|
|
|
2005-10-29 19:16:55 -06:00
|
|
|
ms = __pfn_to_section(start_pfn);
|
|
|
|
if (ms->section_mem_map & SECTION_MARKED_PRESENT) {
|
|
|
|
ret = -EEXIST;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-06-23 01:08:00 -06:00
|
|
|
ms->section_mem_map |= SECTION_MARKED_PRESENT;
|
|
|
|
|
2005-10-29 19:16:55 -06:00
|
|
|
ret = sparse_init_one_section(ms, section_nr, memmap);
|
|
|
|
|
|
|
|
if (ret <= 0)
|
|
|
|
__kfree_section_memmap(memmap, nr_pages);
|
|
|
|
out:
|
|
|
|
pgdat_resize_unlock(pgdat, &flags);
|
|
|
|
return ret;
|
2005-06-23 01:08:00 -06:00
|
|
|
}
|