LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-16-2010, 04:00 AM   #1
icekiss
LQ Newbie
 
Registered: Jul 2010
Posts: 1

Rep: Reputation: 0
how to calculate memory available if needed on a linux system?


I have set swappiness to 0:
# sysctl vm.swappiness
vm.swappiness = 0

According to various sources, this should mean that applications have priority over file chaches, and swap should only be used when the applications themselves need more memory than is physically available.
So I naively took the value free provides in the '-/+ buffers/cache' line as 'free' as the amount of memory to be available on the server.
Unfortunately this is not even close to true: On a server with 20GB RAM, memory utilization by this measure never reached 50%, yet the system swaps.
I then figured out that I could use 'sync; echo 3 > /proc/sys/vm/drop_caches' to drop cached stuff.
I was very surprised to still have 12.5 GB cached data after doing that. I am figuring that it's those 12.5 GB which force the system to start swapping.
I also tried to use /proc/meminfo to figure out how that cached memory is used (by comparing its content before and after dropping caches). However, I don't see the correlation between the numbers provided there and what part of the cache can be dropped.
The closest match seems to be the 'Mapped' line, which was 10GB. I am pretty sure that being mmapped keeps the kernel from dropping cache. However, the value is 2.5 GB less than the cache which can't be dropped. So it is not the whole answer.
What I am looking for is some way to determine how much memory the kernel could provide by dropping stuff if he needs to because of memory pressure. Is there maybe a way to simulate drop_caches without actually doing so?

The amount of potentially available memory does not have to be scientifically correct, but the number should at least be always in the right ballpark, which right now, it ain't...
The point here is that it's a productive system. Sy doing stuff like dropping caches or filling memory until the system starts to swap is not a permanent solution to figure out the value.

By the way, it turned out that postgres was the culprit in this concrete case, stopping it made dropping all caches possible, but that does not answer the general question of how to estimate available memory...

Questions:
1. Is my assumption correct that I can subtract 'Mapped' from the freeable cache memory completely?
2. Where could the other 2.5 GB be used?
3. Is there a way to get a better guess of how much memory the system can free if necessary, before swap has to be used?

System: Debian Lenny

Last edited by icekiss; 07-16-2010 at 04:39 AM. Reason: correction meaning of 'Mapped' in meminfo, Questions
 
Old 07-16-2010, 06:52 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
I don't know why some of the things you tried didn't have the expected effects. But I do know those things are unwise and the effects you think you want would actually make performance worse.

Quote:
Originally Posted by icekiss View Post
I have set swappiness to 0
Not a good idea.

Quote:
According to various sources, this should mean that applications have priority over file chaches
No it means the priority of "anonymous" memory over non anonymous is increased.

To grossly oversimplify, anonymous memory is the heap and stack of your applications (writable data) while non anonymous memory is the code plus read only data.

So setting swappiness to zero gives a higher effective memory priority to the writable data of idle and low priority processes than to the code and read only data of active processes. (Process X is stalled waiting for some external request, while process Y is running. Swappiness of 0 means the system should prefer to keep the writable parts of X in memory rather than the read only parts of Y)

When kicked out of memory, anonymous pages must be written to swap and when accessed again must be read back. But read only non anonymous pages can be kicked out of memory just by discarding them and when accessed again read back from their original source (whatever .so file or executable they were originally read from). So kicking out non anonymous data is less total work and preferred. But for best performance that preference should be moderate, not absolute.

Quote:
So I naively took the value free provides in the '-/+ buffers/cache' line as 'free' as the amount of memory to be available on the server.
Roughly true.

Quote:
memory utilization by this measure never reached 50%, yet the system swaps.
That probably means you have services that are idle for long periods (waiting for some external requests that aren't arriving) and best performance is achieved by swapping out the anonymous memory of those services.

Quote:
The amount of potentially available memory does not have to be scientifically correct, but the number should at least be always in the right ballpark, which right now, it ain't.
What is the purpose to knowing that number?

It is much harder to estimate the system's effective need for physical ram used for non anonymous pages. How much file cache memory must be used for decent performance vs. how much more is being used simply because it is there and slightly better to use it for file cache vs. not use it for file cache.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to calculate cpu and memory usage of a process narendra1310 Ubuntu 1 08-30-2008 02:39 AM
Difference between resident memory,shared memory and virtual memory in system monitor mathimca05 Linux - Newbie 1 11-11-2007 04:05 AM
Linux System Administrator Needed! BernardHodes LQ Job Marketplace [Archive] 0 10-18-2007 02:57 PM
calculate system clock in milliseconds bndpatel Linux - General 1 06-14-2005 11:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration