public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug malloc/17195] New: excessive heap trimming in threaded programs
@ 2014-07-24 11:04 jtaylor.debian at googlemail dot com
  2014-07-24 11:07 ` [Bug malloc/17195] excessive heap trimming in threaded programs even when disabled with mallopt jtaylor.debian at googlemail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jtaylor.debian at googlemail dot com @ 2014-07-24 11:04 UTC (permalink / raw)
  To: glibc-bugs

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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-10-08  2:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-24 11:04 [Bug malloc/17195] New: excessive heap trimming in threaded programs jtaylor.debian at googlemail dot com
2014-07-24 11:07 ` [Bug malloc/17195] excessive heap trimming in threaded programs even when disabled with mallopt jtaylor.debian at googlemail dot com
2014-08-30 12:34 ` neleai at seznam dot cz
2014-08-30 12:40 ` jtaylor.debian at googlemail dot com
2015-02-12 17:46 ` jtaylor.debian at googlemail dot com
2015-02-18  5:48 ` siddhesh at redhat dot com
2015-04-02  6:46 ` cvs-commit at gcc dot gnu.org
2015-04-02  6:48 ` siddhesh at redhat dot com
2015-10-08  2:23 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).