大网数据广告活动
服务器运维问答

What units are the I/O measures in GNU "time" in?

· 52CE 我爱测

GNU time has optional display of I/O measurements: TIME="%I:%O" /usr/bin/time cp filea fileb 0:5488 but what units is it measuring? Any ideas? The manual only says %I Number of filesystem inputs by the process. %O Number of files…

问题原文

原帖链接 · Craig Ringer · CC BY-SA 4.0

GNU time has optional display of I/O measurements:

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

but what units is it measuring? Any ideas? The manual only says

   %I     Number of filesystem inputs by the process.

   %O     Number of filesystem outputs by the process.

which is less than helpful.

A few tests suggest it is probably 512k blocks, both data and metadata:

$ 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

but it'd be nice to confirm that.

Anyone know where it comes from?

已采纳解答

原帖链接 · rsaxvc · CC BY-SA 4.0

From the manual:

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.

So units are in I/Os. Perhaps the source code knows what that means. From the summarize function documentation in time.c:

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

ru_inblock and ru_oblock come from getrusage. From the getrusage manual:

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.

Well that's not particularly useful, but LKML shows the patches being discussed(https://lkml.org/lkml/2007/3/19/100) to add ru_inblock and ru_oublock:

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

A check on the current kernel source code(https://github.com/spotify/linux/blob/master/include/linux/task_io_accounting_ops.h) shows:

/*
 * 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;
}

and

/*
 * 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;
}

In short, yes, blocks are approximately 512 bytes each.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-01-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。