This is the mail archive of the libc-alpha@sources.redhat.com 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]

Problems with malloc.


Hi,
while testing with nptl for s390 if found something in malloc that I consider
to be a bug. The symptom on my system is that after creating 55 threads
a calloc returns NULL although there is memory left malloc could use.
At the time of the failure the memory map looks like this:

00400000-00402000 r-xp 00000000 5e:06 87034      /usr/src/libc-build/nptl/tst-mutex7
00402000-00403000 rw-p 00001000 5e:06 87034      /usr/src/libc-build/nptl/tst-mutex7
unused memory 00403000-40000000
40000000-40001000 rw-p 00000000 00:00 0
40001000-4000d000 r-xp 00000000 5e:06 87043      /usr/src/libc-build/nptl/libpthread.so
4000d000-4000f000 rw-p 0000b000 5e:06 87043      /usr/src/libc-build/nptl/libpthread.so
4000f000-40011000 rw-p 00000000 00:00 0
40011000-40142000 r-xp 00000000 5e:06 69113      /usr/src/libc-build/libc.so
40142000-40161000 rw-p 00130000 5e:06 69113      /usr/src/libc-build/libc.so
40161000-40164000 rw-p 00000000 00:00 0		0x3000 private space
40164000-40165000 ---p 00000000 00:00 0		0x1000   thread stack end 1
40165000-40964000 rwxp 00001000 00:00 0		0x7ff000 thread stack 1
40964000-40965000 ---p 00800000 00:00 0		0x1000   thread stack end 2
40965000-41164000 rwxp 00801000 00:00 0		0x7ff000 thread stack 2
41164000-41165000 ---p 01000000 00:00 0		0x1000   thread stack end 3
41165000-41964000 rwxp 01001000 00:00 0		0x7ff000 thread stack 3
41964000-41965000 ---p 01800000 00:00 0		0x1000   thread stack end 4
41965000-42164000 rwxp 01801000 00:00 0		0x7ff000 thread stack 4
42164000-42165000 ---p 02000000 00:00 0		0x1000   thread stack end 5
42165000-42964000 rwxp 02001000 00:00 0		0x7ff000 thread stack 5
42964000-42965000 ---p 02800000 00:00 0		0x1000   thread stack end 6
42965000-43164000 rwxp 02801000 00:00 0		0x7ff000 thread stack 6
43164000-43165000 ---p 03000000 00:00 0		0x1000   thread stack end 7
43165000-43964000 rwxp 03001000 00:00 0		0x7ff000 thread stack 7
43964000-43965000 ---p 03800000 00:00 0		0x1000   thread stack end 8
43965000-44164000 rwxp 03801000 00:00 0		0x7ff000 thread stack 8
44164000-44165000 ---p 04000000 00:00 0		0x1000   thread stack end 9
44165000-44964000 rwxp 04001000 00:00 0		0x7ff000 thread stack 9
44964000-44965000 ---p 04800000 00:00 0		0x1000   thread stack end 10
44965000-45164000 rwxp 04801000 00:00 0		0x7ff000 thread stack 10
45164000-45165000 ---p 05000000 00:00 0		0x1000   thread stack end 11
45165000-45964000 rwxp 05001000 00:00 0		0x7ff000 thread stack 11
45964000-45965000 ---p 05800000 00:00 0		0x1000   thread stack end 12
45965000-46164000 rwxp 05801000 00:00 0		0x7ff000 thread stack 12
46164000-46165000 ---p 06000000 00:00 0		0x1000   thread stack end 13
46165000-46964000 rwxp 06001000 00:00 0		0x7ff000 thread stack 13
46964000-46965000 ---p 06800000 00:00 0		0x1000   thread stack end 14
46965000-47164000 rwxp 06801000 00:00 0		0x7ff000 thread stack 14
47164000-47165000 ---p 07000000 00:00 0		0x1000   thread stack end 15
47165000-47964000 rwxp 07001000 00:00 0		0x7ff000 thread stack 15
47964000-47965000 ---p 07800000 00:00 0		0x1000   thread stack end 16
47965000-48164000 rwxp 07801000 00:00 0		0x7ff000 thread stack 16
48164000-48165000 ---p 08000000 00:00 0		0x1000   thread stack end 17
48165000-48964000 rwxp 08001000 00:00 0		0x7ff000 thread stack 17
48964000-48965000 ---p 08800000 00:00 0		0x1000   thread stack end 18
48965000-49164000 rwxp 08801000 00:00 0		0x7ff000 thread stack 18
49164000-49165000 ---p 09000000 00:00 0		0x1000   thread stack end 19
49165000-49964000 rwxp 09001000 00:00 0		0x7ff000 thread stack 19
49964000-49965000 ---p 09800000 00:00 0		0x1000   thread stack end 20
49965000-4a164000 rwxp 09801000 00:00 0		0x7ff000 thread stack 20
4a164000-4a165000 ---p 0a000000 00:00 0		0x1000   thread stack end 21
4a165000-4a964000 rwxp 0a001000 00:00 0		0x7ff000 thread stack 21
4a964000-4a965000 ---p 0a800000 00:00 0		0x1000   thread stack end 22
4a965000-4b164000 rwxp 0a801000 00:00 0		0x7ff000 thread stack 22
4b164000-4b165000 ---p 0b000000 00:00 0		0x1000   thread stack end 23
4b165000-4b964000 rwxp 0b001000 00:00 0		0x7ff000 thread stack 23
4b964000-4b965000 ---p 0b800000 00:00 0		0x1000   thread stack end 24
4b965000-4c164000 rwxp 0b801000 00:00 0		0x7ff000 thread stack 24
4c164000-4c165000 ---p 0c000000 00:00 0		0x1000   thread stack end 25
4c165000-4c964000 rwxp 0c001000 00:00 0		0x7ff000 thread stack 25
4c964000-4c965000 ---p 0c800000 00:00 0		0x1000   thread stack end 26
4c965000-4d164000 rwxp 0c801000 00:00 0		0x7ff000 thread stack 26
4d164000-4d165000 ---p 0d000000 00:00 0		0x1000   thread stack end 27
4d165000-4d964000 rwxp 0d001000 00:00 0		0x7ff000 thread stack 27
4d964000-4d965000 ---p 0d800000 00:00 0		0x1000   thread stack end 28
4d965000-4e164000 rwxp 0d801000 00:00 0		0x7ff000 thread stack 28
4e164000-4e165000 ---p 0e000000 00:00 0		0x1000   thread stack end 29
4e165000-4e964000 rwxp 0e001000 00:00 0		0x7ff000 thread stack 29
4e964000-4e965000 ---p 0e800000 00:00 0		0x1000   thread stack end 30
4e965000-4f164000 rwxp 0e801000 00:00 0		0x7ff000 thread stack 30
4f164000-4f165000 ---p 0f000000 00:00 0		0x1000   thread stack end 31
4f165000-4f964000 rwxp 0f001000 00:00 0		0x7ff000 thread stack 31
4f964000-4f965000 ---p 0f800000 00:00 0		0x1000   thread stack end 32
4f965000-50164000 rwxp 0f801000 00:00 0		0x7ff000 thread stack 32
50164000-50165000 ---p 10000000 00:00 0		0x1000   thread stack end 33
50165000-50964000 rwxp 10001000 00:00 0		0x7ff000 thread stack 33
50964000-50965000 ---p 10800000 00:00 0		0x1000   thread stack end 34
50965000-51164000 rwxp 10801000 00:00 0		0x7ff000 thread stack 34
51164000-51165000 ---p 11000000 00:00 0		0x1000   thread stack end 35
51165000-51964000 rwxp 11001000 00:00 0		0x7ff000 thread stack 35
51964000-51965000 ---p 11800000 00:00 0		0x1000   thread stack end 36
51965000-52164000 rwxp 11801000 00:00 0		0x7ff000 thread stack 36
52164000-52165000 ---p 12000000 00:00 0		0x1000   thread stack end 37
52165000-52964000 rwxp 12001000 00:00 0		0x7ff000 thread stack 37
52964000-52965000 ---p 12800000 00:00 0		0x1000   thread stack end 38
52965000-53164000 rwxp 12801000 00:00 0		0x7ff000 thread stack 38
53164000-53165000 ---p 13000000 00:00 0		0x1000   thread stack end 39
53165000-53964000 rwxp 13001000 00:00 0		0x7ff000 thread stack 39
53964000-53965000 ---p 13800000 00:00 0		0x1000   thread stack end 40
53965000-54164000 rwxp 13801000 00:00 0		0x7ff000 thread stack 40
54164000-54165000 ---p 14000000 00:00 0		0x1000   thread stack end 41
54165000-54964000 rwxp 14001000 00:00 0		0x7ff000 thread stack 41
54964000-54965000 ---p 14800000 00:00 0		0x1000   thread stack end 42
54965000-55164000 rwxp 14801000 00:00 0		0x7ff000 thread stack 42
55164000-55264000 rw-p 00000000 00:00 0		mmap'ed malloc area.
unused memory from 55264000-55555000
55555000-5556b000 r-xp 00000000 5e:06 96425      /usr/src/libc-build/elf/ld.so
5556b000-5556e000 rw-p 00015000 5e:06 96425      /usr/src/libc-build/elf/ld.so
5556e000-5556f000 rwxp 00000000 00:00 0		sbrk'ed malloc area.
5556f000-55570000 ---p 00001000 00:00 0		0x1000   thread stack end 43
55570000-55d6f000 rwxp 00002000 00:00 0		0x7ff000 thread stack 43
55d6f000-55d70000 ---p 00801000 00:00 0		0x1000   thread stack end 44
55d70000-5656f000 rwxp 00802000 00:00 0		0x7ff000 thread stack 44
5656f000-56570000 ---p 01001000 00:00 0		0x1000   thread stack end 45
56570000-56d6f000 rwxp 01002000 00:00 0		0x7ff000 thread stack 45
56d6f000-56d70000 ---p 01801000 00:00 0		0x1000   thread stack end 46
56d70000-5756f000 rwxp 01802000 00:00 0		0x7ff000 thread stack 46
5756f000-57570000 ---p 02001000 00:00 0		0x1000   thread stack end 47
57570000-57d6f000 rwxp 02002000 00:00 0		0x7ff000 thread stack 47
57d6f000-57d70000 ---p 02801000 00:00 0		0x1000   thread stack end 48
57d70000-5856f000 rwxp 02802000 00:00 0		0x7ff000 thread stack 48
5856f000-58570000 ---p 03001000 00:00 0		0x1000   thread stack end 49
58570000-58d6f000 rwxp 03002000 00:00 0		0x7ff000 thread stack 49
58d6f000-58d70000 ---p 03801000 00:00 0		0x1000   thread stack end 50
58d70000-5956f000 rwxp 03802000 00:00 0		0x7ff000 thread stack 50
5956f000-59570000 ---p 04001000 00:00 0		0x1000   thread stack end 51
59570000-59d6f000 rwxp 04002000 00:00 0		0x7ff000 thread stack 51
59d6f000-59d70000 ---p 04801000 00:00 0		0x1000   thread stack end 52
59d70000-5a56f000 rwxp 04802000 00:00 0		0x7ff000 thread stack 52
5a56f000-5a570000 ---p 05001000 00:00 0		0x1000   thread stack end 53
5a570000-5ad6f000 rwxp 05002000 00:00 0		0x7ff000 thread stack 53
5ad6f000-5ad70000 ---p 05801000 00:00 0		0x1000   thread stack end 54
5ad70000-5b56f000 rwxp 05802000 00:00 0		0x7ff000 thread stack 54
5b56f000-5b570000 ---p 06001000 00:00 0		0x1000   thread stack end 55
5b570000-5c56f000 rwxp 06002000 00:00 0		0x7ff000 thread stack 55
unused memory from 5c56f000-7fffc000
7fffc000-80000000 rwxp ffffd000 00:00 0		stack main program

pthread_create calls allocate_dtv to allocate room in the dtv. This is done
by calloc. The area used for the 68 bytes needed for the calloc call is full
so sYSMALLOc gets called. The MORECODE call which in fact is sbrk
fails because there is no more room after the sbrk area of ld.so. The fallback
to mmap is used and the mmap call to get the additional 1M returns the
address 0x55264000. But old_end still points to the end of the sbrk area
and the "else if" in the following code piece from sYSMALLOc becomes
true:

    /*
      If MORECORE extends previous space, we can likewise extend top size.
    */

    if (brk == old_end && snd_brk == (char*)(MORECORE_FAILURE)) {
      set_head(old_top, (size + old_size) | PREV_INUSE);

    } else if (old_size && brk < old_end) { /* <--- This if becomes true !! */
      /* Oops!  Someone else killed our space..  Can't touch anything.  */
      assert(0);
    }

sYSMALLOc returns NULL and the calloc fails. I wonder if the "else if"
might be incorrect. 

blue skies,
  Martin.


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