- May 31, 2001
- 10,027
- 1
- 81
On one of the linux servers at work, After a while there appears to be quite a bit of memory being used. After killing all the applications, is there a way to release any inused ram?
Originally posted by: drag
Do you think you have memory leaks or something?
If so then restarting the application should get rid of them temporarially.
Ofter ram will get 'used' as cache for file system. This helps speed things up as disks are the slowest part of the computer and avoiding disk access when ever possible usually causes a nice performance increase.
But in Linux telling what memory is doing can be confusing.
Originally posted by: Nothinman
If the 'cached' column in 'free' output is really high that's where your memory is and it's essentially free, that's the filesystem cache and it'll be reused as necessary. If you want to flush the filesystem cache, and you probably don't want to, you can 'echo 3 > /proc/sys/vm/drop_caches' if your kernel is new enough. But as I said, you probably don't want to do that since it'll just cause all of the stuff that really is in use to be paged back in so your disks will go crazy if the box is actually doing something.
It's kind of funny how there's a lot of threads where people buy 2 gigs of ram and only want their OS to ever use 512 MB
Originally posted by: drag
Originally posted by: Nothinman
If the 'cached' column in 'free' output is really high that's where your memory is and it's essentially free, that's the filesystem cache and it'll be reused as necessary. If you want to flush the filesystem cache, and you probably don't want to, you can 'echo 3 > /proc/sys/vm/drop_caches' if your kernel is new enough. But as I said, you probably don't want to do that since it'll just cause all of the stuff that really is in use to be paged back in so your disks will go crazy if the box is actually doing something.
There was a nice article on doing stuff like that I just remembered. Pretty new.
http://aplawrence.com/Linux/buffer_cache.html
It's kind of funny how there's a lot of threads where people buy 2 gigs of ram and only want their OS to ever use 512 MB
Well it makes sense. The purpose of a OS is to run the applications. So this means that the OS needs to be as light weight as possible (while retaining the sophistication needed for stability and performance) to make the most efficient use of the computer to drive the application.
Doesn't help also that each application and each place you look at in Linux will give you a different statistic on 'memory usage'.
There was a nice article on doing stuff like that I just remembered. Pretty new.
http://aplawrence.com/Linux/buffer_cache.html
Originally posted by: Nothinman
There was a nice article on doing stuff like that I just remembered. Pretty new.
http://aplawrence.com/Linux/buffer_cache.html
Although sadly the guy doesn't seem to have any clue as to how the drop_caches stuff is implemented, he even lists his failed attempts to corrupt a file and can't figure out why it didn't work. It only takes a minute to open up fs/drop_caches.c see that the drop_pagecache function eventually calls invalidate_mapping_pages which has a huge comment at the top that says "It will not invalidate pages which are dirty, locked, under writeback or mapped into pagetables." so there's no need to call sync before touching it.
Ah even better is that the site that he links to linux.inet.hr as a reference for the drop_caches information specifically says that it'll only drop clean pages.
And he keeps referring to the caching as the buffer cache which is seperate from the page cache in Linux and is rarely used these days.