Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5474553rwb; Mon, 14 Nov 2022 05:19:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf7ZcwEZWxNwN+pf+1r0xbpzZ7syMhwKTAprNWo7yeA88VRdDQeLYHwSxx7Im2wQPJUeLBWI X-Received: by 2002:a05:6a00:1f13:b0:567:546c:718b with SMTP id be19-20020a056a001f1300b00567546c718bmr13895042pfb.17.1668431981404; Mon, 14 Nov 2022 05:19:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668431981; cv=none; d=google.com; s=arc-20160816; b=wnCBUpN3WsjsM6fCOw080QFP50zhwNgoz3RwD3zUau12RCNRdg/A+OsaIrD0Cw23JD 3Fo9v56LKvAyRVHCfba/Vw4YQ9KpzofvQHBmEv222WCW5QcRQIejefQDMgMqgutRXDze AuU2L7g4ydTEaT9ugQ0O6u88uDE4NNG5TdmiPppBBZYP7bz5JJWhba+jY0+XoMPYcIC1 ahbQlgUSJt3AGTIPal1YCmmGg8kGh7TiqSqnZYNOUqSqCriW1dTIz1yzdGx4r1LXPoLo adEcdGFeEMIAqyQAYA3oQ69aoUmuUNaLLz8coeaR+s771FdC3OEYx13tLmnDe/sWdnRd Mn7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=QbjuoRrIf4yoLtJPrfhCjpRfUTSXH41VEourASZkn8s=; b=k+h2UocrOQU0VjjVz45Q7fQGG5gDi+Or2SJpGZBHF7i/3207OawM4r33E295qUHr3i PabDEeCFt+YET9/XannK1eRz+SOaaBKnwCt9C2tgm6TBxGmqKegccLUJ+wtiR/aS0nZR sXIMhuGpgEwqr8ebHWpaFg44d4G7zB7l456+UAhIiSAQ1AgvYOR6pcssVmYv4hMr1kma QNrT6T2Cxf5VdD09ATes/Jguepo6D8QT7EkpJhW8nAM7IRh1iITY5/TyHYGD0hd3kmiD tZk29aCJ8xXDSJhnaQNg+GS/HcaxMo2MAVYCsU+ppuODtfzBFnfI58GjzJqRvgbut3kz QMIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Xpf3Gvnj; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k13-20020a6555cd000000b004700981177dsi9781266pgs.528.2022.11.14.05.19.29; Mon, 14 Nov 2022 05:19:41 -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=@gmail.com header.s=20210112 header.b=Xpf3Gvnj; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237094AbiKNMUp (ORCPT + 88 others); Mon, 14 Nov 2022 07:20:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229647AbiKNMUn (ORCPT ); Mon, 14 Nov 2022 07:20:43 -0500 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3483222A0; Mon, 14 Nov 2022 04:20:42 -0800 (PST) Received: by mail-lj1-x234.google.com with SMTP id d20so12895033ljc.12; Mon, 14 Nov 2022 04:20:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:from:to :cc:subject:date:message-id:reply-to; bh=QbjuoRrIf4yoLtJPrfhCjpRfUTSXH41VEourASZkn8s=; b=Xpf3GvnjHi39RV0QhlmLV4yQfSnW6zSwPOneEsYhjx1wEbp5a7FVesMP1t6wPvJmFE kDgKulspLcq8BAm8DeAGhy4u+flrdJDGpBbWxYYSHXNhu9PhO4I7CXMgslryiD7iuKpe ryYYtRrL1HdCeD3WLoJj1w/rPQgbNVwc68Ly49cFKMOrXpgin2yCgB9TGyGb7aievrkT 6J2xjPnb75z1NcV0Rvmw8dwj/Prw9Fag8nLDU5h2L9ot8nFUh2vPSkTW2x2maswdwIk4 LWBrcxjQAz90xUqX7aq9aYizbEEJrUZRHrpj0+YGqp1ffNX0gKXQAxjJAUL+f+UPhRiK 6zpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QbjuoRrIf4yoLtJPrfhCjpRfUTSXH41VEourASZkn8s=; b=pdutFUMM1T731gynn7FOEymB0/3GpbJZwCBD+ucMuFoFMlftXbE191RgojyX5yVxNE CHwVzxalFkLJI8noq1aB4jEUubMmZMsA7NB8dwMW+6IjAWmViSQLRNyMaUJMBbOXLyru +/3LVw5NCrlcGCuWzuFarHCdEJMg4qFQVOGtMJhZUDIAINVu3lN2soeCPD1+N7b/OSEb Xocfo4FZHhowgCi5SQAa67+r4cU2XrX2vNieyvXSZk0pZjxgITfblj9ES6U0OCD8rM47 mPPfwjUlVziNXf87yA6AAo75sR+VD5QMw57yTLKHUEjFjJxa2RqEyuUEUv7WSdLJFqlf JjhQ== X-Gm-Message-State: ANoB5pl2CmXOi+r85gecEqyJNnOf6KPS2GYbS4ZukOa2vM83xKv7DzQA Ml5MZHjZOpfN0kSdtKV/tOE= X-Received: by 2002:a2e:7219:0:b0:277:5e9d:508a with SMTP id n25-20020a2e7219000000b002775e9d508amr4309942ljc.191.1668428440816; Mon, 14 Nov 2022 04:20:40 -0800 (PST) Received: from pc636 (host-90-235-0-38.mobileonline.telia.com. [90.235.0.38]) by smtp.gmail.com with ESMTPSA id p21-20020a056512235500b00498fc3d4d15sm1809497lfu.190.2022.11.14.04.20.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 04:20:40 -0800 (PST) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Mon, 14 Nov 2022 13:20:33 +0100 To: Joel Fernandes Cc: Uladzislau Rezki , linux-kernel@vger.kernel.org, paulmck@kernel.org, rcu@vger.kernel.org Subject: Re: [PATCH v2] rcu/kfree: Do not request RCU when not needed Message-ID: References: <20221109024758.2644936-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 > On Thu, Nov 10, 2022 at 03:01:30PM +0100, Uladzislau Rezki wrote: > > > Hi, > > > > > > On Thu, Nov 10, 2022 at 8:05 AM Uladzislau Rezki wrote: > > > > > > > > On ChromeOS, using this with the increased timeout, we see that we > > > > almost always > > > > > never need to initiate a new grace period. Testing also shows this frees > > > > large > > > > > amounts of unreclaimed memory, under intense kfree_rcu() pressure. > > > > > > > > > > Signed-off-by: Joel Fernandes (Google) > > > > > --- > > > > > v1->v2: Same logic but use polled grace periods instead of sampling > > > > gp_seq. > > > > > > > > > > kernel/rcu/tree.c | 8 +++++++- > > > > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > > > > > > > diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c > > > > > index 591187b6352e..ed41243f7a49 100644 > > > > > --- a/kernel/rcu/tree.c > > > > > +++ b/kernel/rcu/tree.c > > > > > @@ -2935,6 +2935,7 @@ struct kfree_rcu_cpu_work { > > > > > > > > > > /** > > > > > * struct kfree_rcu_cpu - batch up kfree_rcu() requests for RCU grace > > > > period > > > > > + * @gp_snap: The GP snapshot recorded at the last scheduling of monitor > > > > work. > > > > > * @head: List of kfree_rcu() objects not yet waiting for a grace period > > > > > * @bkvhead: Bulk-List of kvfree_rcu() objects not yet waiting for a > > > > grace period > > > > > * @krw_arr: Array of batches of kfree_rcu() objects waiting for a > > > > grace period > > > > > @@ -2964,6 +2965,7 @@ struct kfree_rcu_cpu { > > > > > struct kfree_rcu_cpu_work krw_arr[KFREE_N_BATCHES]; > > > > > raw_spinlock_t lock; > > > > > struct delayed_work monitor_work; > > > > > + unsigned long gp_snap; > > > > > bool initialized; > > > > > int count; > > > > > > > > > > @@ -3167,6 +3169,7 @@ schedule_delayed_monitor_work(struct kfree_rcu_cpu > > > > *krcp) > > > > > mod_delayed_work(system_wq, &krcp->monitor_work, > > > > delay); > > > > > return; > > > > > } > > > > > + krcp->gp_snap = get_state_synchronize_rcu(); > > > > > queue_delayed_work(system_wq, &krcp->monitor_work, delay); > > > > > } > > > > > > > > > How do you guarantee a full grace period for objects which proceed > > > > to be placed into an input stream that is not yet detached? > > > > > > > > > Just replying from phone as I’m OOO today. > > > > > > Hmm, so you’re saying that objects can be queued after the delayed work has > > > been queued, but processed when the delayed work is run? I’m looking at > > > this code after few years so I may have missed something. > > > > > > That’s a good point and I think I missed that. I think your version did too > > > but I’ll have to double check. > > > > > > The fix then is to sample the clock for the latest object queued, not for > > > when the delayed work is queued. > > > > > The patch i sent gurantee it. Just in case see v2: > > You are right and thank you! CBs can be queued while the monitor timer is in > progress. So we need to sample unconditionally. I think my approach is still > better since I take advantage of multiple seconds (I update snapshot on every > CB queue monitor and sample in the monitor handler). > > Whereas your patch is snapshotting before queuing the regular work and when > the work is executed (This is a much shorter duration and I bet you would be > blocking in cond_synchronize..() more often). > There is a performance test that measures a taken time and memory footprint, so you can do a quick comparison. A "rcutorture" can be run with various parameters to figure out if a patch that is in question makes any difference. Usually i run it as: #! /usr/bin/env bash LOOPS=10 for (( i=0; i<$LOOPS; i++ )); do tools/testing/selftests/rcutorture/bin/kvm.sh --memory 10G --torture rcuscale --allcpus --duration 1 \ --kconfig CONFIG_NR_CPUS=64 \ --kconfig CONFIG_RCU_NOCB_CPU=y \ --kconfig CONFIG_RCU_NOCB_CPU_DEFAULT_ALL=y \ --kconfig CONFIG_RCU_LAZY=n \ --bootargs "rcuscale.kfree_rcu_test=1 rcuscale.kfree_nthreads=16 rcuscale.holdoff=20 rcuscale.kfree_loops=10000 torture.disable_onoff_at_boot" --trust-make echo "Done $i" done just run it from your linux sandbox. -- Uladzislau Rezki