Subject: Re: Reporting free memory: vmstat output hard to read
To: B. James Phillippe spamblock <bryan-spamtrap1@darkforest.org>
From: Jeremy C. Reed <reed@reedmedia.net>
List: netbsd-users
Date: 04/23/2002 12:58:31
On Tue, 23 Apr 2002, B. James Phillippe spamblock wrote:

> method, if one exists.  When I run vmstat I don't see swap listed
> separately (BTW the memory numbers are listed with no white-space between
> them (I have 512MB phys) so it's difficult to read).

Use "vmstat -s".

"swap pages" * "bytes per page" / 1024 = swap in bytes

> What I'm looking for is something like the "free" command in Linux.

rainier:~$ ./scripts/free.sh
             total       used       free    buffers
Mem:        126072     125332        740          0
Swap:       197564     197564          0

I've been using this script mostly from Simon Burge (posted to
current-users) since Nov, 2000.

#!/bin/sh

# based on:
#Date: Thu, 30 Nov 2000 19:49:01 +1100
#From: Simon Burge <simonb@wasabisystems.com>

vmstat -s | awk '
/ bytes per page$/ { bpp = $1 }
/ pages managed$/ { totalmem = $1 }
/ pages free$/ { free = $1 }
/ vnode data pages$/ { vbuffer = $1 }
/ swap pages$/ { totalswap = $1 }
/ swap pages in use$/ { swapused = $1 }
END {
        printf("%18s %10s %10s %10s\n", "total", "used", "free", "buffers");

        printf("Mem:    %10d %10d %10d %10d\n", totalmem * bpp / 1024,
            (totalmem - free) * bpp / 1024, free * bpp / 1024,
            vbuffer * bpp / 1024);

        printf("Swap:   %10d %10d %10d\n", totalswap * bpp / 1024,
            swapused * bpp / 1024, (totalswap - swapused) * bpp / 1024);
}'

I'll submit this as a package. I placed it on my "live" cd as
/usr/local/bin/free.

   Jeremy C. Reed
   http://www.reedmedia.net/