Skip to content

--fsync (and --fdatasync) sync the wrong file when multiple files are in use #1904

@StephanDollberg

Description

@StephanDollberg

Please acknowledge the following before creating a ticket

Description of the bug:

When using the --fsync/--fdatasync option together with --nrfiles=2 (effectively anything larger than 1) fio will write to file X and issue the fsync to file X+1 which is obviously not what is intended.

This results in a wildly different performance profile between --nrfiles=1 and --nrfiles=2.

Environment: Ubuntu 24.04 / Linux 6.8.0

fio version:

ubuntu@ip-172-31-44-44:~/fio$ ./fio --version
fio-3.40
ubuntu@ip-172-31-44-44:~/fio$ git rev-parse HEAD
ff930c4653ae3952d6b09ab3ec89671aeabf2cbe

Reproduction steps

Example reproducer:

./fio --name=write_iops --directory=/mnt/xfs --size=5G --time_based --runtime=1s --ramp_time=0s --ioengine=libaio --direct=1 --verify=0 --bs=8K --iodepth=1 --nrfiles=2 --rw=write --fdatasync=1

To see what's going on we can trace the sync backend:

sudo perf trace -- ./fio --name=write_iops --directory=/mnt/xfs --size=5G --time_based --runtime=1s --ramp_time=0s --ioengine=sync --direct=1 --verify=0 --bs=8K --iodepth=1 --nrfiles=2 --rw=write --fdatasync=1 --rate=10M

and we will see lots of output like this:

   720.442 ( 0.023 ms): fio/1451 write(fd: 6</mnt/xfs/write_iops.0.0>, buf: 0xb2e3b946b000, count: 8192) = 8192
   720.467 ( 0.002 ms): fio/1451 fdatasync(fd: 7</mnt/xfs/write_iops.0.1>)                             = 0
   720.471 ( 0.748 ms): fio/1451 clock_nanosleep(rqtp: 0xffffd97b9298)                                 = 0
   721.224 ( 0.026 ms): fio/1451 write(fd: 6</mnt/xfs/write_iops.0.0>, buf: 0xb2e3b946b000, count: 8192) = 8192
   721.252 ( 0.002 ms): fio/1451 fdatasync(fd: 7</mnt/xfs/write_iops.0.1>)                             = 0
   721.255 ( 0.745 ms): fio/1451 clock_nanosleep(rqtp: 0xffffd97b9298)                                 = 0
   722.005 ( 0.024 ms): fio/1451 write(fd: 6</mnt/xfs/write_iops.0.0>, buf: 0xb2e3b946b000, count: 8192) = 8192
   722.031 ( 0.002 ms): fio/1451 fdatasync(fd: 7</mnt/xfs/write_iops.0.1>)                             = 0

which clearly shows the problem. The writes go to fd 6 and the fsyncs go to fd 7.

Metadata

Metadata

Assignees

No one assigned

    Labels

    patcheswelcomeNo one internal is working on this but an external contributor's help is very welcome!triagedIssue cause is understood but a patch is needed to fix it

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions