mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
mount: leave -cacheMinFreeSpace free on the chunk cache's disk (#13124)
* 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>
This commit is contained in:
18 files changed
+762
-16
No files matched your search
@@ -191,6 +191,8 @@ func runFuse(cmd *Command, args []string) bool {
|
||||
}
|
||||
case "cacheDirWrite":
|
||||
mountOptions.cacheDirForWrite = ¶meter.value
|
||||
case "cacheMinFreeSpace":
|
||||
mountOptions.cacheMinFreeSpace = ¶meter.value
|
||||
case "writeBufferSizeMB":
|
||||
if parsed, err := strconv.ParseInt(parameter.value, 0, 64); err == nil {
|
||||
mountOptions.writeBufferSizeMB = &parsed
|
||||
@@ -328,6 +330,11 @@ func runFuse(cmd *Command, args []string) bool {
|
||||
if err := checkIdmap(runtime.GOOS, *mountOptions.idmap, *mountOptions.defaultPermissions); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// The child checks it as well, but by then the parent only waits for
|
||||
// its signal, so a bad value has to fail here.
|
||||
if _, err := parseCacheMinFreeSpace(&mountOptions); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
util_http.InitGlobalHttpClient()
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ type MountOptions struct {
|
||||
cacheDirForRead *string
|
||||
cacheDirForWrite *string
|
||||
cacheSizeMBForRead *int64
|
||||
cacheMinFreeSpace *string
|
||||
writeBufferSizeMB *int64
|
||||
dataCenter *string
|
||||
allowOthers *bool
|
||||
@@ -120,6 +121,7 @@ func init() {
|
||||
mountOptions.readerCacheSizeMB = cmdMount.Flag.Int64("readerCacheSizeMB", 256, "memory budget in MiB for downloaded and in-flight reader buffers across all files; must fit the largest pooled chunk buffer")
|
||||
mountOptions.cacheDirForRead = cmdMount.Flag.String("cacheDir", os.TempDir(), "local cache directory for file chunks and meta data")
|
||||
mountOptions.cacheSizeMBForRead = cmdMount.Flag.Int64("cacheCapacityMB", 128, "file chunk read cache capacity in MB")
|
||||
mountOptions.cacheMinFreeSpace = cmdMount.Flag.String("cacheMinFreeSpace", "1", "free space the chunk cache leaves on the disk holding -cacheDir, as a percentage like 1 or a size like 10GiB: the cache shrinks to fit above it and takes no new disk space while the disk is under it")
|
||||
mountOptions.cacheDirForWrite = cmdMount.Flag.String("cacheDirWrite", "", "buffer writes mostly for large files")
|
||||
mountOptions.writeBufferSizeMB = cmdMount.Flag.Int64("writeBufferSizeMB", 0, "global cap on the per-mount write buffer (memory + swap) in MB, 0 means unlimited. Bounds /tmp growth when volume uploads stall")
|
||||
mountOptions.cacheMetaTtlSec = cmdMount.Flag.Int("cacheMetaTtlSec", 60, "metadata cache validity seconds")
|
||||
|
||||
@@ -198,6 +198,7 @@ type fileSystemParams struct {
|
||||
chunkSizeLimitMB int
|
||||
cacheDirForRead string
|
||||
cacheDirForWrite string
|
||||
cacheMinFree *util.MinFreeSpace // the parsed -cacheMinFreeSpace
|
||||
|
||||
// eagerFilerCreate persists a created file's entry at create time rather
|
||||
// than at flush. A platform sets it when it cannot run the flush before
|
||||
@@ -230,6 +231,7 @@ func buildSeaweedFileSystem(option *MountOptions, p fileSystemParams) *mount.WFS
|
||||
ReaderCacheSizeMB: readerCacheSizeMB,
|
||||
CacheDirForRead: p.cacheDirForRead,
|
||||
CacheSizeMBForRead: *option.cacheSizeMBForRead,
|
||||
CacheMinFreeSpace: p.cacheMinFree,
|
||||
CacheDirForWrite: p.cacheDirForWrite,
|
||||
WriteBufferSizeMB: *option.writeBufferSizeMB,
|
||||
CacheMetaTTlSec: *option.cacheMetaTtlSec,
|
||||
@@ -362,6 +364,19 @@ func resolveMountRoot(filerMountRootPath string) string {
|
||||
return mountRoot
|
||||
}
|
||||
|
||||
// parseCacheMinFreeSpace reads -cacheMinFreeSpace, written like the volume
|
||||
// server's -minFreeSpace.
|
||||
func parseCacheMinFreeSpace(option *MountOptions) (*util.MinFreeSpace, error) {
|
||||
if option.cacheMinFreeSpace == nil {
|
||||
return nil, nil
|
||||
}
|
||||
minFreeSpace, err := util.ParseMinFreeSpace(*option.cacheMinFreeSpace)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cacheMinFreeSpace %q: want a percentage like 1 or a size like 10GiB", *option.cacheMinFreeSpace)
|
||||
}
|
||||
return minFreeSpace, nil
|
||||
}
|
||||
|
||||
// resolveCacheDirs falls back to the read cache when no write cache is set.
|
||||
func resolveCacheDirs(option *MountOptions) (string, string) {
|
||||
cacheDirForRead := util.ResolvePath(*option.cacheDirForRead)
|
||||
|
||||
@@ -471,3 +471,36 @@ func Test_ensureMountRootDirectory(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func Test_parseCacheMinFreeSpace(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
value string
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{value: "1", want: "1.00%"},
|
||||
{value: "0", want: "0.00%"},
|
||||
{value: "10GiB", want: "10GiB"},
|
||||
{value: "101", wantErr: true},
|
||||
{value: "lots", wantErr: true},
|
||||
} {
|
||||
value := tc.value
|
||||
got, err := parseCacheMinFreeSpace(&MountOptions{cacheMinFreeSpace: &value})
|
||||
if tc.wantErr {
|
||||
if err == nil {
|
||||
t.Errorf("-cacheMinFreeSpace=%s: no error", tc.value)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("-cacheMinFreeSpace=%s: %v", tc.value, err)
|
||||
continue
|
||||
}
|
||||
if got.String() != tc.want {
|
||||
t.Errorf("-cacheMinFreeSpace=%s: %s, want %s", tc.value, got, tc.want)
|
||||
}
|
||||
}
|
||||
if got, err := parseCacheMinFreeSpace(&MountOptions{}); got != nil || err != nil {
|
||||
t.Errorf("unset -cacheMinFreeSpace: %v, %v; want no floor", got, err)
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,11 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
cacheMinFree, parseErr := parseCacheMinFreeSpace(option)
|
||||
if parseErr != nil {
|
||||
fmt.Println(parseErr)
|
||||
return false
|
||||
}
|
||||
|
||||
// basic checks
|
||||
chunkSizeLimitMB := *mountOptions.chunkSizeLimitMB
|
||||
@@ -264,6 +269,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
|
||||
chunkSizeLimitMB: chunkSizeLimitMB,
|
||||
cacheDirForRead: cacheDirForRead,
|
||||
cacheDirForWrite: cacheDirForWrite,
|
||||
cacheMinFree: cacheMinFree,
|
||||
})
|
||||
|
||||
if !createMountRoot(seaweedFileSystem, mountRoot, bucketRootPath, filerAddresses) {
|
||||
|
||||
@@ -34,6 +34,11 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
|
||||
fmt.Println(err)
|
||||
return false
|
||||
}
|
||||
cacheMinFree, parseErr := parseCacheMinFreeSpace(option)
|
||||
if parseErr != nil {
|
||||
fmt.Println(parseErr)
|
||||
return false
|
||||
}
|
||||
|
||||
chunkSizeLimitMB := *mountOptions.chunkSizeLimitMB
|
||||
if chunkSizeLimitMB <= 0 {
|
||||
@@ -105,6 +110,7 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
|
||||
chunkSizeLimitMB: chunkSizeLimitMB,
|
||||
cacheDirForRead: cacheDirForRead,
|
||||
cacheDirForWrite: cacheDirForWrite,
|
||||
cacheMinFree: cacheMinFree,
|
||||
// WinFsp posts the cleanup and close that carry the flush after
|
||||
// CloseHandle has already returned, so entry creation cannot wait
|
||||
// for the flush the way it does when close(2) runs it synchronously.
|
||||
|
||||
Reference in new issue
Block a user