Use sync_file_range() instead of fsync(), sync()

The place to discuss linux version of MakeMKV
Post Reply
mmlloorrdd
Posts: 6
Joined: Sat Apr 21, 2012 6:10 pm

Use sync_file_range() instead of fsync(), sync()

Post by mmlloorrdd »

Today I tried using MakeMKV to convert some .iso images into episode files, all on a single 2TB drive. At the same time, I have a massive filesystem copy happening between two other drives.

MakeMKV is horrendously slow in this situation, and when it gets to almost the end it just sits there with all three drives (including the two unrelated ones) busy as heck.

I strongly suspect the culprit at the end to be MakeMKV invoking sync(), which won't complete because of all of the unrelated I/O that is happening in the filesystem copies.

MakeMKV should not use sync(). If anything (debateable), it should use fsync(fd) on the specific files it is writing to. Or even better, use sync_file_range().

Performance would be much improved.
If I had the source, I'd happily fix this and send you a patch.

Cheers
mike admin
Posts: 4075
Joined: Wed Nov 26, 2008 2:26 am
Contact:

Re: Use sync_file_range() instead of fsync(), sync()

Post by mike admin »

MakeMKV uses fsync(fd) at the end of conversion. This is done to avoid corrupted files when writing to SMB mounted shares.
mmlloorrdd
Posts: 6
Joined: Sat Apr 21, 2012 6:10 pm

Re: Use sync_file_range() instead of fsync(), sync()

Post by mmlloorrdd »

MMmm.. fsync() by itself should be fine, but the behaviour I'm observing looks very much like sync(), not fsync().

fsync() could end up waiting for all outstanding I/O on the same filesystems to complete, but it's not supposed to care about other filesystems.

On the other hand, sync() won't complete until all filesystems are flushed, and that's what makemkv is doing: waiting for all filesystems to be flushed.

Strange.
Post Reply