* mount: leave -cacheMinFreeSpace free on the chunk cache's disk
weed mount sizes its on-disk chunk cache by -cacheCapacityMB alone and
preallocates each cache file in full when it creates it. With a capacity
larger than the free space of the disk holding -cacheDir, the cache takes
that disk down to nothing: the preallocations run until fallocate fails,
and chunk writes fill the rest. The mount's metadata cache (a leveldb
store under -cacheDir) and the swap files of dirty pages (-cacheDirWrite,
which defaults to -cacheDir) live on the same disk, so once it is full
their writes fail with ENOSPC, and writes whose dirty pages spill to
swap return EIO to the application. The same happens when several mounts
share a cache disk and together are configured beyond it.
-cacheMinFreeSpace is the free space the cache leaves on that disk,
written like the volume server's -minFreeSpace: a percentage like 1 or a
size like 10GiB, 1 by default, as for volume servers.
- When the cache opens, its disk layers shrink to the space above the
floor, counting the cache files already in the directory as the cache's
own. With no room the disk tier keeps no files.
- Each new cache file preallocates only what the disk holds above the
floor at that moment, so the files of one cache, or the caches of
several mounts opening together, stop reserving at the floor.
- A chunk write that lands in blocks its file already holds, preallocated
or written, goes ahead as before, even with the disk under the floor.
A write that takes new disk space, into a file a rotation truncated or
where nothing could be preallocated, goes ahead only while the space
above the floor covers it. The disk is read at most once a second, and
the cache counts what it takes in between, so it cannot run past the
floor between readings. A rotation gives the truncated file's blocks
back, so the write after it reads the disk again.
A chunk the cache cannot place is not cached, like any other miss. The
webdav server's cache passes no floor and behaves as before.
* mount: read the cache disk on every write that takes space, leave the index files room
Review follow-ups.
- take reads the disk each time, instead of once a second less what the
cache took since, so a write sees what other mounts sharing the disk
wrote, and what a rotation gave back. It runs only for writes past the
blocks a file already holds, and a statfs costs little next to the
write.
- The index files (.idx and the leveldb maps) grow by a few dozen bytes a
chunk beside the data files that the cache size counts. Sizing leaves
them a sixteenth of the room above the floor.
- The cache's own files count as room by the blocks they hold, so a file
that was preallocated but not yet written when the mount exited counts
in full when the cache reopens.
- weed fuse checks -o cacheMinFreeSpace in the parent as well: the parent
waits for the child's signal, and a child that rejects the value never
sends it.
* mount: keep the resolveCacheDirs doc comment on resolveCacheDirs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* mount: say -cacheMinFreeSpace stops new disk space, not every chunk
Under the floor the cache still fills the blocks its files already hold.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* chore(weed/util/chunk_cache): remove unused functions
* fix(chunk_cache): bound ReadAt buffer in readNeedleSliceAt
When the caller-provided buffer is larger than the remaining needle
bytes, ReadAt would spill into the next needle and trigger the
n != wanted error. Slice to data[:wanted] so the read stops at the
needle boundary.
---------
Co-authored-by: Chris Lu <chris.lu@gmail.com>