Skip to content

Commit 791c8ab

Browse files
committed
Merge tag 'bcachefs-2023-11-17' of https://evilpiepirate.org/git/bcachefs
Pull bcachefs fixes from Kent Overstreet: "Lots of small fixes for minor nits and compiler warnings. Bigger items: - The six locks lost wakeup is finally fixed: six_read_trylock() was checking for the waiting bit before decrementing the number of readers - validated the fix with a torture test. - Fix for a memory reclaim issue: when needing to reallocate a key cache key, we now do our usual GFP_NOWAIT; unlock(); GFP_KERNEL dance. - Multiple deleted inodes btree fixes - Fix an issue in fsck, where i_nlink would be recalculated incorrectly for hardlinked files if a snapshot had ever been taken. - Kill journal pre-reservations: This is a bigger patch than I would normally send at this point, but it deletes code and it fixes some of our tests that would sporadically die with the journal getting stuck, and it's a performance improvement, too" * tag 'bcachefs-2023-11-17' of https://evilpiepirate.org/git/bcachefs: (22 commits) bcachefs: Fix missing locking for dentry->d_parent access bcachefs: six locks: Fix lost wakeup bcachefs: Fix no_data_io mode checksum check bcachefs: Fix bch2_check_nlinks() for snapshots bcachefs: Don't decrease BTREE_ITER_MAX when LOCKDEP=y bcachefs: Disable debug log statements bcachefs: Fix missing transaction commit bcachefs: Fix error path in bch2_mount() bcachefs: Fix potential sleeping during mount bcachefs: Fix iterator leak in may_delete_deleted_inode() bcachefs: Kill journal pre-reservations bcachefs: Check for nonce offset inconsistency in data_update path bcachefs: Make sure to drop/retake btree locks before reclaim bcachefs: btree_trans->write_locked bcachefs: Run btree key cache shrinker less aggressively bcachefs: Split out btree_key_cache_types.h bcachefs: Guard against insufficient devices to create stripes bcachefs: Fix null ptr deref in bch2_backpointer_get_node() bcachefs: Fix multiple -Warray-bounds warnings bcachefs: Use DECLARE_FLEX_ARRAY() helper and fix multiple -Warray-bounds warnings ...
2 parents 12ee72f + ba276ce commit 791c8ab

27 files changed

+248
-377
lines changed

fs/bcachefs/backpointers.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,17 @@ struct btree *bch2_backpointer_get_node(struct btree_trans *trans,
313313
bp.level - 1,
314314
0);
315315
b = bch2_btree_iter_peek_node(iter);
316-
if (IS_ERR(b))
316+
if (IS_ERR_OR_NULL(b))
317317
goto err;
318318

319319
BUG_ON(b->c.level != bp.level - 1);
320320

321-
if (b && extent_matches_bp(c, bp.btree_id, bp.level,
322-
bkey_i_to_s_c(&b->key),
323-
bucket, bp))
321+
if (extent_matches_bp(c, bp.btree_id, bp.level,
322+
bkey_i_to_s_c(&b->key),
323+
bucket, bp))
324324
return b;
325325

326-
if (b && btree_node_will_make_reachable(b)) {
326+
if (btree_node_will_make_reachable(b)) {
327327
b = ERR_PTR(-BCH_ERR_backpointer_to_overwritten_btree_node);
328328
} else {
329329
backpointer_not_found(trans, bp_pos, bp, bkey_i_to_s_c(&b->key));

fs/bcachefs/bcachefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ struct journal_seq_blacklist_table {
617617
u64 start;
618618
u64 end;
619619
bool dirty;
620-
} entries[0];
620+
} entries[];
621621
};
622622

623623
struct journal_keys {

fs/bcachefs/btree_iter.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,8 +3087,6 @@ void bch2_trans_put(struct btree_trans *trans)
30873087
srcu_read_unlock(&c->btree_trans_barrier, trans->srcu_idx);
30883088
}
30893089

3090-
bch2_journal_preres_put(&c->journal, &trans->journal_preres);
3091-
30923090
kfree(trans->extra_journal_entries.data);
30933091

