Skip to content

Commit

Permalink
Add gc for file storage. (v6d-io#1862)
Browse files Browse the repository at this point in the history
- Add file storage gc for each client.
- Add global storage to scan dir and delete outdated files.
- Fix bugs in Update when delete files that do not meet requirements.

Fixes v6d-io#1861

Signed-off-by: vegetableysm <[email protected]>
  • Loading branch information
vegetableysm authored Apr 16, 2024
1 parent 78e236e commit 5a400fb
Show file tree
Hide file tree
Showing 11 changed files with 662 additions and 49 deletions.
18 changes: 17 additions & 1 deletion modules/llm-cache/ds/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,32 @@ struct FileCacheConfig : public KVCacheConfig {
int splitNumber;
std::string root;
FilesystemType filesystemType;
int clientGCInterval; // second
int ttl; // second
bool enbaleGlobalGC;
int globalGCInterval; // second
int globalTTL; // second

// Default gc interval is 30 minutes and default global gc interval is 3
// hours.
FileCacheConfig(int tensorByte = 10, int cacheCapacity = 10, int layer = 1,
int batchSize = 4, int splitNumber = 2,
std::string root = "/tmp/llm_cache/",
FilesystemType filesystemType = LOCAL)
FilesystemType filesystemType = LOCAL,
int clientGCInterval = 30 * 60, int ttl = 30 * 60,
bool enbaleGlobalGC = false,
int globalGCInterval = 3 * 60 * 60,
int globalTTL = 3 * 60 * 60)
: KVCacheConfig{tensorByte, cacheCapacity, layer} {
this->root = root;
this->batchSize = batchSize;
this->splitNumber = splitNumber;
this->filesystemType = filesystemType;
this->clientGCInterval = clientGCInterval;
this->ttl = ttl;
this->enbaleGlobalGC = enbaleGlobalGC;
this->globalGCInterval = globalGCInterval;
this->globalTTL = globalTTL;
}
};

Expand Down
15 changes: 10 additions & 5 deletions modules/llm-cache/ds/kv_state_cache_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ Status KVStateCacheManager::Make(std::shared_ptr<KVStateCacheManager>& manager,
if (config.filesystemType == FilesystemType::LOCAL) {
file_storage = std::make_shared<LocalFileStorage>(
config.tensorByte, config.cacheCapacity, config.layer, config.batchSize,
config.splitNumber, config.root);
config.splitNumber, config.root, config.clientGCInterval, config.ttl,
config.enbaleGlobalGC, config.globalGCInterval, config.globalTTL);
} else {
return Status::Invalid("Unsupported filesystem type");
}
manager = std::make_shared<KVStateCacheManager>(file_storage);
RETURN_ON_ERROR(file_storage->Init());
manager->config = std::make_shared<FileCacheConfig>(config);
return Status::OK();
}
Expand Down Expand Up @@ -400,12 +402,15 @@ Status KVStateCacheManager::ClearGlobalCache(Client& client,
config.llmRefcntObjectName);
}

Status ClearGlobalCache(Client& client, FileCacheConfig& config) {
// TBD
return Status::OK();
void KVStateCacheManager::Close() { storage->CloseCache(); }

void KVStateCacheManager::StopGlobalGCThread() {
storage->StopGlobalGCThread();
}

void KVStateCacheManager::Close() { storage->CloseCache(); }
void KVStateCacheManager::StartGlobalGCThread() {
storage->StartGlobalGCThread();
}

KVStateCacheManager::~KVStateCacheManager() {}

Expand Down
6 changes: 4 additions & 2 deletions modules/llm-cache/ds/kv_state_cache_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ class KVStateCacheManager {

void Close();

static Status ClearGlobalCache(Client& client, VineyardCacheConfig& config);
void StopGlobalGCThread();

void StartGlobalGCThread();

static Status ClearGlobalCache(Client& client, FileCacheConfig& config);
static Status ClearGlobalCache(Client& client, VineyardCacheConfig& config);

std::shared_ptr<KVCacheConfig> Config() { return config; }

Expand Down
Loading

0 comments on commit 5a400fb

Please sign in to comment.