Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3933268yba; Wed, 17 Apr 2019 00:38:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxCfaA8AyFlYy1EvNMOom6zrk1rm1j4Fx/ZGyW0NiKBQx+ugqhZp/BwbrcF9F2fTkucYcVQ X-Received: by 2002:a65:43c3:: with SMTP id n3mr83309716pgp.375.1555486691569; Wed, 17 Apr 2019 00:38:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555486691; cv=none; d=google.com; s=arc-20160816; b=Ta4mHeT4IsPz12oGazA2Ra5b5WsK7SrpowWnQD208GRgn/x2v0GoqjRVLpGD1IpiAQ 0SXseXPJZuJuQxrk39Azwblx6zjIaQ2kW5b9WR+XQ8EUaGxLzXrHFyL62zBOrVvyJCYI qQmDyj3XNpVjV+L7J5t2J+5PvlyvTBTUkuh6jsBFkIU4ztjzdVGcI20yJB0MDG0x3R0k S2/F6zCdASqldOaCgz8/NBdKjjJaQuDA0Kfi49chN34KKIwLpo/Pv56YHY/aldtsi1jP +MMUnJ8OCTS+u8xmr6ZvUdIj3CxH+PuiAZzPxhsyABo89oer05QGTqaLNFSZeo9ctdQg 3uxw== 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:dkim-signature; bh=LpSOMcBlyIhKDhjISPyeoabpIEP0cf1quEet+iani6w=; b=iXJhXUDxftKDl14BLD1+s4oTdmKulRUz84Hdfi9TuhNkP3h87bNmpjhQe1Z0ZWUZHJ cAA2lDBKTw8d7osqeCyVp2KfecB4aAImCmrgvWuJhSmSNDbWiFWuQbJf5G5ICnpeghyj wff/ST8yEUdi8AE4CeK0IsXJno5+dhK2I3mVPEzAjnnAh3TH/xeHJHu+0QyYmZiaGmPc xPBVAdGU5nLzDtJ2PNNkBCfl9To/AyD/72DcJ4jyF/q+LSzQjMS7RL5eNWPEONdNSp1k kHzTnKmzkUL4e0RQrQ+mUZPM9lToWp/0gKfPUK16wnDQgEXRNGyX6Q0ohIM/vaW8LW09 T4TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=D2DW7Bml; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s20si39390112pgs.509.2019.04.17.00.37.56; Wed, 17 Apr 2019 00:38:11 -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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=D2DW7Bml; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731196AbfDQHgM (ORCPT + 99 others); Wed, 17 Apr 2019 03:36:12 -0400 Received: from merlin.infradead.org ([205.233.59.134]:54020 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725848AbfDQHgM (ORCPT ); Wed, 17 Apr 2019 03:36:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LpSOMcBlyIhKDhjISPyeoabpIEP0cf1quEet+iani6w=; b=D2DW7BmlhNdsVW2N0qdQU5a4Q Rh12MOnXCjmXuA5EvJUsZAN+IntE+AG0sQu2GM5pUT+nQVaD+ML2pB6XKdWlcT4U6lhqDa6rhPPRj eZ1tx6efRzTLZPydik65cMcS4dmTXzoyhdmquMC01ihvJJ+7O26gO1DcbR1tvIXQZpYBKIKYGQkMR ERe0HsoxVcJqq4S+BF72DY+L2uRGs/BAcnFnrrSuomZULtLLL4J82yJlxhJhJ8HILfKoW11zFvwAr lNzhFpcG18y4vdVDP+DQScSYYca10XAscnw/TbEkSehfzTJ/NubqC7aWDFyBfFZP2FXCU0PpOVRiw OuD1Wl7Ig==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGf6v-0005vA-44; Wed, 17 Apr 2019 07:36:01 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id D06F829B5293D; Wed, 17 Apr 2019 09:35:59 +0200 (CEST) Date: Wed, 17 Apr 2019 09:35:59 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , Will Deacon , Thomas Gleixner , linux-kernel@vger.kernel.org, x86@kernel.org, Davidlohr Bueso , Linus Torvalds , Tim Chen , huang ying Subject: Re: [PATCH v4 07/16] locking/rwsem: Implement lock handoff to prevent lock starvation Message-ID: <20190417073559.GZ4038@hirez.programming.kicks-ass.net> References: <20190413172259.2740-1-longman@redhat.com> <20190413172259.2740-8-longman@redhat.com> <20190416154937.GL12232@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 16, 2019 at 02:16:11PM -0400, Waiman Long wrote: > >> @@ -324,6 +364,12 @@ static void __rwsem_mark_wake(struct rw_semaphore *sem, > >> adjustment -= RWSEM_FLAG_WAITERS; > >> } > >> > >> + /* > >> + * Clear the handoff flag > >> + */ > > Right, but that is a trivial comment in the 'increment i' style, it > > clearly states what the code does, but completely fails to elucidate the > > code. > > > > Maybe: > > > > /* > > * When we've woken a reader, we no longer need to force writers > > * to give up the lock and we can clear HANDOFF. > > */ > > > > And I suppose this is required if we were the pickup of the handoff set > > above, but is there a guarantee that the HANDOFF was not set by a > > writer? > > I can change the comment. The handoff bit is always cleared in > rwsem_try_write_lock() when the lock is successfully acquire. Will add a > comment to document that. That doesn't help much, because it drops ->wait_lock between setting it and acquiring it. So the read-acquire can interleave. I _think_ it works, but I'm having trouble explaining how exactly. I think because readers don't spin yet and thus wakeups abide by queue order. And the other way around should have (write) spinners terminate the moment they see HANDOFF set by a readers, but I'm not immediately seeing that either. I'll continue staring at that.