Skip to content

Commit 084e04f

Browse files
joelagnelpaulmckrcu
authored andcommitted
rcuscale: Add laziness and kfree tests
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>
1 parent c945b4d commit 084e04f

1 file changed

Lines changed: 65 additions & 2 deletions

File tree

kernel/rcu/rcuscale.c

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ torture_param(int, verbose, 1, "Enable verbose debugging printk()s");
9595
torture_param(int, writer_holdoff, 0, "Holdoff (us) between GPs, zero to disable");
9696
torture_param(int, kfree_rcu_test, 0, "Do we run a kfree_rcu() scale test?");
9797
torture_param(int, kfree_mult, 1, "Multiple of kfree_obj size to allocate.");
98+
torture_param(int, kfree_by_call_rcu, 0, "Use call_rcu() to emulate kfree_rcu()?");
9899

99100
static char *scale_type = "rcu";
100101
module_param(scale_type, charp, 0444);
@@ -659,6 +660,14 @@ struct kfree_obj {
659660
struct rcu_head rh;
660661
};
661662

663+
/* Used if doing RCU-kfree'ing via call_rcu(). */
664+
static void kfree_call_rcu(struct rcu_head *rh)
665+
{
666+
struct kfree_obj *obj = container_of(rh, struct kfree_obj, rh);
667+
668+
kfree(obj);
669+
}
670+
662671
static int
663672
kfree_scale_thread(void *arg)
664673
{
@@ -696,6 +705,11 @@ kfree_scale_thread(void *arg)
696705
if (!alloc_ptr)
697706
return -ENOMEM;
698707

708+
if (kfree_by_call_rcu) {
709+
call_rcu(&(alloc_ptr->rh), kfree_call_rcu);
710+
continue;
711+
}
712+
699713
// By default kfree_rcu_test_single and kfree_rcu_test_double are
700714
// initialized to false. If both have the same value (false or true)
701715
// both are randomly tested, otherwise only the one with value true
@@ -767,11 +781,58 @@ kfree_scale_shutdown(void *arg)
767781
return -EINVAL;
768782
}
769783

784+
// Used if doing RCU-kfree'ing via call_rcu().
785+
static unsigned long jiffies_at_lazy_cb;
786+
static struct rcu_head lazy_test1_rh;
787+
static int rcu_lazy_test1_cb_called;
788+
static void call_rcu_lazy_test1(struct rcu_head *rh)
789+
{
790+
jiffies_at_lazy_cb = jiffies;
791+
WRITE_ONCE(rcu_lazy_test1_cb_called, 1);
792+
}
793+
770794
static int __init
771795
kfree_scale_init(void)
772796
{
773-
long i;
774797
int firsterr = 0;
798+
long i;
799+
unsigned long jif_start;
800+
unsigned long orig_jif;
801+
802+
// Also, do a quick self-test to ensure laziness is as much as
803+
// expected.
804+
if (kfree_by_call_rcu && !IS_ENABLED(CONFIG_RCU_LAZY)) {
805+
pr_alert("CONFIG_RCU_LAZY is disabled, falling back to kfree_rcu() for delayed RCU kfree'ing\n");
806+
kfree_by_call_rcu = 0;
807+
}
808+
809+
if (kfree_by_call_rcu) {
810+
/* do a test to check the timeout. */
811+
orig_jif = rcu_lazy_get_jiffies_till_flush();
812+
813+
rcu_lazy_set_jiffies_till_flush(2 * HZ);
814+
rcu_barrier();
815+
816+
jif_start = jiffies;
817+
jiffies_at_lazy_cb = 0;
818+
call_rcu(&lazy_test1_rh, call_rcu_lazy_test1);
819+
820+
smp_cond_load_relaxed(&rcu_lazy_test1_cb_called, VAL == 1);
821+
822+
rcu_lazy_set_jiffies_till_flush(orig_jif);
823+
824+
if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start < 2 * HZ)) {
825+
pr_alert("ERROR: call_rcu() CBs are not being lazy as expected!\n");
826+
WARN_ON_ONCE(1);
827+
return -1;
828+
}
829+
830+
if (WARN_ON_ONCE(jiffies_at_lazy_cb - jif_start > 3 * HZ)) {
831+
pr_alert("ERROR: call_rcu() CBs are being too lazy!\n");
832+
WARN_ON_ONCE(1);
833+
return -1;
834+
}
835+
}
775836

776837
kfree_nrealthreads = compute_real(kfree_nthreads);
777838
/* Start up the kthreads. */
@@ -784,7 +845,9 @@ kfree_scale_init(void)
784845
schedule_timeout_uninterruptible(1);
785846
}
786847

787-
pr_alert("kfree object size=%zu\n", kfree_mult * sizeof(struct kfree_obj));
848+
pr_alert("kfree object size=%zu, kfree_by_call_rcu=%d\n",
849+
kfree_mult * sizeof(struct kfree_obj),
850+
kfree_by_call_rcu);
788851

789852
kfree_reader_tasks = kcalloc(kfree_nrealthreads, sizeof(kfree_reader_tasks[0]),
790853
GFP_KERNEL);

0 commit comments

Comments
 (0)