Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp341278rwb; Wed, 14 Dec 2022 18:22:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf5fiwN1si8LYFEsIowf+ivoo9IhvdqB7ow37IB4uD5+27bbTgWgYPumBCZknGTGb1RiFTrN X-Received: by 2002:a05:6a20:4990:b0:ad:c4e5:5a41 with SMTP id fs16-20020a056a20499000b000adc4e55a41mr11556315pzb.21.1671070976678; Wed, 14 Dec 2022 18:22:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671070976; cv=none; d=google.com; s=arc-20160816; b=bx7I4JgmvzozhhPVFtYT6cQ25p2hcX1UyYCT9kR9Xatc6/ZDJ6/aSKQO7zVGkYTtVh RWzqu8+pyHgdrgkZqorQ9F7nsC77eEoSIOJH0BE7kKgN1hDARDw0PYbdeaVmIjiBRSYP /1oNDt3nG1kxYerTt+ed44gOAInIal2wRAhm7stSIsgyUPGed90jbxje3pD64SE+Uoaa Zf88JYEenbUAkSjBU+KxZIyyOYUg/IH3iwKpjkjwRpgcANkG2QkWj8JlHqUit0Ln92qR VSNxF+/x1gqxKP4KetDkdSPfiPSkfRXZr9333718hkeOKVhszm2CIg4od2TvOY3Sg9K+ lQqw== 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-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=5lyMI2cHsHtcGzji1JkVnFX7ovIt/pZ3RPfdo9AC4iw=; b=ktNDgp9aTONjgPbwvHlfLd3tFuNthN4RepiqDPjM20GetlxnYpM7EDeYj/an9dSrU3 nSUh7lsHmaqZPmx68X9fHXNP5uXtN2VXQ5wYGSrT8OZdwIjz88WBlA/pZ+ghSq77aSWW Cd9SvDRaUxT8xpXNXGHS1AsWaQ5geTzfYIgj+G+Z75mj93tc4jPfb37N43DiVEn+QoBf 1NIeCkuMQZqPQJxoU+lqIHkDAJUuH++uqPgtA0sNtxgX3tynTvICN2n6LObRlhySjJGD HdUplFxionD2u4pB/RRHX9XKiObWlO1C5kbLdTSjuRabAe4PwCCRvBVy8iFq/JK4nMZY Y/Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=obsJuRgc; 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 p125-20020a634283000000b0047874cf7b40si1529813pga.178.2022.12.14.18.22.47; Wed, 14 Dec 2022 18:22:56 -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=obsJuRgc; 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 S229484AbiLOBjp (ORCPT + 70 others); Wed, 14 Dec 2022 20:39:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbiLOBjm (ORCPT ); Wed, 14 Dec 2022 20:39:42 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FB371EAE0; Wed, 14 Dec 2022 17:39:41 -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 ams.source.kernel.org (Postfix) with ESMTPS id 35407B81AD3; Thu, 15 Dec 2022 01:39:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C96F0C433F0; Thu, 15 Dec 2022 01:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671068378; bh=s6b0uszi3DpFRj6ZPXGBLSj2n0806qTbbl7XXYe9TSw=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=obsJuRgco9TTNdcWHiJmTFbt3bu81Pjuf7EuJfmhooUlDQyBiNnLDqaJc5Qw67xVs 9joX6AkbHN/I69XqpylEyti2JvGoEg2j1jwieDXhcOCgPOMo0Xv6LEZ4AfTov5LRWD PNv4wteumSDMDVSA8SPv7dsr8FIp35LKqXynHlZ0Xw3ZzVz3IZqjIVPPInBi4BigV5 rnPCno/cExZVdEGvJXSd9FWM/sk6XnSmlzYfxVnCCAxpeyJzwToZLHhJSDRP83xQE+ xbcWpTByJv4t/zsf1PbNLPSfan6WOsum/7CHM3B70P7vVPa2/+NO6xIWg0TEacQi9l IJSfa7bhZ7Qnw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 657165C0A6A; Wed, 14 Dec 2022 17:39:38 -0800 (PST) Date: Wed, 14 Dec 2022 17:39:38 -0800 From: "Paul E. McKenney" To: Joel Fernandes Cc: boqun.feng@gmail.com, frederic@kernel.org, neeraj.iitr10@gmail.com, urezki@gmail.com, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC] srcu: Yet more detail for srcu_readers_active_idx_check() comments Message-ID: <20221215013938.GF4001@paulmck-ThinkPad-P17-Gen-1> Reply-To: paulmck@kernel.org References: <20221214191355.GA2596199@paulmck-ThinkPad-P17-Gen-1> <20221214212455.GA4001@paulmck-ThinkPad-P17-Gen-1> <20221215000433.GD4001@paulmck-ThinkPad-P17-Gen-1> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 On Wed, Dec 14, 2022 at 08:34:03PM -0500, Joel Fernandes wrote: > On Wed, Dec 14, 2022 at 7:04 PM Paul E. McKenney wrote: > > > > On Wed, Dec 14, 2022 at 11:14:48PM +0000, Joel Fernandes wrote: > > > On Wed, Dec 14, 2022 at 11:10 PM Joel Fernandes wrote: > > > > > > > > On Wed, Dec 14, 2022 at 11:07 PM Joel Fernandes wrote: > > > > > > > > > > On Wed, Dec 14, 2022 at 9:24 PM Paul E. McKenney wrote: > > > > > > > I also did not get why you care about readers that come and ago (you > > > > > > > mentioned the first reader seeing incorrect idx and the second reader > > > > > > > seeing the right flipped one, etc). Those readers are irrelevant > > > > > > > AFAICS since they came and went, and need not be waited on , right?. > > > > > > > > > > > > The comment is attempting to show (among other things) that we don't > > > > > > need to care about readers that come and go more than twice during that > > > > > > critical interval of time during the counter scans. > > > > > > > > > > Why do we need to care about readers that come and go even once? Once > > > > > they are gone, they have already done an unlock() and their RSCS is > > > > > over, so they need to be considered AFAICS. > > > > > > > > > > > > > Aargh, I meant: "so they need to be considered AFAICS". > > > > > > Trying again: "so they need not be considered AFAICS". > > > > Give or take counter wrap, which can make it appear that still-present > > readers have finished. > > Ah you mean those flood of readers affect the counter wrapping and not > that those readers have to be waited on or anything, they just happen > to have a side-effect on *existing readers* which need to be waited > on. Exactly, that flood of readers could potentially result in a counter-wrap-induced too-short SRCU grace period, and it is SRCU's job to avoid that, and specifically the job of the code that this comment lives in. > Thanks a lot for this explanation, this part I agree. Readers that > sampled the idx before the flip happened, and then did their > lock+unlock counter increments both after the flip, and after the > second unlock counter scan (second scan), can mess up the lock > counters such that the second scan found lock==unlock, even though it > is not to be due to pre-existing readers. But as you pointed out, > there have to be a substantially large number of these to cause the > equality check to match. This might be another reason why it is > important to scan the unlocks first, because the locks are what have > to cause the wrap around of the lock counter. Instead if you counted > locks first, then the unlocks would have to do the catching up to the > locks which are much fewer than a full wrap around. True enough! > I still don't see why this affects only the first reader. There could > be more than 1 reader that needs to be waited on (the readers that > started before the grace period started). Say there are 5 of them. > When the grace period starts, the interfering readers (2^32 of them or > so) could have sampled the old idx before the flip, and then do > lock+unlock (on that old pre-flip() idx) in quick succession after the > smp_mb() in the second srcu_readers_active_idx_check(). That causes > those 5 poor readers to not be waited on. Granted, any new readers > after this thundering herd should see the new idx and will not be > affected, thanks to the memory barriers. Yes, there could be quite a few such readers, but it only takes one messed-up reader to constitute a bug in SRCU. ;-) > Still confused, but hey I'll take it little at a time ;-) Also thanks > for the suggestions for litmus tests. Agreed, setting this sort of thing aside for a bit and then coming back to it can be helpful. Thanx, Paul > Cheers, > > - Joel > > > > Anyway, my 1 year old son is sick so signing off for now. Thanks. > > > > Ouch! I hope he recovers quickly and completely!!! > > > > Thanx, Paul