Link to home
Start Free TrialLog in
Avatar of ngoel
ngoel

asked on

How to find the memory usage of a multithreaded process (on AIX)!?

Hi,

I have this program which runs for days and allocates a lot of RAM. Often I start getting No-Memory errors in the program (new() failed) even when programs like "top" or "ps" show the memory usage to be less than available memory.  I would like a way to let the program figure out it's own memory usage, and if possible , the maximum amount of memory it can allocate at any point of time.

The program is compiled as a 32 bit executable on a 64 bit AIX 4.3 machine. The available memory is 12Gb, my program starts having failed new() allcoations around 1.4Gb (close to but not yet at the 2Gb limit for the 32 but program).

Any help at all would be welcome. Any insights into how 32 bit programs memory allocation is dealt with in a 64 but enviro !?
Avatar of jlevie
jlevie

How much swap is available? Typically on a Unix OS the kernel will use brk() to swap out the task when it is necessary to increase the in-core size of the task as memory is allocated by malloc(). Because brk() is expensive, a sizeable chunk (much larger than the outstanding malloc()) is allocated. So if swap isn't large enough to hold the task and any other swapped out tasks you'll get the "out of memory error" even when there is free memory on the system when the kernel needs to increase the size of the task.
Also what about ulimit -m (memory any one process is allowed)?
did you check with vmstat?
Avatar of ngoel

ASKER

ulimit is not a problem, my 32 bit application can theoretically allocate 2Gb and small test applications on that system actually allow a "new" of that size.

Actually for some reasons, I am not sure that the OS is reporting the correct memory usage (through PS or TOP), that is why I wanted some way of figuring out memory usage from *within* the program itself. Is there any way ?

Moreover, there is plenty of swap space (there is even tons of real memory available) because as I said, I am running this on a 64 bit machine with tons of ram and swap space, my 32 bit application cannot even physically address all that RAM available.

So if there was some way of seeing the available memory from the process's eyes (whatever way the 32bit emulation works), then I would like to know.
sbrk(0) will return the current max addressible location for the process.  That doesn't mean you actually get to use that whole mem space, though, since it's laid out with some bits set aside for the stack, some for shated memory segments, some for memory mapped files, etc.  You can easily hit the 2gb limit without having 2gb of usable memory for your process.
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
I would have expected to see an answer that spoke specifically about the memory model used for 32-bit applications on AIX.
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial