1754394 Members
2697 Online
108813 Solutions
New Discussion юеВ

maxdsiz and mallinfo()

 
SOLVED
Go to solution
Thu Nguyen_2
Advisor

maxdsiz and mallinfo()

The maxdsiz value on my system is set to 1.9G. My application calls mallinfo() to get memory allocated tracked by the system and here is the result:
System-tracked memory statistics:
----------------------------------------------------
Total space in arena 359501064 bytes
Number of ordinary blocks 352488
Number of small blocks 0
Space in holding block headers 0 bytes
Number of holding blocks 0
Space in small blocks in use 0 bytes
Space in free small blocks 0 bytes
Space in ordinary blocks in use 359555296 bytes
Space in free ordinary blocks 863208 bytes
Space penalty for keep option 0 bytes

Please help me to understand the result from mallinfo... Specifically, where is maxdsize in the picture???
11 REPLIES 11
harry d brown jr
Honored Contributor

Re: maxdsiz and mallinfo()

Mike Stroyan
Honored Contributor
Solution

Re: maxdsiz and mallinfo()

mallinfo just reports what memory malloc has allocated, not how much memory it will be able to allocate.
maxdsiz is one of the limits that could cause a malloc to fail. It could also fail for running out of swap space, or for reaching the start of another memory segment.
You can inquire maxdsiz on 11.11 and later by calling gettune().
To use 1.9GB your process will need to be linked with -Wl,-N. That makes data in a 32-bit process start just above the text area instead of starting at 0x4000000.
Thu Nguyen_2
Advisor

Re: maxdsiz and mallinfo()

Thanks very much for your response Mike... So what is the meaning of "Space in free ordinary blocks". Is it the space available? And Is -N is a default for ANSI C compile?
Mike Stroyan
Honored Contributor

Re: maxdsiz and mallinfo()

"Space in free ordinary blocks" is the total amount of memory that malloc is holding for reuse by future malloc/realloc/calloc requests. When a free or realloc call releases memory it is added to a free blocks list. It is not removed from the process's data segment. Depending on fragmentation, the process could malloc as much as the "Space in free ordinary blocks" without using brk/sbrk to grow the process data area. There can still be much more space available to the process, but that will depend on external resources and other limits like maxdsiz and getrlimit(RLIMIT_DATA).
The "small blocks" data from mallinfo refers to the "small block allocator" or SBA. That uses a different strategy to make small block allocations more efficient. It handles malloc requests smaller than M_MXFAST bytes by allocating large groups of those small blocks and then allocating and releasing those smaller blocks within the groups of the same size. That can make malloc/free quite a bit faster. It can also reduce fragmentation caused by small blocks getting in between large free blocks and preventing them from being coalesced for a large request.

The -Wl,-N option is not the default. You need to use that explicitly to get more data area. You can also use "chatr +q3p enable" on 11i or a properly patched 11.00. The more extreme "chatr +q4p enable" can be used on 11i if your process can run without shared memory. Those chatr options can drive maximum data size to almost 3GB or almost 4GB.
Thu Nguyen_2
Advisor

Re: maxdsiz and mallinfo()

Hi, thanks again.. please explain when we have negative values like this:
----------------------------------------------------
Total space in arena 632114272 bytes
Number of ordinary blocks 443748
Number of small blocks 0
Space in holding block headers 0 bytes
Number of holding blocks 0
Space in small blocks in use 0 bytes
Space in free small blocks 0 bytes
Space in ordinary blocks in use -352390632 bytes
Space in free ordinary blocks 247702416 bytes
Space penalty for keep option 0 bytes
Mike Stroyan
Honored Contributor

Re: maxdsiz and mallinfo()

Mallinfo is using signed 32 bit integers for sizes. It gets confused for numbers higher than 2^31-1. You can map a negative number to the real value with
echo '2^32 - 352390632' | bs
which in this case is 3942576664.
That's kind of big.
Thu Nguyen_2
Advisor

Re: maxdsiz and mallinfo()

Please help me to understand the meanings of "Total space in arena" and "Space in ordinary block in use". Thanks very much
Mike Stroyan
Honored Contributor

Re: maxdsiz and mallinfo()

"Total space in arena" is the total area that malloc has allocated with brk. That includes ordinary and small blocks, both in-use and freed space.
"Space in ordinary block in use" is the amount of currently malloc'd memory that was allocated in chunks larger than the M_MXFAST small block limit, and that has not been freed by the application.
Thu Nguyen_2
Advisor

Re: maxdsiz and mallinfo()

Hi, so now I'm even more confused...You said that the "total space in arena" ( in my case is 342MB) includes the ordinary space in used and freed (3.7GB and 236MB)

I still don't know how I can interpret the result of mallinfo()... Please help me again
Thanks a lot