Chinaunix首页 | 论坛 | 博客
  • 博客访问: 562662
  • 博文数量: 104
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1559
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-21 00:58
个人简介

锻炼精神,首先要锻炼肉体

文章分类

全部博文(104)

文章存档

2018年(1)

2016年(1)

2015年(101)

2014年(1)

我的朋友

分类: LINUX

2015-06-16 18:40:26

Name
numactl - Control NUMA policy for processes or shared memory
numactl - 用于控制 进程与共享存储的 NUMA 技术机制
NUMA -- (Non Uniform Memory Access Architecture) 非统一内存访问架构

Synopsis
概述
numactl [--interleave nodes] [--preferred node] [--membind nodes]
  [--cpunodebind nodes] [--physcpubind cpus] [--localalloc] [--] {arguments ...}
numactl --show
numactl --hardware
numactl [--huge] [--offset offset] [--shmmode shmmode] [--length length] [--strict]
[--shmid id] --shm shmkeyfile | --file tmpfsfile
[--touch] [--dump] [--dump-nodes] memory policy

Description
使用方法介绍

numactl runs processes with a specific NUMA scheduling or memory placement policy.
使用 numactl 命令启动的进程会按照特定的 NUMA 调度机制或是在指定的内存空间位置上运行.

The policy is set for command and inherited by all of its children .
让进程按照NUMA 调度机制运行是通过命令行来实现的,而被设定进程得子进程也会遵照 NUMA 调度机制运行.

In addition it can set persistent policy for shared memory segments or files.
除了将 NUMA 调度机制设置在进程上之外, 还可通过将该 NUMA 调度机制作用在 共享内存段或是文件对象上来实现 NUMA策略的持久化.
/ 也就是把可持久化的对象(内存空间或是文件实体)设定成符合 NUMA调度机制的实体,这样运行在该块空间上的所有数据的调度都可以按照 NUMA 策略来执行
Use
     -- before command if using command options that could be confused with numactl options.
numactl 命令的使用方法
     -- 在使用该命令之前,如果不了解每个命令选项的确切含义的话,只会是使用命令使用者徒增麻烦

Policy settings are :
关于 numactl 命令的不同选项解释如下

--interleave=nodes, -i nodes
          Set a memory interleave policy. Memory will be allocated using round robin on nodes.
          这个选项用于设定内存的交织分配模式。 也就是说系统在为多个节点分配内存空间的时候,将会以轮询分发的方式被分配给这多个节点.
          When memory cannot be allocated on the current interleave target fall back to other nodes.
          如果在当前众多的交织分配内存节点中的目标节点无法正确的分配内存空间的话,内存空间将会由其他的节点来分配。

       Multiple nodes may specified on --interleave, --membind and --cpunodebind.
       多节点可以通过 --interleave , --membind 和 --cpunodebind 命令来指定.

       You may specify "all" , which means all nodes in the current cpuset. nodes may be specified as N,N,N or N-N or N, N-N or N-N , N-N and so forth.
       也可以通过使用 'all'  这个选项, 'all' 选项是用来选定在当前运行的 cpu 集合中的所有节点. 节点可以通过 N,N,N 或是 N-N 或是 N,N-N 或者是 N-N , N-N 诸如此类的
       方式来指定
     / 其中 N,N,N --> node1,node2,node0  可以看做是将 numa 调度机制施加到 node1, node2, node3 的上面
    /  而 N-N or N ---> node1-node7, node12 可以看做是将 numa 机制施加到 [node1,node7] 和单独的 node12 节点上面 ,
    /   后面的 N-N 等等都是在此基础上演变而来的

        Relative nodes may be specified as +N,N,N or +N-N or +N,N-N and so forth.
        如果节点之间具有相关性的话,是可以通过 +N,N,N 或者是 +N-N 或者是 +N,N-N 这种设定方式来表明这些节点之间是有相关性的.

        The +indicates that the node numbers are relative to the process' set of allowed cpu in its current cpuset .
         上面命令中 使用 '+' 符号作为修饰的节点与 被准许留在在当前 cpu 集合中 的cpu 上所运行的进程是一一对应的.

        A !N-N notation indicates the inverse of N-N , in other words all nodes except N-N.
        !N-N 这种表述方式表明的是 N-N 含义的翻转,也就是说,某个命令将会被施加在除了 N-N 这一区间内的节点以外的所有节点集 上面
         If used with + notation , specify !+N-N .
         如果在使用 '!' 符号的同时,也需要使用 '+' 符号的话, 按照 '!+N-N' 这个顺序来使用。

