Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from netdata:master #365

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/libnetdata/onewayalloc/onewayalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ typedef struct owa_page {
size_t stats_mallocs_size;
size_t size; // the total size of the page
size_t offset; // the first free byte of the page
bool mmap;
struct owa_page *next; // the next page on the list
struct owa_page *last; // the last page on the list - we currently allocate on this
} OWA_PAGE;
Expand Down Expand Up @@ -54,7 +55,12 @@ static OWA_PAGE *onewayalloc_create_internal(OWA_PAGE *head, size_t size_hint) {

// Use netdata_mmap instead of mallocz
OWA_PAGE *page = (OWA_PAGE *)nd_mmap_advanced(NULL, size, MAP_ANONYMOUS | MAP_PRIVATE, 0, false, false, NULL);
if(unlikely(!page)) fatal("Cannot allocate onewayalloc buffer of size %zu", size);
if(unlikely(!page)) {
page = mallocz(size);
page->mmap = false;
}
else
page->mmap = true;

__atomic_add_fetch(&onewayalloc_total_memory, size, __ATOMIC_RELAXED);

Expand Down Expand Up @@ -196,8 +202,11 @@ void onewayalloc_destroy(ONEWAYALLOC *owa) {
page = page->next;

// Use netdata_munmap instead of freez
nd_munmap(p, p->size);
if(p->mmap)
nd_munmap(p, p->size);
else
freez(p);
}

__atomic_sub_fetch(&onewayalloc_total_memory, total_size, __ATOMIC_RELAXED);
}
}
Loading