From patchwork Thu Feb 27 21:17:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 11410745 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 23D3A1580 for ; Thu, 27 Feb 2020 21:45:48 +0000 (UTC) Received: from pdx1-mailman02.dreamhost.com (pdx1-mailman02.dreamhost.com [64.90.62.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 06E0B24690 for ; Thu, 27 Feb 2020 21:45:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06E0B24690 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lustre-devel-bounces@lists.lustre.org Received: from pdx1-mailman02.dreamhost.com (localhost [IPv6:::1]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id B165034B0B9; Thu, 27 Feb 2020 13:36:26 -0800 (PST) X-Original-To: lustre-devel@lists.lustre.org Delivered-To: lustre-devel-lustre.org@pdx1-mailman02.dreamhost.com Received: from smtp3.ccs.ornl.gov (smtp3.ccs.ornl.gov [160.91.203.39]) by pdx1-mailman02.dreamhost.com (Postfix) with ESMTP id 8A85D3489A1 for ; Thu, 27 Feb 2020 13:21:17 -0800 (PST) Received: from star.ccs.ornl.gov (star.ccs.ornl.gov [160.91.202.134]) by smtp3.ccs.ornl.gov (Postfix) with ESMTP id 0AF8191D9; Thu, 27 Feb 2020 16:18:20 -0500 (EST) Received: by star.ccs.ornl.gov (Postfix, from userid 2004) id 0950346C; Thu, 27 Feb 2020 16:18:20 -0500 (EST) From: James Simmons To: Andreas Dilger , Oleg Drokin , NeilBrown Date: Thu, 27 Feb 2020 16:17:22 -0500 Message-Id: <1582838290-17243-575-git-send-email-jsimmons@infradead.org> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> References: <1582838290-17243-1-git-send-email-jsimmons@infradead.org> Subject: [lustre-devel] [PATCH 574/622] lustre: ldlm: simplify ldlm_ns_hash_defs[] X-BeenThere: lustre-devel@lists.lustre.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "For discussing Lustre software development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lustre Development List MIME-Version: 1.0 Errors-To: lustre-devel-bounces@lists.lustre.org Sender: "lustre-devel" From: NeilBrown As the ldlm_ns_types are dense, we can use the type as the index to the array, rather than searching through the array for a match. We can also discard nsd_hops as all hash tables now use the same hops. This makes the table smaller and the code simpler. WC-bug-id: https://jira.whamcloud.com/browse/LU-8130 Lustre-commit: 416142145c9d ("LU-8130 ldlm: simplify ldlm_ns_hash_defs[]") Signed-off-by: NeilBrown Reviewed-on: https://review.whamcloud.com/36220 Reviewed-by: Andreas Dilger Reviewed-by: Mike Pershin Reviewed-by: Neil Brown Signed-off-by: James Simmons --- fs/lustre/ldlm/ldlm_resource.c | 62 ++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 42 deletions(-) diff --git a/fs/lustre/ldlm/ldlm_resource.c b/fs/lustre/ldlm/ldlm_resource.c index d009d5d..9b24be7 100644 --- a/fs/lustre/ldlm/ldlm_resource.c +++ b/fs/lustre/ldlm/ldlm_resource.c @@ -522,55 +522,35 @@ static void ldlm_res_hop_put(struct cfs_hash *hs, struct hlist_node *hnode) .hs_put = ldlm_res_hop_put }; -struct ldlm_ns_hash_def { - enum ldlm_ns_type nsd_type; +static struct { /** hash bucket bits */ unsigned int nsd_bkt_bits; /** hash bits */ unsigned int nsd_all_bits; - /** hash operations */ - struct cfs_hash_ops *nsd_hops; -}; - -static struct ldlm_ns_hash_def ldlm_ns_hash_defs[] = { - { - .nsd_type = LDLM_NS_TYPE_MDC, +} ldlm_ns_hash_defs[] = { + [LDLM_NS_TYPE_MDC] = { .nsd_bkt_bits = 11, .nsd_all_bits = 16, - .nsd_hops = &ldlm_ns_hash_ops, }, - { - .nsd_type = LDLM_NS_TYPE_MDT, + [LDLM_NS_TYPE_MDT] = { .nsd_bkt_bits = 14, .nsd_all_bits = 21, - .nsd_hops = &ldlm_ns_hash_ops, }, - { - .nsd_type = LDLM_NS_TYPE_OSC, + [LDLM_NS_TYPE_OSC] = { .nsd_bkt_bits = 8, .nsd_all_bits = 12, - .nsd_hops = &ldlm_ns_hash_ops, }, - { - .nsd_type = LDLM_NS_TYPE_OST, + [LDLM_NS_TYPE_OST] = { .nsd_bkt_bits = 11, .nsd_all_bits = 17, - .nsd_hops = &ldlm_ns_hash_ops, }, - { - .nsd_type = LDLM_NS_TYPE_MGC, + [LDLM_NS_TYPE_MGC] = { .nsd_bkt_bits = 3, .nsd_all_bits = 4, - .nsd_hops = &ldlm_ns_hash_ops, }, - { - .nsd_type = LDLM_NS_TYPE_MGT, + [LDLM_NS_TYPE_MGT] = { .nsd_bkt_bits = 3, .nsd_all_bits = 4, - .nsd_hops = &ldlm_ns_hash_ops, - }, - { - .nsd_type = LDLM_NS_TYPE_UNKNOWN, }, }; @@ -594,7 +574,6 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, enum ldlm_ns_type ns_type) { struct ldlm_namespace *ns = NULL; - struct ldlm_ns_hash_def *nsd; int idx; int rc; @@ -606,15 +585,10 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, return NULL; } - for (idx = 0; ; idx++) { - nsd = &ldlm_ns_hash_defs[idx]; - if (nsd->nsd_type == LDLM_NS_TYPE_UNKNOWN) { - CERROR("Unknown type %d for ns %s\n", ns_type, name); - goto out_ref; - } - - if (nsd->nsd_type == ns_type) - break; + if (ns_type >= ARRAY_SIZE(ldlm_ns_hash_defs) || + ldlm_ns_hash_defs[ns_type].nsd_bkt_bits == 0) { + CERROR("Unknown type %d for ns %s\n", ns_type, name); + goto out_ref; } ns = kzalloc(sizeof(*ns), GFP_NOFS); @@ -622,11 +596,13 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, goto out_ref; ns->ns_rs_hash = cfs_hash_create(name, - nsd->nsd_all_bits, nsd->nsd_all_bits, - nsd->nsd_bkt_bits, 0, + ldlm_ns_hash_defs[ns_type].nsd_all_bits, + ldlm_ns_hash_defs[ns_type].nsd_all_bits, + ldlm_ns_hash_defs[ns_type].nsd_bkt_bits, + 0, CFS_HASH_MIN_THETA, CFS_HASH_MAX_THETA, - nsd->nsd_hops, + &ldlm_ns_hash_ops, CFS_HASH_DEPTH | CFS_HASH_BIGNAME | CFS_HASH_SPIN_BKTLOCK | @@ -634,7 +610,9 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name, if (!ns->ns_rs_hash) goto out_ns; - ns->ns_bucket_bits = nsd->nsd_all_bits - nsd->nsd_bkt_bits; + ns->ns_bucket_bits = ldlm_ns_hash_defs[ns_type].nsd_all_bits - + ldlm_ns_hash_defs[ns_type].nsd_bkt_bits; + ns->ns_rs_buckets = kvmalloc(BIT(ns->ns_bucket_bits) * sizeof(ns->ns_rs_buckets[0]), GFP_KERNEL);