Linux

GNU“時間”中的 I/O 度量單位是什麼?

  • July 8, 2020

GNUtime具有可選的 I/O 測量顯示:

TIME="%I:%O" /usr/bin/time cp filea fileb
0:5488

但它測量的是什麼單位?有任何想法嗎?說明書只說

  %I     Number of filesystem inputs by the process.

  %O     Number of filesystem outputs by the process.

這沒什麼幫助。

一些測試表明它可能是 512k 塊,包括數據和元數據:

$ TIME="%I:%O" /usr/bin/time dd if=/dev/zero of=foo bs=1 count=1024
1024 bytes (1.0 kB, 1.0 KiB) copied, 0.0120082 s, 85.3 kB/s
0:8

$ TIME="%I:%O" /usr/bin/time dd if=/dev/zero of=foo bs=1k count=1 conv=sync
1024 bytes (1.0 kB, 1.0 KiB) copied, 0.000354987 s, 2.9 MB/s
0:8

$ TIME="%I:%O" /usr/bin/time dd if=/dev/zero of=foo bs=1k count=1024
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.017763 s, 59.0 MB/s
0:2080

[craig@ayaki-localdomain personal-git]$ TIME="%I:%O" /usr/bin/time dd if=/dev/zero of=foo bs=1M count=1 conv=sync
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0052077 s, 201 MB/s
0:2048

但很高興確認這一點。

有誰知道它來自哪裡?

從手冊:

The `%I' and `%O' values are allegedly only `real'
input and output and do not include those supplied
by caching devices. The meaning of `real' I/O reported
by `%I' and `%O' may be muddled for workstations,
especially diskless ones.

所以單元在 I/O 中。也許原始碼知道這意味著什麼。從 time.c 中的匯總函式文件中:

...
I == file system inputs (ru_inblock)
...
O == file system outputs (ru_oublock)
...

ru_inblock 和 ru_oblock 來自 getrusage。從 getrusage 手冊:

ru_inblock (since Linux 2.6.22)
 The number of times the filesystem had to perform input.

ru_oublock (since Linux 2.6.22)
 The number of times the filesystem had to perform output.

好吧,這並不是特別有用,但是 LKML 顯示了正在討論的更新檔(https://lkml.org/lkml/2007/3/19/100)以添加 ru_inblock 和 ru_oublock:

As TASK_IO_ACCOUNTING currently counts bytes, we approximate blocks
count doing : nr_blocks = nr_bytes / 512

檢查目前核心原始碼(https://github.com/spotify/linux/blob/master/include/linux/task_io_accounting_ops.h)顯示:

/*
* We approximate number of blocks, because we account bytes only.
* A 'block' is 512 bytes
*/
static inline unsigned long task_io_get_inblock(const struct task_struct *p)
{
   return p->ioac.read_bytes >> 9;
}

/*
* We approximate number of blocks, because we account bytes only.
* A 'block' is 512 bytes
*/
static inline unsigned long task_io_get_oublock(const struct task_struct *p)
{
   return p->ioac.write_bytes >> 9;
}

簡而言之,是的,每個塊大約有 512 個字節。

引用自:https://serverfault.com/questions/951226