public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "drepper at redhat dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sources.redhat.com
Subject: [Bug libc/2531] missing call or documentation for malloc_trim() ...
Date: Wed, 26 Apr 2006 02:15:00 -0000	[thread overview]
Message-ID: <20060426021522.26354.qmail@sourceware.org> (raw)
In-Reply-To: <20060409085351.2531.sakovacs@freemail.hu>


------- Additional Comments From drepper at redhat dot com  2006-04-26 02:15 -------
Why don't you make your little program write out the data:

#include <unistd.h>
#include <stdlib.h>
#include <malloc.h>
#include <stdio.h>
int
main (int argc, char *argv[])
{
  char cmd[100];
  snprintf (cmd, sizeof (cmd), "grep heap /proc/%d/maps || echo no heap",
            getpid ());
  void *before = sbrk (0);
  system (cmd);
  int max = 10000000;
  char **p1 = (char **) malloc (max * sizeof (char *));
  for (int x = 0; x < max; x++)
    {
      p1[x] = (char *) malloc (29);
    }
  for (int x = 0; x < max; x++)
    {
      free (p1[x]);
    }
  free (p1);
  void *middle = sbrk (0);
  system (cmd);
  malloc_trim (0);
  void *after = sbrk (0);
  system (cmd);
  printf ("before = %p, middle = %p, after = %p\n", before, middle, after);
  return 0;
}


When I run this I see

no heap
00501000-1cee1000 rw-p 00501000 00:00 0                                  [heap]
00501000-00502000 rw-p 00501000 00:00 0                                  [heap]
before = 0x501000, middle = 0x1cee1000, after = 0x502000


This clearly shows that

a) libc returns all memory if malloc_trim is used
b) the kernel frees all memory.


So, what's the problem?

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://sourceware.org/bugzilla/show_bug.cgi?id=2531

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


  parent reply	other threads:[~2006-04-26  2:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-09  8:53 [Bug libc/2531] New: " sakovacs at freemail dot hu
2006-04-09  8:55 ` [Bug libc/2531] " sakovacs at freemail dot hu
2006-04-26  2:15 ` drepper at redhat dot com [this message]
2006-04-26 11:35 ` sakovacs at freemail dot hu
2006-05-01 18:41 ` drepper at redhat dot com

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=20060426021522.26354.qmail@sourceware.org \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sources.redhat.com \
    /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).