From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:50817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RwTa5-0004wq-Mw for qemu-devel@nongnu.org; Sun, 12 Feb 2012 02:10:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RwTa4-0006p4-G4 for qemu-devel@nongnu.org; Sun, 12 Feb 2012 02:10:41 -0500 Received: from mail-pz0-f45.google.com ([209.85.210.45]:42492) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RwTa4-0006ox-BQ for qemu-devel@nongnu.org; Sun, 12 Feb 2012 02:10:40 -0500 Received: by dadp14 with SMTP id p14so4154840dad.4 for ; Sat, 11 Feb 2012 23:10:38 -0800 (PST) Date: Sun, 12 Feb 2012 16:10:34 +0900 From: Takuya Yoshikawa Message-Id: <20120212161034.9d8f68df72f6c28298cdcd33@gmail.com> In-Reply-To: <4F313354.4080401@redhat.com> References: <4F2AB552.2070909@redhat.com> <4F2B41D6.8020603@codemonkey.ws> <51470503-DEE0-478D-8D01-020834AF6E8C@suse.de> <4F3117E5.6000105@redhat.com> <4F31241C.70404@redhat.com> <4F313354.4080401@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC] Next gen kvm api List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: Alexander Graf , KVM list , qemu-devel , kvm-ppc , linux-kernel Avi Kivity wrote: > > > Slot searching is quite fast since there's a small number of slots, and we sort the larger ones to be in the front, so positive lookups are fast. We cache negative lookups in the shadow page tables (an spte can be either "not mapped", "mapped to RAM", or "not mapped and known to be mmio") so we rarely need to walk the entire list. > > > > Well, we don't always have shadow page tables. Having hints for unmapped guest memory like this is pretty tricky. > > We're currently running into issues with device assignment though, where we get a lot of small slots mapped to real hardware. I'm sure that will hit us on x86 sooner or later too. > > For x86 that's not a problem, since once you map a page, it stays mapped > (on modern hardware). > I was once thinking about how to search a slot reasonably fast for every case, even when we do not have mmio-spte cache. One possible way I thought up was to sort slots according to their base_gfn. Then the problem would become: "find the first slot whose base_gfn + npages is greater than this gfn." Since we can do binary search, the search cost is O(log(# of slots)). But I guess that most of the time was wasted on reading many memslots just to know their base_gfn and npages. So the most practically effective thing is to make a separate array which holds just their base_gfn. This will make the task a simple, and cache friendly, search on an integer array: probably faster than using *-tree data structure. If needed, we should make cmp_memslot() architecture specific in the end? Takuya