mirror of
https://github.com/torvalds/linux.git
synced 2024-12-28 05:41:55 +00:00
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: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
58474f76a7
commit
c2f6e16a67
@ -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,
|
|||||||
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,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
Loading…
Reference in New Issue
Block a user