暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

Linux 绑核工具 numactl

原创 wzf0072 2023-09-22
938

Linux 绑核工具 numactl  

  • 本文主要介绍 numactl 的安装、使用。NUMA(Non-Uniform Memory Access,非一致性内存访问)绑核工具,主要为了防止 CPU 资源争抢引发性能降低的问题。

介绍

numactl 通过将 CPU 划分多个 node 减少 CPU 对总线资源的竞争,一般使用在高配置服务器部署多个 CPU 消耗性服务使用。

安装


yum -y install numactl

$ numactl usage: numactl [--all | -a] [--interleave= | -i <nodes>] [--preferred= | -p <node>] [--physcpubind= | -C <cpus>] [--cpunodebind= | -N <nodes>] [--membind= | -m <nodes>] [--localalloc | -l] command args ... numactl [--show | -s] numactl [--hardware | -H] numactl [--length | -l <length>] [--offset | -o <offset>] [--shmmode | -M <shmmode>] [--strict | -t] [--shmid | -I <id>] --shm | -S <shmkeyfile> [--shmid | -I <id>] --file | -f <tmpfsfile> [--huge | -u] [--touch | -T] memory policy | --dump | -d | --dump-nodes | -D memory policy is --interleave | -i, --preferred | -p, --membind | -m, --localalloc | -l <nodes> is a comma delimited list of node numbers or A-B ranges or all. Instead of a number a node can also be: netdev:DEV the node connected to network device DEV file:PATH the node the block device of path is connected to ip:HOST the node of the network device host routes through block:PATH the node of block device path pci:[seg:]bus:dev[:func] The node of a PCI device <cpus> is a comma delimited list of cpu numbers or A-B ranges or all all ranges can be inverted with ! all numbers and ranges can be made cpuset-relative with + the old --cpubind argument is deprecated. use --cpunodebind or --physcpubind instead <length> can have g (GB), m (MB) or k (KB) suffixes
  • 查看numa状态

$ numactl --show policy: default preferred node: current physcpubind: 0 1 2 3 4 5 6 7 8 9 cpubind: 0 1 nodebind: 0 1 membind: 0 1 $ numactl --hardware available: 2 nodes (0-1) node 0 cpus: 0 1 2 3 4 node 0 size: 1853 MB node 0 free: 1559 MB node 1 cpus: 5 6 7 8 9 node 1 size: 1934 MB node 1 free: 1563 MB node distances: node 0 1 0: 10 20 1: 20 10

此系统共有2个node,node0有4个cpu和1853内存,node1有4个cpu和1934内存


$ numastat node0 node1 numa_hit 230764 243128 numa_miss 0 0 numa_foreign 0 0 interleave_hit 8011 8054 local_node 230309 235324 other_node 455 7804

说明:

  • numa_hit:该节点成功分配本地内存访问的内存大小
  • numa_miss:内存访问分配到另一个node的大小,该值和另一个node的numa_foreign相对应
  • local_node:该节点的进程成功在本节点上分配内存访问的大小
  • other_node:该节点进程在其它节点上分配的内存访问的大小

注意:miss 和 foreign 的值越高,就考虑 CPU 绑定

使用示例

内存交织分配模式

使用 --interleave 参数,如占用内存的mongodb程序,共享所有 node 内存:


numactl --interleave=all mongod -f /etc/mongod.conf


内存绑定


numactl --cpunodebind=0 --membind=0 python param numactl --physcpubind=0 --membind=0 python param

CPU绑定


numactl -C 0-1 ./test

将应用程序test绑定到0~1核上运行

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论