Re: What does SZ on the ps output mean?



apm35@xxxxxxxxxxxxxxxxxx wrote:
But this does not tell me all that I need to know. I used to think
that SZ was the amount of heap storage used, as allocated typically
(but not exclusively) through malloc. But I am not sure now. I
originally assumed that no matter how many malloc and frees were done,
if they all matched and the app did not leak then SZ would not show an
ongoing upward trend. I think I need to understand more about SZ so I
have come here for help please.

'SZ' is an OS concept about mapped spaces.

'malloc' and 'free' are library routines that do not always directly
affect mappings. In particular, 'free' will not normally return the
now-unused memory back to the OS (there are many reasons this can be
difficult to do). Some alternate allocation libraries will try to do
this as well as possible.

You are correct that over the long term if the malloc and frees match
up, there shouldn't be an upward trend. But it is possible for
fragmentation to occur in the allocation area. If that happens, then
you lose useful space to fragmentation.

Here's why I am not sure: I have a java program, a server, that uses
SWIG/JNI to talk to a C wrapper which in turn talks to a third-party C
API. I have been using ps to monitor the value of SZ over time in the
hope of spotting any memory leak. I am also using JMX via jconsole to
examine the java heap as mgd by the JVM. Jconsole tells me that the
heap is periodically GCd with a series of relatively frequent minor GC
efforts and a more major GC effort every two hours or so. It basically
says there are no leaks. But the value of SZ keeps going up. There are
fluctuations and one has to see the ps results over a 24 hour period
to see the overall trend. The trend is a slow climb of around 500
pages followed by a sharp spike every few hours of between 500 to 1500
pages. The overall effect is a definate upward trend with an average
growth of 1 MB per hour.

When I only had figures for the first hour or so and I saw a spike I
figured that because the values after the spike had gone down maybe
there weren't any leaks and any outstanding memory would be reclaimed
eventually. But the climb of SZ is relentless. It is one of the
biggest processes on the machine now and this has me worried.

Rather than a single value, you might examine the process with 'pmap -x
<PID>' and see which particular mapping (or mappings) is growing. Of
course if it is the heap, then you'll have to do the debugging at the
Java or library level to see why the memory is continuing to leak.

--
Darren Dunham ddunham@xxxxxxxx
Senior Technical Consultant TAOS http://www.taos.com/
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
.



Relevant Pages

  • Re: trap in malloc on 2000 terminal server
    ... For the error in the debugger extension, looks like you have an old debugger ... some operation that has an undefined behavior beforehand. ... On average, heap corruption shows up as crashes in random places, ... What is the logic of malloc? ...
    (microsoft.public.win32.programmer.kernel)
  • Re: trap in malloc on 2000 terminal server
    ... For the error in the debugger extension, looks like you have an old debugger ... some operation that has an undefined behavior beforehand. ... On average, heap corruption shows up as crashes in random places, ... What is the logic of malloc? ...
    (microsoft.public.win32.programmer.tools)
  • Re: malloc questions in C
    ... malloc() or one of the similar functions, it will be available until you call free. ... A lot of C implementations will also free this memory for you when your program exits, ... /* a) myhappyfunmodule has an internal memory leak */ ...
    (comp.lang.c)
  • Re: evc4 app memory leak
    ... You've got a leak. ... If you never malloc or LocalAlloc (or use a heap ... checked these and they all appear to have new/delete pairs. ... The app does have a section that deals with socket communication that uses ...
    (microsoft.public.pocketpc.developer)
  • Re: Modifying default Win32 heap management.
    ... I'm doing some experiment about heap management on Windows. ... is intercepting Win32 default heap management calls and modifying its ... replaced these calls with another verified malloc implementation, ... works on Win32 as well. ...
    (microsoft.public.win32.programmer.kernel)