[RFC PATCH 0/6] add defer mechanism to ksm to make it more suitable for Android devices

Wenwei Tao
2015-06-10T06:32:22Z

I observe that it is unlikely for KSM to merge new pages from an area
that has already been scanned twice on Android mobile devices, so it's
a waste of power to scan these areas in high frequency. In this patchset,
a defer mechanism is introduced which is borrowed from page compaction to KSM.

A new slot list called active_slot is added into ksm_scan. MMs which have
VMA marked for merging via madvise are added (MM is new to KSM) or moved to
(MM is in the ksm_scan.mm_slot list) active_slot. In "scan_get_next_rmap_item()",
the active_slot list will be scaned firstly unless it is empty, then the mm_slot list.
MMs in the active_slot list will be scaned twice, after that they will be moved
to mm_slot list. Once scanning the mm_slot list, the defer mechanism will be activated:

a) if KSM scans "ksm_thread_pages_to_scan" pages but none of them get
merged or become unstable, increase the ksm_defer_shift(new member of ksm_scan)
by one (no more than 6 by now). And in the next "1UL << ksm_scan.ksm_defer_shift"
times KSM been scheduled or woken up it will not do the actual scan, compare
and merge job, it just schedule out.

b) if KSM scans "ksm_thread_pages_to_scan" pages and more than zero of them
get merged or become unstable, reset the ksm_defer_shift and ksm_considered
to zero.

Some applications may continue to produce new mergeable VMAs to KSM, in order
to avoid scanning VMAs of these applications that have already been scanned twice,
we use VM_HUGETLB to indicate new mergeable VMAs since hugetlb vm are not
supported by KSM.

Wenwei Tao (6):
mm: add defer mechanism to ksm to make it more suitable
mm: change the condition of identifying hugetlb vm
perf: change the condition of identifying hugetlb vm
fs/binfmt_elf.c: change the condition of identifying hugetlb vm
x86/mm: change the condition of identifying hugetlb vm
powerpc/kvm: change the condition of identifying hugetlb vm

arch/powerpc/kvm/e500_mmu_host.c | 3 +-
arch/x86/mm/tlb.c | 3 +-
fs/binfmt_elf.c | 2 +-
include/linux/hugetlb_inline.h | 2 +-
include/linux/mempolicy.h | 2 +-
kernel/events/core.c | 2 +-
mm/gup.c | 6 +-
mm/huge_memory.c | 17 ++-
mm/ksm.c | 230 +++++++++++++++++++++++++++++++++-----
mm/madvise.c | 6 +-
mm/memory.c | 5 +-
mm/mprotect.c | 6 +-
12 files changed, 238 insertions(+), 46 deletions(-)

--
1.7.9.5