KVM: X86: Optimize pte_list_desc with per-array counter
authorPeter Xu <peterx@redhat.com>
Fri, 30 Jul 2021 22:06:02 +0000 (18:06 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 4 Aug 2021 09:55:56 +0000 (05:55 -0400)
commit13236e25ebab91b3e42ddedf5354b569ace1b555
treef9ec9b4ff7beda994cbd901c317abccc4878b9b8
parentdc1cff969101afd08601e90463b44bd572e62dd4
KVM: X86: Optimize pte_list_desc with per-array counter

Add a counter field into pte_list_desc, so as to simplify the add/remove/loop
logic.  E.g., we don't need to loop over the array any more for most reasons.

This will make more sense after we've switched the array size to be larger
otherwise the counter will be a waste.

Initially I wanted to store a tail pointer at the head of the array list so we
don't need to traverse the list at least for pushing new ones (if without the
counter we traverse both the list and the array).  However that'll need
slightly more change without a huge lot benefit, e.g., after we grow entry
numbers per array the list traversing is not so expensive.

So let's be simple but still try to get as much benefit as we can with just
these extra few lines of changes (not to mention the code looks easier too
without looping over arrays).

I used the same a test case to fork 500 child and recycle them ("./rmap_fork
500" [1]), this patch further speeds up the total fork time of about 4%, which
is a total of 33% of vanilla kernel:

        Vanilla:      473.90 (+-5.93%)
        3->15 slots:  366.10 (+-4.94%)
        Add counter:  351.00 (+-3.70%)

[1] https://github.com/xzpeter/clibs/commit/825436f825453de2ea5aaee4bdb1c92281efe5b3

Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20210730220602.26327-1-peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/mmu.c