Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp4032323pxt; Tue, 10 Aug 2021 18:10:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVuxK4JSQ2FRByRi4vPzxw1I5X3u+UkwYIHi+fWkjXN5VHKrvPpH6znsnCZJtfGCPAhFtZ X-Received: by 2002:a05:6402:550:: with SMTP id i16mr8291649edx.177.1628644236630; Tue, 10 Aug 2021 18:10:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628644236; cv=none; d=google.com; s=arc-20160816; b=wzNTDv0npdCvfEaXtguXY5pOapxFkS/WFTjjnv3Y7wqI/VkPN5Scn1e5paFg5LYRfx Z0zJLjz/J0ENHhED3d51BZNmwxU0dLo6FUYVWxAGIGXR1o9jOv+Sne3uFQm1NRLm05XD TbDRcZa1zXB8F32kbjDl55jM8yDhwZusp2QMqK8wxVQ/XqZdW9CknMgZLWIp2ig+Mqja A87V2X0yJH1oMr0bGcN0gzzNrl8yXh+6dVtrfAEqUm5Qs3EZMHFEN5wnL1Id9NtYe1z+ 5bcKVCzApGd0e6VDQHa7DkSzwZtahRNmuM2sdBZhZGmFS9B7Vqg0miN7eFX5UAD0eoe4 gTEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=a2EnmaKuDExlU8XnGG3RzNSaMcnDIxhrZpe2LhsoZ6U=; b=XZc+0zXrJ5190/+VZgFMUuFYerTToga0GscqGgmS3+z/rkszr739m/iqK/E56OSQP/ LOQGIwnZimhAf2mwBsuWP2HkWu2JAHe9Nr5p0d8c1eYRHfRQD/zCA3b7D6v/xpzTegZ5 HCDebSXM9/IOfm96YP36AqvLvHueKy/MMktbj4CM5NlfEdKPRPd6qclNe6PaxuLTHou0 zrMi3jCYVaL1Bc5eM0AHbaCe78D5KiaP39HItFph0N+zJyTiIXrDIcQuOnmeJeCdcsaq BfhRE7uQgnBtXEcNKbSM9wIQIQ+EuiiRTcTz4kHSEnk0ltoYnfx8EJUR9bk0JgsqtkvX Dtcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=D+iac3Bl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b88si13786886edf.358.2021.08.10.18.10.11; Tue, 10 Aug 2021 18:10:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=D+iac3Bl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236096AbhHKBH0 (ORCPT + 99 others); Tue, 10 Aug 2021 21:07:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235897AbhHKBH0 (ORCPT ); Tue, 10 Aug 2021 21:07:26 -0400 Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8F9CC0613D3 for ; Tue, 10 Aug 2021 18:07:03 -0700 (PDT) Received: by mail-yb1-xb29.google.com with SMTP id w17so1322093ybl.11 for ; Tue, 10 Aug 2021 18:07:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=a2EnmaKuDExlU8XnGG3RzNSaMcnDIxhrZpe2LhsoZ6U=; b=D+iac3BlDRd6s0yv+eLa06H+mhkklWKygguLtLbE9OuiaDc+/UyKG+rXsHuab5RuoC CsCc/0sFilzc9MaswCDRBsmqTtHlY9MRKXDRRbJCePew7jTeU+5AWO/DOuo3PQ1QpPq6 H8EINzcA6L2OyDF1Ca9LDszPDOdjNPA3lUG3IxVfZcFGS6oTnDdxQCe6vinuPjcrFPfy 3hcidiDyzHza4QxKwz/MTFk+rlSo4K06JRizz7yldoCmRlgk2mVtGcuPl5V8HRCIxdaw DW1XkVCypHjfAzeZqxtKNjPXwfdqnrwGnlLQkscZgq6py40eCQmzF6qotvBS0vvTFqcs cpwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=a2EnmaKuDExlU8XnGG3RzNSaMcnDIxhrZpe2LhsoZ6U=; b=EhcZh3rhWEbLPmoC1nf+b1ZeV/A8ofZhv0xyeaazhsNdisDAMI+RnZX7WHY7DLETNf kuDH5vbP6fInZJBKlpfyzyJDc0KI4Uw7ZC005eICqsoWGQEapOQEIc389L5AEc2v2g8j 7hmkwNYxgGIuwfcTKU4I0OmwblbCAwAodXHHZavKbB3qqjMIkH6a0Pkyf7Sq67zAG14M eH55+F/1k37HOcTEpQrZFox5lJBMiptuIMrRwvc4Y0DmXNIFvbnMX0I9zkHuiujsfRIj cHumDFz1q9ZNV3DHpK+XoZGHIpcJPweJ8jzlHwKYJUXvEcP2KHMCfdh+qQ0nmKmV6Jsw rY6g== X-Gm-Message-State: AOAM533MoNrVcJ2XEWKm/6R11SyC7D/dMkQlq7F+xEJxamFWMC2GIbEV SEpDgmjJJQT9svslv+4eKHuagyiJf14wx7DnDr+2b21e6hgU2g== X-Received: by 2002:a25:f503:: with SMTP id a3mr40167717ybe.501.1628644022703; Tue, 10 Aug 2021 18:07:02 -0700 (PDT) MIME-Version: 1.0 References: <20210803044607.599629-1-mizhang@google.com> <20210803044607.599629-4-mizhang@google.com> In-Reply-To: From: Mingwei Zhang Date: Tue, 10 Aug 2021 18:06:51 -0700 Message-ID: Subject: Re: [PATCH v4 3/3] KVM: x86/mmu: Add detailed page size stats To: Peter Xu Cc: Jim Mattson , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , kvm , LKML , Ben Gardon , David Matlack , Jing Zhang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peter, Thanks for the comments. Please check my feedback inline. > > From a functionality point of view, the above patch seems duplicate > > with mine. > > The rmap statistics are majorly for rmap, not huge pages. > Got you. I guess the focus of the stat is different. > > I have a question: why change to using atomic ops? As most kvm statistic= s > seems to be not with atomics before. > > AFAIK atomics are expensive, and they get even more expensive when the ho= st is > bigger (it should easily go into ten-nanosecond level). So I have no ide= a > whether it's worth it for persuing that accuracy. > > Thanks, Yes, regarding the usage of 'atomic_t', we previously had discussions internally with Sean. So I think the main reason is because: in KVM currently, mmu may have several modes. Among them, one is the mmu running with TDP enabled (say, legacy mode in this scope) and another one is the TDP mmu mode (mmu/tdp_mmu.c). In the legacy mode, mmu will update spte under a write lock, while in comparison, in the TDP MMU mode, mmu will use a read lock. I copied a simple code snippet to illustrate the situation: =C2=BB.......if (is_tdp_mmu_fault) =C2=BB.......=C2=BB.......read_lock(&vcpu->kvm->mmu_lock); =C2=BB.......else =C2=BB.......=C2=BB.......write_lock(&vcpu->kvm->mmu_lock); So here comes the problem: how do we make the page stat update correctly across all modes? For the latter case, we definitely have to update the stat in an atomic way unless we want extra locking (we don't want that). So we could either 1) use a branch to update the stat differently for each mode or 2) use an atomic update across all cases. After review, Sean mentioned (in pre-v1 internal review) that we should just use atomic. I agree since adding a branch at such a hot path may slow down even more globally, especially if there is branch misprediction? But I appreciate your feedback as well. Regarding the pursuit for accuracy, I think there might be several reasons. One of the most critical reasons that I know is that we need to ensure dirty logging works correctly, i.e., when dirty logging is enabled, all huge pages (both 2MB and 1GB) _are_ gone. Hope that clarifies a little bit? Thanks. -Mingwei -Mingwei > > -- > Peter Xu >