哪些因素触发linux内核将IO缓冲区刷新到磁盘上

问题描述 投票:1回答:1

我写了一个写有缓冲的IO的程序:-

  current_offset = 0;
  int fd = open(file_name, O_RDWR , 0644);
  while (current_offset + 4096 < 600M) {
     int ret = pwrite(fd, buf, 4096 , current_offset);
     current_offset += 4096;
   } 

  fsync(fd);

即使有很多可用的缓冲区,并且在代码执行fsync之前,内核仍在将缓冲区写入磁盘。

dstat输出下面显示内核正在后台将缓冲区写入磁盘:-

dstat -d -D /dev/sdb
read  writ

0    19M
0    48M
0    16M
0    16M
0    16M
0    15M
0    16M
0    16M
0    16M
0    16M
0    25M
0    32M
0    31M

free -m表示没有内存压力。

$ free -m
              total        used        free      shared  buff/cache   available
Mem:          64323       27472       35398           0        1452       36187
Swap:             0           0           0

哪些因素决定内核触发将缓冲区写入磁盘?

是否有任何内核可调参数可以更改该行为?

linux caching filesystems
1个回答
0
投票

以下内核参数由pdflush / flush / kdmflush使用:

vm.dirty_background_bytes = 0
vm.dirty_background_ratio = 10
vm.dirty_bytes = 0
vm.dirty_expire_centisecs = 3000
vm.dirty_ratio = 30
vm.dirty_writeback_centisecs = 500
© www.soinside.com 2019 - 2024. All rights reserved.