我有一台操作系统为 22.04 的 Ubuntu 服务器。我遇到了 NUMA 亲和性绑定问题。
1.)服务器相应地有两个NUMA节点。
server-1:# numactl -H
available: 2 nodes (0-1)
node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
node 0 size: 1031782 MB
node 0 free: 989481 MB
node 1 cpus: 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
node 1 size: 1021920 MB
node 1 free: 1018313 MB
node distances:
node 0 1
0: 10 21
1: 21 10
2.) 当我为属于 numa node0 的 cpu 0 的新进程设置 CPU 亲和性时,它跨越了两个 numa 节点之间的多个 cpu。
server-1:# taskset -c 0 cat /dev/random >& /dev/null &
[1] 2685342
server-1:# taskset -cp 2685342
pid 2685342's current affinity list: 0,1,30,48-51,96,97,144-147
我认为它应该坚持使用 cpu 0 而不是多 cpu。你能告诉我这是怎么发生的吗?
编辑:
server-1:# strace -e sched_setaffinity -fyy taskset -p 0 2947449
pid 2947449's current affinity mask: f00000000000300000000000f000040000003
sched_setaffinity(2947449, 24, []) = -1 EINVAL (Invalid argument)
taskset: failed to set pid 2947449's affinity: Invalid argument
+++ exited with 1 +++
server-1:# grep Cpus_allowed_list /proc/2947449/status
Cpus_allowed_list: 0-1,30,48-51,96-97,144-147
編輯-2:
-- Initiated process on cpu 1.
server-1:# taskset -c 1 cat /dev/random >& /dev/null &
[1] 691247
-- Queried taskset shows remains same. Why this values are constant.
server-1:# taskset -cp 691247
pid 691247's current affinity list: 0,1,30,48-51,96,97,144-147
-- changed task over cpu 5 using strace and it was successful.
server-1:# strace -e sched_setaffinity -fyy taskset -p 5 691247
pid 691247's current affinity mask: f00000000000300000000000f000040000003
sched_setaffinity(691247, 24, [0, 2]) = 0
pid 691247's new affinity mask: 5
+++ exited with 0 +++
-- Again, queried taskset shows previous which is not 5.
server-1:# taskset -cp 691247
pid 691247's current affinity list: 0,1,30,48-51,96,97,144-147```