Clone
1
Directory Usage
Chris Lu edited this page 2026-12-03 23:42:26 -08:00

Directory Usage

The dir_usage plugin worker job keeps the size of each bucket and of the large directories in it, so that reading them walks nothing. It is off by default; turn it on for its job type in the admin UI. fs.du -report reads what it keeps.

What it keeps

For each bucket, and each top-level directory outside the buckets folder, the job keeps what fs.du adds up (bytes, chunks, files and directories) of the bucket and of each directory in it holding at least 1% of the bucket's bytes, down to 10 levels below the bucket. A smaller or deeper directory counts toward the directory above it. Directories at one depth do not overlap, so a bucket has at most 1,000 such directories, whatever the shape of its tree.

The totals of a bucket are one file, /etc/seaweedfs/dir_usage/<store signature>/buckets/<bucket>.json, or .../top/<name>.json for a top-level directory. The job's position in the metadata log is /etc/seaweedfs/dir_usage/cursor-<store signature>.json, and meta_log_purge keeps the log from there on.

How it stays current

  • A bucket without totals is walked once while the job follows the metadata log, and the two are reconciled, so the totals are those of the bucket at one position in the log. All buckets without totals are walked in one walk of the buckets folder, and the top-level directories in one walk of /. A walk takes about as long as fs.du of the same tree.
  • After that, each run (every hour by default) replays the metadata events since the last one and rewrites the files that changed.
  • A bucket created since the last run is walked by the next one.
  • A directory that moves keeps its totals at its new path.
  • A directory that grows past 1% after its bucket was walked counts toward the directory above it until the bucket is walked again.
  • A bucket whose events the log no longer holds is walked again, as after the job was off for longer than meta_log_purge keeps the log for it.

To have a bucket walked again, delete its file; the next run walks it:

> fs.rm /etc/seaweedfs/dir_usage/<store signature>/buckets/<bucket>.json

An entry that a TTL expires comes off in the first run after the end of the hour it expires in, or, for a TTL of 200 hours or more, after the end of a step of up to 1% of the TTL. The filer removes such an entry without logging an event, so the job keeps when each one expires. An S3 lifecycle expiration also logs a delete, and the entry comes off only once.

Reading it

> fs.du -report -depth=1 /buckets/media
block:1201	logical size:  14680064	/buckets/media/2025
block: 702	logical size:   6729608	/buckets/media/2026
block:1903	logical size:  21409672	/buckets/media
as of 2026-12-03T08:30:00Z, 12m0s ago