Add a call DisownData() to Cache, which should speed up shutdown

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
main
Igor Canadi 11 years ago
parent 677fee27c6
commit b13bdfa500
  1. 9
      include/rocksdb/cache.h
  2. 3
      util/cache.cc

@ -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);

@ -409,6 +409,9 @@ class ShardedLRUCache : public Cache {
virtual size_t GetCapacity() {
return capacity_;
}
virtual void DisownData() {
shard_ = nullptr;
}
};
} // end anonymous namespace

Loading…
Cancel
Save