Our computers have more memory than they’ve ever had. Chances are good that this is true no matter when you’re reading this. That said, no matter how much memory you have, it never seems to be quite enough.
You can pack your computer or server full of all the RAM it will take, and something will always find a use for it. Most of the time this is a good thing. After all, what is the point of all that RAM if you don’t use it? On the other hand, if you’re limited, running out of memory can be a problem.
Are You Sure About Your Memory Usage?
Before you start looking to free up memory, you want to make sure that something is actually using it. Because of the way Linux handles memory, it just might seem like something is using all of your available memory.
As Linux Ate My RAM explains, the
top command showing that you’re low on memory may not mean what you think it means. By default, Linux sets aside otherwise unused memory for disk caching, which actually helps speed up your computer.
That said, there could be some problematic services or applications that are actually using more RAM than they should be.
Diagnosing Memory Usage
To diagnose your memory, you’ll need to use a few different commands. The
top command is good for looking at any applications that may be eating up too much RAM – just don’t rely solely on the PhysMem stat showing at the top.
You can use the
ps commands to help diagnose any RAM issues, too. To use
free, just run the following:
You’ll notice that the “total” and “used” figures will be similar. As we mentioned above, this is normal behavior for Linux, so don’t worry about this. The most important thing to pay attention to is the “used” section in the “buffers/cached” row, as this is what applications and services are actually using.
You can use
ps similarly to
top to determine which applications are using the most memory. To this, simply run the following:
This will show you which apps are using the most memory and show you their process IDs.
Fixing Your High Memory Usage
There are a few common culprits when it comes to high memory usage on Linux. One of the main offenders is Java. Whether you’re using the official Java runtime environment or the GNU-supplied alternative, this can cause you trouble. If you’re running into this on a server, it could be caused by JBoss or Tomcat. You’ll find their configuration files somewhere like the following:
Other culprits can be Apache or MySQL. It’s beyond the scope of this article to show you exactly how to configure these, but you can check your log files for errors or warnings from these services.
If you’re looking for performance gains or to fix an issue, memory may not always be the culprit. It depends on what you’re looking for, but your solution could lie in another part of the computer entirely. Make sure you keep this in mind.
Don’t worry, as no matter what the trouble is, we can help you out. If your desktop, laptop, or server is running slow, take a look at our guide to finding the cause. Even if it doesn’t solve your problem, it will likely help you find where to start.
Our latest tutorials delivered straight to your inbox