From patchwork Fri Dec 1 00:03:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Herbert X-Patchwork-Id: 843262 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="IrCOx9G0"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ynvd928Rrz9sNd for ; Fri, 1 Dec 2017 11:03:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751888AbdLAADz (ORCPT ); Thu, 30 Nov 2017 19:03:55 -0500 Received: from mail-pl0-f68.google.com ([209.85.160.68]:34926 "EHLO mail-pl0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751801AbdLAADx (ORCPT ); Thu, 30 Nov 2017 19:03:53 -0500 Received: by mail-pl0-f68.google.com with SMTP id b96so5242640pli.2 for ; Thu, 30 Nov 2017 16:03:53 -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=h7SfUZvx3TY3SM0ZMz9/kCUix6Ik1ZuM5nnAcGQIC7E=; b=IrCOx9G0sTFClxv782DKQLbrqbhLgjJOjAl4tb1LZ0C9bf5PIHK1vPGNedNU2MWbq4 lyBf0bHX20Y3AgNUvXx+ZeMX4MPu0hLl2GqzjpUAacMgFGJ7u2JOtJpOe+2mptEIMRWf Q0N6k95vSGeNi8GpNjs1MUDMK0SsscYRQIqXMHMygIBpBTVjAdVGvK/5Q8iqhMBFZ1Cd c3FrjMm77CU3n1YtLBjzDFAE6NaV5JJ+6tha864Ue8eQ4M8JEPSSwvsbzN1h1LWqTMdd M7hhMymNLJCCzmDohOai5PPjOy+vwhrbhOHXW2Nz9X3h+7aGU2L69ukBh9Sg1uuL18HM FsMA== 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=h7SfUZvx3TY3SM0ZMz9/kCUix6Ik1ZuM5nnAcGQIC7E=; b=ZWMssVEegrPvXRTMRpmynXFRRHvE41KAVGOkLqqWcLSCR8+EcuaKurWCjTrjz1cj48 oLCB7/B3yP0fByb3n387RpC0L6tOIQAWHUMJ7+xyl9NAx1Phh0ZrXCQT7jL/r1zaFK1i 4D3k3B8D2Xf62DwBwh8IYAIFBftDDxd1pVsxXO27CtXenq3ZTsvEAVJ/ocTvR+dTBJCX NpIDHhy08eoRJRxoOOpVZxvxYBWRcd9hdsOouzKm4S3uyAfHiUKgI+YqiRw1c+CQmuPd JnvyQPIN51W+cBFx+usyjffVow1IK7FbDyinNNUSwi8v+yYGWdvCc6i0jeQlIE2Utj0b 70ig== X-Gm-Message-State: AJaThX5d9zeON0/5zVzO2qb7actLLoS76IvK8/0Y4WBVq/11ajHPPq2u a9DVsbU3OJVXaEK02pIwbo2dlw== X-Google-Smtp-Source: AGs4zMbHPcMZ+Fzd1kwQsoLt27/Grp9rn1iK5ymUfDCS5RsWQKIvlli6Ug0DyRGsVTLF30xUCXsYqg== X-Received: by 10.159.207.146 with SMTP id z18mr2883162plo.100.1512086632866; Thu, 30 Nov 2017 16:03:52 -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 s66sm10510569pfd.74.2017.11.30.16.03.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Nov 2017 16:03:51 -0800 (PST) From: Tom Herbert To: davem@davemloft.net Cc: netdev@vger.kernel.org, rohit@quantonium.net, herbert@gondor.apana.org.au, Tom Herbert Subject: [PATCH net-next 5/5] rhashtable: Call library function alloc_bucket_locks Date: Thu, 30 Nov 2017 16:03:05 -0800 Message-Id: <20171201000305.2392-6-tom@quantonium.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171201000305.2392-1-tom@quantonium.net> References: <20171201000305.2392-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 1d58231110af..a9c04e5e4767 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; }