LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-28-2008, 03:55 AM   #1
morfeus80
Member
 
Registered: Mar 2006
Distribution: OpenSUSE 10.3
Posts: 53

Rep: Reputation: 15
Memory allocation


I have seen that in Linux if you run a program that uses some memory(RAM), when you close it, the allocated memory isn't released. So, how can I release it to see the real memory usage of the programs I'm running?
 
Old 01-28-2008, 04:55 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Close - it may not be immediately released. If no-one else needs it, it may be "pending" release (my terminology). Has nothing to do with your programs "usage".
What you are using (sort of) will be shown by top/sar/whatever. If you need some of the "pending" storage you will get it.
End of story.
 
Old 01-28-2008, 05:13 AM   #3
morfeus80
Member
 
Registered: Mar 2006
Distribution: OpenSUSE 10.3
Posts: 53

Original Poster
Rep: Reputation: 15
Thanks, but you are not so clear... I've have some allocated memory I am not using, so how can I release it?
 
Old 01-28-2008, 05:31 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Don't worry about it. If you haven't used it, you aren't using it. No PTE, so nothing to release.
If you really want to know what you're using, have a look at /proc/<pid>/smaps.
Documentation is sparse ...
 
Old 01-28-2008, 12:49 PM   #5
geesh
Member
 
Registered: Feb 2004
Posts: 53

Rep: Reputation: 16
this tells you about free memory


free -m



use in a root terminal to clear cached memory but i wouldn't do this often since cached memory speeds your system up


sync; echo 3 >> /proc/sys/vm/drop_caches
 
Old 01-28-2008, 02:51 PM   #6
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
If you run 'free' it'll give you this:
Code:
             total       used       free     shared    buffers     cached
Mem:       1033612    1013016      20596          0        108     729112
-/+ buffers/cache:     283796     749816
Swap:      1967952         12    1967940
The important value here (in red) is 749816, that's the amount of free RAM I have at the moment. However, note that Linux is using 1013016 bytes, and the total is 1033612.

The calculation for free memory here is:
729112 cached memory + 108 memory buffers + 20596 completely free = 749816 free memory

Here's a decent explanation of what these mean:
http://mail.nl.linux.org/linux-mm/2003-03/msg00077.html
Quote:
2. Definitions

RAM (Random Access Memory) - Location where programs reside when
they are running. Other names for this are system memory or
physical memory. The purpose of this document is to determine if
you have enough of this.

Memory Buffers - A page cache for the virtual memory system. The
kernel keeps track of frequently accessed memory and stores the
pages here.

Memory Cached - Any modern operating system will cache files
frequently accessed. You can see the effects of this with the
following commands:

for i in 1 2 ; do
free -o
time grep -r foo /usr/bin >/dev/null 2>/dev/null
done

Memory Used - Amount of RAM in use by the computer. The kernel
will attempt to use as much of this as possible through buffers
and caching.
or a more complicated in-depth explanation:
http://tldp.org/LDP/khg/HyperNews/ge...y/linuxmm.html

So, basically, the kernel will use all your memory, mostly for cached memory, which will greatly speed up access to frequently used files. However, it will release this cached memory when there are more important things to do with it, such as when programs need it. So, don't worry. Trust Linus T.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
memory allocation esael Linux - General 7 01-12-2008 12:12 PM
memory allocation gecoool Programming 2 10-24-2005 09:47 AM
Help - memory allocation in C zaichik Programming 3 09-04-2005 10:16 AM
memory allocation docGonzo2000 Linux - General 1 05-16-2003 09:24 PM
memory allocation docGonzo2000 Linux - General 1 05-16-2003 09:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration