- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: free all memory allocations related to POSIX t...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2013 11:43 PM
11-04-2013 11:43 PM
I have written a simple multithreaded test program. It is attached to this post.
When I compile it with aCC (aCC: HP C/aC++ B3910B A.06.15 [May 16 2007]) and run it on HPUX 11.31 with libRTC
I see that some memory allocations are not freed until the end of the program:
aCC -mt +DD64 -g test_pthread_key.cpp -lpthread -o test_pthread_key.acc
>ldd ./test_pthread_key.acc
./test_pthread_key.acc:
libpthread.so.1 => /usr/lib/hpux64/libpthread.so.1
libstd_v2.so.1 => /usr/lib/hpux64/libstd_v2.so.1
libCsup.so.1 => /usr/lib/hpux64/libCsup.so.1
libm.so.1 => /usr/lib/hpux64/libm.so.1
libunwind.so.1 => /usr/lib/hpux64/libunwind.so.1
libc.so.1 => /usr/lib/hpux64/libc.so.1
libdl.so.1 => /usr/lib/hpux64/libdl.so.1
libuca.so.1 => /usr/lib/hpux64/libuca.so.1
BATCH_RTC=on LD_PRELOAD=/opt/langtools/lib/hpux64/librtc.so ./test_pthread_key.acc 1000 10 0
What I see is that when the program creates N POSIX threads then there will be N blocks of size 4096 bytes in a heap-report of libRTC.
I mean that N blocks of size 4096 bytes are not freed even thought I did pthread_join for each of the POSIX thread.
For example, this is one of allocations:
-------------------------------------------------------------------------
40960 bytes in 10 blocks (30.30% of all bytes allocated)
These range in size from 4096 to 4096 bytes and are allocated
#0 __pthread_setspecific() at /ux/core/libs/threadslibs/src/common/pthreads/specific.c:952
#1 __pthread_setspecific() at /ux/core/libs/threadslibs/src/common/pthreads/specific.c:692
#2 threadfunc(void*)() at test_pthread_key.cpp:22
#3 __pthread_bound_body() at /ux/core/libs/threadslibs/src/common/pthreads/pthread.c:4875
There are other allocations that are also related to the number of created threads.
I will attach a heap-report as well.
The same report I get if I compile the program with gcc.
Is it possible to free this memory allocations related to POSIX threads as soon as a POSIX thread has been joined?
My another program runs for a long time and have lots of short-lived threads and I am afraid that these memory allocations inside POSIX threads that are not freed properly will eventually cause increased memory consumption.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2013 11:45 PM
11-04-2013 11:45 PM
Re: free all memory allocations related to POSIX threads
A heap-report file produced by libRTC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2013 11:36 AM - edited 11-05-2013 11:37 AM
11-05-2013 11:36 AM - edited 11-05-2013 11:37 AM
Solution>I see that some memory allocations are not freed until the end of the program:
>I mean that N blocks of size 4096 bytes are not freed even though I did pthread_join
This storage is cached, so you can create new threads faster.
> aCC -mt +DD64 -g test_pthread_key.cpp -lpthread -o test_pthread_key.acc
(No need for -lpthread of you use -mt.)
>Is it possible to free this memory allocations related to POSIX threads as soon as a POSIX thread has been joined?
I don't think so. This isn't a leak, it will be reused when needed. (As long as the number of threads reaches a steady state.)
>have lots of short-lived threads
Then this caching will speed things up.
>will eventually cause increased memory consumption.
If you have a leak, you should be able to see it.