{question}
How do I address out of/high memory usage?
{question}
{answer}
If your system runs out of memory, it will work less efficiently. Moreover, applications running on such systems will run into performance issues. This is because they start using disk for "memory swapping", disks have much slower Read/Write speeds. While running out of memory for a short time is acceptable in some cases, if your swap memory is disabled or becomes full, your system will be critically low on memory, and your operating system may start killing other non-os related processes to free up memory, thus effecting the running applications on your system.
Checking for Memory usage:
There are tools installed by default on Linux operating systems that would allow you to check for memory usage such as free, top, and ps:
1. Top
Some of the important information displayed by the top tool:
PID: The unique process id of the corresponding task.
%MEM: Memory usage of the corresponding task.
2. Free
Some of the important information displayed by the free command:
total: Total amount of memory that can be used.
free: Amount of free/unused memory.
used: Used memory.
avail Mem: An estimate of the amount of memory that is available.
3. ps
The following ps command will show you the top 10 processes that are using the most memory in descending order :
ps aux --sort=-%mem | head
Some of the important information displayed by the above ps command:
PID: The unique process id of the corresponding task.
%MEM: Memory usage consumed by the process.
When should I start to worry?
While running out of memory for a short time is acceptable in some cases, a genuine low memory situation that you may want to look into:
- When available memory is close to 0.
- The amount of swap used increases.
- You start seeing Out of Memory Killer in the kernel messages.
More information on Out of Memory Killer messages and how to check for them here.
Fixing Your High Memory Usage:
If you're continually running into out of/high memory usage, consider the following options:
- Increase your system's physical memory.
- Identify nonessential processes/applications using large amounts of memory and limit their memory usage.
- Create/Increase Swap space on your system; more on this here.
{answer}