]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/memory/allocator.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / memory / allocator.h
CommitLineData
7c673cae 1// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
11fdf7f2
TL
2// This source code is licensed under both the GPLv2 (found in the
3// COPYING file in the root directory) and Apache 2.0 License
4// (found in the LICENSE.Apache file in the root directory).
7c673cae
FG
5//
6// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7// Use of this source code is governed by a BSD-style license that can be
8// found in the LICENSE file. See the AUTHORS file for names of contributors.
9//
10// Abstract interface for allocating memory in blocks. This memory is freed
11// when the allocator object is destroyed. See the Arena class for more info.
12
13#pragma once
7c673cae 14#include <cerrno>
11fdf7f2 15#include <cstddef>
1e59de90 16
11fdf7f2 17#include "rocksdb/write_buffer_manager.h"
7c673cae 18
f67539c2 19namespace ROCKSDB_NAMESPACE {
7c673cae
FG
20
21class Logger;
22
23class Allocator {
24 public:
25 virtual ~Allocator() {}
26
27 virtual char* Allocate(size_t bytes) = 0;
28 virtual char* AllocateAligned(size_t bytes, size_t huge_page_size = 0,
29 Logger* logger = nullptr) = 0;
30
31 virtual size_t BlockSize() const = 0;
32};
33
11fdf7f2
TL
34class AllocTracker {
35 public:
36 explicit AllocTracker(WriteBufferManager* write_buffer_manager);
f67539c2
TL
37 // No copying allowed
38 AllocTracker(const AllocTracker&) = delete;
39 void operator=(const AllocTracker&) = delete;
40
11fdf7f2
TL
41 ~AllocTracker();
42 void Allocate(size_t bytes);
43 // Call when we're finished allocating memory so we can free it from
44 // the write buffer's limit.
45 void DoneAllocating();
46
47 void FreeMem();
48
49 bool is_freed() const { return write_buffer_manager_ == nullptr || freed_; }
50
51 private:
52 WriteBufferManager* write_buffer_manager_;
53 std::atomic<size_t> bytes_allocated_;
54 bool done_allocating_;
55 bool freed_;
11fdf7f2
TL
56};
57
f67539c2 58} // namespace ROCKSDB_NAMESPACE