From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: KVM architecture docs Date: Wed, 05 Mar 2008 08:58:48 +0200 Message-ID: <47CE44A8.4030509@qumranet.com> References: <47CC1E91.7050207@sintesi80.it> <47CC421F.5070003@qumranet.com> <47CD0769.6020104@qumranet.com> <47CD14B6.9010908@qumranet.com> <90eb1dc70803040617j3590c52bj3d77a327143bda5f@mail.gmail.com> <47CD6601.5050907@qumranet.com> <47CE2D46.1030608@qumranet.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kvm-devel@lists.sourceforge.net, Javier Guerra To: Zhao Forrest Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org Zhao Forrest wrote: >>> Normally swapping mechanism choose the Least Recently Used(LRU) pages >>> of a process to be swapped out. When KVM uses MMU notifier in linux >>> kernel to implement swapping for VM, could KVM choose LRU pages of a >>> VM to swap out? If so, could you give a brief description about how >>> this is implemented? >>> >>> >> The Linux memory manager approximates LRU by scanning pages for the >> accessed bit, which is set in the pte by the processor when a page is >> accessed through that pte. mmu notifiers provide a callback for the >> check, so that kvm can check the accessed bit on the shadow ptes. >> > > Linux kernel maintains a reverse mapping from a page frame to all page tables > pointing to this page frame. Does KVM need to maintain a similar reverse mapping > from a page frame to all shadow page tables pointing to this page frame? > Yes, look for 'rmap' in mmu.c. The purpose was initially to be able to write-protect shadowed guest page tables without horrible worst-case performance, and was later extended to swapping. With mmu notifiers, when the kernel swaps a page, it first scans its own rmap, then calls kvm which scans the kvm rmap. So one way to look at mmu notifiers is as rmap extenders (that's not the whole story -- kvm ptes are in a different format than Linux ptes, so the code has to be different). -- Do not meddle in the internals of kernels, for they are subtle and quick to panic. ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/