This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug malloc/17195] New: excessive heap trimming in threaded programs


https://sourceware.org/bugzilla/show_bug.cgi?id=17195

            Bug ID: 17195
           Summary: excessive heap trimming in threaded programs
           Product: glibc
           Version: 2.19
            Status: NEW
          Severity: normal
          Priority: P2
         Component: malloc
          Assignee: unassigned at sourceware dot org
          Reporter: jtaylor.debian at googlemail dot com

using glibc 2.19 from ubuntu 14.04 amd64 the following simple program causes a
huge amount of page faults due to the heap being trimmed on every second free()
even though heap trimming was disabled and the mmap threshold is set to the
maximum:

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <malloc.h>

int main(int argc, const char *argv[])
{
    mallopt (M_TRIM_THRESHOLD, -1);
    mallopt (M_MMAP_THRESHOLD, 1024*1024*32);
#pragma omp parallel for num_threads(2)
    for (size_t i = 0; i < 1000; i++) {
        size_t n = 1024*1024*16;
        double * m = malloc(n);
        memset(m, 1, n);
        free(m);
    }
    return 0;
}

gcc test.c -std=c99 -g -O2 -fopenmp
perf stat -e page-faults ./a.out 
         2,036,312 page-faults         

strace -f -e madvise ./a.out 2>&1 | grep MADV_DONTNEED | wc -l
500

when setting the number of threads to 1 it reuses the memory as expected:
perf stat -e page-faults ./a.out 
             4,271 page-faults

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]