I would like to understand the following problem:
The process only executes a sys write call, in an infinite loop. When I raise iotop, I expect to see non-zero write speed and zero read speed associated with this process. But iotop says that reading and writing can be equal (depending on the size of one record). Take a look at the C code:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#define BUFSIZE 1000000
char buf[BUFSIZE];
const int write_size = 4000;
int main(){
int fd;
if ((fd = open("filename", O_RDWR | O_CREAT, 0666)) < 0){
return -1;
}
ssize_t ret;
while (1){
ret = write(fd, buf, write_size);
if (ret != write_size){
return -1;
}
}
return 0;
}
If you assign different values to "write_size", you will see different read speeds in iotop. If the value is indicated in the code above, iotop shows that reading and writing are equal.
Important:
The problem only occurs under certain conditions:
- The file must be created and filled with data (say, at least 8 GB) before running the code
conf:
Debian lenny, 2TB ( xfs ext4),
uname -a
Linux g-6 2.6.26-bpo.1-xen-amd64 # 1 SMP Mon Jan 12 14:32:40 UTC 2009 x86_64 GNU/Linux
,
.