Skip to content

Commit

Permalink
Add a call DisownData() to Cache, which should speed up shutdown
Browse files Browse the repository at this point in the history
Summary: On a shutdown, freeing memory takes a long time. If we're shutting down, we don't really care about memory leaks. I added a call to Cache that will avoid freeing all objects in cache.

Test Plan:
I created a script to test the speedup and demonstrate how to use the call: https://phabricator.fb.com/P3864368

Clean shutdown took 7.2 seconds, while fast and dirty one took 6.3 seconds. Unfortunately, the speedup is not that big, but should be bigger with bigger block_cache. I have set up the capacity to 80GB, but the script filled up only ~7GB.

Reviewers: dhruba, haobo, MarkCallaghan, xjin

Reviewed By: dhruba

CC: leveldb

Differential Revision: https://reviews.facebook.net/D15069
  • Loading branch information
igorcanadi committed Jan 24, 2014
1 parent 677fee2 commit b13bdfa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/rocksdb/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ class Cache {
// returns the maximum configured capacity of the cache
virtual size_t GetCapacity() = 0;

// Call this on shutdown if you want to speed it up. Cache will disown
// any underlying data and will not free it on delete. This call will leak
// memory - call this only if you're shutting down the process.
// Any attempts of using cache after this call will fail terribly.
// Always delete the DB object before calling this method!
virtual void DisownData() {
// default implementation is noop
};

private:
void LRU_Remove(Handle* e);
void LRU_Append(Handle* e);
Expand Down
3 changes: 3 additions & 0 deletions util/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ class ShardedLRUCache : public Cache {
virtual size_t GetCapacity() {
return capacity_;
}
virtual void DisownData() {
shard_ = nullptr;
}
};

} // end anonymous namespace
Expand Down

0 comments on commit b13bdfa

Please sign in to comment.