Commit c2f6e16a authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Increase size of cuckoo hash table on too many rehashes

Also, improve the calculation of the new table size, so that it can
shrink when needed.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 58474f76
...@@ -93,7 +93,7 @@ int bch2_set_bucket_needs_journal_commit(struct buckets_waiting_for_journal *b, ...@@ -93,7 +93,7 @@ int bch2_set_bucket_needs_journal_commit(struct buckets_waiting_for_journal *b,
.dev_bucket = (u64) dev << 56 | bucket, .dev_bucket = (u64) dev << 56 | bucket,
.journal_seq = journal_seq, .journal_seq = journal_seq,
}; };
size_t i, size, new_bits, nr_elements = 1, nr_rehashes = 0; size_t i, size, new_bits, nr_elements = 1, nr_rehashes = 0, nr_rehashes_this_size = 0;
int ret = 0; int ret = 0;
mutex_lock(&b->lock); mutex_lock(&b->lock);
...@@ -106,7 +106,7 @@ int bch2_set_bucket_needs_journal_commit(struct buckets_waiting_for_journal *b, ...@@ -106,7 +106,7 @@ int bch2_set_bucket_needs_journal_commit(struct buckets_waiting_for_journal *b,
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
nr_elements += t->d[i].journal_seq > flushed_seq; nr_elements += t->d[i].journal_seq > flushed_seq;
new_bits = t->bits + (nr_elements * 3 > size); new_bits = ilog2(roundup_pow_of_two(nr_elements * 3));
n = kvmalloc(sizeof(*n) + (sizeof(n->d[0]) << new_bits), GFP_KERNEL); n = kvmalloc(sizeof(*n) + (sizeof(n->d[0]) << new_bits), GFP_KERNEL);
if (!n) { if (!n) {
...@@ -115,7 +115,14 @@ int bch2_set_bucket_needs_journal_commit(struct buckets_waiting_for_journal *b, ...@@ -115,7 +115,14 @@ int bch2_set_bucket_needs_journal_commit(struct buckets_waiting_for_journal *b,
} }
retry_rehash: retry_rehash:
if (nr_rehashes_this_size == 3) {
new_bits++;
nr_rehashes_this_size = 0;
}
nr_rehashes++; nr_rehashes++;
nr_rehashes_this_size++;
bucket_table_init(n, new_bits); bucket_table_init(n, new_bits);
tmp = new; tmp = new;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment