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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46B00C433EF for ; Fri, 22 Jul 2022 20:59:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53DBE6B0072; Fri, 22 Jul 2022 16:59:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EA8E6B0073; Fri, 22 Jul 2022 16:59:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 38B436B0074; Fri, 22 Jul 2022 16:59:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 29E746B0072 for ; Fri, 22 Jul 2022 16:59:05 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 02E5BC0D9B for ; Fri, 22 Jul 2022 20:59:04 +0000 (UTC) X-FDA: 79715950650.30.582A42B Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf09.hostedemail.com (Postfix) with ESMTP id 878371400A2 for ; Fri, 22 Jul 2022 20:59:04 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id 12so5109706pga.1 for ; Fri, 22 Jul 2022 13:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=sRtc60bVHDuSQyy9YfLGbb/EZRQBkQQyTX+neLttrJI=; b=VT9WZjGGoaYO6wyINeAk1IALZT19I8nvGaJlOLvSTsMGMXO2aI48bLngF7CtjZAvoY Nk4dj0ETYHZSQT86zOPNHYg7GeO54xGWEIJhFv/C0BrBO+t5mqhus74Y4xbk+8fyul8M HfArgcswQSvdoHC84nrbwn2mXJxz+9qFiCBQ69YkVOPUHk9BdnilnJfVEOdrt3RS3CJ4 +mBwVu+wySOMJ/nQcZ/3u7v3umsb304sjJE7eni7WKU27HJWuFzI6grkrasDGOuFewyR 5YIPM89seaz3zWvRqyMCiwRGPEmx5/kbjcwH21G8dckWuQ/kFANi+7LycZSgyao947dV do6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=sRtc60bVHDuSQyy9YfLGbb/EZRQBkQQyTX+neLttrJI=; b=qFjWenw7J7aBX5UVj0c2+5+G8ZzXPu8tA7/qg7eA6cJGcWcgz5VOJpKV+0cvT3y9un jZwIGwPEF+Ay+mO3KCVeUJPE+fG25pgKTw/yEkUUfM7RocJNPKOZB/bU86j1NtQrW6AV bcErDsnmImJsh+4bz1LZHjkuLh/Gi/0YyUUcUCPbySNoVeqKq388UUlRhUn1xYCteqyF 8U1R7W/RAk9MK2sW3gVF4tD5I4qVPIX8jcGhqnKi30O0wyyuTv7gNJgQZmtyRAicXKko fL4hTb4gU6tgNCIztFj06Me1edPiWwTDgfRCqqSvZB58Avlb19r127RiLURZ/Q3wOsJv jbMA== X-Gm-Message-State: AJIora9DQXIQYDq6b/fSw4S0ZC0MjUsh2qh/q0aph/xrz8LFVesONaCA eb/rQc/tKSsvbvqhNo0gkspGOA== X-Google-Smtp-Source: AGRyM1tTvyJodPHKaLxzuJZFM95uuASDg1Sh5BgVVmp6RF38yEdu4iqgj2c7B6w9K0El2nFlSq1YJQ== X-Received: by 2002:a63:6a45:0:b0:419:cb1b:891b with SMTP id f66-20020a636a45000000b00419cb1b891bmr1367197pgc.135.1658523543280; Fri, 22 Jul 2022 13:59:03 -0700 (PDT) Received: from google.com (59.39.145.34.bc.googleusercontent.com. [34.145.39.59]) by smtp.gmail.com with ESMTPSA id d26-20020a634f1a000000b004088f213f68sm3893786pgb.56.2022.07.22.13.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 13:59:02 -0700 (PDT) Date: Fri, 22 Jul 2022 20:58:59 +0000 From: Mingwei Zhang To: Yosry Ahmed Cc: Tejun Heo , Johannes Weiner , Zefan Li , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andrew Morton , Michal Hocko , Roman Gushchin , Shakeel Butt , Oliver Upton , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v4 3/4] KVM: x86/mmu: count KVM mmu usage in secondary pagetable stats. Message-ID: References: <20220429201131.3397875-1-yosryahmed@google.com> <20220429201131.3397875-4-yosryahmed@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220429201131.3397875-4-yosryahmed@google.com> ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=VT9WZjGG; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of mizhang@google.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=mizhang@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658523544; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sRtc60bVHDuSQyy9YfLGbb/EZRQBkQQyTX+neLttrJI=; b=uMKEtaTtYpGFT/ChwYiX5A5ZmVjTQK+iRdUw/MPP0xx03XmlNpfUC9gLbQmb6Hu6slwW1y IhIbeZm9129zk9UZp+g6yciV24MorZL6Aga0cOVL7SKPeeLVykxPNg3y4Y0aVzhyR0hdAa EJPVgG6OadhgmZprtX3xGkuF7kfkN88= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658523544; a=rsa-sha256; cv=none; b=nLbHJErRhZBPjHxdt66DGtsVHe0dMOh7MGzYOrT8xYdoNuqrrTsEXJsUW0caZQr7+cPFyP mS+PNEvTpzQ+dqscq6CKvm146KNBaG66HFQSMMb9q934ZSKABePiy43u6WZPU86XwP10zB BQLApngBDp+QwkM0BD4yACUA0Dp6R0Y= X-Rspam-User: X-Stat-Signature: 3qomdhuz8ok6nmcok9wwuuanc7xf981n X-Rspamd-Queue-Id: 878371400A2 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=VT9WZjGG; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of mizhang@google.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=mizhang@google.com X-Rspamd-Server: rspam04 X-HE-Tag: 1658523544-440705 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Apr 29, 2022, Yosry Ahmed wrote: > Count the pages used by KVM mmu on x86 for in secondary pagetable stats. > > For the legacy mmu, accounting pagetable stats is combined KVM's > existing for mmu pages in newly introduced kvm_[un]account_mmu_page() > helpers. > > For tdp mmu, introduce new tdp_[un]account_mmu_page() helpers. That > combines accounting pagetable stats with the tdp_mmu_pages counter > accounting. > > tdp_mmu_pages counter introduced in this series [1]. This patch was > rebased on top of the first two patches in that series. > > [1]https://lore.kernel.org/lkml/20220401063636.2414200-1-mizhang@google.com/ > > Signed-off-by: Yosry Ahmed > --- It looks like there are two metrics for mmu in x86: one for shadow mmu and the other for TDP mmu. Is there any plan to merge them together? > arch/x86/kvm/mmu/mmu.c | 16 ++++++++++++++-- > arch/x86/kvm/mmu/tdp_mmu.c | 16 ++++++++++++++-- > 2 files changed, 28 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 78d8e1d8fb99..e5b0e826445d 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -1679,6 +1679,18 @@ static inline void kvm_mod_used_mmu_pages(struct kvm *kvm, long nr) > percpu_counter_add(&kvm_total_used_mmu_pages, nr); > } > > +static void kvm_account_mmu_page(struct kvm *kvm, struct kvm_mmu_page *sp) > +{ > + kvm_mod_used_mmu_pages(kvm, +1); > + kvm_account_pgtable_pages((void *)sp->spt, +1); > +} > + > +static void kvm_unaccount_mmu_page(struct kvm *kvm, struct kvm_mmu_page *sp) > +{ > + kvm_mod_used_mmu_pages(kvm, -1); > + kvm_account_pgtable_pages((void *)sp->spt, -1); > +} > + > static void kvm_mmu_free_page(struct kvm_mmu_page *sp) > { > MMU_WARN_ON(!is_empty_shadow_page(sp->spt)); > @@ -1734,7 +1746,7 @@ static struct kvm_mmu_page *kvm_mmu_alloc_page(struct kvm_vcpu *vcpu, int direct > */ > sp->mmu_valid_gen = vcpu->kvm->arch.mmu_valid_gen; > list_add(&sp->link, &vcpu->kvm->arch.active_mmu_pages); > - kvm_mod_used_mmu_pages(vcpu->kvm, +1); > + kvm_account_mmu_page(vcpu->kvm, sp); > return sp; > } > > @@ -2363,7 +2375,7 @@ static bool __kvm_mmu_prepare_zap_page(struct kvm *kvm, > list_add(&sp->link, invalid_list); > else > list_move(&sp->link, invalid_list); > - kvm_mod_used_mmu_pages(kvm, -1); > + kvm_unaccount_mmu_page(kvm, sp); > } else { > /* > * Remove the active root from the active page list, the root > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > index 3456277ade18..6295c4da5dee 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.c > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > @@ -371,6 +371,18 @@ static void handle_changed_spte_dirty_log(struct kvm *kvm, int as_id, gfn_t gfn, > } > } > > +static void tdp_account_mmu_page(struct kvm *kvm, struct kvm_mmu_page *sp) > +{ > + atomic64_inc(&kvm->arch.tdp_mmu_pages); > + kvm_account_pgtable_pages((void *)sp->spt, +1); > +} > + > +static void tdp_unaccount_mmu_page(struct kvm *kvm, struct kvm_mmu_page *sp) > +{ > + atomic64_dec(&kvm->arch.tdp_mmu_pages); > + kvm_account_pgtable_pages((void *)sp->spt, -1); > +} > + > /** > * tdp_mmu_unlink_sp() - Remove a shadow page from the list of used pages > * > @@ -383,7 +395,7 @@ static void handle_changed_spte_dirty_log(struct kvm *kvm, int as_id, gfn_t gfn, > static void tdp_mmu_unlink_sp(struct kvm *kvm, struct kvm_mmu_page *sp, > bool shared) > { > - atomic64_dec(&kvm->arch.tdp_mmu_pages); > + tdp_unaccount_mmu_page(kvm, sp); > > if (!sp->lpage_disallowed) > return; > @@ -1121,7 +1133,7 @@ static int tdp_mmu_link_sp(struct kvm *kvm, struct tdp_iter *iter, > tdp_mmu_set_spte(kvm, iter, spte); > } > > - atomic64_inc(&kvm->arch.tdp_mmu_pages); > + tdp_account_mmu_page(kvm, sp); > > return 0; > } > -- > 2.36.0.464.gb9c8b46e94-goog >