Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp182878imm; Thu, 31 May 2018 21:52:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL4nXo3HtdDDAPJwl/S6j/CxQvTvqbIRMog/iSv1X6I/WpZuHVcviQueyPdNjeHLOsCa3pf X-Received: by 2002:a17:902:988b:: with SMTP id s11-v6mr9686130plp.304.1527828743110; Thu, 31 May 2018 21:52:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527828743; cv=none; d=google.com; s=arc-20160816; b=kEd6c+Q9WTIhaYpdkSooSEYBykTRBAcXt+GGwBeW76DK6m09GHwTPlY7Gw9gZSeNXe u9aYFsTVtaDk6KN1LMBSDVpI2tz73FFHr1L90V7NNOafm3/Cf+rcKKO0MRhBNYZD4dRW QRaw21XqnWxXJavxso4yBfAmkLcwDbblsIHggqXYhziJtFfQoGuOABO5UWWN03GgUeH8 ab/d+ArhF2ncVwpA+WiOn4fY+JyxVnCQFrc5LgCvsuvHo69qQOdu7prrl/U/DV+cGs6N G3XWJgOEFCPN+v/DXYvJzVjFIM+Clk8vwKXJQ+u5/Fh5dazxQfTiNJ81+gBrag2UhLUh FNZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:cc:subject:date:to :from:arc-authentication-results; bh=1OxVxqDdj1s7GB0ccdQSOce7sC9PaadjXf0YnOe3D6k=; b=NdERYZEuuDBqu6SNa1j4N6z3cV54ZnSAbyBVrSZEoZZmt0IoiabZ3HzzQmyTUVgihW LNXQffAWbNKmpG2h7bFNFZ6Tx2p4pv+KcspWc2Si+ws3beLcPXBjnIxuM9PqH2m+/7X+ YB2VmA38YslIACPw/3V4YQvRKimDduPr3UWfifSEztkPMWbngUl0uXKFlY2ir3EPJ5Rn SC0656VwzzxjcuisdDt77ahDeqCMFGUxsQBvEL7VLkQTi6ejRlJYaKLsaVLLG8tG+pZf ppRXmXF5W00AHtXeooFalIe3BiTDs9Ot6b3zGcva+ru/ne/xJCH9QPEA4PfdiByaow8V NMtQ== 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 s24-v6si1807283pgv.494.2018.05.31.21.52.07; Thu, 31 May 2018 21:52:23 -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 S1751439AbeFAEpr (ORCPT + 99 others); Fri, 1 Jun 2018 00:45:47 -0400 Received: from mx2.suse.de ([195.135.220.15]:34054 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751393AbeFAEpm (ORCPT ); Fri, 1 Jun 2018 00:45:42 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6ADE7AD02; Fri, 1 Jun 2018 04:45:41 +0000 (UTC) From: NeilBrown To: Thomas Graf , Herbert Xu Date: Fri, 01 Jun 2018 14:44:09 +1000 Subject: [PATCH 06/18] rhashtable: simplify nested_table_alloc() and rht_bucket_nested_insert() Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <152782824950.30340.10831876745236207066.stgit@noble> In-Reply-To: <152782754287.30340.4395718227884933670.stgit@noble> References: <152782754287.30340.4395718227884933670.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we don't use the hash value or shift in nested_table_alloc() there is room for simplification. We only need to pass a "is this a leaf" flag to nested_table_alloc(), and don't need to track as much information in rht_bucket_nested_insert(). Note there is another minor cleanup in nested_table_alloc() here. The number of elements in a page of "union nested_tables" is most naturally PAGE_SIZE / sizeof(ntbl[0]) The previous code had PAGE_SIZE / sizeof(ntbl[0].bucket) which happens to be the correct value only because the bucket uses all the space in the union. Signed-off-by: NeilBrown --- lib/rhashtable.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/rhashtable.c b/lib/rhashtable.c index 8582e1916c2d..e209069f1d74 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -116,7 +116,7 @@ static void bucket_table_free_rcu(struct rcu_head *head) static union nested_table *nested_table_alloc(struct rhashtable *ht, union nested_table __rcu **prev, - unsigned int shifted) + bool leaf) { union nested_table *ntbl; int i; @@ -127,8 +127,8 @@ static union nested_table *nested_table_alloc(struct rhashtable *ht, ntbl = kzalloc(PAGE_SIZE, GFP_ATOMIC); - if (ntbl && shifted) { - for (i = 0; i < PAGE_SIZE / sizeof(ntbl[0].bucket); i++) + if (ntbl && leaf) { + for (i = 0; i < PAGE_SIZE / sizeof(ntbl[0]); i++) INIT_RHT_NULLS_HEAD(ntbl[i].bucket); } @@ -155,7 +155,7 @@ static struct bucket_table *nested_bucket_table_alloc(struct rhashtable *ht, return NULL; if (!nested_table_alloc(ht, (union nested_table __rcu **)tbl->buckets, - 0)) { + false)) { kfree(tbl); return NULL; } @@ -1209,24 +1209,18 @@ struct rhash_head __rcu **rht_bucket_nested_insert(struct rhashtable *ht, unsigned int index = hash & ((1 << tbl->nest) - 1); unsigned int size = tbl->size >> tbl->nest; union nested_table *ntbl; - unsigned int shifted; - unsigned int nhash; ntbl = (union nested_table *)rcu_dereference_raw(tbl->buckets[0]); hash >>= tbl->nest; - nhash = index; - shifted = tbl->nest; ntbl = nested_table_alloc(ht, &ntbl[index].table, - size <= (1 << shift) ? shifted : 0); + size <= (1 << shift)); while (ntbl && size > (1 << shift)) { index = hash & ((1 << shift) - 1); size >>= shift; hash >>= shift; - nhash |= index << shifted; - shifted += shift; ntbl = nested_table_alloc(ht, &ntbl[index].table, - size <= (1 << shift) ? shifted : 0); + size <= (1 << shift)); } if (!ntbl)