From patchwork Wed Jul 24 01:10:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13740502 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 4EA6CC3DA63 for ; Wed, 24 Jul 2024 01:11:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E344A6B0093; Tue, 23 Jul 2024 21:11:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D1F8D6B0092; Tue, 23 Jul 2024 21:11:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B95F66B0093; Tue, 23 Jul 2024 21:11:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9D2BB6B008C for ; Tue, 23 Jul 2024 21:11:21 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5B5C3140520 for ; Wed, 24 Jul 2024 01:11:21 +0000 (UTC) X-FDA: 82372867962.22.BAEF2A0 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf01.hostedemail.com (Postfix) with ESMTP id 9335A40009 for ; Wed, 24 Jul 2024 01:11:19 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ngabXLYq; spf=pass (imf01.hostedemail.com: domain of 3tlSgZgoKCB0CMAHN9AMHG9HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--jthoughton.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3tlSgZgoKCB0CMAHN9AMHG9HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721783433; 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=RjwIFwaGyFm0pqYoSJRPlexY59ZZdKZ6ixfPL8P7AvM=; b=e+snCwYiBFRDC905rWcc69C4sotVa1/ZpPzNcLtG/hYgFrwz4LIdhAJUB0Dp9aq34V8ibG LHc5n89lXhuRhYbfGlE1/OhbJHODjjZikReIco4vuSJ9Q9GeMWAmb/yJDgRolqwLY5syu9 XR39NAKuvPHQOzoAJVpaMy4hGjcsfdA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721783433; a=rsa-sha256; cv=none; b=zA2kIQE+c4Fz+zkScYI5EinbVlJXzUcebdjbbHSxtXa4hgzud5sTPPrUYxAZgUarb88YTt 9poIJYgNAnZPO7iHj5GPBBhBoq6lgbcJ3kVNb9U2OCTk0xBjYihC4Qo42fqGfPCYdxnOJH Y7OdIhdeqoJRG4qQ++ayNX/hFF9ByFw= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ngabXLYq; spf=pass (imf01.hostedemail.com: domain of 3tlSgZgoKCB0CMAHN9AMHG9HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--jthoughton.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3tlSgZgoKCB0CMAHN9AMHG9HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e02a4de4f4eso13598224276.1 for ; Tue, 23 Jul 2024 18:11:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1721783479; x=1722388279; darn=kvack.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=RjwIFwaGyFm0pqYoSJRPlexY59ZZdKZ6ixfPL8P7AvM=; b=ngabXLYqzU/aj15BnXxwwJtc1sdobeYhM8VftC6B27l45IjKBFpy8rInVeBztT/Ecx Yfiorz+1kdA58oFaGyOKpW3wbd3XeJ9w8cy26ttr4WxEtPkHmfbl/T0n6tmSckVRq6gi zf+gcn+ARhc0oa4oUsbf6juOzbwDgW1rm/YoNplsO09IKxgOdBpr6sy0YnOLTfPxuAyx z7q5ktnsbk3FyRoNlZnFK/lfdd78P4yy4Ur5Ru3PJ7aKi6KlSxtd6yImZYsnBw4fDTPu iSQ2g9GXPug2tFJzYKRgKzR2AMz0LGiwAA9jqd+Qoo8s0IfgdnGPygghAmsE5FC+3B59 NOUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721783479; x=1722388279; 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=RjwIFwaGyFm0pqYoSJRPlexY59ZZdKZ6ixfPL8P7AvM=; b=gjCnphIYkD9EVxMlyV3OMNWwq6SY8mELdJgxwBP5wXtpEPdnr3hqgaot9b1azkBirj K5nSaFuHLhkvp7PzSYTHxm88a7FmubzZ+eVcEpVnl1odlk62c79J2VgxCBDOPMwMJyZw KtCM/r8qEyYSmUqqN2N1unut98GCCBmZggG+WMUc9CLsiOG7HtjvFOlPnTrf8onoJO75 8BeXCAonQt7/Yn6mk7tm/BdCCAMCuajvaaeE8GK8iAOVRf8j6R4vXdpGff1uTuATJU3M H/Ws/KpUrlvrl2NeuEYzubU9SM/37DCLAWVNVgp3VKtQSUzlHW0ISw/Z/qbXdpYjLykM MahA== X-Forwarded-Encrypted: i=1; AJvYcCWaRsEHczeMsJFGXdRf7tJxM/k0InhcQWB48k23HKz/chF8sTUK7ywAUAksCT7s3iBU4ZC97L2C4x+AcRLloL/bNfY= X-Gm-Message-State: AOJu0Yy+9ThqLg2Rst4258uKvXSzm5ATlo3SWJfSwFzELwAhyOuoKekY 9e7adMEjCbHu5CW78IPKfQeh54cpPUjhdjPAwaVpP2nxJRnBhetTmMZafe3hAXhNrwrEVCsJDyT 8TstwrAOIUNjTqHRE2w== X-Google-Smtp-Source: AGHT+IEf8LhPu+J2AQj8JKbpYxC+Q+/7UmZG6e+vLGbTXrpNe4bcC8God4ZSRUYFG8d6cpp91FbqTUc9FhMyYUjh X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6902:20ca:b0:e08:5554:b2be with SMTP id 3f1490d57ef6-e0b0e60b370mr1189276.9.1721783478588; Tue, 23 Jul 2024 18:11:18 -0700 (PDT) Date: Wed, 24 Jul 2024 01:10:31 +0000 In-Reply-To: <20240724011037.3671523-1-jthoughton@google.com> Mime-Version: 1.0 References: <20240724011037.3671523-1-jthoughton@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240724011037.3671523-7-jthoughton@google.com> Subject: [PATCH v6 06/11] mm: Add has_fast_aging to struct 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 , 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-Rspamd-Queue-Id: 9335A40009 X-Stat-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yIVhXDtTNWL09kBP3bXWh1+QQB2PfpQj8wvokO66FhklaZZnsYgJ1AGnvJvJVVtBaal11F8RKVmBwTBw9F6lifhicSo7kW9UBo+dSDStD1PnxhmlxmoyXfnOy5SFPeJQ4fUAGtWCt5Lt7f+wvis0/MO9mal60W4SY+SMWm8Gg/YoidxZ+BPWHv2gJ+wuZLv9NjpRKMOM0a0wrgmwkol5wAYtg+BnSRi6rxlo0bu1hUqZLq4VqF93e92Zxf+6xVBPlSetynoUfn94vsIm7k1r1eneSrrPVxJC3MZYBHOjDqnhccwgWlL3yC3iRhxtC13iA9jMywApiqr8si/6wmzq6cHjHduFbgHLJO7qHS1ealEXBGtcq0BVRX7aWJmP5YU2lUEM0Cl3015yleiop0X2Yd9tGfEjqDQMwixt87FFGOdEyAYsNT1InPHLQESpNoWnEJNX5IXJlwo34lR91lIQdDTNGgCvjKInQ2RPNWfM//mNn+gMu+jLr1JkdfsB0Ftg3Loob64wZEDoYp+drzyT3RbKzD5PK8RdH/o8Zyuv8WQLx1JZeWpdePCaxtZeavofGKf5W4cZGGw7hRPlIkpZoi9cNGu+ 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: List-Subscribe: List-Unsubscribe: has_fast_aging should be set by subscribers that non-trivially implement fast_only versions of both test_young() and clear_young(). Fast aging must be opt-in. For a subscriber that has not been enlightened with "fast aging", the test/clear_young() will behave identically whether or not fast_only is given. Given that KVM is the only test/clear_young() implementer, we could instead add an equivalent check in KVM, but doing so would incur an indirect function call every time, even if the notifier ends up being a no-op. Add mm_has_fast_young_notifiers() in case a caller wants to know if it should skip many calls to the mmu notifiers that may not be necessary (like MGLRU look-around). Signed-off-by: James Houghton --- include/linux/mmu_notifier.h | 14 ++++++++++++++ mm/mmu_notifier.c | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h index 45c5995ebd84..e23fc10f864b 100644 --- a/include/linux/mmu_notifier.h +++ b/include/linux/mmu_notifier.h @@ -233,6 +233,7 @@ struct mmu_notifier { struct mm_struct *mm; struct rcu_head rcu; unsigned int users; + bool has_fast_aging; }; /** @@ -387,6 +388,7 @@ extern int __mmu_notifier_clear_young(struct mm_struct *mm, extern int __mmu_notifier_test_young(struct mm_struct *mm, unsigned long address, bool fast_only); +extern bool __mm_has_fast_young_notifiers(struct mm_struct *mm); 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, @@ -449,6 +451,13 @@ static inline int mmu_notifier_test_young_fast_only(struct mm_struct *mm, return 0; } +static inline bool mm_has_fast_young_notifiers(struct mm_struct *mm) +{ + if (mm_has_notifiers(mm)) + return __mm_has_fast_young_notifiers(mm); + return 0; +} + static inline void mmu_notifier_invalidate_range_start(struct mmu_notifier_range *range) { @@ -653,6 +662,11 @@ static inline int mmu_notifier_test_young_fast_only(struct mm_struct *mm, return 0; } +static inline bool mm_has_fast_young_notifiers(struct mm_struct *mm) +{ + 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 f9a0ca6ffe65..f9ec810c8a1b 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -382,6 +382,26 @@ int __mmu_notifier_clear_flush_young(struct mm_struct *mm, return young; } +bool __mm_has_fast_young_notifiers(struct mm_struct *mm) +{ + struct mmu_notifier *subscription; + bool has_fast_aging = false; + int id; + + id = srcu_read_lock(&srcu); + hlist_for_each_entry_rcu(subscription, + &mm->notifier_subscriptions->list, hlist, + srcu_read_lock_held(&srcu)) { + if (subscription->has_fast_aging) { + has_fast_aging = true; + break; + } + } + srcu_read_unlock(&srcu, id); + + return has_fast_aging; +} + int __mmu_notifier_clear_young(struct mm_struct *mm, unsigned long start, unsigned long end, @@ -394,6 +414,9 @@ int __mmu_notifier_clear_young(struct mm_struct *mm, hlist_for_each_entry_rcu(subscription, &mm->notifier_subscriptions->list, hlist, srcu_read_lock_held(&srcu)) { + if (fast_only && !subscription->has_fast_aging) + continue; + if (subscription->ops->clear_young) young |= subscription->ops->clear_young(subscription, mm, start, end, @@ -415,6 +438,9 @@ int __mmu_notifier_test_young(struct mm_struct *mm, hlist_for_each_entry_rcu(subscription, &mm->notifier_subscriptions->list, hlist, srcu_read_lock_held(&srcu)) { + if (fast_only && !subscription->has_fast_aging) + continue; + if (subscription->ops->test_young) { young = subscription->ops->test_young(subscription, mm, address,