]> git.proxmox.com Git - ceph.git/blame - ceph/src/rocksdb/util/allocator.h
bump version to 15.2.11-pve1
[ceph.git] / ceph / src / rocksdb / util / 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
TL
15#include <cstddef>
16#include "rocksdb/write_buffer_manager.h"
7c673cae
FG
17
18namespace rocksdb {
19
20class Logger;
21
22class Allocator {
23 public:
24 virtual ~Allocator() {}
25
26 virtual char* Allocate(size_t bytes) = 0;
27 virtual char* AllocateAligned(size_t bytes, size_t huge_page_size = 0,
28 Logger* logger = nullptr) = 0;
29
30 virtual size_t BlockSize() const = 0;
31};
32
11fdf7f2
TL
33class AllocTracker {
34 public:
35 explicit AllocTracker(WriteBufferManager* write_buffer_manager);
36 ~AllocTracker();
37 void Allocate(size_t bytes);
38 // Call when we're finished allocating memory so we can free it from
39 // the write buffer's limit.
40 void DoneAllocating();
41
42 void FreeMem();
43
44 bool is_freed() const { return write_buffer_manager_ == nullptr || freed_; }
45
46 private:
47 WriteBufferManager* write_buffer_manager_;
48 std::atomic<size_t> bytes_allocated_;
49 bool done_allocating_;
50 bool freed_;
51
52 // No copying allowed
53 AllocTracker(const AllocTracker&);
54 void operator=(const AllocTracker&);
55};
56
7c673cae 57} // namespace rocksdb