GNU“时间”中的 I/O 度量单位是什么?

GNU“时间”中的 I/O 度量单位是什么?

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

但如果能确认这一点就更好了。

有谁知道它来自哪里?

答案1

来自手册:

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 字节。

答案2

我会猜测“文件系统输入/输出”是指块大小,因此如果底层文件系统已用 512 字节块格式化,它会返回该大小,如果是其他大小,则返回该大小。

但这只是猜测。

相关内容