no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | linux_memory_and_processes [2012/02/08 20:31] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Linux Memory and Processes ====== | ||
+ | |||
+ | * [[Apache Tuning]] | ||
+ | * [[htop]] | ||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | Use '' | ||
+ | |||
+ | Display memory usage in MB: | ||
+ | |||
+ | < | ||
+ | free -m | ||
+ | </ | ||
+ | |||
+ | Sample output: | ||
+ | |||
+ | < | ||
+ | | ||
+ | Mem: 3952 | ||
+ | -/+ buffers/ | ||
+ | Swap: 517 256 261 | ||
+ | </ | ||
+ | |||
+ | The total memory available to the OS is the '' | ||
+ | |||
+ | The top row '' | ||
+ | |||
+ | The actual memory being used is in the '' | ||
+ | |||
+ | Determining swap usage is the same as before. | ||
+ | |||
+ | === Finding how much memory a process is using === | ||
+ | |||
+ | This is especially helpful for tuning system daemons that can modify their memory usage, such as MySQL and Apache. | ||
+ | |||
+ | First, display just the processes for one program, and sort them by memory usage (rss) in order from lowest to highest thread. | ||
+ | |||
+ | < | ||
+ | ps a -ylC httpd --sort rss | ||
+ | </ | ||
+ | |||
+ | Next, we only need the RSS column: | ||
+ | |||
+ | < | ||
+ | ps a -ylC httpd --sort rss | awk ' | ||
+ | </ | ||
+ | |||
+ | This still displays the memory usage for all the processes, and in the case of Apache, all the threads. | ||
+ | |||
+ | < | ||
+ | ps a -ylC httpd --sort rss | awk ' | ||
+ | </ | ||
+ | |||
+ | An example output would be '' | ||
+ | |||
+ | < | ||
+ | htop -u apache --sort-key M_RESIDENT | ||
+ | </ | ||
+ | |||
+ | Or, you can use top, though it is not sorted. | ||
+ | |||
+ | < | ||
+ | top -u apache -n 1 | ||
+ | </ | ||
+ | |||
+ | Divide that number by 1024 to determine the amount of memory used in MB. | ||
+ | |||
+ | < | ||
+ | echo 22596/1024 | bc | ||
+ | 22 | ||
+ | </ | ||
+ | |||
+ | So, the thread using the most memory is taking 22 MB. | ||
+ | |||
+ | |||
+ | |||