RCHAR是否包含READ_BYTES(proc / <pid> / io)?</pid>

时间:2012-05-17 14:07:41

标签: linux io linux-kernel procfs monetdb

我读proc/<pid>/io来测量SQL查询的IO活动,其中<pid>是数据库服务器的PID。我读取每个查询之前和之后的值以计算差异并获得请求被读取和/或写入的字节数。

据我所知,字段READ_BYTES计算实际磁盘IO,而RCHAR包含更多内容,例如linux页面缓存可以满足的读取(请参阅Understanding the counters in /proc/[pid]/io进行说明) )。 这导致假设RCHAR应该得出等于或大于READ_BYTES的值,但我的结果与此假设相矛盾。

我可以想象我为Infobright ICE得到的一些小块或页面开销(值为MB):

        Query        RCHAR   READ_BYTES
tpch_q01.sql|    34.44180|    34.89453|
tpch_q02.sql|     2.89191|     3.64453|
tpch_q03.sql|    32.58994|    33.19531|
tpch_q04.sql|    17.78325|    18.27344|

但我完全不理解MonetDB的IO计数器(值为MB):

        Query        RCHAR   READ_BYTES
tpch_q01.sql|     0.07501|   220.58203|
tpch_q02.sql|     1.37840|    18.16016|
tpch_q03.sql|     0.08272|   162.38281|
tpch_q04.sql|     0.06604|    83.25391|

假设RCHAR包含READ_BYTES,我错了吗?有没有办法欺骗内核计数器,MonetDB可以使用?这是怎么回事?

我可以补充一点,我清除页面缓存并在每次查询之前重新启动数据库服务器。 我在Ubuntu 11.10上运行内核3.0.0-15-generic。

2 个答案:

答案 0 :(得分:3)

我只能想到两件事:

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/filesystems/proc.txt;hb=HEAD#l1305

1:

1446 read_bytes
1447 ----------
1448
1449 I/O counter: bytes read
1450 Attempt to count the number of bytes which this process really did cause to
1451 be fetched from the storage layer.

我读过“导致从存储层获取”以包含readahead,无论如何。

2:

1411 rchar
1412 -----
1413
1414 I/O counter: chars read
1415 The number of bytes which this task has caused to be read from storage. This
1416 is simply the sum of bytes which this process passed to read() and pread().
1417 It includes things like tty IO and it is unaffected by whether or not actual
1418 physical disk IO was required (the read might have been satisfied from
1419 pagecache)

请注意,这并未说明“通过内存映射文件进行磁盘访问”。我认为这是更可能的原因,并且您的MonetDB可能会编写其数据库文件,然后执行所有操作。

由于其性质,我不确定如何检查mmap上的已用带宽。

答案 1 :(得分:0)

您还可以阅读Linux内核源代码文件:/include/linux/task_io_accounting.h

struct task_io_accounting {
#ifdef CONFIG_TASK_XACCT
  /* bytes read */
  u64 rchar;
  /*  bytes written */
  u64 wchar;
  /* # of read syscalls */
  u64 syscr;
  /* # of write syscalls */
  u64 syscw;
#endif /* CONFIG_TASK_XACCT */

#ifdef CONFIG_TASK_IO_ACCOUNTING
  /*
   * The number of bytes which this task has caused to be read from
   * storage.
   */
  u64 read_bytes;

  /*
   * The number of bytes which this task has caused, or shall cause to be
   * written to disk.
   */
  u64 write_bytes;

  /*
   * A task can cause "negative" IO too.  If this task truncates some
   * dirty pagecache, some IO which another task has been accounted for
   * (in its write_bytes) will not be happening.  We _could_ just
   * subtract that from the truncating task's write_bytes, but there is
   * information loss in doing that.
   */
  u64 cancelled_write_bytes;
#endif /* CONFIG_TASK_IO_ACCOUNTING */
};
相关问题