I am trying to work with dm-mapper and it doesnt accept files. so i need a device.
So i have created a 1500M file on ram(ramfs filesystem) at /dev/shm/f and mapped it to /dev/loop0(by losetup).
But i have about a fourth performance on loop-device compared to the file.
File on ram benchmark:
# dd if=/dev/shm/f of=/dev/null bs=16k
96000+0 records in
96000+0 records out
1572864000 bytes (1.6 GB, 1.5 GiB) copied, 0.379551 s, 4.1 GB/s
Loopback device benchmark:
# dd if=/dev/loop0 of=/dev/null bs=16k
96000+0 records in
96000+0 records out
1572864000 bytes (1.6 GB, 1.5 GiB) copied, 1.62812 s, 966 MB/s
Is there any better way to chage the file into the device?
If no is there anything i can do to make loop-device faster?
Edit 1: System specs: ram ddr2 667 and cpu e5500
I have tried created ramdisk and /dev/shm/f with random data and for testing changed bs=16k to bs=512k. hear are the result:
- the file on ramfs without direct io(doesnt accept the direct flag) 3.5GB :
# dd if=/dev/shm/f of=/dev/null bs=512K status=progress
2048+0 records in
2048+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.3091 s, 3.5 GB/s
- ramdisk without and with direct io ( 1GB/s and 3.4GB/s) :
# dd if=/dev/ram0 of=/dev/null bs=512K status=progress
937951232 bytes (938 MB, 894 MiB) copied, 1.00036 s, 938 MB/s
2048+0 records in
2048+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 1.22576 s, 876 MB/s
# dd if=/dev/ram0 of=/dev/null bs=512K status=progress iflag=direct
2048+0 records in
2048+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.319873 s, 3.4 GB/s
3)loop device without and with direct (954MB/s and 2.5GB/s):
# dd if=/dev/loop0 of=/dev/null bs=512k status=progress
2048+0 records in
2048+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 1.1009 s, 975 MB/s
# dd if=/dev/loop0 of=/dev/null bs=512k status=progress iflag=direct
2048+0 records in
2048+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.436886 s, 2.5 GB/s
- ramdisk in device mapper (920MB/s and 2.4GB/s)
mount /dev/mapper/ram-snap /mnt/sta1
cat /dev/urandom >/mnt/sta1/tst
# dd if=/mnt/sta1/tst of=/dev/null bs=512K count=1500 status=progress conv=sync
1500+0 records in
1500+0 records out
786432000 bytes (786 MB, 750 MiB) copied, 0.850705 s, 924 MB/s
# dd if=/mnt/sta1/tst of=/dev/null bs=512K count=1500 status=progress iflag=direct conv=sync
1500+0 records in
1500+0 records out
786432000 bytes (786 MB, 750 MiB) copied, 0.327174 s, 2.4 GB/s
- loop device on dm without and with direct(950MB/s and 1.7GB/s)
# dd if=/mnt/sta1/tst of=/dev/null bs=512K count=1500 status=progress
1500+0 records in
1500+0 records out
786432000 bytes (786 MB, 750 MiB) copied, 0.827005 s, 951 MB/s
# dd if=/mnt/sta1/tst of=/dev/null bs=512k count=1500 status=progress iflag=direct
1500+0 records in
1500+0 records out
786432000 bytes (786 MB, 750 MiB) copied, 0.451071 s, 1.7 GB/s
Well roughly it seems even in the case that you can use direct flag there is about 30% reduction in performance in (case 3, 4 and 5) and in practical situation you dont have control on direct flag so the real performance drop is 60%-70%(read speed without direct on my system around 800-1000 MB/s).
Considering that some ssd have the same read speeds, i think something is wrong.
Is there any way to make read from loop device(not loop file attached to loop device ) direct by defult?