0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-04-09 15:47:53 +00:00

do not use mmap when the mmap limit is too low ()

This commit is contained in:
Costa Tsaousis 2025-02-26 11:32:51 +00:00 committed by GitHub
parent fbc551a9e4
commit b71bc97008
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 45 additions and 2 deletions

View file

@ -1056,6 +1056,8 @@ set(LIBNETDATA_FILES
src/libnetdata/os/run_dir.h
src/libnetdata/os/file_lock.c
src/libnetdata/os/file_lock.h
src/libnetdata/os/mmap_limit.c
src/libnetdata/os/mmap_limit.h
)
list(APPEND LIBNETDATA_FILES ${INICFG_FILES})

View file

@ -143,6 +143,15 @@ struct aral {
#define aral_pages_head_free(ar, marked) (marked ? &ar->aral_lock.pages_marked_free : &ar->aral_lock.pages_free)
#define aral_pages_head_full(ar, marked) (marked ? &ar->aral_lock.pages_marked_full : &ar->aral_lock.pages_full)
static inline bool aral_malloc_use_mmap(ARAL *ar __maybe_unused, size_t size) {
unsigned long long mmap_limit = os_mmap_limit();
if(mmap_limit > 256 * 1000 && size >= ARAL_MALLOC_USE_MMAP_ABOVE)
return true;
return false;
}
const char *aral_name(ARAL *ar) {
return ar->config.name;
}
@ -503,7 +512,7 @@ static ALWAYS_INLINE size_t aral_next_allocation_size___adders_lock_needed(ARAL
ar->ops[idx].adders.allocation_size = size;
}
if(!ar->config.mmap.enabled && size < ARAL_MALLOC_USE_MMAP_ABOVE) {
if(!ar->config.mmap.enabled && aral_malloc_use_mmap(ar, size)) {
// when doing malloc, don't allocate entire pages, but only what needed
size =
aral_elements_in_page_size(ar, size) * ar->config.element_size +
@ -553,7 +562,7 @@ static ARAL_PAGE *aral_create_page___no_lock_needed(ARAL *ar, size_t size TRACE_
else {
size_t ARAL_PAGE_size = memory_alignment(sizeof(ARAL_PAGE), SYSTEM_REQUIRED_ALIGNMENT);
if (size >= ARAL_MALLOC_USE_MMAP_ABOVE) {
if (aral_malloc_use_mmap(ar, size)) {
bool mapped;
uint8_t *ptr =
nd_mmap_advanced(NULL, size, MAP_ANONYMOUS | MAP_PRIVATE, 1, false, ar->config.options & ARAL_DONT_DUMP, NULL);

View file

@ -0,0 +1,21 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include "mmap_limit.h"
#include "libnetdata/libnetdata.h"
unsigned long long os_mmap_limit(void) {
static unsigned long long cached_limit = 0;
if (cached_limit)
return cached_limit;
#if defined(OS_LINUX)
if(read_single_number_file("/proc/sys/vm/max_map_count", &cached_limit) != 0)
cached_limit = 65536;
#else
// For other operating systems, assume no limit.
cached_limit = UINT32_MAX;
#endif
return cached_limit;
}

View file

@ -0,0 +1,10 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef NETDATA_MMAP_LIMIT_H
#define NETDATA_MMAP_LIMIT_H
#include "libnetdata/common.h"
unsigned long long os_mmap_limit(void);
#endif //NETDATA_MMAP_LIMIT_H

View file

@ -39,6 +39,7 @@
#include "boot_id.h"
#include "run_dir.h"
#include "file_lock.h"
#include "mmap_limit.h"
// this includes windows.h to the whole of netdata
// so various conflicts arise