io wait

2023-05-16

    准确的说iowait只是表示在统计CPU空闲周期时间片内,有多少时间在等待IO执行,反应的是IO设备的性能。这里CPU并不会等待IO,但是相应的      操作IO的线程或者进程需要等到IO操作完成
   以下是man top 的解释
   iowait is the percentage of the time that the system was idle and at least one process was waiting for disk IO to finish.
The precise meaning of I/O wait time in Linux
November 18, 2013 (updated March 3, 2015)
Some time ago I had a discussion with some systems guys about the exact meaning of the I/O wait time which is displayed by top as a percentage of total CPU time. Their answer was that it is the time spent by the CPU(s) while waiting for outstanding I/O operations to complete. Indeed, the man page for the top command defines this as the “time waiting for I/O completion”.


However, this definition is obviously not correct (or at least not complete), because a CPU never spends clock cycles waiting for an I/O operation to complete. Instead, if a task running on a given CPU blocks on a synchronous I/O operation, the kernel will suspend that task and allow other tasks to be scheduled on that CPU.


So what is the exact definition then? There is an interesting Server Fault question that discussed this. Somebody came up with the following definition that describes I/O wait time as a sub-category of idle time:


iowait is time that the processor/processors are waiting (i.e. is in an idle state and does nothing), during which there in fact was outstanding disk I/O requests.
That makes perfect sense for uniprocessor systems, but there is still a problem with that definition when applied to multiprocessor systems. In fact, “idle” is a state of a CPU, while “waiting for I/O completion” is a state of a task. However, as pointed out earlier, a task waiting for outstanding I/O operations is not running on any CPU. So how can the I/O wait time be accounted for on a per-CPU basis?


For example, let’s assume that on an otherwise idle system with 4 CPUs, a single, completely I/O bound task is running. Will the overall I/O wait time be 100% or 25%? I.e. will the I/O wait time be 100% on a single CPU (and 0% on the others), or on all 4 CPUs? This can be easily checked by doing a simple experiment. One can simulate an I/O bound process using the following command, which will simply read data from the hard disk as fast as it can:


dd if=/dev/sda of=/dev/null bs=1MB
Note that you need to execute this as root and if necessary change the input file to the appropriate block device for your hard disk.


Looking at the CPU stats in top (press 1 to get per-CPU statistics), you should see something like this:


%Cpu0  :  3,1 us, 10,7 sy,  0,0 ni,  3,5 id, 82,4 wa,  0,0 hi,  0,3 si,  0,0 st
%Cpu1  :  3,6 us,  2,0 sy,  0,0 ni, 90,7 id,  3,3 wa,  0,0 hi,  0,3 si,  0,0 st
%Cpu2  :  1,0 us,  0,3 sy,  0,0 ni, 96,3 id,  2,3 wa,  0,0 hi,  0,0 si,  0,0 st
%Cpu3  :  3,0 us,  0,3 sy,  0,0 ni, 96,3 id,  0,3 wa,  0,0 hi,  0,0 si,  0,0 st
This output indicates that a single I/O bound task only increases the I/O wait time on a single CPU. Note that you may see that occasionally the task “switches” from one CPU to another. That is because the Linux kernel tries to schedule a task on the CPU it ran last (in order to improve CPU cache hit rates), but this is not always possible and the task is moved on another CPU. On some systems, this may occur so frequently that the I/O wait time appears to be distributed over multiple CPUs, as in the following example:


%Cpu0  :  5.7 us,  5.7 sy,  0.0 ni, 50.5 id, 34.8 wa,  3.3 hi,  0.0 si,  0.0 st
%Cpu1  :  3.0 us,  3.3 sy,  0.0 ni, 72.5 id, 20.9 wa,  0.3 hi,  0.0 si,  0.0 st
%Cpu2  :  7.0 us,  4.3 sy,  0.0 ni, 62.0 id, 26.7 wa,  0.0 hi,  0.0 si,  0.0 st
%Cpu3  :  4.3 us,  2.3 sy,  0.0 ni, 89.6 id,  3.7 wa,  0.0 hi,  0.0 si,  0.0 st
Nevertheless, assuming that dd is the only task doing I/O on the system, there can be at most one CPU in state I/O wait at any given point in time. Indeed, 34.8+20.9+26.7+3.7=86.1 which is close to but lower than 100.


To make the experiment more reproducible, we can use the taskset command to “pin” a process to a given CPU (Note that the first command line argument is not the CPU number, but a mask):


taskset 1 dd if=/dev/sda of=/dev/null bs=1MB
Another interesting experiment is to run a CPU bound task at the same time on the same CPU:


