Skip to content

Commit

Permalink
bcachefs: Increase size of cuckoo hash table on too many rehashes
Browse files Browse the repository at this point in the history
Also, improve the calculation of the new table size, so that it can
shrink when needed.

Signed-off-by: Kent Overstreet <[email protected]>
  • Loading branch information
Kent Overstreet committed Aug 16, 2024
1 parent 58474f7 commit c2f6e16
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions fs/bcachefs/buckets_waiting_for_journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int bch2_set_bucket_needs_journal_commit(struct buckets_waiting_for_journal *b,
.dev_bucket = (u64) dev << 56 | bucket,
.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;

mutex_lock(&b->lock);
Expand All @@ -106,7 +106,7 @@ int bch2_set_bucket_needs_journal_commit(struct buckets_waiting_for_journal *b,
for (i = 0; i < size; i++)
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);
if (!n) {
Expand All @@ -115,7 +115,14 @@ int bch2_set_bucket_needs_journal_commit(struct buckets_waiting_for_journal *b,
}

retry_rehash:
if (nr_rehashes_this_size == 3) {
new_bits++;
nr_rehashes_this_size = 0;
}

nr_rehashes++;
nr_rehashes_this_size++;

bucket_table_init(n, new_bits);

tmp = new;
Expand Down

0 comments on commit c2f6e16

Please sign in to comment.