Help! Linux ate my ram!
Posted: Wed Jul 17, 2013 5:32 pm
After using the Raspberry for the purpose of web server, and, in the meantime playing with bash and configuration, I’ve noticed that from time to time my free memory becomes very low, going down to 50MB. This can be a problem, especially when you run several things on your machine. I’ve googled several solutions, such as emptying the buffer cache, or scripts that automatically reboot your Pi but, I suppose, are not that necessary and useless as far as it comes to Pi.
Empty the Linux buffer cache
Linux systems, as most OSes, use buffer cache. Linux is borrowing unused memory for disk caching. This makes it looks like you are low on memory, but you are not! Everything is fine! This is because disk caching makes the system much faster. There are no downsides, except for confusing newbies. It does not take memory away from applications in any way, ever.
If your applications want more memory, they just take back a chunk that the disk cache borrowed. Disk cache can always be given back to applications immediately! You are not low on ram! Disk caching only borrows the ram that applications don’t currently want. If applications want more memory, they just take it back from the disk cache.
How do I stop Linux from doing this?
You can’t disable disk caching. The only reason anyone ever wants to disable disk caching is because they think it takes memory away from their applications, which it doesn’t! Disk cache makes applications load faster and run smoother, but it NEVER EVER takes memory away from them!
Therefore, there’s absolutely no reason to disable it!
Why does top and free say all my ram is used if it isn’t?
This is just a misunderstanding of terms. Both you and Linux agree that memory taken by applications is “used”, while memory that isn’t used for anything is “free”.
But what do you call memory that is both used for something and available for applications?
You would call that “free”, but Linux calls it “used”.
This “something” is what top and free calls “buffers” and “cached”. Since your and Linux’s terminology differs, you think you are low on ram when you’re not.
How do I see how much free ram I really have?
Too see how much ram is free to use for your applications, run free -m and look at the row that says “-/+ buffers/cache” in the column that says “free”. That is your answer in megabytes:
If you don’t know how to read the numbers, you’ll think the ram is 99% full when it’s really just 42%.
Still not convinced? Read more…
http://www.bartbania.com/index.php/help ... te-my-ram/
Empty the Linux buffer cache
Linux systems, as most OSes, use buffer cache. Linux is borrowing unused memory for disk caching. This makes it looks like you are low on memory, but you are not! Everything is fine! This is because disk caching makes the system much faster. There are no downsides, except for confusing newbies. It does not take memory away from applications in any way, ever.
If your applications want more memory, they just take back a chunk that the disk cache borrowed. Disk cache can always be given back to applications immediately! You are not low on ram! Disk caching only borrows the ram that applications don’t currently want. If applications want more memory, they just take it back from the disk cache.
How do I stop Linux from doing this?
You can’t disable disk caching. The only reason anyone ever wants to disable disk caching is because they think it takes memory away from their applications, which it doesn’t! Disk cache makes applications load faster and run smoother, but it NEVER EVER takes memory away from them!
Therefore, there’s absolutely no reason to disable it!
Why does top and free say all my ram is used if it isn’t?
This is just a misunderstanding of terms. Both you and Linux agree that memory taken by applications is “used”, while memory that isn’t used for anything is “free”.
But what do you call memory that is both used for something and available for applications?
You would call that “free”, but Linux calls it “used”.
This “something” is what top and free calls “buffers” and “cached”. Since your and Linux’s terminology differs, you think you are low on ram when you’re not.
How do I see how much free ram I really have?
Too see how much ram is free to use for your applications, run free -m and look at the row that says “-/+ buffers/cache” in the column that says “free”. That is your answer in megabytes:
Code: Select all
$ free -m
total used free shared buffers cached
Mem: 1504 1491 13 0 91 764
-/+ buffers/cache: 635 869
Swap: 2047 6 2041
$Still not convinced? Read more…
http://www.bartbania.com/index.php/help ... te-my-ram/