taskset 1 sh -c "while true; do true; done"
The I/O wait time now drops to 0 on that CPU (and also remains 0 on the other CPUs), while user and system time account for 100% CPU usage:


%Cpu0  : 80,3 us, 15,5 sy,  0,0 ni,  0,0 id,  0,0 wa,  0,0 hi,  4,3 si,  0,0 st
%Cpu1  :  4,7 us,  3,4 sy,  0,0 ni, 91,3 id,  0,0 wa,  0,0 hi,  0,7 si,  0,0 st
%Cpu2  :  2,3 us,  0,3 sy,  0,0 ni, 97,3 id,  0,0 wa,  0,0 hi,  0,0 si,  0,0 st
%Cpu3  :  2,7 us,  4,3 sy,  0,0 ni, 93,0 id,  0,0 wa,  0,0 hi,  0,0 si,  0,0 st
That is expected because I/O wait time is a sub-category of idle time, and the CPU to which we pinned both tasks is never idle.


These findings allow us to deduce the exact definition of I/O wait time:


For a given CPU, the I/O wait time is the time during which that CPU was idle (i.e. didn’t execute any tasks) and there was at least one outstanding disk I/O operation requested by a task scheduled on that CPU (at the time it generated that I/O request).


Note that the nuance is not innocent and has practical consequences. For example, on a system with many CPUs, even if there is a problem with I/O performance, the observed overall I/O wait time may still be small if the problem only affects a single task. It also means that while it is generally correct to say that faster CPUs tend to increase I/O wait time (simply because a faster CPU tends to be idle more often), that statement is no longer true if one replaces “faster” by “more”.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

io wait 的相关文章

  • 如何让 C 程序等待(在 Linux 上)?

    如何让 C 程序等待 在 Linux 上 我需要使用等待与 MPI 我需要 C 代码 如果要等待 MPI 请求 请使用 MPI Wait http www manpagez com man 3 MPI Wait 如果您想等待一定时间 请使用
  • 在 Java 的 main() 中对 Thread 实例运行 wait()

    我正在尝试 java lang Object 中 wait 的定时版本 并观察到它在两种不同场景中的行为有所不同 场景1 使用Thread中run 的默认定义 public static void main String args thro
  • 如何使用 Qt 创建暂停/等待函数?

    我正在玩Qt 我想在两个命令之间创建一个简单的暂停 但它似乎不会让我使用Sleep int mili 而且我找不到任何明显的等待函数 我基本上只是制作一个控制台应用程序来测试一些类代码 这些代码稍后将包含在适当的 Qt GUI 中 所以现在
  • Python,睡眠一些代码而不是全部

    我遇到一种情况 在代码中的某个时刻我想触发多个计时器 代码将继续运行 但在某个时刻这些函数将触发并从 给定列表中删除一个项目 类似 但不完全像下面的代码 问题是 我希望这些函数等待一定的时间 我知道如何使用睡眠的唯一方法是使用睡眠 但是当我
  • Python - 等待没有高CPU使用率的条件

    在这种情况下 假设我想等待一个可能在任何随机时间发生的条件发生 while True if condition Do Whatever else pass 正如您所看到的 直到条件为 True 时才会发生 pass 但是 虽然条件不成立 但
  • html2canvas 等待图像加载

    我遇到这个问题已经有一段时间了 但我似乎找不到解决方案 我正在使用最新的 html2canvas js 插件来截取使用 fllotcharts 制作的图表的屏幕截图 然后通过隐藏输入提交 base64 屏幕截图 问题是带有图表的 div 也
  • 等待用户输入 C# 控制台应用程序的设置时间

    对于控制台应用程序 我需要知道在继续应用程序的 自动运行 部分之前 如何等待用户输入一个或一组按键设定的时间 大约 10 秒 这让我很困扰 因为我不太清楚计时器是如何工作的 或者 threading sleep 我应该使用什么 一整天都在谷
  • java中使用wait()和notify()的简单场景

    我可以获得一个完整的简单场景 即建议如何使用它的教程 特别是使用队列 The wait and notify 方法旨在提供一种机制 允许线程阻塞直到满足特定条件 为此 我假设您想要编写一个阻塞队列实现 其中有一些固定大小的元素后备存储 您要
  • wait() 调用时出现 IllegalMonitorStateException

    我在我的程序中使用了java中的多线程 我已经成功运行线程 但是当我使用时Thread wait 它正在抛出java lang IllegalMonitorStateException 如何让线程等待直到收到通知 你需要处于一个synchr
  • 了解 C++ 中的 fork、exec 和 wait (Linux)

    我对在 Linux 中使用这些不同类型的系统调用非常陌生 这让我很困惑 就此而言 我只是要求朝着正确的方向推动 开始 而不是要求完成 使用fork exec and wait 我已经阅读了它们 但这仍然对我的情况没有真正帮助 我要做的是以下
  • JavaScript、node.js 在继续之前等待 socket.on 响应

    我需要从客户端的服务器获取信息 所以在服务器端 当客户端第一次连接时我得到了这个 socket on adduser function username misc code where i set num player and whatno
  • 需要 Android 活动等待获取 GPS 位置

    对不起我的英语不好 我正在尝试从 GPS 获取单个位置以添加全局变量纬度 经度 GPS 打开 但在从 GPS 检索数据之前活动仍在继续 换句话说 我的需求 仅当找到位置并且填充了经度和纬度变量时 方法 getCurrentLocation
  • 如何等待 ThreadPoolExecutor 中的所有任务完成而不关闭 Executor?

    我不能使用shutdown and awaitTermination 因为在等待时 新任务可能会被添加到 ThreadPoolExecutor 中 因此 我正在寻找一种方法来等待 ThreadPoolExecutor 清空其队列并完成所有任
  • Linux 等待单个对象?

    这是一段显示问题的代码 main Process process NULL while process cout lt
  • 如何在网络驱动程序中检查页面是否已完全加载?

    我正在编写一些 Java Webdriver 代码来自动化我的应用程序 如何正确判断页面是否已加载 该应用程序也有一些 Ajax 调用 我已经声明了对 WebDriver 的隐式等待 硒会为你做到这一点 或者至少它尽力了 有时它会达不到要求
  • 如何冻结一个线程并从另一个线程通知它?

    我需要暂停 Rust 中的当前线程并从另一个线程通知它 在Java中我会写 synchronized myThread myThread wait 并从第二个线程 恢复主线程 synchronized myThread myThread n
  • 为什么 std::condition_variable::wait 需要互斥锁?

    TL DR 为什么std condition variable 等待 http en cppreference com w cpp thread condition variable wait需要互斥锁作为其变量之一吗 Answer 1 您
  • 检查线程状态,同时使其处于等待状态

    我想知道是否可以检查线程的状态 该线程可能处于可等待状态 但不一定如此 如果它处于可等待状态 我想将其保留在该状态 基本上 如何在不更改线程 可等待 状态的情况下检查线程的状态 通过等待 我的意思是如果我调用 wait pid 它会正确返回
  • 如何在我的 Lua 脚本中添加“睡眠”或“等待”?

    我正在尝试通过更改一天中的时间来为游戏制作一个简单的脚本 但我想快速完成 这就是我要说的 function disco hour minute setTime 1 0 SLEEP setTime 2 0 SLEEP setTime 3 0
  • 如何使用 wait() 和 notification() 正确暂停线程

    我想要一个启动线程并提供暂停和继续该线程的方法的类 我的第一个方法是使用标志 只要该值为 true 它就会循环 sleep 方法 就像是 public class Bot private Thread t private boolean i

