Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5760894imm; Mon, 23 Jul 2018 05:44:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfe60JrxrkWQTxfBgIlxXSVrdirgfhtlNj+IEE1bHugXRfMJKaeLjweQCIWj8FQQSmINTKe X-Received: by 2002:a63:be4a:: with SMTP id g10-v6mr11942626pgo.378.1532349870721; Mon, 23 Jul 2018 05:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532349870; cv=none; d=google.com; s=arc-20160816; b=q/2y7F6X0GoGnQyZHpEayLHfhjtkPe6O4AL+qwP7bkg7l11+WfnBcjWY3Pmg5S2opC pvgAI2hNbAmZ2kLLOtz+D51C/vbxugG2oTX+BrVtup0QUNFHy72vIRhtAV2+jZT6TyJ9 g+XmwM3J7O6Z/xbQ81OJ8Qi9/ch86FOaj2UuTUVIFuyoJcg5A60IZbt4Uz8d1+5mGu5s CG+SKzgKa97O5uLwP1nuG1M3OFhJzJwiBsWEbNtGOWV0f/+rsA50inzir2S2RWpLaI+M a68PIPahelo0M7xdLUPC6s6Cywsar32Ts/1HKmPkuQEuMDHWNc7hkLaFx0EJ5OmF/eiM Vz6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=JqnAbS6uCGW8xXgi9fSmDUzRlEKAUAsvwP/8sYkljY8=; b=bo4pCKC9Gz4fDkKdO66Y4qzCIdngsN96eayWAmVgTSG2Ag3BsLDFXvyTQYl4Eux595 iiNK4apdoFRu/eIH9R/sBc9MZDhNMeijwClTESnRpOwdXFjmctOkyjaAukXsFwUNMph1 y/iEr2I59K4SJkSTV1QKuiptrg4CEZF+mo9QE5xh601z7bUryZT2XaYSY3PKampPOjVX 1GgjK7LM/JFc33UuuYz1GFq19fwc5/xZwBmEDWAG/xaGP1vxCrJx7Le3t1fZQ14+zXem 0JniqKRqvvvh1QIRGEKXSUjRAqjpUfgYYudvWrx+2h0nGIX0t7nyNcxuQR+PsRq/uUqL N8/Q== 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 5-v6si8322841pgp.439.2018.07.23.05.44.16; Mon, 23 Jul 2018 05:44:30 -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 S2388533AbeGWNnx (ORCPT + 99 others); Mon, 23 Jul 2018 09:43:53 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47616 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388251AbeGWNnx (ORCPT ); Mon, 23 Jul 2018 09:43:53 -0400 Received: from localhost (LFbn-1-12238-233.w90-92.abo.wanadoo.fr [90.92.53.233]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2DF4ABCF; Mon, 23 Jul 2018 12:42:50 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Davidlohr Bueso , Herbert Xu , "David S. Miller" Subject: [PATCH 4.4 010/107] lib/rhashtable: consider param->min_size when setting initial table size Date: Mon, 23 Jul 2018 14:41:04 +0200 Message-Id: <20180723122413.381466292@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180723122413.003644357@linuxfoundation.org> References: <20180723122413.003644357@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Davidlohr Bueso [ Upstream commit 107d01f5ba10f4162c38109496607eb197059064 ] rhashtable_init() currently does not take into account the user-passed min_size parameter unless param->nelem_hint is set as well. As such, the default size (number of buckets) will always be HASH_DEFAULT_SIZE even if the smallest allowed size is larger than that. Remediate this by unconditionally calling into rounded_hashtable_size() and handling things accordingly. Signed-off-by: Davidlohr Bueso Acked-by: Herbert Xu Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- lib/rhashtable.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -670,8 +670,16 @@ EXPORT_SYMBOL_GPL(rhashtable_walk_stop); static size_t rounded_hashtable_size(const struct rhashtable_params *params) { - return max(roundup_pow_of_two(params->nelem_hint * 4 / 3), - (unsigned long)params->min_size); + size_t retsize; + + if (params->nelem_hint) + retsize = max(roundup_pow_of_two(params->nelem_hint * 4 / 3), + (unsigned long)params->min_size); + else + retsize = max(HASH_DEFAULT_SIZE, + (unsigned long)params->min_size); + + return retsize; } static u32 rhashtable_jhash2(const void *key, u32 length, u32 seed) @@ -728,8 +736,6 @@ int rhashtable_init(struct rhashtable *h struct bucket_table *tbl; size_t size; - size = HASH_DEFAULT_SIZE; - if ((!params->key_len && !params->obj_hashfn) || (params->obj_hashfn && !params->obj_cmpfn)) return -EINVAL; @@ -756,8 +762,7 @@ int rhashtable_init(struct rhashtable *h ht->p.min_size = max(ht->p.min_size, HASH_MIN_SIZE); - if (params->nelem_hint) - size = rounded_hashtable_size(&ht->p); + size = rounded_hashtable_size(&ht->p); /* The maximum (not average) chain length grows with the * size of the hash table, at a rate of (log N)/(log log N).