2008-01-30 19:30:37 +07:00
|
|
|
/*
|
2005-04-17 05:20:36 +07:00
|
|
|
* Generic VM initialization for x86-64 NUMA setups.
|
|
|
|
* Copyright 2002,2003 Andi Kleen, SuSE Labs.
|
2008-01-30 19:30:37 +07:00
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/bootmem.h>
|
2010-08-26 03:39:17 +07:00
|
|
|
#include <linux/memblock.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/mmzone.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/nodemask.h>
|
2008-01-30 19:33:11 +07:00
|
|
|
#include <linux/sched.h>
|
2011-02-16 18:13:06 +07:00
|
|
|
#include <linux/acpi.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#include <asm/e820.h>
|
|
|
|
#include <asm/proto.h>
|
|
|
|
#include <asm/dma.h>
|
|
|
|
#include <asm/acpi.h>
|
2010-09-17 23:03:43 +07:00
|
|
|
#include <asm/amd_nb.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-02-22 17:10:08 +07:00
|
|
|
#include "numa_internal.h"
|
2011-02-16 23:11:08 +07:00
|
|
|
|
2005-09-07 05:17:45 +07:00
|
|
|
struct pglist_data *node_data[MAX_NUMNODES] __read_mostly;
|
2008-01-30 19:30:37 +07:00
|
|
|
EXPORT_SYMBOL(node_data);
|
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
nodemask_t numa_nodes_parsed __initdata;
|
2011-02-16 18:13:07 +07:00
|
|
|
|
2011-05-02 19:18:51 +07:00
|
|
|
static struct numa_meminfo numa_meminfo
|
|
|
|
#ifndef CONFIG_MEMORY_HOTPLUG
|
|
|
|
__initdata
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
static int numa_distance_cnt;
|
|
|
|
static u8 *numa_distance;
|
|
|
|
|
2011-02-16 23:11:10 +07:00
|
|
|
static int __init numa_add_memblk_to(int nid, u64 start, u64 end,
|
|
|
|
struct numa_meminfo *mi)
|
2011-02-16 23:11:07 +07:00
|
|
|
{
|
2011-02-16 23:11:09 +07:00
|
|
|
/* ignore zero length blks */
|
|
|
|
if (start == end)
|
|
|
|
return 0;
|
2011-02-16 23:11:08 +07:00
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
/* whine about and ignore invalid blks */
|
|
|
|
if (start > end || nid < 0 || nid >= MAX_NUMNODES) {
|
|
|
|
pr_warning("NUMA: Warning: invalid memblk node %d (%Lx-%Lx)\n",
|
|
|
|
nid, start, end);
|
|
|
|
return 0;
|
2011-02-16 23:11:07 +07:00
|
|
|
}
|
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
if (mi->nr_blks >= NR_NODE_MEMBLKS) {
|
|
|
|
pr_err("NUMA: too many memblk ranges\n");
|
2011-02-16 23:11:07 +07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2011-02-16 23:11:08 +07:00
|
|
|
mi->blk[mi->nr_blks].start = start;
|
|
|
|
mi->blk[mi->nr_blks].end = end;
|
|
|
|
mi->blk[mi->nr_blks].nid = nid;
|
|
|
|
mi->nr_blks++;
|
2011-02-16 23:11:07 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-22 17:10:08 +07:00
|
|
|
/**
|
|
|
|
* numa_remove_memblk_from - Remove one numa_memblk from a numa_meminfo
|
|
|
|
* @idx: Index of memblk to remove
|
|
|
|
* @mi: numa_meminfo to remove memblk from
|
|
|
|
*
|
|
|
|
* Remove @idx'th numa_memblk from @mi by shifting @mi->blk[] and
|
|
|
|
* decrementing @mi->nr_blks.
|
|
|
|
*/
|
2011-02-22 17:10:08 +07:00
|
|
|
void __init numa_remove_memblk_from(int idx, struct numa_meminfo *mi)
|
2011-02-16 23:11:09 +07:00
|
|
|
{
|
|
|
|
mi->nr_blks--;
|
|
|
|
memmove(&mi->blk[idx], &mi->blk[idx + 1],
|
|
|
|
(mi->nr_blks - idx) * sizeof(mi->blk[0]));
|
|
|
|
}
|
|
|
|
|
2011-02-22 17:10:08 +07:00
|
|
|
/**
|
|
|
|
* numa_add_memblk - Add one numa_memblk to numa_meminfo
|
|
|
|
* @nid: NUMA node ID of the new memblk
|
|
|
|
* @start: Start address of the new memblk
|
|
|
|
* @end: End address of the new memblk
|
|
|
|
*
|
|
|
|
* Add a new memblk to the default numa_meminfo.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* 0 on success, -errno on failure.
|
|
|
|
*/
|
2011-02-16 23:11:10 +07:00
|
|
|
int __init numa_add_memblk(int nid, u64 start, u64 end)
|
|
|
|
{
|
|
|
|
return numa_add_memblk_to(nid, start, end, &numa_meminfo);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* Initialize bootmem allocator for a node */
|
2009-05-16 03:59:37 +07:00
|
|
|
void __init
|
2011-05-02 19:18:51 +07:00
|
|
|
setup_node_bootmem(int nid, unsigned long start, unsigned long end)
|
2008-01-30 19:30:37 +07:00
|
|
|
{
|
2011-05-02 19:18:51 +07:00
|
|
|
const u64 nd_low = (u64)MAX_DMA_PFN << PAGE_SHIFT;
|
|
|
|
const u64 nd_high = (u64)max_pfn_mapped << PAGE_SHIFT;
|
2011-05-02 19:18:51 +07:00
|
|
|
const size_t nd_size = roundup(sizeof(pg_data_t), PAGE_SIZE);
|
|
|
|
unsigned long nd_pa;
|
|
|
|
int tnid;
|
2009-04-23 04:19:27 +07:00
|
|
|
|
2009-05-16 03:59:37 +07:00
|
|
|
/*
|
|
|
|
* Don't confuse VM with a node that doesn't have the
|
|
|
|
* minimum amount of memory:
|
|
|
|
*/
|
|
|
|
if (end && (end - start) < NODE_MIN_SIZE)
|
|
|
|
return;
|
|
|
|
|
2008-07-25 21:48:58 +07:00
|
|
|
start = roundup(start, ZONE_ALIGN);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-05-02 19:18:51 +07:00
|
|
|
printk(KERN_INFO "Initmem setup node %d %016lx-%016lx\n",
|
|
|
|
nid, start, end);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-05-02 19:18:51 +07:00
|
|
|
/*
|
|
|
|
* Try to allocate node data on local node and then fall back to
|
|
|
|
* all nodes. Never allocate in DMA zone.
|
|
|
|
*/
|
|
|
|
nd_pa = memblock_x86_find_in_range_node(nid, nd_low, nd_high,
|
|
|
|
nd_size, SMP_CACHE_BYTES);
|
|
|
|
if (nd_pa == MEMBLOCK_ERROR)
|
|
|
|
nd_pa = memblock_find_in_range(nd_low, nd_high,
|
|
|
|
nd_size, SMP_CACHE_BYTES);
|
|
|
|
if (nd_pa == MEMBLOCK_ERROR) {
|
|
|
|
pr_err("Cannot find %lu bytes in node %d\n", nd_size, nid);
|
2006-04-08 00:49:21 +07:00
|
|
|
return;
|
2011-05-02 19:18:51 +07:00
|
|
|
}
|
2011-05-02 19:18:51 +07:00
|
|
|
memblock_x86_reserve_range(nd_pa, nd_pa + nd_size, "NODE_DATA");
|
2011-05-02 19:18:51 +07:00
|
|
|
|
|
|
|
/* report and initialize */
|
2011-05-02 19:18:51 +07:00
|
|
|
printk(KERN_INFO " NODE_DATA [%016lx - %016lx]\n",
|
|
|
|
nd_pa, nd_pa + nd_size - 1);
|
|
|
|
tnid = early_pfn_to_nid(nd_pa >> PAGE_SHIFT);
|
|
|
|
if (tnid != nid)
|
|
|
|
printk(KERN_INFO " NODE_DATA(%d) on node %d\n", nid, tnid);
|
|
|
|
|
2011-05-02 19:18:51 +07:00
|
|
|
node_data[nid] = __va(nd_pa);
|
2011-05-02 19:18:51 +07:00
|
|
|
memset(NODE_DATA(nid), 0, sizeof(pg_data_t));
|
|
|
|
NODE_DATA(nid)->node_id = nid;
|
|
|
|
NODE_DATA(nid)->node_start_pfn = start >> PAGE_SHIFT;
|
|
|
|
NODE_DATA(nid)->node_spanned_pages = (end - start) >> PAGE_SHIFT;
|
|
|
|
|
|
|
|
node_set_online(nid);
|
2008-01-30 19:30:37 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-02-22 17:10:08 +07:00
|
|
|
/**
|
|
|
|
* numa_cleanup_meminfo - Cleanup a numa_meminfo
|
|
|
|
* @mi: numa_meminfo to clean up
|
|
|
|
*
|
|
|
|
* Sanitize @mi by merging and removing unncessary memblks. Also check for
|
|
|
|
* conflicts and clear unused memblks.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* 0 on success, -errno on failure.
|
|
|
|
*/
|
2011-02-22 17:10:08 +07:00
|
|
|
int __init numa_cleanup_meminfo(struct numa_meminfo *mi)
|
2011-02-16 23:11:08 +07:00
|
|
|
{
|
2011-02-16 23:11:09 +07:00
|
|
|
const u64 low = 0;
|
|
|
|
const u64 high = (u64)max_pfn << PAGE_SHIFT;
|
2011-02-16 23:11:09 +07:00
|
|
|
int i, j, k;
|
2011-02-16 23:11:07 +07:00
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
for (i = 0; i < mi->nr_blks; i++) {
|
2011-02-16 23:11:08 +07:00
|
|
|
struct numa_memblk *bi = &mi->blk[i];
|
2011-02-16 23:11:07 +07:00
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
/* make sure all blocks are inside the limits */
|
|
|
|
bi->start = max(bi->start, low);
|
|
|
|
bi->end = min(bi->end, high);
|
|
|
|
|
|
|
|
/* and there's no empty block */
|
2011-05-02 00:12:04 +07:00
|
|
|
if (bi->start >= bi->end) {
|
2011-02-16 23:11:09 +07:00
|
|
|
numa_remove_memblk_from(i--, mi);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
for (j = i + 1; j < mi->nr_blks; j++) {
|
2011-02-16 23:11:08 +07:00
|
|
|
struct numa_memblk *bj = &mi->blk[j];
|
2011-02-16 23:11:07 +07:00
|
|
|
unsigned long start, end;
|
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
/*
|
|
|
|
* See whether there are overlapping blocks. Whine
|
|
|
|
* about but allow overlaps of the same nid. They
|
|
|
|
* will be merged below.
|
|
|
|
*/
|
|
|
|
if (bi->end > bj->start && bi->start < bj->end) {
|
|
|
|
if (bi->nid != bj->nid) {
|
|
|
|
pr_err("NUMA: node %d (%Lx-%Lx) overlaps with node %d (%Lx-%Lx)\n",
|
|
|
|
bi->nid, bi->start, bi->end,
|
|
|
|
bj->nid, bj->start, bj->end);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
pr_warning("NUMA: Warning: node %d (%Lx-%Lx) overlaps with itself (%Lx-%Lx)\n",
|
|
|
|
bi->nid, bi->start, bi->end,
|
|
|
|
bj->start, bj->end);
|
|
|
|
}
|
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
/*
|
|
|
|
* Join together blocks on the same node, holes
|
|
|
|
* between which don't overlap with memory on other
|
|
|
|
* nodes.
|
|
|
|
*/
|
2011-02-16 23:11:08 +07:00
|
|
|
if (bi->nid != bj->nid)
|
2011-02-16 23:11:07 +07:00
|
|
|
continue;
|
2011-02-16 23:11:09 +07:00
|
|
|
start = max(min(bi->start, bj->start), low);
|
|
|
|
end = min(max(bi->end, bj->end), high);
|
2011-02-16 23:11:09 +07:00
|
|
|
for (k = 0; k < mi->nr_blks; k++) {
|
2011-02-16 23:11:08 +07:00
|
|
|
struct numa_memblk *bk = &mi->blk[k];
|
|
|
|
|
|
|
|
if (bi->nid == bk->nid)
|
2011-02-16 23:11:07 +07:00
|
|
|
continue;
|
2011-02-16 23:11:08 +07:00
|
|
|
if (start < bk->end && end > bk->start)
|
2011-02-16 23:11:07 +07:00
|
|
|
break;
|
|
|
|
}
|
2011-02-16 23:11:08 +07:00
|
|
|
if (k < mi->nr_blks)
|
2011-02-16 23:11:07 +07:00
|
|
|
continue;
|
|
|
|
printk(KERN_INFO "NUMA: Node %d [%Lx,%Lx) + [%Lx,%Lx) -> [%lx,%lx)\n",
|
2011-02-16 23:11:08 +07:00
|
|
|
bi->nid, bi->start, bi->end, bj->start, bj->end,
|
2011-02-16 23:11:07 +07:00
|
|
|
start, end);
|
2011-02-16 23:11:08 +07:00
|
|
|
bi->start = start;
|
|
|
|
bi->end = end;
|
2011-02-16 23:11:09 +07:00
|
|
|
numa_remove_memblk_from(j--, mi);
|
2011-02-16 23:11:07 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
for (i = mi->nr_blks; i < ARRAY_SIZE(mi->blk); i++) {
|
|
|
|
mi->blk[i].start = mi->blk[i].end = 0;
|
|
|
|
mi->blk[i].nid = NUMA_NO_NODE;
|
|
|
|
}
|
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
/*
|
|
|
|
* Set nodes, which have memory in @mi, in *@nodemask.
|
|
|
|
*/
|
|
|
|
static void __init numa_nodemask_from_meminfo(nodemask_t *nodemask,
|
|
|
|
const struct numa_meminfo *mi)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(mi->blk); i++)
|
|
|
|
if (mi->blk[i].start != mi->blk[i].end &&
|
|
|
|
mi->blk[i].nid != NUMA_NO_NODE)
|
|
|
|
node_set(mi->blk[i].nid, *nodemask);
|
|
|
|
}
|
|
|
|
|
2011-02-22 17:10:08 +07:00
|
|
|
/**
|
|
|
|
* numa_reset_distance - Reset NUMA distance table
|
|
|
|
*
|
|
|
|
* The current table is freed. The next numa_set_distance() call will
|
|
|
|
* create a new one.
|
2011-02-16 23:11:09 +07:00
|
|
|
*/
|
2011-02-22 17:10:08 +07:00
|
|
|
void __init numa_reset_distance(void)
|
2011-02-16 23:11:09 +07:00
|
|
|
{
|
2011-03-02 17:22:14 +07:00
|
|
|
size_t size = numa_distance_cnt * numa_distance_cnt * sizeof(numa_distance[0]);
|
2011-02-16 23:11:09 +07:00
|
|
|
|
2011-03-02 17:32:47 +07:00
|
|
|
/* numa_distance could be 1LU marking allocation failure, test cnt */
|
2011-03-02 17:22:14 +07:00
|
|
|
if (numa_distance_cnt)
|
2011-02-17 20:46:37 +07:00
|
|
|
memblock_x86_free_range(__pa(numa_distance),
|
|
|
|
__pa(numa_distance) + size);
|
2011-03-02 17:22:14 +07:00
|
|
|
numa_distance_cnt = 0;
|
2011-03-02 17:32:47 +07:00
|
|
|
numa_distance = NULL; /* enable table creation */
|
2011-02-16 23:11:09 +07:00
|
|
|
}
|
|
|
|
|
2011-02-22 17:18:49 +07:00
|
|
|
static int __init numa_alloc_distance(void)
|
|
|
|
{
|
|
|
|
nodemask_t nodes_parsed;
|
|
|
|
size_t size;
|
|
|
|
int i, j, cnt = 0;
|
|
|
|
u64 phys;
|
|
|
|
|
|
|
|
/* size the new table and allocate it */
|
|
|
|
nodes_parsed = numa_nodes_parsed;
|
|
|
|
numa_nodemask_from_meminfo(&nodes_parsed, &numa_meminfo);
|
|
|
|
|
|
|
|
for_each_node_mask(i, nodes_parsed)
|
|
|
|
cnt = i;
|
2011-02-25 16:06:39 +07:00
|
|
|
cnt++;
|
|
|
|
size = cnt * cnt * sizeof(numa_distance[0]);
|
2011-02-22 17:18:49 +07:00
|
|
|
|
|
|
|
phys = memblock_find_in_range(0, (u64)max_pfn_mapped << PAGE_SHIFT,
|
|
|
|
size, PAGE_SIZE);
|
|
|
|
if (phys == MEMBLOCK_ERROR) {
|
|
|
|
pr_warning("NUMA: Warning: can't allocate distance table!\n");
|
|
|
|
/* don't retry until explicitly reset */
|
|
|
|
numa_distance = (void *)1LU;
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
memblock_x86_reserve_range(phys, phys + size, "NUMA DIST");
|
|
|
|
|
|
|
|
numa_distance = __va(phys);
|
|
|
|
numa_distance_cnt = cnt;
|
|
|
|
|
|
|
|
/* fill with the default distances */
|
|
|
|
for (i = 0; i < cnt; i++)
|
|
|
|
for (j = 0; j < cnt; j++)
|
|
|
|
numa_distance[i * cnt + j] = i == j ?
|
|
|
|
LOCAL_DISTANCE : REMOTE_DISTANCE;
|
|
|
|
printk(KERN_DEBUG "NUMA: Initialized distance table, cnt=%d\n", cnt);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-22 17:10:08 +07:00
|
|
|
/**
|
|
|
|
* numa_set_distance - Set NUMA distance from one NUMA to another
|
|
|
|
* @from: the 'from' node to set distance
|
|
|
|
* @to: the 'to' node to set distance
|
|
|
|
* @distance: NUMA distance
|
|
|
|
*
|
|
|
|
* Set the distance from node @from to @to to @distance. If distance table
|
2011-03-18 02:24:16 +07:00
|
|
|
* doesn't exist, one which is large enough to accommodate all the currently
|
2011-02-22 17:10:08 +07:00
|
|
|
* known nodes will be created.
|
2011-03-02 17:32:47 +07:00
|
|
|
*
|
|
|
|
* If such table cannot be allocated, a warning is printed and further
|
|
|
|
* calls are ignored until the distance table is reset with
|
|
|
|
* numa_reset_distance().
|
|
|
|
*
|
|
|
|
* If @from or @to is higher than the highest known node at the time of
|
|
|
|
* table creation or @distance doesn't make sense, the call is ignored.
|
|
|
|
* This is to allow simplification of specific NUMA config implementations.
|
2011-02-16 23:11:09 +07:00
|
|
|
*/
|
|
|
|
void __init numa_set_distance(int from, int to, int distance)
|
|
|
|
{
|
2011-02-22 17:18:49 +07:00
|
|
|
if (!numa_distance && numa_alloc_distance() < 0)
|
|
|
|
return;
|
2011-02-16 23:11:09 +07:00
|
|
|
|
|
|
|
if (from >= numa_distance_cnt || to >= numa_distance_cnt) {
|
|
|
|
printk_once(KERN_DEBUG "NUMA: Debug: distance out of bound, from=%d to=%d distance=%d\n",
|
|
|
|
from, to, distance);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((u8)distance != distance ||
|
|
|
|
(from == to && distance != LOCAL_DISTANCE)) {
|
|
|
|
pr_warn_once("NUMA: Warning: invalid distance parameter, from=%d to=%d distance=%d\n",
|
|
|
|
from, to, distance);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
numa_distance[from * numa_distance_cnt + to] = distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __node_distance(int from, int to)
|
|
|
|
{
|
|
|
|
if (from >= numa_distance_cnt || to >= numa_distance_cnt)
|
|
|
|
return from == to ? LOCAL_DISTANCE : REMOTE_DISTANCE;
|
|
|
|
return numa_distance[from * numa_distance_cnt + to];
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__node_distance);
|
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
/*
|
|
|
|
* Sanity check to catch more bad NUMA configurations (they are amazingly
|
|
|
|
* common). Make sure the nodes cover all memory.
|
|
|
|
*/
|
2011-02-16 23:11:09 +07:00
|
|
|
static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
|
2011-02-16 23:11:09 +07:00
|
|
|
{
|
|
|
|
unsigned long numaram, e820ram;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
numaram = 0;
|
2011-02-16 23:11:09 +07:00
|
|
|
for (i = 0; i < mi->nr_blks; i++) {
|
|
|
|
unsigned long s = mi->blk[i].start >> PAGE_SHIFT;
|
|
|
|
unsigned long e = mi->blk[i].end >> PAGE_SHIFT;
|
2011-02-16 23:11:09 +07:00
|
|
|
numaram += e - s;
|
2011-02-16 23:11:09 +07:00
|
|
|
numaram -= __absent_pages_in_range(mi->blk[i].nid, s, e);
|
2011-02-16 23:11:09 +07:00
|
|
|
if ((long)numaram < 0)
|
|
|
|
numaram = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
e820ram = max_pfn - (memblock_x86_hole_size(0,
|
|
|
|
max_pfn << PAGE_SHIFT) >> PAGE_SHIFT);
|
|
|
|
/* We seem to lose 3 pages somewhere. Allow 1M of slack. */
|
|
|
|
if ((long)(e820ram - numaram) >= (1 << (20 - PAGE_SHIFT))) {
|
|
|
|
printk(KERN_ERR "NUMA: nodes only cover %luMB of your %luMB e820 RAM. Not used.\n",
|
|
|
|
(numaram << PAGE_SHIFT) >> 20,
|
|
|
|
(e820ram << PAGE_SHIFT) >> 20);
|
2011-02-16 23:11:09 +07:00
|
|
|
return false;
|
2011-02-16 23:11:09 +07:00
|
|
|
}
|
2011-02-16 23:11:09 +07:00
|
|
|
return true;
|
2011-02-16 23:11:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init numa_register_memblks(struct numa_meminfo *mi)
|
|
|
|
{
|
2011-02-21 16:58:13 +07:00
|
|
|
int i, nid;
|
2011-02-16 23:11:09 +07:00
|
|
|
|
|
|
|
/* Account for nodes with cpus and no memory */
|
2011-02-16 23:11:09 +07:00
|
|
|
node_possible_map = numa_nodes_parsed;
|
|
|
|
numa_nodemask_from_meminfo(&node_possible_map, mi);
|
2011-02-16 23:11:09 +07:00
|
|
|
if (WARN_ON(nodes_empty(node_possible_map)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-02-16 23:11:08 +07:00
|
|
|
for (i = 0; i < mi->nr_blks; i++)
|
|
|
|
memblock_x86_register_active_regions(mi->blk[i].nid,
|
|
|
|
mi->blk[i].start >> PAGE_SHIFT,
|
|
|
|
mi->blk[i].end >> PAGE_SHIFT);
|
2011-02-16 23:11:08 +07:00
|
|
|
|
|
|
|
/* for out of order entries */
|
|
|
|
sort_node_map();
|
2011-02-16 23:11:09 +07:00
|
|
|
if (!numa_meminfo_cover_memory(mi))
|
2011-02-16 23:11:08 +07:00
|
|
|
return -EINVAL;
|
|
|
|
|
2011-02-21 16:58:13 +07:00
|
|
|
/* Finally register nodes. */
|
|
|
|
for_each_node_mask(nid, node_possible_map) {
|
|
|
|
u64 start = (u64)max_pfn << PAGE_SHIFT;
|
|
|
|
u64 end = 0;
|
2011-02-16 23:11:09 +07:00
|
|
|
|
2011-02-21 16:58:13 +07:00
|
|
|
for (i = 0; i < mi->nr_blks; i++) {
|
|
|
|
if (nid != mi->blk[i].nid)
|
2011-02-16 23:11:09 +07:00
|
|
|
continue;
|
2011-02-21 16:58:13 +07:00
|
|
|
start = min(mi->blk[i].start, start);
|
|
|
|
end = max(mi->blk[i].end, end);
|
2011-02-16 23:11:09 +07:00
|
|
|
}
|
2011-02-21 16:58:13 +07:00
|
|
|
|
|
|
|
if (start < end)
|
|
|
|
setup_node_bootmem(nid, start, end);
|
2011-02-16 23:11:09 +07:00
|
|
|
}
|
2011-02-16 23:11:08 +07:00
|
|
|
|
2011-02-16 23:11:07 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-04 21:17:21 +07:00
|
|
|
/**
|
|
|
|
* dummy_numma_init - Fallback dummy NUMA init
|
|
|
|
*
|
|
|
|
* Used if there's no underlying NUMA architecture, NUMA initialization
|
|
|
|
* fails, or NUMA is disabled on the command line.
|
|
|
|
*
|
|
|
|
* Must online at least one node and add memory blocks that cover all
|
|
|
|
* allowed memory. This function must not fail.
|
|
|
|
*/
|
2011-02-17 20:53:20 +07:00
|
|
|
static int __init dummy_numa_init(void)
|
2011-02-16 18:13:06 +07:00
|
|
|
{
|
2005-04-17 05:20:36 +07:00
|
|
|
printk(KERN_INFO "%s\n",
|
|
|
|
numa_off ? "NUMA turned off" : "No NUMA configuration found");
|
2008-01-30 19:30:37 +07:00
|
|
|
printk(KERN_INFO "Faking a node at %016lx-%016lx\n",
|
2011-02-16 18:13:06 +07:00
|
|
|
0LU, max_pfn << PAGE_SHIFT);
|
2011-02-16 18:13:06 +07:00
|
|
|
|
2011-02-16 23:11:09 +07:00
|
|
|
node_set(0, numa_nodes_parsed);
|
2011-02-16 23:11:08 +07:00
|
|
|
numa_add_memblk(0, 0, (u64)max_pfn << PAGE_SHIFT);
|
2011-02-16 18:13:07 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-04 21:17:21 +07:00
|
|
|
static int __init numa_init(int (*init_func)(void))
|
2011-02-16 18:13:06 +07:00
|
|
|
{
|
2011-03-04 21:17:21 +07:00
|
|
|
int i;
|
|
|
|
int ret;
|
2011-02-16 18:13:06 +07:00
|
|
|
|
2011-03-04 21:17:21 +07:00
|
|
|
for (i = 0; i < MAX_LOCAL_APIC; i++)
|
|
|
|
set_apicid_to_node(i, NUMA_NO_NODE);
|
2011-02-16 18:13:06 +07:00
|
|
|
|
2011-03-04 21:17:21 +07:00
|
|
|
nodes_clear(numa_nodes_parsed);
|
|
|
|
nodes_clear(node_possible_map);
|
|
|
|
nodes_clear(node_online_map);
|
|
|
|
memset(&numa_meminfo, 0, sizeof(numa_meminfo));
|
|
|
|
remove_all_active_ranges();
|
|
|
|
numa_reset_distance();
|
2011-02-16 18:13:06 +07:00
|
|
|
|
2011-03-04 21:17:21 +07:00
|
|
|
ret = init_func();
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
ret = numa_cleanup_meminfo(&numa_meminfo);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2011-02-16 18:13:06 +07:00
|
|
|
|
2011-03-04 21:17:21 +07:00
|
|
|
numa_emulation(&numa_meminfo, numa_distance_cnt);
|
2011-02-16 18:13:07 +07:00
|
|
|
|
2011-03-04 21:17:21 +07:00
|
|
|
ret = numa_register_memblks(&numa_meminfo);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2011-02-22 17:10:08 +07:00
|
|
|
|
2011-03-04 21:17:21 +07:00
|
|
|
for (i = 0; i < nr_cpu_ids; i++) {
|
|
|
|
int nid = early_cpu_to_node(i);
|
2011-02-22 17:10:08 +07:00
|
|
|
|
2011-03-04 21:17:21 +07:00
|
|
|
if (nid == NUMA_NO_NODE)
|
2011-02-16 23:11:08 +07:00
|
|
|
continue;
|
2011-03-04 21:17:21 +07:00
|
|
|
if (!node_online(nid))
|
|
|
|
numa_clear_node(i);
|
|
|
|
}
|
|
|
|
numa_init_array();
|
|
|
|
return 0;
|
|
|
|
}
|
2011-02-16 23:11:08 +07:00
|
|
|
|
2011-03-04 21:17:21 +07:00
|
|
|
void __init initmem_init(void)
|
|
|
|
{
|
|
|
|
if (!numa_off) {
|
|
|
|
#ifdef CONFIG_ACPI_NUMA
|
2011-04-04 06:17:40 +07:00
|
|
|
if (!numa_init(x86_acpi_numa_init))
|
2011-03-04 21:17:21 +07:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_AMD_NUMA
|
2011-04-04 06:17:40 +07:00
|
|
|
if (!numa_init(amd_numa_init))
|
2011-03-04 21:17:21 +07:00
|
|
|
return;
|
|
|
|
#endif
|
2011-02-16 18:13:06 +07:00
|
|
|
}
|
2011-03-04 21:17:21 +07:00
|
|
|
|
|
|
|
numa_init(dummy_numa_init);
|
2005-11-05 23:25:53 +07:00
|
|
|
}
|
|
|
|
|
2008-01-30 19:30:37 +07:00
|
|
|
unsigned long __init numa_free_all_bootmem(void)
|
|
|
|
{
|
2005-04-17 05:20:36 +07:00
|
|
|
unsigned long pages = 0;
|
2008-01-30 19:30:37 +07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for_each_online_node(i)
|
2005-04-17 05:20:36 +07:00
|
|
|
pages += free_all_bootmem_node(NODE_DATA(i));
|
2008-01-30 19:30:37 +07:00
|
|
|
|
2010-02-10 16:20:20 +07:00
|
|
|
pages += free_all_memory_core_early(MAX_NUMNODES);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
return pages;
|
2008-01-30 19:30:37 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-05-02 19:18:51 +07:00
|
|
|
#ifdef CONFIG_MEMORY_HOTPLUG
|
|
|
|
int memory_add_physaddr_to_nid(u64 start)
|
|
|
|
{
|
|
|
|
struct numa_meminfo *mi = &numa_meminfo;
|
|
|
|
int nid = mi->blk[0].nid;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < mi->nr_blks; i++)
|
|
|
|
if (mi->blk[i].start <= start && mi->blk[i].end > start)
|
|
|
|
nid = mi->blk[i].nid;
|
|
|
|
return nid;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
|
|
|
|
#endif
|