随机推荐

  • 《最重要的事,只有一件》读书笔记

    背景 每天都在忙忙碌碌中度过 xff0c 感觉到很累 xff0c 但仔细思考一下好像也没有收获 仔细想一想 xff0c 在每天之中 xff0c 大脑主动或被动的接受了太多的信息 xff0c 如果没有给信息分出轻重缓急 xff0c 整理归类
  • table合并单元格colspan和rowspan

    span style font family none code span style background color rgb 255 255 0 span style font family none code span style f
  • jQuery两个稳定版本的比较

    jquery历经了多个版本的更新 xff0c 版本上的比较貌似没什么必要性 xff0c 一般来说新的版本会比旧的版本各方面都略有提升 xff0c 但由于新版中增加了各种新的功能 xff0c 难免会引起bug的发生 评估一个版本是否适合当前开
  • 室内定位简介

    室内定位定义 xff1a 室内定位是指在室内环境中实现位置定位 xff0c 主要采用无线通讯 基站定位 惯导定位等多种技术集成形成一套室内位置定位体系 xff0c 从而实现人员 物体等在室内空间中的位置监控 室内定位需求 xff1a 在室外
  • 命令行提交代码到gitLab服务器

    1 创建项目 xff0c 前提是gitLab服务器已经搭建完成 xff0c 在gitLab个人账户下创建一个项目 xff0c 项目名称自己定义 xff0c 如图 xff1a 2 拷贝本地代码到指定目录 xff0c 一般自己创建一个固定的代码
  • VS 附加到进程调试技巧

    有些时候碰到自己开发的程序嵌入到别人的框架中 xff0c 而在接口的地方出了问题 xff0c 而又不方便将自己的模快加入到别人的工程中 有很多相关的文件 xff0c 还有mster页面等 xff0c 这个时候VS的附加到进程调试变得不可或缺
  • Request和Response详解

    Request 和 Response 对象起到了服务器与客户机之间的信息传递作用 Request 对象用于接收客户端浏览器提交的数据 xff0c 而 Response 对象的功能则是将服务器端的数据发送到客户端浏览器 一 Request对象
  • 人最宝贵的东西是生命

    钢铁是怎样炼成的 人最宝贵的东西是生命 生命属于人只有一次 一个人的生命是应该这样度过的 当他回首往事的时候 他不会因虚度年华而悔恨 也不会因碌碌无为而羞耻 这样在临死的时候 他才能够说 39 我的生命和全部的经历 都献给世界上最壮丽的事业
  • 树莓派卡在开机界面循环要求输入密码,提示cannot currently show the desktop

    这个必须得记录下来 xff0c 太坑了 昨天树莓派用着好好的 xff0c 突然就拷贝ssh拷贝东西进去拷贝不成功 xff0c VNC登陆图形界面 xff0c 输入密码后又循环弹出输入密码解密 xff0c 还提示 cannot current
  • FreeRTOS----debug之任务的挂起和恢复实验,任务无法切换

    任务的挂起和恢复 debug xff1a 背景 xff1a 有两个Task Task1为LED闪烁任务 Task2为挂起恢复LED任务 调试程序遇到的问题 xff1a LED灯闪烁任务不能正常执行 一直常亮 原因 xff1a LED闪烁任务
  • 提高IT运维效率,深度解读京东云AIOps落地实践(异常检测篇)

    基于深度学习对运维时序指标进行异常检测 xff0c 快速发现线上业务问题 时间序列的异常检测是实际应用中的一个关键问题 xff0c 尤其是在 IT 行业 我们没有采用传统的基于阈值的方法来实现异常检测 xff0c 而是通过深度学习提出了一种
  • Android getResources的作用和需要注意点

    今天做一个Android的文件管理器 xff0c 里面用到很多的地方用到了getResources Drawable currentIcon 61 null currentIcon 61 getResources getDrawable R
  • Mac OS X 的包管理器 HomeBrew

    Homebrew 是最简单和灵活的方式 xff0c 用来在 Mac OS X 安装 Linux 工具包 Homebrew 国内高速安装脚本 xff1a HomebrewCN Homebrew 国内安装脚本 安装过程很简单 xff1a rub
  • Android中Parcelable的原理和使用方法

    Parcelable的简单介绍 介绍Parcelable不得不先提一下Serializable接口 xff0c Serializable是Java为我们提供的一个标准化的序列化接口 那什么是序列化呢 进行Android开发的时候 xff0c
  • 小米路由器安装mt工具箱

    去年六月底的时候在小米路由3上开启了ssh 安装了mt工具箱 现在回头看来 xff0c 开启ssh的方法已经大相径庭 不过 xff0c 今天的主角换成了小米路由器pro半个月前替换掉原来的小米路由3 那么 xff0c 肯定也是要在小米路由器
  • SSD的随机读能力 和一个高访问量的读写服务系统

    昨天晚上写了个代码 xff0c 测试了下目前我这个1000块钱的SSD的随机读能力 主机配置 i5 4核 两物理核 8G内存 linux 内核版本 2 6 18 128 el5 一个50G的文件 gt gt 8G内存 防止全缓存至内存中 p
  • 系统过载及保护的思考

    家用电器为了防止电流过大 xff0c 都会有保险装置 当电流过大时 xff0c 自动切断电流 xff0c 防止电器损坏 防洪大坝的水位超过了警戒线 xff0c 会开闸泄洪 xff0c 防止大坝崩溃 而我们的服务系统如果一旦流量过大 用户或请
  • 系统调用,上下文切换及中断概念的汇总

    仔细揣摩了一段时间 系统调用和上下文切换 1 1 首先每个进程都拥有两个堆栈 用户态栈和内核态栈 1 2 每CPU变量中会有两个栈单独用于中断过程 分别用于每个独立核的软中断和硬中断 2 6 x版本后 1 3 系统调用过程 进程进入内核态
  • 吞吐量和延时

    某单机计算秘钥的服务 cpu bound 4核 xff0c 接受网络req 最大吞吐10万 s xff0c 4核cpu均达到99 以上 当吞吐达到10万 s时 xff0c 对于单个req延时是多少 xff1f 假设服务有个队列 xff08
  • io wait

    准确的说iowait只是表示在统计CPU空闲周期时间片内 xff0c 有多少时间在等待IO执行 xff0c 反应的是IO设备的性能 这里CPU并不会等待IO xff0c 但是相应的 操作IO的线程或者进程需要等到IO操作完成 以下是man