Received: by 10.192.165.148 with SMTP id m20csp949032imm; Wed, 2 May 2018 11:23:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpbXYNuD1pu+dfRWzCpB3eLnKWBZWNCNFj7YR/0VBiR5KbQPM99W9Ag1nO/PQJKerqEGo8N X-Received: by 10.98.220.138 with SMTP id c10mr20450733pfl.183.1525285387731; Wed, 02 May 2018 11:23:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525285387; cv=none; d=google.com; s=arc-20160816; b=UUwNe5SkZzGROdNblV+7gY6nB7i85jZ3quzBjU327SbhRCDFr2/YLU25hvd/yzYd7f o5sqdAdusLr+4BOppcDE14iFqSN4eDY+HCLPHNskE6Gq2DGdJ1tUgGqOr+vEJEAlkmxw VCrX+v3P9/gI65IRfsbB2jDIerivZ39w3lWiTDWOw/98jbD4h0FXyBB1+bnajAxNMY1r NV3dYqXDV7eYplMuyMMQfl5vmClqT4W3ffN8eoOotuHsbhtAIqwS0bhJ5l8V+P4wNfHT RDqHRlQ+WuA7vUqxQ2HD3Ac/lObNafvIo18INfMmsNQf39asxPs39jwZBBolfpFgaqkT Mlsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Pcwis3R3DIvxfancNaazhg2Qe3JtntuM47aVUTh9EN4=; b=xvzT3FENUFEsAq3qufYyNMCKilVanv9Lp6f+PE1JxaI2Y9Rw5FIuYnZhCkwGmwZjv0 2TguaZJLYGAiHGlnMfxibmGpKMchsWast32YlJiv2dTMSb06d0SfGLemoys/oN/sij4J 9CbdC/RJBRcdol8C2neXY54vF9dAKdMo5EDqqSU12IQXk1ca7wmwjhpdPRr3sPdtWFiV ljUrUJceUejNSbGfrTwr+UF7fLCWhHbqpdP08pUmI4K2SI4VXgbCZ+Qe4sEesRYlJtLc 4o1YTF7lCHhcEinaPbaNjnQoJqoaUupS4yadG02Zfa8bULhMcfW9JEjvHRc1BxDRGYVD WWUA== 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 c9-v6si10814533plz.501.2018.05.02.11.22.53; Wed, 02 May 2018 11:23:07 -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 S1751346AbeEBSV6 (ORCPT + 99 others); Wed, 2 May 2018 14:21:58 -0400 Received: from smtp3.ccs.ornl.gov ([160.91.203.39]:55674 "EHLO smtp3.ccs.ornl.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751019AbeEBSVx (ORCPT ); Wed, 2 May 2018 14:21:53 -0400 Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp3.ccs.ornl.gov (Postfix) with ESMTP id A99CDE1E; Wed, 2 May 2018 14:21:51 -0400 (EDT) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id A2873D96; Wed, 2 May 2018 14:21:51 -0400 (EDT) From: James Simmons To: Greg Kroah-Hartman , devel@driverdev.osuosl.org, Andreas Dilger , Oleg Drokin , Lai Siyao , Jinshan Xiong , NeilBrown Cc: Linux Kernel Mailing List , Lustre Development List , Li Xi , Gu Zheng , James Simmons Subject: [PATCH 1/4] staging: lustre: obdclass: change spinlock of key to rwlock Date: Wed, 2 May 2018 14:21:45 -0400 Message-Id: <1525285308-15347-2-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1525285308-15347-1-git-send-email-jsimmons@infradead.org> References: <1525285308-15347-1-git-send-email-jsimmons@infradead.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Li Xi Most of the time, keys are never changed. So rwlock might be better for the concurrency of key read. Signed-off-by: Li Xi Signed-off-by: Gu Zheng Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6800 Reviewed-on: http://review.whamcloud.com/15558 Reviewed-by: Faccini Bruno Reviewed-by: James Simmons Reviewed-by: Oleg Drokin Signed-off-by: James Simmons --- drivers/staging/lustre/lustre/obdclass/lu_object.c | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/staging/lustre/lustre/obdclass/lu_object.c b/drivers/staging/lustre/lustre/obdclass/lu_object.c index fa986f2..04475e9 100644 --- a/drivers/staging/lustre/lustre/obdclass/lu_object.c +++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c @@ -1317,7 +1317,7 @@ enum { static struct lu_context_key *lu_keys[LU_CONTEXT_KEY_NR] = { NULL, }; -static DEFINE_SPINLOCK(lu_keys_guard); +static DEFINE_RWLOCK(lu_keys_guard); static atomic_t lu_key_initing_cnt = ATOMIC_INIT(0); /** @@ -1341,7 +1341,7 @@ int lu_context_key_register(struct lu_context_key *key) LASSERT(key->lct_tags != 0); result = -ENFILE; - spin_lock(&lu_keys_guard); + write_lock(&lu_keys_guard); for (i = 0; i < ARRAY_SIZE(lu_keys); ++i) { if (!lu_keys[i]) { key->lct_index = i; @@ -1353,7 +1353,7 @@ int lu_context_key_register(struct lu_context_key *key) break; } } - spin_unlock(&lu_keys_guard); + write_unlock(&lu_keys_guard); return result; } EXPORT_SYMBOL(lu_context_key_register); @@ -1387,7 +1387,7 @@ void lu_context_key_degister(struct lu_context_key *key) lu_context_key_quiesce(key); ++key_set_version; - spin_lock(&lu_keys_guard); + write_lock(&lu_keys_guard); key_fini(&lu_shrink_env.le_ctx, key->lct_index); /** @@ -1395,18 +1395,18 @@ void lu_context_key_degister(struct lu_context_key *key) * run lu_context_key::lct_fini() method. */ while (atomic_read(&key->lct_used) > 1) { - spin_unlock(&lu_keys_guard); + write_unlock(&lu_keys_guard); CDEBUG(D_INFO, "%s: \"%s\" %p, %d\n", __func__, module_name(key->lct_owner), key, atomic_read(&key->lct_used)); schedule(); - spin_lock(&lu_keys_guard); + write_lock(&lu_keys_guard); } if (lu_keys[key->lct_index]) { lu_keys[key->lct_index] = NULL; lu_ref_fini(&key->lct_reference); } - spin_unlock(&lu_keys_guard); + write_unlock(&lu_keys_guard); LASSERTF(atomic_read(&key->lct_used) == 1, "key has instances: %d\n", @@ -1526,7 +1526,7 @@ void lu_context_key_quiesce(struct lu_context_key *key) /* * XXX memory barrier has to go here. */ - spin_lock(&lu_keys_guard); + write_lock(&lu_keys_guard); key->lct_tags |= LCT_QUIESCENT; /** @@ -1534,19 +1534,19 @@ void lu_context_key_quiesce(struct lu_context_key *key) * have completed. */ while (atomic_read(&lu_key_initing_cnt) > 0) { - spin_unlock(&lu_keys_guard); + write_unlock(&lu_keys_guard); CDEBUG(D_INFO, "%s: \"%s\" %p, %d (%d)\n", __func__, module_name(key->lct_owner), key, atomic_read(&key->lct_used), atomic_read(&lu_key_initing_cnt)); schedule(); - spin_lock(&lu_keys_guard); + write_lock(&lu_keys_guard); } list_for_each_entry(ctx, &lu_context_remembered, lc_remember) key_fini(ctx, key->lct_index); - spin_unlock(&lu_keys_guard); + write_unlock(&lu_keys_guard); ++key_set_version; } } @@ -1584,9 +1584,9 @@ static int keys_fill(struct lu_context *ctx) * An atomic_t variable is still used, in order not to reacquire the * lock when decrementing the counter. */ - spin_lock(&lu_keys_guard); + read_lock(&lu_keys_guard); atomic_inc(&lu_key_initing_cnt); - spin_unlock(&lu_keys_guard); + read_unlock(&lu_keys_guard); LINVRNT(ctx->lc_value); for (i = 0; i < ARRAY_SIZE(lu_keys); ++i) { @@ -1655,9 +1655,9 @@ int lu_context_init(struct lu_context *ctx, __u32 tags) ctx->lc_state = LCS_INITIALIZED; ctx->lc_tags = tags; if (tags & LCT_REMEMBER) { - spin_lock(&lu_keys_guard); + write_lock(&lu_keys_guard); list_add(&ctx->lc_remember, &lu_context_remembered); - spin_unlock(&lu_keys_guard); + write_unlock(&lu_keys_guard); } else { INIT_LIST_HEAD(&ctx->lc_remember); } @@ -1683,10 +1683,10 @@ void lu_context_fini(struct lu_context *ctx) keys_fini(ctx); } else { /* could race with key degister */ - spin_lock(&lu_keys_guard); + write_lock(&lu_keys_guard); keys_fini(ctx); list_del_init(&ctx->lc_remember); - spin_unlock(&lu_keys_guard); + write_unlock(&lu_keys_guard); } } EXPORT_SYMBOL(lu_context_fini); @@ -1714,7 +1714,7 @@ void lu_context_exit(struct lu_context *ctx) for (i = 0; i < ARRAY_SIZE(lu_keys); ++i) { /* could race with key quiescency */ if (ctx->lc_tags & LCT_REMEMBER) - spin_lock(&lu_keys_guard); + read_lock(&lu_keys_guard); if (ctx->lc_value[i]) { struct lu_context_key *key; @@ -1724,7 +1724,7 @@ void lu_context_exit(struct lu_context *ctx) key, ctx->lc_value[i]); } if (ctx->lc_tags & LCT_REMEMBER) - spin_unlock(&lu_keys_guard); + read_unlock(&lu_keys_guard); } } } -- 1.8.3.1