From nobody Thu Apr 2 16:37:26 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68867C43217 for ; Sun, 16 Oct 2022 16:24:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229786AbiJPQYK (ORCPT ); Sun, 16 Oct 2022 12:24:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbiJPQXo (ORCPT ); Sun, 16 Oct 2022 12:23:44 -0400 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE8D736DEA for ; Sun, 16 Oct 2022 09:23:39 -0700 (PDT) Received: by mail-qt1-x82e.google.com with SMTP id a24so6477734qto.10 for ; Sun, 16 Oct 2022 09:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MFv2k9n8x/vbjzME1MIB+yYKdyjDx7vFk8XwTZ/52oM=; b=pFoAWi3kBEAGDc2aHFGMmCJvf5Zfz5LxHgotdiEB9LFKrsTbW15ZnDMU1HUBK5zm8W crxIjDZHN1eKJsY0Bq+u2RNV3MIm5nOZdhzA2SuantNmQf2+oFOg6DzxFxue8tSYymUg j3DuWTFxWngANZ4oR094/l7N7vAUXimfSN/7c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MFv2k9n8x/vbjzME1MIB+yYKdyjDx7vFk8XwTZ/52oM=; b=v5i0jvtZl8rz6DpmWhU6k1u9gZd1rAhQ96A0WbdqlFoK+IGYRida6XKSDujlcL6nB3 kphbXv+r/lRyXCXvSXQQS1Yer/iEneVxUi+Lh+qD9K+klsPTO8CZ6YD2viARHWJiO2Uy npKw3AWMOruJamk/VR/D2gFYzCWlVWwKISLxKVaY3pyBJq36mcOCEWI0mHxHc/oP/jai 0ek6hFmGdruCfzjOsFcMJ8BIXiG3JlGOu9DrcifnZbks0pwWTGWxU4wvspzoXzzVjzHK nv0Smd4uFwKaXX7i+vothLLMLcxds1thX2cdfTTPGsklO0F+sqLBmMYESU6i3wnVP+yq 5EAg== X-Gm-Message-State: ACrzQf1ZDeFAphOg23MJngEVKOAVKhIHJRoF3jsQnoF9RxvctdSnzgww an5Pi+77C0wXSuaQCzZfGsUqMA== X-Google-Smtp-Source: AMsMyM7b+ICrOC1y2bDpkpmXAXe6iS6hNeyabB8X44Csffuhjo7JADShW4MjaDVEKWBPE5ASn89YFw== X-Received: by 2002:ac8:5995:0:b0:39a:acd0:ecd with SMTP id e21-20020ac85995000000b0039aacd00ecdmr5638044qte.206.1665937417931; Sun, 16 Oct 2022 09:23:37 -0700 (PDT) Received: from joelboxx.c.googlers.com.com (228.221.150.34.bc.googleusercontent.com. [34.150.221.228]) by smtp.gmail.com with ESMTPSA id x19-20020ac87ed3000000b003436103df40sm6001207qtj.8.2022.10.16.09.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 09:23:37 -0700 (PDT) From: "Joel Fernandes (Google)" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, frederic@kernel.org, paulmck@kernel.org, "Joel Fernandes (Google)" Subject: [PATCH v9 05/13] rcuscale: Add laziness and kfree tests Date: Sun, 16 Oct 2022 16:22:57 +0000 Message-Id: <20221016162305.2489629-6-joel@joelfernandes.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221016162305.2489629-1-joel@joelfernandes.org> References: <20221016162305.2489629-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We add 2 tests to rcuscale, first one is a startup test to check whether we are not too lazy or too hard working. Two, emulate kfree_rcu() itself to use call_rcu() and check memory pressure. In my testing, the new call_rcu() does well to keep memory pressure under control, similar to kfree_rcu(). Signed-off-by: Joel Fernandes (Google) --- kernel/rcu/rcuscale.c | 68 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c index 3ef02d4a8108..bbdcac1804ec 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 d= isable"); 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()?"); =20 static char *scale_type =3D "rcu"; module_param(scale_type, charp, 0444); @@ -659,6 +660,14 @@ struct kfree_obj { struct rcu_head rh; }; =20 +/* Used if doing RCU-kfree'ing via call_rcu(). */ +static void kfree_call_rcu(struct rcu_head *rh) +{ + struct kfree_obj *obj =3D 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; =20 + 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,59 @@ kfree_scale_shutdown(void *arg) return -EINVAL; } =20 +// 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 =3D jiffies; + WRITE_ONCE(rcu_lazy_test1_cb_called, 1); +} + static int __init kfree_scale_init(void) { - long i; int firsterr =3D 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 =3D 0; + } + + if (kfree_by_call_rcu) { + /* do a test to check the timeout. */ + orig_jif =3D rcu_lazy_get_jiffies_till_flush(); + + rcu_lazy_set_jiffies_till_flush(2 * HZ); + rcu_barrier(); + + jif_start =3D jiffies; + jiffies_at_lazy_cb =3D 0; + call_rcu(&lazy_test1_rh, call_rcu_lazy_test1); + + smp_cond_load_relaxed(&rcu_lazy_test1_cb_called, VAL =3D=3D 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; + } + } =20 kfree_nrealthreads =3D compute_real(kfree_nthreads); /* Start up the kthreads. */ @@ -784,7 +846,9 @@ kfree_scale_init(void) schedule_timeout_uninterruptible(1); } =20 - pr_alert("kfree object size=3D%zu\n", kfree_mult * sizeof(struct kfree_ob= j)); + pr_alert("kfree object size=3D%zu, kfree_by_call_rcu=3D%d\n", + kfree_mult * sizeof(struct kfree_obj), + kfree_by_call_rcu); =20 kfree_reader_tasks =3D kcalloc(kfree_nrealthreads, sizeof(kfree_reader_ta= sks[0]), GFP_KERNEL); --=20 2.38.0.413.g74048e4d9e-goog