I run LXC/LXD in Arch Linux (Kernel version = 5.12.8-arch1-1) and Disk IO is waaay slower in lxc containers than in the actual drive.
Here are what I tested:
lvm storage backend:
The problem arose with the lvm storage backend
lxc storage create lvm_pool source=lvmVG lvm.vg.force_reuse=true
lxc launch -p default --config=limits.memory=2GB ubuntu:20.04 test
lxc exec test bash
dd if=/dev/zero of=benchfile bs=4k count=200000 && sync; rm benchfile
200000+0 records in
200000+0 records out
819200000 bytes (819 MB, 781 MiB) copied, 5.68229 s, 144 MB/s
Then I mounted the LV and tried the dd command and it performs well
sudo mount /dev/mapper/lvmVG-containers_test /mnt
dd if=/dev/zero of=benchfile bs=4k count=200000 && sync; rm benchfile
200000+0 records in
200000+0 records out
819200000 bytes (819 MB, 781 MiB) copied, 0.527557 s, 1.6 GB/s
Then I used the dir backend. Nothing changed
lxc storage create dir_pool source=/mnt/containers
lxc launch -p default --config=limits.memory=2GB ubuntu:20.04 test
dd if=/dev/zero of=benchfile bs=4k count=200000 && sync; rm benchfile
200000+0 records in
200000+0 records out
819200000 bytes (819 MB, 781 MiB) copied, 4.67927 s, 175 MB/s
and on the /mnt/container directly
dd if=/dev/zero of=benchfile bs=4k count=200000 && sync; rm benchfile
200000+0 records in
200000+0 records out
819200000 bytes (819 MB, 781 MiB) copied, 0.604141 s, 1.4 GB/s
On BTRFS, things are better!
# In a container
dd if=/dev/zero of=benchfile bs=4k count=200000 && sync; rm benchfile
200000+0 records in
200000+0 records out
819200000 bytes (819 MB, 781 MiB) copied, 0.690473 s, 1.2 GB/s
# In the host
dd if=/dev/zero of=benchfile bs=4k count=200000 && sync; rm benchfile
200000+0 records in
200000+0 records out
819200000 bytes (819 MB, 781 MiB) copied, 0.592722 s, 1.4 GB/s
ZFS is Okey-ish too
dd if=/dev/zero of=benchfile bs=4k count=200000 && sync; rm benchfile
200000+0 records in
200000+0 records out
819200000 bytes (819 MB, 781 MiB) copied, 1.0413 s, 787 MB/s
I can’t use ZFS or BTRFS in my use case, since they don’t play well with kubernetes and/or nested containers.
My questions are:
Is the difference between my host and containers using dir and lvm OKey ? the containers are almost unusable and very slow. Is there a problem ? and how can I debug it ?
Is ZFS performance normal compared to btrfs backend (and to host’s) ?
What are the tools and methods you use to debug storage problems lxc and linux in general ?
Instead of dd + sync, could you try dd with conv=fdatasync?
sync is always a global action and will flush the buffers not just of the container but of the entire host system too, so fdatasync should give more consistent results.
I tried multiple times and I still get a little bit less IOPS and throughput in a container than host. I guess it’s related to the snapshot thing of containers.