From patchwork Wed Nov 28 00:53:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 10701685 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4640217D5 for ; Wed, 28 Nov 2018 00:54:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AB2C2B645 for ; Wed, 28 Nov 2018 00:54:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19CE32B67E; Wed, 28 Nov 2018 00:54:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6D3B2B645 for ; Wed, 28 Nov 2018 00:54:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726457AbeK1Lxl (ORCPT ); Wed, 28 Nov 2018 06:53:41 -0500 Received: from mx2.suse.de ([195.135.220.15]:48402 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726418AbeK1Lxl (ORCPT ); Wed, 28 Nov 2018 06:53:41 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "To" Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E143AAC38; Wed, 28 Nov 2018 00:53:56 +0000 (UTC) From: NeilBrown To: "J. Bruce Fields" , kernel test robot To: Jeff Layton Date: Wed, 28 Nov 2018 11:53:48 +1100 Cc: LKML , Jeff Layton , lkp@01.org, linux-nfs@vger.kernel.org Subject: [PATCH] locks: fix performance regressions. In-Reply-To: <87mupup0ot.fsf@notabene.neil.brown.name> References: <20181127060102.GF6163@shao2-debian> <20181127174315.GA29963@parsley.fieldses.org> <87mupup0ot.fsf@notabene.neil.brown.name> Message-ID: <87k1kyowdf.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The kernel test robot reported two performance regressions caused by recent patches. Both appear to related to the global spinlock blocked_lock_lock being taken more often. This patch avoids taking that lock in the cases tested. Reported-by: kernel test robot Signed-off-by: NeilBrown --- Hi Jeff, you might like to merge these back into the patches that introduced the problem. Or you might like me to re-send the series with these merged in, in which case, please ask. And a BIG thank-you to the kernel-test-robot team!! Thanks, NeilBrown fs/locks.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fs/locks.c b/fs/locks.c index f456cd3d9d50..67519a43e27a 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -444,6 +444,13 @@ static void locks_move_blocks(struct file_lock *new, struct file_lock *fl) { struct file_lock *f; + /* + * As ctx->flc_lock is held, new requests cannot be added to + * ->fl_blocked_requests, so we don't need a lock to check if it + * is empty. + */ + if (list_empty(&fl->fl_blocked_requests)) + return; spin_lock(&blocked_lock_lock); list_splice_init(&fl->fl_blocked_requests, &new->fl_blocked_requests); list_for_each_entry(f, &fl->fl_blocked_requests, fl_blocked_member) @@ -749,6 +756,20 @@ int locks_delete_block(struct file_lock *waiter) { int status = -ENOENT; + /* + * If fl_blocker is NULL, it won't be set again as this thread + * "owns" the lock and is the only one that might try to claim + * the lock. So it is safe to test fl_blocker locklessly. + * Also if fl_blocker is NULL, this waiter is not listed on + * fl_blocked_requests for some lock, so no other request can + * be added to the list of fl_blocked_requests for this + * request. So if fl_blocker is NULL, it is safe to + * locklessly check if fl_blocked_requests is empty. If both + * of these checks succeed, there is no need to take the lock. + */ + if (waiter->fl_blocker == NULL && + list_empty(&waiter->fl_blocked_requests)) + return status; spin_lock(&blocked_lock_lock); if (waiter->fl_blocker) status = 0;