Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/rhashtable.c: use kvzalloc() in bucket_table_alloc() when possible

bucket_table_alloc() can be currently called with GFP_KERNEL or
GFP_ATOMIC. For the former we basically have an open coded kvzalloc()
while the later only uses kzalloc(). Let's simplify the code a bit by
the dropping the open coded path and replace it with kvzalloc().

Link: http://lkml.kernel.org/r/20170531155145.17111-3-mhocko@kernel.org
Signed-off-by: Michal Hocko <mhocko@suse.com>
Cc: Thomas Graf <tgraf@suug.ch>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Michal Hocko and committed by
Linus Torvalds
12e8fd6f c46ecce4

+3 -4
+3 -4
lib/rhashtable.c
··· 211 211 int i; 212 212 213 213 size = sizeof(*tbl) + nbuckets * sizeof(tbl->buckets[0]); 214 - if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER) || 215 - gfp != GFP_KERNEL) 214 + if (gfp != GFP_KERNEL) 216 215 tbl = kzalloc(size, gfp | __GFP_NOWARN | __GFP_NORETRY); 217 - if (tbl == NULL && gfp == GFP_KERNEL) 218 - tbl = vzalloc(size); 216 + else 217 + tbl = kvzalloc(size, gfp); 219 218 220 219 size = nbuckets; 221 220