@ -79,7 +79,7 @@ WriteBufferManager::~WriteBufferManager() {
void WriteBufferManager : : ReserveMemWithCache ( size_t mem ) {
void WriteBufferManager : : ReserveMemWithCache ( size_t mem ) {
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
assert ( cache_rep_ ! = nullptr ) ;
assert ( cache_rep_ ! = nullptr ) ;
// Use a mutex to protect various data structures. Can be optimz ied to a
// Use a mutex to protect various data structures. Can be optimiz ed to a
// lock-free solution if it ends up with a performance bottleneck.
// lock-free solution if it ends up with a performance bottleneck.
std : : lock_guard < std : : mutex > lock ( cache_rep_ - > cache_mutex_ ) ;
std : : lock_guard < std : : mutex > lock ( cache_rep_ - > cache_mutex_ ) ;
@ -102,14 +102,14 @@ void WriteBufferManager::ReserveMemWithCache(size_t mem) {
void WriteBufferManager : : FreeMemWithCache ( size_t mem ) {
void WriteBufferManager : : FreeMemWithCache ( size_t mem ) {
# ifndef ROCKSDB_LITE
# ifndef ROCKSDB_LITE
assert ( cache_rep_ ! = nullptr ) ;
assert ( cache_rep_ ! = nullptr ) ;
// Use a mutex to protect various data structures. Can be optimz ied to a
// Use a mutex to protect various data structures. Can be optimiz ed to a
// lock-free solution if it ends up with a performance bottleneck.
// lock-free solution if it ends up with a performance bottleneck.
std : : lock_guard < std : : mutex > lock ( cache_rep_ - > cache_mutex_ ) ;
std : : lock_guard < std : : mutex > lock ( cache_rep_ - > cache_mutex_ ) ;
size_t new_mem_used = memory_used_ . load ( std : : memory_order_relaxed ) - mem ;
size_t new_mem_used = memory_used_ . load ( std : : memory_order_relaxed ) - mem ;
memory_used_ . store ( new_mem_used , std : : memory_order_relaxed ) ;
memory_used_ . store ( new_mem_used , std : : memory_order_relaxed ) ;
// Gradually shrink memory costed in the block cache if the actual
// Gradually shrink memory costed in the block cache if the actual
// usage is less than 3/4 of what we reserve from the block cache.
// usage is less than 3/4 of what we reserve from the block cache.
// We do this becauss e:
// We do this because:
// 1. we don't pay the cost of the block cache immediately a memtable is
// 1. we don't pay the cost of the block cache immediately a memtable is
// freed, as block cache insert is expensive;
// freed, as block cache insert is expensive;
// 2. eventually, if we walk away from a temporary memtable size increase,
// 2. eventually, if we walk away from a temporary memtable size increase,