YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/memtable_allocator.cc
Line
Count
Source
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under the BSD-style license found in the
3
//  LICENSE file in the root directory of this source tree. An additional grant
4
//  of patent rights can be found in the PATENTS file in the same directory.
5
//
6
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
21
// Use of this source code is governed by a BSD-style license that can be
22
// found in the LICENSE file. See the AUTHORS file for names of contributors.
23
24
#include "yb/rocksdb/db/memtable_allocator.h"
25
26
#include <assert.h>
27
#include "yb/rocksdb/db/writebuffer.h"
28
29
namespace rocksdb {
30
31
MemTableAllocator::MemTableAllocator(Allocator* allocator,
32
                                     WriteBuffer* write_buffer)
33
380k
    : allocator_(allocator), write_buffer_(write_buffer), bytes_allocated_(0) {}
34
35
361k
MemTableAllocator::~MemTableAllocator() { DoneAllocating(); }
36
37
285k
char* MemTableAllocator::Allocate(size_t bytes) {
38
285k
  assert(write_buffer_ != nullptr);
39
285k
  bytes_allocated_.fetch_add(bytes, std::memory_order_relaxed);
40
285k
  write_buffer_->ReserveMem(bytes);
41
285k
  return allocator_->Allocate(bytes);
42
285k
}
43
44
char* MemTableAllocator::AllocateAligned(size_t bytes, size_t huge_page_size,
45
152M
                                         Logger* logger) {
46
152M
  assert(write_buffer_ != nullptr);
47
152M
  bytes_allocated_.fetch_add(bytes, std::memory_order_relaxed);
48
152M
  write_buffer_->ReserveMem(bytes);
49
152M
  return allocator_->AllocateAligned(bytes, huge_page_size, logger);
50
152M
}
51
52
386k
void MemTableAllocator::DoneAllocating() {
53
386k
  if (write_buffer_ != nullptr) {
54
361k
    write_buffer_->FreeMem(bytes_allocated_.load(std::memory_order_relaxed));
55
361k
    write_buffer_ = nullptr;
56
361k
  }
57
386k
}
58
59
1.30k
size_t MemTableAllocator::BlockSize() const { return allocator_->BlockSize(); }
60
61
}  // namespace rocksdb