V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
Davic1
V2EX  ›  Linux

系统负载(Load average)和 Run Queue 问题

  •  
  •   Davic1 · 2022-02-21 09:58:39 +08:00 · 2303 次点击
    这是一个创建于 822 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Load average(下面用 load avg 代替)用来表示进程对系统资源的需求情况 在 Linux 上计算 load avg 的时候包含了 Runnable/Running(R 状态)和 Sleeping Uninterruptible(D 状态)的进程.

    每个进程占用 CPU 的时间是有限的,当前未能占用的进程会被安排在 run queue 里等待 CPU 的下一次调度. load avg 的值反映了 run queue 中等待 CPU 的进程数量情况.进程越多,load avg 值越大.

    根据wikipedia的介绍,run queue 有两种模型:

    1. 每个 CPU 有一个 run queue
    2. 只有 1 个 run queue

    我的问题是

    1. 怎么去判断自己的 Linux 机器是采用哪种 run queue 模型?
    2. 如果是每个 CPU 一个 run queue, 用什么命令 /方式去查看每个 CPU 的 run queue 情况呢?
    6 条回复    2022-03-21 15:16:45 +08:00
    libook
        1
    libook  
       2022-02-21 10:16:01 +08:00
    没研究过这个东西。

    粗略看了一下 Wikipedia ,有这么一句话:“In the Linux operating system (prior to kernel 2.6.23), each CPU in the system is given a run queue, which maintains both an active and expired array of processes. ”就是说每个 CPU 有一个 runqueue 。

    还有一句话是:“In UNIX or Linux, the sar command is used to check the run queue. ”
    你可以 man sar 看看这个指令怎么用。
    libook
        2
    libook  
       2022-02-21 10:19:16 +08:00
    Davic1
        3
    Davic1  
    OP
       2022-02-21 10:45:16 +08:00
    @libook sar 只会显示一个 r 列 所以我不太明白他究竟是代表 1 个 queue 还是说把所有 queue 的 TASK 数量都加在一起然后显示成 1 列....
    libook
        4
    libook  
       2022-02-21 12:27:05 +08:00   ❤️ 2
    可以看一下源码 https://github.com/torvalds/linux/blob/master/kernel/sched/core.c

    我问了对 Kernel 开发比较了解的朋友,说现在 Linux 都是每个 CPU 有一个 runqueue 。
    Davic1
        5
    Davic1  
    OP
       2022-02-21 13:33:40 +08:00
    @libook 谢谢!
    guoooo00oohao
        6
    guoooo00oohao  
       2022-03-21 15:16:45 +08:00
    可以在 /proc/sched_debug 中看到每 cpu 的 running queue 的情况.

    load 的负载还与 .nr_uninterruptible. 有直接关系.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2424 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 15:42 · PVG 23:42 · LAX 08:42 · JFK 11:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.