From patchwork Thu Jun 26 19:12:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4430901 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3F25EBEECB for ; Thu, 26 Jun 2014 19:15:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6550D202D1 for ; Thu, 26 Jun 2014 19:15:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 88C352028D for ; Thu, 26 Jun 2014 19:15:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751845AbaFZTPb (ORCPT ); Thu, 26 Jun 2014 15:15:31 -0400 Received: from mail-qg0-f48.google.com ([209.85.192.48]:33363 "EHLO mail-qg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751508AbaFZTP3 (ORCPT ); Thu, 26 Jun 2014 15:15:29 -0400 Received: by mail-qg0-f48.google.com with SMTP id q108so3415801qgd.21 for ; Thu, 26 Jun 2014 12:15:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=EjKv5fkfqmltUDWwfa85fkpdlpPufaxKX1WaoNt6gj0=; b=mVMU3QR0u/Y/tgai/mdYvFOgBHFWTLPCTbc+bG1X87lGgSUR0wvnTsbc1cB0IoxtRO Fck3vQUootkD2+ih4Q8ChyIEHuKk6PM5at+fcLdLOr2B09GkU3IFbKZixZvcaEobLotN 8CMPzVrxoeyLpOMT9koTBPP6DoO51FGuxHRkaKcx5/CEAGfgUSZd/jI5hr9PtH/AcRgF Ou2yXpcLINa4Q4r0JdzamX9ZgLs8b40f9h/i95O5sp6n1+Iiwu2meZ8YfeZdUKd5IE1q PeM9LD2ekOO3ScSARoR/BnO6k6dxSN7zaCOlFnMgICK+x750ZMr6Zgm2eAABd6WRM3L/ 9RNg== X-Gm-Message-State: ALoCoQl0Mh1+oI8ujfENbPoPgh3TUgRJzl+zxUehj/0C9ka2XufWjaLMnOsskc9Oc9qEpVQQ57ls X-Received: by 10.140.27.108 with SMTP id 99mr380171qgw.77.1403810129123; Thu, 26 Jun 2014 12:15:29 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id 88sm4763039qgh.5.2014.06.26.12.15.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jun 2014 12:15:28 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 076/117] nfsd: optimize destroy_lockowner cl_lock thrashing Date: Thu, 26 Jun 2014 15:12:56 -0400 Message-Id: <1403810017-16062-77-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1403810017-16062-1-git-send-email-jlayton@primarydata.com> References: <1403810017-16062-1-git-send-email-jlayton@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Reduce the cl_lock trashing in destroy_lockowner. Unhash all of the lockstateids on the lockowner's list. Put the reference under the lock and see if it was the last one. If so, then add it to a private list to be destroyed after we drop the lock. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 92680d6531e7..790ff7dacbfb 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -938,14 +938,23 @@ static void put_generic_stateid(struct nfs4_ol_stateid *stp) nfs4_put_stid(&stp->st_stid); } -static void release_lock_stateid(struct nfs4_ol_stateid *stp) +static void unhash_lock_stateid(struct nfs4_ol_stateid *stp) { struct nfs4_openowner *oo = openowner(stp->st_openstp->st_stateowner); - spin_lock(&oo->oo_owner.so_client->cl_lock); - list_del(&stp->st_locks); + lockdep_assert_held(&oo->oo_owner.so_client->cl_lock); + + list_del_init(&stp->st_locks); unhash_generic_stateid(stp); unhash_stid(&stp->st_stid); +} + +static void release_lock_stateid(struct nfs4_ol_stateid *stp) +{ + struct nfs4_openowner *oo = openowner(stp->st_openstp->st_stateowner); + + spin_lock(&oo->oo_owner.so_client->cl_lock); + unhash_lock_stateid(stp); spin_unlock(&oo->oo_owner.so_client->cl_lock); put_generic_stateid(stp); } @@ -959,30 +968,37 @@ static void unhash_lockowner_locked(struct nfs4_lockowner *lo) list_del_init(&lo->lo_owner.so_strhash); } -static void release_lockowner_stateids(struct nfs4_lockowner *lo) +static void release_lockowner(struct nfs4_lockowner *lo) { struct nfs4_client *clp = lo->lo_owner.so_client; struct nfs4_ol_stateid *stp; + struct list_head reaplist; - lockdep_assert_held(&clp->cl_lock); + INIT_LIST_HEAD(&reaplist); + spin_lock(&clp->cl_lock); + unhash_lockowner_locked(lo); while (!list_empty(&lo->lo_owner.so_stateids)) { stp = list_first_entry(&lo->lo_owner.so_stateids, struct nfs4_ol_stateid, st_perstateowner); - spin_unlock(&clp->cl_lock); - release_lock_stateid(stp); - spin_lock(&clp->cl_lock); + unhash_lock_stateid(stp); + /* + * We now know that no new references can be added to the + * stateid. If ours is the last one, finish the unhashing + * and put it on the list to be reaped. + */ + if (atomic_dec_and_test(&stp->st_stid.sc_count)) { + remove_stid_locked(clp, &stp->st_stid); + list_add(&stp->st_locks, &reaplist); + } } -} - -static void release_lockowner(struct nfs4_lockowner *lo) -{ - struct nfs4_client *clp = lo->lo_owner.so_client; - - spin_lock(&clp->cl_lock); - unhash_lockowner_locked(lo); - release_lockowner_stateids(lo); spin_unlock(&clp->cl_lock); + while (!list_empty(&reaplist)) { + stp = list_first_entry(&reaplist, struct nfs4_ol_stateid, + st_locks); + list_del(&stp->st_locks); + stp->st_stid.sc_free(&stp->st_stid); + } nfs4_put_stateowner(&lo->lo_owner); }