Skip to contentSkip to conversation

KSM: allow dedup all tasks memory

PATCH New Timofey Titovets 1 participant 1 message Nov 13, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 KSM: allow dedup all tasks memory

ksm by default working only on memory that added by madvise().

And only way get that work on other applications:
* Use LD_PRELOAD and libraries
* Patch kernel

Lets use kernel task list and add logic to import VMAs from tasks.

That behaviour controlled by new attributes:
* mode:
I try mimic hugepages attribute, so mode have two states:
* madvise - old default behaviour
* always [new] - allow ksm to get tasks vma and try working on that.
* seeker_sleep_millisecs:
Add pauses between imports tasks VMA

For rate limiting proporses and tasklist locking time, ksm seeker thread only import VMAs from one task per loop.

Some numbers from different not madvised workloads. Formulas:
Percentage ratio = (pages_sharing - pages_shared)/pages_unshared Memory saved = (pages_sharing - pages_shared)*4/1024 MiB Memory used = free -h

* Name: My working laptop

    Description: Many different chrome/electron apps + KDE
    Ratio: 5%
    Saved: ~100  MiB
    Used:  ~2000 MiB

* Name: K8s test VM

    Description: Some small random running docker images
    Ratio: 40%
    Saved: ~160 MiB
    Used:  ~920 MiB

* Name: Ceph test VM

    Description: Ceph Mon/OSD, some containers
    Ratio: 20%
    Saved: ~60 MiB
    Used:  ~600 MiB

* Name: BareMetal K8s backend server

    Description: Different server apps in containers C, Java, GO & etc
    Ratio: 72%
    Saved: ~5800 MiB
    Used:  ~35.7 GiB

* Name: BareMetal K8s processing server

    Description: Many instance of one CPU intensive application
    Ratio: 55%
    Saved: ~2600 MiB
    Used:  ~28.0 GiB

* Name: BareMetal Ceph node

    Description: Only OSD storage daemons running
    Raio: 2%
    Saved: ~190 MiB
    Used:  ~11.7 GiB

Changes:
v1 -> v2:
* Rebase on v4.19.1 (must also apply on 4.20-rc2+)
v2 -> v3:
* Reformat patch description
* Rename mode normal to madvise
* Add some memory numbers
* Separate ksm vma seeker to another kthread
* Fix: "BUG: scheduling while atomic: ksmd" by move seeker to another thread
v3 -> v4:
* Fix again "BUG: scheduling while atomic" by get()/put() task API
* Remove unused variable "error"

CC Matthew Wilcox <[email protected]>
CC Oleksandr Natalenko <[email protected]>
CC Pavel Tatashin <[email protected]>
---
 Documentation/admin-guide/mm/ksm.rst |  15 ++
 mm/ksm.c                             | 217 +++++++++++++++++++++++----
 2 files changed, 200 insertions(+), 32 deletions(-)
Documentation/admin-guide/mm/ksm.rst +15 -0
index 9303786632d1..7cffd47f9b38 100644
@@ -116,6 +116,21 @@ run
         Default: 0 (must be changed to 1 to activate KSM, except if
         CONFIG_SYSFS is disabled)
 
+mode
+        * set always to allow ksm deduplicate memory of every process
+        * set madvise to use only madvised memory
+
+        Default: madvise (dedupulicate only madvised memory as in
+        earlier releases)
+
+seeker_sleep_millisecs
+        how many milliseconds ksmd task seeker should sleep try another
+        task.
+        e.g. ``echo 1000 > /sys/kernel/mm/ksm/seeker_sleep_millisecs``
+
+        Default: 1000 (chosen for rate limit purposes)
+
+
 use_zero_pages
         specifies whether empty pages (i.e. allocated pages that only
         contain zeroes) should be treated specially.  When set to 1,
mm/ksm.c +185 -32

286 lines not on this page · raw message

Signature · 1 line
2.19.1