Linux – Difference between “blockdev –flushbufs” and “sync” on Linux

bufferdisklinux

Is there a difference in practice between running blockdev --flushbufs and sync(1) on Linux? (apart from blockdev flushing for a specific device, and sync being system-wide).

sync(1) manpage says it flushes file system buffers (only?). If do I/O to a drive (with say, dd) without going through a file-system layer, is sync really ineffectual?

When should I use one instead of the other?

Best Answer

If do I/O to a drive (with say, dd) without going through a file-system layer, is sync really inefficient?

This begs the question that writing to a device node bypasses "the file-system layer". I suppose in a sense it obviously does...

In any case, it doesn't matter. If what you are doing does not involve caching, then running sync (or some equivalent) anyway wouldn't be "inefficient": if there's nothing to sync, it's a trivial call.

When should one use one instead of the other?

I guess when you want to target a particular partition, blockdev makes sense. I can't see how it would have any particular advantage over sync otherwise (and vice versa).