From patchwork Wed May 29 18:05:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13679384 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 11FA9C25B75 for ; Wed, 29 May 2024 18:05:58 +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:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=5ptv07AvUswUW4kgO5/q6D89gyWRkYQqyugEbxAw+pc=; b=Zzc 0txxRBLReINKOdXzNlbiz1rMJDC9CkGl/imUYv72D0U1v4ht2ZeHefn1Pi7KqgteuU2dKS8WqVKsm E7R57kMBRAYqTZgDNjDMEKqBTDm93Yh33B4rIUkeH7/m+x8lD8peKr6DLle6PeJRYFBBeIQDpgfzv M0JqT5xt+XOVHuwzB2fWISpKrEp6/ym1xQCW/IYAgy6U0+JtKj+5Lz+76qIQ9JaRb7cBHTYjbHA6a swR4aIWK+p3+g++gfuMU3LSLoFMSXLfcMO5SVrTqqRA7/govMDcx1X/cn5Lm6cR9hwxn9I1XmVDqj 3kgygoreIwnnVpLSmk9yCtBNwcSnVHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCNgC-000000058xg-0Q6l; Wed, 29 May 2024 18:05:40 +0000 Received: from mail-vs1-xe4a.google.com ([2607:f8b0:4864:20::e4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCNfu-000000058hT-2xAu for linux-arm-kernel@lists.infradead.org; Wed, 29 May 2024 18:05:26 +0000 Received: by mail-vs1-xe4a.google.com with SMTP id ada2fe7eead31-48a3972ade6so21892137.0 for ; Wed, 29 May 2024 11:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717005917; x=1717610717; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=oSeK4HIzvhbzZ4+kBhyxeRArFmVuKpeUMlCOBrkyZKY=; b=gPtYY8HRHXx361FEwwwThzZyFyFFU8vyYL+z4CNj3xKDRltjFILgGNKekmI/r1vR5r giuQbD5W2Xms+00cnFaNErA72XpAtii36txToAaT35PJM2po1+l+VI7Vn4IALEgwk/xm Lcd673MG3VvmdiUDbYk77u0Anot8EjrwyBvTWDQ0anqd+WFLi8B7OymcQ229Z+nlgerk 8a/blJ0N9ExkEQcVslhL06TUz2Xx1X3Bu1QoYdJPjXyJJ4Hoi3ueTJ+DXr29qGON/Mpi hHeDwxSADndw7+Nok1njyfZZIjwFcdAxodoFxnV/7QvEjRd3YmzkcZIJHgCtcXo5gOS1 /7WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717005917; x=1717610717; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=oSeK4HIzvhbzZ4+kBhyxeRArFmVuKpeUMlCOBrkyZKY=; b=lxWVga3IZ8TIHZFpj+0sXdoU1oWf6EHgEcFBXEkgkWS2G3eCW/sXkFLWdPhbOIW1qi dG1ZryVXhApGzuVN6FKju4WXYkPojkeuGqQJ+QV+80lB58Aforuh82H4gFjWeLjGM++Z jDTz7ffqHAyT79QMyNkLZEQBUyQ+V1R9mKWA/Wjr4HqtEGWVV2rXb/cuc031Z2iCsVRs 2Jj7AyC/AG7WBQHouornISch4vps/8moYBlz979wrTh9/Gp0wStqZ6KGKqCDugtCT+EO HUKLIww9hG5wHILIlJ2h8Pr0i+0lqurqUjLQkGy2A/awBE8cJJXdUULOXGdu6ZHHJENh xVbQ== X-Forwarded-Encrypted: i=1; AJvYcCWtxO/zPExmrgMD12EF04WFkoN7KsllbFLwa28BEapAj9kRGlYlkSsyggVg3lx1lZNVxKexOsY0Oo+3yv/FKrX2bWv+dIv8pWJazD+Gwq3wOyAy8Oc= X-Gm-Message-State: AOJu0YwXAQREWiwTwMBoqR3ePF6oFdv9akQBP6bA6BL4+BE7zms+UI0q kbqrOdh9rZgazV/iZcCn+2xNDVqBxC+s1hSboIMiheZ9d4aHDEPvL2BdcMlPZlUWSA9Q5sqeZFO Ea4VMU3r5c8dIhct6kA== X-Google-Smtp-Source: AGHT+IGirSTR9frt+FMY7mEAkHJfvAwcaa/uk6kZfZAYRVHTIdMTLDcjTaGUq6V+fW4RjZ9NSYV+AI/l972bzeUv X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6102:3f9e:b0:48a:5834:cea7 with SMTP id ada2fe7eead31-48a5834e759mr882345137.7.1717005917523; Wed, 29 May 2024 11:05:17 -0700 (PDT) Date: Wed, 29 May 2024 18:05:03 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240529180510.2295118-1-jthoughton@google.com> Subject: [PATCH v4 0/7] mm: multi-gen LRU: Walk secondary MMU page tables while aging From: James Houghton To: Andrew Morton , Paolo Bonzini Cc: Albert Ou , Ankit Agrawal , Anup Patel , Atish Patra , Axel Rasmussen , Bibo Mao , Catalin Marinas , David Matlack , David Rientjes , Huacai Chen , James Houghton , James Morse , Jonathan Corbet , Marc Zyngier , Michael Ellerman , Nicholas Piggin , Oliver Upton , Palmer Dabbelt , Paul Walmsley , Raghavendra Rao Ananta , Ryan Roberts , Sean Christopherson , Shaoqin Huang , Shuah Khan , Suzuki K Poulose , Tianrui Zhao , Will Deacon , Yu Zhao , Zenghui Yu , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240529_110522_848133_037F5D89 X-CRM114-Status: GOOD ( 20.87 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patchset makes it possible for MGLRU to consult secondary MMUs while doing aging, not just during eviction. This allows for more accurate reclaim decisions, which is especially important for proactive reclaim. This series makes the necessary MMU notifier changes to MGLRU and then includes optimizations on top of that. This series also now includes changes to access_tracking_perf_test to verify that aging works properly for pages that are mainly used by KVM. access_tracking_perf_test also has a mode (-p) to check performance of MGLRU aging while the VM is faulting memory in. Here are some results: Testing MGLRU aging while vCPUs are faulting in memory on x86 with the TDP MMU. THPs disabled. The test results varied a decent amount from run to run. I did my best to take representative averages, but nonetheless, the big picture is the important part. Main takeaways: - With the optimizations, the workload is much less impacted by the presence of aging. - With the optimizations, MGLRU is able to do aging much more quickly, especially at 8+ vCPUs on my machine. ./access_tracking_perf_test -p -l -b 1G -v $N_VCPUS # 1G per vCPU num_vcpus vcpu wall time aging avg pass time 1 (no aging) 0.878822016 n/a 1 (no opt) 0.938250568 0.008236007 1 (opt) 0.912270190 0.007314582 2 (no aging) 0.984959659 n/a 2 (no opt) 1.057880728 0.017989741 2 (opt) 1.037735641 0.013996319 4 (no aging) 1.264881581 n/a 4 (no opt) 1.318849182 0.056164918 4 (opt) 1.314653465 0.029311993 8 (no aging) 1.473883699 n/a 8 (no opt) 1.589441079 0.227419586s 8 (opt) 1.498439592 0.063857740s 16 (no aging) 2.048766096 n/a 16 (no opt) 2.399335597 1.247142841s 16 (opt) 2.000914001 0.121628689s 32 (no aging) 3.316256321 n/a 32 (no opt) 3.955417018 4.347290433 32 (opt) 3.355274507 0.250886289 64 (no aging) 6.498958516 n/a 64 (no opt) 7.127533884 9.815592054 64 (opt) 6.442582168 1.392907010 112 (no aging) 8.498029491 n/a 112 (no opt) 10.21372495 13.47381656 112 (opt) 8.896963554 2.292223850 Previous versions of this series included logic in MGLRU and KVM to support batching the updates to secondary page tables. This version removes this logic, as it was complex and not necessary to enable proactive reclaim. This optimization, as well as the additional optimizations for arm64 and powerpc, can be done in a later series. Changes since v3[1]: - Vastly simplified the series (thanks David). Removed mmu notifier batching logic entirely. - Cleaned up how locking is done for mmu_notifier_test/clear_young (thanks David). - Look-around is now only done when there are no secondary MMUs subscribed to MMU notifiers. - CONFIG_LRU_GEN_WALKS_SECONDARY_MMU has been added. - Fixed the lockless implementation of kvm_{test,}age_gfn for x86 (thanks David). - Added MGLRU functional and performance tests to access_tracking_perf_test (thanks Axel). - In v3, an mm would be completely ignored (for aging) if there was a secondary MMU but support for secondary MMU walking was missing. Now, missing secondary MMU walking support simply skips the notifier calls (except for eviction). - Added a sanity check for that range->lockless and range->on_lock are never both provided for the memslot walk. For the changes from v2[2] to v3, see v3[1]. This series applies cleanly to mm/mm-unstable and kvm/queue. [1]: https://lore.kernel.org/linux-mm/20240401232946.1837665-1-jthoughton@google.com/ [2]: https://lore.kernel.org/kvmarm/20230526234435.662652-1-yuzhao@google.com/ James Houghton (7): mm/Kconfig: Add LRU_GEN_WALKS_SECONDARY_MMU mm: multi-gen LRU: Have secondary MMUs participate in aging KVM: Add lockless memslot walk to KVM KVM: Move MMU lock acquisition for test/clear_young to architecture KVM: x86: Relax locking for kvm_test_age_gfn and kvm_age_gfn KVM: arm64: Relax locking for kvm_test_age_gfn and kvm_age_gfn KVM: selftests: Add multi-gen LRU aging to access_tracking_perf_test Documentation/admin-guide/mm/multigen_lru.rst | 6 +- arch/arm64/kvm/hyp/pgtable.c | 9 +- arch/arm64/kvm/mmu.c | 30 +- arch/loongarch/kvm/mmu.c | 20 +- arch/mips/kvm/mmu.c | 21 +- arch/powerpc/kvm/book3s.c | 14 +- arch/riscv/kvm/mmu.c | 26 +- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/mmu/mmu.c | 10 +- arch/x86/kvm/mmu/tdp_iter.h | 27 +- arch/x86/kvm/mmu/tdp_mmu.c | 67 ++- include/linux/kvm_host.h | 1 + include/linux/mmzone.h | 6 +- mm/Kconfig | 8 + mm/rmap.c | 9 +- mm/vmscan.c | 144 +++++-- tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/access_tracking_perf_test.c | 365 ++++++++++++++-- .../selftests/kvm/include/lru_gen_util.h | 55 +++ .../testing/selftests/kvm/lib/lru_gen_util.c | 391 ++++++++++++++++++ virt/kvm/kvm_main.c | 38 +- 21 files changed, 1104 insertions(+), 145 deletions(-) create mode 100644 tools/testing/selftests/kvm/include/lru_gen_util.h create mode 100644 tools/testing/selftests/kvm/lib/lru_gen_util.c base-commit: e0cce98fe279b64f4a7d81b7f5c3a23d80b92fbc