Re: FW: [Myricom help #22513] MPICH-GM 1.2.5..10 on Intell C++ 7.1 for Itanium2 realloc problem]
Loic Prylli <[email protected]> Wed, 10 Mar 2004 05:56:26 -0500
| Newsgroups | gmane.network.myrinet.general |
|---|---|
| Message-ID | <[email protected]> |
> -----Original Message----- > From: Alexey V. Medvedev [mailto:[email protected]] Sent: > Friday, March 05, 2004 12:30 AM > To: [email protected] > Cc: [email protected]; [email protected] > Subject: Re: [Myricom help #22513] MPICH-GM 1.2.5..10 on Intell C++ > 7.1 for Itanium2 realloc problem] > > [...] > > I think I have found bug in ptmalloc2 code used in MPICH-GM > which causes described failures. > Dear Alexey, We would like to thank you for tracking this bug, and for the excellent work you did on it. We are sorry that we were not able to help you, but we were originally not able to reproduce the problem, even taking time to take your malloc traces and generating artifical programs doing the same allocation patterns. As you point out, our modification of the MMAP related constants in the ptmalloc code create a bug, the symptoms will be: - realloc() might fail (i.e. return null prematurely) for multithreaded programs when extending a block of less than 1Mbyte to something between 1Mb and 4Mb. - Multithreaded programs with the possibility of concurrent malloc or reallocs in several threads are affected, mono-threaded programs are immune to this bug due to the way ptmalloc works. The Intel C++ runtime had an influence on malloc/realloc usage() (and that sent us on the wrong path). > I think you must fix the problem in the nearest mpich-gm release ASAP. > > We have a mpich-1.2.5..12pre5.tar.gz tar-ball on the ftp/web page, which contains a fix for that among other changes, and which will become mpich-1.2.5..12 if no problem is found during final testing. It contains the patch attached to this mail as a fix to the realloc() problem. Note that we made a little test case to reproduce the bug which is in the second attachment. Regards, Loic _______________________________________________ Myrinet mailing list [email protected] http://email.osc.edu/mailman/listinfo/myrinet
ptmalloc.patch
(text/x-patch, 948 B)
diff -u ../mpich-1.2.5..12pre5/mpid/ch_gm/ptmalloc2/arena.c mpid/ch_gm/ptmalloc2/arena.c --- ../mpich-1.2.5..12pre5/mpid/ch_gm/ptmalloc2/arena.c Wed Mar 12 20:13:46 2003 +++ mpid/ch_gm/ptmalloc2/arena.c Fri Mar 5 12:22:02 2004 @@ -24,7 +24,7 @@ #define HEAP_MIN_SIZE (32*1024) #ifndef HEAP_MAX_SIZE -#define HEAP_MAX_SIZE (1024*1024) /* must be a power of two */ +#define HEAP_MAX_SIZE (4*1024*1024) /* must be a power of two */ #endif /* HEAP_MIN_SIZE and HEAP_MAX_SIZE limit the size of mmap()ed heaps diff -u ../mpich-1.2.5..12pre5/mpid/ch_gm/ptmalloc2/malloc.c mpid/ch_gm/ptmalloc2/malloc.c --- ../mpich-1.2.5..12pre5/mpid/ch_gm/ptmalloc2/malloc.c Wed Apr 16 23:57:31 2003 +++ mpid/ch_gm/ptmalloc2/malloc.c Fri Mar 5 12:22:31 2004 @@ -15,7 +15,7 @@ #define MORECORE gmpi_sbrk #define munmap(a,b) gmpi_munmap(a,b) -#define DEFAULT_MMAP_THRESHOLD 4*1024*1024 +#define DEFAULT_MMAP_THRESHOLD (2*1024*1024) #define HAVE_MREMAP 0
ptmalloc_bug.c
(text/x-c, 505 B)
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <pthread.h>
#include <assert.h>
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
#define DO_LOCK 0
void *bug(void *a)
{
void *ptr;
while (1) {
if (DO_LOCK) pthread_mutex_lock(&mutex);
ptr = malloc(300);
ptr = realloc(ptr,1500000);
assert(ptr);
free(ptr);
if (DO_LOCK) pthread_mutex_unlock(&mutex);
}
return 0;
}
int main()
{
pthread_t ph;
pthread_create(&ph,0, bug,0);
bug(0);
return 0;
}