--membind=nodes, -m nodes
          Only allocate memory from nodes. Allocation will fail when there is not enough memory available on these nodes.
           选项 '--membind' 仅用来从节点中分配内存空间所用。 如果在这些节点中无法分配出所请求的空间大小的话该分配操作将会失败.
           nodes may be specified as noted above .
           上述命令中指定需要分配空间的 nodes 的方式可以遵照上述 N,N,N , N-N ,N 这种方式来指定.

--cpunodebind=nodes, -N nodes
           Only execute process on cpus. This accepts cpu numbers as shown in the processor fields of /proc/cpuinfo , or relative cpus as in relative to the current cpuset.
          上述命令仅用于施加在运行与 cpu 上的进程。这个命令用于显示 cpu 的个数,cpu 数目信息同样记录在系统中的存放处理器领域信息的 /proc/cpuinfo 文件夹下,
          或者是按照关联的中央处理器信息 在当前的中央处理器集中所存放.          

You may specify "all" , which means all cpus in the current cpuset .

  使用者可以通过制定 "all" 这个选项来选定当前 中央处理器集合中的所有 中央处理器对象.
      

             Physical cpus may be specified as N,N,N or N-N or N, N-N or N-N,N-N and so forth .
             物理(而非程序中所抽象的) cpu 实体也可以按照 N,N,N 或是 N-N  或者是 N,N-N 或是 N-N,N-N 诸多选定方式进行选定.
     

            Relative cpus may be specified as +N,N,N or +N-N or +N,N-N and so forth.
           相互关联的 cpu 实体也可以按照 +N,N,N 或是 +N-N , 或 +N,N-N 来选定并表明他们之间的关系.

             The +indicates that the cpu numbers are relative to the process' set of allowed cpu in its current cpuset.
          上述命令中的 '+' 符号用于表明 中央处理器的标号与当前其所在的中央处理器集合中某个 cpu 上运行的进程集合中的进程之间是有一定的关联的

              A !N-N notation indicates that the cpu inverse of N-N , in other words all cpus except N-N if used with + notation , specify !+N-N .
            !N-N 这种表述方式表明的是 N-N 含义的翻转,也就是说,某个命令将会被施加在除了 N-N 这一区间内的节点以外的所有节点集
   
--localalloc , -l
                Always allocate on the current node.
           这个命令选项通常是为当前的节点分配内存的

--preferred=node
                Preferably allocate memory on node, but if memory cannot be allocated there fallback to other nodes.
               该命令由于指定优先分配内存空间的节点,如果无法将空间分配给该节点的话,应该分配给该节点上的空间将会被分发到其他的节点上               

                This option takes only
a single node number . Relative notation may be used.
                该命令选项后面仅接收一个单独的节点标号. 
相关的表示方式也可以使用.

--show,-s
               Show NUMA policy setting of the current process.
           该命令用于显示 NUMA 机制作用在当前运行的那些进程上

--hardware , -H
                Show inventory of available nodes on the system.
            该命令用于显示当前系统中有多少个可用的节点.

Numactl can set up policy for a SYSV shared memory segmemnt or a file in shmfs/hugetlbfs.
numactl 命令也可以作用在系统级的共享内存段上或者是施加在 shmfs/hugetlbfs 的文件上

                This policy is persistent and will be used by all mappings from that shared memory .
                 numa 的这种机制是可以被持久化的,并且将  被施加 numa 机制的共享内存 映射到自己地址空间中 的进程都具有 numa 机制

The order of options matters here.

调用命令时所使用的参数选项按照下面的顺序来使用

                 The specification must at least include either of --shm , --shmid , --file to specify the shared memory segment or file
                         and a memory policy like
described above ( --interleave , --localalloc , --preferred , --membind) .
                 在使用命令的时候必须至少包括 --shm ,--shmid , --file 来表明numa 机制作用在共享内存段上还是文件上面,
                 并且还要指定上面介绍过的操作内存的方式 (通过这些选项来指定 --
interleave, --localalloc, --preferred , --membind  )
                

