From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-25.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F835C432BE for ; Wed, 28 Jul 2021 21:01:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 80E9D6101C for ; Wed, 28 Jul 2021 21:01:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231734AbhG1VBc (ORCPT ); Wed, 28 Jul 2021 17:01:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231666AbhG1VB2 (ORCPT ); Wed, 28 Jul 2021 17:01:28 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD85EC061757 for ; Wed, 28 Jul 2021 14:01:25 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id m1so7092867pjv.2 for ; Wed, 28 Jul 2021 14:01:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=FJEdJNA4sywUWglVLwn78S3p+lPMZ01rTY+4k5h2Png=; b=vM44vlNslYWPbrjWIUu3iZFP6177zbLGeg6hyqrWdrVuDIZbAVbau4oMY3s6yBUNag cAWhQkel7/cgeaXF3reLPEscphuVuKsHMJB303I8gNYS5XZBHLxst+dWkokgP2eoW9tl RRcSnX2yLFCeOTUfLqSdMOEDr/avbk8h+vsooe3UpIAQ56O6b6/ThWXRMPf4Rc4fZCOp euc3dkrMYRfyP0IgN9H2ymWsJeGaaoSXkEpeCAKuSSFd8YFfLUEj5aHwJfggS1bjlBVA Rrkd2MaQIr4jgEQtyeHXjj1RqfAxdMGDxGxwbGmUjUUl8qMsPBIJfUgwtyctiCRu6Ue/ os+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=FJEdJNA4sywUWglVLwn78S3p+lPMZ01rTY+4k5h2Png=; b=l/YKdSGD/FQWlrt5XkZzuBS56XB1Kae6wNmtOuorL9PnnNiLX9qWSKKEkgF+fnaA4P Xgbz77mYrLhEkKOPIAl2ja0hzZgjwBLhMfbGsJksitBKNBQ4U06kZE2sILHmgbSs7L9A 3n/gWluZal7kSnRkblTBSfCiXTRIDav3MzgKwTRhO+LW3mbK1MqlJcXbIPiZWDo8hr0u 5BhMmiq8vsX/Ykv6LS5aLzdHs+pedZ0CmIBPylcXmFQB3IjBJincobZGErQVACh+Tzve GfowGK5sy/i0VPqZ1LbQhvnhtRcHvWzoNdFoiryNwclUaaxGfK2OhRxRg8MroE32P+7j RvmQ== X-Gm-Message-State: AOAM533QVX2xToCw6MMbaizaawncqFjyX7CIORh+b2SkmvE8XTsPbUjV gWYZEkn28BVIdEE0SXs0/ZuDkA== X-Google-Smtp-Source: ABdhPJwx4GRnRHuDauI9xgKnOWibZNxddcRVd4P3ZBzKBS71Eqdi0J1GWpZUKB18NEIaKPOMp/cs9A== X-Received: by 2002:a17:902:ab88:b029:12b:d2ee:c26f with SMTP id f8-20020a170902ab88b029012bd2eec26fmr1549354plr.38.1627506085157; Wed, 28 Jul 2021 14:01:25 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id l2sm882101pfc.157.2021.07.28.14.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 14:01:24 -0700 (PDT) Date: Wed, 28 Jul 2021 21:01:20 +0000 From: Sean Christopherson To: Peter Xu Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Maxim Levitsky , Vitaly Kuznetsov , Paolo Bonzini Subject: Re: [PATCH v2 7/9] KVM: X86: MMU: Tune PTE_LIST_EXT to be bigger Message-ID: References: <20210625153214.43106-1-peterx@redhat.com> <20210625153413.43570-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210625153413.43570-1-peterx@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 25, 2021, Peter Xu wrote: > Currently rmap array element only contains 3 entries. However for EPT=N there > could have a lot of guest pages that got tens of even hundreds of rmap entry. > > A normal distribution of a 6G guest (even if idle) shows this with rmap count > statistics: > > Rmap_Count: 0 1 2-3 4-7 8-15 16-31 32-63 64-127 128-255 256-511 512-1023 > Level=4K: 3089171 49005 14016 1363 235 212 15 7 0 0 0 > Level=2M: 5951 227 0 0 0 0 0 0 0 0 0 > Level=1G: 32 0 0 0 0 0 0 0 0 0 0 > > If we do some more fork some pages will grow even larger rmap counts. > > This patch makes PTE_LIST_EXT bigger so it'll be more efficient for the general > use case of EPT=N as we do list reference less and the loops over PTE_LIST_EXT > will be slightly more efficient; but still not too large so less waste when > array not full. > > It should not affecting EPT=Y since EPT normally only has zero or one rmap > entry for each page, so no array is even allocated. > > With a test case to fork 500 child and recycle them ("./rmap_fork 500" [1]), > this patch speeds up fork time of about 22%. > > Before: 367.20 (+-4.58%) > After: 302.00 (+-5.30%) > > [1] https://github.com/xzpeter/clibs/commit/825436f825453de2ea5aaee4bdb1c92281efe5b3 > > Signed-off-by: Peter Xu > --- > arch/x86/kvm/mmu/mmu.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index b3f738a7c05e..9b093985a2ef 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -137,8 +137,8 @@ module_param(dbg, bool, 0644); > > #include > > -/* make pte_list_desc fit well in cache line */ > -#define PTE_LIST_EXT 3 > +/* make pte_list_desc fit well in cache lines */ > +#define PTE_LIST_EXT 15 Ha, I was going to say that this should be '14' to fit pte_list_desc within two cache lines, but looks like Paolo fixed it up on commit. Also, if the whole cache line thing actually matters, sptes[] and spte_count should be swapped since spte_count is always read, whereas spte_count[7:14] will be read iff there are 8+ SPTEs. > struct pte_list_desc { > u64 *sptes[PTE_LIST_EXT]; > -- > 2.31.1 >