So this is a simple one, if I run the following code on Ubuntu 18.04 (4.15.0-29-generic ) and against Ubuntu 16.04 ( 4.4.0-87-generic) I get two different results ; The question is why? It seems that fsync may be broken in the latest kernel and may well be broken as early as 4.10 ? This has huge implications around performance sensitive applications like mysql. (Yes I know it can be turned off in mysql but thats only any good if you like your databases corrupted). 4.4.0-87-generic - # time ./fsync real 0m7.537s <----- user 0m0.000s sys 0m1.060s <-----
4.15.0-29-generic - # time ./fsync real 1m38.299s <----- user 0m0.013s sys 0m0.893s <----- Source stolen from else where. ;-) #include <stdio.h> #include <fcntl.h> #include <time.h> #include <unistd.h> void withSync() { int f = open( "/tmp/t8" , O_RDWR | O_CREAT ); lseek (f, 0, SEEK_SET ); int records = 10*1000; clock_t ustart = clock(); for(int i = 0; i < records; i++) { write(f, "012345678901234567890123456789" , 30); fsync(f); } clock_t uend = clock(); close (f); printf(" sync() seconds:%lf writes per second:%lf\n", ((double)(uend-ustart))/(CLOCKS_PER_SEC), ((double)records)/((double)(uend-ustart))/(CLOCKS_PER_SEC)); } void withoutSync() { int f = open( "/tmp/t10" , O_RDWR | O_CREAT ); lseek (f, 0, SEEK_SET ); int records = 10*1000; clock_t ustart = clock(); for(int i = 0; i < records; i++) { write(f, "012345678901234567890123456789" , 30 ); } clock_t uend = clock(); close (f); printf("no sync() seconds:%lf writes per second:%lf \n", ((double)(uend-ustart))/(CLOCKS_PER_SEC), ((double)records)/((double)(uend-ustart))/(CLOCKS_PER_SEC)); } int main(int argc, const char * argv[]) { /* withoutSync();*/ withSync(); return 0; }
First, 4.15 is not the latest kernel. It may be the latest *Ubuntu* kernel, but this bugzilla is for upstream kernel development, not for Ubuntu kernels. If you have a complaint about an Ubuntu kernel, you should file it with the Ubuntu bug tracking system. I've used the btrace program (from the blktrace package), and verified that as far as the upstream kernel is concerned, fsync was clearly working: 252,4 0 2346 3.637855121 6916 Q WS 645592 + 8 [foo] 252,4 0 2347 3.640164007 6916 Q WS 645592 + 8 [foo] 252,4 0 2348 3.642730677 6916 Q WS 645592 + 8 [foo] 252,4 0 2349 3.645426881 6916 Q WS 645592 + 8 [foo] 252,4 2 1623 3.648270538 6916 Q WS 645592 + 8 [foo] 252,4 2 1624 3.650811476 6916 Q WS 645592 + 8 [foo] 252,4 2 1625 3.653352656 6916 Q WS 645592 + 8 [foo] 252,4 4 1585 3.654199271 0 C WS 527264 + 8 [0] 252,4 4 1586 3.654214847 0 C WS 527272 + 8 [0] 252,4 4 1587 3.655853164 0 C WFS 527280 + 8 [0] 252,4 4 1588 3.656583532 6680 Q WS 527288 + 8 [jbd2/dm-4-8] 252,4 4 1589 3.656640851 6680 Q WS 527296 + 8 [jbd2/dm-4-8] 252,4 4 1590 3.656914175 6680 Q FWFS 527304 + 8 [jbd2/dm-4-8] 252,4 1 1528 3.612347468 0 C WFS 526896 + 8 [0] 252,4 1 1529 3.612850602 0 C WS 645592 + 8 [0] 252,4 1 1530 3.612996388 6680 Q WS 526904 + 8 [jbd2/dm-4-8] 252,4 1 1531 3.613039457 6680 Q WS 526912 + 8 [jbd2/dm-4-8] 252,4 1 1532 3.613196025 0 C WS 526904 + 8 [0] 252,4 1 1533 3.613209660 0 C WS 526912 + 8 [0]