Main       Comic       Forums       Anime       Tools       Fun       
Categories
Recent Articles
Recent Posts
Buy DSG Items
The DeadGod Anime Manager
helps you stay up-to-date
on your favorite anime series.
Recent Posts       Popular Articles       Popular Threads       [ View All Recent Posts ]
1. It's not just Japan by DranoK -- 4H 24M ago.
2. Commuting in Japan. by Jeffe -- 14H 31M ago.
3. This cat needs a friend by DranoK -- 1D 4H ago.
4. DeadGod Survival Game - Cycle 12 by DSG -- 2D 0H ago.
 
[ Login | Register ]
 
Viewing 'Free memory on Linux'
Dec
27
Wednesday, December 27th, 2006 (16683 Views)
Intermediate
DranoK
One of the frustrations I deal with on nearly a day-to-day basis is people's misconceptions about how memory is allocated under Linux 2.4 and later.

Listing 1: Tools to report memory usage
* top
* free -m
* cat /proc/meminfo

Let's take a typical example. The "free -m" output below is from a production system that has been running for 80 days.

Listing 2:
             total       used       free     shared    buffers     cached
Mem:          3956       3939         16          0         81       3504
-/+ buffers/cache:        353       3602
Swap:        16378          0      16378

This system has 4GB of physical memory and 16GB of swap. At first glance it looks like 99.57% of the memory is in use. Your first instinct would be to run "top", press capital "M" to sort by memory usage and find out what the hell is taking up so much memory. Doing so will yield no results, however--on this particular system top will show no process taking up more than around 100MB of memory. This can be confirmed with the "ps" command.

So where did all this memory go? The answer lies in the theory of memory management. In particular, the Linux memory management system believes in the following two principles:

1) No matter how much memory is in use, system performance will not be impacted until it is required to use swap space.
2) Unused physical memory is wasted.

Now we can tackle the first line of the "free -m" output.

Listing 3:
             total       used       free     shared    buffers     cached
Mem:          3956       3939         16          0         81       3504

The key lies in the last two columns: buffers and cached. The largest of these is cached. Whenever Linux accesses a file on a filesystem it stores the content of that file in memory. As long as the data doesn't change, subsequent requests for that file will be read from memory instead of physical disk. This vastly improves file access time.

Memory used in such a manner can be freed up almost instantly, thus should really be counted as free memory instead of used. The "-/+ buffers/cache" line of our "free -m" output reflects this.

Listing 4:
             total       used       free     shared    buffers     cached
Mem:          3956       3939         16          0         81       3504
-/+ buffers/cache:        353       3602

Actual used memory here is 353MB. Free memory is 3602MB (Don't add the original 16MB back to this--it's already accounted for). That means over 90% of this system's memory is free and available for use. Quite a bit different than only having 16MB of memory free.

The 3602MB value comes from adding the 3504MB of cache with the 81MB of buffers and 16MB of actual free memory. The 353MB of used memory comes from taking total memory and subtracting the "virtually free" 3602MB value. Note that due to rounding these values may be a bit off.
Permalink - Forum Thread - 11 Comments - Subscribe!Social Bookmark Button



11 Comments -- Post a Comment


504 Days 22 Hours ago, LiQUiD_X said...

Now I'll have something to link people when they get all confused about the output of free -m =)

489 Days 1 Hour ago, highone.gp said...

Thank you ... I've learned Linux on my own and there are many holes in my knowledge...

This most certainly comes in handy

488 Days 23 Hours ago, DranoK said...

Glad to help out :) If you have any specific questions I'd be more than happy to consider them for another article..

101 Days 16 Hours ago, Ashik said...

Great.... its asumm.. many of the ppl doesnt know this..
Thanks. a lot..

89 Days 2 Hours ago, Rishi said...

I'm sure many of Linux professional are not aware of this.

Great article !!

80 Days 8 Hours ago, Immubus said...

I Just installed Ubuntu and tried to get steam working under the gutsy build with wine and no luck :(

79 Days 22 Hours ago, DranoK said...

Chances are no DirectX app will work with Wine, even the commercial CodeWeaver one.

79 Days 16 Hours ago, LiQUiD_X said...

Nope. OpenGL ones do though.

78 Days 23 Hours ago, Ratha said...

By steam do you mean the steam platform itself, or the half-life games?

Would be nice to see Direct X become more widely compatible with different operating systems, but i suspect its one of the keystones in the Microsoft foundations which keep people and game developers closely linked to the windows platform. I think the move pushing DX10 to be a vista-only solution was a bad move on Microsoft's part since vista seemed to be rushed out long before it was really ready for the market. Im really hoping to see some sort of XP integration in the future but thats an unlikely long shot.

78 Days 22 Hours ago, DranoK said...

Microsoft had a golden chance to not only dominate PC gaming, but to become the backbone of a massive growth potential. More than that, they had the opportunity to completely destroy Sony and Nintendo. All they had to do was create native compilers for DX10 that would translate it to hardware architectures.

Instead they make it Vista-only. Which, really, is the exact opposite of what they should have done.

Sadly, the Microsoft marketing genius we feared and respected in the late '90s is no more =/

78 Days 8 Hours ago, Rishi kapur said...

Was not aware of that! Thanks for opening my eyes.

RHCE


Post a Comment
Name (Required)
Register an account to gain access to all the great features of DeadGod.Net! It's fast, and free. Register now!

You may use BBCode in your post.


Older Articles
 
 
DeadGod.Net - Cute Evil Atheists
Encouraging critical thought and general enjoyment since 2001.
Want to join our community? Have suggestions or comments?
Contact Us or Visit our forums.