From: "Paul E. McKenney" <paulmck@kernel.org>
To: rcu@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com,
rostedt@goodmis.org,
"Joel Fernandes (Google)" <joel@joelfernandes.org>,
"Paul E . McKenney" <paulmck@kernel.org>
Subject: [PATCH v2 rcu 07/16] rcuscale: Add laziness and kfree tests
Date: Mon, 21 Nov 2022 17:04:12 -0800 [thread overview]
Message-ID: <20221122010421.3799681-7-paulmck@kernel.org> (raw)
In-Reply-To: <20221122010408.GA3799268@paulmck-ThinkPad-P17-Gen-1>
From: "Joel Fernandes (Google)" <joel@joelfernandes.org>
This commit adds 2 tests to rcuscale. The first one is a startup test
to check whether we are not too lazy or too hard working. The second
one causes kfree_rcu() itself to use call_rcu() and checks memory
pressure. Testing indicates that the new call_rcu() keeps memory pressure
under control roughly as well as does kfree_rcu().
[ paulmck: Apply checkpatch feedback. ]
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
---
kernel/rcu/rcuscale.c | 67 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 65 insertions(+), 2 deletions(-)
diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c
index 3ef02d4a81085..3baded807a616 100644
--- a/kernel/rcu/rcuscale.c
+++ b/kernel/rcu/rcuscale.c
@@ -95,6 +95,7 @@ torture_param(int, verbose, 1, "Enable verbose debugging printk()s");
torture_param(int, writer_holdoff, 0, "Holdoff (us) between GPs, zero to disable");
torture_param(int, kfree_rcu_test, 0, "Do we run a kfree_rcu() scale test?");
torture_param(int, kfree_mult, 1, "Multiple of kfree_obj size to allocate.");
+torture_param(int, kfree_by_call_rcu, 0, "Use call_rcu() to emulate kfree_rcu()?");
static char *scale_type = "rcu";
module_param(scale_type, charp, 0444);
@@ -659,6 +660,14 @@ struct kfree_obj {
struct rcu_head rh;
};
+/* Used if doing RCU-kfree'ing via call_rcu(). */
+static void kfree_call_rcu(struct rcu_head *rh)
+{
+ struct kfree_obj *obj = container_of(rh, struct kfree_obj, rh);
+
+ kfree(obj);
+}
+
static int
kfree_scale_thread(void *arg)
{
@@ -696,6 +705,11 @@ kfree_scale_thread(void *arg)
if (!alloc_ptr)
return -ENOMEM;
+ if (kfree_by_call_rcu) {
+ call_rcu(&(alloc_ptr->rh), kfree_call_rcu);
+ continue;
+ }
+
// By default kfree_rcu_test_single and kfree_rcu_test_double are
// initialized to false. If both have the same value (false or true)
// both are randomly tested, otherwise only the one with value true
@@ -767,11 +781,58 @@ kfree_scale_shutdown(void *arg)
return -EINVAL;
}
+// Used if doing RCU-kfree'ing via call_rcu().
+static unsigned long jiffies_at_lazy_cb;
+static struct rcu_head lazy_test1_rh;
+static int rcu_lazy_test1_cb_called;
+static void call_rcu_lazy_test1(struct rcu_head *rh)
+{
+ jiffies_at_lazy_cb = jiffies;
+ WRITE_ONCE(rcu_lazy_test1_cb_called, 1);
+}
+
static int __init
kfree_scale_init(void)
{
- long i;
int firsterr = 0;
+ long i;
+ unsigned long jif_start;
+ unsigned long orig_jif;
+
+ // Also, do a quick self-test to ensure laziness is as much as
+ // expected.
+ if (kfree_by_call_rcu && !IS_ENABLED(CONFIG_RCU_LAZY)) {
+ pr_alert("CONFIG_RCU_LAZY is disabled, falling back to kfree_rcu() for delayed RCU kfree'ing\n");
+ kfree_by_call_rcu = 0;
+ }
+
+ if (kfree_by_call_rcu) {
+ /* do a test to check the timeout. */
+ orig_jif = rcu_lazy_get_jiffies_till_flush();
+
+ rcu_lazy_set_jiffies_till_flush(2 * HZ);
+ rcu_barrier();
+
+ jif_start = jiffies;
+ jiffies_at_lazy_cb = 0;
+ call_rcu(&lazy_test1_rh, call_rcu_lazy_test1);
+
+ smp_cond_load_relaxed(&rcu_lazy_test1_cb_called, VAL == 1);
+
+ rcu_lazy_set_jiffies_till_flush(orig_jif);
+
+ if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
+ pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
+ WARN_ON_ONCE(1);
+ return -1;
+ }
+
+ if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start > 3 * HZ)) {
+ pr_alert("ERROR: call_rcu() CBs are being too lazy!\n");
+ WARN_ON_ONCE(1);
+ return -1;
+ }
+ }
kfree_nrealthreads = compute_real(kfree_nthreads);
/* Start up the kthreads. */
@@ -784,7 +845,9 @@ kfree_scale_init(void)
schedule_timeout_uninterruptible(1);
}
- pr_alert("kfree object size=%zu\n", kfree_mult * sizeof(struct kfree_obj));
+ pr_alert("kfree object size=%zu, kfree_by_call_rcu=%d\n",
+ kfree_mult * sizeof(struct kfree_obj),
+ kfree_by_call_rcu);
kfree_reader_tasks = kcalloc(kfree_nrealthreads, sizeof(kfree_reader_tasks[0]),
GFP_KERNEL);
--
2.31.1.189.g2e36527f23
next prev parent reply other threads:[~2022-11-22 1:04 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-22 1:04 [PATCH rcu 0/16 Lazy call_rcu() updates for v6.2 Paul E. McKenney
2022-11-22 1:04 ` [PATCH v2 rcu 01/16] rcu: Simplify rcu_init_nohz() cpumask handling Paul E. McKenney
2022-11-22 1:04 ` [PATCH v2 rcu 02/16] rcu: Fix late wakeup when flush of bypass cblist happens Paul E. McKenney
2022-11-22 1:04 ` [PATCH v2 rcu 03/16] rcu: Fix missing nocb gp wake on rcu_barrier() Paul E. McKenney
2022-11-22 1:04 ` [PATCH v2 rcu 04/16] rcu: Make call_rcu() lazy to save power Paul E. McKenney
2022-11-22 1:04 ` [PATCH v2 rcu 05/16] rcu: Refactor code a bit in rcu_nocb_do_flush_bypass() Paul E. McKenney
2022-11-23 15:59 ` Frederic Weisbecker
2022-11-23 17:54 ` Paul E. McKenney
2022-11-24 1:00 ` Joel Fernandes
2022-11-22 1:04 ` [PATCH v2 rcu 06/16] rcu: Shrinker for lazy rcu Paul E. McKenney
2022-11-22 1:04 ` Paul E. McKenney [this message]
2022-11-22 1:04 ` [PATCH v2 rcu 08/16] percpu-refcount: Use call_rcu_flush() for atomic switch Paul E. McKenney
2022-11-22 1:04 ` [PATCH v2 rcu 09/16] rcu/sync: Use call_rcu_flush() instead of call_rcu Paul E. McKenney
2022-11-22 1:04 ` [PATCH v2 rcu 10/16] rcu/rcuscale: Use call_rcu_flush() for async reader test Paul E. McKenney
2022-11-22 1:04 ` [PATCH v2 rcu 11/16] rcu/rcutorture: Use call_rcu_flush() where needed Paul E. McKenney
2022-11-22 1:04 ` [PATCH v2 rcu 12/16] scsi/scsi_error: Use call_rcu_flush() instead of call_rcu() Paul E. McKenney
2022-11-26 0:11 ` Bart Van Assche
2022-11-28 21:39 ` Paul E. McKenney
2022-11-26 2:42 ` Martin K. Petersen
2022-11-22 1:04 ` [PATCH v2 rcu 13/16] workqueue: Make queue_rcu_work() use call_rcu_flush() Paul E. McKenney
2022-11-22 1:09 ` Tejun Heo
2022-11-22 1:23 ` Paul E. McKenney
2022-11-22 1:37 ` Tejun Heo
2022-11-22 1:52 ` Paul E. McKenney
2022-11-22 21:30 ` Tejun Heo
2022-11-22 1:04 ` [PATCH v2 rcu 14/16] rxrpc: Use call_rcu_flush() instead of call_rcu() Paul E. McKenney
2022-11-22 1:04 ` [PATCH v2 rcu 15/16] net: Use call_rcu_flush() for dst_release() Paul E. McKenney
2022-11-22 1:04 ` [PATCH v2 rcu 16/16] net: devinet: Reduce refcount before grace period 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=20221122010421.3799681-7-paulmck@kernel.org \
--to=paulmck@kernel.org \
--cc=joel@joelfernandes.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.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