How to free up unused cache or memory space

Posted on 2003-11-18
Last Modified: 2013-12-27
Hi ,
 I have a routine process which includes several bash scripts , perl programs and
other compiled programs which utilize a lot of memory. ( takes almost 32 hours to run )
 Initially the process runs as expected , but after say 10 hours , i can see that the speed of processing has gone down drastically. I mean when i do a 'ps' i can see that the current script is utilizing only 1.6% CPU and takes hours to complete. Whereas if i run the same script alone , It utilizes sizable memory ( 95% CPU ) and completes within 15 minutes.
 I guess i may have got some memory stuck or blocked ....
I have.....
RAM:1023 MB
SWAP : 3892 MB
OS : SunOS Release 5.8 Generic_108529-13

Ouestion: How do I release the memory without stopping the process or from within the process ( bashscript ) ? and also please note that I am not the Administrator.Any other related suggestions are also welcome.

Question by:SachinDesai
  • 4
  • 2
LVL 24

Accepted Solution

shivsa earned 125 total points
ID: 9776873
In first case, your system is stress and starving for memory.

The application code and its data files are still in memory, even though they are not active. The memory they occupy is not "free." since the same application running it finds the pages that are already in memory and not able to free. and there is insufficient free memory for any new process.

when u start a alone new process the kernel will scan for pages that have not been touched for a long time, and "free" them. Once you quit the first application, the memory it occupies is not being touched, so it will be freed quickly for use by other applications.

In 1988, Sun introduced this feature in SunOS 4.0. It still applies to all versions of Solaris 1 and 2. The kernel is trying to avoid disk reads by caching as many files as possible in memory. Attaching to a page in memory is around 1,000 times faster than reading it in from disk. The kernel figures that you paid good money for all of that RAM, so it will try to make good use of it by retaining files you might need.

So short answer that u can not free up memory while running the process. u may use good programming technique for memory management(like free up all the memory in code after using that and all).
u may also check your programs for possible memory leaks.
LVL 24

Expert Comment

ID: 9776875

Expert Comment

ID: 9776916
I'm a little confused.

> It utilizes sizable memory ( 95% CPU )
Memory and CPU are different entities. Just because it uses 95% CPU does not mean it uses lots of memory.

What I think you need to do is monitor the process throughout its life, recording the main system attributes during that period.

The first port of call is usually sar. There are heaps of parameters to sar, but run without any it will record the proportion of time the system is being used by usr and sys and the proportion spent waiting for io. Running it like this:
   sar 60 1000 > sar.out
will run the reporting every 60 seconds for 1000 cycles (ie it will report once every 60 secs for 1000 minutes) and will output to file "logfile".

Have a look at the man page for sar for an explanation of the output.

If the CPU use goes right down, but the process still continues running, it could be that you are out of memory and starting to swap. Look at the paging stats from vmstat. As before:
   vmstat 60 1000 > vmstat.out
The columns to look at are:
   free   free memory pages
   swap   free pages in swap
   sr  scan rate - indicates that the system is scanning memory for pages to move out into swap
   po  page out - pages being moved to swap

There are other tools available, for example prstat and mpstat. Take a look and see haow you get on.
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.


Expert Comment

ID: 9776933
Just to clarify something shivsa said. The file cache will occupy almost all free memory after the system has been in use for some time. However this is still effectively free memory, and so will be used by processes as they need it. There is no need to force it to be free.

At some stage (not sure if it is Solaris 8 or 9) the free memory reporting has been changed so that it counts file cache as free memory.
LVL 38

Expert Comment

ID: 9776982
As already mentioned in the about comments, you can not use script to FREE
process memory. "u may use good programming technique for memory management(free() up all the memory in code after using that and all).

Have a look at the following Solaris memory management doc:


UNIX FAQ: -- Virtual Memory

Performance tune:
LVL 24

Expert Comment

ID: 9783825
Hi Sachin.
do u need more help here. please keep posted.
LVL 24

Expert Comment

ID: 9816358
You can close the question by following this guidelines:

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question