From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161429AbdAFMRu (ORCPT ); Fri, 6 Jan 2017 07:17:50 -0500 Received: from mx2.suse.de ([195.135.220.15]:44384 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759259AbdAFMQo (ORCPT ); Fri, 6 Jan 2017 07:16:44 -0500 Date: Fri, 6 Jan 2017 13:16:42 +0100 From: Michal Hocko To: Tom Herbert Cc: linux-mm@kvack.org, LKML Subject: Re: weird allocation pattern in alloc_ila_locks Message-ID: <20170106121642.GJ5556@dhcp22.suse.cz> References: <20170106095115.GG5556@dhcp22.suse.cz> <20170106100433.GH5556@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170106100433.GH5556@dhcp22.suse.cz> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I was thinking about the rhashtable which was the source of the c&p and it can be simplified as well. --- >>From 555543604f5f020284ea85d928d52f6a55fde7ca Mon Sep 17 00:00:00 2001 From: Michal Hocko Date: Fri, 6 Jan 2017 13:12:31 +0100 Subject: [PATCH] rhashtable: simplify a strange allocation pattern alloc_bucket_locks allocation pattern is quite unusual. We are preferring vmalloc when CONFIG_NUMA is enabled which doesn't make much sense because there is no special NUMA locality handled in that code path. Let's just simplify the code and use kvmalloc helper, which is a transparent way to use kmalloc with vmalloc fallback, if the caller is allowed to block and use the flag otherwise. Signed-off-by: Michal Hocko --- lib/rhashtable.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/rhashtable.c b/lib/rhashtable.c index 32d0ad058380..4d3886b6ab7d 100644 --- a/lib/rhashtable.c +++ b/lib/rhashtable.c @@ -77,16 +77,9 @@ static int alloc_bucket_locks(struct rhashtable *ht, struct bucket_table *tbl, size = min_t(unsigned int, size, tbl->size >> 1); if (sizeof(spinlock_t) != 0) { - tbl->locks = NULL; -#ifdef CONFIG_NUMA - if (size * sizeof(spinlock_t) > PAGE_SIZE && - gfp == GFP_KERNEL) - tbl->locks = vmalloc(size * sizeof(spinlock_t)); -#endif - if (gfp != GFP_KERNEL) - gfp |= __GFP_NOWARN | __GFP_NORETRY; - - if (!tbl->locks) + 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) -- 2.11.0 -- Michal Hocko SUSE Labs