[ug-bosug] Fwd: [cslug] malloc problem on Solaris
S h i v
shivakumar.gn at gmail.com
Fri Sep 14 22:37:03 PDT 2007
> ---------- Forwarded message ----------
> From: vijay das <lovingvijay2002 at yahoo.com>
> To: cslug at yahoogroups.com
>
> The default Sun Solaris malloc library is generally
> considered inefficient.
> For high scalability and high performance, it is best
> to use 3rd party memory manager library. For example,
> I have simple/pure C/C++ program
>
> 1. Allocates, say 512 MB memory.
> 2. Free the memory allocated in step 1.
> 3. Allocate, memory in step1 + 10MB.
> 4. Free the memory in step 3.
>
I havent run any benchmarks or tests to compare the efficiency of the
memory management, so cant comment on the *considered inefficient*
part.
But the example above does not give an indication of proper/improper
memory management due to reasons mentioned below.
> If I use 'pmap' to watch the meomory *after* step 2
> and step 4, it still says that much memory is still in
> use by the process.
As far as my understanding goes, with default memory management in
Solaris, the heap mapping is virtual memory, so requesting memory with
malloc does not allocate physical memory. It allocates the virtual
address space. Physical address gets allocated on first reference
(triggered by a page fault). On freeing the memory, the memory is not
reclaimed immediately by the system but remain in the heap mapping as
unused pages. Subsequent allocations will reuse these pages and not
get it allocated from the system thus yielding better efficiency (do a
memory allocation again after free and the memory as shown by
prstat/pmap doesnt grow).
There is a system page scanner that runs in the background and
reclaims the unused pages when system moves towards mem crunch
situation.
The "Solaris Internals" book covers this in great detail in sections
"9 Virtual Memory" & "10. Physical Memory".
Others who have additional info may add to this.
-Shiv
More information about the ug-bosug
mailing list