LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-21-2013, 12:37 AM   #1
rarrao
LQ Newbie
 
Registered: May 2013
Posts: 8

Rep: Reputation: Disabled
Linux Multi-heap Multi-thread application


We are porting a multi-process application to multi-threaded architecture. We have the same application running on Windows and it is very performant.
For Linux we are using the pthread libraries. In order to avoid memory contention we have custom heaps, each thread having its own heap. We are using mspace for this custom heap implemention. However the issue is that this approach is causing a lot of performance overhead. The mspace memory allocations are very slow as compared to the native malloc. This is the bottleneck. We tried the Hoard allocator but that is much worse.

Is there any alternative to acheive multi-heap which is also performant?
 
Old 05-21-2013, 04:18 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
I think you can reach the best performannce without any custom heap handler. You can try valgrind to catch memory handling problem.
 
Old 05-21-2013, 08:15 AM   #3
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
Looking through http://gee.cs.oswego.edu/pub/misc/malloc.c, my intuition is that your library is compiled with USE_LOCKS:
Quote:
USE_LOCKS default: 0 (false)
Causes each call to each public routine to be surrounded with pthread or WIN32 mutex lock/unlock. (If set true, this can be overridden on a per-mspace basis for mspace versions.) If set to a non-zero value other than 1, locks are used, but their implementation is left out, so lock functions must be supplied manually, as described below.
 
Old 05-22-2013, 08:00 PM   #4
rarrao
LQ Newbie
 
Registered: May 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
I think you can reach the best performannce without any custom heap handler. You can try valgrind to catch memory handling problem.
Thanks for the reply. However it is not possible to use a common heap since we have lots & lots - in terms of millions per hour - allocations and a single heap is getting fragmented and very less performant.
Also I want to make sure each thread has a separate chunk of memory to avoid leak/overrun since the threads can run custom code and plugins.
Any suggestions?
 
Old 05-22-2013, 08:03 PM   #5
rarrao
LQ Newbie
 
Registered: May 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
Looking through http://gee.cs.oswego.edu/pub/misc/malloc.c, my intuition is that your library is compiled with USE_LOCKS:
Thanks for the reply. This is a really good option. However I did explore this earlier and don't see any improvements

How is it that Linux doesn't have native multi heap implementation? When pthread supports all if not more features of Windows multi-thread, it should also have supported multiple heap concept...
 
Old 05-22-2013, 08:14 PM   #6
rarrao
LQ Newbie
 
Registered: May 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hi all,

Are there any other linux custom heap allocators? I have tried mspace & hoard.

Do you think the issue with mspace is that it runs in user-mode and not in kernel-mode?

This is a generic problem for any huge application. Are there any huge applications that is multi-threaded in linux? Or is it that all are multi-process?

Does anybody else have same issue? If so, I think we should put this feature into linux kernel itself...

Please do provide inputs.
 
Old 05-23-2013, 02:57 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,930

Rep: Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321Reputation: 7321
probably you need clone? http://www.linuxforu.com/2011/08/lig...linux-threads/
 
Old 05-23-2013, 11:07 AM   #8
rarrao
LQ Newbie
 
Registered: May 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
Thanks for suggestion. Do you mean use "clone" APIs instead of "pthread"? I do not think this is the bottle neck. I think the issue is Linux lacking multi-heap APIs and mspace not being performant in user mode under heavy load...
 
Old 05-30-2013, 10:10 AM   #9
rarrao
LQ Newbie
 
Registered: May 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hello everyone,
I am sure multi heap is a requirement for using multi threaded applications in Linux. Any huge application will end up getting its memory fragmented and insecure if it lets same heap for all threads and plugins.

Please share your valuable inputs.

Is this under requirements for Linux kernel?
Is there any good algorithm for multi heap in linux?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Performance issues in Linux Multi-heap Multi-thread application rarrao Linux - Newbie 2 05-21-2013 01:25 AM
Linux Multi-heap Multi-thread application rarrao Linux - Software 1 05-21-2013 01:25 AM
[SOLVED] what's the difference between a multi-cpu , multi-core and a multi-thread system ? entz Linux - Hardware 11 12-20-2011 04:49 PM
global integer in the multi-thread application lordofring Programming 1 08-23-2005 09:36 PM
multi-thread VS multi-process ltcstyle Programming 3 12-04-2004 06:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration