add wrapper for madvise

This commit is contained in:
Daniel Micay 2021-03-22 12:24:26 -04:00
parent 73b78a8adb
commit b84af9b499
3 changed files with 11 additions and 2 deletions

View File

@ -1773,7 +1773,7 @@ EXPORT int h_malloc_trim(UNUSED size_t pad) {
for (size_t i = 0; i < slab_quarantine_random_length; i++) {
void *p = c->quarantine_random[i];
if (p != NULL) {
madvise(p, size, MADV_DONTNEED);
memory_purge(p, size);
}
}
#endif
@ -1783,7 +1783,7 @@ EXPORT int h_malloc_trim(UNUSED size_t pad) {
for (size_t i = 0; i < slab_quarantine_queue_length; i++) {
void *p = c->quarantine_queue[i];
if (p != NULL) {
madvise(p, size, MADV_DONTNEED);
memory_purge(p, size);
}
}
#endif

View File

@ -92,6 +92,14 @@ int memory_remap_fixed(void *old, size_t old_size, void *new, size_t new_size) {
}
#endif
int memory_purge(void *ptr, size_t size) {
int ret = madvise(ptr, size, MADV_DONTNEED);
if (unlikely(ret) && errno != ENOMEM) {
fatal_error("non-ENOMEM MADV_DONTNEED madvise failure");
}
return ret;
}
void memory_set_name(UNUSED void *ptr, UNUSED size_t size, UNUSED const char *name) {
#ifdef LABEL_MEMORY
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, ptr, size, name);

View File

@ -19,6 +19,7 @@ int memory_protect_rw_metadata(void *ptr, size_t size);
int memory_remap(void *old, size_t old_size, size_t new_size);
int memory_remap_fixed(void *old, size_t old_size, void *new, size_t new_size);
#endif
int memory_purge(void *ptr, size_t size);
void memory_set_name(void *ptr, size_t size, const char *name);
#endif