bcachefs: Fix pathalogical behaviour with inode sharding by cpu ID
authorKent Overstreet <kent.overstreet@gmail.com>
Fri, 28 May 2021 09:06:18 +0000 (05:06 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:04 +0000 (17:09 -0400)
If the transactior restarts on a different CPU, it could end up needing
to read in a different btree node, which makes another transaction
restart more likely...

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/fs-common.c
fs/bcachefs/inode.c
fs/bcachefs/inode.h

index 08c6af886df7b651c8346e855ba923655838b714..00a63fecb976e6da858c1adc64de69d40fcf3710 100644 (file)
@@ -23,6 +23,7 @@ int bch2_create_trans(struct btree_trans *trans, u64 dir_inum,
        struct btree_iter *inode_iter = NULL;
        struct bch_hash_info hash = bch2_hash_info_init(c, new_inode);
        u64 now = bch2_current_time(c);
+       u64 cpu = raw_smp_processor_id();
        u64 dir_offset = 0;
        int ret;
 
@@ -36,7 +37,7 @@ int bch2_create_trans(struct btree_trans *trans, u64 dir_inum,
        if (!name)
                new_inode->bi_flags |= BCH_INODE_UNLINKED;
 
-       inode_iter = bch2_inode_create(trans, new_inode, U32_MAX);
+       inode_iter = bch2_inode_create(trans, new_inode, U32_MAX, cpu);
        ret = PTR_ERR_OR_ZERO(inode_iter);
        if (ret)
                goto err;
index 0af493c8669d5f535d7da28b74a0b87de1877927..524da018e9d94feb996059649b635ba6e82817d2 100644 (file)
@@ -472,7 +472,7 @@ static inline u32 bkey_generation(struct bkey_s_c k)
 
 struct btree_iter *bch2_inode_create(struct btree_trans *trans,
                                     struct bch_inode_unpacked *inode_u,
-                                    u32 snapshot)
+                                    u32 snapshot, u64 cpu)
 {
        struct bch_fs *c = trans->c;
        struct btree_iter *iter = NULL;
@@ -482,8 +482,6 @@ struct btree_iter *bch2_inode_create(struct btree_trans *trans,
        unsigned bits = (c->opts.inodes_32bit ? 31 : 63);
 
        if (c->opts.shard_inode_numbers) {
-               u64 cpu = raw_smp_processor_id();
-
                bits -= c->inode_shard_bits;
 
                min = (cpu << bits);
index 558d5464095d2506daf02bd614fab45f86b556a3..2cb081ae44d92f1c0c589528836397f4a9e967f9 100644 (file)
@@ -70,7 +70,7 @@ void bch2_inode_init(struct bch_fs *, struct bch_inode_unpacked *,
                     struct bch_inode_unpacked *);
 
 struct btree_iter *bch2_inode_create(struct btree_trans *,
-                                    struct bch_inode_unpacked *, u32);
+                                    struct bch_inode_unpacked *, u32, u64);
 
 int bch2_inode_rm(struct bch_fs *, u64, bool);