bcachefs: Add an option to control sharding new inode numbers
authorKent Overstreet <kent.overstreet@gmail.com>
Fri, 28 May 2021 00:20:20 +0000 (20:20 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:04 +0000 (17:09 -0400)
We're seeing a bug where inode creates end up spinning in
bch2_inode_create - disabling sharding will simplify what we're testing.

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

index 98a87e4928abf7d03fa95f53b68420d40ba0051a..6cfb8959d57940f72d64f1a6206cbe0ea214b0bf 100644 (file)
@@ -1348,6 +1348,7 @@ LE64_BITMASK(BCH_SB_GC_RESERVE_BYTES,     struct bch_sb, flags[2],  4, 64);
 
 LE64_BITMASK(BCH_SB_ERASURE_CODE,      struct bch_sb, flags[3],  0, 16);
 LE64_BITMASK(BCH_SB_METADATA_TARGET,   struct bch_sb, flags[3], 16, 28);
+LE64_BITMASK(BCH_SB_SHARD_INUMS,       struct bch_sb, flags[3], 28, 29);
 
 /*
  * Features:
index 2ae55467c583132fb22c4f3c2f54209dd3ef3cd9..0af493c8669d5f535d7da28b74a0b87de1877927 100644 (file)
@@ -479,16 +479,23 @@ struct btree_iter *bch2_inode_create(struct btree_trans *trans,
        struct bkey_s_c k;
        u64 min, max, start, pos, *hint;
        int ret = 0;
+       unsigned bits = (c->opts.inodes_32bit ? 31 : 63);
 
-       u64 cpu = raw_smp_processor_id();
-       unsigned bits = (c->opts.inodes_32bit
-               ? 31 : 63) - c->inode_shard_bits;
+       if (c->opts.shard_inode_numbers) {
+               u64 cpu = raw_smp_processor_id();
 
-       min = (cpu << bits);
-       max = (cpu << bits) | ~(ULLONG_MAX << bits);
+               bits -= c->inode_shard_bits;
 
-       min = max_t(u64, min, BLOCKDEV_INODE_MAX);
-       hint = c->unused_inode_hints + cpu;
+               min = (cpu << bits);
+               max = (cpu << bits) | ~(ULLONG_MAX << bits);
+
+               min = max_t(u64, min, BLOCKDEV_INODE_MAX);
+               hint = c->unused_inode_hints + cpu;
+       } else {
+               min = BLOCKDEV_INODE_MAX;
+               max = ~(ULLONG_MAX << bits);
+               hint = c->unused_inode_hints;
+       }
 
        start = READ_ONCE(*hint);
 
index 42bf38922d468b3b35a84de6b30b4d30cc0a2c7e..074ab2d4f0faf35908f796e7d445e59c6c9ab6bb 100644 (file)
@@ -165,8 +165,13 @@ enum opt_type {
        x(inodes_32bit,                 u8,                             \
          OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                             \
          OPT_BOOL(),                                                   \
-         BCH_SB_INODE_32BIT,           false,                          \
+         BCH_SB_INODE_32BIT,           true,                           \
          NULL,         "Constrain inode numbers to 32 bits")           \
+       x(shard_inode_numbers,          u8,                             \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                             \
+         OPT_BOOL(),                                                   \
+         BCH_SB_SHARD_INUMS,           false,                          \
+         NULL,         "Shard new inode numbers by CPU id")            \
        x(gc_reserve_percent,           u8,                             \
          OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                             \
          OPT_UINT(5, 21),                                              \