From mboxrd@z Thu Jan 1 00:00:00 1970 From: Izik Eidus Subject: Re: KSM Algorithm Date: Thu, 10 Jul 2008 05:44:30 -0500 Message-ID: <4875E80E.3020305@qumranet.com> References: <4875D47E.603@qumranet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org To: Sukanto Ghosh Return-path: Received: from mis011-1.exch011.intermedia.net ([64.78.21.128]:6135 "EHLO mis011-1.exch011.intermedia.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752751AbYGJKov (ORCPT ); Thu, 10 Jul 2008 06:44:51 -0400 In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: =D7=A6=D7=99=D7=98=D7=95=D7=98 Sukanto Ghosh: >>> Are every guest pages scanned in KVM while using KSM or page-scanni= ng >>> and sharing is triggered on some event (low memory, etc) ? >>> >>> =20 >> no, the scanning run all the time (with number pages to scan and sle= ep >> parameters...) >> =20 > > Does the scanner(s) run as separate kernel threads ?\ > =20 it can run as kernel thread / or by ioctl runing from userspace > > =20 >>> Is sharing done only between the pages which have been registered v= ia >>> KSM_REGISTER_MEMORY_REGION ? >>> >>> =20 >> yes >> >> =20 >>> What are these for ? KSM_CREATE_SHARED_MEMORY_AREA and KSM_CREATE_S= CAN ? >>> >>> =20 >> KSM_CREATE_SHARED_MEMORY_AREA - to register memory area to be scanne= d for >> identical pages >> KSM_CREATE_SCAN - to create the scanner that scan for this pages >> =20 > > > So kvm will create a scanner using KSM_CREATE_SCAN ioctl to /dev/ksm. > kvm sets its parameters which specify the frequency of scan operation= =2E > Then, it tries to determine periodically from the shadow page tables > about the guest memory region, and registers them with the /dev/ksm. > The scanner as configured will scan the registered areas and will > create COW shared pages for identical pages. > Am I right ? > =20 yea > Doesn't KSM notifies KVM about the shared pages so that KVM can updat= e > its sptes accordingly or is it done by KSM itself ? > =20 when using kvm, mmu notifiers is a must for ksm, (mmu notifiers update=20 kvm about the changes in the host page table) > What about KSM being used by someone other than KVM ? Does KSM update= s > the ptes of the shared pages itself ? > =20 it can be used by any application, it update the ptes of the host, what= =20 you mean by the shared pages itself? > > =20 >>> Where are the shared pages kept ? In kernel memory ? Aren't the sha= red >>> pages always pinned in RAM (due to same reasons for pinned shadowed >>> pages) ? >>> >>> =20 >> in the version that was sent to the list it was kernel memory (meani= ng >> shared pages are not swappable >> (just the pages that are shared not the pages that we scan, when the= y are >> split beacuse of copy on write it become swappable again >> new version that i will send soon the pages are normal anonymous/use= rspace >> memory that is swappable >> >> =20 > > What is the strategy/method which you will use to represent the share= d > memory as normal anonymous/userspace memory ? Then, these pages must > be staying at one of the guest's address-space (whose pages have been > =20 > shared) ? > =20 it possible due to another patch that i need to send, that allow module= s=20 register new reverse mapping call backs..., > > =20 >>> How much is the overhead involved due to this ? >>> >>> =20 >> depeand on the speed you tell it to scan, but the overhead is about = ~5% for >> common cases >> =20 > > Can I know the typical values of the parameters : sleep time, no. of > pages to scan, which you used to arrive at the above mentioned > overhead. > =20 i think it is about 256 2000 (256 pages per 2000 usleep) (note that most of the cpu is acutlay taken by the copying of the pages= =20 when a new shared page is created, i have possible way to change it and= =20 reduce the cpu even more but i dont know if i want to do it) (it add more IFs to the fast path=20 inside the mm) > > =20