Received: by 2002:ab2:69cc:0:b0:1fd:c486:4f03 with SMTP id n12csp37242lqp; Mon, 10 Jun 2024 17:24:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVDSUPbbtsXX98By7I5gJlx7d2mlrXzveALdMrL+VcWrGVnz+9ZTBWSdQAIVQtD6vdZi5iYb3eXAiRTlVbTFXMhuTmxys1PL9i+4gELzQ== X-Google-Smtp-Source: AGHT+IGrqEKHCALp4HJRkIS+OKOu+Wc2UYIU3HIibZZjCDxMCAtAMrOMuNmEKpWhuoibMtI3VIwL X-Received: by 2002:a05:6122:603:b0:4d4:1a1a:6db7 with SMTP id 71dfb90a1353d-4eb5621d03cmr9844202e0c.2.1718065445987; Mon, 10 Jun 2024 17:24:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718065445; cv=pass; d=google.com; s=arc-20160816; b=pdUf7N1bKrL42OUHSG9QESfd7HAjYc1vUK8OX0DwuCnaAkNTyn2OV4lRpCSaLMpTTa zuWMK2evM1pe99I6kEAwIetb26W+x2joskFAxeG0kKd2exH2A8DyD2tuh0EozP2Zu/+n 6UYEK+t4n7hLCnrQQTLyw4sc16NjxO9FICcKJN/DdSwIv+nkSKCcOZzQ/tgZkzClAl8S t3xUnaQFTAFTFa8r4MpV/wHJBqHJuUdAnQC+msYDgQ1LvP+dcB8yh64qSVBF6yw2Tto2 Hyk11a6S+DQwMM4rHAedYEXdWDUgRNIyQoIbjQCaESphYYUglclOwqz4hz0oZ2P0MLQp xEGA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=6j3rWVw+E6yiyAll83pvyiHc59e6Q6WaEN3pW8ayg5o=; fh=HZL4tyIWAIFb/0n8SH/0D0vEGCDRn4aaIWPCe650A0E=; b=gwRSPWNJtXDqZwThnJashM7LG23r0qXN3SHLeEzFnk4gV7Y2KBB87hDK3ABPl+Trv/ IURzbt3MBw3fiF+IPhu8+pFbRHHrlLv1WHpWsq8ZKfHh6v8vAblQ1eifR9TlJIJyKA4T TeSgvH20YgKHsF9jg0pMuQAJHj9Wy5bRofVLwbtTmoIEkvIWMmYJBSh6m0pFAMZFP+9h PY87rSbebq7qd5t7bLW8AoTadEV6YgyicWhffifE4W2FuF5mJKR5My7iFZdYRHnLD9fr T9ygLnNSS+OwBVTcMwyuRZl21SJkO7y9UvQkD8Be6LkMZ57bnLr5JVmME2hww8nFWOzz +0sA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aCXwHRst; arc=pass (i=1 spf=pass spfdomain=flex--jthoughton.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-209118-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209118-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d75a77b69052e-44109fdc7b7si24488521cf.331.2024.06.10.17.24.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 17:24:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-209118-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=aCXwHRst; arc=pass (i=1 spf=pass spfdomain=flex--jthoughton.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-209118-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-209118-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A59141C21907 for ; Tue, 11 Jun 2024 00:24:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C69972B9BE; Tue, 11 Jun 2024 00:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="aCXwHRst" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 496B4EDF for ; Tue, 11 Jun 2024 00:22:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718065325; cv=none; b=V0bSvTCfH61AQsU3Hk54Y2Cb5gyAmPX56LidRkfsPj3+WriNn+N6/CXdRBQiYHpTZS5vXCHdThSv/NTs9xIjc80YPWBRToi27f44mywRy0Adzp+AETpYO0sVM7s9WjfO0PhAK4dHzPRf590eByCj/3qgu4zlrvI617g9L+gxSyI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718065325; c=relaxed/simple; bh=hrTHF1LPFXBYPkOeqn+Sm4a6LUN1ZOrT0EeRBRT4T7A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ana5MK3v8Ab2sUnpVyQKTWygw/IPO888hG/cpirN/JqsOA71p8Ewe+0lsBQ3QUvauWrpdifHoOzm57lnJ6C9LbjDzVZ/IXHuu7lkLyfwK42GKCHjX6dE9MEChwTukI5Dr+JTurgk0/kOKXSrzpYq1GilAanx74BvR729+jkLcS8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=aCXwHRst; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthoughton.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-62d032a07a9so9229117b3.2 for ; Mon, 10 Jun 2024 17:22:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718065322; x=1718670122; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6j3rWVw+E6yiyAll83pvyiHc59e6Q6WaEN3pW8ayg5o=; b=aCXwHRstM3P/cvDYwPBZtBQ8cHq5tbnCdkCqDPQ68M+15HsxXC8nKWh0FS/L2WiH74 c0h1HyItpdC/y5wDhpHydJo2OKmF8Qkp8CCKe9d6xbsCNaUyiL9jhBLRrO04BgFBDJ+4 G2mf7pOjglTa8c8nvmH6LHA+uFfmitFw2b/dFPgKXn+7W6tkqGYdvLkWMhZbG2grC1OO 9u/vZxx6PTSWRNIreMu7N6OPVL4sP+hrFzN7n8ifRDaEu/ixgiSy5ZMtZj/GGQSa7M5W 53Umnw2azVkhyMfnXpHPhqY93pIox+gzSQCz0Qt8ifQQHjulRtXVbIbjGySsefGmmX1W LZVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718065322; x=1718670122; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6j3rWVw+E6yiyAll83pvyiHc59e6Q6WaEN3pW8ayg5o=; b=NVlV4yXA2wgkNKzdh9WS4lzzAgkufrLqKPfORyQqZ+TTK51nBGqHrwD+CF6HYfYobl dUJMoNiz95dyZf/Cmua/nkAjkKCpSxWG2/CjUKfMYdBIO/FE7Af9uS3VZpACTvP4xcD2 BX0NF7xmoPde1pcNpDSgPOURwNNBXk7TPveKk61PMIIXwb7xcqJEX+Cv/wMjerCF8leC QB09B+KPgD/lvROqKHZXO2xR7MnTYMB2/ecqPLPdtY45QSTQajUJyX9cXNKU/OYwu5mP Bu3FNg8x6SBKmcdO8TY+3wlY98qnBnN5auZWaD5Rtve9Yn0mCTO9A5Q6r1jduBhw0qzf 2asg== X-Forwarded-Encrypted: i=1; AJvYcCX992o6zaYi9msgVDReYs63nLOpulmq2W7jWtFAFF0Ej/YIHJ9BGgbu1KmYtyGieYavUydLyWJPDCUyB85OTUGE3DqPlQIW5Z+LpqPe X-Gm-Message-State: AOJu0YzOKUiUST8Ye3U20+rRD6b73HtLKa71GaC0ZnPpZnlx1cNZcBka cTrtX1RLAmNg5epwMSc5nG1ZZnytJEODVu0NDmGMX5iJR3iX6V/HOpKzG25+niV0Wm2bW/jbTFK 89D+CySgmWa++95ATSQ== X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:690c:4485:b0:62d:fbf:920a with SMTP id 00721157ae682-62d0fbf9666mr11256657b3.10.1718065322252; Mon, 10 Jun 2024 17:22:02 -0700 (PDT) Date: Tue, 11 Jun 2024 00:21:40 +0000 In-Reply-To: <20240611002145.2078921-1-jthoughton@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240611002145.2078921-1-jthoughton@google.com> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Message-ID: <20240611002145.2078921-5-jthoughton@google.com> Subject: [PATCH v5 4/9] mm: Add test_clear_young_fast_only MMU notifier From: James Houghton To: Andrew Morton , Paolo Bonzini Cc: Ankit Agrawal , Axel Rasmussen , Catalin Marinas , David Matlack , David Rientjes , James Houghton , James Morse , 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 Content-Type: text/plain; charset="UTF-8" This new notifier is for multi-gen LRU specifically, as it wants to be able to get and clear age information from secondary MMUs only if it can be done "fast". By having this notifier specifically created for MGLRU, what "fast" means comes down to what is "fast" enough to improve MGLRU's ability to reclaim most of the time. Signed-off-by: James Houghton --- include/linux/mmu_notifier.h | 50 ++++++++++++++++++++++++++++++++++++ mm/mmu_notifier.c | 26 +++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index d39ebb10caeb..2655d841a409 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -61,6 +61,15 @@ enum mmu_notifier_event { #define MMU_NOTIFIER_RANGE_BLOCKABLE (1 << 0) +/* + * Bits in the return value for test_clear_young_fast_only. + * + * MMU_NOTIFIER_FAST_YOUNG: notifier succeeded, secondary MMU reports young. + * MMU_NOTIFIER_FAST_FAILED: notifier failed. + */ +#define MMU_NOTIFIER_FAST_YOUNG (1 << 0) +#define MMU_NOTIFIER_FAST_FAILED (1 << 1) + struct mmu_notifier_ops { /* * Called either by mmu_notifier_unregister or when the mm is @@ -122,6 +131,24 @@ struct mmu_notifier_ops { struct mm_struct *mm, unsigned long address); + /* + * test_clear_young_fast_only is called to check (and optionally clear) + * the young/accessed bitflag in the secondary pte such that the + * secondary MMU must implement it in a way that will not significantly + * disrupt other MMU operations. In other words, speed is more + * important than accuracy. + * + * Returns MMU_NOTIFIER_FAST_YOUNG if the secondary pte(s) were young. + * Returns MMU_NOTIFIER_FAST_FAILED if the secondary MMU could not do + * an accurate fast-only test and/or clear of the young/accessed + * flag. + */ + int (*test_clear_young_fast_only)(struct mmu_notifier *subscription, + struct mm_struct *mm, + unsigned long start, + unsigned long end, + bool clear); + /* * invalidate_range_start() and invalidate_range_end() must be * paired and are called only when the mmap_lock and/or the @@ -383,6 +410,10 @@ extern int __mmu_notifier_clear_young(struct mm_struct *mm, unsigned long end); extern int __mmu_notifier_test_young(struct mm_struct *mm, unsigned long address); +extern int __mmu_notifier_test_clear_young_fast_only(struct mm_struct *mm, + unsigned long start, + unsigned long end, + bool clear); extern int __mmu_notifier_invalidate_range_start(struct mmu_notifier_range *r); extern void __mmu_notifier_invalidate_range_end(struct mmu_notifier_range *r); extern void __mmu_notifier_arch_invalidate_secondary_tlbs(struct mm_struct *mm, @@ -428,6 +459,17 @@ static inline int mmu_notifier_test_young(struct mm_struct *mm, return 0; } +static inline int mmu_notifier_test_clear_young_fast_only(struct mm_struct *mm, + unsigned long start, + unsigned long end, + bool clear) +{ + if (mm_has_notifiers(mm)) + return __mmu_notifier_test_clear_young_fast_only(mm, start, end, + clear); + return 0; +} + static inline void mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) { @@ -612,6 +654,14 @@ static inline int mmu_notifier_test_young(struct mm_struct *mm, return 0; } +static inline int mmu_notifier_test_clear_young_fast_only(struct mm_struct *mm, + unsigned long start, + unsigned long end, + bool clear) +{ + return 0; +} + static inline void mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) { diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index 8982e6139d07..7b77ad6cf833 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -424,6 +424,32 @@ int __mmu_notifier_test_young(struct mm_struct *mm, return young; } +int __mmu_notifier_test_clear_young_fast_only(struct mm_struct *mm, + unsigned long start, + unsigned long end, + bool clear) +{ + struct mmu_notifier *subscription; + int ret = 0, id; + + id = srcu_read_lock(&srcu); + hlist_for_each_entry_rcu(subscription, + &mm->notifier_subscriptions->list, hlist, + srcu_read_lock_held(&srcu)) { + if (subscription->ops->test_clear_young_fast_only) { + ret = subscription->ops->test_clear_young_fast_only( + subscription, mm, start, end, clear); + if (ret & MMU_NOTIFIER_FAST_FAILED) + break; + if (!clear && (ret & MMU_NOTIFIER_FAST_YOUNG)) + break; + } + } + srcu_read_unlock(&srcu, id); + + return ret; +} + static int mn_itree_invalidate(struct mmu_notifier_subscriptions *subscriptions, const struct mmu_notifier_range *range) { -- 2.45.2.505.gda0bf45e8d-goog