--huge

            When creating a SYSV shared memory segment use huge pages . Only valid before --shmid or --shm
            当创建一个基于大内存页面的系统级的共享内存段的时候,使用 --huge 这个选项。
           --huge 选项仅在 --shmid 或是 --shm 命令的后面使用才有效.
--offset
            Specify offset into the shared memory segment. Default 0. Valid uints are m (for MB), g (for GB) , k (for KB) , otherwise it specifies bytes.
           该参数选项用于指定共享内存段中的位移量的偏移。 默认的情况下偏移量是 0 。 有效的偏移量单位是 m (用于表示 MB)
            g (用于表示 GB) , k (用于表示 KB ), 其他没有指定的被认为是以字节为单位.

--strict 
             Given an error when a page in the policied area in the shared memory segment already was faulted in with a conflicting policy .
             Default is to
silently ignore this .
             这个参数选项 当施加了 NUMA 调度机制的共享内存段区域的页面被施加了另一个机制而导致错误的时候,
            使用 --strict 选项将会把错误信息显示出来. 默认情况是不使用该选项的。

--shmmode shmmode
             Only valid before --shmid or --shm When creating a shared memory segment set it to numeric mode shmmode .
          该选项仅在 --shmid 或是 --shm 之前使用才会生效。 当创建一个共享内存段的时候,通过整型数值来指定
           共享内存的共享的模式类型.

--length length
            Apply policy to length range in the shared memory segment or make the segment length long Default is to use the remaining
           length Required when a shared
memory segment is created and specifies the length of the new segment then .
            Valid units are m ( for MB ) , g( for GB) , k ( for KB) , otherwise it specifies bytes.
            
         


--shmid id
            Create or use an shared memory segment with numeric ID id .
             通过ID 号码来创建或使用一个共享内存段。
               (如果共享内存段已经存在,那么通过 shmid 来指定下面要使用某个 ID 的共享内存 ;  如果该 ID 对应的共享内存段并不存在的话,那么就创建一个)

--shm shmkeyfile
            Create or use an shared memory segment , with the ID generate using fork(3) from shmkeyfile
             通过存放在 shmkeyfile(共享内存-键文件)中的 ID 号码来创建或者是使用一个共享内存段。
             访问 shmkeyfile 文件的进程是通过 fork(3 arguments) 方法来实现的.

--file tmpfsfile
            Set policy for a file in tmpfs or hugetlbfs
         将 numa 机制施加于文件上面, 这个文件属于 tmpfs或者是 hugetlbfs 这种特殊的文件系统

--touch
            Touch pages to enforce policy early. Default is to not touch them , the policy is applied when a applications maps and accesses a page.
             通过将 numa 机制施加于刚刚页面上来实现内存的早期 numa 化。
             默认情况下是不使用该选项,如果存在映射或是访问页面的应用的话,将会使用该早期实行 NUMA 机制的这种方法.

--dump
            Dump policy in the specified range .
         该选项用于废除将已经 numa 化的特定区域上的 NUMA性质.
Valid node specifiers
            all                             All nodes
            number                     Node number
            number1{,number2}  Node number1 and Node number2
            number1-number2     Nodes from number1 to number2
            !nodes                     Invert selection of the following specification .
(--dump ) 选项后,有效指定 node 的书写方式
         all  用于将所有的节点上的 NUMA 特性移除
         number  通过指定 node 后接的数值来废除该数字对应的 node
         number1(number2)  node number1(node number2)上的 NUMA 特性将会被移除
         number1-number2    node number1 -- node number2 区间上的所有存在的 node 的 NUMA 特性将会被移除
         !nodes                除了 nodes 所指定的节点以外的所有节点上的 NUMA 特性全都会被移除




Examples
使用示例

numactl --physcpubind=+0-4,8-12 myapplic arguments

Run myapplic on cpus 0-4 and 8-12 of the current cpuset .

上述的这个命令用于将 myapplic 程序进程运行在当前中央处理器集合的 0-4 和 8-12 标号的cpu 上面.

numactl --interleave=all bigdatabase arguments

Run big database with its memory interleaved on all CPUs.
将大型数据库系统进程,并且允许该进程使用所有 cpu 交替分配的内存空间.(round robin 内存分配机制)

numactl --cpubind=0 --membind=0,1 process

Run process on node 0 with memory allocated on node0 and 1 .
上述的命令是将进程运行在 node0 上面,而进程运行所需要的内存空间则是从 node0 和 node1 上面分配而来的

numactl --cpubind=0 --membind=0,1 --process -l

Run process as above, but with an option (-l) that would be confused with a numactl option .
运行上述的程序,但是这个命令中有一个 -l 的选项可能会和 numactl 的设置选项弄混淆

numactl --preferred=1 numactl --show

Set preferred node 1 and show the resulting state.
将 node1 这个节点设置为优先运行进程的节点,设置之后调用 --show 参数来显示当前进程运行的状态信息

numactl --interleave=all --shmkeyfile /tmp/shmkey

interleave all of the
sysv shared memory region specified by /tmp/shmkey over all nodes.
交织/交替 将系统中所有在 /tmp/shmkey 文件夹下创建的系统级的共享内存域(因为内存区间段可能有多个,并且有可能出现不连续的,这个命令是将其全部选上)
分配给系统中的所有节点

numactl --offset=1G --length=1G --membind=1 --file /dev/shm/A --touch

Bind the second gigabyte in the tmpfs file /dev/shm/A to node1.

在 tmpfs 文件系统中文件夹 /dev/shm/ 下面创建 1 GB 大小的文件 ,并将该文件命名为 A ,然后将该 1GB 的文件与 node 1 进行绑定.
/ 也就是说 node1 中使用的内存是来自于文件系统中的文件.

numactl --localalloc /dev/shm/file

Reset the policy for the shared memory file  to the default localalloc policy.
将共享文件的 NUMA 特性重置成本地默认调度机制

Notes
注意

Requires an NUMA policy aware kernel .
执行 numactl 命令之前,需要明确知道当前主机的内核是支持 NUMA 技术的.

Command is not executed using s shell. If you want to use shell metacharacters in the child use sh -c as wrapper.
上述命令在 shell 脚本中无法被执行。 如果想要在子脚本中使用 shell 元字符的话需要在前面加上用作封装器的 -c 选项

Setting policy for hugetlbfs file does currently not work because it cannot be extended by truncate.
将 NUMA 机制施加于 hugetblfs 文件系统中的文件上的时是不会立即生效的,因为 hugetblfs 这个文件系统无法以 truncate 的方式打开文件.
/在普通文件系统中,truncate 打开文件的方式是这样的 : 当文件不在指定路径下存在的时候,会在该路径下创建该文件,然后将其打开;
/ 当文件存在的时候,会自己打开该文件

Shared memory segments larger than numactl's address space cannot be completely policied.
如果共享内存段的大小要大于 执行 numactl 这一命令进程的地址空间要打的话,不能够确保全部共享内存区域都具有 NUMA 机制.

This could be a problem on 32bit architectures.
在 32 位架构主机上就有可能出现这个问题(共享内存段无法完全的实现 NUMA 机制).

Changing it piece by piece may work .
把(范围区间十分大的)共享内存段分割成多个小段,然后一段一段的 NUMA 化可能会解决这个问题.

The old --cpubind which accepts node numbers, not cpu numbers, is deprecated and replaced with the new --cpunodebind and --physcpubind optins.
以前的旧命令选项 --cpubind 接收的数字表示的是 node 的个数而非 cpu 的个数, 这个命令已经过时了,取而代之的是 --cpunodebind 和 --physcpubind
(分别用于设定绑定的 cpu 中节点的个数, 和绑定的 物理 cpu 的个数

Files
关于系统文件

/proc/cpuinfo for the listing of active CPUs.
位于 /proc/cpuinfo 路径下的文件记录的是当前活跃状态的 CPU 的信息

/sys/devices/system/node/node*/numastat for NUMA memory hit statistics.
/sys/devices/system/node/node*/numastat 文件用于记录的是使用 NUMA 调度策略之后, 内存命中率 等相关统计信息

 
这篇文章我是通过翻译的方式来自学的,有很多地方理解的都不到位,如果您看到有明确错误的地方,
或是翻译得不恰当的地方,希望您能指出来,我会学习改正。十分感谢.

阅读(8725) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~