iowait 是否包含等待網路呼叫的時間?

iowait 是否包含等待網路呼叫的時間?

線上說明頁面proc(5)將 iowait 描述為「等待 IO 完成的時間」。這是主要解釋了在之前的一個問題中。我的問題是:在等待阻塞IO時,這包括等待阻塞網路IO,還是僅等待本地IO?

答案1

這意味著等待“文件I/O”,也就是說,對已安裝文件系統中的文件進行任何讀/寫調用,但也可能會計算等待換入或請求加載頁面到內存的時間,例如,庫不是尚未在記憶體中,或不在 RAM 中的 mmap() 檔案頁。

它不會計算等待 IPC 物件(例如套接字、管道、ttys、select()、poll()、sleep()、pause() 等)所花費的時間。

基本上,這是線程等待同步磁碟 IO 的時間 - 在此期間,理論上它可以運行,但不能運行,因為它需要的某些資料尚不存在。此類進程通常顯示為“D”狀態,並影響盒子的平均負載。

令人困惑的是,我認為這可能包括網路檔案系統上的檔案 IO。

答案2

iowait 時間是進程在核心 I/O 調度程式中花費的時間量。據我所知,就常規套接字連接而言,這與網路 I/O 沒有任何關係。但是,它將包括等待 NFS 等網路檔案系統所花費的時間。

答案3

確實如此。

順便說一句,我管理的一台伺服器出現了高 iowait,這是由錯誤的 NFS 安裝引起的。

top - 06:19:03 up 14 days, 10:15,  3 users,  load average: 9.67, 11.83, 12.31
Tasks: 135 total,   1 running, 134 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.2%us,  0.2%sy,  0.0%ni,  0.0%id, 99.7%wa,  0.0%hi,  0.0%si,  0.0%st

top - 06:22:55 up 14 days, 10:19,  3 users,  load average: 10.58, 11.13, 11.89
Tasks: 137 total,   1 running, 136 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.2%sy,  0.0%ni,  0.0%id, 99.8%wa,  0.0%hi,  0.0%si,  0.0%st

並查看D狀態中的進程。

root     27011  0.0  0.0      0     0 ?        S    03:12   0:00 [nfsd4]
root     27012  0.0  0.0      0     0 ?        S    03:12   0:00 [nfsd4_callbacks]
root     27013  0.0  0.0      0     0 ?        D    03:12   0:01 [nfsd]
root     27014  0.0  0.0      0     0 ?        D    03:12   0:01 [nfsd]
root     27015  0.0  0.0      0     0 ?        D    03:12   0:01 [nfsd]
root     27016  0.0  0.0      0     0 ?        D    03:12   0:01 [nfsd]

答案4

iowait 包含網路呼叫。我這樣說是因為從核心的角度來看,NFS 處理的 Linux 本機檔案系統一樣多:

$ vim linux-2.6.38.2/fs/nfs/file.c 

const struct file_operations nfs_file_operations = {
        .llseek         = nfs_file_llseek,
        .read           = do_sync_read,
        .write          = do_sync_write,
        .aio_read       = nfs_file_read,
        .aio_write      = nfs_file_write,
        .mmap           = nfs_file_mmap,
        .open           = nfs_file_open,
        .flush          = nfs_file_flush,
        .release        = nfs_file_release,
        .fsync          = nfs_file_fsync,
        .lock           = nfs_lock,
        .flock          = nfs_flock,
        .splice_read    = nfs_file_splice_read,
        .splice_write   = nfs_file_splice_write,
        .check_flags    = nfs_check_flags,
        .setlease       = nfs_setlease,
};

當進程呼叫檔案描述符 5 上的寫入時,會發生類似的情況:

files->fd_array[5]->f_op->write(argv.......)

因此,進程不知道正在使用哪種檔案系統(vfs 魔法),且 iowait 與本機檔案系統相同。

相關內容