From patchwork Fri Aug 30 14:14:01 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 2852084 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C67CE9F313 for ; Fri, 30 Aug 2013 14:14:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B1002205C2 for ; Fri, 30 Aug 2013 14:14:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0B023205AC for ; Fri, 30 Aug 2013 14:14:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756161Ab3H3OOH (ORCPT ); Fri, 30 Aug 2013 10:14:07 -0400 Received: from dkim1.fusionio.com ([66.114.96.53]:60306 "EHLO dkim1.fusionio.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755723Ab3H3OOE (ORCPT ); Fri, 30 Aug 2013 10:14:04 -0400 Received: from mx2.fusionio.com (unknown [10.101.1.160]) by dkim1.fusionio.com (Postfix) with ESMTP id 4F5A37C065C for ; Fri, 30 Aug 2013 08:14:04 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fusionio.com; s=default; t=1377872044; bh=D/+w+aOQWhGui2mIoCjecsUtqAIRR/90U3BnDA+5/GQ=; h=From:To:Subject:Date; b=mflaEIBulAUy7X/opAOVL+0IpJM7ZGwHTqX6wevft5lsFRjop5cGcxGV8aXNDye42 46xmIeXsjVkVFewK0REJCgjs2OdFCNficJ3gzLUiwJJ0/JeO8uYiai12z4fTbwjFHz GVlMDEKVlnEr+kL0Hi/ZO+EVvQx7uJR8vO8UZhr8= X-ASG-Debug-ID: 1377872043-0421b50221329bf0001-6jHSXT Received: from CAS1.int.fusionio.com (cas1.int.fusionio.com [10.101.1.40]) by mx2.fusionio.com with ESMTP id Mc99uZBowGAANKe7 (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO); Fri, 30 Aug 2013 08:14:03 -0600 (MDT) X-Barracuda-Envelope-From: JBacik@fusionio.com Received: from localhost (10.101.1.160) by mail.fusionio.com (10.101.1.40) with Microsoft SMTP Server (TLS) id 14.3.158.1; Fri, 30 Aug 2013 08:14:02 -0600 From: Josef Bacik To: , , , , Subject: [PATCH] rwsem: add rwsem_is_contended Date: Fri, 30 Aug 2013 10:14:01 -0400 X-ASG-Orig-Subj: [PATCH] rwsem: add rwsem_is_contended Message-ID: <1377872041-390-1-git-send-email-jbacik@fusionio.com> X-Mailer: git-send-email 1.7.7.6 MIME-Version: 1.0 X-Originating-IP: [10.101.1.160] X-Barracuda-Connect: cas1.int.fusionio.com[10.101.1.40] X-Barracuda-Start-Time: 1377872043 X-Barracuda-Encrypted: AES128-SHA X-Barracuda-URL: http://10.101.1.181:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at fusionio.com X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.139843 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Btrfs uses an rwsem to control access to its extent tree. Threads will hold a read lock on this rwsem while they scan the extent tree, and if need_resched() they will drop the lock and schedule. The transaction commit needs to take a write lock for this rwsem for a very short period to switch out the commit roots. If there are a lot of threads doing this caching operation we can starve out the committers which slows everybody out. To address this we want to add this functionality to see if our rwsem has anybody waiting to take a write lock so we can drop it and schedule for a bit to allow the commit to continue. Thanks, Signed-off-by: Josef Bacik --- I've cc'ed people who seemed like they may be in charge/familiar with this code, hopefully I got the right people. include/linux/rwsem.h | 1 + lib/rwsem.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-) diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h index 0616ffe..61a8802 100644 --- a/include/linux/rwsem.h +++ b/include/linux/rwsem.h @@ -35,6 +35,7 @@ extern struct rw_semaphore *rwsem_down_read_failed(struct rw_semaphore *sem); extern struct rw_semaphore *rwsem_down_write_failed(struct rw_semaphore *sem); extern struct rw_semaphore *rwsem_wake(struct rw_semaphore *); extern struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem); +extern int rwsem_is_contended(struct rw_semaphore *sem); /* Include the arch specific part */ #include diff --git a/lib/rwsem.c b/lib/rwsem.c index 19c5fa9..20858cd 100644 --- a/lib/rwsem.c +++ b/lib/rwsem.c @@ -287,6 +287,23 @@ struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem) return sem; } +/* + * check to see if the rwsem we're holding has anybody waiting to acquire it. + */ +int rwsem_is_contended(struct rw_semaphore *sem) +{ + int ret = 0; + unsigned long flags; + + if (!raw_spin_trylock_irqsave(&sem->wait_lock, flags)) + return 1; + if (!list_empty(&sem->wait_list)) + ret = 1; + raw_spin_unlock_irqrestore(&sem->wait_lock, flags); + return ret; +} + +EXPORT_SYMBOL(rwsem_is_contended); EXPORT_SYMBOL(rwsem_down_read_failed); EXPORT_SYMBOL(rwsem_down_write_failed); EXPORT_SYMBOL(rwsem_wake);