Home > Linux > Felsökning minnesproblem i Linux

Felsökning minnesproblem i Linux

September 3rd, 2010 Leave a comment Go to comments

Use free -t -m to get a summary of the memory usage. Example:

             total       used       free     shared    buffers     cached
Mem:          2026       1817        208          0        404       1035
-/+ buffers/cache:        377       1648
Swap:         2047         17       2030
Total:        4074       1835       2238

The Linux kernel uses as much RAM as possible for caching recently used data and for data buffers to increase overall system performance/responsiveness. Linux will dynamically increase or decrease these pools of memory as needed. In the example above pay attention to the line ‘-/+ buffers/cache: 377 1648‘. This means without buffers and cache you are only using 377MB of ram and have 1648MB free available for programs. If you have swap space defined the Linux kernel will use it if it determines that swapping a sleeping process memory out to disk in favor of additional buffer space or cache would lead to better overall system performance. In the example above you have only 17MB of swap in use. Windows 2000/XP/2003 function similarly but are no where near as aggressive. Windows Vista/7/Server 2008 are more akin to Linux in this respect.

So in this example you could make do with as little as 512MB of RAM with only a slight impact on performance.

OOM errors and mem used by processes

To troubleshoot out of memory problems (OOM), read http://linux-mm.org/OOM

top can be used to see memoty usage, but ‘top’ will not give you enough detail to troubleshoot OOM’s, just give you an indication that something is consuming a lot of memory.

Sorting by memory usage (SHIFT-O n ENTER) will sort the top output by memory usage.

Start top with sudo in Ubuntu/Debian to see processes from all users:

sudo top

You can also use ps to see where the memory is used:

sudo ps aux

You can use cat /proc/meminfo for low-level troubleshooting.

Categories: Linux Tags:
  1. No comments yet.
  1. No trackbacks yet.