Krishna
Krishna

Reputation: 13

What factors trigger linux kernel to flush IO buffers to disk

I wrote a program that writes buffered 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);

Even though there are plenty of free buffers available and before the code does fsync, kernel is writing the buffers to the disk.

Below dstat output shows kernel is writing buffers to the disk in the background:-

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 shows there is not memory pressure.

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

What factors determine the kernel to trigger writing the buffers to the disk ?

Are there any kernel tunable parameters to change that behavior?

Upvotes: 1

Views: 806

Answers (1)

pifor
pifor

Reputation: 7892

Following kernel parameters are used by 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

These are documented at https://www.kernel.org/doc/Documentation/sysctl/vm.txt

Upvotes: 1

Related Questions