Btrfs and KSM (kernel samepage merging)

Hi!

I have the following setup:
100 Fedora 41 VMs each 4 GB RAM running on 128 GB server (laptop).
All VMs have the same setup.
Especially all have “autopart --type=lvm” (kickstart setup)
This is working because KSM (kernel samepage merging) is working very very well.
I use:
echo 1 > /sys/kernel/mm/ksm/run
echo 100000 > /sys/kernel/mm/ksm/pages_to_scan
Inside the VM I fill up the memory with “rpm -Vaq” (mostly filesystem cache).
Outside after some time there is no swap usage and there are even about 40 GB free.
“top” really shows 100 processes (“qemu-system-x86”) each having 4,0g RSS.

I now tried to use “autopart --type=btrfs” for the VM setup,
but with that the saving through KSM is much less.

The only change in the kickstart file is:
“autopart --type=lvm” → “autopart --type=btrfs”

Is this a known behavior and can I do something to improve this keeping with btrfs?

Thank you
Christoph

My guess is that what you are seeing is the checksum feature of btrfs data integrity making the meta data cached by the kernel different in each VM.

Is there a way to read these checksums so that I can compare them?
Just to be sure it is this feature.

That would require knowledge of the btrfs disk format and in kernel structures. I do not have that knowledge.