Re: [PATCH 2/3] mm/ksm: Support prctl controlling KSM with pid

From: xu xin
Date: Tue Sep 03 2024 - 00:13:42 EST


Thanks for your reply.

Selection of interface
======================

At this point, I have been thinking for a long time, and in order to achieve
the control of the KSM scanning of an already running process, the current
prctl PR_SET_MEMORY_MERGE is the most suitable interface. On the one hand,
it is compatible with the existing KSM PRCTL interface, making it easier
for users to get used to and adapt to it; On the other hand, it adds prctl
control over processes that have already been started through PID. Lastly,
I referred to the PR_SCHED_CORE option of prctl, which also uses arg3 to
perform operations on tasks pointed to by specific PID.

Anyway, the current way may not necessarily violates "prctl() manipulates
various aspects of the behavior of the calling thread or process." ,
becasue we can consider controlling KSM scanning of pid as a behavior of
the calling thread.

By the way, I explain some more about why we want to manipulates KSM
behavior of an already running process.

Purpose (or usecase):
=====================

In the field of embedded Linux for cost considerations, resources including
cpu and memory, are often not very sufficient, so the global deployment of
KSM can be a mitigation strategy, which is feasible for closed system
(scenarios without Internet connection). However, KSM has a side effect of
increasing write time replication latency, which is somewhat unacceptable
for latency sensitive applications. Therefore, it can be combined with the
QoS of the business tasks to dynamically close some part of those already
started processes in real time if the QoS degrade. Although it is also
beneficial for server/cloud OS, the requirement of embedded system is more
urgent and strong compared to cloud or server operating systems with
sufficient memory.