LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 11-15-2012, 03:16 PM   #1
thiyagusham
Member
 
Registered: Apr 2012
Posts: 213

Rep: Reputation: Disabled
Free command in linux


Hi to all;

free -m

here it shows 3 lines ..
I am very clear with 1st and 3rd line.
what indicates 2nd line here ? i mean -
-/+ buffers/cache, purpose of this one.
 
Old 11-15-2012, 05:58 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
The memory currently used for buffers and cache (as shown in the first line of the output from free) can be considered "almost free" memory, i.e., memory that could be immediately used to satisfy requests from a process for additional memory. The "cached" memory holds data that was recently read from or written to a block device and is kept around because (a) there is some chance that this data might be accessed again, and (b) keeping track of what is there costs almost nothing. The "buffers" memory is similar, but is used for file system metadata and data that is "in flight" to or from a block device, and the amount of memory allocated for that purpose is highly flexible.

So, the free command shows two calculations for "used" and "free" memory. In the first line, the amount shown for "buffers" and "cached" is included in the "used" total. In the second line, that memory is considered "free", i.e., subtracted from the previous "used" amount and added to the previous "free" amount.
 
1 members found this post helpful.
Old 11-15-2012, 07:11 PM   #3
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
http://www.linuxatemyram.com/
 
Old 11-16-2012, 07:38 AM   #4
thiyagusham
Member
 
Registered: Apr 2012
Posts: 213

Original Poster
Rep: Reputation: Disabled
@ rknichols

I never seen swap area used in my system. allocated swap space 2047 mb free also 2047mb i.e. always showing used = 0
then purpose of swap area ...when linux utilize swap area ?

Swap indicates ram memory. If this area is not ever used , allocated ram memory is waste.
am i right ?

Last edited by thiyagusham; 11-16-2012 at 07:48 AM.
 
Old 11-16-2012, 08:43 AM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Swap is virtual memory. It is disk-storage that gets 'swapped' in and out of real memory by the kernel on an as-needed basis. Strategically, it is a last resort for allocation of memory, since it requires the relatively slow access to disk hardware. Showing that your system has never used swap memory means that your system has as much or more real memory than required for the applications you are using (a good thing).
--- rod.
 
Old 11-16-2012, 08:51 AM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Swap space is space on disk used as secondary storage when there is high demand for physical RAM. If you have plenty of RAM on your machine, it is normal to see little or no use of swap space, but if your system is running for a long time there will almost always be a few megabytes of memory pages that some process allocated when the machine was booted and never referenced since then, and those pages will eventually end up in swap.

The other time that swap space is used is if you use the "hibernate" (suspend to disk) feature of the OS. Then, all of the allocated non-cache pages of physical memory get saved in the swap space so that they can be reloaded when the machine is restarted. For that to work, you need swap space (which could be one or more partitions and/or files) that is at least as large as physical memory. If you're not using hibernate, then swap space of 1X to 2X physical memory (but not more than 2GB to 4GB) is a useful safety net for that time you're editing a couple of huge image files and need a lot more memory than usual. (A system that is actually using more swap than that would be so slowed by paging as to be almost useless, though there are undoubtedly some special use cases where huge amounts of swap make sense.)
 
Old 11-16-2012, 09:07 AM   #7
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by thiyagusham View Post
Swap indicates ram memory.
No, it is disk space.

Quote:
If this area is not ever used , allocated ram memory is waste.
am i right ?
A 2GB swap space, that is never needed, is a good safety net for an ordinary Linux system. Just in case some process uses an unexpected large amount of ram, you will have just a slow down rather than a failure.

Yes, that 2GB of disk space is probably "wasted". How big is your hard drive? With an obsolete 80GB hard drive, I'd be a little upset about wasting 2GB. I have a fairly old 500GB hard drive, so wasting 2GB of it doesn't bother me at all. I have no clue what size hard drive you have, so I don't know whether wasting 2GB of it should bother you.

All the 1x ram or 2x ram nonsense frequently suggested was always an unsound "rule of thumb" to apply in cases where you have no clue how much swap you need. But really the amount of swap you might need has no real correlation with the amount of ram. Unless your hard drive is tiny, I think 2GB is a good swap size for an ordinary Linux system, regardless of ram size.

Last edited by johnsfine; 11-16-2012 at 09:08 AM.
 
  


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
Like to understand the linux "free" command with respect to cache and free memory bruzzese Linux - Server 2 03-28-2010 12:52 PM
Free SMS / calls with gizmo, command-lined with linux ? frenchn00b General 0 11-08-2007 05:38 PM

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

All times are GMT -5. The time now is 12:38 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