Skip to content

RFC mm/ksm: add option to automerge VMAs

Oleksandr Natalenko linux-api linux-mm lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 RFC Latest4 patches 16 repliesIn review
  2. v1 RFC4 patches 9 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4mm/ksm: introduce ksm_enter() helpermm/ksm.c+36 -240 replies
2/4mm/ksm: introduce ksm_leave() helpermm/ksm.c+22 -100 replies
3/4mm/ksm: introduce force_madvise knobmm/ksm.c+68 -02 replies
4/4mm/ksm: add force merging/unmerging documentationDocumentation/admin-guide/mm/ksm.rst+11 -02 replies

Reviews trailers per patch

2 of 4 patches have a Reviewed-by or Acked-by.

PatchAaron TomlinTimofey Titovets
1/4
2/4
3/4R-b R-b
4/4R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH RFC v2 0/4] mm/ksm: add option to automerge VMAs

By default, KSM works only on memory that is marked by madvise(). And the only way to get around that is to either:

* use LD_PRELOAD; or
* patch the kernel with something like UKSM or PKSM.

Instead, lets implement a sysfs knob, which allows marking VMAs as mergeable. This can be used manually on some task in question or by some small userspace helper daemon.

The knob is named "force_madvise", and it is write-only. It accepts a PID to act on. To mark the VMAs as mergeable, use:

   # echo PID > /sys/kernel/mm/ksm/force_madvise

To unmerge all the VMAs, use the same approach, prepending the PID with the "minus" sign:

   # echo -PID > /sys/kernel/mm/ksm/force_madvise

This patchset is based on earlier Timofey's submission [1], but it doesn't use dedicated kthread to walk through the list of tasks/VMAs. Instead, it is up to userspace to traverse all the tasks in /proc if needed.

The previous suggestion [2] was based on amending do_anonymous_page() handler to implement fully automatic mode, but this approach was incorrect due to improper locking and not desired due to excessive complexity.

The current approach just implements minimal interface and leaves the decision on how and when to act to userspace.

Thanks.

[1] https://lore.kernel.org/patchwork/patch/1012142/
[2] http://lkml.iu.edu/hypermail/linux/kernel/1905.1/02417.html

Oleksandr Natalenko (4):
mm/ksm: introduce ksm_enter() helper mm/ksm: introduce ksm_leave() helper mm/ksm: introduce force_madvise knob mm/ksm: add force merging/unmerging documentation

 Documentation/admin-guide/mm/ksm.rst |  11 ++
 mm/ksm.c                             | 160 +++++++++++++++++++++------
 2 files changed, 137 insertions(+), 34 deletions(-)
Signature · 1 line
2.21.0