public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jtaylor.debian at googlemail dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug malloc/17195] New: excessive heap trimming in threaded programs
Date: Thu, 24 Jul 2014 11:04:00 -0000	[thread overview]
Message-ID: <bug-17195-131@http.sourceware.org/bugzilla/> (raw)

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.


             reply	other threads:[~2014-07-24 11:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-24 11:04 jtaylor.debian at googlemail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-17195-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).