6

Is there a way to sync a specific device in Linux?

This would be used to ensure that, e.g., writes to a USB thumb drive have taken place without waiting for queued writes from a video processing job to complete on an unrelated RAID array.

If there is a system call / combination of parameters that can achieve this, I could probably write a simple C wrapper. If someone knows of a Ubuntu package that can do this, that'd be even better.

2
  • 2
    Closely related: unix.stackexchange.com/questions/28554/… Commented Jul 12, 2015 at 2:25
  • Have you heard of stripes lvm? Another choice is with rsync --Only update the changes in another partition or folder like a cvs or subversion. Commented Jul 12, 2015 at 4:44

2 Answers 2

5

You cannot sync(2) a device, and that does not have any sense. You are syncing a file system (not the device mounting it) with syncfs or the entire page cache with sync.

The sync(2) syscall is called by the sync(1) command.

(I don't know of any usual command doing a syncfs)

However, you could flush the buffers for a file system by using the Linux specific syncfs(2) syscall. So write a simple C wrapper doing that.

For an opened file descriptor, you could use fsync(2) or fdatasync

Notice that unmounting a file system is generally flushing it.

1
  • 3
    Well, syncing a device is obviously not what sync(2) does. However, I believe syncing a device nevertheless has a "sense". It is observed that on Linux, "dd" happily returns as soon as the commanded write operations have been queued by the OS, and does not wait for the data to reach the target. So Linux does buffering of writes to block devices, not only to files residing on filesystems. And a way to perform a sync of such buffers is what I was asking about. Commented Jul 14, 2015 at 0:25
0

Consider using Direct I/O, this will avoid the need to sync. Some filesystems can be forced to use it via mount option (dio).

1
  • But direct I/O would greatly decrease performance.... Commented Jul 12, 2015 at 9:32

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.