Skip to content

Commit bbfceef

Browse files
Matt TolentinoLinus Torvalds
authored andcommitted
[PATCH] add x86-64 specific support for sparsemem
This patch adds in the necessary support for sparsemem such that x86-64 kernels may use sparsemem as an alternative to discontigmem for NUMA kernels. Note that this does no preclude one from continuing to build NUMA kernels using discontigmem, but merely allows the option to build NUMA kernels with sparsemem. Interestingly, the use of sparsemem in lieu of discontigmem in NUMA kernels results in reduced text size for otherwise equivalent kernels as shown in the example builds below: text data bss dec hex filename 2371036 765884 1237108 4374028 42be0c vmlinux.discontig 2366549 776484 1302772 4445805 43d66d vmlinux.sparse Signed-off-by: Matt Tolentino <matthew.e.tolentino@intel.com> Signed-off-by: Dave Hansen <haveblue@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 2b97690 commit bbfceef

4 files changed

Lines changed: 51 additions & 12 deletions

File tree

‎arch/x86_64/kernel/setup.c‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
#include <linux/acpi.h>
4141
#include <linux/kallsyms.h>
4242
#include <linux/edd.h>
43+
#include <linux/mmzone.h>
44+
4345
#include <asm/mtrr.h>
4446
#include <asm/uaccess.h>
4547
#include <asm/system.h>
@@ -378,16 +380,19 @@ static __init void parse_cmdline_early (char ** cmdline_p)
378380
}
379381

380382
#ifndef CONFIG_NUMA
381-
static void __init contig_initmem_init(void)
383+
static void __init
384+
contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
382385
{
383-
unsigned long bootmap_size, bootmap;
384-
bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
385-
bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size);
386-
if (bootmap == -1L)
387-
panic("Cannot find bootmem map of size %ld\n",bootmap_size);
388-
bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
389-
e820_bootmem_free(NODE_DATA(0), 0, end_pfn << PAGE_SHIFT);
390-
reserve_bootmem(bootmap, bootmap_size);
386+
unsigned long bootmap_size, bootmap;
387+
388+
memory_present(0, start_pfn, end_pfn);
389+
bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
390+
bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size);
391+
if (bootmap == -1L)
392+
panic("Cannot find bootmem map of size %ld\n",bootmap_size);
393+
bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
394+
e820_bootmem_free(NODE_DATA(0), 0, end_pfn << PAGE_SHIFT);
395+
reserve_bootmem(bootmap, bootmap_size);
391396
}
392397
#endif
393398

@@ -557,7 +562,7 @@ void __init setup_arch(char **cmdline_p)
557562
#ifdef CONFIG_NUMA
558563
numa_initmem_init(0, end_pfn);
559564
#else
560-
contig_initmem_init();
565+
contig_initmem_init(0, end_pfn);
561566
#endif
562567

563568
/* Reserve direct mapping */
@@ -618,6 +623,8 @@ void __init setup_arch(char **cmdline_p)
618623
}
619624
}
620625
#endif
626+
627+
sparse_init();
621628
paging_init();
622629

623630
check_ioapic();

‎arch/x86_64/mm/numa.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ int __init compute_hash_shift(struct node *nodes, int numnodes)
6666
return -1;
6767
}
6868

69+
#ifdef CONFIG_SPARSEMEM
70+
int early_pfn_to_nid(unsigned long pfn)
71+
{
72+
return phys_to_nid(pfn << PAGE_SHIFT);
73+
}
74+
#endif
75+
6976
/* Initialize bootmem allocator for a node */
7077
void __init setup_node_bootmem(int nodeid, unsigned long start, unsigned long end)
7178
{
@@ -80,6 +87,7 @@ void __init setup_node_bootmem(int nodeid, unsigned long start, unsigned long en
8087
start_pfn = start >> PAGE_SHIFT;
8188
end_pfn = end >> PAGE_SHIFT;
8289

90+
memory_present(nodeid, start_pfn, end_pfn);
8391
nodedata_phys = find_e820_area(start, end, pgdat_size);
8492
if (nodedata_phys == -1L)
8593
panic("Cannot find memory pgdat in node %d\n", nodeid);

‎include/asm-x86_64/bitops.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,6 @@ static __inline__ int ffs(int x)
411411
/* find last set bit */
412412
#define fls(x) generic_fls(x)
413413

414-
#define ARCH_HAS_ATOMIC_UNSIGNED 1
415-
416414
#endif /* __KERNEL__ */
417415

418416
#endif /* _X86_64_BITOPS_H */

‎include/asm-x86_64/sparsemem.h‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef _ASM_X86_64_SPARSEMEM_H
2+
#define _ASM_X86_64_SPARSEMEM_H 1
3+
4+
#ifdef CONFIG_SPARSEMEM
5+
6+
/*
7+
* generic non-linear memory support:
8+
*
9+
* 1) we will not split memory into more chunks than will fit into the flags
10+
* field of the struct page
11+
*
12+
* SECTION_SIZE_BITS 2^n: size of each section
13+
* MAX_PHYSADDR_BITS 2^n: max size of physical address space
14+
* MAX_PHYSMEM_BITS 2^n: how much memory we can have in that space
15+
*
16+
*/
17+
18+
#define SECTION_SIZE_BITS 27 /* matt - 128 is convenient right now */
19+
#define MAX_PHYSADDR_BITS 40
20+
#define MAX_PHYSMEM_BITS 40
21+
22+
extern int early_pfn_to_nid(unsigned long pfn);
23+
24+
#endif /* CONFIG_SPARSEMEM */
25+
26+
#endif /* _ASM_X86_64_SPARSEMEM_H */

0 commit comments

Comments
 (0)