Unix: Knowing your memory commands

Memory is one of the most important parts of your Unix system for performance. Let's look at some commands that will tell you what you need to know about how your memory is being used.

By  

Memory is still one of the things that most determines how well your Unix servers will perform. Knowing what commands will tell you what you need to know and what their responses mean will help keep you alert to potential problems and give you something to compare against when and if your system starts to slow down.

free

One of the most basic memory commands available on Linux systems is the free command. Free will report memory usage in kilobytes if you don't tell it otherwise. The command below uses the -m option to convert this to megabytes -- a little easier a format for me to deal with and maybe for you as well.

$ free -m
             total       used       free     shared    buffers     cached
Mem:          2026       1524        502          0        556        584
-/+ buffers/cache:        383       1643
Swap:         4094         40       4054

This system has 2 GB of memory, of which about 75% is in use. It has twice that much swap, but is using almost none of it.

sar

The sar command, deriving from Solaris and sometimes available on Linux systems as well, is a great tool for looking at memory usage over a long period of time. This is especially helpful if you want to see how your systems are performing all week or to compare one day with another.

The sar command is one of the best tools for routine performance reporting. Frequently set up to collect data periodically throughout the week, it can also be used to tell you how performance measurements look right now and those measurements include memory. To get two samples of five seconds each of memory usage, you can use the sar -r 5 2 command as shown below.

$ sar -r 5 2

SunOS boson 5.10 Generic_127127-11 sun4u    07/20/2014

16:26:16 freemem freeswap
16:26:21    5591   733840
16:26:26    5591   733840

Average     5591   733840

The units reported by sar are pages (freemem) and disk blocks (freeswap). To understand what these numbers really mean, you need to determine what these values represent. Fortunately, there are some commands to help you figure this out.

pagesize

We can use the Solaris pagesize command to display the page size -- normally 8192 bytes or 8 KB.

$ pagesize
8192

df -g

For disk blocks, we need to look at the sizing parameters for the particular file system. Here, we see that the block size is also set to 8192 bytes.

$ df -g /
/           (/dev/dsk/c1t0d0s0 ):         8192 block size       1024 frag size
30256454 total blocks  21252254 free blocks 20949690 available 1822912 total files
 1657400 free files     8388632 filesys id
     ufs fstype      0x00000004 flag             255 filename length

Of course, you still need to marry these numbers together -- the block size from the df -g command and the pagesize.

Photo Credit: 

flickr / Steve Jurvetson

https://creativecommons.org/licenses/by-nc-nd/2.0/

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Operating SystemsWhite Papers & Webcasts

See more White Papers | Webcasts

Answers - Powered by ITworld

ITworld Answers helps you solve problems and share expertise. Ask a question or take a crack at answering the new questions below.

Ask a Question