Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp201776imm; Thu, 26 Jul 2018 17:03:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcXy+glmy6u6Yw8PjjBCoblfUrPZOssN+oIC1M7g6wSRizheWtZEij9UY93412gjPHqBMvX X-Received: by 2002:a62:789:: with SMTP id 9-v6mr4168681pfh.213.1532649825485; Thu, 26 Jul 2018 17:03:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532649825; cv=none; d=google.com; s=arc-20160816; b=qpo9ha0tjAHeSdASvigyVjcCPkW/9v3wf4NRwOXanMsJQfPxQqiZtyQ7X68nwXepnz fiet6pi1C7YiGUVHiok7+bhvnqAuFoV62vCbNQfJb4fZ2qLOjFi2isdlcIAY3kJaOjRd HPR4BXEzQaOg718Sk7B6PUpE+Uz2UVBxK9o1oFVnZpvVkel9M0Za4JIOEBzn20UYi8Xo WrOYphfttm6UoBh0+TDrA7sf3dq5NSyj8idkxM8DHm+B7khsOgTJpt3fLB8WJeH/dfKz jg9Wuh0jmEZAkE2HFO6ke7Z59WUs5e8jDCxsACS4r4GYany5L7KrkdNfxIykGBP57X67 8POQ== 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=KbbMKv5Yjsvdg4pr35E3topHY9bbIPRPBFT/BIWlv0Y=; b=dJpwZCWDzkmGBUqb49SdhaVEZRZ7ho8IKvvVoD9qnK7XDihXS5+6aON8VtbaxUphFp MENawW092ruISvV54W8MzN05ayuUi/hDUL5QCWhWpmxh3T0oDPkudGPgpNJQUj3be80f HNrBIo3cUDs6cf50j/2lctI7XKAUXV6FyeMxUoD2sNzCpkFTQwITQUU/jDqT2zC3A049 3lcP+CXTvp9TK4eVwPFW0DDa9ttlGktkEducJCKZmB6tH80Lz9tMB0Ln8DJpCNGJcrK/ uszZH+34ereur3Pd2LZjZmOalBzLjCA7nAH5HfDIFFmoy9RSjVxQaQJbjsG546MgzdDH JyWQ== 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 be5-v6si2443502plb.67.2018.07.26.17.03.25; Thu, 26 Jul 2018 17:03:45 -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 S1731903AbeG0BVa (ORCPT + 99 others); Thu, 26 Jul 2018 21:21:30 -0400 Received: from mx2.suse.de ([195.135.220.15]:49862 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731412AbeG0BVa (ORCPT ); Thu, 26 Jul 2018 21:21:30 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 445C9AE75; Fri, 27 Jul 2018 00:02:20 +0000 (UTC) Date: Thu, 26 Jul 2018 17:02:15 -0700 From: Davidlohr Bueso To: Waiman Long Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , linux-kernel@vger.kernel.org, Joe Mario Subject: Re: [PATCH v3] locking/rwsem: Exit read lock slowpath if queue empty & no writer Message-ID: <20180727000215.ez3el2tbbasxa5fk@linux-r8p5> References: <1532459425-19204-1-git-send-email-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <1532459425-19204-1-git-send-email-longman@redhat.com> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 24 Jul 2018, 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 Reviewed-by: Davidlohr Bueso