Skip to main content

Why is the measurement of memory usage using "top" utility not accurate?

  • February 16, 2013
  • 0 replies
  • 1 view

Problem:

  • Product Version: VBC Full
  • Platform Version: All Unix
  • JDK Version: NA
  • Compiler Version: NA
  • Product Component: ORB

Why is the measurement of memory usage using "top" utility not accurate?

Resolution:

To understand why the memory usage reported by top is not accurate, it is essential to have an understanding of how malloc() and free() work.

When the malloc() request for additional memory, sbrk() is called to increase the size of the heap if it does not contain enough free memory to fulfill the request. However, when memory is freed, sbrk() is not called to shrink the heap size accordingly. The freed memory is made available for other malloc() requests. This is done for two reasons.

First, unless the freed block is at the very top of the heap, it would be impossible to shrink the heap size without defragmenting all the remaining allocated memory segments. This would be very expensive CPU wise at each free() operation.

Secondly, if the virtual memory system does run out of physical RAM and pages out a block of now-unused heap space, it will not get paged back in until it happens to get malloced for something else.


#free
#memory
#VisiBroker
#Security
#malloc
#heap