How to free up unused cache or memory space

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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

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.
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:
Hi Sachin.
do u need more help here. please keep posted.
You can close the question by following this guidelines:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.