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 or package. Most FreeBSD user use the sysctal command to get all data. There is a perl script that automates everything and display back result on screen.
Use sysctl command to find out how much RAM is installed on a FreeBSD
Type the following command:
$ sysctl hw.physmem
$ sysctl hw | egrep 'hw.(phys|user|real)'
OR
$ grep memory /var/run/dmesg.boot
Sample outputs:
Fig.01: FreeBSD Command To Find How Much RAM is Installed On a Server
FreeBSD command about RAM size and information
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. First, download a Perl script which is written by Ralf S. Engelschall:
$ fetch http://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
$ sudo mv freebsd-memory.pl.txt /usr/local/bin/free
$ sudo chmod +x /usr/local/bin/free
Make sure perl is installed on your system (which perl). To display or list total system memory usage type:
$ free
Sample outputs:
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
You can avoid Perl based code and use standard sh shell to get same info using freebsd-memory.sh script:
$ fetch https://raw.githubusercontent.com/ocochard/myscripts/master/FreeBSD/freebsd-memory.sh
## or use curl command ##
## $ curl -O https://raw.githubusercontent.com/ocochard/myscripts/master/FreeBSD/freebsd-memory.sh
$ sh freebsd-memory.sh
Sample outputs from my FreeBSD based home router:
SYSTEM MEMORY INFORMATION: mem_wire: 70152192 ( 66MB) [ 14%] Wired: disabled for paging out mem_active: + 44515328 ( 42MB) [ 9%] Active: recently referenced mem_inactive:+ 333316096 ( 317MB) [ 67%] Inactive: recently not referenced mem_cache: + 798720 ( 0MB) [ 0%] Cached: almost avail. for allocation mem_free: + 44724224 ( 42MB) [ 9%] Free: fully available for allocation mem_gap_vm: + -45056 ( 0MB) [ 0%] Memory gap: UNKNOWN ______________ ____________ ___________ ______ mem_all: = 493461504 ( 470MB) [100%] Total real memory managed mem_gap_sys: + 9297920 ( 8MB) Memory gap: Kernel?! ______________ ____________ ___________ mem_phys: = 502759424 ( 479MB) Total real memory available mem_gap_hw: + 34111488 ( 32MB) Memory gap: Segment Mappings?! ______________ ____________ ___________ mem_hw: = 536870912 ( 512MB) Total real memory installed SYSTEM MEMORY SUMMARY: mem_used: 158031872 ( 150MB) [ 29%] Logically used memory mem_avail: + 378839040 ( 361MB) [ 70%] Logically available memory ______________ ____________ __________ _______ mem_total: = 536870912 ( 512MB) [100%] Logically total memory
Linux like free command for my FreeBSD server
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
OR
# pkg install freecolor
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))
The options are as follows:
-b Display the amount of memory in bytes. -k Display the amount of memory in kilobytes. This is the default. -m Display the amount of memory in megabytes. -o Display the output in old format, the only difference being this option will disable the display of the "buffer adjusted" line. -s Continuously display the result delay seconds apart. You may actually specify any floating point number for delay, usleep(3) is used for microsecond resolution delay times. -t Display a line showing the column totals. -V Display version information.
Here is a sample demo from my server:
Use top command
The top display and update information about the top cpu processes including "Physical Memory Stats" as follows (from top(1) man page):
- Active: number of bytes active.
- Inact: number of bytes inactive.
- Wired: number of bytes wired down, including BIO-level cached file data pages.
- Cache: number of clean bytes caching data that are available for immediate reallocation.
- Buf: number of bytes used for BIO-level disk caching.
- Free: number of bytes free.
$ top
Sample outputs:
Fig.02 See memory usage using the top command.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 20 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
same thing as “sysctl -a|grep mem”
great post though, most users have no idea how to obtain this information in FreeBSD
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
Edited:fetch -o /usr/local/bin/free https://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
is more useful.
Edited:
fetch -o /usr/local/bin/free https://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
is more useful. Then chmod 755 /usr/local/bin/free
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
# 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 ??
Try upgrading port and base system. If it is not fixed, try these suggestions.
Installing it in Darwin and also in OS X Leopard:
Illegal division by zero at /usr/local/bin/free line 51.
for me, the same error appears. any suggestions?
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
It is quite possible that freecolor may have some sort of bug or problem. Send an email to its author and report your problem.
perl script url 404’s
I tried freecolor, but I get an error:
Any idea what that means?
dmesg | egrep -rni “(physmem|avail memory|usable memory)”
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
Try
# pkg install freecolor
;)
freebsd-memory.pl converted into bin/sh (no more perl dependency).
Awesome. The faq has been updated to include your script.
Just curious – how did you record the animated gif (with the timer in the corner)?
Nice tutorial, I have the same question, how did you record the animated gif ?
Thanks!