Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2823175rwb; Wed, 30 Nov 2022 11:19:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf5CarQfC+BozJDkeG1CwD9aOKbboBGcazaAP4clLZwAUSBlIzivT8Gn7+0YNo8RyNrMYjh3 X-Received: by 2002:a17:906:b29a:b0:78d:b695:1d68 with SMTP id q26-20020a170906b29a00b0078db6951d68mr37291188ejz.235.1669835976170; Wed, 30 Nov 2022 11:19:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669835976; cv=none; d=google.com; s=arc-20160816; b=Mo4CSn3cqBgF6DQVNCWnHbgI1i/pgra4LNCTyKCDOtPkYiby0iDwMrLDsnOGBeNU8s Z9q/mGT6Y8Na7PBzksqLXPwtUrH5Zx8YXtwjbrAxvY9qxotb8hoT1kY3sizPcczE2dkN 2YzVjviQX1e/SX7Z5DRpiOG6OYkNNgPtnMTgawXn3ShIXnAfugmREMnQLjJNcJQDEWtc gPuYQI7Ooq/H2ezzYBV2mucd3kGBSyl6XS00IlQzal4b2mH4TdoXQBKQ/PCuZPPRKdOs WkedmoZ6WDDSLfg1NmJMytLO8hDYAC6oh176cBNDUkLfnfd9/AjD10W83v27KEkt8Qz2 g9LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZHuFqUUNuNBBbGtm2obtlgmElzjDDyVm88R/Db4kxYU=; b=Bm+Xi4sZzNGZaUGfeyZAF3CvtPF+F8A3TIiKCVQV4A08hxDG7xERwkZEfT1LoMfqq+ Ct+ZeorI8H4vXw4F32u0ojiRlxWC5JifraPAVq29r8dFn5ybt0tGGE8oNkgKjYpB973w J5OY8jkqV0psvy0SBo8xtTXdb4nb+TTchbf2uEEQE7M6HnECkdh6lWZqofk82YLWOy4C qiCRtyKLYskq+zbpLOfhaVjEQdiSx3j3kZfASnAISSGj0B8uwJN+6AvFiRIcBMqIXqp1 jqh25Rs2MJKU/3vyTwnLHKBNiIn19nFhMKfis8qD8STzk9e020hblkPQT4zp6itpxB7M gvTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mfxSe3go; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y8-20020a056402270800b0046b32882b04si1890431edd.440.2022.11.30.11.19.16; Wed, 30 Nov 2022 11:19:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mfxSe3go; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230171AbiK3SN6 (ORCPT + 83 others); Wed, 30 Nov 2022 13:13:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbiK3SNa (ORCPT ); Wed, 30 Nov 2022 13:13:30 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80D2C862C9; Wed, 30 Nov 2022 10:13:29 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 17FDF61D5C; Wed, 30 Nov 2022 18:13:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3625C43151; Wed, 30 Nov 2022 18:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669832008; bh=B649m1ZX6zSaxE2rwxoHbFbQjFjTg7X6m3NxA9r7zOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mfxSe3go/rNNMfTBQnQyJaJaHF/0vxwxJugp+gTMgidOOl7XzZFzW6lt6iAxEfszC CTZOz52+VrmRWHwuVmNzFguPfy/ApYLBKyZjKAscf+hX6p1B0vFqWmwtj3/dhs53dv XK+rk7SMsaplB3m/ektanHjB+/ZngnNe+gI8IEXIfg3uUBxKlFnnIwNtT8NDczzvUi rvci2gYKPco/tNgIKh2mcT4wula/mw7MDkPQ6tjzwPdffk2XW+atTYbj2QUi6cih7Q O0Rskjv3AT7ppaFhK45PUYI57MC6g1o8TElFYKmT+YfUjP3paDLa5Oc2azScYCPh2h 2qTBaSL/gq46Q== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 624275C14A0; Wed, 30 Nov 2022 10:13:27 -0800 (PST) From: "Paul E. McKenney" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, "Joel Fernandes (Google)" , "Paul E . McKenney" Subject: [PATCH rcu 07/16] rcuscale: Add laziness and kfree tests Date: Wed, 30 Nov 2022 10:13:16 -0800 Message-Id: <20221130181325.1012760-7-paulmck@kernel.org> X-Mailer: git-send-email 2.31.1.189.g2e36527f23 In-Reply-To: <20221130181316.GA1012431@paulmck-ThinkPad-P17-Gen-1> References: <20221130181316.GA1012431@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Joel Fernandes (Google)" 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) Signed-off-by: Paul E. McKenney --- 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