systemd allows to use the same mechanism (kernel API) as uksmd using the MemoryKSM=yes service option. The idea is that we take the processes that are parent to most user processes like display managers (SDDM/GDM/LightMD/Ly/etc) or getty in case we don't have a display manager, and enable MemoryKSM=yes for them, so that all child processes inherit the PR_SET_MEMORY_MERGE attribute, which gives ksmd a hint that the pages of this process can be merged. Unlike uksmd it allows us to:
1) Don't waste a lot of unnecessary CPU time for tracking down new processes.
2) No need for additional kernel patches that will probably never be accepted in upstream.
3) Avoid depending on extra services/packages which may be undesirable for some users (see https://github.com/CachyOS/CachyOS-PKGBUILDS/issues/203)
4) For some users uksmd causes freezes (see https://github.com/CachyOS/uksmd/issues/5).
I also put a new ksmctl utility in these patches that allows you to disable ksmd right at runtime, in case debugging/regressions occur. Measurements and profits can be retrieved using topmem --sort ksm.
Marked as a draft until systemd 256 is available in the repo, as it contains an important fix related to these changes.
systemd allows to use the same mechanism (kernel API) as uksmd using the
MemoryKSM=yes
service option. The idea is that we take the processes that are parent to most user processes like display managers (SDDM/GDM/LightMD/Ly/etc) or getty in case we don't have a display manager, and enableMemoryKSM=yes
for them, so that all child processes inherit the PR_SET_MEMORY_MERGE attribute, which gives ksmd a hint that the pages of this process can be merged. Unlike uksmd it allows us to: 1) Don't waste a lot of unnecessary CPU time for tracking down new processes. 2) No need for additional kernel patches that will probably never be accepted in upstream. 3) Avoid depending on extra services/packages which may be undesirable for some users (see https://github.com/CachyOS/CachyOS-PKGBUILDS/issues/203) 4) For some users uksmd causes freezes (see https://github.com/CachyOS/uksmd/issues/5).I also put a new
ksmctl
utility in these patches that allows you to disable ksmd right at runtime, in case debugging/regressions occur. Measurements and profits can be retrieved usingtopmem --sort ksm
.Marked as a draft until systemd 256 is available in the repo, as it contains an important fix related to these changes.