Skip to content

Commit

Permalink
rhashtable: Schedule async resize when sync realloc fails
Browse files Browse the repository at this point in the history
When rhashtable_insert_rehash() fails with ENOMEM, this indicates that
we can't allocate the necessary memory in the current context but the
limits as set by the user would still allow to grow.

Thus attempt an async resize in the background where we can allocate
using GFP_KERNEL which is more likely to succeed. The insertion itself
will still fail to indicate pressure.

This fixes a bug where the table would never continue growing once the
utilization is above 100%.

Fixes: ccd57b1 ("rhashtable: Add immediate rehash during insertion")
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Thomas Graf authored and David S. Miller committed Apr 22, 2015
1 parent d83769a commit e2307ed
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rhashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,13 @@ int rhashtable_insert_rehash(struct rhashtable *ht)
return -EBUSY;

new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC);
if (new_tbl == NULL)
if (new_tbl == NULL) {
/* Schedule async resize/rehash to try allocation
* non-atomic context.
*/
schedule_work(&ht->run_work);
return -ENOMEM;
}

err = rhashtable_rehash_attach(ht, tbl, new_tbl);
if (err) {
Expand Down

0 comments on commit e2307ed

Please sign in to comment.