Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1829693lql; Wed, 13 Mar 2024 09:13:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVpS5rmzxLep1uMECN4rk+aplB5Yv4xy2foRuq9LSAY+E8CQg55gkBb4EZhu5/UQKGymFcgRpVtThJnBI0nGFSqwL8KdcuY/1hhO4ifqA== X-Google-Smtp-Source: AGHT+IHd34L2x20une+HHxoYlJdgeGhhB1Q9FUoe6R3qyMNtEJxIholn6ZnTXHAVTEACIAfLRsWl X-Received: by 2002:a05:620a:4509:b0:788:1887:7621 with SMTP id t9-20020a05620a450900b0078818877621mr309410qkp.76.1710346433743; Wed, 13 Mar 2024 09:13:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710346433; cv=pass; d=google.com; s=arc-20160816; b=nKE3aMPsQrSjhw8hVe6jZ8n7/LihEFhhZrfJljPtpkSZud853XYHfxOU49pECwhrb7 jDd+gBWwsrlJantQfaQQF9QJnerkO5Hml0tdkqLoGUgYUd9/JuvyMCiliVvzAjCEmBLN hkJpfLHEjIe3g1DSPcHZ/B+knH7eASu/kFnIfOV70Ul1BrdPwXJF6gVJANBTZkyhMH1X CaoyHADRzC+i4GRbgyqH+6CW4qOZQ/wY+kOFyA0Nz+UIH9ni4j3LUAzNBD4kLurFJzmE pMUUQuREbGt7t+zORdu7tNx8B1s1+6EkG0IDeJ7t2Bc0gxQqpiAOIE+kmMtYjWPmkLiI b/ng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=zwnqsAsnQJNzhhnd2M+aClTGEWIUxWCyEYQGJKC7krI=; fh=X6loAOL6rJtC7M8yjlu+oqtlvsGDW3No0O6hxj/Gn7k=; b=o68L18RXoLocj3UX2NnHLQqMZZuTa6+iQ7V3hdu7zr69p+8WQ6wLtyXlW7H0a+w9Iw bLXBbsne9VOdd5pv0rFcrl6gEKj9xYMxbOYvPkOlkgs4aK0M3E2IT23tP2EE/+yoQXed ruSg3W0z7ujYIPmiUXGj418t29kuBp/WTJxmTA1NiysuWLDtMM6PHgj0qaAIC/3PMims 82RiUk5Ztr5uZY4vJDkt4k7igeUbRWdUytIiB6EUz5a/jSDC46Qq8JzSxHxbgxIQZ3Gi mWmxVTBBQtxvP3gPozvpjaU3DMXxyJ0LyuhIuWbq7TOONDjAbsV3j4fE1iI2JBzDpwIA cVyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=QzkDn3XF; arc=pass (i=1 spf=pass spfdomain=joelfernandes.org dkim=pass dkdomain=joelfernandes.org); spf=pass (google.com: domain of linux-kernel+bounces-101718-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101718-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id yf21-20020a05620a3bd500b007885eb686bfsi9440904qkn.785.2024.03.13.09.13.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 09:13:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101718-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=QzkDn3XF; arc=pass (i=1 spf=pass spfdomain=joelfernandes.org dkim=pass dkdomain=joelfernandes.org); spf=pass (google.com: domain of linux-kernel+bounces-101718-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101718-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3ADA21C21713 for ; Wed, 13 Mar 2024 16:13:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E4366482C6; Wed, 13 Mar 2024 16:13:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="QzkDn3XF" Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C0C6481C6 for ; Wed, 13 Mar 2024 16:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710346426; cv=none; b=M+++LMBzW+tX4wuuhSCDW6ajg2AMa/MkdKcQdyo1nbnIVIJoF0g3FNQbuA2YguguXKtEpAGP6+HCe7jWYaFuHvINuBORCGVL7ru66INVSd+24QUT3a7PzkATHmDRam5mX5QdIeymJ7cjFC1QNz1FZ5G7hU+AWOa9sYXNmOKyL7w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710346426; c=relaxed/simple; bh=jJmIDaRn0Or9FghTpyzKhcD4M+MhdevWRGCsllzE61c=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=GInfaT+eJkKaa+gpYk8OnQwXNEhyQ3OpuzURokQ+0Y06vcKiVQlkwXEE2SOGOmVpJGTzdm0cSa4d8x9+tvjWuQdIcHETXmmtedOdO/+nyJufLV/vcuXiMo0llmwQvmqvIGekHUQf2KSXo1d180jTmXop2Djz7iGtpGFBrcUZvXk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org; spf=pass smtp.mailfrom=joelfernandes.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b=QzkDn3XF; arc=none smtp.client-ip=209.85.160.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=joelfernandes.org Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-42edb7a1114so24826231cf.1 for ; Wed, 13 Mar 2024 09:13:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1710346423; x=1710951223; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=zwnqsAsnQJNzhhnd2M+aClTGEWIUxWCyEYQGJKC7krI=; b=QzkDn3XFZGX7d3nymNQggGPjB0+vntqH+HKS+iFcp2x+zd6gGFutBXEsB5x6W/pLAt jDsQeTIT6qoUi/Hhm5Jak/8HBMjmMBD6is+qLv2jO2MDEJyNIbUB77bmoxdAFTC1MLKK 5jxhKBJKqaXyeQEKzLwRdo26KdwL1BV4at/Uw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710346423; x=1710951223; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zwnqsAsnQJNzhhnd2M+aClTGEWIUxWCyEYQGJKC7krI=; b=pwlcMdOQBgDsXiSLX1ZokvuE68LM1Yd+8wGi8rN/H9LGPscS2L9CikVLjmVHc51hlU XbzHVbHHHBCI+3nJ1UaIW9DEd3Jb98GSSD4epxim0x9qZUAFxouVHBPg7IGtwZtxqky+ CIr65RHLK/TcfnA+fdtzpX26UkzWLDv3LEJhG0sS7UoxSqmGla8eizL2yuty0gKryZGG KlyEReHt2veWMvm7LUGlWjTNS3kFfoV9ysJc2uBNDoQ+WQpTgXFW791N85hxcKWwnCKE Imw/KTdoFIaIKA2NCL3cwXoklLLNhkuyvvQAXbFgumxccsCeFH6J3//iA5WyXgibnvc3 F5Og== X-Forwarded-Encrypted: i=1; AJvYcCXyUYOBSlp4hL0mLccPi1BXxNnXrzAMJJOEbgtzBw+zF4itQZVfhCBU7wvPthh5r8RRxjCAuUNDWthxb5oidBu76+Ep5GEVxiwCgwMl X-Gm-Message-State: AOJu0YyRipdiNTenV1LU43R+nz26zO6A7NPTv2DbgSxYckAEJUq4XAWM sfn7jd0A36r+/KaHssxn6iVtrZ70ja6iepSdEaDCQcSoKK7j4o1DQMJHRJhn/mA= X-Received: by 2002:a05:622a:295:b0:42e:f7cf:ff84 with SMTP id z21-20020a05622a029500b0042ef7cfff84mr17072690qtw.52.1710346423215; Wed, 13 Mar 2024 09:13:43 -0700 (PDT) Received: from [10.5.0.2] ([91.196.69.182]) by smtp.gmail.com with ESMTPSA id u25-20020ac87519000000b0042ec8412342sm4954841qtq.80.2024.03.13.09.13.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Mar 2024 09:13:42 -0700 (PDT) Message-ID: <06e83751-3aef-4c7d-b4d4-e10e7da6d50a@joelfernandes.org> Date: Wed, 13 Mar 2024 12:13:40 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] rcu: Reduce synchronize_rcu() delays when all wait heads are in use Content-Language: en-US To: Neeraj Upadhyay , paulmck@kernel.org, frederic@kernel.org, josh@joshtriplett.org, boqun.feng@gmail.com, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, jiangshanlai@gmail.com, qiang.zhang1211@gmail.com Cc: rcu@vger.kernel.org, linux-kernel@vger.kernel.org, neeraj.upadhyay@kernel.org References: <20240313083228.233247-1-Neeraj.Upadhyay@amd.com> <6c1ac571-b758-4168-a992-3704c60dba61@amd.com> From: Joel Fernandes In-Reply-To: <6c1ac571-b758-4168-a992-3704c60dba61@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/13/2024 12:04 PM, Neeraj Upadhyay wrote: > Hi Joel, > > On 3/13/2024 8:10 PM, Joel Fernandes wrote: >> Hi Neeraj, >> >> On 3/13/2024 4:32 AM, Neeraj Upadhyay wrote: >>> When all wait heads are in use, which can happen when >>> rcu_sr_normal_gp_cleanup_work()'s callback processing >>> is slow, any new synchronize_rcu() user's rcu_synchronize >>> node's processing is deferred to future GP periods. This >>> can result in long list of synchronize_rcu() invocations >>> waiting for full grace period processing, which can delay >>> freeing of memory. Mitigate this problem by using first >>> node in the list as wait tail when all wait heads are in use. >>> While methods to speed up callback processing would be needed >>> to recover from this situation, allowing new nodes to complete >>> their grace period can help prevent delays due to a fixed >>> number of wait head nodes. >>> >>> Signed-off-by: Neeraj Upadhyay >>> --- >>> kernel/rcu/tree.c | 27 +++++++++++++-------------- >>> 1 file changed, 13 insertions(+), 14 deletions(-) >>> >>> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c >>> index 9fbb5ab57c84..bdccce1ed62f 100644 >>> --- a/kernel/rcu/tree.c >>> +++ b/kernel/rcu/tree.c >>> @@ -1470,14 +1470,11 @@ static void rcu_poll_gp_seq_end_unlocked(unsigned long *snap) >>> * for this new grace period. Given that there are a fixed >>> * number of wait nodes, if all wait nodes are in use >>> * (which can happen when kworker callback processing >>> - * is delayed) and additional grace period is requested. >>> - * This means, a system is slow in processing callbacks. >>> - * >>> - * TODO: If a slow processing is detected, a first node >>> - * in the llist should be used as a wait-tail for this >>> - * grace period, therefore users which should wait due >>> - * to a slow process are handled by _this_ grace period >>> - * and not next. >>> + * is delayed), first node in the llist is used as wait >>> + * tail for this grace period. This means, the first node >>> + * has to go through additional grace periods before it is >>> + * part of the wait callbacks. This should be ok, as >>> + * the system is slow in processing callbacks anyway. >>> * >>> * Below is an illustration of how the done and wait >>> * tail pointers move from one set of rcu_synchronize nodes >>> @@ -1725,15 +1722,17 @@ static bool rcu_sr_normal_gp_init(void) >>> return start_new_poll; >>> >>> wait_head = rcu_sr_get_wait_head(); >>> - if (!wait_head) { >>> - // Kick another GP to retry. >>> + if (wait_head) { >>> + /* Inject a wait-dummy-node. */ >>> + llist_add(wait_head, &rcu_state.srs_next); >>> + } else { >>> + // Kick another GP for first node. >>> start_new_poll = true; >>> - return start_new_poll; >>> + if (first == rcu_state.srs_done_tail) >> >> small nit: >> Does done_tail access here need smp_load_acquire() or READ_ONCE() to match the >> other users? >> > > As srs_done_tail is only updated in RCU GP thread context, I think it is not required. > Please correct me if I am wrong here. But will KCSAN not scream that its a data race? thanks, - Joel