Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2157551imm; Mon, 28 May 2018 02:51:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqFE2ybLmVMxy3vt08OnyIhmakSy9OuCDqZceGi/NkhUrpNgNyAkbLy5SGsq/nSwsP0mgp0 X-Received: by 2002:a62:6304:: with SMTP id x4-v6mr12807774pfb.94.1527501078068; Mon, 28 May 2018 02:51:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527501078; cv=none; d=google.com; s=arc-20160816; b=qmODw29Ju9h3N1uhaJN7M3/m8609KUnrHemDcVG//qH22NIjVZlyZJAclCSv0bd6A3 VR7CoMmnCoWX8DkQdlZoU9jZNXvtk7LtV5wlupkNOi+MoYxPlRmcK0Ev9K8MelS3+zUo R5nzp6CXcAyukVj3Ktl4DYmhpYIaMAwIpHTWQWtTUT57ExBBqYG6psj6eLgZYUx10Zwv csqqDh90ImE+/f5X65yPPV2uSkQwvzsMYrvDz8udi0vdn0IX/hpQ2urHVZs/T5T0eS9I Lcw1m7MjBbRvO9q7qwpqd/Xiuc96CKnEd+cTnbL/ZI5NL9+1r9zJnsFm/tBZ5hqOdMsH CBjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=VSwn9VhgBK7g51KxTsoVao9alR/chIESRNrKX7vfigA=; b=s6TIeHBkQEIsObqYOO2Eg+dF8wkGbf5EC3kfNmBFukSXYVTOxi69sO0bAkB8DiVJYj ktEzLm63wUcDZUz3ls/t7N6IoG3PtA5QEBr+yEwveXjReVsk+hTOCLd7AOAJscLknkEQ PJfJ85BMwsHth2SL5iMFbju96zgGloL9dy2VP5Ra1Q23fm7ezFzBI/8/b9BRiclAJvk4 KssAeyewENsiII574vcnSH4mEKDTdg2kjg8r85iEX5PPhIqz6/vV6ARvJXRCNXTGkh+r 67i52cGBxM2w0QcoZ2VuWkQuHSViuCycgRejMgvxIrCjzghWDjGPdaXeUYAWJhRPn7M/ BKWw== 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 f9-v6si28149465plo.568.2018.05.28.02.51.03; Mon, 28 May 2018 02:51:18 -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 S933450AbeE1Ju2 (ORCPT + 99 others); Mon, 28 May 2018 05:50:28 -0400 Received: from orcrist.hmeau.com ([104.223.48.154]:40950 "EHLO deadmen.hmeau.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932300AbeE1JuG (ORCPT ); Mon, 28 May 2018 05:50:06 -0400 Received: from gondobar.mordor.me.apana.org.au ([192.168.128.4] helo=gondobar) by deadmen.hmeau.com with esmtps (Exim 4.89 #2 (Debian)) id 1fNEmt-0002Vo-OM; Mon, 28 May 2018 17:49:59 +0800 Received: from herbert by gondobar with local (Exim 4.89) (envelope-from ) id 1fNEmq-0004gE-Lq; Mon, 28 May 2018 17:49:56 +0800 Date: Mon, 28 May 2018 17:49:56 +0800 From: Herbert Xu To: Davidlohr Bueso Cc: akpm@linux-foundation.org, torvalds@linux-foundation.org, tgraf@suug.ch, manfred@colorfullife.com, guillaume.knispel@supersonicimagine.com, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: Re: [PATCH 2/6] lib/rhashtable: guarantee initial hashtable allocation Message-ID: <20180528094956.zaxusqqju3wtbdcz@gondor.apana.org.au> References: <20180524211135.27760-1-dave@stgolabs.net> <20180524211135.27760-3-dave@stgolabs.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180524211135.27760-3-dave@stgolabs.net> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 24, 2018 at 02:11:31PM -0700, Davidlohr Bueso wrote: > > -static struct bucket_table *bucket_table_alloc(struct rhashtable *ht, > - size_t nbuckets, > - gfp_t gfp) > +static struct bucket_table *__bucket_table_alloc(struct rhashtable *ht, > + size_t nbuckets, > + gfp_t gfp, bool retry) > { > struct bucket_table *tbl = NULL; > size_t size, max_locks; > int i; > > size = sizeof(*tbl) + nbuckets * sizeof(tbl->buckets[0]); > + if (retry) { > + gfp |= __GFP_NOFAIL; > + tbl = kzalloc(size, gfp); > + } /* fall-through */ I'd prefer this logic to be moved to the caller. So just call the function with GFP_KERNEL | __GFP_NOFAIL. Of course you need to modify bucket_table_alloc so that it still treats this as GFP_KERNEL (as opposed to GFP_ATOMIC). That is, instead of > if (gfp != GFP_KERNEL) You will need if ((gfp & ~__GFP_NOFAIL) != GFP_KERNEL) > @@ -1067,9 +1086,20 @@ int rhashtable_init(struct rhashtable *ht, > } > } > > + /* > + * This is api initialization and thus we need to guarantee the > + * initial rhashtable allocation. Upon failure, retry with a > + * smallest possible size, otherwise we exhaust our options with > + * __GFP_NOFAIL. > + */ > tbl = bucket_table_alloc(ht, size, GFP_KERNEL); > - if (tbl == NULL) > - return -ENOMEM; > + if (unlikely(tbl == NULL)) { > + size = HASH_MIN_SIZE; > + > + tbl = bucket_table_alloc(ht, size, GFP_KERNEL); > + if (tbl == NULL) > + tbl = bucket_table_alloc_retry(ht, size, GFP_KERNEL); > + } Perhaps you should also explain here why we don't just try the minimum size with __GFP_NOFAIL as the second step rather than the third. Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt