| 74 | } |
| 75 | |
| 76 | void MemPool::FreeAll() { |
| 77 | DFAKE_SCOPED_LOCK(mutex_); |
| 78 | int64_t total_bytes_released = 0; |
| 79 | MonotonicStopWatch sw; |
| 80 | sw.Start(); |
| 81 | for (auto& chunk: chunks_) { |
| 82 | total_bytes_released += chunk.size; |
| 83 | free(chunk.data); |
| 84 | counters_.sys_free_duration.UpdateCounter(sw.Reset()); |
| 85 | counters_.freed_bytes.UpdateCounter(chunk.size); |
| 86 | } |
| 87 | chunks_.clear(); |
| 88 | next_chunk_size_ = INITIAL_CHUNK_SIZE; |
| 89 | current_chunk_idx_ = -1; |
| 90 | total_allocated_bytes_ = 0; |
| 91 | total_reserved_bytes_ = 0; |
| 92 | |
| 93 | mem_tracker_->Release(total_bytes_released); |
| 94 | } |
| 95 | |
| 96 | bool MemPool::FindChunk(int64_t min_size, bool check_limits) noexcept { |
| 97 | // Try to allocate from a free chunk. We may have free chunks after the current chunk |