numaperf.rst 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. =======================
  2. NUMA Memory Performance
  3. =======================
  4. NUMA Locality
  5. =============
  6. Some platforms may have multiple types of memory attached to a compute
  7. node. These disparate memory ranges may share some characteristics, such
  8. as CPU cache coherence, but may have different performance. For example,
  9. different media types and buses affect bandwidth and latency.
  10. A system supports such heterogeneous memory by grouping each memory type
  11. under different domains, or "nodes", based on locality and performance
  12. characteristics. Some memory may share the same node as a CPU, and others
  13. are provided as memory only nodes. While memory only nodes do not provide
  14. CPUs, they may still be local to one or more compute nodes relative to
  15. other nodes. The following diagram shows one such example of two compute
  16. nodes with local memory and a memory only node for each of compute node::
  17. +------------------+ +------------------+
  18. | Compute Node 0 +-----+ Compute Node 1 |
  19. | Local Node0 Mem | | Local Node1 Mem |
  20. +--------+---------+ +--------+---------+
  21. | |
  22. +--------+---------+ +--------+---------+
  23. | Slower Node2 Mem | | Slower Node3 Mem |
  24. +------------------+ +--------+---------+
  25. A "memory initiator" is a node containing one or more devices such as
  26. CPUs or separate memory I/O devices that can initiate memory requests.
  27. A "memory target" is a node containing one or more physical address
  28. ranges accessible from one or more memory initiators.
  29. When multiple memory initiators exist, they may not all have the same
  30. performance when accessing a given memory target. Each initiator-target
  31. pair may be organized into different ranked access classes to represent
  32. this relationship. The highest performing initiator to a given target
  33. is considered to be one of that target's local initiators, and given
  34. the highest access class, 0. Any given target may have one or more
  35. local initiators, and any given initiator may have multiple local
  36. memory targets.
  37. To aid applications matching memory targets with their initiators, the
  38. kernel provides symlinks to each other. The following example lists the
  39. relationship for the access class "0" memory initiators and targets::
  40. # symlinks -v /sys/devices/system/node/nodeX/access0/targets/
  41. relative: /sys/devices/system/node/nodeX/access0/targets/nodeY -> ../../nodeY
  42. # symlinks -v /sys/devices/system/node/nodeY/access0/initiators/
  43. relative: /sys/devices/system/node/nodeY/access0/initiators/nodeX -> ../../nodeX
  44. A memory initiator may have multiple memory targets in the same access
  45. class. The target memory's initiators in a given class indicate the
  46. nodes' access characteristics share the same performance relative to other
  47. linked initiator nodes. Each target within an initiator's access class,
  48. though, do not necessarily perform the same as each other.
  49. The access class "1" is used to allow differentiation between initiators
  50. that are CPUs and hence suitable for generic task scheduling, and
  51. IO initiators such as GPUs and NICs. Unlike access class 0, only
  52. nodes containing CPUs are considered.
  53. NUMA Performance
  54. ================
  55. Applications may wish to consider which node they want their memory to
  56. be allocated from based on the node's performance characteristics. If
  57. the system provides these attributes, the kernel exports them under the
  58. node sysfs hierarchy by appending the attributes directory under the
  59. memory node's access class 0 initiators as follows::
  60. /sys/devices/system/node/nodeY/access0/initiators/
  61. These attributes apply only when accessed from nodes that have the
  62. are linked under the this access's initiators.
  63. The performance characteristics the kernel provides for the local initiators
  64. are exported are as follows::
  65. # tree -P "read*|write*" /sys/devices/system/node/nodeY/access0/initiators/
  66. /sys/devices/system/node/nodeY/access0/initiators/
  67. |-- read_bandwidth
  68. |-- read_latency
  69. |-- write_bandwidth
  70. `-- write_latency
  71. The bandwidth attributes are provided in MiB/second.
  72. The latency attributes are provided in nanoseconds.
  73. The values reported here correspond to the rated latency and bandwidth
  74. for the platform.
  75. Access class 1 takes the same form but only includes values for CPU to
  76. memory activity.
  77. NUMA Cache
  78. ==========
  79. System memory may be constructed in a hierarchy of elements with various
  80. performance characteristics in order to provide large address space of
  81. slower performing memory cached by a smaller higher performing memory. The
  82. system physical addresses memory initiators are aware of are provided
  83. by the last memory level in the hierarchy. The system meanwhile uses
  84. higher performing memory to transparently cache access to progressively
  85. slower levels.
  86. The term "far memory" is used to denote the last level memory in the
  87. hierarchy. Each increasing cache level provides higher performing
  88. initiator access, and the term "near memory" represents the fastest
  89. cache provided by the system.
  90. This numbering is different than CPU caches where the cache level (ex:
  91. L1, L2, L3) uses the CPU-side view where each increased level is lower
  92. performing. In contrast, the memory cache level is centric to the last
  93. level memory, so the higher numbered cache level corresponds to memory
  94. nearer to the CPU, and further from far memory.
  95. The memory-side caches are not directly addressable by software. When
  96. software accesses a system address, the system will return it from the
  97. near memory cache if it is present. If it is not present, the system
  98. accesses the next level of memory until there is either a hit in that
  99. cache level, or it reaches far memory.
  100. An application does not need to know about caching attributes in order
  101. to use the system. Software may optionally query the memory cache
  102. attributes in order to maximize the performance out of such a setup.
  103. If the system provides a way for the kernel to discover this information,
  104. for example with ACPI HMAT (Heterogeneous Memory Attribute Table),
  105. the kernel will append these attributes to the NUMA node memory target.
  106. When the kernel first registers a memory cache with a node, the kernel
  107. will create the following directory::
  108. /sys/devices/system/node/nodeX/memory_side_cache/
  109. If that directory is not present, the system either does not provide
  110. a memory-side cache, or that information is not accessible to the kernel.
  111. The attributes for each level of cache is provided under its cache
  112. level index::
  113. /sys/devices/system/node/nodeX/memory_side_cache/indexA/
  114. /sys/devices/system/node/nodeX/memory_side_cache/indexB/
  115. /sys/devices/system/node/nodeX/memory_side_cache/indexC/
  116. Each cache level's directory provides its attributes. For example, the
  117. following shows a single cache level and the attributes available for
  118. software to query::
  119. # tree /sys/devices/system/node/node0/memory_side_cache/
  120. /sys/devices/system/node/node0/memory_side_cache/
  121. |-- index1
  122. | |-- indexing
  123. | |-- line_size
  124. | |-- size
  125. | `-- write_policy
  126. The "indexing" will be 0 if it is a direct-mapped cache, and non-zero
  127. for any other indexed based, multi-way associativity.
  128. The "line_size" is the number of bytes accessed from the next cache
  129. level on a miss.
  130. The "size" is the number of bytes provided by this cache level.
  131. The "write_policy" will be 0 for write-back, and non-zero for
  132. write-through caching.
  133. See Also
  134. ========
  135. [1] https://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf
  136. - Section 5.2.27