Skip to contentSkip to conversation

x86: Reduce MAX_LOCAL_APIC and MAX_IO_APICS

RFC PATCH Daniel J Blueman 1 participant 1 message Oct 2, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw
Quoted 7 lines · Denys Vlasenko

Before this change MAX_LOCAL_APIC had the fixed value of 32*1024. Such a big value causes several data arrays to be quite oversized:

phys_cpu_present_map is 4 kbytes (one bit per apic id), __apicid_to_node[] is 64 kbytes, apic_version[] is 128 kbytes.

Quoted 5 lines

On "usual" systems, APIC ids simply go from zero
to maximum logical CPU number, mirroring CPU ids.

On broken and unusual multi-socket systems
APIC ids can be non-contiguous.

The Intel x2APIC spec states the upper 16-bits of APIC ID is the cluster ID [1, p2-12], intended for future distributed systems. Beyond the legacy 8-bit APIC ID, Numascale NumaConnect uses 4-bits for the position of a server on each axis of a multi-dimension torus; SGI NUMAlink also structures the APIC ID space.

Instead, define an array based on NR_CPUs to achieve a 1:1 mapping and perform linear search; this addresses the binary bloat and the present artificial APIC ID limits. With CONFIG_NR_CPUS=256:

$ size vmlinux vmlinux-patched
 text    data     bss     dec     hex filename
18232877        1849656 2281472 22364005        1553f65 vmlinux
18233034        1786168 2281472 22300674        1544802 vmlinux-patched

Works peachy on a 256-core system with a 20-bit APIC ID space, and on a 48-core legacy 8-bit APIC ID system. If we care, I can make numa_cpu_node O(1) lookup for typical cases.

Daniel

[1] http://www.intel.com/content/dam/doc/specification-update/64-architecture-x2apic-specification.pdf

---

arch/x86/include/asm/numa.h | 13 +++++++------
arch/x86/kernel/cpu/amd.c   |  8 ++++----
arch/x86/mm/numa.c          | 31 +++++++++++++++++++++++--------
3 files changed, 34 insertions(+), 18 deletions(-)
arch/x86/include/asm/numa.h +0 -0
index 01b493e..33becb8 100644
@@ -17,6 +17,11 @@

*/
#define NODE_MIN_SIZE (4*1024*1024)

+struct apicid_to_node {
+ int apicid;
+ s16 node;
+};
+
extern int numa_off;

/*
@@ -27,17 +32,13 @@ extern int numa_off;
* should be accessed by the accessors - set_apicid_to_node() and
* numa_cpu_node().
*/
-extern s16 __apicid_to_node[MAX_LOCAL_APIC];
+extern struct apicid_to_node __apicid_to_node[NR_CPUS]; extern nodemask_t numa_nodes_parsed __initdata;

extern int __init numa_add_memblk(int nodeid, u64 start, u64 end); extern void __init numa_set_distance(int from, int to, int distance);

-static inline void set_apicid_to_node(int apicid, s16 node) -{
- __apicid_to_node[apicid] = node;
-}
-
+extern void set_apicid_to_node(int apicid, s16 node); extern int numa_cpu_node(int cpu);

#else /* CONFIG_NUMA */

arch/x86/kernel/cpu/amd.c +4 -4
index 4a70fc6..e65c01c 100644
@@ -277,12 +277,12 @@ static int nearby_node(int apicid)
      int i, node;
 
      for (i = apicid - 1; i >= 0; i--) {
-               node = __apicid_to_node[i];
+               node = __apicid_to_node[i].node;
              if (node != NUMA_NO_NODE && node_online(node))
                      return node;
      }
      for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
-               node = __apicid_to_node[i];
+               node = __apicid_to_node[i].node;
              if (node != NUMA_NO_NODE && node_online(node))
                      return node;
      }
@@ -422,8 +422,8 @@ static void srat_detect_node(struct cpuinfo_x86 *c)
              int ht_nodeid = c->initial_apicid;
 
              if (ht_nodeid >= 0 &&
-                   __apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
-                       node = __apicid_to_node[ht_nodeid];
+                   __apicid_to_node[ht_nodeid].node != NUMA_NO_NODE)
+                       node = __apicid_to_node[ht_nodeid].node;
              /* Pick a nearby node */
              if (!node_online(node))
                      node = nearby_node(apicid);
arch/x86/mm/numa.c +0 -0
index c3b3f65..70f03a0 100644
@@ -56,16 +56,34 @@ early_param("numa", numa_setup);

/*
* apicid, cpu, node mappings
*/
-s16 __apicid_to_node[MAX_LOCAL_APIC] = {
- [0 ... MAX_LOCAL_APIC-1] = NUMA_NO_NODE
+
+struct apicid_to_node __apicid_to_node[NR_CPUS] = {
+ [0 ... NR_CPUS-1] = {-1, NUMA_NO_NODE}
};

+void set_apicid_to_node(int apicid, s16 node)
+{
+ static int ent;
+
+ /* Protect against small kernel on large system */
+ if (ent >= NR_CPUS)
+ return;
+

+       __apicid_to_node[ent].apicid = apicid;
+       __apicid_to_node[ent].node = node;
+       ent++;

+}
+
int numa_cpu_node(int cpu)
{

-       int apicid = early_per_cpu(x86_cpu_to_apicid, cpu);
+       int ent, apicid = early_per_cpu(x86_cpu_to_apicid, cpu);
+       if (apicid == BAD_APICID)

+ return NUMA_NO_NODE;
+
+ for (ent = 0; ent < NR_CPUS; ent++)
+ if (__apicid_to_node[ent].apicid == apicid)
+ return __apicid_to_node[ent].node;

- if (apicid != BAD_APICID)

-               return __apicid_to_node[apicid];
      return NUMA_NO_NODE;
}

@@ -607,9 +625,6 @@ static int __init numa_init(int (*init_func)(void))

      int i;
      int ret;

- for (i = 0; i < MAX_LOCAL_APIC; i++)
- set_apicid_to_node(i, NUMA_NO_NODE);
-

      nodes_clear(numa_nodes_parsed);
      nodes_clear(node_possible_map);
      nodes_clear(node_online_map);