Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4347544ybp; Mon, 7 Oct 2019 07:12:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqza7duvW5i0k3oY1eAv56ZHbr5P0AdskcRbnQErt+UPUTD3a58/F4hWIblmzT36N/7U6rXO X-Received: by 2002:a50:a557:: with SMTP id z23mr28391705edb.99.1570457520967; Mon, 07 Oct 2019 07:12:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570457520; cv=none; d=google.com; s=arc-20160816; b=kW04ZiBvJFVop5ZamNNc9EEJxV31kmYkxxxTkV/ea5qDfhyIVK8BsV5S1B1FRY5QoO FobtTb7Lvnp65YL7yMdYebwdyy2t3+h9qr/ek96P0YrmwmXNMGNcK48UGSKKSdzktxMw Niom79852pBvjhr3gL12LpnG5Bw91W6wu67gTN702NzMjKiNxytDxQeZPdUW8jsApGD3 yNYNZoxcPXb0N0b3IjeWqOD5HO7+QRa/xE5iwL8LWawpZ0K6EXDWyQDQzLsuLUaNW7AW 9wDKa60n6I/dJ5gZF81COD07a/Sq+Z9Q3jWAMKvcD4oBEV9sCkIU01d8perHZdZjNCNA B6WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=rYpv67KE8KyhoNMEueSVPgm1SQo8Rv27T8BgDgsxFHk=; b=e7zoIVnX2+kUGa+c3Y3vOxcm2h3FC8sK/SLgyv20yV2SzXu/pXRnlA8zYM0+DB06Kn REI8IT74uSbqG/yLZHwwjuUiX4f27pZC/aE+nxarHddQHDONo/ndtauBpCgQ7wzsk3C1 b6SgCntlj9//lo/bICMXKEH+tQPrp3+o7MRlBAGbnLTJngKDzUuD79Od9N1xmT/D5YEf nnz+4rYncbgDky2hJW5TPIeWZ8iKmJaSYyBoWjGwLIgQfx2DumseSU3iuvJHx8TDdZdb qV0c3BVVEVbAMV5+gZNZAmpOQdLz0reolCyfVUE/DzszHhtGXviYrMnp1WMfL5/Kdwvu 9/bQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p15si8688741eda.294.2019.10.07.07.11.37; Mon, 07 Oct 2019 07:12:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727920AbfJGOJw (ORCPT + 99 others); Mon, 7 Oct 2019 10:09:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56418 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727744AbfJGOJw (ORCPT ); Mon, 7 Oct 2019 10:09:52 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB8F82112; Mon, 7 Oct 2019 14:09:51 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.44]) by smtp.corp.redhat.com (Postfix) with SMTP id 3EEEE1001B11; Mon, 7 Oct 2019 14:09:44 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 7 Oct 2019 16:09:50 +0200 (CEST) Date: Mon, 7 Oct 2019 16:09:42 +0200 From: Oleg Nesterov To: Joel Fernandes Cc: linux-kernel@vger.kernel.org, bristot@redhat.com, peterz@infradead.org, paulmck@kernel.org, rcu@vger.kernel.org, Josh Triplett , Lai Jiangshan , Mathieu Desnoyers , "Paul E. McKenney" , Steven Rostedt Subject: Re: [PATCH] Remove GP_REPLAY state from rcu_sync Message-ID: <20191007140942.GA12213@redhat.com> References: <20191004145741.118292-1-joel@joelfernandes.org> <20191004154102.GA20945@redhat.com> <20191004163732.GA253167@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191004163732.GA253167@google.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Mon, 07 Oct 2019 14:09:52 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/04, Joel Fernandes wrote: > > On Fri, Oct 04, 2019 at 05:41:03PM +0200, Oleg Nesterov wrote: > > On 10/04, Joel Fernandes (Google) wrote: > > > > > > Taking a step back, why did we intend to have > > > to wait for a new GP if another rcu_sync_exit() comes while one is still > > > in progress? > > > > To ensure that if another CPU sees rcu_sync_is_idle() (GP_IDLE) after you > > do rcu_sync_exit(), then it must also see all memory changes you did before > > rcu_sync_exit(). > > Would this not be better implemented using memory barriers, than starting new > grace periods just for memory ordering? A memory barrier is lighter than > having to go through a grace period. So something like: if the state is > already GP_EXIT, then rcu_sync_exit() issues a memory barrier instead of > replaying. But if state is GP_PASSED, then wait for a grace period. But these 2 cases do not differ. If we can use mb() if GP_EXIT, then we can do the same if state == GP_PASSED and just move the state to GP_IDLE, and remove both GP_PASSED/GP_REPLAY states. However, in this case the readers will need the barrier too, and rcu_sync_enter() will _always_ need to block (wait for GP). rcu_sync.c is "equivalent" to the following implementation: struct rcu_sync_struct { atomic_t writers; }; bool rcu_sync_is_idle(rss) { return atomic_read(rss->writers) == 0; } void rcu_sync_enter(rss) { atomic_inc(rss->writers); synchronize_rcu(); } void rcu_sync_exit(rss) { synchronize_rcu(); atomic_dec(rss->writers); } except - rcu_sync_exit() never blocks - synchronize_rcu/call_rci is called only if it is really needed. In particular, if 2 writers come in a row the 2nd one will not block in _enter(). Oleg.