#7577·juicefs

Automatic metadata backup counts inodes of the --subdir quota but dumps the whole volume

Author: YuarenArtCreated Sep 24, 2026Updated Sep 29, 2026

What happened:

When a client is mounted with --subdir and that subdirectory has a quota, the automatic metadata backup (--backup-meta) takes the inode count from the quota, but dumps the whole volume.

Backup gets the count with m.StatFS(ctx, meta.RootInode, ...) (backup.go#L72). With --subdir, checkRoot(RootInode) returns the mounted subdirectory (base.go#L645-L654), and StatFS then reports UsedInodes of its quota (base.go#L1115-L1159). The dump starts from inode 0, the root of the volume (backup.go#L124).

Both checks that use the count get the small number:

  • the skip for more than 1e6 inodes with an interval of 1 hour or less (backup.go#L73-L77) does not fire;
  • fast mode turns on when the count is below 1e5 (backup.go#L87), so for SQL and TKV engines the dump loads the metadata of the whole volume into memory (sql.go#L4905-L4912).

A --subdir mount with a quota is the usual setup in juicefs-csi-driver: each dynamically provisioned PV is a subdirectory with a quota, and --backup-meta stays at the default 1h. juicedata/juicefs-csi-driver#1648 (mount pod OOMKilled hourly, stops with --backup-meta 0) may be related, but I have not confirmed that this is the cause there.

What you expected to happen:

The count used for these checks should describe what is dumped, the whole volume. In the same function, GetXattr, SetXattr and DumpMeta already use inode 0 for this. Passing 0 to StatFS as well fixes it:

diff
-			_ = m.StatFS(ctx, meta.RootInode, &dummy, &dummy, &iused, &dummy)
+			_ = m.StatFS(ctx, 0, &dummy, &dummy, &iused, &dummy)

df -i on the subdirectory mount still reports the quota. Only the backup changes. The line is the same on main.

How to reproduce it (as minimally and precisely as possible):

S=/tmp/jfs-repro; mkdir -p $S/mnt-root $S/mnt-pv
juicefs format --storage file --bucket $S/bucket/ sqlite3://$S/jfs.db demo
juicefs mount -d --backup-meta 0 sqlite3://$S/jfs.db $S/mnt-root
mkdir $S/mnt-root/pv1 && touch $S/mnt-root/pv1/f{0..9}
# 120000 files outside pv1, above the fast mode threshold of 1e5
python3 -c 'import os, sys
for d in range(120):
    p = f"{sys.argv[1]}/other/d{d}"; os.makedirs(p)
    for i in range(1000): open(f"{p}/f{i}", "w").close()' $S/mnt-root
df -i $S/mnt-root
juicefs umount $S/mnt-root
juicefs quota set sqlite3://$S/jfs.db --path /pv1 --capacity 1

# the mount a CSI mount pod makes for a PV; the short interval only makes the first backup start within seconds
SKIP_BACKUP_META_CHECK=true juicefs mount -d --subdir /pv1 --backup-meta 1m --log $S/pv.log sqlite3://$S/jfs.db $S/mnt-pv
sleep 20; grep 'backup metadata' $S/pv.log
df -i $S/mnt-pv

df -i reports 120132 used inodes on the root mount and 10 on the subdirectory mount. The backup log:

<INFO>: backup metadata succeed, fast mode: true, path: "file://$S/bucket/demo/meta/dump-2026-09-24-122425.json.gz", used 4.020622612s [[email protected]:90]

The dump holds the whole volume: 120133 entries, 120121 of them under /other. With the change above, the same mount logs:

<INFO>: backup metadata started, inodes=120132 [[email protected]:85]
<INFO>: backup metadata succeed, fast mode: false, path: "file://$S/bucket/demo/meta/dump-2026-09-24-121200.json.gz", used 8.879660877s [[email protected]:90]

Anything else we need to know?

On this volume juicefs dump --fast peaks at 161 MB RSS against 117 MB without it. The difference grows with the volume.

I can open a PR with the change and a unit test if this looks right.

Environment:

  • JuiceFS version (use juicefs --version) or Hadoop Java SDK version: 1.4.1+2026-07-30.0b90c7db, built from the v1.4.1 tag
  • Cloud provider or hardware configuration running JuiceFS: local workstation
  • OS (e.g cat /etc/os-release): Ubuntu 22.04.5 LTS
  • Kernel (e.g. uname -a): Linux 6.8.0-138-generic x86_64
  • Object storage (cloud provider and region, or self maintained): local, --storage file
  • Metadata engine info (version, cloud provider managed or self maintained): SQLite, built in (mattn/go-sqlite3 v1.14.24)
  • Network connectivity (JuiceFS to metadata engine, JuiceFS to object storage): all local
  • Others: quota set with juicefs quota set --capacity, as juicefs-csi-driver does