From patchwork Wed Jul 24 01:10:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13740523 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 E6779C3DA49 for ; Wed, 24 Jul 2024 01:12:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:Mime-Version:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=4cSOuBWS+C1ycbtiGXOUNR2uU8fUZDxisEhVyZ4yNKI=; b=zwh9ZdL0prw0w+WRwuCBnQU9j9 jpk/t/jvB9DhuxpQl9KB4ekt2+FHOWX51hHcLchcK2jZJEAf/8pV1DG3yfMmeYsOnNS6JtvHmxppD 672kYUIwvwpmIfbM2V4oiraNHAdofskPm4wjwBbBF3PfOJ5jK/bcFhFDC19pplc7Yz8haP1bWC9C2 l8YaxoGdACjR8EJuqcfg2iGJfan4lblR0RDvn4BNkJi8c7eWEWZwCSC8gB3IBsM0q9YJ/JpYP2TPF q935FiB9PFBVQK/wHvmFqCdRv1Zeou6mTuzWveotFxP4utL+cw9bE+/bxHAd+IPLxHfyYoZSKPwsJ XhuySaCA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWQXd-0000000DxNX-40ts; Wed, 24 Jul 2024 01:11:42 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sWQXD-0000000Dx8H-0s8p for linux-arm-kernel@lists.infradead.org; Wed, 24 Jul 2024 01:11:17 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-66af35f84a3so121916997b3.1 for ; Tue, 23 Jul 2024 18:11:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721783473; x=1722388273; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=4cSOuBWS+C1ycbtiGXOUNR2uU8fUZDxisEhVyZ4yNKI=; b=VSHOjwodllAn9eBSzhqkwtZEDV5dLE/5lXRcPwbNdxB/gtabl/0L3UntXbDFgGozHQ EtFBwMFx+Y4u8vtEs2eQ/3/Fo0TiBTHzBLyUMPLnKixHlE7dGNnsZHLnUDd2mhZV8w2j sgnIKBBL3Ik0DOUWJZWvheYScVewOmEruXYrJvTvoxLjeWQmoPmVBhfgesaoWzDIIqGY ZAZgIlUitxr6oqA/AM2YLyEJWd9pKFcjJnshR1yG3mjcZHGEWBxwMx4L8jm/J900I3tl ss8D9+XneF3tPkGoppbTSl8GK486rTTiuTZa/zOGDNU48kOBIIWCbTnh3L5Jwz7h3kT6 9nmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721783473; x=1722388273; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4cSOuBWS+C1ycbtiGXOUNR2uU8fUZDxisEhVyZ4yNKI=; b=bGhQGFN6tKRouxpZNnaCPqcC6Kzs7TXzzsqHJrVbjgFbl+MBGexc1wjIACZaoBpper 9NlWCskgUTP2F1j86RqKlYRnnc8zUGQw2NzwhtRwgxSasidV+UTbnGEe/ytEicAwoVuw besMfdCHggu60sow4IRgo0vCXkYk9TvZHcq/HC4fDADKUg/qvdmz3HobJ9itq12RITzg sTsNKmq4QQAL6MXJ1jJ3P8caUJtVYkq4Ek+yJ+ZKcUDWlbzi+aFDGcWd4KdgegRkcbxW MVXFwZvRjQ0jbS2vB6IjGXJ9AIyMGYtiOw+ABrG7SXqO+7zdQqGo/fbD4gPFpQ0nxGc3 QUEA== X-Forwarded-Encrypted: i=1; AJvYcCUgAyGeIEnR0dnryJX+cdMfLVyCdpC6hZ5d2dZdozCY0spmAeHWTf2VpGpNIIreCKmomoQ7Tyx5YekSAneXpZwIwpvkyFL9L/Z4lASe+FdcPY6CMy8= X-Gm-Message-State: AOJu0YyVoNBiuZbLHYWGz+Y7G9V/UT5RXtOxR+0D84RUZKjaQNyYUgAZ KoERUNwlx22gXoOnObu7Ep53CVbNhnHrN/aIdv2nRQ0ywiFOS29AJseE16FvVCC5WPyaHjzqjAS 1cQknDQIBRG0WW3wnVg== X-Google-Smtp-Source: AGHT+IHTWsfjxkFhlZ/efjqoG2otoOld5wqzU0dS4uuWsUR/MGeJLDWGi8tLphMhuDEGJQs1xgmW73pGbIUMunRM X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:690c:289:b0:627:a787:abf4 with SMTP id 00721157ae682-671f0bcbd75mr236647b3.3.1721783473255; Tue, 23 Jul 2024 18:11:13 -0700 (PDT) Date: Wed, 24 Jul 2024 01:10:25 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240724011037.3671523-1-jthoughton@google.com> Subject: [PATCH v6 00/11] mm: multi-gen LRU: Walk secondary MMU page tables while aging From: James Houghton To: Andrew Morton , Paolo Bonzini Cc: Ankit Agrawal , Axel Rasmussen , Catalin Marinas , David Matlack , David Rientjes , James Houghton , James Morse , Jason Gunthorpe , Jonathan Corbet , Marc Zyngier , Oliver Upton , Raghavendra Rao Ananta , Ryan Roberts , Sean Christopherson , Shaoqin Huang , Suzuki K Poulose , Wei Xu , Will Deacon , Yu Zhao , Zenghui Yu , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240723_181115_298361_FC08696E X-CRM114-Status: GOOD ( 25.24 ) 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 does the following: 1. Improve locking for the existing test/clear_young notifiers for x86 and arm64. 2. Add a fast_only parameter into test_young() and clear_young(), and add helper functions for using the new parameter (e.g. mmu_notifier_clear_young_fast_only(). Non-trivially implement the fast-only test_young() and clear_young() for x86_64. 3. Incorporate mmu_notifier_clear_young_fast_only() into MGLRU aging. 4. Add an MGLRU mode (-l) to access_tracking_perf_test to show that aging is working properly. Please note that mmu_notifier_test_young_fast_only() is added but not used in this series. I am happy to remove it if that would be appropriate. The fast-only notifiers serve a particular purpose: for aging, we neither want to delay other operations (e.g. unmapping for eviction) nor do we want to be delayed by these other operations ourselves. By default, the implementations of test_young() and clear_young() are meant to be *accurate*, not fast. The fast-only notifiers will only give age information that can be gathered fast. The fast-only notifiers are non-trivially implemented for only x86_64 right now (as the KVM/x86 TDP MMU is the only secondary MMU that supports lockless Accessed bit harvesting). To make aging work for more than just x86, the fast-only clear_young() notifier must be non-trivially implemented by those other architectures and HAVE_KVM_MMU_NOTIFIER_YOUNG_FAST_ONLY needs to be set. access_tracking_perf_test now has a mode (-p) to check performance of MGLRU aging while the VM is faulting memory in. See the v4 cover letter[2] for performance data collected with this test. 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 enabling aging for arm64 and powerpc, can be done in a later series. === Previous Versions === Since v5[1]: - Reworked test_clear_young_fast_only() into a new parameter for the existing notifiers (thanks Sean). - Added mmu_notifier.has_fast_aging to tell mm if calling fast-only notifiers should be done. - Added mm_has_fast_young_notifiers() to inform users if calling fast-only notifier helpers is worthwhile (for look-around to use). - Changed MGLRU to invoke a single notifier instead of two when aging and doing look-around (thanks Yu). - For KVM/x86, check indirect_shadow_pages > 0 instead of kvm_memslots_have_rmaps() when collecting age information (thanks Sean). - For KVM/arm, some fixes from Oliver. - Small fixes to access_tracking_perf_test. - Added missing !MMU_NOTIFIER version of mmu_notifier_clear_young(). Since v4[2]: - Removed Kconfig that controlled when aging was enabled. Aging will be done whenever the architecture supports it (thanks Yu). - Added a new MMU notifier, test_clear_young_fast_only(), specifically for MGLRU to use. - Add kvm_fast_{test_,}age_gfn, implemented by x86. - Fix locking for clear_flush_young(). - Added KVM_MMU_NOTIFIER_YOUNG_LOCKLESS to clean up locking changes (thanks Sean). - Fix WARN_ON and other cleanup for the arm64 locking changes (thanks Oliver). Since v3[3]: - 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 since v2[4], see v3. Based on latest kvm/next. [1]: https://lore.kernel.org/linux-mm/20240611002145.2078921-1-jthoughton@google.com/ [2]: https://lore.kernel.org/linux-mm/20240529180510.2295118-1-jthoughton@google.com/ [3]: https://lore.kernel.org/linux-mm/20240401232946.1837665-1-jthoughton@google.com/ [4]: https://lore.kernel.org/kvmarm/20230526234435.662652-1-yuzhao@google.com/ James Houghton (11): KVM: Add lockless memslot walk to KVM 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 mm: Add missing mmu_notifier_clear_young for !MMU_NOTIFIER mm: Add fast_only bool to test_young and clear_young MMU notifiers mm: Add has_fast_aging to struct mmu_notifier KVM: Pass fast_only to kvm_{test_,}age_gfn KVM: x86: Optimize kvm_{test_,}age_gfn a little bit KVM: x86: Implement fast_only versions of kvm_{test_,}age_gfn mm: multi-gen LRU: Have secondary MMUs participate in aging KVM: selftests: Add multi-gen LRU aging to access_tracking_perf_test Documentation/admin-guide/mm/multigen_lru.rst | 6 +- arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/hyp/pgtable.c | 15 +- arch/arm64/kvm/mmu.c | 30 +- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/Kconfig | 2 + arch/x86/kvm/mmu/mmu.c | 23 +- arch/x86/kvm/mmu/tdp_iter.h | 27 +- arch/x86/kvm/mmu/tdp_mmu.c | 67 ++- include/linux/kvm_host.h | 2 + include/linux/mmu_notifier.h | 67 ++- include/linux/mmzone.h | 6 +- include/trace/events/kvm.h | 19 +- mm/damon/vaddr.c | 2 - mm/mmu_notifier.c | 38 +- mm/rmap.c | 9 +- mm/vmscan.c | 148 +++++-- tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/access_tracking_perf_test.c | 369 +++++++++++++++-- .../selftests/kvm/include/lru_gen_util.h | 55 +++ .../testing/selftests/kvm/lib/lru_gen_util.c | 391 ++++++++++++++++++ virt/kvm/Kconfig | 7 + virt/kvm/kvm_main.c | 73 ++-- 23 files changed, 1194 insertions(+), 165 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: 332d2c1d713e232e163386c35a3ba0c1b90df83f