[Lguest] KSM in lguest?

Andrea Arcangeli aarcange at redhat.com
Sat Oct 26 02:35:39 EST 2013


Hi,

On Mon, Oct 21, 2013 at 02:32:24PM +1030, Rusty Russell wrote:
> Rusty Russell <rusty at rustcorp.com.au> writes:
> 
> > Earlence Fernandes <earlenceferns at gmail.com> writes:
> >> What needs to be changed in lguest to enable samepage merging?
> >> Does KSM make sense for lguest? (I would think so)
> >>
> >> If such a patch is needed, I'll be happy to conribute it.
> >
> > It's possible, but it's probably the trickiest TODO in lguest.
> >
> > We currently have a very naive system which pins pages when in use by
> > the guest, and we discard that under memory pressure.  I believe that
> > this will cause KSM not to function.
> >
> > The correct method is to use register_mmu_notifier.  See virt/kvm/ for
> > how it is used.

Correct, to use KSM you should not pin the pages and you should use
the mmu_notifier instead. Immediately after gup_fast returns you
should put_page (I soon need to introduce gup_flags in gup_fast to
avoid that terribly annoying atomic_inc that forces the put_page then,
I mean to avoid implying FOLL_GET).

Then the host will not just do KSM for you but it will also handle
swap, zswap, NUMA balancing, khugepaged transhuge page collapsing,
page migration during memory compaction, and numad using cpuset and
cgroup to do dynamic numa placement from userland algorithms.

All critical VM features depends on mmu notifier to work. Specifically
for KSM you also need to remember your userland to run
madvise(MADV_MEGEABLE) on the virtual memory range hosting the guest
physical memory.

Thanks,
Andrea


More information about the Lguest mailing list