proxygen
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
JemallocNodumpAllocator.h
Go to the documentation of this file.
1
/*
2
* Copyright 2016-present Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
17
// http://www.canonware.com/download/jemalloc/jemalloc-latest/doc/jemalloc.html
18
19
#pragma once
20
21
#include <
folly/CPortability.h
>
22
#include <
folly/portability/Config.h
>
23
24
#if defined(FOLLY_USE_JEMALLOC) && !FOLLY_SANITIZE
25
26
#include <
folly/portability/SysMman.h
>
27
#include <jemalloc/jemalloc.h>
28
29
#if (JEMALLOC_VERSION_MAJOR > 3) && defined(MADV_DONTDUMP)
30
#define FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED 1
31
#if (JEMALLOC_VERSION_MAJOR == 4)
32
#define FOLLY_JEMALLOC_NODUMP_ALLOCATOR_CHUNK
33
#define JEMALLOC_CHUNK_OR_EXTENT chunk
34
#else
35
#define FOLLY_JEMALLOC_NODUMP_ALLOCATOR_EXTENT
36
#define JEMALLOC_CHUNK_OR_EXTENT extent
37
#endif
38
#endif
39
40
#endif // FOLLY_USE_JEMALLOC
41
42
#include <cstddef>
43
44
namespace
folly
{
45
68
class
JemallocNodumpAllocator
{
69
public
:
70
enum class
State
{
71
ENABLED
,
72
DISABLED
,
73
};
74
75
// To be used as IOBuf::FreeFunction, userData should be set to
76
// reinterpret_cast<void*>(getFlags()).
77
static
void
deallocate
(
void
* p,
void
* userData);
78
79
explicit
JemallocNodumpAllocator
(
State
state
=
State::ENABLED
);
80
81
void
*
allocate
(
size_t
size
);
82
void
*
reallocate
(
void
* p,
size_t
size);
83
void
deallocate
(
void
* p,
size_t
= 0);
84
85
unsigned
getArenaIndex
()
const
{
86
return
arena_index_
;
87
}
88
int
getFlags
()
const
{
89
return
flags_
;
90
}
91
92
private
:
93
#ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED
94
#ifdef FOLLY_JEMALLOC_NODUMP_ALLOCATOR_CHUNK
95
static
chunk_alloc_t* original_alloc_;
96
static
void
* alloc(
97
void
* chunk,
98
#
else
99
static
extent_hooks_t
extent_hooks_;
100
static
extent_alloc_t
* original_alloc_;
101
static
void
* alloc(
102
extent_hooks_t
* extent,
103
void
* new_addr,
104
#endif
105
size_t
size,
106
size_t
alignment,
107
bool
* zero,
108
bool
* commit,
109
unsigned
arena_ind);
110
#endif // FOLLY_JEMALLOC_NODUMP_ALLOCATOR_SUPPORTED
111
112
bool
extend_and_setup_arena
();
113
114
unsigned
arena_index_
{0};
115
int
flags_
{0};
116
};
117
121
JemallocNodumpAllocator
&
globalJemallocNodumpAllocator
();
122
123
}
// namespace folly
folly::JemallocNodumpAllocator::flags_
int flags_
Definition:
JemallocNodumpAllocator.h:115
folly::JemallocNodumpAllocator::JemallocNodumpAllocator
JemallocNodumpAllocator(State state=State::ENABLED)
Definition:
JemallocNodumpAllocator.cpp:26
folly::JemallocNodumpAllocator::State::DISABLED
folly::JemallocNodumpAllocator::State::ENABLED
Config.h
folly
—— Concurrent Priority Queue Implementation ——
Definition:
AtomicBitSet.h:29
folly::JemallocNodumpAllocator::extend_and_setup_arena
bool extend_and_setup_arena()
Definition:
JemallocNodumpAllocator.cpp:32
CPortability.h
folly::JemallocNodumpAllocator::getArenaIndex
unsigned getArenaIndex() const
Definition:
JemallocNodumpAllocator.h:85
folly::JemallocNodumpAllocator
Definition:
JemallocNodumpAllocator.h:68
SysMman.h
folly::size
constexpr auto size(C const &c) -> decltype(c.size())
Definition:
Access.h:45
extent_hooks_s
Definition:
JemallocHugePageAllocator.cpp:51
folly::JemallocNodumpAllocator::reallocate
void * reallocate(void *p, size_t size)
Definition:
JemallocNodumpAllocator.cpp:111
folly::JemallocNodumpAllocator::getFlags
int getFlags() const
Definition:
JemallocNodumpAllocator.h:88
folly::JemallocNodumpAllocator::arena_index_
unsigned arena_index_
Definition:
JemallocNodumpAllocator.h:114
folly::JemallocNodumpAllocator::allocate
void * allocate(size_t size)
Definition:
JemallocNodumpAllocator.cpp:107
folly::JemallocNodumpAllocator::State
State
Definition:
JemallocNodumpAllocator.h:70
folly::JemallocNodumpAllocator::deallocate
static void deallocate(void *p, void *userData)
Definition:
JemallocNodumpAllocator.cpp:158
folly::globalJemallocNodumpAllocator
JemallocNodumpAllocator & globalJemallocNodumpAllocator()
Definition:
JemallocNodumpAllocator.cpp:163
extent_alloc_t
void *( extent_alloc_t)(extent_hooks_t *, void *, size_t, size_t, bool *, bool *, unsigned)
Definition:
JemallocHugePageAllocator.cpp:43
state
state
Definition:
http_parser.c:272
proxygen
folly
folly
experimental
JemallocNodumpAllocator.h
Generated by
1.8.11