Linux – Overhead of Using Loop-Mounted Images

linuxloop-device

Is there a CPU/RAM overhead associated with using loop-mounted images versus using a physical partition under Linux?

Best Answer

Yes, unless you have a very recent kernel there is significant overhead when using loop devices on linux: data accessed through the loop device has to go through two filesystem layers, each doing its own caching so data ends up cached twice, wasting much memory (the infamous "double cache" issue)

Aside from casual use better alternatives would be to use a dedicated partition or a chroot so data can be accessed directly.

Or use latest kernel, the issue is fixed in linux 4.4 and newer:

Faster and leaner loop device with Direct I/O and Asynchronous I/O support

This release introduces support of Direct I/O and asynchronous I/O for the loop block device. There are several advantages to use direct I/O and AIO on read/write loop's backing file: double cache is avoided due to Direct I/O which reduces memory usage a lot; unlike user space direct I/O there isn't cost of pinning pages; avoids context switches in some cases because concurrent submissions can be avoided. See commits for benchmarks.

Related Question