public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "izetip at yahoo dot com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug malloc/15089] malloc_trim always trims for large padding
Date: Fri, 01 Feb 2013 23:55:00 -0000	[thread overview]
Message-ID: <bug-15089-131-WO0A3Ffhaq@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-15089-131@http.sourceware.org/bugzilla/>

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

--- Comment #2 from Thiago Ize <izetip at yahoo dot com> 2013-02-01 23:55:45 UTC ---
I didn't realize that when the result is converted to a long that it would give
the correct signed result (most of the time).  Shame on me.  However, I still
detect it doing the wrong thing for very large pad sizes, such as (size_t)-1,
combined with when there are more than 1 pages that can be released.  I wrote a
little test program to make sure this time:

      const size_t pagesz = 4096;
      const size_t MINSIZE = 8;

      long top_size = 12800;
      size_t pad = -1;

      long extra_bad = (top_size - pad - MINSIZE - 1) & ~(pagesz - 1);

      long x = top_size - ((long)MINSIZE) - 1;
      long good_extra = x <= pad? -1 : (x - ((long)pad)) & ~(pagesz - 1);

      printf("top_size: %ld pad:%zu gives %ld %ld\n", top_size, pad,
good_extra, extra_bad);

It returns:
    top_size: 12800 pad:18446744073709551615 gives -1 12288
So clearly in this case it's doing the wrong thing.

Finally, just to prove this happens in the actual glibc code, here's a gdb
output from CentOS 6 (glibc 2.12) that shows extra is positive even though pad
> top_size:

Breakpoint 2, sYSTRIm (s=18446744073709551615) at malloc.c:3475
3475      if (extra > 0) {
3: pad = 18446744073709551615
2: extra = 12288
1: top_size = 13536

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


  parent reply	other threads:[~2013-02-01 23:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-31  8:42 [Bug malloc/15089] New: " izetip at yahoo dot com
2013-01-31 18:13 ` [Bug malloc/15089] " izetip at yahoo dot com
2013-02-01 23:55 ` izetip at yahoo dot com [this message]
2013-11-20  2:03 ` fernandojvdasilva at gmail dot com
2013-12-06 17:08 ` cvs-commit at gcc dot gnu.org
2013-12-06 17:09 ` neleai at seznam dot cz
2014-06-13 10:10 ` fweimer at redhat dot com
2014-06-19 13:35 ` 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-15089-131-WO0A3Ffhaq@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).