This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/2186] New: ptmalloc mallopt(M_MMAP_MAX,) issue


It is open to interpretation whether the following should be
considered a bug or not, but I believe it is:

========[code.c]========================================
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <sys/mman.h>
int main () {
        void    *pmalloc, *pmmap, *buf1, *buf2;
/*
 *  put an mmap 10Mb further into the malloc stack
 *  then try mallocing 20Mb then 6Mb
 *  with mallopt() specified to avoid mmap()
 */
        pmalloc = malloc(1024);
        pmmap = mmap(pmalloc + 10*1024*1024, 1024,
                PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE,
                0, 0);
        mallopt(M_MMAP_MAX, 0);
        buf1 = malloc(20*1024*1024);
        buf2 = malloc(6*1024*1024);
        printf("allocations: buf1 = %p, buf2 = %p\n"
                "(first malloc %p mmap %p)\n",
                buf1, buf2, pmalloc, pmmap);
        return 0;
}
========[output]========================================
allocations: buf1 = 0x40147008, buf2 = (nil)  <--[note buf2 being null]
(first malloc 0x804a008 mmap 0x8a4b000)
========================================================

One interpretation is that this is not a bug because I
instructed ptmalloc not to use mmap, then I placed an
mmap which made it impossible for ptmalloc to fulfill
my request without using mmap, thus any failure I get
at or after my allocation of buf1 is justified.

The other interpretation is that it is a bug because the
mallopt is only a suggestion, and that mmaps should only be
avoided if possible but used if required.  The fact that
buf1 is successfully allocated suggests this is the intended
operation.

Also I have not yet been able to hit this problem using
dlmalloc 2.7.2.  I didn't try earlier versions of ptmalloc
though.

 - Mark

-- 
           Summary: ptmalloc mallopt(M_MMAP_MAX,) issue
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: markall at rsn dot hp dot com
                CC: glibc-bugs at sources dot redhat dot com


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

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]