YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/db/memtable_allocator.cc
Line
Count
Source (jump to first uncovered line)
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
478k
    : allocator_(allocator), write_buffer_(write_buffer), bytes_allocated_(0) {}
34
35
438k
MemTableAllocator::~MemTableAllocator() { DoneAllocating(); }
36
37
291k
char* MemTableAllocator::Allocate(size_t bytes) {
38
291k
  assert(write_buffer_ != nullptr);
39
0
  bytes_allocated_.fetch_add(bytes, std::memory_order_relaxed);
40
291k
  write_buffer_->ReserveMem(bytes);
41
291k
  return allocator_->Allocate(bytes);
42
291k
}
43
44
char* MemTableAllocator::AllocateAligned(size_t bytes, size_t huge_page_size,
45
400M
                                         Logger* logger) {
46
400M
  assert(write_buffer_ != nullptr);
47
0
  bytes_allocated_.fetch_add(bytes, std::memory_order_relaxed);
48
400M
  write_buffer_->ReserveMem(bytes);
49
400M
  return allocator_->AllocateAligned(bytes, huge_page_size, logger);
50
400M
}
51
52
467k
void MemTableAllocator::DoneAllocating() {
53
467k
  if (write_buffer_ != nullptr) {
54
438k
    write_buffer_->FreeMem(bytes_allocated_.load(std::memory_order_relaxed));
55
438k
    write_buffer_ = nullptr;
56
438k
  }
57
467k
}
58
59
1.30k
size_t MemTableAllocator::BlockSize() const { return allocator_->BlockSize(); }
60
61
}  // namespace rocksdb