4 ms·
Point 2 is not actually the case, as long as your write does not partially fill a pagecache page (pagecache pages are the same size as the architecture's native
by caf 13y ago
Point 2 is not actually the case, as long as your write does not partially fill a pagecache page (pagecache pages are the same size as the architecture's native page size - 4K on x86, x86-64 and arm).
You can demonstrate this with a program like the following:
int main(int argc, char *argv[])
{
int i;
char pattern[512*1024];
int fd;
for (i = 0; i < sizeof pattern; i++)
pattern[i] = 'X';
fd = open("testfile", O_RDWR | O_CREAT | O_EXCL, 0666);
if (fd < 0)
{
perror("open");
return 1;
}
while (1)
{
pwrite(fd, pattern, sizeof pattern, 0);
fdatasync(fd);
posix_fadvise(fd, 0, sizeof pattern, POSIX_FADV_DONTNEED);
}
return 0;
}
...then watch vmstat or iostat while it's running. Plenty of writes, no reads.
On the other hand, if you subtract one from the size of 'pattern', you'll see that you also get reads (as partially writing the last page requires a read-modify-write cycle).