add support for KSM

This adds support for KSM (kernel samepage merging). It adds a new
boolean parameter called MemoryKSM to enable the feature. The feature
can only be enabled with newer kernels.
This commit is contained in:
Stefan Roesch
2023-06-05 11:22:43 +02:00
committed by Lennart Poettering
parent 308b189511
commit 85614c6e2f
11 changed files with 65 additions and 0 deletions
+11
View File
@@ -5193,6 +5193,16 @@ static int exec_child(
return r;
}
if (context->memory_ksm >= 0)
if (prctl(PR_SET_MEMORY_MERGE, context->memory_ksm) < 0) {
if (ERRNO_IS_NOT_SUPPORTED(errno))
log_unit_debug_errno(unit, errno, "KSM support not available, ignoring.");
else {
*exit_status = EXIT_KSM;
return log_unit_error_errno(unit, errno, "Failed to set KSM: %m");
}
}
/* Drop groups as early as possible.
* This needs to be done after PrivateDevices=y setup as device nodes should be owned by the host's root.
* For non-root in a userns, devices will be owned by the user/group before the group change, and nobody. */
@@ -5773,6 +5783,7 @@ void exec_context_init(ExecContext *c) {
c->tty_cols = UINT_MAX;
numa_policy_reset(&c->numa_policy);
c->private_mounts = -1;
c->memory_ksm = -1;
}
void exec_context_done(ExecContext *c) {