-
Notifications
You must be signed in to change notification settings - Fork 164
refactor(cache): move rwlock from LruEntry to FileStore, to reduce memory usage #1149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,8 +194,10 @@ int QuotaFilePool::evict(std::string_view filename) { | |
| const auto& filePath = fileIter->first; | ||
| int err; | ||
| auto lruEntry = static_cast<QuotaLruEntry*>(fileIter->second.get()); | ||
|
|
||
| auto cacheStore = static_cast<FileCacheStore*>(open(filePath, O_RDWR, 0644)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DEFER(cacheStore->release())
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| { | ||
| photon::scoped_rwlock rl(lruEntry->rw_lock_, photon::WLOCK); | ||
| photon::scoped_rwlock rl(cacheStore->rw_lock(), photon::WLOCK); | ||
| lru.mark_key_cleared(lruEntry->QuotaLruIter); | ||
| err = mediaFs_->truncate(filePath.data(), 0); | ||
| if (err) { | ||
|
|
@@ -207,6 +209,7 @@ int QuotaFilePool::evict(std::string_view filename) { | |
| } | ||
| afterFtrucate(fileIter); | ||
| } | ||
| cacheStore->release(); | ||
| photon::thread_yield(); | ||
| return 0; | ||
| } | ||
|
|
@@ -234,15 +237,19 @@ void QuotaFilePool::dirEviction() { | |
| auto lruEntry = static_cast<QuotaLruEntry*>(fileIter->second.get()); | ||
| int err; | ||
| bool flags_dir_delete = false; | ||
|
|
||
| auto cacheStore = static_cast<FileCacheStore*>(open(fileName, O_RDWR, 0644)); | ||
| { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DEFER(cacheStore->release())
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| photon::scoped_rwlock rl(lruEntry->rw_lock_, photon::WLOCK); | ||
| photon::scoped_rwlock rl(cacheStore->rw_lock(), photon::WLOCK); | ||
| if (lruEntry->openCount==0){ | ||
| dir->lru.mark_key_cleared(lruEntry->QuotaLruIter); | ||
| } else { | ||
| dir->lru.access(lruEntry->QuotaLruIter); | ||
| } | ||
| err = mediaFs_->truncate(fileName.data(), 0); | ||
| } | ||
| cacheStore->release(); | ||
|
|
||
| if (err) { | ||
| ERRNO e; | ||
| LOG_ERROR("truncate(0) failed, name : `, ret : `, error code : `", fileName, err, e); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEFER(cacheStore->release())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done