From: "Joel Fernandes (Google)" <joel@joelfernandes.org>
To: linux-kernel@vger.kernel.org
Cc: Vineeth Pillai <vineeth@bitbyteword.org>,
Joel Fernandes <joel@joelfernandes.org>,
paulmck@kernel.org,
Rushikesh S Kadam <rushikesh.s.kadam@intel.com>,
"Uladzislau Rezki (Sony)" <urezki@gmail.com>,
Neeraj upadhyay <neeraj.iitr10@gmail.com>,
Frederic Weisbecker <frederic@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>, rcu <rcu@vger.kernel.org>
Subject: [PATCH v4 02/14] rcu: shrinker for lazy rcu
Date: Fri, 19 Aug 2022 20:48:45 +0000 [thread overview]
Message-ID: <20220819204857.3066329-3-joel@joelfernandes.org> (raw)
In-Reply-To: <20220819204857.3066329-1-joel@joelfernandes.org>
From: Vineeth Pillai <vineeth@bitbyteword.org>
The shrinker is used to speed up the free'ing of memory potentially held
by RCU lazy callbacks. RCU kernel module test cases show this to be
effective. Test is introduced in a later patch.
Signed-off-by: Vineeth Pillai <vineeth@bitbyteword.org>
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
kernel/rcu/tree_nocb.h | 52 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/kernel/rcu/tree_nocb.h b/kernel/rcu/tree_nocb.h
index 55636da76bc2..edb4e59dbf38 100644
--- a/kernel/rcu/tree_nocb.h
+++ b/kernel/rcu/tree_nocb.h
@@ -1259,6 +1259,55 @@ int rcu_nocb_cpu_offload(int cpu)
}
EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload);
+static unsigned long
+lazy_rcu_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
+{
+ int cpu;
+ unsigned long count = 0;
+
+ /* Snapshot count of all CPUs */
+ for_each_possible_cpu(cpu) {
+ struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
+
+ count += rcu_cblist_n_lazy_cbs(&rdp->nocb_bypass);
+ }
+
+ return count ? count : SHRINK_EMPTY;
+}
+
+static unsigned long
+lazy_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
+{
+ int cpu;
+ unsigned long flags;
+ unsigned long count = 0;
+
+ /* Snapshot count of all CPUs */
+ for_each_possible_cpu(cpu) {
+ struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
+ int _count = rcu_cblist_n_lazy_cbs(&rdp->nocb_bypass);
+
+ if (_count == 0)
+ continue;
+ rcu_nocb_lock_irqsave(rdp, flags);
+ rcu_cblist_reset_lazy_len(&rdp->nocb_bypass);
+ rcu_nocb_unlock_irqrestore(rdp, flags);
+ wake_nocb_gp(rdp, false);
+ sc->nr_to_scan -= _count;
+ count += _count;
+ if (sc->nr_to_scan <= 0)
+ break;
+ }
+ return count ? count : SHRINK_STOP;
+}
+
+static struct shrinker lazy_rcu_shrinker = {
+ .count_objects = lazy_rcu_shrink_count,
+ .scan_objects = lazy_rcu_shrink_scan,
+ .batch = 0,
+ .seeks = DEFAULT_SEEKS,
+};
+
void __init rcu_init_nohz(void)
{
int cpu;
@@ -1296,6 +1345,9 @@ void __init rcu_init_nohz(void)
if (!rcu_state.nocb_is_setup)
return;
+ if (register_shrinker(&lazy_rcu_shrinker))
+ pr_err("Failed to register lazy_rcu shrinker!\n");
+
#if defined(CONFIG_NO_HZ_FULL)
if (tick_nohz_full_running)
cpumask_or(rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask);
--
2.37.2.609.g9ff673ca1a-goog
next prev parent reply other threads:[~2022-08-19 20:49 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-19 20:48 [PATCH v4 00/14] Implement call_rcu_lazy() and miscellaneous fixes Joel Fernandes (Google)
2022-08-19 20:48 ` [PATCH v4 01/14] rcu: Introduce call_rcu_lazy() API implementation Joel Fernandes (Google)
2022-08-19 20:48 ` Joel Fernandes (Google) [this message]
2022-08-19 20:48 ` [PATCH v4 03/14] rcuscale: Add laziness and kfree tests Joel Fernandes (Google)
2022-08-19 20:48 ` [PATCH v4 04/14] fs: Move call_rcu() to call_rcu_lazy() in some paths Joel Fernandes (Google)
2022-08-19 20:48 ` [PATCH v4 05/14] rcutorture: Add test code for call_rcu_lazy() Joel Fernandes (Google)
2022-08-19 20:48 ` [PATCH v4 06/14] debug: Toggle lazy at runtime and change flush jiffies Joel Fernandes (Google)
2022-08-19 20:48 ` [PATCH v4 07/14] cred: Move call_rcu() to call_rcu_lazy() Joel Fernandes (Google)
2022-08-19 20:48 ` [PATCH v4 08/14] security: " Joel Fernandes (Google)
2022-08-19 20:48 ` [PATCH v4 09/14] net/core: " Joel Fernandes (Google)
2022-08-19 20:48 ` [PATCH v4 10/14] kernel: Move various core kernel usages " Joel Fernandes (Google)
2022-08-19 20:48 ` [PATCH v4 11/14] lib: Move call_rcu() " Joel Fernandes (Google)
2022-08-19 20:48 ` [PATCH v4 12/14] i915: " Joel Fernandes (Google)
2022-08-19 20:48 ` [PATCH v4 13/14] fork: Move thread_stack_free_rcu to call_rcu_lazy Joel Fernandes (Google)
2022-08-19 20:48 ` [PATCH v4 14/14] rcu/tree: Move trace_rcu_callback() before bypassing Joel Fernandes (Google)
2022-08-29 13:40 ` [PATCH v4 00/14] Implement call_rcu_lazy() and miscellaneous fixes Frederic Weisbecker
2022-08-29 16:45 ` Joel Fernandes
2022-08-29 19:46 ` Frederic Weisbecker
2022-08-29 20:31 ` Paul E. McKenney
2022-08-29 20:54 ` Joel Fernandes
2022-08-30 10:50 ` Frederic Weisbecker
2022-08-30 11:47 ` Paul E. McKenney
2022-08-29 20:36 ` Joel Fernandes
2022-08-29 20:42 ` Paul E. McKenney
2022-08-29 20:48 ` Joel Fernandes
2022-08-30 10:57 ` Frederic Weisbecker
2022-08-30 10:53 ` Frederic Weisbecker
2022-08-30 11:43 ` Paul E. McKenney
2022-08-30 16:03 ` Frederic Weisbecker
2022-08-30 16:22 ` Frederic Weisbecker
2022-08-30 16:44 ` Uladzislau Rezki
2022-08-30 18:53 ` Joel Fernandes
2022-09-01 11:29 ` Frederic Weisbecker
2022-09-01 11:59 ` Uladzislau Rezki
2022-09-01 14:41 ` Paul E. McKenney
2022-09-01 15:30 ` Frederic Weisbecker
2022-09-01 16:11 ` Joel Fernandes
2022-09-01 16:52 ` Paul E. McKenney
2022-09-01 15:13 ` Frederic Weisbecker
2022-09-01 16:07 ` Joel Fernandes
2022-08-30 16:46 ` Paul E. McKenney
2022-08-31 15:26 ` Frederic Weisbecker
2022-09-01 14:39 ` Paul E. McKenney
2022-09-01 14:58 ` Frederic Weisbecker
2022-09-01 16:07 ` Joel Fernandes
2022-09-01 16:49 ` Paul E. McKenney
2022-09-01 18:28 ` Frederic Weisbecker
2022-09-01 20:36 ` Paul E. McKenney
2022-08-30 18:46 ` Joel Fernandes
2022-08-30 10:26 ` Frederic Weisbecker
2022-08-30 18:40 ` Joel Fernandes
2022-08-29 19:57 ` Paul E. McKenney
2022-08-30 10:43 ` Frederic Weisbecker
2022-08-30 12:08 ` Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220819204857.3066329-3-joel@joelfernandes.org \
--to=joel@joelfernandes.org \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neeraj.iitr10@gmail.com \
--cc=paulmck@kernel.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=rushikesh.s.kadam@intel.com \
--cc=urezki@gmail.com \
--cc=vineeth@bitbyteword.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®