[Memory Deduplication] Implement New Technology to Incus

BTW Your LD_PRELOAD usage is invalid for systemd.
You can only specify the library name without path.
And it needed to be in system approved library location(seems correct for you,don’t forget to run ldconfig)

A arbitray library with path is forbidden in LD_PRELOAD for systemd.

1 Like

Thank you for the clarification and additional information.

I checked whether the processes are KSM using the files, but it seems these files don’t exist:

root@ksm:~# cat /proc/process_pid/ksm_*
cat: '/proc/process_pid/ksm_*': No such file or directory

I agree that implementing KSM settings directly in systemd would be a cleaner solution for systemd-based systems. There is even information about this implementation here.

Regarding the use of LD_PRELOAD in systemd, I think it’s impractical, even if it seems ideal for systemd-based systems. This approach limits the use of containers based on Alpine Linux with the OpenRC initialization system, which is a popular choice for running containers.

As an alternative, I tried using LD_PRELOAD in the /etc/environment file, which provided more benefits for using KSM:

root@ksm:~# echo $[$(cat /sys/kernel/mm/ksm/pages_sharing)*$(getconf PAGE_SIZE)/1024 ]KB
39540KB

It would be great to have an implementation that doesn’t restrict the use of KSM in different environments. For example, in KVM, it’s implemented out of the box, but the expected advantages are not observed (source).

Thank you once again for your help!

process_pid should be the pid of the process you checking for.
I’m using a custom kernel so I don’t know whether the entry is also available on distro kernel or not.

For some setups, you may want to look into DAMON based memory reclaim(though not as same as ksm)
https://dri.freedesktop.org/docs/drm/admin-guide/mm/damon/reclaim.html

1 Like

Thank you for the explanation.

DAMON looks like an interesting solution, but I’m not yet sure how to use it or how it can help save RAM. I need to dig deeper and learn more about it.

Thank you again for your guidance and support!