Is there a CPU/RAM overhead associated with using loop-mounted images versus using a physical partition under Linux?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0