From be28fbc7b81de5f454beb1ae3555ae28edcd6450 Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Sat, 31 May 2025 09:21:59 +0000 Subject: [PATCH] Refactor StatCache words from NoObject to Negative --- doc/man/s3fs.1.in | 20 +++++++++++++------- src/cache.cpp | 14 +++++++------- src/cache.h | 16 ++++++++-------- src/s3fs.cpp | 10 +++++----- src/s3fs_help.cpp | 19 ++++++++++++++----- 5 files changed, 47 insertions(+), 32 deletions(-) diff --git a/doc/man/s3fs.1.in b/doc/man/s3fs.1.in index 691f200..4077a24 100644 --- a/doc/man/s3fs.1.in +++ b/doc/man/s3fs.1.in @@ -168,10 +168,16 @@ specify expire time (seconds) for entries in the stat cache and symbolic link ca specify expire time (seconds) for entries in the stat cache and symbolic link cache. This expire time is based on the time from the last access time of those cache. This option is exclusive with stat_cache_expire, and is left for compatibility with older versions. .TP -\fB\-o\fR disable_noobj_cache (default is enable) -By default s3fs memorizes when an object does not exist up until the stat cache timeout. -This caching can cause staleness for applications. -If disabled, s3fs will not memorize objects and may cause extra HeadObject requests and reduce performance. +\fB\-o\fR enable_negative_cache (default is enabled negative cache) +This option will keep non-existence of objects in a stat cache. +When this negative cache is enabled, it will not process extra HeadObject requests to search for non-existent objects, improving performance. +This feature is enabled by default, so there is no need to specify it. +.TP +\fB\-o\fR disable_negative_cache (default is enabled negative cache) +By default, s3fs keeps non-existent objects in the stat cache. +This option disables this negative caching. +This prevents delays in updates due to cache retention. +However, it may increase the number of HeadObject requests to check if an object exists, which may decrease performance. .TP \fB\-o\fR no_check_certificate (by default this option is disabled) server certificate won't be checked against the available certificate authorities. @@ -515,13 +521,13 @@ s3fs is a multi-threaded application. Depending on the workload it may use multi .TP s3fs provides several options (e.g. "max_thread_count" option) to control behaviour and thus indirectly the performance. The possible combinations of these options in conjunction with the various S3 backends are so varied that there is no individual recommendation other than the default values. Improved individual settings can be found by testing and measuring. .TP -The two options "Enable no object cache" ("\-o enable_noobj_cache") and "Disable support of alternative directory names" ("\-o notsup_compat_dir") can be used to control shared access to the same bucket by different applications: +The two options "Enable negative cache" ("\-o enable_negative_cache") and "Disable support of alternative directory names" ("\-o notsup_compat_dir") can be used to control shared access to the same bucket by different applications: .TP .IP \[bu] -Enable no object cache ("\-o enable_noobj_cache") +Enable negative cache ("\-o enable_negative_cache") .RS .TP -If a bucket is used exclusively by an s3fs instance, you can enable the cache for non-existent files and directories with "\-o enable_noobj_cache". This eliminates repeated requests to check the existence of an object, saving time and possibly money. +If a bucket is used exclusively by an s3fs instance, you can enable the cache for non-existent files and directories with "\-o enable_negative_cache". This eliminates repeated requests to check the existence of an object, saving time and possibly money. .RE .IP \[bu] Enable support of alternative directory names ("\-o compat_dir") diff --git a/src/cache.cpp b/src/cache.cpp index e62153e..e91aa91 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -119,7 +119,7 @@ std::mutex StatCache::stat_cache_lock; //------------------------------------------------------------------- // Constructor/Destructor //------------------------------------------------------------------- -StatCache::StatCache() : IsExpireTime(true), IsExpireIntervalType(false), ExpireTime(15 * 60), CacheSize(100'000), IsCacheNoObject(true) +StatCache::StatCache() : IsExpireTime(true), IsExpireIntervalType(false), ExpireTime(15 * 60), CacheSize(100'000), UseNegativeCache(true) { if(this == StatCache::getStatCacheData()){ stat_cache.clear(); @@ -175,10 +175,10 @@ time_t StatCache::UnsetExpireTime() return old; } -bool StatCache::SetCacheNoObject(bool flag) +bool StatCache::SetNegativeCache(bool flag) { - bool old = IsCacheNoObject; - IsCacheNoObject = flag; + bool old = UseNegativeCache; + UseNegativeCache = flag; return old; } @@ -222,7 +222,7 @@ bool StatCache::GetStat(const std::string& key, struct stat* pst, headers_t* met // No object if(ent->noobjcache){ - if(!IsCacheNoObject){ + if(!UseNegativeCache){ // need to delete this cache. DelStatHasLock(strpath); }else{ @@ -275,7 +275,7 @@ bool StatCache::GetStat(const std::string& key, struct stat* pst, headers_t* met bool StatCache::IsNoObjectCache(const std::string& key, bool overcheck) { - if(!IsCacheNoObject){ + if(!UseNegativeCache){ return false; } const std::lock_guard lock(StatCache::stat_cache_lock); @@ -433,7 +433,7 @@ bool StatCache::UpdateMetaStats(const std::string& key, const headers_t& meta) bool StatCache::AddNoObjectCache(const std::string& key) { - if(!IsCacheNoObject){ + if(!UseNegativeCache){ return true; // pretend successful } if(CacheSize < 1){ diff --git a/src/cache.h b/src/cache.h index 2d5a464..432de87 100644 --- a/src/cache.h +++ b/src/cache.h @@ -88,7 +88,7 @@ class StatCache bool IsExpireIntervalType; // if this flag is true, cache data is updated at last access time. time_t ExpireTime; unsigned long CacheSize; - bool IsCacheNoObject; + bool UseNegativeCache; symlink_cache_t symlink_cache GUARDED_BY(stat_cache_lock); notruncate_dir_map_t notruncate_file_cache GUARDED_BY(stat_cache_lock); @@ -126,18 +126,18 @@ class StatCache time_t GetExpireTime() const; time_t SetExpireTime(time_t expire, bool is_interval = false); time_t UnsetExpireTime(); - bool SetCacheNoObject(bool flag); - bool EnableCacheNoObject() + bool SetNegativeCache(bool flag); + bool EnableNegativeCache() { - return SetCacheNoObject(true); + return SetNegativeCache(true); } - bool DisableCacheNoObject() + bool DisableNegativeCache() { - return SetCacheNoObject(false); + return SetNegativeCache(false); } - bool GetCacheNoObject() const + bool IsEnabledNegativeCache() const { - return IsCacheNoObject; + return UseNegativeCache; } // Get stat cache diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 573be9b..6d840a0 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -4973,13 +4973,13 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar StatCache::getStatCacheData()->SetExpireTime(expr_time, true); return 0; } - else if(0 == strcmp(arg, "enable_noobj_cache")){ - S3FS_PRN_WARN("enable_noobj_cache is enabled by default and a future version will remove this option."); - StatCache::getStatCacheData()->EnableCacheNoObject(); + else if(0 == strcmp(arg, "enable_negative_cache") || 0 == strcmp(arg, "enable_noobj_cache")){ + S3FS_PRN_WARN("enable_negative_cache(enable_noobj_cache) is enabled by default and a future version will remove this option."); + StatCache::getStatCacheData()->EnableNegativeCache(); return 0; } - else if(0 == strcmp(arg, "disable_noobj_cache")){ - StatCache::getStatCacheData()->DisableCacheNoObject(); + else if(0 == strcmp(arg, "disable_negative_cache") || 0 == strcmp(arg, "disable_noobj_cache")){ + StatCache::getStatCacheData()->DisableNegativeCache(); return 0; } else if(0 == strcmp(arg, "nodnscache")){ diff --git a/src/s3fs_help.cpp b/src/s3fs_help.cpp index 20b41bd..fadc6d8 100644 --- a/src/s3fs_help.cpp +++ b/src/s3fs_help.cpp @@ -204,11 +204,20 @@ static constexpr char help_string[] = " of the stat cache. This option is exclusive with stat_cache_expire,\n" " and is left for compatibility with older versions.\n" "\n" - " disable_noobj_cache (default is enable)\n" - " - By default s3fs memorizes when an object does not exist up until\n" - " the stat cache timeout. This caching can cause staleness for\n" - " applications. If disabled, s3fs will not memorize objects and may\n" - " cause extra HeadObject requests and reduce performance.\n" + " enable_negative_cache (default is enabled negative cache)\n" + " - This option will keep non-existence of objects in a stat cache.\n" + " When this negative cache is enabled, it will not process extra\n" + " HeadObject requests to search for non-existent objects, improving\n" + " performance.\n" + " This feature is enabled by default, so there is no need to specify\n" + " it.\n" + "\n" + " disable_negative_cache (default is enabled negative cache)\n" + " - By default, s3fs keeps non-existent objects in the stat cache.\n" + " This option disables this negative caching.\n" + " This prevents delays in updates due to cache retention.\n" + " However, it may increase the number of HeadObject requests to check\n" + " if an object exists, which may decrease performance.\n" "\n" " no_check_certificate\n" " - server certificate won't be checked against the available \n"