This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug malloc/17195] New: excessive heap trimming in threaded programs
- From: "jtaylor.debian at googlemail dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Thu, 24 Jul 2014 11:04:52 +0000
- Subject: [Bug malloc/17195] New: excessive heap trimming in threaded programs
- Auto-submitted: auto-generated
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.