Skip to contentSkip to conversation

Why does 'direct' influence 'fsync'?

DISCUSSION Stefan Hajnoczi 2 participants 4 messages Jan 25, 2013 – Jan 27, 2013

lore
Share & tools
lore
#0 lore raw

Is there a way to flush the disk write cache when O_DIRECT is in use?

It seems that direct=1 causes the fsync setting to be ignored. Asias

Quoted 7 lines · writes:

The O_DIRECT do affect the flush behaviour. e.g

guest$ fio --fsync=100 --direct=1
No virtio_blk_handle_flush is observed on host side every 100 IOs

guest$ fio --fsync=100 --direct=0 virtio_blk_handle_flush is observed on host side every 100 IOs

Am I missing a reason for this behavior? To me it seems weird since you could already use --fsync=0 --direct=1 if you want to guarantee that fsync is not called. I don't see a need to override the fsync setting.

Stefan

#1 lore raw
Quoted 10 lines · Stefan Hajnoczi

Is there a way to flush the disk write cache when O_DIRECT is in use?

It seems that direct=1 causes the fsync setting to be ignored. Asias

Quoted 5 lines · writes:

The O_DIRECT do affect the flush behaviour. e.g

guest$ fio --fsync=100 --direct=1
No virtio_blk_handle_flush is observed on host side every 100 IOs

Quoted 6 lines
Quoted 2 lines

guest$ fio --fsync=100 --direct=0 virtio_blk_handle_flush is observed on host side every 100 IOs

Am I missing a reason for this behavior? To me it seems weird since you could already use --fsync=0 --direct=1 if you want to guarantee that fsync is not called. I don't see a need to override the fsync setting.

You are right, fio should not be double guessing options like that. If you ask for fsync, you should get fsync.

Does the below work for you?

fio.h +0 -2
index 3a26335..9e20299 100644
@@ -655,8 +655,6 @@ static inline int should_fsync(struct thread_data *td)
 {
 	if (td->last_was_sync)
 		return 0;
-	if (td->o.odirect)
-		return 0;
 	if (td_write(td) || td_rw(td) || td->o.override_sync)
 		return 1;
 
Signature · 1 line
Jens Axboe
author Tested-by
#2 lore raw
Quoted 14 lines · Jens Axboe
Quoted 13 lines · Stefan Hajnoczi

Is there a way to flush the disk write cache when O_DIRECT is in use?

It seems that direct=1 causes the fsync setting to be ignored. Asias

Quoted 7 lines · writes:

The O_DIRECT do affect the flush behaviour. e.g

guest$ fio --fsync=100 --direct=1
No virtio_blk_handle_flush is observed on host side every 100 IOs

guest$ fio --fsync=100 --direct=0 virtio_blk_handle_flush is observed on host side every 100 IOs

Quoted 8 lines
Quoted 3 lines

Am I missing a reason for this behavior? To me it seems weird since you could already use --fsync=0 --direct=1 if you want to guarantee that fsync is not called. I don't see a need to override the fsync setting.

You are right, fio should not be double guessing options like that. If you ask for fsync, you should get fsync.

Does the below work for you?

Yes, thanks!

#3 lore raw
Quoted 19 lines · Stefan Hajnoczi
Quoted 18 lines · Jens Axboe
Quoted 16 lines · Stefan Hajnoczi

Is there a way to flush the disk write cache when O_DIRECT is in use?

It seems that direct=1 causes the fsync setting to be ignored. Asias

Quoted 7 lines · writes:

The O_DIRECT do affect the flush behaviour. e.g

guest$ fio --fsync=100 --direct=1
No virtio_blk_handle_flush is observed on host side every 100 IOs

guest$ fio --fsync=100 --direct=0 virtio_blk_handle_flush is observed on host side every 100 IOs

Am I missing a reason for this behavior? To me it seems weird since you could already use --fsync=0 --direct=1 if you want to guarantee that fsync is not called. I don't see a need to override the fsync setting.

Quoted 8 lines
Quoted 4 lines

You are right, fio should not be double guessing options like that. If you ask for fsync, you should get fsync.

Does the below work for you?

Yes, thanks!

Great, thanks for reporting and testing!

Signature · 1 line
Jens Axboe