精华内容
下载资源
问答
  • 主要介绍了Linux Shell脚本查看NUMA信息,本文直接给出脚本实现代码,需要的朋友可以参考下
  • 获取内存NUMA信息

    千次阅读 2017-03-08 12:24:09
    linux内核获取NUMA信息

    NUMA(Non-uniform memory access)是一个高级玩意,咱先来看看维基百科上的定义:

    is a computer memory design used in multiprocessing, where the memory access time depends on the memory location relative to the processor. Under NUMA, a processor can access its own local memory faster than non-local memory (memory local to another processor or memory shared between processors). The benefits of NUMA are limited to particular workloads, notably on servers where the data are often associated strongly with certain tasks or users.

    总的一句话来讲,就是分配内存时需要区别对待。不同区域的内存我们叫做不同的节点,节点之间我们又定义了个“距离”的概念用来衡量内存访问时间的差异。

    好了,有了基本的概念,我们来看看linux内核中是如何获得NUMA信息的。

    在x86平台,这个工作分成两步

    • 将numa信息保存到numa_meminfo
    • 将numa_meminfo映射到memblock结构

    本文着重关注第一次获取到numa信息的过程,对node和zone的数据结构暂时不在本文中体现。

    全局概览

    做事儿最好有点大局观,看代码学内核也是这个道理。那就先来看看总体结构。

    setup_arch()
      initmem_init()
        x86_numa_init()
            numa_init()
                x86_acpi_numa_init()
                numa_cleanup_meminfo()
                numa_register_memblks()

    接下来我们关注的就是最后这两个函数的作用。

    将numa信息保存到numa_meminfo

    在x86架构上,numa信息第一次获取是通过acpi或者是读取北桥上的信息。具体的函数是numa_init()。不管是哪种方式,numa相关的信息都最后保存在了numa_meminfo这个数据结构中。

    这个数据结构和memblock长得很像,展开看就是一个数组,每个元素记录了一段内存的起止地址和node信息。

        numa_meminfo
        +------------------------------+
        |nr_blks                       |
        |    (int)                     |
        +------------------------------+
        |blk[NR_NODE_MEMBLKS]          |
        |    (struct numa_memblk)      |
        |    +-------------------------+
        |    |start                    |
        |    |end                      |
        |    |   (u64)                 |
        |    |nid                      |
        |    |   (int)                 |
        +----+-------------------------+

    在这个过程中使用的就是这个函数添加的numa_meminfo数据结构。

    • numa_add_memblk()

    这个函数非常简单,而且粗暴。

    将numa_meminfo映射到memblock结构

    内核获取了numa_meminfo之后并没有如我们想象一般直接拿来用了。虽然此时给每个numa节点生成了我们以后会看到的node_data数据结构,但此时并没有直接使能它。

    memblock是内核初期内存分配器,所以当内核获取了numa信息首先是把相关的信息映射到了memblock结构中,使其具有numa的knowledge。这样在内核初期分配内存时,也可以分配到更近的内存了。

    在这个过程中有两个比较重要的函数

    • numa_cleanup_meminfo()
    • numa_register_memblks()

    前者主要用来过滤numa_meminfo结构,合并同一个node上的内存。

    后者就是把numa信息映射到memblock了。除此之外,顺便还把之后需要的node_data给分配了,为后续的页分配器做好了准备。

    观察memblock的变化

    memblock的调试信息默认没有打开,所以要观察的话需要传入内核启动参数”memblock=debug”。

    进入系统后,输入命令”dmesg | grep -A 9 MEMBLOCK”可以看到

    [    0.000000] MEMBLOCK configuration:
    [    0.000000]  memory size = 0x00000001f9c4e800 reserved size = 0x0000000014aab27c
    [    0.000000]  memory.cnt  = 0x7
    [    0.000000]  memory[0x0] [0x0000000000001000-0x000000000009cfff], 0x000000000009c000 bytes flags: 0x0
    [    0.000000]  memory[0x1] [0x0000000000100000-0x00000000ba5b1fff], 0x00000000ba4b2000 bytes flags: 0x0
    [    0.000000]  memory[0x2] [0x00000000ba5b9000-0x00000000bad8dfff], 0x00000000007d5000 bytes flags: 0x0
    [    0.000000]  memory[0x3] [0x00000000bafb6000-0x00000000ca8a1fff], 0x000000000f8ec000 bytes flags: 0x0
    [    0.000000]  memory[0x4] [0x00000000ca93a000-0x00000000ca977fff], 0x000000000003e000 bytes flags: 0x0
    [    0.000000]  memory[0x5] [0x00000000cafff000-0x00000000caffffff], 0x0000000000001000 bytes flags: 0x0
    [    0.000000]  memory[0x6] [0x0000000100000000-0x000000022f5fffff], 0x000000012f600000 bytes flags: 0x0
    --
    [    0.000000] MEMBLOCK configuration:
    [    0.000000]  memory size = 0x00000001f9c4e800 reserved size = 0x0000000014b29800
    [    0.000000]  memory.cnt  = 0x7
    [    0.000000]  memory[0x0] [0x0000000000001000-0x000000000009cfff], 0x000000000009c000 bytes on node 0 flags: 0x0
    [    0.000000]  memory[0x1] [0x0000000000100000-0x00000000ba5b1fff], 0x00000000ba4b2000 bytes on node 0 flags: 0x0
    [    0.000000]  memory[0x2] [0x00000000ba5b9000-0x00000000bad8dfff], 0x00000000007d5000 bytes on node 0 flags: 0x0
    [    0.000000]  memory[0x3] [0x00000000bafb6000-0x00000000ca8a1fff], 0x000000000f8ec000 bytes on node 0 flags: 0x0
    [    0.000000]  memory[0x4] [0x00000000ca93a000-0x00000000ca977fff], 0x000000000003e000 bytes on node 0 flags: 0x0
    [    0.000000]  memory[0x5] [0x00000000cafff000-0x00000000caffffff], 0x0000000000001000 bytes on node 0 flags: 0x0
    [    0.000000]  memory[0x6] [0x0000000100000000-0x000000022f5fffff], 0x000000012f600000 bytes on node 0 flags: 0x0

    瞧,现在每个memblock上都多了node信息是不是?当然我这里只有一个node,如果你的系统上有多个node那就可以看到不一样的信息了。

    插播一条我的补丁

    在code review过程中,发现numa_nodemask_from_meminfo()的作用其实可以被别的东西替代。所以我干脆提了个补丁把这个挪走了。

    补丁的id是:474aeffd88b87746a75583f356183d5c6caa4213

    不过可惜的是,这个补丁还有点小问题。新的改进也写好了,但是到现在还没有合入。社区嘛,你懂的。

    展开全文
  • #!/bin/bashfunction get_nr_processor(){grep '^processor' /proc/cpuinfo | wc -l}function get_nr_socket(){grep 'physical id' /proc/cpuinfo | awk -F: '{print $2 | "sort -un"}' | wc -l}function get_nr_sib...

    #!/bin/bash

    function get_nr_processor()

    {

    grep '^processor' /proc/cpuinfo | wc -l

    }

    function get_nr_socket()

    {

    grep 'physical id' /proc/cpuinfo | awk -F: '{

    print $2 | "sort -un"}' | wc -l

    }

    function get_nr_siblings()

    {

    grep 'siblings' /proc/cpuinfo | awk -F: '{

    print $2 | "sort -un"}'

    }

    function get_nr_cores_of_socket()

    {

    grep 'cpu cores' /proc/cpuinfo | awk -F: '{

    print $2 | "sort -un"}'

    }

    echo '===== CPU Topology Table ====='

    echo

    echo '+--------------+---------+-----------+'

    echo '| Processor ID | Core ID | Socket ID |'

    echo '+--------------+---------+-----------+'

    while read line; do

    if [ -z "$line" ]; then

    printf '| %-12s | %-7s | %-9s |/n' $p_id $c_id $s_id

    echo '+--------------+---------+-----------+'

    continue

    fi

    if echo "$line" | grep -q "^processor"; then

    p_id=`echo "$line" | awk -F: '{print $2}' | tr -d ' '`

    fi

    if echo "$line" | grep -q "^core id"; then

    c_id=`echo "$line" | awk -F: '{print $2}' | tr -d ' '`

    fi

    if echo "$line" | grep -q "^physical id"; then

    s_id=`echo "$line" | awk -F: '{print $2}' | tr -d ' '`

    fi

    done < /proc/cpuinfo

    echo

    awk -F: '{

    if ($1 ~ /processor/) {

    gsub(/ /,"",$2);

    p_id=$2;

    } else if ($1 ~ /physical id/){

    gsub(/ /,"",$2);

    s_id=$2;

    arr[s_id]=arr[s_id] " " p_id

    }

    }

    END{

    for (i in arr)

    printf "Socket %s:%s/n", i, arr[i];

    }' /proc/cpuinfo

    echo

    echo '===== CPU Info Summary ====='

    echo

    nr_processor=`get_nr_processor`

    echo "Logical processors: $nr_processor"

    nr_socket=`get_nr_socket`

    echo "Physical socket: $nr_socket"

    nr_siblings=`get_nr_siblings`

    echo "Siblings in one socket: $nr_siblings"

    nr_cores=`get_nr_cores_of_socket`

    echo "Cores in one socket: $nr_cores"

    let nr_cores*=nr_socket

    echo "Cores in total: $nr_cores"

    if [ "$nr_cores" = "$nr_processor" ]; then

    echo "Hyper-Threading: off"

    else

    echo "Hyper-Threading: on"

    fi

    echo

    echo '===== END ====='

    展开全文
  • Linux中查看NUMA信息2015-03-19本博客所有文章采用的授权方式为自由转载-非商用-非衍生-保持署名,转载请务必注明出处,谢谢。声明:本博客欢迎转发,但请保留原作者信息!新浪微博:@Lingxian_kong;博客地址:孔令贤...

    Linux中查看NUMA信息

    2015-03-19

    本博客所有文章采用的授权方式为

    自由转载-非商用-非衍生-保持署名

    ,转载请务必注明出处,谢谢。

    声明:

    本博客欢迎转发,但请保留原作者信息!

    新浪微博:@Lingxian_kong;

    博客地址:孔令贤的博客;

    微信公众号:飞翔的尘埃;

    内容系本人学习、研究和总结,如有雷同,实属荣幸!

    Nova在NFV场景下会提供NUMA相关高级特性,这里提供一个脚本查看计算节点的NUMA相关信息。

    #!/bin/bash

    function get_nr_processor()

    {

    grep '^processor' /proc/cpuinfo | wc -l

    }

    function get_nr_socket()

    {

    grep 'physical id' /proc/cpuinfo | awk -F: '{

    print $2 | "sort -un"}' | wc -l

    }

    function get_nr_siblings()

    {

    grep 'siblings' /proc/cpuinfo | awk -F: '{

    print $2 | "sort -un"}'

    }

    function get_nr_cores_of_socket()

    {

    grep 'cpu cores' /proc/cpuinfo | awk -F: '{

    print $2 | "sort -un"}'

    }

    echo '===== CPU Topology Table ====='

    echo

    echo '+--------------+---------+-----------+'

    echo '| Processor ID | Core ID | Socket ID |'

    echo '+--------------+---------+-----------+'

    while read line; do

    if [ -z "$line" ]; then

    printf '| %-12s | %-7s | %-9s |\n' $p_id $c_id $s_id

    echo '+--------------+---------+-----------+'

    continue

    fi

    if echo "$line" | grep -q "^processor"; then

    p_id=`echo "$line" | awk -F: '{print $2}' | tr -d ' '`

    fi

    if echo "$line" | grep -q "^core id"; then

    c_id=`echo "$line" | awk -F: '{print $2}' | tr -d ' '`

    fi

    if echo "$line" | grep -q "^physical id"; then

    s_id=`echo "$line" | awk -F: '{print $2}' | tr -d ' '`

    fi

    done < /proc/cpuinfo

    echo

    awk -F: '{

    if ($1 ~ /processor/) {

    gsub(/ /,"",$2);

    p_id=$2;

    } else if ($1 ~ /physical id/){

    gsub(/ /,"",$2);

    s_id=$2;

    arr[s_id]=arr[s_id] " " p_id

    }

    }

    END{

    for (i in arr)

    printf "Socket %s:%s\n", i, arr[i];

    }' /proc/cpuinfo

    echo

    echo '===== CPU Info Summary ====='

    echo

    nr_processor=`get_nr_processor`

    echo "Logical processors: $nr_processor"

    nr_socket=`get_nr_socket`

    echo "Physical socket: $nr_socket"

    nr_siblings=`get_nr_siblings`

    echo "Siblings in one socket: $nr_siblings"

    nr_cores=`get_nr_cores_of_socket`

    echo "Cores in one socket: $nr_cores"

    let nr_cores*=nr_socket

    echo "Cores in total: $nr_cores"

    if [ "$nr_cores" = "$nr_processor" ]; then

    echo "Hyper-Threading: off"

    else

    echo "Hyper-Threading: on"

    fi

    echo

    echo '===== END ====='

    查询结果示例:

    ===== CPU Topology Table =====

    +--------------+---------+-----------+

    | Processor ID | Core ID | Socket ID |

    +--------------+---------+-----------+

    | 0 | 0 | 1 |

    +--------------+---------+-----------+

    | 1 | 1 | 1 |

    +--------------+---------+-----------+

    | 2 | 9 | 1 |

    +--------------+---------+-----------+

    | 3 | 10 | 1 |

    +--------------+---------+-----------+

    | 4 | 0 | 0 |

    +--------------+---------+-----------+

    | 5 | 1 | 0 |

    +--------------+---------+-----------+

    | 6 | 9 | 0 |

    +--------------+---------+-----------+

    | 7 | 10 | 0 |

    +--------------+---------+-----------+

    | 8 | 0 | 1 |

    +--------------+---------+-----------+

    | 9 | 1 | 1 |

    +--------------+---------+-----------+

    | 10 | 9 | 1 |

    +--------------+---------+-----------+

    | 11 | 10 | 1 |

    +--------------+---------+-----------+

    | 12 | 0 | 0 |

    +--------------+---------+-----------+

    | 13 | 1 | 0 |

    +--------------+---------+-----------+

    | 14 | 9 | 0 |

    +--------------+---------+-----------+

    | 15 | 10 | 0 |

    +--------------+---------+-----------+

    Socket 0: 4 5 6 7 12 13 14 15

    Socket 1: 0 1 2 3 8 9 10 11

    ===== CPU Info Summary =====

    Logical processors: 16

    Physical socket: 2

    Siblings in one socket: 8

    Cores in one socket: 4

    Cores in total: 8

    Hyper-Threading: on

    ===== END =====

    展开全文
  • 这篇文章主要介绍了Linux Shell脚本查看NUMA信息,本文直接给出脚本实现代码,需要的朋友可以参考下Nova在NFV场景下会提供NUMA相关高级特性,这里提供一个脚本查看计算节点的NUMA相关信息,?...

    这篇文章主要介绍了Linux Shell脚本查看NUMA信息,本文直接给出脚本实现代码,需要的朋友可以参考下

    Nova在NFV场景下会提供NUMA相关高级特性,这里提供一个脚本查看计算节点的NUMA相关信息,

    ?

    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

    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

    #!/bin/bash

    function get_nr_processor()

    {

    grep ‘^processor‘ /proc/cpuinfo | wc -l

    }

    function get_nr_socket()

    {

    grep ‘physical id‘ /proc/cpuinfo | awk -F: ‘{

    print $2 | "sort -un"}‘ | wc -l

    }

    function get_nr_siblings()

    {

    grep ‘siblings‘ /proc/cpuinfo | awk -F: ‘{

    print $2 | "sort -un"}‘

    }

    function get_nr_cores_of_socket()

    {

    grep ‘cpu cores‘ /proc/cpuinfo | awk -F: ‘{

    print $2 | "sort -un"}‘

    }

    echo ‘===== CPU Topology Table =====‘

    echo

    echo ‘+--------------+---------+-----------+‘

    echo ‘| Processor ID | Core ID | Socket ID |‘

    echo ‘+--------------+---------+-----------+‘

    while read line; do

    if [ -z "$line" ]; then

    printf ‘| %-12s | %-7s | %-9s |\n‘ $p_id $c_id $s_id

    echo ‘+--------------+---------+-----------+‘

    continue

    fi

    if echo "$line" | grep -q "^processor"; then

    p_id=`echo "$line" | awk -F: ‘{print $2}‘ | tr -d ‘ ‘`

    fi

    if echo "$line" | grep -q "^core id"; then

    c_id=`echo "$line" | awk -F: ‘{print $2}‘ | tr -d ‘ ‘`

    fi

    if echo "$line" | grep -q "^physical id"; then

    s_id=`echo "$line" | awk -F: ‘{print $2}‘ | tr -d ‘ ‘`

    fi

    done < /proc/cpuinfo

    echo

    awk -F: ‘{

    if ($1 ~ /processor/) {

    gsub(/ /,"",$2);

    p_id=$2;

    } else if ($1 ~ /physical id/){

    gsub(/ /,"",$2);

    s_id=$2;

    arr[s_id]=arr[s_id] " " p_id

    }

    }

    END{

    for (i in arr)

    printf "Socket %s:%s\n", i, arr[i];

    }‘ /proc/cpuinfo

    echo

    echo ‘===== CPU Info Summary =====‘

    echo

    nr_processor=`get_nr_processor`

    echo "Logical processors: $nr_processor"

    nr_socket=`get_nr_socket`

    echo "Physical socket: $nr_socket"

    nr_siblings=`get_nr_siblings`

    echo "Siblings in one socket: $nr_siblings"

    nr_cores=`get_nr_cores_of_socket`

    echo "Cores in one socket: $nr_cores"

    let nr_cores*=nr_socket

    echo "Cores in total: $nr_cores"

    if [ "$nr_cores" = "$nr_processor" ]; then

    echo "Hyper-Threading: off"

    else

    echo "Hyper-Threading: on"

    fi

    echo

    echo ‘===== END =====‘

    查询结果示例:

    ?

    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

    ===== CPU Topology Table =====

    +--------------+---------+-----------+

    | Processor ID | Core ID | Socket ID |

    +--------------+---------+-----------+

    | 0 | 0 | 1 |

    +--------------+---------+-----------+

    | 1 | 1 | 1 |

    +--------------+---------+-----------+

    | 2 | 9 | 1 |

    +--------------+---------+-----------+

    | 3 | 10 | 1 |

    +--------------+---------+-----------+

    | 4 | 0 | 0 |

    +--------------+---------+-----------+

    | 5 | 1 | 0 |

    +--------------+---------+-----------+

    | 6 | 9 | 0 |

    +--------------+---------+-----------+

    | 7 | 10 | 0 |

    +--------------+---------+-----------+

    | 8 | 0 | 1 |

    +--------------+---------+-----------+

    | 9 | 1 | 1 |

    +--------------+---------+-----------+

    | 10 | 9 | 1 |

    +--------------+---------+-----------+

    | 11 | 10 | 1 |

    +--------------+---------+-----------+

    | 12 | 0 | 0 |

    +--------------+---------+-----------+

    | 13 | 1 | 0 |

    +--------------+---------+-----------+

    | 14 | 9 | 0 |

    +--------------+---------+-----------+

    | 15 | 10 | 0 |

    +--------------+---------+-----------+

    Socket 0: 4 5 6 7 12 13 14 15

    Socket 1: 0 1 2 3 8 9 10 11

    ===== CPU Info Summary =====

    Logical processors: 16

    Physical socket: 2

    Siblings in one socket: 8

    Cores in one socket: 4

    Cores in total: 8

    Hyper-Threading: on

    ===== END =====

    展开全文
  • # ls cpu_layout.py dpdk-hugepages.py dpdk-telemetry-client.py meson.build dpdk-devbind.py dpdk-pmdinfo.py dpdk-telemetry.py 查看NUMA信息 [root@localhost usertools]# ./cpu_layout.py ===================...
  • numa

    千次阅读 2012-07-27 18:05:35
    NUMA 求助编辑百科名片 NUMA(Non Uniform Memory Access Achitecture)技术可以使众多服务器像单一系统那样运转,同时保留小系统便于编程和管理的优点。基于电子商务应用对内存访问提出的更高的要求,NUMA...
  • NUMA

    2015-05-25 21:02:12
    说到服务器的NUMA架构,大家或许都知道。NUMA架构在中大型系统上一直非常盛行,也是高性能的解决方案,尤其在系统延迟方面表现都很优秀。但NUMA架构对服务器的相关性能到底有什么影响,怎样设置会更好呢?本文在此...
  • numa详解

    万次阅读 2018-12-30 23:09:14
    一、系统架构的演进从SMP到NUMA 1、SMP(Symmetric Multi-Processor) 所谓对称多处理器结构,是指服务器中多个CPU对称工作,无主次或从属关系。各CPU共享相同的物理内存,每个 CPU访问内存中的任何地址所需时间是...
  • NUMA概述

    千次阅读 2017-09-03 14:13:50
    NUMA是什么【非统一内存访问(NUMA)是一种用于多处理器的电脑记忆体设计,内存访问时间取决于处理器的内存位置。 在NUMA下,处理器访问它自己的本地存储器的速度比非本地存储器(存储器的地方到另一个处理器之间...
  • NUMA技术相关笔记

    万次阅读 2013-12-06 16:33:55
    起源于在mongo启动脚本中看到numactl --interleave=all mongod ...。 NUMA,非统一内存访问(Non-uniform Memory Access),介于SMP(对称多处理)和MPP...NUMA信息主要通过BIOS中的ACPI(高级配置和编程接口)进行配置,Linux
  • numa总结

    2021-06-18 19:57:26
    文章目录numa架构是啥numa的由来numa带来的问题redis 在NUMA架构上出现...由于其节点之间可以通过互联模块(如称为Crossbar Switch)进行连接和信息交互,因此每个CPU可以访问整个系统的内存(这是NUMA系统与MPP系统的重
  • root@ubuntu2104:~# lscpu |grep NUMA
  • NUMA机制

    2021-04-08 10:21:03
    NUMA一、NUMA二、特点三、缺点 一、NUMA 非一致内存访问(Non-Uniform Aemory Access,NUMA)是一种多核CPU扩展技术。利用NUMA技术,可以将成百上千个CPU组合在服务器中。 访问本地内存(Local Access)速度快 访问远...
  • NUMA 相关

    2020-05-15 14:55:45
    这个命令的一些选项可以用来查看当前的numa信息: numactl --show numactl --hardware 可以看到当前物理机上面有两个NUMA节点。均分所有的CPU,并且还能看到分到的物理内存总量。 dmesg 这个命令打印内

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 13,230
精华内容 5,292
关键字:

numa信息