malloc returning high memory addresses with pthread_create

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

malloc returning high memory addresses with pthread_create

Sayantan Sur
Hi,

I observed a behavior with malloc returning high memory addresses and
I'm wondering if someone could give me some insight into why this
happens.

The attached program sets the M_MMAP_MAX threshold to 0 (ie disabling
the use of mmap by malloc), spawns a thread which simply allocates and
frees 4KB chunk of memory. Now, according to whether both threads
(main thread and the spawned thread) execute concurrently or not, I
see a difference in the values of the pointers returned.

The program when compiled with:

$ gcc -DMALLOC_SERIALIZED mallopt_test.c -lpthread

does not return any high memory addresses. Whereas, when compiled with:

$ gcc -DMALLOC_CONCURRENT mallopt_test.c -lpthread

returns high memory addresses, which are printed out like:

...
Got ptr 0x2aaaaab008d0 in Main thread
Got ptr 0x2aaaaab008d0 in Main thread
Got ptr 0x2aaaaab008d0 in Main thread
...

Why is that when both threads execute concurrently, memory is
allocated at such high values? Is it a known issue? or is it an issue
at all?

My machine is an EM64T Xeon 3.4 GHz with 2GB memory. I'm using RedHat
AS 4 (Red Hat Enterprise Linux AS release 4 (Nahant Update 2)).

TIA,
Sayantan.

--
http://www.cse.ohio-state.edu/~surs

mallopt_test.c (1K) Download Attachment