Skip to content

Commit

Permalink
lib/rhashtable: simplify bucket_table_alloc()
Browse files Browse the repository at this point in the history
As of ce91f6e ("mm: kvmalloc does not fallback to vmalloc for
incompatible gfp flags") we can simplify the caller and trust kvzalloc()
to just do the right thing.  For the case of the GFP_ATOMIC context, we
can drop the __GFP_NORETRY flag for obvious reasons, and for the
__GFP_NOWARN case, however, it is changed such that the caller passes the
flag instead of making bucket_table_alloc() handle it.

This slightly changes the gfp flags passed on to nested_table_alloc() as
it will now also use GFP_ATOMIC | __GFP_NOWARN.  However, I consider this
a positive consequence as for the same reasons we want nowarn semantics in
bucket_table_alloc().

[manfred@colorfullife.com: commit id extended to 12 digits, line wraps updated]
Link: http://lkml.kernel.org/r/20180712185241.4017-8-manfred@colorfullife.com
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Kees Cook <keescook@chromium.org>
Cc: Michael Kerrisk <mtk.manpages@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Davidlohr Bueso authored and Linus Torvalds committed Aug 22, 2018
1 parent 82061c5 commit 93f976b
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/rhashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,7 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht,
int i;

size = sizeof(*tbl) + nbuckets * sizeof(tbl->buckets[0]);
if (gfp != GFP_KERNEL)
tbl = kzalloc(size, gfp | __GFP_NOWARN | __GFP_NORETRY);
else
tbl = kvzalloc(size, gfp);
tbl = kvzalloc(size, gfp);

size = nbuckets;

Expand Down Expand Up @@ -450,7 +447,7 @@ static int rhashtable_insert_rehash(struct rhashtable *ht,

err = -ENOMEM;

new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC);
new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC | __GFP_NOWARN);
if (new_tbl == NULL)
goto fail;

Expand Down

0 comments on commit 93f976b

Please sign in to comment.