Memory, Swap Management October 7, 2005
Posted by Carthik in commands, ubuntu.trackback
A lot of Linux newbies, myself included are often astonished at the amount (%) of memory used by Linux as opposed to, say, Windows on comparable systems. If you look at the System Monitor (Applications -> System Tools -> System Monitor), you can find the amount of memory used by your system. If you leave your computer on for a long period (say more than a day) then the memory usage seems to keep going up. This is a “good thing”. Let me explain why.
Linux actively uses free available memory to improve your system’s performance. Let’s say you have 1 GB of main memory (don’t we all wish!). Now, suppose all the programs you are running together require only 200 MB of memory. What happens to the other 800 MB of the available memory?
On a linux system, the memory is used to “cache” data that is used by the CPU. The idea behind caching is that it takes longer for your CPU to access data on the hard drive than it does to access data that is present in the main memory. So caching using the main memory effectively speeds up the system. On a windows system, there is no such optimization, so free memory is wasted as it does not get used.
Now when an application really needs all the memory that is used for caching, Linux pops out the cached data and makes the required memory available. As a last option, if all of the main memory is used up, then the memory you set aside in your swap partition is used too.
Try the command:
$free -m
to see what your memory usage is. The first line of results is fairly obvious. The second line tells you what the applications “see”, and should tell you how much memory is actually being used by the applications themselves.
Another used command is “top” which gives you a look at the memory/cpu usage and other details about the processes that are running on your computer – all at the terminal. I much prefer it to the GUI-based System Monitor myself.
Knowing that all the memory I paid for is being used to the max makes me feel all warm and fuzzy. For a moment earlier today, I thought there was something wrong, since almost all of my memory was being used, and I was hardly running anything intensive – now I am at ease – there was something wrong earlier, when the memory was not being used by Windows – now I know!!
Windows does do caching, just not as aggressively or efficiently as Linux.
Also, I would reccommend using “htop” over plain old “top”. Especially for anyone new to Linux. htop is much easier to read and use, and it doesn’t have the intimidating information density of top.
What happens when the SWAP used reaches maximum , say for example 100% of 2gb.. is it possible to clear/reset the swap disk to 0%.
Dr Y P Gogia
that’s the problem. I also get a full swap! And I don’t care if linux uses all my memory, but the system gets slower and slower.
and then, there are the memory leaks. i’m only having 250 mb of ram and running quite a lot of proggies at the same time. some applications then tend to accuire more and more memory. like firefox or amule. at one point amule was using over 600 mb of ram /swap and with the other applications running my memory was completely packed. then some chrone job kicked in on top of it. it virtually took minutes to get into a shell and i couldn’t help myself but to reboot the machine…
(and i thought these times are over…)
cheers
Hi, just thought I would mention that you could use [free] that tells you how much ram you have free, but also, of the ram used, how much is file caching and how much is actual usage.
yeah i think i made the stupid mistake of making my swap partition only 500mb…..it does seem a bit slower than before…when i had a larger swap partition…i think it was around 800-1000mb.
Hi, I had an old 9gb hard drive hanging about that I thought I may as well plop in as a swap disk. I use memory intensive Matlab codes so it would be handy. The problem is that after formating with xubuntu’s admin disk tol the system does not recognise the new space space. Also now I cannot change any of the properties of drive, although it is correctly detected. Umm, any help would be gretly appreciated.
I am too looking for a way to clean of swap usage. It is up on a constant 96-98% after 6 days of active usage.
I remember from my Windows era that the swapsize-column in taskman per process was very useful for finding programs hogging swapspace and thus a lot of memory.
PS Ryan: Here is all help you need: http://www.ubuntuforums.org
Yeah, I want to know how to coalesce wap useage. My system is Linux AS4.0 and I running Oracle database 9iR2 on it. As it’s up for week, it use all RAM and Swap. I shut database down to regain RAM free space but swap.
Can anyone tell me how? I very appreciate that.
[…] appears to be caching to buggery. It turns out to be the kernel. The trick here is to interpret the second line, which tells you what programs “see” […]
This post has helped explain things to me a bit better, I’d been wondering about this since switching from windows. Cheers!
hi, i see everybody wants to reduce their use of swap, but i have just the opposite problem: at ubuntu the system doesnt use any swap memory, it is like there were no swap partition, but there is. i dont know how to turn on or find this partition and activate the swap, because i have 256 ram and without the swap the pc goes slow. I know that because one time the swap appear activated in the system monitor, and ubuntu ran better than ever. Please somebody can help me … thanks
hi yall,
to mount swap:
first know what your swap disk is called(sda1,sda2,hdc1,etc…)
then
swapon -v /dev/yourswap (the -v adds verbose option)
swap will be mounted till you reboot.
to have swap mount on boot, edit your /etc/fstab (with caution,back it up first)
example:
#
proc /proc proc defaults 0 0
/dev/sda1 / ext3 defaults,errors=remount-ro,noatime,data=writeback 0 1
/dev/sda2 none swap sw 0 0
sda2 is my swap
you may also be having a vm.swappiness issue. to temporarily change your swappiness, first:
cat /proc/sys/vm/swappiness (to find out your swappiness)
then:
sysctl -w vm.swappiness=100 (100 is best for less ram)
to change permanantly, do:
vim /etc/sysctl.conf (change vim to your default editor) and add this new line to the end:
vm.swappiness=100
hello team
how to test if there is any memory leaks on server
thanks & reguard
chetanM
Hi
i can agree to some point but what if i close an application, should not the memory in use go back since less applications in use ???
now when i start an new application the computer is darn slow …
linux may be the 2nd coming, but whenever my PC comes out of hibernation, all the apps are painfully slow for 10min of usage. At least ‘dumb’ windows can bring stuff out of swap quickly.
With vista comes Superfetch, a very efficient memory caching service. It monitors the user’s activities for some time and based on that fills the memory with what it believes the user’s general requiement will be. Nice thing to do but needs a large RAM (2 GB) to funtion well.
Linux is using my swap very miserly (compared to kernel in Windows). It seems to me that after enabling certain compiz effects the system becomes sluggish. Even more so if you left the computer on for a long time.
BOTTOM LINE: I believe Windows user the memory in a better way.
At present the system is using 60.6% of physiacl RAM and 0.00% of SWAP.
RAM = 1 GB
SWAP = 512 MB (I reduced its size from 1 GB to 512 MB when I saw that none or little of of it was being used anyway)
can some1 tell me a good detail about Linux Ubuntu memory management cuz i need it for a project asap. thatnks..
While preparing to resize the swap partition, I have accidentally discovered how to clean/free Linux swap: deactivate the swap partition in GParted, and reactivating it just after.
Simple and effective. 😀
swapoff -a and then swapon -a
what is the file system for ubuntu ,resource management, memory management and concurrent?
Hi…all
I have some queries.
1. Can the normal Memory Module be used as a cache memory, means not the unused RAM,…the whole RAM..can it be made to work like a cache memory all through?
2. Is it possible to dump the content of the cache memory to any disk, or any storage device for future retrieval, as when power is off content of cache memory gets lost and it has to be reloaded from beginning? If there is any way…..plz explain………..
3. How to expand the size of a L2 cache?
Please HELP!!!!!!!!!
thanks in advance
Debasmita
It only makes sense to cache a slower memory in a faster one. So regular RAM may be used as cache to the disk, but it still orders of magnitude slower than internal processor memory (L1 or even L2), which it cannot be a cache for, but instead be cached in.
See: http://en.wikipedia.org/wiki/Cache
Windows does do caching, just not as aggressively or efficiently as Linux.
Also, I would reccommend using “htop” over plain old “top”. Especially for anyone new to Linux. htop is much easier to read and use, and it doesn’t have the intimidating information density of top.
what is the file system for ubuntu ,resource management, memory management and concurrent?
[…] https://embraceubuntu.com/2005/10/07/memory-swap-management/ […]
At first you should have thought of having a much bigger swap size. I have 4GB size of ram and as suggested that I should have twice the size of my ram as swap space. Now it’s even barely used.
“ulimit” is the solution .
antalya ev ilaçlama
yuz buyk gelsın çocuk gelmesınn
Nice blog here! Also your website loads up very fast!
What web host are you using? Can I get your affliate link to your host?
I wish my site loaded up as fast as yours lol
hmmm
Lmao just lmao
http://Cristinen2026456.Wikidot.com
Memory, Swap Management | Ubuntu Blog