diff options
author | Andy Whitcroft <apw@shadowen.org> | 2005-06-23 03:07:54 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-06-23 12:45:04 -0400 |
commit | d41dee369bff3b9dcb6328d4d822926c28cc2594 (patch) | |
tree | a0405f3b7af3ebca21838a7d427bd75a067bf850 /include/linux/mmzone.h | |
parent | af705362ab6018071310c5fcd436a6b457517d5f (diff) |
[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>
Diffstat (limited to 'include/linux/mmzone.h')
-rw-r--r-- | include/linux/mmzone.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 6ef07de98d69..19860d317ec2 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h | |||
@@ -269,7 +269,9 @@ typedef struct pglist_data { | |||
269 | struct zone node_zones[MAX_NR_ZONES]; | 269 | struct zone node_zones[MAX_NR_ZONES]; |
270 | struct zonelist node_zonelists[GFP_ZONETYPES]; | 270 | struct zonelist node_zonelists[GFP_ZONETYPES]; |
271 | int nr_zones; | 271 | int nr_zones; |
272 | #ifdef CONFIG_FLAT_NODE_MEM_MAP | ||
272 | struct page *node_mem_map; | 273 | struct page *node_mem_map; |
274 | #endif | ||
273 | struct bootmem_data *bdata; | 275 | struct bootmem_data *bdata; |
274 | unsigned long node_start_pfn; | 276 | unsigned long node_start_pfn; |
275 | unsigned long node_present_pages; /* total number of physical pages */ | 277 | unsigned long node_present_pages; /* total number of physical pages */ |
@@ -284,7 +286,11 @@ typedef struct pglist_data { | |||
284 | 286 | ||
285 | #define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages) | 287 | #define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages) |
286 | #define node_spanned_pages(nid) (NODE_DATA(nid)->node_spanned_pages) | 288 | #define node_spanned_pages(nid) (NODE_DATA(nid)->node_spanned_pages) |
289 | #ifdef CONFIG_FLAT_NODE_MEM_MAP | ||
287 | #define pgdat_page_nr(pgdat, pagenr) ((pgdat)->node_mem_map + (pagenr)) | 290 | #define pgdat_page_nr(pgdat, pagenr) ((pgdat)->node_mem_map + (pagenr)) |
291 | #else | ||
292 | #define pgdat_page_nr(pgdat, pagenr) pfn_to_page((pgdat)->node_start_pfn + (pagenr)) | ||
293 | #endif | ||
288 | #define nid_page_nr(nid, pagenr) pgdat_page_nr(NODE_DATA(nid),(pagenr)) | 294 | #define nid_page_nr(nid, pagenr) pgdat_page_nr(NODE_DATA(nid),(pagenr)) |
289 | 295 | ||
290 | extern struct pglist_data *pgdat_list; | 296 | extern struct pglist_data *pgdat_list; |
@@ -416,6 +422,10 @@ extern struct pglist_data contig_page_data; | |||
416 | 422 | ||
417 | #endif /* !CONFIG_NEED_MULTIPLE_NODES */ | 423 | #endif /* !CONFIG_NEED_MULTIPLE_NODES */ |
418 | 424 | ||
425 | #ifdef CONFIG_SPARSEMEM | ||
426 | #include <asm/sparsemem.h> | ||
427 | #endif | ||
428 | |||
419 | #if BITS_PER_LONG == 32 || defined(ARCH_HAS_ATOMIC_UNSIGNED) | 429 | #if BITS_PER_LONG == 32 || defined(ARCH_HAS_ATOMIC_UNSIGNED) |
420 | /* | 430 | /* |
421 | * with 32 bit page->flags field, we reserve 8 bits for node/zone info. | 431 | * with 32 bit page->flags field, we reserve 8 bits for node/zone info. |
@@ -439,6 +449,92 @@ extern struct pglist_data contig_page_data; | |||
439 | #define early_pfn_to_nid(nid) (0UL) | 449 | #define early_pfn_to_nid(nid) (0UL) |
440 | #endif | 450 | #endif |
441 | 451 | ||
452 | #define pfn_to_section_nr(pfn) ((pfn) >> PFN_SECTION_SHIFT) | ||
453 | #define section_nr_to_pfn(sec) ((sec) << PFN_SECTION_SHIFT) | ||
454 | |||
455 | #ifdef CONFIG_SPARSEMEM | ||
456 | |||
457 | /* | ||
458 | * SECTION_SHIFT #bits space required to store a section # | ||
459 | * | ||
460 | * PA_SECTION_SHIFT physical address to/from section number | ||
461 | * PFN_SECTION_SHIFT pfn to/from section number | ||
462 | */ | ||
463 | #define SECTIONS_SHIFT (MAX_PHYSMEM_BITS - SECTION_SIZE_BITS) | ||
464 | |||
465 | #define PA_SECTION_SHIFT (SECTION_SIZE_BITS) | ||
466 | #define PFN_SECTION_SHIFT (SECTION_SIZE_BITS - PAGE_SHIFT) | ||
467 | |||
468 | #define NR_MEM_SECTIONS (1UL << SECTIONS_SHIFT) | ||
469 | |||
470 | #define PAGES_PER_SECTION (1UL << PFN_SECTION_SHIFT) | ||
471 | #define PAGE_SECTION_MASK (~(PAGES_PER_SECTION-1)) | ||
472 | |||
473 | #if (MAX_ORDER - 1 + PAGE_SHIFT) > SECTION_SIZE_BITS | ||
474 | #error Allocator MAX_ORDER exceeds SECTION_SIZE | ||
475 | #endif | ||
476 | |||
477 | struct page; | ||
478 | struct mem_section { | ||
479 | struct page *section_mem_map; | ||
480 | }; | ||
481 | |||
482 | extern struct mem_section mem_section[NR_MEM_SECTIONS]; | ||
483 | |||
484 | /* | ||
485 | * Given a kernel address, find the home node of the underlying memory. | ||
486 | */ | ||
487 | #define kvaddr_to_nid(kaddr) pfn_to_nid(__pa(kaddr) >> PAGE_SHIFT) | ||
488 | |||
489 | static inline struct mem_section *__pfn_to_section(unsigned long pfn) | ||
490 | { | ||
491 | return &mem_section[pfn_to_section_nr(pfn)]; | ||
492 | } | ||
493 | |||
494 | #define pfn_to_page(pfn) \ | ||
495 | ({ \ | ||
496 | unsigned long __pfn = (pfn); \ | ||
497 | __pfn_to_section(__pfn)->section_mem_map + __pfn; \ | ||
498 | }) | ||
499 | #define page_to_pfn(page) \ | ||
500 | ({ \ | ||
501 | page - mem_section[page_to_section(page)].section_mem_map; \ | ||
502 | }) | ||
503 | |||
504 | static inline int pfn_valid(unsigned long pfn) | ||
505 | { | ||
506 | if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS) | ||
507 | return 0; | ||
508 | return mem_section[pfn_to_section_nr(pfn)].section_mem_map != 0; | ||
509 | } | ||
510 | |||
511 | /* | ||
512 | * These are _only_ used during initialisation, therefore they | ||
513 | * can use __initdata ... They could have names to indicate | ||
514 | * this restriction. | ||
515 | */ | ||
516 | #ifdef CONFIG_NUMA | ||
517 | #define pfn_to_nid early_pfn_to_nid | ||
518 | #endif | ||
519 | |||
520 | #define pfn_to_pgdat(pfn) \ | ||
521 | ({ \ | ||
522 | NODE_DATA(pfn_to_nid(pfn)); \ | ||
523 | }) | ||
524 | |||
525 | #define early_pfn_valid(pfn) pfn_valid(pfn) | ||
526 | void sparse_init(void); | ||
527 | #else | ||
528 | #define sparse_init() do {} while (0) | ||
529 | #endif /* CONFIG_SPARSEMEM */ | ||
530 | |||
531 | #ifndef early_pfn_valid | ||
532 | #define early_pfn_valid(pfn) (1) | ||
533 | #endif | ||
534 | |||
535 | void memory_present(int nid, unsigned long start, unsigned long end); | ||
536 | unsigned long __init node_memmap_size_bytes(int, unsigned long, unsigned long); | ||
537 | |||
442 | #endif /* !__ASSEMBLY__ */ | 538 | #endif /* !__ASSEMBLY__ */ |
443 | #endif /* __KERNEL__ */ | 539 | #endif /* __KERNEL__ */ |
444 | #endif /* _LINUX_MMZONE_H */ | 540 | #endif /* _LINUX_MMZONE_H */ |