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 2E659C25B08 for ; Wed, 17 Aug 2022 22:28:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 792766B0075; Wed, 17 Aug 2022 18:28:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7416A8D0003; Wed, 17 Aug 2022 18:28:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6091E8D0002; Wed, 17 Aug 2022 18:28:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 51CF36B0075 for ; Wed, 17 Aug 2022 18:28:37 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 255431C6DB3 for ; Wed, 17 Aug 2022 22:28:37 +0000 (UTC) X-FDA: 79810525074.07.E491F55 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by imf08.hostedemail.com (Postfix) with ESMTP id C401B160046 for ; Wed, 17 Aug 2022 22:28:36 +0000 (UTC) Received: by mail-wr1-f41.google.com with SMTP id n7so6508063wrv.4 for ; Wed, 17 Aug 2022 15:28:36 -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=o1hj40RfZIutgTtHY6Ei4iwhGh1778mLr0oxD454ZKw=; b=dxQEBsrSOL6uneP8vspbdKN8cBHPLmh476RXn4nJLef2SC2AaP3hEaVfFfI+RNXVBC vgzrUEQdxYMNrJ+jezUDoyob0kbiLE7ORKCdTBLFa2i3RQKy1foqJ61Gs3yaQS61PK99 hKCF/kgqBaIHTekyfAfoVByipKAm6EgVGHNqnfh0M6ZBcTluXibNNSDJkKCQJH9N0cWp MaZ/MngfqLuXRrfljnJ/CdzaaBF5y3lB2jjOH9eC3r36yDFw56U7vu6Y6F/AWxpmWg4k +gFmn3dYTFKgVYuqjbtEl0Io2egt9yfZOdljmrlRETUhbMaQg7UXCc4GMk8ygxXXKw4u zrMw== 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=o1hj40RfZIutgTtHY6Ei4iwhGh1778mLr0oxD454ZKw=; b=lpcHoBH0KE6pn5bKOCq1zkKpWDOUnPPp7Rr57pmXgzye2nqgVsV9+X94KGC3lm8FTD BrnX9uG2UvOi+B5wpj5OVtoUo139KXNP6RQkv+RC312RHx8+wvCcFgf0Qy7VwOQ/InBo cZsLI30c0gxS1dgKT9UhHSOHcqgqBz/CR7m1KR95DCGAge3z4P9N0SI3LKyUDi/bKSOG +s6FsCRoMGdsc+6qHUKVf4XMCq+A2bIzIKzNWXbJiJr83kbfchWUKeOW0UAnBVOXAuln +YRFl11IA1sxV5poCUH91zJSdoJwqkvZvMJSmQq6uaCK9YTH5TeDC2QhzZkkOqSg7U/y tvwg== X-Gm-Message-State: ACgBeo0hR4tK3r4MH9Vhavd9pjw0py2qKFhnVc0jngRR3pHDyrBBaV89 6k9re8o3W+k4Y7dxv4DglUiwwuTbzmc4vir6C4iusw== X-Google-Smtp-Source: AA6agR7tp4biFjNEHKNs+HqaDuNi3dJzl8FDIEl5tWodRn34g8QXrKQ82nA0862GDnxXcX0/CDLqX7FOZ/emHPTcrpA= X-Received: by 2002:a05:6000:11d0:b0:225:1c12:65f8 with SMTP id i16-20020a05600011d000b002251c1265f8mr76041wrx.80.1660775315237; Wed, 17 Aug 2022 15:28:35 -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: <20220817102408.7b048f198a736f053ced2862@linux-foundation.org> From: Yosry Ahmed Date: Wed, 17 Aug 2022 15:27:58 -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" ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=dxQEBsrS; spf=pass (imf08.hostedemail.com: domain of yosryahmed@google.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660775316; a=rsa-sha256; cv=none; b=1vzlMWRD3x+qUmBDiOO2zyc6eK5rC2OnGic7wy2rEgTXGxFNNUqDDRXh9nJnYZ9Ni8WEqS dHnpQslMgYEIwJQwsjygg+iGRHnhUeCODCgtiYzYPwWnKmv9dG27fpYHG6w+3QqtddN/nw M6WMaOKRusMEYKEaCh0UOt8oOSaWgC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660775316; 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=o1hj40RfZIutgTtHY6Ei4iwhGh1778mLr0oxD454ZKw=; b=oq2Dhr11pta1iNCNCzKaKekZz4cUMllssxkLMLpRrX0j2OJleUPjy+bLF+X0ayAvKNUrrf DqAerCQjrOIOnkxTidbXCHdXebpeiH5mX5QD/oWlI5EiBqzMY+1BFaAMY3Nsthai7cAYYM jRSbPQY9g85Her+kAa7WruyBJ5JAgws= X-Stat-Signature: yyx8n7h5476qy3g6pk3yqup96mnarp4e X-Rspamd-Queue-Id: C401B160046 Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=dxQEBsrS; spf=pass (imf08.hostedemail.com: domain of yosryahmed@google.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam04 X-HE-Tag: 1660775316-783737 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 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. 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);