Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp82345iof; Sun, 5 Jun 2022 21:49:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3AWGVs319qBIdx0mVfLpTZ1qdjIPWmMLAkouap7LoEZ5YnOpxSKLvCJnVzWXvWycW6HgX X-Received: by 2002:a17:903:249:b0:163:6dc0:b8b3 with SMTP id j9-20020a170903024900b001636dc0b8b3mr22206102plh.24.1654490961359; Sun, 05 Jun 2022 21:49:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654490961; cv=none; d=google.com; s=arc-20160816; b=P2M9FonagpzsUuGO8oVm2OZY5mGmb+vcKgCj4vQ15iGnV6VuCV54RHyCBIoat5ywDg Viowf3b1vmbq32j7o1AH67FlD+FOmWq2Z+PWQpwFTS1ayuGHCALo5MC4pxhOLgv6SWd+ +snW6WaZ7L5YOKlydJs6xDAjsoYDM7FvXx8ZcQ3rgaieBj+m1ieMDmwNVH+Xd5pCEDgQ VzftxD1kGSRYW6aZiJ23S1F49JxVmDtSORVzmjLdcs9Q36dNNk2hv6fFjr3JONd8hrZG /S1b2R5YABVRqScnguDgzUtA6ePXaBAfAwHEDUknp4ifx4xeypgVbGuCvnjnLR0G29/c xcjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pZiq+DaP0uIJbqmhpHEQocGuha+dXUbZZZqTwIB2IaE=; b=EW+Of6xb/+3odvnb+IheaVmG3IWwC1NgzesqsY73dNUhnzGJOqZiwFoXUm9hiN3SAW ByRHqzJ7l5x54rx22Hs24D4w0wsY6B2Gr3fOq+fGxaHh/ZOUdNcazOwT+4kIPlmqC31C ZbokuRJeiWzq4Z+4vX+6ZwJoJHHtGF4kBfaV5+yAjGLMiNzVIxRX0T/XplrtlC6z1M/h UNOVdt8wQQZW1U1P5GecSBnBfwJ0VAh6q3AQ9Xz5UUqMkJ7ZIY4wrcqkFjgXnowvinSh NUx3WY98f0C/lKp04WksI7uAeVXy1rw4VPXVcH2YBg3DcE0EIK3vd790RhWwz8pVzBC9 97mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=rrQxT3vb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s11-20020a056a00194b00b00519099107ddsi12260486pfk.234.2022.06.05.21.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 21:49:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=rrQxT3vb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4CF61A2064; Sun, 5 Jun 2022 21:06:29 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344013AbiFCQmX (ORCPT + 99 others); Fri, 3 Jun 2022 12:42:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241216AbiFCQmU (ORCPT ); Fri, 3 Jun 2022 12:42:20 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DD461EC43 for ; Fri, 3 Jun 2022 09:42:18 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id br33so4663435qkb.0 for ; Fri, 03 Jun 2022 09:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=pZiq+DaP0uIJbqmhpHEQocGuha+dXUbZZZqTwIB2IaE=; b=rrQxT3vbT7GMAWiBE8NKh82hTKWmXoBOIgjSoB8gWHlxJCtpicQfJi6YHcKEu0Skmg abttTcfRqmTOcz4L3ohQC6WWhlA31fuHxoEfeuJpbUAg7kX6/vtplGcJ9j4IrzJVxD9O vdLoYfObodGls9T269h7hJyDm997n4snH1eyk5q8lGm0DuwzVfKoDQFEQSeKxajjX2Yz 5TiL9zM/J27+HT1KqOA1cB9necDYn5jb3A6o3ARG7LxeA2ES2j5uBkLAZdLyHaiO4lvt ER/oF7LY8Hxyq/pFtt8IclZxYPm5bLZuRep0Ojk6gIJnuU/og9qHiw7H4aRy54/0OtvI pIJA== 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=pZiq+DaP0uIJbqmhpHEQocGuha+dXUbZZZqTwIB2IaE=; b=0sd2fXRGofZ8FBUcy0vZGFHDC8navEFOGGA2d8Sb5JHST09BWE65+EA2ASsh1teFt5 /w1lzVd1VFlHLqqxdZXCLrECIbuBcfzTD3hFagjvccB1entv6DOSzshscra+3/N0INCm 3rCpayJuwIhNKvY9pMSyCRTWduHy8MjEl5hF9R+br3yohrWFlSAzAQsvxPoj+4E2088b TJdvw3vK5lq7HLPPrCQbDaeE9nVFAMzgYoZ5bSjvHrRgZprkg6nDrfXvYCDbAIZdMYjw iiNcPi4nyxwQ0+ljboQ2EwBNWELtciuVLdJFuUNbNlsmqlLimshHsfRzoiRH15Yy6m4Y v2bQ== X-Gm-Message-State: AOAM5324d+5z8ymq++0py1MQ4Dc8OiRZhlOhmKmCSEI+u9OH30O9aEW9 RDoPz071CXRtOrJRRPELozMayA== X-Received: by 2002:a05:620a:2845:b0:6a3:646f:9ba8 with SMTP id h5-20020a05620a284500b006a3646f9ba8mr7509475qkp.56.1654274537770; Fri, 03 Jun 2022 09:42:17 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:1d66]) by smtp.gmail.com with ESMTPSA id w184-20020a3794c1000000b006a098381abcsm5550650qkd.114.2022.06.03.09.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 09:42:17 -0700 (PDT) Date: Fri, 3 Jun 2022 12:42:15 -0400 From: Johannes Weiner To: Yosry Ahmed Cc: Sean Christopherson , Shakeel Butt , Marc Zyngier , Tejun Heo , Zefan Li , James Morse , Alexandru Elisei , Suzuki K Poulose , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andrew Morton , Michal Hocko , Roman Gushchin , Oliver Upton , Cgroups , Linux Kernel Mailing List , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Linux-MM Subject: Re: [PATCH v4 1/4] mm: add NR_SECONDARY_PAGETABLE to count secondary page table uses. Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 27, 2022 at 11:33:27AM -0700, Yosry Ahmed wrote: > On Wed, May 25, 2022 at 5:39 PM Sean Christopherson wrote: > > > > On Wed, May 25, 2022, Johannes Weiner wrote: > > > On Tue, May 24, 2022 at 03:31:52PM -0700, Yosry Ahmed wrote: > > > > I don't have enough context to say whether we should piggyback KVM MMU > > > > pages to the existing NR_PAGETABLE item, but from a high level it > > > > seems like it would be more helpful if they are a separate stat. > > > > Anyway, I am willing to go with whatever Sean thinks is best. > > > > > > Somebody should work this out and put it into a changelog. It's > > > permanent ABI. > > > > After a lot of waffling, my vote is to add a dedicated NR_SECONDARY_PAGETABLE. > > > > It's somewhat redundant from a KVM perspective, as 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. > > > > But, 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. > > > > And even in the little bit of time I played with this, I found having > > nr_page_table_pages side-by-side with nr_secondary_page_table_pages to be very > > informative. E.g. when backing a VM with THP versus HugeTLB, > > nr_secondary_page_table_pages is roughly the same, but nr_page_table_pages is an > > order of a magnitude higher with THP. I'm guessing the THP behavior is due to > > something triggering DoubleMap, but now I want to find out why that's happening. > > > > So while I'm pretty sure a clever user could glean the same info by cross-referencing > > NR_PAGETABLE stats with KVM stats, I think having NR_SECONDARY_PAGETABLE will at the > > very least prove to be helpful for understanding tradeoffs between VM backing types, > > and likely even steer folks towards potential optimizations. > > > > Baseline: > > # grep page_table /proc/vmstat > > nr_page_table_pages 2830 > > nr_secondary_page_table_pages 0 > > > > THP: > > # grep page_table /proc/vmstat > > nr_page_table_pages 7584 > > nr_secondary_page_table_pages 140 > > > > HugeTLB: > > # grep page_table /proc/vmstat > > nr_page_table_pages 3153 > > nr_secondary_page_table_pages 153 > > > > Interesting findings! Thanks for taking the time to look into this, Sean! > I will refresh this patchset and summarize the discussion in the > commit message, and also fix some nits on the KVM side. Does this > sound good to everyone? Yes, thanks for summarizing this. Sounds good to me!