Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5821250imm; Mon, 23 Jul 2018 06:42:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc/oZ7Sf88UbTETRSioHu2frrB/ZPj/rJKoldZJno2CGw09ZCMZht/qdobowsPdZmd2gulH X-Received: by 2002:a17:902:24e:: with SMTP id 72-v6mr7656106plc.74.1532353362254; Mon, 23 Jul 2018 06:42:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532353362; cv=none; d=google.com; s=arc-20160816; b=y/hWgqsbX3i0mxEyLa4aiR5vrz9z9xVQ6LrlafTeoBI0Ket3cQAurbRpQHfCHSPD+T AMuLYqzd9yBa4ACUkWy340e7mXw3PjdFHgnbTaszJ3XPJ8xRRCpJACnrls2652ZH5uiG Lj6t9BZDIHlWxEhXem4IrmHUqGQWz3F5w4VNoiQfOVgE8dnEYUQ6Ei5+ZAQTJymix62i fNzATCRSpPOYp5ci3dIe5d4tQskLnF11WOfsPER9pI0BUJcjyJPINXHQlrkxLAX1ThH3 BMUlvXk574fH4uA6O9ls4zWAbS7dtioYYqShZxIbgNJICTTcdmk/JtiLLnSuxy/KehJg Iv+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :arc-authentication-results; bh=xl5tM41pWiHMUO2CHHEkvvQj4sNqzdZcRqI3cEPqpYY=; b=WSV7LGSRvS0oUnXI8+HyrIZ/y3VPzPHLvGw2LWItr3KdX3JGJrIq+x9zrqaRqTDsZJ S14QjCgG+dNKJ21KIUweRRq92O+8sL5PFTJijWtZp/bIbawZqNuFvsB35e5zTEZAHakG MXlpyi9nIujBdzzA/CWpUhb5YkKVhQEmlIPXJKK4G3KfJePfI5pb6yKPFvDfLkk0qXHL HTp1FJNVJekX0qRtFPN1CvR64AYTfYQ3BF9X2nfNJR+HaS0NOi0vEQoHZ3jgs9e1PWPS i9C2B/7Da667tBQoS90cl1nZPzH+h/AMaAIb8v5T4e3VOQ+9BacxomAsaLUdkQU2uYyr TgBg== 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 o10-v6si7837114pls.188.2018.07.23.06.42.26; Mon, 23 Jul 2018 06:42:42 -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 S2388380AbeGWOmS convert rfc822-to-8bit (ORCPT + 99 others); Mon, 23 Jul 2018 10:42:18 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47564 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387956AbeGWOmS (ORCPT ); Mon, 23 Jul 2018 10:42:18 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D4A6A40241D7; Mon, 23 Jul 2018 13:40:58 +0000 (UTC) Received: from llong.remote.csb (dhcp-17-175.bos.redhat.com [10.18.17.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DDE72166BA0; Mon, 23 Jul 2018 13:40:58 +0000 (UTC) Subject: Re: [PATCH v2] locking/rwsem: Take read lock immediate if queue empty with no writer To: Davidlohr Bueso Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , linux-kernel@vger.kernel.org, Mark Ray , Joe Mario , Scott Norton References: <1531506653-5244-1-git-send-email-longman@redhat.com> <20180718161639.GT2494@hirez.programming.kicks-ass.net> <20180723040423.hntq6dzzzf3sagfb@linux-r8p5> From: Waiman Long Organization: Red Hat Message-ID: <9722ffd0-9adb-9ad1-a05b-25869c0b2e60@redhat.com> Date: Mon, 23 Jul 2018 09:40:58 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20180723040423.hntq6dzzzf3sagfb@linux-r8p5> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Content-Language: en-US X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Jul 2018 13:40:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Jul 2018 13:40:58 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'longman@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 07/23/2018 12:04 AM, Davidlohr Bueso wrote: > On Wed, 18 Jul 2018, Waiman Long wrote: > >> The key here is that we don't want other incoming readers to observe >> that there are waiters in the wait queue and hence have to go into the >> slowpath until the single waiter in the queue is sure that it probably >> will need to go to sleep if there is writer. >> >> With a constant stream of incoming readers, a major portion of them will >> observe the a negative count and be serialized to enter the slowpath. >> There are certainly other readers that do not observe the negative count >> in the in between period after one reader clear the count in the unlock >> path and a waiter set the count to negative again. Those readers can go >> ahead and do the read in parallel. But it is the serialized readers that >> cause the performance loss and the observation of spinlock contention in >> the perf output. > > This makes sense and seems feasible in that the optimization is done with > the wait_lock held. > >> >> It is the constant stream of incoming readers that sustain the spinlock >> queue and the repeated clearing and negative setting of the count. > > This would not affect optimistic spinners that haven't yet arrived at the > waitqueue phase because the lock is anonymously owned, so they won't spin > in the first place, right? The reader fastpath would have incremented the active count before entering the slowpath. The spinning writer, seeing a non-zero active count, will not attempt to steal the lock until the reader decrement the count and set the waiting bias in one atomic op. Nothing will happen before that. -Longman