Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp812066imm; Fri, 27 Jul 2018 06:36:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd8DVg9nRm6ZFTv7Hx2ioLzpaC0bX1xzzHUUFZIq1QU8JZI3gfGHRZ9QPMHCJ4cprqUfRcR X-Received: by 2002:a63:1722:: with SMTP id x34-v6mr6226130pgl.268.1532698574242; Fri, 27 Jul 2018 06:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532698574; cv=none; d=google.com; s=arc-20160816; b=yyfDaWc6pyca75g06l8+2y2Q1OG7Asjn/Qf1b8UBeid5aSr1V3OCVYvaWjua1l8kdc SJCqykT736M4SbEV9/SssX5XiGrBQlGnr9Ukszk6+oClpm9iB4l3kUdwUhAfrdmhRSTT O6lAS1llUPjo7ffyGKplGF/ACEoj5U61WpzT/RiYzlHCaE0Wajr77U9O6FK7RzGrjI2e ukqpHWZkzAcA8fA0kpZp5oE64kr5ejRNv1aSHJD4kQZajLgj1kW0ji9p0IYdV0IH+RL3 xHl/owVXL5iu1rftwVqUZ+P5XK2X5O50H1deY6EI/bINPCCBMb166/TvEIYAmIWqv+Yc o9kw== 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:arc-authentication-results; bh=ixnnlrxPj+aDxFaz8xJRzwRorrLeMVcUkv5dOTEE2dE=; b=HaQrE8+JF7B7s9oA1uPUgmPMXbniM029zKapIPQ997vx6XNTkjM4Um/Ot2elzF8F4K IxgdKWeZbWaw8tkZj2AuNY9TkYcKqPz16l/D13fGmdLrawuTgWe3zcuX035ycxFKq83T D96aAcU6K/ZkV+X976RxuYg0clisSdJYaUM6gviWXpfj4n6mW8XFu7bm1POAox6DkI4z RgdbWQewCXW8cIyQ7tW0Lb2jv7DPzDUcD2a3fnJIWjo6IY3tN3p0gDDhsd9mWrHhZiPe XYt0D0i8z2on+D3FL2JnAxgqes1QGXV+IsjgR8UNHQOEbd3j4EoYxBb/VbAOz2GmodFx nWbw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31-v6si3611352plj.216.2018.07.27.06.35.35; Fri, 27 Jul 2018 06:36:14 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730784AbeG0Oza (ORCPT + 99 others); Fri, 27 Jul 2018 10:55:30 -0400 Received: from foss.arm.com ([217.140.101.70]:43676 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730318AbeG0Oz3 (ORCPT ); Fri, 27 Jul 2018 10:55:29 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3EBF280D; Fri, 27 Jul 2018 06:33:32 -0700 (PDT) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0FF393F2EA; Fri, 27 Jul 2018 06:33:32 -0700 (PDT) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 92A131AE5252; Fri, 27 Jul 2018 14:33:32 +0100 (BST) Date: Fri, 27 Jul 2018 14:33:32 +0100 From: Will Deacon To: Waiman Long Cc: Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org, Joe Mario , Davidlohr Bueso Subject: Re: [PATCH v3] locking/rwsem: Exit read lock slowpath if queue empty & no writer Message-ID: <20180727133331.GC28549@arm.com> References: <1532459425-19204-1-git-send-email-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1532459425-19204-1-git-send-email-longman@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 24, 2018 at 03:10:25PM -0400, Waiman Long wrote: > It was discovered that a constant stream of readers with occassional > writers pounding on a rwsem may cause many of the readers to enter the > slowpath unnecessarily thus increasing latency and lowering performance. > > In the current code, a reader entering the slowpath critical section > will unconditionally set the WAITING_BIAS, if not set yet, and clear > its active count even if no one is in the wait queue and no writer > is present. This causes some incoming readers to observe the presence > of waiters in the wait queue and hence have to go into the slowpath > themselves. > > With sufficient numbers of readers and a relatively short lock hold time, > the WAITING_BIAS may be repeatedly turned on and off and a substantial > portion of the readers will go into the slowpath sustaining a rather > long queue in the wait queue spinlock and repeated WAITING_BIAS on/off > cycle until the logjam is broken opportunistically. > > To avoid this situation from happening, an additional check is added to > detect the special case that the reader in the critical section is the > only one in the wait queue and no writer is present. When that happens, > it can just exit the slowpath and return immediately as its active count > has already been set in the lock. Other incoming readers won't observe > the presence of waiters and so will not be forced into the slowpath. > > The issue was found in a customer site where they had an application > that pounded on the pread64 syscalls heavily on an XFS filesystem. The > application was run in a recent 4-socket boxes with a lot of CPUs. They > saw significant spinlock contention in the rwsem_down_read_failed() call. > With this patch applied, the system CPU usage went down from 85% to 57%, > and the spinlock contention in the pread64 syscalls was gone. > > v3: Revise the commit log and comment again. > v2: Add customer testing results and remove wording that may cause > confusion. > > Signed-off-by: Waiman Long > --- > kernel/locking/rwsem-xadd.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) My nits with the commit message have been addressed, so: Acked-by: Will Deacon Thanks! Will