mbox series

[v2,0/5] propose auto-run mode of ksm and its tests

Message ID 20220812101102.41422-1-xu.xin16@zte.com.cn (mailing list archive)
Headers show
Series propose auto-run mode of ksm and its tests | expand

Message

CGEL Aug. 12, 2022, 10:11 a.m. UTC
From: xu xin <xu.xin16@zte.com.cn>

The following patch series bring a NEW running state "auto mode". In
traditional KSM, whether ksmd works scanning and merging or not
depends on the sysfs klob ksm_run.

Most of time, letting ksmd run is not very much needed, for example,
when memory is sufficient, because it increases the delays of COW for
user applications and also consume extra cpu resource. Besides, the fixed
pages_to_scan is not always good. When there are a lot of same pages,
the default pages_to_scan makes ksmd so slow to merge them.

The four patches try to optimize the above two points with a auto mode.
It's a lightweight optimization to KSM, not like uksm or pksm and so on.

The tests show:
	The convergence time of merging time of auto-mode reduces can low to
	HALF of normal-mode. The cpu consumption of auto-mode also get less
	than normal-mode.

There are two type of TEST which have different shape of samepage areas.
One is full-samepages vm areas, and the other is sparse-samepage areas.
Both of the madvise area'size are 300MB.

Here is test log:
****************** TEST 1 ******************
Now the shape of memory area is full-samepages:
[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx]

Start to test normal-run ksmd...
ksm current cpu total slice: 15274
ksm normal-run's merging time: 45.596018 seconds
ksm current cpu total slice: 16370
Start to test auto-run ksmd...
ksm auto-run's merging time: 17.599391 seconds
ksm current cpu total slice: 16488

****************** TEST 2 ******************
Now the shape of memory area is sparse-samepages:
[xx]          [xx]          [xx]   

Start to test normal-run ksmd...
ksm current cpu total slice: 16532
ksm normal-run's merging time: 21.625451 seconds
ksm current cpu total slice: 16833
Start to test auto-run ksmd...
ksm auto-run's merging time: 17.684379 seconds
ksm current cpu total slice: 16950

Change log
==========
for v2:
	1. We adjust the scan-enhanced algorithm, abstract its implementation
	into a single function, which is clearer and smoother.
	2. Add tests of auto-mode of ksm to verify the effectiveness.

xu xin (5):
  ksm: add a auto-run mode of ksm
  ksm: implement scan-enhanced algorithm
  ksm: let ksmd auto-work with memory threshold
  ksm: show ksmd status for auto mode
  ksm: add tests of ksm auto mode

 mm/ksm.c                                   | 250 ++++++++++++++++++-
 tools/testing/selftests/vm/.gitignore      |   1 +
 tools/testing/selftests/vm/Makefile        |   1 +
 tools/testing/selftests/vm/test-ksm-auto.c | 273 +++++++++++++++++++++
 4 files changed, 519 insertions(+), 6 deletions(-)
 create mode 100644 tools/testing/selftests/vm/test-ksm-auto.c