Skip to content

RFC Selective KSM: Synchronous and Partitioned Merging

Sourav Panda linux-mm lkml 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest6 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6mm: introduce SELECTIVE_KSM KConfigmm/Kconfig+11 -00 replies
2/6mm: make Selective KSM synchronousmm/ksm.c+271 -460 replies
3/6mm: make Selective KSM partitionedmm/ksm.c+95 -60 replies
4/6mm: create dedicated trees for SELECTIVE KSM partitionsmm/ksm.c+111 -540 replies
5/6mm: trigger unmerge and remove SELECTIVE KSM partitionmm/ksm.c+120 -00 replies
6/6mm: syscall alternative for SELECTIVE_KSMarch/x86/entry/syscalls/syscall_64.tbl include/linux/ksm.h mm/ksm.c+161 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/6] Selective KSM: Synchronous and Partitioned Merging

The purpose of this RFC is to supplement our discussion in LSF/MM-25.

This is sent as a proof of concept. It applies on top of v6.14-rc7.

With the goal of increasing security and improving CPU efficiency, we would like to propose making KSM synchronous and partitioned.

The synchronous aspect eliminates the need of ksmd running in the background. Instead, userspace can trigger merging on the specified memory region synchronously. Contrary to SKSM [1], which uses MADV_MERGE, we also propose sysfs and syscall based alternatives.

The partitioned aspect divides the merge space into security domains. Merging of pages only takes place within a partition, improving security. Furthermore, trees in each partitioning becomes smaller, improving CPU efficiency.

Proposal 1: SYSFS Interface

KSM_SYSFS=/sys/kernel/mm/ksm

  echo "part_1" >  ${KSM_SYSFS}/ksm/control/add_partition

ls ${KSM_SYSFS}/part_1/
pages_scanned pages_to_scan sleep_millisecs ...

  echo "pid start_addr end_addr" > ${KSM_SYSFS}/part_1/trigger_merge

Proposal 2: SYSCALL Interface

Partition can be created or opened using:

int ksm_fd = ksm_open(ksm_name, flag);
name specifies the ksm partition to be created or opened. flags:
O_CREAT
Create the ksm partition object if it does not exist.
O_EXCL
If O_CREAT was also specified, and a shared memory object with the given name already exists, return an error.

Trigger the merge using:

    ksm_merge(ksm_fd, pid, start_addr, size);

[1] https://lore.kernel.org/linux-mm/[email protected]/

Sourav Panda (6):
mm: introduce SELECTIVE_KSM KConfig
mm: make Selective KSM synchronous
mm: make Selective KSM partitioned
mm: create dedicated trees for SELECTIVE KSM partitions
mm: trigger unmerge and remove SELECTIVE KSM partition
mm: syscall alternative for SELECTIVE_KSM

 arch/x86/entry/syscalls/syscall_64.tbl |   3 +-
 include/linux/ksm.h                    |   4 +
 mm/Kconfig                             |  11 +
 mm/ksm.c                               | 823 ++++++++++++++++++++++---
 4 files changed, 751 insertions(+), 90 deletions(-)
Signature · 1 line
2.49.0.395.g12beb8f557-goog