x(mi_btree_bitmap,              BCH_VERSION(1,  7))             \
        x(bucket_stripe_sectors,        BCH_VERSION(1,  8))             \
        x(disk_accounting_v2,           BCH_VERSION(1,  9))             \
-       x(disk_accounting_v3,           BCH_VERSION(1, 10))
+       x(disk_accounting_v3,           BCH_VERSION(1, 10))             \
+       x(disk_accounting_inum,         BCH_VERSION(1, 11))
 
 enum bcachefs_metadata_version {
        bcachefs_metadata_version_min = 9,
 
                ret = bch2_disk_accounting_mod(trans, &acc_btree_key, &replicas_sectors, 1, gc);
                if (ret)
                        return ret;
+       } else {
+               bool insert = !(flags & BTREE_TRIGGER_overwrite);
+               struct disk_accounting_pos acc_inum_key = {
+                       .type           = BCH_DISK_ACCOUNTING_inum,
+                       .inum.inum      = k.k->p.inode,
+               };
+               s64 v[3] = {
+                       insert ? 1 : -1,
+                       insert ? k.k->size : -((s64) k.k->size),
+                       replicas_sectors,
+               };
+               ret = bch2_disk_accounting_mod(trans, &acc_inum_key, v, ARRAY_SIZE(v), gc);
+               if (ret)
+                       return ret;
        }
 
        if (bch2_bkey_rebalance_opts(k)) {
 
                        if (acc_k.type >= BCH_DISK_ACCOUNTING_TYPE_NR)
                                continue;
 
+                       if (acc_k.type == BCH_DISK_ACCOUNTING_inum)
+                               continue;
+
                        bch2_accounting_mem_read(c, k.k->p, v, nr);
 
                        if (memcmp(a.v->d, v, nr * sizeof(u64))) {
 
        struct disk_accounting_pos acc_k;
        bpos_to_disk_accounting_pos(&acc_k, a.k->p);
 
+       if (acc_k.type == BCH_DISK_ACCOUNTING_inum)
+               return 0;
+
        if (!gc && !read) {
                switch (acc_k.type) {
                case BCH_DISK_ACCOUNTING_persistent_reserved:
 
        x(compression,          4)              \
        x(snapshot,             5)              \
        x(btree,                6)              \
-       x(rebalance_work,       7)
+       x(rebalance_work,       7)              \
+       x(inum,                 8)
 
 enum disk_accounting_type {
 #define x(f, nr)       BCH_DISK_ACCOUNTING_##f = nr,
        __u32                   id;
 } __packed;
 
+struct bch_acct_inum {
+       __u64                   inum;
+} __packed;
+
 struct bch_acct_rebalance_work {
 };
 
                struct bch_acct_snapshot        snapshot;
                struct bch_acct_btree           btree;
                struct bch_acct_rebalance_work  rebalance_work;
+               struct bch_acct_inum            inum;
                } __packed;
        } __packed;
                struct bpos                     _pad;
 
          BCH_FSCK_ERR_accounting_key_replicas_nr_devs_0,       \
          BCH_FSCK_ERR_accounting_key_replicas_nr_required_bad, \
          BCH_FSCK_ERR_accounting_key_replicas_devs_unsorted,   \
-         BCH_FSCK_ERR_accounting_key_junk_at_end)
+         BCH_FSCK_ERR_accounting_key_junk_at_end)              \
+       x(disk_accounting_inum,                                 \
+         BIT_ULL(BCH_RECOVERY_PASS_check_allocations),         \
+         BCH_FSCK_ERR_accounting_mismatch)
 
 #define DOWNGRADE_TABLE()                                      \
        x(bucket_stripe_sectors,                                \