public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
	LKML <linux-kernel@vger.kernel.org>,
	kvm@vger.kernel.org
Subject: Re: [PATCH] kvm cleanup: Introduce sibling_pte and do cleanup for reverse map and parent_pte
Date: Tue, 03 Aug 2010 09:51:25 +0300	[thread overview]
Message-ID: <4C57BC6D.8060306@redhat.com> (raw)
In-Reply-To: <4C577F45.9030208@cn.fujitsu.com>

  On 08/03/2010 05:30 AM, Lai Jiangshan wrote:
> This patch is just a big cleanup. it reduces 220 lines of code.
>
> It introduces sibling_pte array for tracking identical sptes, so the
> identical sptes can be linked as a single linked list by their
> corresponding sibling_pte. A reverse map or a parent_pte points at
> the head of this single linked list. So we can do cleanup for
> reverse map and parent_pte VERY LARGELY.
>
> BAD:
>    If most rmap have only one entry or most sp have only one parent,
>    this patch may use more memory than before.

That is the case with NPT and EPT.  Each page has exactly one spte 
(except a few vga pages), and each sp has exactly one parent_pte (except 
the root pages).

> GOOD:
>    1) Reduce a lot of code, The functions which are in hot path becomes
>       very very simple and terrifically fast.
>    2) rmap_next(): O(N) ->  O(1). traveling a ramp: O(N*N) ->  O(N)

The existing rmap_next() is not O(N), it's O(RMAP_EXT), which is 4.  The 
data structure was chosen over a simple linked list to avoid extra cache 
misses.

>    3) Remove the ugly interlayer: struct kvm_rmap_desc, struct kvm_pte_chain

kvm_rmap_desc and kvm_pte_chain are indeed ugly, but they do save a lot 
of memory and cache misses.

>    4) We don't need to allocate any thing when we change the mappings.
>       So we can avoid allocation when we have held kvm mmu spin lock.
>       (this feature is very helpful in future).
>    5) better readability.

I agree the new code is more readable.  Unfortunately it uses more 
memory and is likely to be slower.  You add a cache miss for every spte, 
while kvm_rmap_desc amortizes the cache miss among 4 sptes, and special 
cases 1 spte to have no cache misses (or extra memory requirements).

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


  reply	other threads:[~2010-08-03  6:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-03  2:30 [PATCH] kvm cleanup: Introduce sibling_pte and do cleanup for reverse map and parent_pte Lai Jiangshan
2010-08-03  6:51 ` Avi Kivity [this message]
2010-08-03  8:59   ` Lai Jiangshan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C57BC6D.8060306@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox