KSM was originally developed for use with KVM (where it was known as Kernel Shared Memory), to fit more virtual machines into physical memory, by sharing the data common between them. But it can be useful to any application which generates many instances of the same data.
The KSM daemon ksmd periodically scans those areas of user memory which have been registered with it, looking for pages of identical content which can be replaced by a single write-protected page (which is automatically copied if a process later wants to update its content). The amount of pages that KSM daemon scans in a single pass and the time between the passes are configured using sysfs interface
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)
One imagines that one could maybe make a library interposer to induce use of that.
I wonder how much exact duplication each process has?
https://www.kernel.org/doc/html/latest/admin-guide/mm/ksm.html
One imagines that one could maybe make a library interposer to induce use of that.
I guess the key is it has to be the same version of electron in the back end. If they change too much of it then how much memory can be shared?