24 #include <seastar/core/resource.hh>
25 #include <seastar/core/bitops.hh>
26 #include <seastar/util/modules.hh>
27 #ifndef SEASTAR_MODULE
125 #ifdef SEASTAR_OVERRIDE_ALLOCATOR_PAGE_SIZE
126 #define SEASTAR_INTERNAL_ALLOCATOR_PAGE_SIZE (SEASTAR_OVERRIDE_ALLOCATOR_PAGE_SIZE)
128 #define SEASTAR_INTERNAL_ALLOCATOR_PAGE_SIZE 4096
131 static constexpr
size_t page_size = SEASTAR_INTERNAL_ALLOCATOR_PAGE_SIZE;
132 static constexpr
size_t page_bits = log2ceil(page_size);
133 static constexpr
size_t huge_page_size =
134 #if defined(__x86_64__) || defined(__i386__) || defined(__s390x__) || defined(__zarch__)
136 #elif defined(__aarch64__)
138 #elif defined(__PPC__)
141 #error "Huge page size is not defined for this architecture"
147 struct memory_range {
150 unsigned numa_node_id;
154 std::vector<memory_range> ranges;
157 numa_layout merge(numa_layout one, numa_layout two);
161 internal::numa_layout
configure(std::vector<resource::memory> m,
bool mbind,
162 bool transparent_hugepages,
163 std::optional<std::string> hugetlbfs_path = {});
166 [[deprecated(
"use set_abort_on_allocation_failure(true) instead")]]
167 void enable_abort_on_allocation_failure();
169 class disable_abort_on_alloc_failure_temporarily {
171 disable_abort_on_alloc_failure_temporarily();
172 ~disable_abort_on_alloc_failure_temporarily() noexcept;
178 class disable_backtrace_temporarily {
181 disable_backtrace_temporarily();
182 ~disable_backtrace_temporarily();
185 enum class reclaiming_result {
191 enum class reclaimer_scope {
215 size_t bytes_to_reclaim;
217 using reclaim_fn = std::function<reclaiming_result ()>;
219 std::function<reclaiming_result (request)> _reclaim;
220 reclaimer_scope _scope;
225 reclaimer(std::function<reclaiming_result (request)> reclaim, reclaimer_scope scope =
reclaimer_scope::async);
227 reclaiming_result do_reclaim(
size_t bytes_to_reclaim) {
return _reclaim(request{bytes_to_reclaim}); }
228 reclaimer_scope scope()
const {
return _scope; }
231 extern std::pmr::polymorphic_allocator<char>* malloc_allocator;
237 bool drain_cross_cpu_freelist();
246 void set_reclaim_hook(
247 std::function<
void (std::function<
void ()>)> hook);
251 SEASTAR_MODULE_EXPORT_BEGIN
286 uint64_t _cross_cpu_frees;
287 size_t _total_memory;
290 uint64_t _large_allocs;
291 uint64_t _failed_allocs;
293 uint64_t _foreign_mallocs;
294 uint64_t _foreign_frees;
295 uint64_t _foreign_cross_frees;
299 uint64_t large_allocs, uint64_t failed_allocs,
303 , _large_allocs(large_allocs), _failed_allocs(failed_allocs)
310 uint64_t
frees()
const {
return _frees; }
372 size_t _old_threshold;
381 if (_old_threshold) {
391 size_t _old_threshold;
400 if (_old_threshold) {
432 SEASTAR_MODULE_EXPORT_END
Definition: memory.hh:426
Disable large allocation warnings for a scope.
Definition: memory.hh:390
Set a different large allocation warning threshold for a scope.
Definition: memory.hh:371
Memory allocation statistics.
Definition: memory.hh:283
uint64_t failed_allocations() const
Definition: memory.hh:328
uint64_t foreign_frees() const
Number of foreign frees.
Definition: memory.hh:332
uint64_t cross_cpu_frees() const
Definition: memory.hh:313
size_t total_memory() const
Total memory (in bytes)
Definition: memory.hh:321
uint64_t large_allocations() const
Number of allocations which violated the large allocation threshold.
Definition: memory.hh:325
uint64_t mallocs() const
Total number of memory allocations calls since the system was started.
Definition: memory.hh:308
uint64_t reclaims() const
Number of reclaims performed due to low memory.
Definition: memory.hh:323
size_t live_objects() const
Total number of objects which were allocated but not freed.
Definition: memory.hh:315
uint64_t frees() const
Total number of memory deallocations calls since the system was started.
Definition: memory.hh:310
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:330
size_t free_memory() const
Total free memory (in bytes)
Definition: memory.hh:317
size_t allocated_memory() const
Total allocated memory (in bytes)
Definition: memory.hh:319
uint64_t foreign_cross_frees() const
Number of foreign frees on reactor threads.
Definition: memory.hh:334
futurize_t< std::invoke_result_t< Func, Args... > > async(thread_attributes attr, Func &&func, Args &&... args) noexcept
Definition: thread.hh:247
size_t free_memory()
Returns the size of free memory in bytes.
void set_large_allocation_warning_threshold(size_t threshold)
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_heap_profiling_enabled(bool)
void set_abort_on_allocation_failure(bool enabled)
Set the global state of the abort on allocation failure behavior.
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:338
future configure(const options &opts)
set the metrics configuration
Seastar API namespace.
Definition: abort_on_ebadf.hh:26