30943092
if (trans->fs_usage_deltas) {

fs/bcachefs/btree_key_cache.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,13 @@ static void bkey_cached_free(struct btree_key_cache *bc,
8989
ck->btree_trans_barrier_seq =
9090
start_poll_synchronize_srcu(&c->btree_trans_barrier);
9191

92-
if (ck->c.lock.readers)
92+
if (ck->c.lock.readers) {
9393
list_move_tail(&ck->list, &bc->freed_pcpu);
94-
else
94+
bc->nr_freed_pcpu++;
95+
} else {
9596
list_move_tail(&ck->list, &bc->freed_nonpcpu);
97+
bc->nr_freed_nonpcpu++;
98+
}
9699
atomic_long_inc(&bc->nr_freed);
97100

98101
kfree(ck->k);
@@ -109,6 +112,8 @@ static void __bkey_cached_move_to_freelist_ordered(struct btree_key_cache *bc,
109112
{
110113
struct bkey_cached *pos;
111114

115+
bc->nr_freed_nonpcpu++;
116+
112117
list_for_each_entry_reverse(pos, &bc->freed_nonpcpu, list) {
113118
if (ULONG_CMP_GE(ck->btree_trans_barrier_seq,
114119
pos->btree_trans_barrier_seq)) {
@@ -158,6 +163,7 @@ static void bkey_cached_move_to_freelist(struct btree_key_cache *bc,
158163
#else
159164
mutex_lock(&bc->lock);
160165
list_move_tail(&ck->list, &bc->freed_nonpcpu);
166+
bc->nr_freed_nonpcpu++;
161167
mutex_unlock(&bc->lock);
162168
#endif
163169
} else {
@@ -217,6 +223,7 @@ bkey_cached_alloc(struct btree_trans *trans, struct btree_path *path,
217223
f->nr < ARRAY_SIZE(f->objs) / 2) {
218224
ck = list_last_entry(&bc->freed_nonpcpu, struct bkey_cached, list);
219225
list_del_init(&ck->list);
226+
bc->nr_freed_nonpcpu--;
220227
f->objs[f->nr++] = ck;
221228
}
222229

@@ -229,6 +236,7 @@ bkey_cached_alloc(struct btree_trans *trans, struct btree_path *path,
229236
if (!list_empty(&bc->freed_nonpcpu)) {
230237
ck = list_last_entry(&bc->freed_nonpcpu, struct bkey_cached, list);
231238
list_del_init(&ck->list);
239+
bc->nr_freed_nonpcpu--;
232240
}
233241
mutex_unlock(&bc->lock);
234242
#endif
@@ -664,7 +672,6 @@ static int btree_key_cache_flush_pos(struct btree_trans *trans,
664672
goto out;
665673

666674
bch2_journal_pin_drop(j, &ck->journal);
667-
bch2_journal_preres_put(j, &ck->res);
668675

669676
BUG_ON(!btree_node_locked(c_iter.path, 0));
670677

@@ -762,18 +769,6 @@ bool bch2_btree_insert_key_cached(struct btree_trans *trans,
762769

763770
BUG_ON(insert->k.u64s > ck->u64s);
764771

765-
if (likely(!(flags & BTREE_INSERT_JOURNAL_REPLAY))) {
766-
int difference;
767-
768-
BUG_ON(jset_u64s(insert->k.u64s) > trans->journal_preres.u64s);
769-
770-
difference = jset_u64s(insert->k.u64s) - ck->res.u64s;
771-
if (difference > 0) {
772-
trans->journal_preres.u64s -= difference;
773-
ck->res.u64s += difference;
774-
}
775-
}
776-
777772
bkey_copy(ck->k, insert);
778773
ck->valid = true;
779774

@@ -850,6 +845,8 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
850845
* Newest freed entries are at the end of the list - once we hit one
851846
* that's too new to be freed, we can bail out:
852847
*/
848+
scanned += bc->nr_freed_nonpcpu;
849+
853850
list_for_each_entry_safe(ck, t, &bc->freed_nonpcpu, list) {
854851
if (!poll_state_synchronize_srcu(&c->btree_trans_barrier,
855852
ck->btree_trans_barrier_seq))
@@ -859,13 +856,15 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
859856
six_lock_exit(&ck->c.lock);
860857
kmem_cache_free(bch2_key_cache, ck);
861858
atomic_long_dec(&bc->nr_freed);
862-
scanned++;
863859
freed++;
860+
bc->nr_freed_nonpcpu--;
864861
}
865862

866863
if (scanned >= nr)
867864
goto out;
868865

866+
scanned += bc->nr_freed_pcpu;
867+
869868
list_for_each_entry_safe(ck, t, &bc->freed_pcpu, list) {
870869
if (!poll_state_synchronize_srcu(&c->btree_trans_barrier,
871870
ck->btree_trans_barrier_seq))
@@ -875,8 +874,8 @@ static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
875874
six_lock_exit(&ck->c.lock);
876875
kmem_cache_free(bch2_key_cache, ck);
877876
atomic_long_dec(&bc->nr_freed);
878-
scanned++;
879877
freed++;
878+
bc->nr_freed_pcpu--;
880879
}
881880

882881
if (scanned >= nr)
@@ -982,6 +981,9 @@ void bch2_fs_btree_key_cache_exit(struct btree_key_cache *bc)
982981
}
983982
#endif
984983

984+
BUG_ON(list_count_nodes(&bc->freed_pcpu) != bc->nr_freed_pcpu);
985+
BUG_ON(list_count_nodes(&bc->freed_nonpcpu) != bc->nr_freed_nonpcpu);
986+
985987
list_splice(&bc->freed_pcpu, &items);
986988
list_splice(&bc->freed_nonpcpu, &items);
987989

@@ -991,7 +993,6 @@ void bch2_fs_btree_key_cache_exit(struct btree_key_cache *bc)
991993
cond_resched();
992994

993995
bch2_journal_pin_drop(&c->journal, &ck->journal);
994-
bch2_journal_preres_put(&c->journal, &ck->res);
995996

996997
list_del(&ck->list);
997998
kfree(ck->k);

fs/bcachefs/btree_key_cache_types.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _BCACHEFS_BTREE_KEY_CACHE_TYPES_H
3+
#define _BCACHEFS_BTREE_KEY_CACHE_TYPES_H
4+
5+
struct btree_key_cache_freelist {
6+
struct bkey_cached *objs[16];
7+
unsigned nr;
8+
};
9+
10+
struct btree_key_cache {
11+
struct mutex lock;
12+
struct rhashtable table;
13+
bool table_init_done;
14+
15+
struct list_head freed_pcpu;
16+
size_t nr_freed_pcpu;
17+
struct list_head freed_nonpcpu;
18+
size_t nr_freed_nonpcpu;
19+
20+
struct shrinker *shrink;
21+
unsigned shrink_iter;
22+
struct btree_key_cache_freelist __percpu *pcpu_freed;
23+
24+
atomic_long_t nr_freed;
25+
atomic_long_t nr_keys;
26+
atomic_long_t nr_dirty;
27+
};
28+
29+
struct bkey_cached_key {
30+
u32 btree_id;
31+
struct bpos pos;
32+
} __packed __aligned(4);
33+
34+
#endif /* _BCACHEFS_BTREE_KEY_CACHE_TYPES_H */

0 commit comments

Comments
 (0)