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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65C86C32774 for ; Tue, 23 Aug 2022 00:05:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234240AbiHWAFj (ORCPT ); Mon, 22 Aug 2022 20:05:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238567AbiHWAFg (ORCPT ); Mon, 22 Aug 2022 20:05:36 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6581254CAE for ; Mon, 22 Aug 2022 17:05:35 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id bq11so8506020wrb.12 for ; Mon, 22 Aug 2022 17:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=qokcu5tCtpQLCQgO9pVTazHLwMpC9kMD5hOC340KS1I=; b=jBPLk8bHlDLGIvGVE4zL26EtBtv9avfUdg557Lw4E+XzpuWZRA6yrM8jemnayVxmTu HFUGMWr/PHR8LguRaK0GVi7w26Qnt3CxyVGcW0n7UF3R4pU31QDsJO6/jSpmu9xmtRvy GHEx+99kDAzCMm28iwalvBDKvUcqcKRg/skmcRT/eIrUVHr5GG/kBpafDR+G5cad3XCs SCh0iHzLtcfdouEA1DsVo0u8G4R8t2qE8/4a4DAj7CCMmsaTPR1R4XpS2cOFX5Kk+Ew+ PN7CoifI1ft5ccWK48IE5B74fHCM7d5LD91G37VfgpN9TcT7S+yGetYQj7xs0JO8WSdi opgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=qokcu5tCtpQLCQgO9pVTazHLwMpC9kMD5hOC340KS1I=; b=N4wUKS3C/Vg/qTCiWi7DnogmVWw66JrQ4BEOmMuGOrOtdsS4gW+U9rxHYYPZ3syKw7 5pk0yWds1TpJDQx3MzphK1MVkkgYREITpsQKOHwq+xhtxfDNKuI+8UAMuOoUmfXzrBEd M/J8bqdPyI6J+604A/Z18ADw6eCyVQ3Kq0G29VkVeZn7DR4QFZd/ajNUwCQ1REr9HdTZ dxI9pkOrEnR449FB/BBxqBJreutm12Xipw4ARsIqOVaatzmnJupypG+q7cqWTaS8d6Y1 oXrDwdWmvxhDi7VfGuF5GFbt/mlA9JmrQzqWVMiNkFGzv0lp7HhjhO1+TlvpUtcA6LMk ER/Q== X-Gm-Message-State: ACgBeo0zFsRDW0wKA2b8vvK57+9aMBq2sXx7RR7uH+IjHR/xQCCasGPM QDqngemXEnW1FzmoNQ/aR7KVEjgAbsh33r9lMLGubg== X-Google-Smtp-Source: AA6agR5Lo8c+tVx21B5A2il5HGzGcfxxCY5VNzyOQ8xHSFF9B9ZhcgyTcMW2pafj/S8owJMHXTCJIeOP/v9Ei+X67uo= X-Received: by 2002:a05:6000:1188:b0:220:6c20:fbf6 with SMTP id g8-20020a056000118800b002206c20fbf6mr12350055wrx.372.1661213133858; Mon, 22 Aug 2022 17:05:33 -0700 (PDT) MIME-Version: 1.0 References: <20220628220938.3657876-1-yosryahmed@google.com> <20220628220938.3657876-2-yosryahmed@google.com> <20220817102408.7b048f198a736f053ced2862@linux-foundation.org> In-Reply-To: From: Yosry Ahmed Date: Mon, 22 Aug 2022 17:04:57 -0700 Message-ID: Subject: Re: [PATCH v6 1/4] mm: add NR_SECONDARY_PAGETABLE to count secondary page table uses. To: Andrew Morton 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 , Michal Hocko , Roman Gushchin , Shakeel Butt , Oliver Upton , Huang@google.com, Shaoqin , Cgroups , Linux Kernel Mailing List , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Linux-MM Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 17, 2022 at 3:27 PM Yosry Ahmed wrote: > > On Wed, Aug 17, 2022 at 10:24 AM Andrew Morton > wrote: > > > > On Tue, 28 Jun 2022 22:09:35 +0000 Yosry Ahmed wrote: > > > > > We keep track of several kernel memory stats (total kernel memory, page > > > tables, stack, vmalloc, etc) on multiple levels (global, per-node, > > > per-memcg, etc). These stats give insights to users to how much memory > > > is used by the kernel and for what purposes. > > > > > > Currently, memory used by kvm mmu is not accounted in any of those > > > kernel memory stats. This patch series accounts the memory pages > > > used by KVM for page tables in those stats in a new > > > NR_SECONDARY_PAGETABLE stat. This stat can be later extended to account > > > for other types of secondary pages tables (e.g. iommu page tables). > > > > > > KVM has a decent number of large allocations that aren't for page > > > tables, but for most of them, the number/size of those allocations > > > scales linearly with either the number of vCPUs or the amount of memory > > > assigned to the VM. KVM's secondary page table allocations do not scale > > > linearly, especially when nested virtualization is in use. > > > > > > >From a KVM perspective, NR_SECONDARY_PAGETABLE will scale with KVM's > > > per-VM pages_{4k,2m,1g} stats unless the guest is doing something > > > bizarre (e.g. accessing only 4kb chunks of 2mb pages so that KVM is > > > forced to allocate a large number of page tables even though the guest > > > isn't accessing that much memory). However, someone would need to either > > > understand how KVM works to make that connection, or know (or be told) to > > > go look at KVM's stats if they're running VMs to better decipher the stats. > > > > > > Furthermore, having NR_PAGETABLE side-by-side with NR_SECONDARY_PAGETABLE > > > is informative. For example, when backing a VM with THP vs. HugeTLB, > > > NR_SECONDARY_PAGETABLE is roughly the same, but NR_PAGETABLE is an order > > > of magnitude higher with THP. So having this stat will at the very least > > > prove to be useful for understanding tradeoffs between VM backing types, > > > and likely even steer folks towards potential optimizations. > > > > > > The original discussion with more details about the rationale: > > > https://lore.kernel.org/all/87ilqoi77b.wl-maz@kernel.org > > > > > > This stat will be used by subsequent patches to count KVM mmu > > > memory usage. > > > > Nits and triviata: > > > > > --- a/Documentation/filesystems/proc.rst > > > +++ b/Documentation/filesystems/proc.rst > > > @@ -977,6 +977,7 @@ Example output. You may not have all of these fields. > > > SUnreclaim: 142336 kB > > > KernelStack: 11168 kB > > > PageTables: 20540 kB > > > + SecPageTables: 0 kB > > > NFS_Unstable: 0 kB > > > Bounce: 0 kB > > > WritebackTmp: 0 kB > > > @@ -1085,6 +1086,9 @@ KernelStack > > > Memory consumed by the kernel stacks of all tasks > > > PageTables > > > Memory consumed by userspace page tables > > > +SecPageTables > > > + Memory consumed by secondary page tables, this currently > > > + currently includes KVM mmu allocations on x86 and arm64. > > > > Something happened to the whitespace there. > > Yeah I have the fix for this queued for v7. Thanks! > > > > > > + "Node %d SecPageTables: %8lu kB\n" > > > ... > > > + nid, K(node_page_state(pgdat, NR_SECONDARY_PAGETABLE)), > > > > The use of "sec" in the user-facing changes and "secondary" in the > > programmer-facing changes is irksome. Can we be consistent? I'd > > prefer "secondary" throughout. > > > > SecondaryPageTables is too long (unfortunately), it messes up the > formatting in node_read_meminfo() and meminfo_proc_show(). I would > prefer "secondary" as well, but I don't know if breaking the format in > this way is okay. Any thoughts here Andrew? Change to SecondaryPageTables anyway? Change all to use "sec" instead of "secondary"? Leave as-is? > > This is what I mean by breaking the format btw (the numbers become misaligned): > > diff --git a/drivers/base/node.c b/drivers/base/node.c > index 5ad56a0cd593..4f85750a0f8e 100644 > --- a/drivers/base/node.c > +++ b/drivers/base/node.c > @@ -433,7 +433,7 @@ static ssize_t node_read_meminfo(struct device *dev, > "Node %d ShadowCallStack:%8lu kB\n" > #endif > "Node %d PageTables: %8lu kB\n" > - "Node %d SecPageTables: %8lu kB\n" > + "Node %d SecondaryPageTables: %8lu kB\n" > "Node %d NFS_Unstable: %8lu kB\n" > "Node %d Bounce: %8lu kB\n" > "Node %d WritebackTmp: %8lu kB\n" > diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c > index 208efd4fa52c..b7166d09a38f 100644 > --- a/fs/proc/meminfo.c > +++ b/fs/proc/meminfo.c > @@ -115,7 +115,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) > #endif > show_val_kb(m, "PageTables: ", > global_node_page_state(NR_PAGETABLE)); > - show_val_kb(m, "SecPageTables: ", > + show_val_kb(m, "SecondaryPageTables: ", > global_node_page_state(NR_SECONDARY_PAGETABLE)); > > show_val_kb(m, "NFS_Unstable: ", 0); 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 mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by smtp.lore.kernel.org (Postfix) with ESMTP id B432EC3F6B0 for ; Tue, 23 Aug 2022 00:05:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 079C34CE00; Mon, 22 Aug 2022 20:05:44 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BQOMzO3n6nYD; Mon, 22 Aug 2022 20:05:40 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 341334CE17; Mon, 22 Aug 2022 20:05:40 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 585AA4CE0E for ; Mon, 22 Aug 2022 20:05:39 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4MvWSfp6bAFq for ; Mon, 22 Aug 2022 20:05:35 -0400 (EDT) Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 0ADEE4CE00 for ; Mon, 22 Aug 2022 20:05:34 -0400 (EDT) Received: by mail-wr1-f47.google.com with SMTP id u5so7265720wrt.11 for ; Mon, 22 Aug 2022 17:05:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=qokcu5tCtpQLCQgO9pVTazHLwMpC9kMD5hOC340KS1I=; b=jBPLk8bHlDLGIvGVE4zL26EtBtv9avfUdg557Lw4E+XzpuWZRA6yrM8jemnayVxmTu HFUGMWr/PHR8LguRaK0GVi7w26Qnt3CxyVGcW0n7UF3R4pU31QDsJO6/jSpmu9xmtRvy GHEx+99kDAzCMm28iwalvBDKvUcqcKRg/skmcRT/eIrUVHr5GG/kBpafDR+G5cad3XCs SCh0iHzLtcfdouEA1DsVo0u8G4R8t2qE8/4a4DAj7CCMmsaTPR1R4XpS2cOFX5Kk+Ew+ PN7CoifI1ft5ccWK48IE5B74fHCM7d5LD91G37VfgpN9TcT7S+yGetYQj7xs0JO8WSdi opgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=qokcu5tCtpQLCQgO9pVTazHLwMpC9kMD5hOC340KS1I=; b=IASaQ0l4b3QWhcCiyf6wZW/koJbIxLuucjHNkAsYv/GzLT/WQQ/aBvpFTvTWiWAqbu UGHsOda10hkjv5O9zQkPMQpnX7gnpgoFqc1RQ3GoLO42zPfu5qhjZP+CF1NHeyhLPKCx Ru+A8lR4kDdVLhi0101h14wdU2kIP0EjhN3Qa5M0NU+TKLTPn2v++JYG6N4E8QPaQB2v Ywopkl+oLoP4mkN+qYID8dBBYW9mXJSviLgOJxHbGGobF8usVBwOpoqwUKvblrgFrCni w+ynRQQzUoy7EJONWG6wSRPrv7OoIXGdDe5VquTieyF5tap9cSw0CyxiWf/H23Yibqgu nXdA== X-Gm-Message-State: ACgBeo2Oxeok5NbaCmWygN0Qu2NFe2TMfDE1nVlz7VdaOJ5VSQNQamzv KfTc8kzVjVGU6mSpBV7vQs/b177TluOuX4ez9DKGhg== X-Google-Smtp-Source: AA6agR5Lo8c+tVx21B5A2il5HGzGcfxxCY5VNzyOQ8xHSFF9B9ZhcgyTcMW2pafj/S8owJMHXTCJIeOP/v9Ei+X67uo= X-Received: by 2002:a05:6000:1188:b0:220:6c20:fbf6 with SMTP id g8-20020a056000118800b002206c20fbf6mr12350055wrx.372.1661213133858; Mon, 22 Aug 2022 17:05:33 -0700 (PDT) MIME-Version: 1.0 References: <20220628220938.3657876-1-yosryahmed@google.com> <20220628220938.3657876-2-yosryahmed@google.com> <20220817102408.7b048f198a736f053ced2862@linux-foundation.org> In-Reply-To: From: Yosry Ahmed Date: Mon, 22 Aug 2022 17:04:57 -0700 Message-ID: Subject: Re: [PATCH v6 1/4] mm: add NR_SECONDARY_PAGETABLE to count secondary page table uses. To: Andrew Morton Cc: Wanpeng Li , kvm@vger.kernel.org, Roman Gushchin , Michal Hocko , Shaoqin , Linux-MM , Zefan Li , kvmarm@lists.cs.columbia.edu, Marc Zyngier , Joerg Roedel , Shakeel Butt , Cgroups , Huang@google.com, linux-arm-kernel@lists.infradead.org, Jim Mattson , Linux Kernel Mailing List , Johannes Weiner , Tejun Heo , Paolo Bonzini , Vitaly Kuznetsov X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Wed, Aug 17, 2022 at 3:27 PM Yosry Ahmed wrote: > > On Wed, Aug 17, 2022 at 10:24 AM Andrew Morton > wrote: > > > > On Tue, 28 Jun 2022 22:09:35 +0000 Yosry Ahmed wrote: > > > > > We keep track of several kernel memory stats (total kernel memory, page > > > tables, stack, vmalloc, etc) on multiple levels (global, per-node, > > > per-memcg, etc). These stats give insights to users to how much memory > > > is used by the kernel and for what purposes. > > > > > > Currently, memory used by kvm mmu is not accounted in any of those > > > kernel memory stats. This patch series accounts the memory pages > > > used by KVM for page tables in those stats in a new > > > NR_SECONDARY_PAGETABLE stat. This stat can be later extended to account > > > for other types of secondary pages tables (e.g. iommu page tables). > > > > > > KVM has a decent number of large allocations that aren't for page > > > tables, but for most of them, the number/size of those allocations > > > scales linearly with either the number of vCPUs or the amount of memory > > > assigned to the VM. KVM's secondary page table allocations do not scale > > > linearly, especially when nested virtualization is in use. > > > > > > >From a KVM perspective, NR_SECONDARY_PAGETABLE will scale with KVM's > > > per-VM pages_{4k,2m,1g} stats unless the guest is doing something > > > bizarre (e.g. accessing only 4kb chunks of 2mb pages so that KVM is > > > forced to allocate a large number of page tables even though the guest > > > isn't accessing that much memory). However, someone would need to either > > > understand how KVM works to make that connection, or know (or be told) to > > > go look at KVM's stats if they're running VMs to better decipher the stats. > > > > > > Furthermore, having NR_PAGETABLE side-by-side with NR_SECONDARY_PAGETABLE > > > is informative. For example, when backing a VM with THP vs. HugeTLB, > > > NR_SECONDARY_PAGETABLE is roughly the same, but NR_PAGETABLE is an order > > > of magnitude higher with THP. So having this stat will at the very least > > > prove to be useful for understanding tradeoffs between VM backing types, > > > and likely even steer folks towards potential optimizations. > > > > > > The original discussion with more details about the rationale: > > > https://lore.kernel.org/all/87ilqoi77b.wl-maz@kernel.org > > > > > > This stat will be used by subsequent patches to count KVM mmu > > > memory usage. > > > > Nits and triviata: > > > > > --- a/Documentation/filesystems/proc.rst > > > +++ b/Documentation/filesystems/proc.rst > > > @@ -977,6 +977,7 @@ Example output. You may not have all of these fields. > > > SUnreclaim: 142336 kB > > > KernelStack: 11168 kB > > > PageTables: 20540 kB > > > + SecPageTables: 0 kB > > > NFS_Unstable: 0 kB > > > Bounce: 0 kB > > > WritebackTmp: 0 kB > > > @@ -1085,6 +1086,9 @@ KernelStack > > > Memory consumed by the kernel stacks of all tasks > > > PageTables > > > Memory consumed by userspace page tables > > > +SecPageTables > > > + Memory consumed by secondary page tables, this currently > > > + currently includes KVM mmu allocations on x86 and arm64. > > > > Something happened to the whitespace there. > > Yeah I have the fix for this queued for v7. Thanks! > > > > > > + "Node %d SecPageTables: %8lu kB\n" > > > ... > > > + nid, K(node_page_state(pgdat, NR_SECONDARY_PAGETABLE)), > > > > The use of "sec" in the user-facing changes and "secondary" in the > > programmer-facing changes is irksome. Can we be consistent? I'd > > prefer "secondary" throughout. > > > > SecondaryPageTables is too long (unfortunately), it messes up the > formatting in node_read_meminfo() and meminfo_proc_show(). I would > prefer "secondary" as well, but I don't know if breaking the format in > this way is okay. Any thoughts here Andrew? Change to SecondaryPageTables anyway? Change all to use "sec" instead of "secondary"? Leave as-is? > > This is what I mean by breaking the format btw (the numbers become misaligned): > > diff --git a/drivers/base/node.c b/drivers/base/node.c > index 5ad56a0cd593..4f85750a0f8e 100644 > --- a/drivers/base/node.c > +++ b/drivers/base/node.c > @@ -433,7 +433,7 @@ static ssize_t node_read_meminfo(struct device *dev, > "Node %d ShadowCallStack:%8lu kB\n" > #endif > "Node %d PageTables: %8lu kB\n" > - "Node %d SecPageTables: %8lu kB\n" > + "Node %d SecondaryPageTables: %8lu kB\n" > "Node %d NFS_Unstable: %8lu kB\n" > "Node %d Bounce: %8lu kB\n" > "Node %d WritebackTmp: %8lu kB\n" > diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c > index 208efd4fa52c..b7166d09a38f 100644 > --- a/fs/proc/meminfo.c > +++ b/fs/proc/meminfo.c > @@ -115,7 +115,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) > #endif > show_val_kb(m, "PageTables: ", > global_node_page_state(NR_PAGETABLE)); > - show_val_kb(m, "SecPageTables: ", > + show_val_kb(m, "SecondaryPageTables: ", > global_node_page_state(NR_SECONDARY_PAGETABLE)); > > show_val_kb(m, "NFS_Unstable: ", 0); _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1D80AC32792 for ; Tue, 23 Aug 2022 00:07:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=B7vDbsiKnI5VzzQORCntw2ShrF+YHRTLqSBTBGTmceE=; b=BPZn6vzbVfqezQ a/DwKU6vSQASL2VbQBUuRR8uVkK3Xc55Z3oAYDbhBGQLud/2GH1ou9XyNZP7dzGiAddClj4hzElUV JzZNw7NaVj4MulPpphxyeI0/sD45VRpJ3AozWHYeSd2OM9baZccm1paVM6nIeIwZu01SZJWDZRZf9 k5DgyNUnG+/13Egnpe2BySxH+ZJM+M88+ZM650SI3r1UlMvmNxpRTWmKHN0VC+s/D0rnu+JUal+sT 0O/VMtYfD7BpSfNG9TarHH6RNw5IFLG8vftw6KbmytsOXp0LRcKkny+FJF4dkMDOkfo/Sy81ou12k b5rZ7fuqAXSIbFpnDHng==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQHQa-00GK7r-VY; Tue, 23 Aug 2022 00:05:57 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oQHQN-00GJvY-F8 for linux-arm-kernel@lists.infradead.org; Tue, 23 Aug 2022 00:05:53 +0000 Received: by mail-wr1-x429.google.com with SMTP id bq11so8506022wrb.12 for ; Mon, 22 Aug 2022 17:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=qokcu5tCtpQLCQgO9pVTazHLwMpC9kMD5hOC340KS1I=; b=jBPLk8bHlDLGIvGVE4zL26EtBtv9avfUdg557Lw4E+XzpuWZRA6yrM8jemnayVxmTu HFUGMWr/PHR8LguRaK0GVi7w26Qnt3CxyVGcW0n7UF3R4pU31QDsJO6/jSpmu9xmtRvy GHEx+99kDAzCMm28iwalvBDKvUcqcKRg/skmcRT/eIrUVHr5GG/kBpafDR+G5cad3XCs SCh0iHzLtcfdouEA1DsVo0u8G4R8t2qE8/4a4DAj7CCMmsaTPR1R4XpS2cOFX5Kk+Ew+ PN7CoifI1ft5ccWK48IE5B74fHCM7d5LD91G37VfgpN9TcT7S+yGetYQj7xs0JO8WSdi opgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=qokcu5tCtpQLCQgO9pVTazHLwMpC9kMD5hOC340KS1I=; b=YTSkKeKm1VXm9IpMaGM23QLXS9DHznh1IoQP49xCtQYOeQUcolYVLtCQsExBan5cFQ svH3X5PsfG2J13hBLlVAQuLB3BJYXDnmEHGAbaYhPJXZQfkbfeUGlFjaJGWtYgTaJBOb xdIITUeUdZF7NgU/PEB3anuhrjU0/AE38eAaxxptYWcIp7oEucNdOc9RGvsjWOZpZUhb TPJHT/pd82txnioSc4bGshvjQ7u8XAwl9ZNf+YY2MOee+dKcpgkstFCH9DfmOjD+sM56 OLTXcI399sf2NTAaQgRij1bSga8VBpOnWo79buZd3JZL7wNhtliN+67jcQwWk3r473RJ grEw== X-Gm-Message-State: ACgBeo2hhwhGOCU7vVvqa0pCkWNHp4NkalUO8eIYc9XA1BwSxTxPjqhQ rTvVdNNBLwoHrPp6Vs24mtgCxliDa/Oz9puxHgR5Bw== X-Google-Smtp-Source: AA6agR5Lo8c+tVx21B5A2il5HGzGcfxxCY5VNzyOQ8xHSFF9B9ZhcgyTcMW2pafj/S8owJMHXTCJIeOP/v9Ei+X67uo= X-Received: by 2002:a05:6000:1188:b0:220:6c20:fbf6 with SMTP id g8-20020a056000118800b002206c20fbf6mr12350055wrx.372.1661213133858; Mon, 22 Aug 2022 17:05:33 -0700 (PDT) MIME-Version: 1.0 References: <20220628220938.3657876-1-yosryahmed@google.com> <20220628220938.3657876-2-yosryahmed@google.com> <20220817102408.7b048f198a736f053ced2862@linux-foundation.org> In-Reply-To: From: Yosry Ahmed Date: Mon, 22 Aug 2022 17:04:57 -0700 Message-ID: Subject: Re: [PATCH v6 1/4] mm: add NR_SECONDARY_PAGETABLE to count secondary page table uses. To: Andrew Morton 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 , Michal Hocko , Roman Gushchin , Shakeel Butt , Oliver Upton , Huang@google.com, Shaoqin , Cgroups , Linux Kernel Mailing List , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Linux-MM X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220822_170550_491500_B045D08B X-CRM114-Status: GOOD ( 40.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Aug 17, 2022 at 3:27 PM Yosry Ahmed wrote: > > On Wed, Aug 17, 2022 at 10:24 AM Andrew Morton > wrote: > > > > On Tue, 28 Jun 2022 22:09:35 +0000 Yosry Ahmed wrote: > > > > > We keep track of several kernel memory stats (total kernel memory, page > > > tables, stack, vmalloc, etc) on multiple levels (global, per-node, > > > per-memcg, etc). These stats give insights to users to how much memory > > > is used by the kernel and for what purposes. > > > > > > Currently, memory used by kvm mmu is not accounted in any of those > > > kernel memory stats. This patch series accounts the memory pages > > > used by KVM for page tables in those stats in a new > > > NR_SECONDARY_PAGETABLE stat. This stat can be later extended to account > > > for other types of secondary pages tables (e.g. iommu page tables). > > > > > > KVM has a decent number of large allocations that aren't for page > > > tables, but for most of them, the number/size of those allocations > > > scales linearly with either the number of vCPUs or the amount of memory > > > assigned to the VM. KVM's secondary page table allocations do not scale > > > linearly, especially when nested virtualization is in use. > > > > > > >From a KVM perspective, NR_SECONDARY_PAGETABLE will scale with KVM's > > > per-VM pages_{4k,2m,1g} stats unless the guest is doing something > > > bizarre (e.g. accessing only 4kb chunks of 2mb pages so that KVM is > > > forced to allocate a large number of page tables even though the guest > > > isn't accessing that much memory). However, someone would need to either > > > understand how KVM works to make that connection, or know (or be told) to > > > go look at KVM's stats if they're running VMs to better decipher the stats. > > > > > > Furthermore, having NR_PAGETABLE side-by-side with NR_SECONDARY_PAGETABLE > > > is informative. For example, when backing a VM with THP vs. HugeTLB, > > > NR_SECONDARY_PAGETABLE is roughly the same, but NR_PAGETABLE is an order > > > of magnitude higher with THP. So having this stat will at the very least > > > prove to be useful for understanding tradeoffs between VM backing types, > > > and likely even steer folks towards potential optimizations. > > > > > > The original discussion with more details about the rationale: > > > https://lore.kernel.org/all/87ilqoi77b.wl-maz@kernel.org > > > > > > This stat will be used by subsequent patches to count KVM mmu > > > memory usage. > > > > Nits and triviata: > > > > > --- a/Documentation/filesystems/proc.rst > > > +++ b/Documentation/filesystems/proc.rst > > > @@ -977,6 +977,7 @@ Example output. You may not have all of these fields. > > > SUnreclaim: 142336 kB > > > KernelStack: 11168 kB > > > PageTables: 20540 kB > > > + SecPageTables: 0 kB > > > NFS_Unstable: 0 kB > > > Bounce: 0 kB > > > WritebackTmp: 0 kB > > > @@ -1085,6 +1086,9 @@ KernelStack > > > Memory consumed by the kernel stacks of all tasks > > > PageTables > > > Memory consumed by userspace page tables > > > +SecPageTables > > > + Memory consumed by secondary page tables, this currently > > > + currently includes KVM mmu allocations on x86 and arm64. > > > > Something happened to the whitespace there. > > Yeah I have the fix for this queued for v7. Thanks! > > > > > > + "Node %d SecPageTables: %8lu kB\n" > > > ... > > > + nid, K(node_page_state(pgdat, NR_SECONDARY_PAGETABLE)), > > > > The use of "sec" in the user-facing changes and "secondary" in the > > programmer-facing changes is irksome. Can we be consistent? I'd > > prefer "secondary" throughout. > > > > SecondaryPageTables is too long (unfortunately), it messes up the > formatting in node_read_meminfo() and meminfo_proc_show(). I would > prefer "secondary" as well, but I don't know if breaking the format in > this way is okay. Any thoughts here Andrew? Change to SecondaryPageTables anyway? Change all to use "sec" instead of "secondary"? Leave as-is? > > This is what I mean by breaking the format btw (the numbers become misaligned): > > diff --git a/drivers/base/node.c b/drivers/base/node.c > index 5ad56a0cd593..4f85750a0f8e 100644 > --- a/drivers/base/node.c > +++ b/drivers/base/node.c > @@ -433,7 +433,7 @@ static ssize_t node_read_meminfo(struct device *dev, > "Node %d ShadowCallStack:%8lu kB\n" > #endif > "Node %d PageTables: %8lu kB\n" > - "Node %d SecPageTables: %8lu kB\n" > + "Node %d SecondaryPageTables: %8lu kB\n" > "Node %d NFS_Unstable: %8lu kB\n" > "Node %d Bounce: %8lu kB\n" > "Node %d WritebackTmp: %8lu kB\n" > diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c > index 208efd4fa52c..b7166d09a38f 100644 > --- a/fs/proc/meminfo.c > +++ b/fs/proc/meminfo.c > @@ -115,7 +115,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) > #endif > show_val_kb(m, "PageTables: ", > global_node_page_state(NR_PAGETABLE)); > - show_val_kb(m, "SecPageTables: ", > + show_val_kb(m, "SecondaryPageTables: ", > global_node_page_state(NR_SECONDARY_PAGETABLE)); > > show_val_kb(m, "NFS_Unstable: ", 0); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 From: Yosry Ahmed Subject: Re: [PATCH v6 1/4] mm: add NR_SECONDARY_PAGETABLE to count secondary page table uses. Date: Mon, 22 Aug 2022 17:04:57 -0700 Message-ID: References: <20220628220938.3657876-1-yosryahmed@google.com> <20220628220938.3657876-2-yosryahmed@google.com> <20220817102408.7b048f198a736f053ced2862@linux-foundation.org> Mime-Version: 1.0 Return-path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=qokcu5tCtpQLCQgO9pVTazHLwMpC9kMD5hOC340KS1I=; b=jBPLk8bHlDLGIvGVE4zL26EtBtv9avfUdg557Lw4E+XzpuWZRA6yrM8jemnayVxmTu HFUGMWr/PHR8LguRaK0GVi7w26Qnt3CxyVGcW0n7UF3R4pU31QDsJO6/jSpmu9xmtRvy GHEx+99kDAzCMm28iwalvBDKvUcqcKRg/skmcRT/eIrUVHr5GG/kBpafDR+G5cad3XCs SCh0iHzLtcfdouEA1DsVo0u8G4R8t2qE8/4a4DAj7CCMmsaTPR1R4XpS2cOFX5Kk+Ew+ PN7CoifI1ft5ccWK48IE5B74fHCM7d5LD91G37VfgpN9TcT7S+yGetYQj7xs0JO8WSdi opgg== In-Reply-To: List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Andrew Morton 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 , Michal Hocko , Roman Gushchin , Shakeel Butt , Oliver Upton , Huang@google.com, Shaoqin , Cgroups , Linux Kernel Mailing List On Wed, Aug 17, 2022 at 3:27 PM Yosry Ahmed wrote: > > On Wed, Aug 17, 2022 at 10:24 AM Andrew Morton > wrote: > > > > On Tue, 28 Jun 2022 22:09:35 +0000 Yosry Ahmed wrote: > > > > > We keep track of several kernel memory stats (total kernel memory, page > > > tables, stack, vmalloc, etc) on multiple levels (global, per-node, > > > per-memcg, etc). These stats give insights to users to how much memory > > > is used by the kernel and for what purposes. > > > > > > Currently, memory used by kvm mmu is not accounted in any of those > > > kernel memory stats. This patch series accounts the memory pages > > > used by KVM for page tables in those stats in a new > > > NR_SECONDARY_PAGETABLE stat. This stat can be later extended to account > > > for other types of secondary pages tables (e.g. iommu page tables). > > > > > > KVM has a decent number of large allocations that aren't for page > > > tables, but for most of them, the number/size of those allocations > > > scales linearly with either the number of vCPUs or the amount of memory > > > assigned to the VM. KVM's secondary page table allocations do not scale > > > linearly, especially when nested virtualization is in use. > > > > > > >From a KVM perspective, NR_SECONDARY_PAGETABLE will scale with KVM's > > > per-VM pages_{4k,2m,1g} stats unless the guest is doing something > > > bizarre (e.g. accessing only 4kb chunks of 2mb pages so that KVM is > > > forced to allocate a large number of page tables even though the guest > > > isn't accessing that much memory). However, someone would need to either > > > understand how KVM works to make that connection, or know (or be told) to > > > go look at KVM's stats if they're running VMs to better decipher the stats. > > > > > > Furthermore, having NR_PAGETABLE side-by-side with NR_SECONDARY_PAGETABLE > > > is informative. For example, when backing a VM with THP vs. HugeTLB, > > > NR_SECONDARY_PAGETABLE is roughly the same, but NR_PAGETABLE is an order > > > of magnitude higher with THP. So having this stat will at the very least > > > prove to be useful for understanding tradeoffs between VM backing types, > > > and likely even steer folks towards potential optimizations. > > > > > > The original discussion with more details about the rationale: > > > https://lore.kernel.org/all/87ilqoi77b.wl-maz@kernel.org > > > > > > This stat will be used by subsequent patches to count KVM mmu > > > memory usage. > > > > Nits and triviata: > > > > > --- a/Documentation/filesystems/proc.rst > > > +++ b/Documentation/filesystems/proc.rst > > > @@ -977,6 +977,7 @@ Example output. You may not have all of these fields. > > > SUnreclaim: 142336 kB > > > KernelStack: 11168 kB > > > PageTables: 20540 kB > > > + SecPageTables: 0 kB > > > NFS_Unstable: 0 kB > > > Bounce: 0 kB > > > WritebackTmp: 0 kB > > > @@ -1085,6 +1086,9 @@ KernelStack > > > Memory consumed by the kernel stacks of all tasks > > > PageTables > > > Memory consumed by userspace page tables > > > +SecPageTables > > > + Memory consumed by secondary page tables, this currently > > > + currently includes KVM mmu allocations on x86 and arm64. > > > > Something happened to the whitespace there. > > Yeah I have the fix for this queued for v7. Thanks! > > > > > > + "Node %d SecPageTables: %8lu kB\n" > > > ... > > > + nid, K(node_page_state(pgdat, NR_SECONDARY_PAGETABLE)), > > > > The use of "sec" in the user-facing changes and "secondary" in the > > programmer-facing changes is irksome. Can we be consistent? I'd > > prefer "secondary" throughout. > > > > SecondaryPageTables is too long (unfortunately), it messes up the > formatting in node_read_meminfo() and meminfo_proc_show(). I would > prefer "secondary" as well, but I don't know if breaking the format in > this way is okay. Any thoughts here Andrew? Change to SecondaryPageTables anyway? Change all to use "sec" instead of "secondary"? Leave as-is? > > This is what I mean by breaking the format btw (the numbers become misaligned): > > diff --git a/drivers/base/node.c b/drivers/base/node.c > index 5ad56a0cd593..4f85750a0f8e 100644 > --- a/drivers/base/node.c > +++ b/drivers/base/node.c > @@ -433,7 +433,7 @@ static ssize_t node_read_meminfo(struct device *dev, > "Node %d ShadowCallStack:%8lu kB\n" > #endif > "Node %d PageTables: %8lu kB\n" > - "Node %d SecPageTables: %8lu kB\n" > + "Node %d SecondaryPageTables: %8lu kB\n" > "Node %d NFS_Unstable: %8lu kB\n" > "Node %d Bounce: %8lu kB\n" > "Node %d WritebackTmp: %8lu kB\n" > diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c > index 208efd4fa52c..b7166d09a38f 100644 > --- a/fs/proc/meminfo.c > +++ b/fs/proc/meminfo.c > @@ -115,7 +115,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) > #endif > show_val_kb(m, "PageTables: ", > global_node_page_state(NR_PAGETABLE)); > - show_val_kb(m, "SecPageTables: ", > + show_val_kb(m, "SecondaryPageTables: ", > global_node_page_state(NR_SECONDARY_PAGETABLE)); > > show_val_kb(m, "NFS_Unstable: ", 0);