Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1296098rwe; Thu, 1 Sep 2022 16:17:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR7DWHP0BS/4mMhhq11n7KUWN2a5P0A+xdmZHjgjYMqHPx9qUUrZ2OQCbLi7UYFqRy5RpOSq X-Received: by 2002:a17:906:cc5a:b0:741:5240:d91a with SMTP id mm26-20020a170906cc5a00b007415240d91amr18596563ejb.500.1662074238989; Thu, 01 Sep 2022 16:17:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662074238; cv=none; d=google.com; s=arc-20160816; b=jmx4CMMdWOrChc+J2xCffrkjeTc+QlYfLCceOE6Mh3uCJ6sQjEqrTh66Mn37v6Y7d6 a8uvsDOJp0SL6B7Fnjjv12IjzdrKZHEz3KavBSrtSREGJCo2Z/hXg/iFoNiEnUdSMN7M N31P1xL1AUONzauA8X3QE1TB1jQ+vEmqAGQUkw3zmE0KCaicJne8EsFNEDeaGrjqJI1x zlt53o1g1K5Yl6k0jecbVU6WV1KoBNXjHzOiycRcAqReTedEkeOq6IijngHqUdWkLK8Q XYDI7RK5uLCAZtehMwvVY4C2d8VPgQbVCDro8mN0IBouA0y3oK8ciTz6FFGw3ZPYRfVc wkEg== 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=9dE4Rk8OIOb+ihEgM/v0EEwGQjrbZnrnEwGtQG+Tokc=; b=hfjNYqbLEF9zIyEnUmF8lL2Kziau3wFYwo1WXRChdRMp0wdeZvMBCZM770T/uGl3LT dR+7L3a+q/1x43dGOiqPbF958rUKTmrLsugWtZbNz1otRYk8t5jOxmrkPVjskHjxSpS4 b+mnGVsWlgZrgj6Xsz1q1Gi3fHDuA1Tbc9r0Rn8//jNoVufUy/KxVTVj3E3V0MOjnrEz Hz8s5+9cOD6tGYcI+E8vNR3A0zNR4IsqZUSCqZRWu3plbiPMEYG/6abPaB6ZDGrP24Os jwOcwjulAhQ5ofDur0qfVtNGXirysMDFjiCuJQ6Ul32NuWGvNRTjx9MQP5m6vOdqSGMX hdvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=hduLdeo2; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o21-20020a1709061d5500b0072fa13ddca0si415451ejh.229.2022.09.01.16.16.53; Thu, 01 Sep 2022 16:17:18 -0700 (PDT) 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=@joelfernandes.org header.s=google header.b=hduLdeo2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235112AbiIAWTA (ORCPT + 99 others); Thu, 1 Sep 2022 18:19:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234624AbiIAWSF (ORCPT ); Thu, 1 Sep 2022 18:18:05 -0400 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BE70580B6 for ; Thu, 1 Sep 2022 15:18:04 -0700 (PDT) Received: by mail-qv1-xf31.google.com with SMTP id kh8so185970qvb.1 for ; Thu, 01 Sep 2022 15:18:04 -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; bh=9dE4Rk8OIOb+ihEgM/v0EEwGQjrbZnrnEwGtQG+Tokc=; b=hduLdeo23eUYXwfIi5kOwRTpmsQWKz5WMzdJryBENxzTtKqWyj8jKS1pkZfs7K8ix/ 433izYbBsAKpcvkSRytC/Vy95tY1M4jnMjqRDxPDnm8amlDKZui5CBFRq87fL6LuqJ/2 5PT2xT3jsfon0zpijEzJBydZ5JMeqjs5NKQVw= 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; bh=9dE4Rk8OIOb+ihEgM/v0EEwGQjrbZnrnEwGtQG+Tokc=; b=YMCRYajNcmRT5ezkJCeBY/4DlKXAhdpWPIPs98tUMaDAavVt0a3nS1407Vn4i/aVyb soOunjtcw6mfLlkdJAzWnbYDSE+TXsfdClS10KqiQsUoflDHHl7COxiD1XcNR12F+741 3l3CDFHpIZPqhIefIN3TEJ+m7KLdpmckKnshcG2Vx45Fewnsyi3CDZKpU7tvnTmCA8S8 iIoXmHnnL7TWfgWuMSmy/1zohvPXBNolX9omXXLWv3GA+NNaIILNY2dF1VN4WWxt0jps q5d1Sn7+eVuaZ8C64VuQ8fYQcUCaW9gzOOXNcKfq3BvCXu6rJdekJNDvrcyPwdrKmejX nuLA== X-Gm-Message-State: ACgBeo3bZ8l/hx27/+3xAKwYKBj82yV7j+YC2UzRQICyn1eSj1VV4ess yIvKLTo+E3+jTSE/N/BNeFYQcA== X-Received: by 2002:a05:6214:b61:b0:498:ff24:9b59 with SMTP id ey1-20020a0562140b6100b00498ff249b59mr21011911qvb.98.1662070683846; Thu, 01 Sep 2022 15:18:03 -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 s16-20020ac85290000000b0034305a91aaesm11060794qtn.83.2022.09.01.15.18.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 15:18:03 -0700 (PDT) From: "Joel Fernandes (Google)" To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, rushikesh.s.kadam@intel.com, urezki@gmail.com, neeraj.iitr10@gmail.com, frederic@kernel.org, paulmck@kernel.org, rostedt@goodmis.org, vineeth@bitbyteword.org, boqun.feng@gmail.com, "Joel Fernandes (Google)" Subject: [PATCH v5 09/18] rcuscale: Add laziness and kfree tests Date: Thu, 1 Sep 2022 22:17:11 +0000 Message-Id: <20220901221720.1105021-10-joel@joelfernandes.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220901221720.1105021-1-joel@joelfernandes.org> References: <20220901221720.1105021-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 We aad 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_lazy() and check memory pressure. In my testing, call_rcu_lazy() does well to keep memory pressure under control, similar to kfree_rcu(). Signed-off-by: Joel Fernandes (Google) --- kernel/rcu/rcuscale.c | 74 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/kernel/rcu/rcuscale.c b/kernel/rcu/rcuscale.c index 3ef02d4a8108..6808f2e14385 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_rcu_by_lazy, 0, "Use call_rcu_lazy() 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_lazy(). */ +static void kfree_rcu_lazy(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_rcu_by_lazy) { + call_rcu_lazy(&(alloc_ptr->rh), kfree_rcu_lazy); + 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 @@ -738,6 +752,9 @@ kfree_scale_cleanup(void) { int i; + if (kfree_rcu_by_lazy) + rcu_force_call_rcu_to_lazy(false); + if (torture_cleanup_begin()) return; @@ -767,11 +784,64 @@ kfree_scale_shutdown(void *arg) return -EINVAL; } +// Used if doing RCU-kfree'ing via call_rcu_lazy(). +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; + unsigned long orig_jif, jif_start; + + // If lazy-rcu based kfree'ing is requested, then for kernels that + // support it, force all call_rcu() to call_rcu_lazy() so that non-lazy + // CBs do not remove laziness of the lazy ones (since the test tries to + // stress call_rcu_lazy() for OOM). + // + // Also, do a quick self-test to ensure laziness is as much as + // expected. + if (kfree_rcu_by_lazy && !IS_ENABLED(CONFIG_RCU_LAZY)) { + pr_alert("CONFIG_RCU_LAZY is disabled, falling back to kfree_rcu() " + "for delayed RCU kfree'ing\n"); + kfree_rcu_by_lazy = 0; + } + + if (kfree_rcu_by_lazy) { + /* do a test to check the timeout. */ + orig_jif = rcu_lazy_get_jiffies_till_flush(); + + rcu_force_call_rcu_to_lazy(true); + rcu_lazy_set_jiffies_till_flush(2 * HZ); + rcu_barrier(); + + jif_start = jiffies; + jiffies_at_lazy_cb = 0; + call_rcu_lazy(&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: Lazy 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: Lazy CBs are being too lazy!\n"); + WARN_ON_ONCE(1); + return -1; + } + } kfree_nrealthreads = compute_real(kfree_nthreads); /* Start up the kthreads. */ @@ -784,7 +854,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_rcu_by_lazy=%d\n", + kfree_mult * sizeof(struct kfree_obj), + kfree_rcu_by_lazy); kfree_reader_tasks = kcalloc(kfree_nrealthreads, sizeof(kfree_reader_tasks[0]), GFP_KERNEL); -- 2.37.2.789.g6183377224-goog