brintos

brintos / linux-shallow public Read only

0
0
Text · 8.6 KiB · 0f1b568 Raw
149 lines · plain
1Started Nov 1999 by Kanoj Sarcar <kanoj@sgi.com>2 3=============4What is NUMA?5=============6 7This question can be answered from a couple of perspectives:  the8hardware view and the Linux software view.9 10From the hardware perspective, a NUMA system is a computer platform that11comprises multiple components or assemblies each of which may contain 012or more CPUs, local memory, and/or IO buses.  For brevity and to13disambiguate the hardware view of these physical components/assemblies14from the software abstraction thereof, we'll call the components/assemblies15'cells' in this document.16 17Each of the 'cells' may be viewed as an SMP [symmetric multi-processor] subset18of the system--although some components necessary for a stand-alone SMP system19may not be populated on any given cell.   The cells of the NUMA system are20connected together with some sort of system interconnect--e.g., a crossbar or21point-to-point link are common types of NUMA system interconnects.  Both of22these types of interconnects can be aggregated to create NUMA platforms with23cells at multiple distances from other cells.24 25For Linux, the NUMA platforms of interest are primarily what is known as Cache26Coherent NUMA or ccNUMA systems.   With ccNUMA systems, all memory is visible27to and accessible from any CPU attached to any cell and cache coherency28is handled in hardware by the processor caches and/or the system interconnect.29 30Memory access time and effective memory bandwidth varies depending on how far31away the cell containing the CPU or IO bus making the memory access is from the32cell containing the target memory.  For example, access to memory by CPUs33attached to the same cell will experience faster access times and higher34bandwidths than accesses to memory on other, remote cells.  NUMA platforms35can have cells at multiple remote distances from any given cell.36 37Platform vendors don't build NUMA systems just to make software developers'38lives interesting.  Rather, this architecture is a means to provide scalable39memory bandwidth.  However, to achieve scalable memory bandwidth, system and40application software must arrange for a large majority of the memory references41[cache misses] to be to "local" memory--memory on the same cell, if any--or42to the closest cell with memory.43 44This leads to the Linux software view of a NUMA system:45 46Linux divides the system's hardware resources into multiple software47abstractions called "nodes".  Linux maps the nodes onto the physical cells48of the hardware platform, abstracting away some of the details for some49architectures.  As with physical cells, software nodes may contain 0 or more50CPUs, memory and/or IO buses.  And, again, memory accesses to memory on51"closer" nodes--nodes that map to closer cells--will generally experience52faster access times and higher effective bandwidth than accesses to more53remote cells.54 55For some architectures, such as x86, Linux will "hide" any node representing a56physical cell that has no memory attached, and reassign any CPUs attached to57that cell to a node representing a cell that does have memory.  Thus, on58these architectures, one cannot assume that all CPUs that Linux associates with59a given node will see the same local memory access times and bandwidth.60 61In addition, for some architectures, again x86 is an example, Linux supports62the emulation of additional nodes.  For NUMA emulation, linux will carve up63the existing nodes--or the system memory for non-NUMA platforms--into multiple64nodes.  Each emulated node will manage a fraction of the underlying cells'65physical memory.  NUMA emulation is useful for testing NUMA kernel and66application features on non-NUMA platforms, and as a sort of memory resource67management mechanism when used together with cpusets.68[see Documentation/admin-guide/cgroup-v1/cpusets.rst]69 70For each node with memory, Linux constructs an independent memory management71subsystem, complete with its own free page lists, in-use page lists, usage72statistics and locks to mediate access.  In addition, Linux constructs for73each memory zone [one or more of DMA, DMA32, NORMAL, HIGH_MEMORY, MOVABLE],74an ordered "zonelist".  A zonelist specifies the zones/nodes to visit when a75selected zone/node cannot satisfy the allocation request.  This situation,76when a zone has no available memory to satisfy a request, is called77"overflow" or "fallback".78 79Because some nodes contain multiple zones containing different types of80memory, Linux must decide whether to order the zonelists such that allocations81fall back to the same zone type on a different node, or to a different zone82type on the same node.  This is an important consideration because some zones,83such as DMA or DMA32, represent relatively scarce resources.  Linux chooses84a default Node ordered zonelist. This means it tries to fallback to other zones85from the same node before using remote nodes which are ordered by NUMA distance.86 87By default, Linux will attempt to satisfy memory allocation requests from the88node to which the CPU that executes the request is assigned.  Specifically,89Linux will attempt to allocate from the first node in the appropriate zonelist90for the node where the request originates.  This is called "local allocation."91If the "local" node cannot satisfy the request, the kernel will examine other92nodes' zones in the selected zonelist looking for the first zone in the list93that can satisfy the request.94 95Local allocation will tend to keep subsequent access to the allocated memory96"local" to the underlying physical resources and off the system interconnect--97as long as the task on whose behalf the kernel allocated some memory does not98later migrate away from that memory.  The Linux scheduler is aware of the99NUMA topology of the platform--embodied in the "scheduling domains" data100structures [see Documentation/scheduler/sched-domains.rst]--and the scheduler101attempts to minimize task migration to distant scheduling domains.  However,102the scheduler does not take a task's NUMA footprint into account directly.103Thus, under sufficient imbalance, tasks can migrate between nodes, remote104from their initial node and kernel data structures.105 106System administrators and application designers can restrict a task's migration107to improve NUMA locality using various CPU affinity command line interfaces,108such as taskset(1) and numactl(1), and program interfaces such as109sched_setaffinity(2).  Further, one can modify the kernel's default local110allocation behavior using Linux NUMA memory policy. [see111Documentation/admin-guide/mm/numa_memory_policy.rst].112 113System administrators can restrict the CPUs and nodes' memories that a non-114privileged user can specify in the scheduling or NUMA commands and functions115using control groups and CPUsets.  [see Documentation/admin-guide/cgroup-v1/cpusets.rst]116 117On architectures that do not hide memoryless nodes, Linux will include only118zones [nodes] with memory in the zonelists.  This means that for a memoryless119node the "local memory node"--the node of the first zone in CPU's node's120zonelist--will not be the node itself.  Rather, it will be the node that the121kernel selected as the nearest node with memory when it built the zonelists.122So, default, local allocations will succeed with the kernel supplying the123closest available memory.  This is a consequence of the same mechanism that124allows such allocations to fallback to other nearby nodes when a node that125does contain memory overflows.126 127Some kernel allocations do not want or cannot tolerate this allocation fallback128behavior.  Rather they want to be sure they get memory from the specified node129or get notified that the node has no free memory.  This is usually the case when130a subsystem allocates per CPU memory resources, for example.131 132A typical model for making such an allocation is to obtain the node id of the133node to which the "current CPU" is attached using one of the kernel's134numa_node_id() or CPU_to_node() functions and then request memory from only135the node id returned.  When such an allocation fails, the requesting subsystem136may revert to its own fallback path.  The slab kernel memory allocator is an137example of this.  Or, the subsystem may choose to disable or not to enable138itself on allocation failure.  The kernel profiling subsystem is an example of139this.140 141If the architecture supports--does not hide--memoryless nodes, then CPUs142attached to memoryless nodes would always incur the fallback path overhead143or some subsystems would fail to initialize if they attempted to allocated144memory exclusively from a node without memory.  To support such145architectures transparently, kernel subsystems can use the numa_mem_id()146or cpu_to_mem() function to locate the "local memory node" for the calling or147specified CPU.  Again, this is the same node from which default, local page148allocations will be attempted.149