From patchwork Mon Dec 4 18:31:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 844368 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quantonium-net.20150623.gappssmtp.com header.i=@quantonium-net.20150623.gappssmtp.com header.b="RZBGA3yu"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yrD4q0L3Kz9sDB for ; Tue, 5 Dec 2017 05:32:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752563AbdLDScZ (ORCPT ); Mon, 4 Dec 2017 13:32:25 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:45238 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752291AbdLDScS (ORCPT ); Mon, 4 Dec 2017 13:32:18 -0500 Received: by mail-pf0-f195.google.com with SMTP id u19so9155562pfa.12 for ; Mon, 04 Dec 2017 10:32:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quantonium-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SbKCh451uHuGfXyD36OBSbrD/8P96luBUetHIaFi4k4=; b=RZBGA3yuavtra9ko7U2A7+mXv11nDBrMiDWTWVhXUrW8k8du+7dc2Xe1XMyijXV3Ld r5D2CRU332JnqFVrYz2JSn6IyJBlHR4vA+AAE5RThK0WCeD2iJJR9gJiTEQd3SOr+vuf 8YxTK/RQRHLL4rguMB8kWOI8+h8lIVDhky6LQ9REMaMHtlx8YwCdtaXu0sSQXivS/S6N 2Aojf6S7blPXLDn+SZMaKexndAd2tw9G/aIhBGN2TY31vS3PaK82F4fDblsIVeVH+p54 x8Nh32VxNV0u/fjR2yfAqULZQ8Ay/PZYwA81tRK1InCRie9YYPz13fVuORD8M6c6QFrw Aeog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SbKCh451uHuGfXyD36OBSbrD/8P96luBUetHIaFi4k4=; b=X6m+e+mThi48JKNAnEEq4fwIpB7sDFj0dIu3FrGnvHsqbZ4qhd1bNN9OYE4L5kzAeC 5mvzFcyM/ycr5+l/Y1weefuO2g/B4Gu9MdXVP85YIU+79Grw1SWKpw7YkTk58hESgLZn +8hkEMUzzUGt+aK0BOP9Qm6gWX6suVj1qnlFEBocaz15xVd+r66cljL+pTXYNTbDjBHj P1tcs6Nwf1zuBKKFkoxut3lNpALbu85/Ke6xENPrALFJq+2E1xThH9OBc7rjbGekoAzA belHECTUP2H/lMy3HbnImULwp6RJGjYH7mIGpHz05Y2tP59BwnUbk1HUqEv+yz/QmSrI A0jQ== X-Gm-Message-State: AJaThX4+XtpH62z+D7VaEGIGxiXOW01fCqP+Q45WFZuzwNLzJvwOF/rs w5IfcRYLGyLnBCOTYNH1f+emVME6 X-Google-Smtp-Source: AGs4zMbzQNZ4hbu0FentGrDSpPqKdwfCAHRjiVItkZwx6t2DIzLXVuxnAstWlYRrXAnHph7Z/9oO/g== X-Received: by 10.98.236.137 with SMTP id e9mr20445851pfm.123.1512412338116; Mon, 04 Dec 2017 10:32:18 -0800 (PST) Received: from localhost.localdomain (c-73-162-13-107.hsd1.ca.comcast.net. [73.162.13.107]) by smtp.gmail.com with ESMTPSA id z2sm3558962pgu.17.2017.12.04.10.32.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Dec 2017 10:32:17 -0800 (PST) From: Tom Herbert To: davem@davemloft.net Cc: netdev@vger.kernel.org, herbert@gondor.apana.org.au, rohit@quantonium.net, Tom Herbert Subject: [PATCH v2 net-next 5/5] rhashtable: Call library function alloc_bucket_locks Date: Mon, 4 Dec 2017 10:31:45 -0800 Message-Id: <20171204183145.3277-6-tom@quantonium.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171204183145.3277-1-tom@quantonium.net> References: <20171204183145.3277-1-tom@quantonium.net> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org To allocate the array of bucket locks for the hash table we now call library function alloc_bucket_spinlocks. This function is based on the old alloc_bucket_locks in rhashtable and should produce the same effect. Signed-off-by: Tom Herbert --- lib/rhashtable.c | 47 ++++++++--------------------------------------- 1 file changed, 8 insertions(+), 39 deletions(-) diff --git a/lib/rhashtable.c b/lib/rhashtable.c index 6fc52d82efe6..3825c30aaa36 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -65,42 +65,6 @@ EXPORT_SYMBOL_GPL(lockdep_rht_bucket_is_held); #define ASSERT_RHT_MUTEX(HT) #endif - -static int alloc_bucket_locks(struct rhashtable *ht, struct bucket_table *tbl, - gfp_t gfp) -{ - unsigned int i, size; -#if defined(CONFIG_PROVE_LOCKING) - unsigned int nr_pcpus = 2; -#else - unsigned int nr_pcpus = num_possible_cpus(); -#endif - - nr_pcpus = min_t(unsigned int, nr_pcpus, 64UL); - size = roundup_pow_of_two(nr_pcpus * ht->p.locks_mul); - - /* Never allocate more than 0.5 locks per bucket */ - size = min_t(unsigned int, size, tbl->size >> 1); - - if (tbl->nest) - size = min(size, 1U << tbl->nest); - - if (sizeof(spinlock_t) != 0) { - if (gfpflags_allow_blocking(gfp)) - tbl->locks = kvmalloc(size * sizeof(spinlock_t), gfp); - else - tbl->locks = kmalloc_array(size, sizeof(spinlock_t), - gfp); - if (!tbl->locks) - return -ENOMEM; - for (i = 0; i < size; i++) - spin_lock_init(&tbl->locks[i]); - } - tbl->locks_mask = size - 1; - - return 0; -} - static void nested_table_free(union nested_table *ntbl, unsigned int size) { const unsigned int shift = PAGE_SHIFT - ilog2(sizeof(void *)); @@ -140,7 +104,7 @@ static void bucket_table_free(const struct bucket_table *tbl) if (tbl->nest) nested_bucket_table_free(tbl); - kvfree(tbl->locks); + free_bucket_spinlocks(tbl->locks); kvfree(tbl); } @@ -207,7 +171,7 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht, gfp_t gfp) { struct bucket_table *tbl = NULL; - size_t size; + size_t size, max_locks; int i; size = sizeof(*tbl) + nbuckets * sizeof(tbl->buckets[0]); @@ -227,7 +191,12 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht, tbl->size = size; - if (alloc_bucket_locks(ht, tbl, gfp) < 0) { + max_locks = size >> 1; + if (tbl->nest) + max_locks = min_t(size_t, max_locks, 1U << tbl->nest); + + if (alloc_bucket_spinlocks(&tbl->locks, &tbl->locks_mask, max_locks, + ht->p.locks_mul, gfp) < 0) { bucket_table_free(tbl); return NULL; }