Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1766830lql; Wed, 13 Mar 2024 07:41:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUGZ+vR9ytI72P3TVFk0usupwzg03uRKaP8/M+IqP+khOeqlU/BSzoY/f77W63YkCnIQw+egf9rzSwuQ7CBHrPMfZD1NLrlQTVqHnOaUg== X-Google-Smtp-Source: AGHT+IHq5a9FV/jB3GIo71CGezc8IPTmCQZyzxszyMGZS8BZnjKCY4VqK0r3NA4EgcJLF9TsB7gS X-Received: by 2002:a05:620a:1448:b0:789:c8a9:c442 with SMTP id i8-20020a05620a144800b00789c8a9c442mr32760qkl.44.1710340864712; Wed, 13 Mar 2024 07:41:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710340864; cv=pass; d=google.com; s=arc-20160816; b=zYeF6iUW6PDdUy+KHQJVrsrt1h6va3JTafCT7OQzFk5EwNjRoyMCBNxe70UiOz6N2c l7HEMWbetM+Bip6ysKW2tRYlc/orvYWcKD2M3BL1JTP2NpHPIFELOrr4F4hFnyG5to/L w0Sw1Gibmd08l3vlc0C5f+QE//eFazpAFmhcOMFc04vq6bRNstLdhuXCn3loCBMgStQx S2PfSim9Yj+BunEfE+q2NidshIxjZNF36cqR1Fc4+VEWcim0di5hoVY0QmZ2CS71Zo4J TLm85qhGfrWcA1cWIOvrzg98SD4pDkbS6Hs1ZilQlR7MdZpgBoMVNCw7lGNCJrKgaupg 0JSQ== 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=wwH7Po5mYA7bjttrElAdnD+M7EOKKFjEG6xtlrYwvBg=; fh=fT6ZH9243iG19NqLY2J9ZxehKhnts4GKwCW8WbChDDA=; b=FsCR16swf6tW4pO1L2FfuRQoQ5oC61N3zu3PoEtkLDLj5rYPPgSjxO7lYNfjF/dYrN juRSnA8TI6p+p1GcJFzRgcPRjPom5gUexqjAMtvDSGh4k/OEueONfHccUQSBFy28rIwl tF4U3ZOGWc+CCpLcyqVoBzmsD0hCYFNrz9gE+hS7vq7LIfW62Z90+WHpHtDGwSiiegHY Aul/ovSnY6J41mgJ0PvxAqEj1njiBUX6dVQ3AjxcdzSxa5Sp18JbyDK2HdCw/ieJKse6 Yk4qy54fJPLtZws8xP9o8M/6zzCe1hYwnNMmqmehP1ljHi7qVTlIWC9+IFE67mx+vinO b/TA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=eX0ymyI5; arc=pass (i=1 spf=pass spfdomain=joelfernandes.org dkim=pass dkdomain=joelfernandes.org); spf=pass (google.com: domain of linux-kernel+bounces-101629-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101629-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z21-20020ae9c115000000b007883f93585fsi9895716qki.458.2024.03.13.07.41.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 07:41:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-101629-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=eX0ymyI5; arc=pass (i=1 spf=pass spfdomain=joelfernandes.org dkim=pass dkdomain=joelfernandes.org); spf=pass (google.com: domain of linux-kernel+bounces-101629-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-101629-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 D0A531C21CAE for ; Wed, 13 Mar 2024 14:41:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA8B24A0C; Wed, 13 Mar 2024 14:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="eX0ymyI5" Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (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 300BC290A for ; Wed, 13 Mar 2024 14:40:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710340855; cv=none; b=XmFGh5A11cBwRyTkYf0IDv8x7JpyMuZ5gh4cRyzwOJFSIDkY/naWE4U+gAcYJMDzmDKx+ahvz2fgS3+OorHSESRYWNUkOdGXsMvkvKNwUW1Ht1H3NJK5F6xy6SEHPwohgI93HY6s6KHyVc2X25ILyUDXg8LK+O6t8+KZKzaPdbI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710340855; c=relaxed/simple; bh=YSUjV/yHnDAZVgS3+ncJxNIQukG94Jfh316n+Q5XKik=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KNXFxCxbGERpJsFZ/i7A1SXTpCDKj6dW6p6AbtVLZSi7CxVIQKTOvRM80Y2JjaCULwJ9s0FRF/+pKcHxg1ijPBItT0eOCNZ0KNodG9n6sh++AHqKZGZTZqU8NY6Ikk4R93+nZShyEPwvO78cGqVAmO0C1AA6I8YzOSiyarqPDxs= 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=eX0ymyI5; arc=none smtp.client-ip=209.85.219.50 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-qv1-f50.google.com with SMTP id 6a1803df08f44-690be84583fso31662776d6.1 for ; Wed, 13 Mar 2024 07:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1710340853; x=1710945653; 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=wwH7Po5mYA7bjttrElAdnD+M7EOKKFjEG6xtlrYwvBg=; b=eX0ymyI5DeWKmGnbShb/DyQZD97bIJeXOh5GC86/Eaz6rVpzyksM13x2hLZsB7DsfX ZX8KT02phUVaAfGVTcGJEE37I1eUPVFZ9Iqa0heQxzgWbVfAOpoo82bwoQPpTCWwSQ3h FW4NnlrqntxdhWvhgT4R899DzEDYx5jhjbMgQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710340853; x=1710945653; 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=wwH7Po5mYA7bjttrElAdnD+M7EOKKFjEG6xtlrYwvBg=; b=sGd2JucrPHLdYzR9XNdUD0EWFMywcZHBJJ9Ja34NqAKetCF2VxVFUnVBFXeGqfNPSP Ky8u7CrkE1HQolo1xKG6G9QUQOH1SaS5CugsroKEoIYqVIQ4YZM08hBUn9RbZWCOvA4K q3uGs8OPDHeYq9aNiuHAH9aD5/6YsPlqvsg+VyAQb3qyg7Hwj1lknnaNMiPgzWyxzyvg 6kCf/Xjvjtd75ezqgQhursOS3qvID/9W7XsQ9p2uTs5ST+87Unfr8V3qmwt9sbyKLcRg OaUUc5mX8f89OT9q9RvwtWkSQ+x1DAO8O3ynNlcSNw3BwnGr/OwgbzIqpBveY27Jr2mS 9hrw== X-Forwarded-Encrypted: i=1; AJvYcCUMh85lQN00l41x02ILtAvnN/+RVjoLDeBoZU+CfCG61XOMTea7L5gnPscLoiyzYFGAKzQ7eoP9baNxTwk7EfNGopmOAVWNT1xaU/n5 X-Gm-Message-State: AOJu0YwB2SqCIUFH+pn9xF//jYt8E9h/w9rPbzCIfR4VvF1IKxktwtzO FqAF8YiCk4Riud3z6E2T+gX/WaFgAzPGmMj+0uJw3oT4WCpLZ4TcWmFlXSHfIM4= X-Received: by 2002:a0c:c445:0:b0:690:de2a:3f1f with SMTP id t5-20020a0cc445000000b00690de2a3f1fmr18603qvi.32.1710340852927; Wed, 13 Mar 2024 07:40:52 -0700 (PDT) Received: from [10.5.0.2] ([91.196.69.182]) by smtp.gmail.com with ESMTPSA id c2-20020a0ceb42000000b00690cba72427sm3560137qvq.33.2024.03.13.07.40.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Mar 2024 07:40:52 -0700 (PDT) Message-ID: Date: Wed, 13 Mar 2024 10:40:50 -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> From: Joel Fernandes In-Reply-To: <20240313083228.233247-1-Neeraj.Upadhyay@amd.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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? Also if you don't mind could you please rebase your patch on top of mine [1] ? I think it will otherwise trigger this warning in my patch: WARN_ON_ONCE(!rcu); Because I always assume there to be at least 2 wait heads at clean up time. [1] https://lore.kernel.org/all/20240308224439.281349-1-joel@joelfernandes.org/ Thanks! - Joel > + return start_new_poll; > + wait_head = first; > } > > - /* Inject a wait-dummy-node. */ > - llist_add(wait_head, &rcu_state.srs_next); > - > /* > * A waiting list of rcu_synchronize nodes should be empty on > * this step, since a GP-kthread, rcu_gp_init() -> gp_cleanup(),