Yes ksmtuned is your friend. For VMs it can be managed / enabled like any other Linux Kernel + QEMU/KVM running with KSM enabled.
On LXC containers it may be a bit harder as it depends a LOT, best results if you’re using systemd both the host and containers. It may work out all out of the box or you’ll have to resort to ksm_wrapper in both the Incus executable and the stuff running inside your containers.
Don’t forget that:
KSM only operates on those areas of address space which an application has advised to be likely candidates for merging, by using the madvise(2) system call: int madvise(addr, length, MADV_MERGEABLE). www.kernel.org/doc/Documentation/vm/ksm.txt