≡ Menu

FreeBSD find out RAM size including total amount of free and used memory size

Q. How do I find out RAM size / memory size in FreeBSD? How do I display amount of free and used memory in the system?

A. To displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel you need to install special script Most user use sysctal command to get all data. There is a perl script that automates everything and display back result on screen.

This script query the system through the generic sysctl interface. The sysctl utility retrieves kernel state and allows processes with appropriate privilege to set kernel state. You must have perl installed on FreeBSD.

FreeBSD command about RAM size and information

Download perl script which is written by Ralf S. Engelschall:

# fetch http://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
# mv freebsd-memory.pl.txt /usr/local/bin/free
# chmod +x /usr/local/bin/free

Make sure perl is installed. Now to display or list total system memory usage type
$ free
Output:

SYSTEM MEMORY INFORMATION:
mem_wire:          25341952 (     24MB) [  9%] Wired: disabled for paging out
mem_active:  +     47529984 (     45MB) [ 18%] Active: recently referenced
mem_inactive:+     15605760 (     14MB) [  6%] Inactive: recently not referenced
mem_cache:   +        16384 (      0MB) [  0%] Cached: almost avail. for allocation
mem_free:    +    165556224 (    157MB) [ 65%] Free: fully available for allocation
mem_gap_vm:  +       389120 (      0MB) [  0%] Memory gap: UNKNOWN
-------------- ------------ ----------- ------
mem_all:     =    254439424 (    242MB) [100%] Total real memory managed
mem_gap_sys: +      4988928 (      4MB)        Memory gap: Kernel?!
-------------- ------------ -----------
mem_phys:    =    259428352 (    247MB)        Total real memory available
mem_gap_hw:  +      9007104 (      8MB)        Memory gap: Segment Mappings?!
-------------- ------------ -----------
mem_hw:      =    268435456 (    256MB)        Total real memory installed
SYSTEM MEMORY SUMMARY:
mem_used:          87257088 (     83MB) [ 32%] Logically used memory
mem_avail:   +    181178368 (    172MB) [ 67%] Logically available memory
-------------- ------------ ----------- ------
mem_total:   =    268435456 (    256MB) [100%] Logically total memory

Linux like free command for FreeBSD

Freecolor is a free replacement that displays free memory graphically as a bargraph. It supports the same options as free. Install freecolor, enter:
# cd /usr/ports/sysutils/freecolor
# make install clean

To see memory details, enter:
$ freecolor -m -o
Sample output:

             total       used       free     shared    buffers     cached
Mem:          4082        825       3256          0          0        117
Swap:         2048          0       2047

$ freecolor -t -m -o
Sample output:

             total       used       free     shared    buffers     cached
Mem:          4082        825       3256          0          0        117
Swap:         2048          0       2047
Total:        6130 = (     826 (used) +     5421 (free))
Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 16 comments… add one }

  • Scott July 9, 2007, 8:45 am

    same thing as “sysctl -a|grep mem”

    great post though, most users have no idea how to obtain this information in FreeBSD

  • andrei manescu February 4, 2008, 12:13 pm

    Vivek, FreeBSD does not have wget by default. Maybe you should replace wget with fetch.

    It’s visible that you’re more used to Linux :P

  • andrei manescu February 4, 2008, 12:15 pm

    Edited:fetch -o /usr/local/bin/free http://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
    is more useful.

  • andrei manescu February 4, 2008, 12:18 pm

    Edited:
    fetch -o /usr/local/bin/free http://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
    is more useful. Then chmod 755 /usr/local/bin/free

  • nixCraft February 4, 2008, 12:23 pm

    andrei,

    Heh, I do have wget installed but you are right on target about default ftp client. The faq has been updated. I think you still need to run chmod +x free

  • Wirasto S. Karim May 1, 2009, 12:14 pm

    # freecolor -t -m -o
    total used free shared buffers cached
    Mem: 1514 535 978 0 0 1
    Swap: 2048 0 2048
    Total: 4294965248 = ( 3117 (used) + 3028 (free))
    Segmentation fault

    What’s wrong ??

  • Aki June 21, 2009, 2:55 am

    Installing it in Darwin and also in OS X Leopard:

    Illegal division by zero at /usr/local/bin/free line 51.

  • Joe July 10, 2009, 12:42 pm

    for me, the same error appears. any suggestions?

  • Manish October 3, 2009, 2:22 pm

    Hi,

    I have FreeBSD 7.2 AMD 64 bit vserion installed with 8G memory and when I use freecolor command it only displays 4Gig memory instead of 8Gig.

    # dmesg |grep mem
    real memory = 9395240960 (8960 MB)
    avail memory = 8391131136 (8002 MB)

    Is that freecolor command doesn’t support for more that 4G of RAM is installed.

    Thank you
    Manish

    • nixCraft October 3, 2009, 2:32 pm

      It is quite possible that freecolor may have some sort of bug or problem. Send an email to its author and report your problem.

  • jackwade September 3, 2010, 10:18 pm

    perl script url 404’s

  • Stefan Lasiewski January 12, 2012, 8:24 pm

    I tried freecolor, but I get an error:

    # /usr/local/bin/freecolor -m -o
    Bus error: 10
    

    Any idea what that means?

  • dudemonger July 26, 2012, 8:43 pm

    dmesg | egrep -rni “(physmem|avail memory|usable memory)”

  • ub3rst4r April 19, 2014, 6:52 pm

    It seems that freecolor doesn’t work on 64 bit systems:

    [root@ /usr/ports/sysutils/freecolor]# make install clean
    ===> freecolor-0.8.8 is marked as broken: Does not function correctly on !i386.
    *** Error code 1

    Stop.
    make: stopped in /usr/ports/sysutils/freecolor

    • Biker May 26, 2014, 2:33 pm

      Try

      # pkg install freecolor

      ;)

Leave a Comment