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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-15-2010, 02:25 AM
|
#1
|
Member
Registered: Aug 2009
Posts: 539
Rep:
|
How to understand the result from 'free'?
I list the memory with 'free' and got followings:
Code:
total used free shared buffers cached
Mem: 3864624 2886828 977796 0 247564 730480
-/+ buffers/cache: 1908784 1955840
Swap: 1044184 0 1044184
One can see the total and free of Swap are the same. What does this mean?
|
|
|
01-15-2010, 03:06 AM
|
#2
|
Senior Member
Registered: Oct 2003
Posts: 3,018
|
It means no swap is being used which is not surprising since you seem to have 4GB of ram.
|
|
|
01-15-2010, 03:38 AM
|
#3
|
Senior Member
Registered: Dec 2008
Posts: 4,732
|
Quote:
Originally Posted by kilgoretrout
It means no swap is being used which is not surprising since you seem to have 4GB of ram.
|
Does it mean no swap partition has been created ???
|
|
|
01-15-2010, 04:02 AM
|
#4
|
Member
Registered: Aug 2009
Posts: 539
Original Poster
Rep:
|
Quote:
Originally Posted by kilgoretrout
It means no swap is being used which is not surprising since you seem to have 4GB of ram.
|
Here is another one:
Code:
total used free shared buffers cached
Mem: 3088968 2718840 370128 0 116228 172136
-/+ buffers/cache: 2430476 658492
Swap: 1044184 43812 1000372
The ram is 3 GB but it takes some swap. Why?
|
|
|
01-15-2010, 07:29 AM
|
#5
|
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
|
Quote:
Originally Posted by thomas2004ch
The ram is 3 GB but it takes some swap. Why?
|
Apparently at some point over 3GB of RAM was being used and the system needed to put something in swap. To be honest, I'm not seeing anything unusual there.
Quote:
Originally Posted by anishakaul
Does it mean no swap partition has been created ???
|
The fact that there is an entry for Swap in the total column means that yes, a swap partition was created. It just wasn't being used.
|
|
1 members found this post helpful.
|
01-15-2010, 07:36 AM
|
#6
|
Senior Member
Registered: Dec 2008
Posts: 4,732
|
Quote:
Originally Posted by Hangdog42
The fact that there is an entry for Swap in the total column means that yes, a swap partition was created. It just wasn't being used.
|
Isn't it surprising that no swap is being used at all ?
In which case does this happen ?
In my computer whenever I do " free" swap column is never shown 0 !
|
|
|
01-15-2010, 07:50 AM
|
#7
|
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
|
Quote:
Isn't it surprising that no swap is being used at all ? In which case does this happen ?
|
Actually, no it isn't surprising, particularly with 4GB of RAM. I've got 4GB on my main laptop and I've never seen swap used. Heck, on my netbook I've got 2GB of RAM and never created a swap partition and it runs without a problem. Linux is actually pretty intelligent about how it uses RAM and since swap is glacially slow compared to RAM it doesn't use it unless it has to.
Quote:
In my computer whenever I do "free" swap column is never shown 0 !
|
Well, swap usage is a function of how much RAM is available and what services are running. The fact that I don't even have swap on my netbook reflects that it has a decent amount of RAM relative to the work I do with it. It runs things like a browser and word processor. If I were trying to serve tons of web pages or run databases on it, the lack of swap would likely be a problem. I've got a similar amount of RAM on my server and that is almost always using some swap, but that is running Apache, MySQL, SAMBA and a few other things.
|
|
1 members found this post helpful.
|
01-15-2010, 11:30 AM
|
#8
|
LQ Guru
Registered: Dec 2007
Distribution: Centos
Posts: 5,286
|
Most of the above discussion ignores the important interaction between swap and cache.
Linux keeps recently read pages in cache. That includes pages of data files your applications may have read as well as pages of read only file mappings (such as .so file and the main executable) that have been faulted out of a process's working set but not all the way out of physical ram.
If something needs memory and swap space is not available, then Linux must take that memory by reducing the cache. Sometimes that results in worse performance than if the swap space had been available.
If something needs memory and swap space is available, Linux will still usually take from the cache rather than swap pages out to swap space. But most systems have some processes that are either idle or have stale anonymous data, so there are anonymous data pages whose most recent access is significantly older than the most recent access of any read only mappings in the cache. Then it makes sense to swap those idle pages out to swap space in order to keep the cache large.
So, with plenty of ram and little enough file I/O and read only mapping that the cache never grows big enough to take most of the free memory, obviously the swap will never be used.
However with plenty of ram so the system never "needs" to use swap, but with enough recent file I/O or read only mapping that the cache is "full" (free memory outside the cache minimal) and also everything in the cache is newer than some stale anonymous pages, then Linux will correctly use some swap space even though it doesn't "need" to.
|
|
|
01-22-2010, 02:23 AM
|
#9
|
Senior Member
Registered: Dec 2008
Posts: 4,732
|
@Hangdog42
Many thanks for the info
I was not aware of the fact that swap partition is not always necessary. Today I did a free on my computer and saw 0 swap used.
Can we create a swap partition later on if we realize, that now system gets loaded too much and swap is necessary ??
|
|
|
01-22-2010, 02:35 AM
|
#10
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
Yes you could. If you have 4 GB of ram and are using a 32bit distro, you have as much real ram as address space unless you use a PAE kernel. Many programs and services will use some memory when they are starting up but the memory may not be used again. Memory like that that doesn't used for a long time may get swapped out freeing more real memory for your applications. Also the swap partition is used if you suspend your computer. The rule of thumb I use for over 2 GB of ram is to make the swap partition a bit larger then the amount of ram. Drives are very large now so it shouldn't be missed.
|
|
|
01-22-2010, 07:11 AM
|
#11
|
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
|
I guess my rule of thumb is that if you have decent disk space, you should probably have some swap from the get-go. Yes, you can add a swap partition after install (provided you can re-partition your drive), but it is usually easier to do that at install time. There are a couple of reasons why I didn't put a swap partition on my netbook. First, it has a 16GB drive and I need every last GB of that for software. Second, the 16GB drive is an SSD and I wanted to eliminate as many read/write cycles as possible to preserve the drive life.
Quote:
Originally Posted by jschiwal
Also the swap partition is used if you suspend your computer
|
You're right you do need swap to hibernate your computer (suspend to disk), but I don't think you need it to suspend to RAM.
|
|
|
01-24-2010, 06:54 PM
|
#12
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,444
|
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 10:20 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|