24#include <seastar/core/resource.hh>
25#include <seastar/core/bitops.hh>
26#include <seastar/util/backtrace.hh>
27#include <seastar/util/modules.hh>
28#include <seastar/util/sampler.hh>
128#ifdef SEASTAR_OVERRIDE_ALLOCATOR_PAGE_SIZE
129#define SEASTAR_INTERNAL_ALLOCATOR_PAGE_SIZE (SEASTAR_OVERRIDE_ALLOCATOR_PAGE_SIZE)
131#define SEASTAR_INTERNAL_ALLOCATOR_PAGE_SIZE 4096
134static constexpr size_t page_size = SEASTAR_INTERNAL_ALLOCATOR_PAGE_SIZE;
135static constexpr size_t page_bits = log2ceil(page_size);
136static constexpr size_t huge_page_size =
137#if defined(__x86_64__) || defined(__i386__) || defined(__s390x__) || defined(__zarch__)
139#elif defined(__aarch64__)
141#elif defined(__PPC__)
144#error "Huge page size is not defined for this architecture"
153 unsigned numa_node_id;
157 std::vector<memory_range> ranges;
160numa_layout merge(numa_layout one, numa_layout two);
164internal::numa_layout
configure(std::vector<resource::memory> m,
bool mbind,
165 bool transparent_hugepages,
166 std::optional<std::string> hugetlbfs_path = {});
168void configure_minimal();
171[[deprecated(
"use set_abort_on_allocation_failure(true) instead")]]
172void enable_abort_on_allocation_failure();
174class disable_abort_on_alloc_failure_temporarily {
176 disable_abort_on_alloc_failure_temporarily();
177 ~disable_abort_on_alloc_failure_temporarily()
noexcept;
183class disable_backtrace_temporarily {
186 disable_backtrace_temporarily();
189enum class reclaiming_result {
195enum class reclaimer_scope {
219 size_t bytes_to_reclaim;
221 using reclaim_fn = std::function<reclaiming_result ()>;
223 std::function<reclaiming_result (request)> _reclaim;
224 reclaimer_scope _scope;
229 reclaimer(std::function<reclaiming_result (request)> reclaim, reclaimer_scope scope =
reclaimer_scope::async);
231 reclaiming_result do_reclaim(
size_t bytes_to_reclaim) {
return _reclaim(request{bytes_to_reclaim}); }
232 reclaimer_scope scope()
const {
return _scope; }
235extern std::pmr::polymorphic_allocator<char>* malloc_allocator;
241bool drain_cross_cpu_freelist();
250void set_reclaim_hook(
251 std::function<
void (std::function<
void ()>)> hook);
255SEASTAR_MODULE_EXPORT_BEGIN
290 uint64_t _cross_cpu_frees;
291 size_t _total_memory;
294 uint64_t _large_allocs;
295 uint64_t _failed_allocs;
297 uint64_t _foreign_mallocs;
298 uint64_t _foreign_frees;
299 uint64_t _foreign_cross_frees;
303 uint64_t large_allocs, uint64_t failed_allocs,
307 , _large_allocs(large_allocs), _failed_allocs(failed_allocs)
314 uint64_t
frees()
const {
return _frees; }
376 size_t _old_threshold;
385 if (_old_threshold) {
395 size_t _old_threshold;
404 if (_old_threshold) {
421 mutable size_t count = 0;
436 return !(*
this == o);
501SEASTAR_MODULE_EXPORT_END
509struct hash<
seastar::memory::allocation_site> {
Enable heap profiling for the duration of the scope.
Definition: memory.hh:495
Disable large allocation warnings for a scope.
Definition: memory.hh:394
Set a different large allocation warning threshold for a scope.
Definition: memory.hh:375
Memory allocation statistics.
Definition: memory.hh:287
uint64_t failed_allocations() const
Definition: memory.hh:332
uint64_t foreign_frees() const
Number of foreign frees.
Definition: memory.hh:336
uint64_t cross_cpu_frees() const
Definition: memory.hh:317
size_t total_memory() const
Total memory (in bytes)
Definition: memory.hh:325
uint64_t large_allocations() const
Number of allocations which violated the large allocation threshold.
Definition: memory.hh:329
uint64_t mallocs() const
Total number of memory allocations calls since the system was started.
Definition: memory.hh:312
uint64_t reclaims() const
Number of reclaims performed due to low memory.
Definition: memory.hh:327
size_t live_objects() const
Total number of objects which were allocated but not freed.
Definition: memory.hh:319
uint64_t frees() const
Total number of memory deallocations calls since the system was started.
Definition: memory.hh:314
friend statistics stats()
Capture a snapshot of memory allocation statistics for this lcore.
uint64_t foreign_mallocs() const
Number of foreign allocations.
Definition: memory.hh:334
size_t free_memory() const
Total free memory (in bytes)
Definition: memory.hh:321
size_t allocated_memory() const
Total allocated memory (in bytes)
Definition: memory.hh:323
uint64_t foreign_cross_frees() const
Number of foreign frees on reactor threads.
Definition: memory.hh:338
Definition: backtrace.hh:82
futurize_t< std::invoke_result_t< Func, Args... > > async(thread_attributes attr, Func &&func, Args &&... args) noexcept
Definition: thread.hh:245
size_t get_heap_profiling_sample_rate()
Returns the current heap profiling sampling rate (0 means off)
size_t free_memory()
Returns the size of free memory in bytes.
void set_large_allocation_warning_threshold(size_t threshold)
void set_heap_profiling_sampling_rate(size_t sample_rate)
Enable sampled heap profiling by setting a sample rate.
size_t get_large_allocation_warning_threshold()
Gets the current large allocation warning threshold.
statistics stats()
Capture a snapshot of memory allocation statistics for this lcore.
void set_min_free_pages(size_t pages)
Sets the value of free memory low water mark in memory::page_size units.
void set_abort_on_allocation_failure(bool enabled)
Set the global state of the abort on allocation failure behavior.
std::vector< allocation_site > sampled_memory_profile()
If memory sampling is on returns the current sampled memory live set.
bool is_abort_on_allocation_failure()
Determine the abort on allocation failure mode.
void disable_large_allocation_warning()
Disable large allocation warnings.
Definition: memory.hh:342
future configure(const options &opts)
set the metrics configuration
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
RAII class to temporarily pause sampling.
Definition: sampler.hh:91
Describes an allocation location in the code.
Definition: memory.hh:420
const allocation_site * next
call site for this allocation
Definition: memory.hh:428
simple_backtrace backtrace
amount of bytes in live objects allocated at backtrace.
Definition: memory.hh:423
size_t size
number of live objects allocated at backtrace.
Definition: memory.hh:422
Definition: backtrace.hh:169