- How to check RAM size?
- How to find total physical memory (RAM) size on Linux?
- Using free Command
- Command
- Output
- Command
- Output
- Using vmstat Command
- Command
- Output
- Command
- Output
- Command
- Output
- Using top Command
- Command
- Output
- dmidecode Utility
- Installing dmidecode
- Using dmidecode Utility
- Command
- Output
- Using /proc/meminfo Virtual File
- Command
- Output
- Command
- Output
- Conclusion
- how to determine the available physical memory in linux
- 5 Answers 5
- get available memory in gb using single bash shell command
- 6 Answers 6
How to check RAM size?
-m , —mebi Display the amount of memory in mebibytes.
—mega Display the amount of memory in megabytes. Implies —si .
free -h will output it in human-readable output (usually GiB: Gibibytes—base 1024). But, since RAM is usually sold in GB (Gigabytes—base 1000), NOT GiB (Gibibytes), free -h —si is usually better, as @Jollywatt says, to output it in Gigabytes instead.
Open a terminal ( CTRL + ALT + T ).
Run following command to see RAM information in KB (1 KB is equal to 1024 bytes).
Run following command to see RAM information in MB (1 MB is equal to 1024 KB).
Run following command to see RAM information in GB (1 GB is equal to 1024 MB).
Or you can run following command to see more information about the same:
free -h seems most helpful to me. «all output fields automatically scaled to shortest three digit unit»
Click on the power/gear icon (System Menu) in the top right corner of the screen and choose About This Computer. You will see the total available memory in GiB. Multiply the value by 1024 to get the size in MiB.
This value (and the value shown as Total in output of free -m on the console), is total physical RAM size, minus the amount assigned to the internal GPU, if your computer has one.
To see the total amount of physical RAM installed, you can run sudo lshw -c memory which will show you each individual bank of RAM you have installed, as well as the total size for the System Memory. This will likely presented as GiB value, which you can again multiply by 1024 to get the MiB value.
How to find total physical memory (RAM) size on Linux?
We can often get away without checking for total memory usage on servers running Linux. However, sometimes we may want to know the total memory available on our servers. Luckily, there are various ways to accomplish this task. In this tutorial, I’ll show you some of them.
Using free Command
free is the simplest among the various commands we’ll encounter. It’s used to display the current amount of physical and virtual RAM (RAM) being utilized by your system. By default, it outputs to standard out. You can run the free utility without any flags to get an idea about how much RAM is currently being used by your system.
Command
Output
total used free shared buff/cache available Mem: 8021048 1320432 5689744 335556 1010872 6121932 Swap: 0 0 0
We can use the -h or —human flag to display the output in a human readable format.
Command
Output
total used free shared buff/cache available Mem: 7.6Gi 1.3Gi 5.4Gi 318Mi 985Mi 5.8Gi Swap: 0B 0B 0B
We have a total of 7,600 GB of RAM. There are many other options that can be useful for printing the results in the format we want them printed. One more interesting one is the -k (kilobyte) and -M (megabyte) options.
The -s flag means “seconds”, so free will print out the RAM use every five seconds in this example. You can stop the program by pressing Ctrl+C.
Using vmstat Command
When we run the vmstat program, it will print out the free, buffed, and cached memory alongside the swapspace, CPU, IO,and sys info.
Command
Output
--procs-- -----------------------memory---------------------- ---swap-- ----- io---- -system-- --------cpu-------- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 5352900 56816 1053708 0 0 162 73 328 1087 18 4 78 0 0
We’re interested in the total memory usage so we need to use the -s (statistics) flag.
Command
Output
8021048 K total memory 1564516 K used memory 305336 K active memory 1962636 K inactive memory 5391588 K free memory 58224 K buffer memory 1006720 K swap cache 0 K total swap 0 K used swap 0 K free swap 76393 non-nice user cpu ticks 5 nice user cpu ticks 14122 system cpu ticks 337834 idle cpu ticks 1790 IO-wait cpu ticks 1463 IRQ cpu ticks 614 softirq cpu ticks 0 stolen cpu ticks 617253 pages paged in 310410 pages paged out 0 pages swapped in 0 pages swapped out 1426200 interrupts 4722588 CPU context switches 1625563254 boot time 1949 forks
The first line in the output contains the total number of bytes of physical memory available. We can get rid of everything except for the first line by using grep.
Command
$ vmstat -s | grep -i 'total memory' | sed 's/ *//'
Output
Using top Command
Top is a tool that displays various statistics about your computer’s resources. You can run it via the terminal (on Linux) or through the Windows GUI. To start it, type «top» into the terminal window.
Command
Output
top - 15:18:13 up 57 min, 1 user, load average: 3.40, 3.26, 2.04 Tasks: 138 total, 1 running, 137 sleeping, 0 stopped, 0 zombie %Cpu(s): 17.2 us, 3.6 sy, 0.0 ni, 77.5 id, 0.3 wa, 0.9 hi, 0.5 si, 0.0 st MiB Mem : 7833.1 total, 4665.9 free, 1782.3 used, 1384.8 buff/cache top - 15:18:49 up 57 min, 1 user, load average: 2.61, 3.08, 2.03 Tasks: 138 total, 1 running, 137 sleeping, 0 stopped, 0 zombie top - 15:18:58 up 58 min, 1 user, load average: 2.45, 3.02, 2.02 MiB Swap: 0.0 total, 0.0 free, 0.0 used. 5324.5 avail Mem
At the top, you can see the system information for the computer. You can see that there is a total of 7833 MB of RAM installed.
dmidecode Utility
dmidecod is a utility that prints out useful info about your computer hardware. It extracts the relevant info from the DMI table (a part of the UEFI firmware). You can also use it to get some interesting info about your system such as its maximum supported RAM size.
Installing dmidecode
On some Linux distros, dmidecke isn’t installed by default, so we’re going to need to download and compile it first. We can get dmidecke from our distribution repository using an apt-get command.
To install the software for Ubuntu-based distros, we can use the command line tool «apt» −
To install Red Hat Enterprise Linux (RHEL), Fedora, or CentOS, we can use YUM −
On Arch-derived distros, just type ‘pacman’ −
Using dmidecode Utility
After installing the package, we can run the `dmidecode` commands from our terminal.
To get access to the full list of available commands, we need to have root permissions. Once we run the dmidecode command, we’re going to be able to view detailed info about our system. However, we’re only concerned with one piece of info — the total amount of RAM installed on our computer.
We can use the -t type argument to specify which component we want to check. For example, if we wanted to see temperature readings from our CPU, we would run dmidecode -t 4.
We’re interested in looking at the memory DMI types, which can be found by using the numbers 5, 6,16,17,18,19,20,21,22. However, we’re interested in the one numbered 19, which will show us the RAM devices that are connected to the slots on our motherboards.
Command
Output
Getting SMBIOS data from sysfs. SMBIOS 3.0.0 present. Handle 0x0049, DMI type 19, 31 bytes Memory Array Mapped Address Starting Address: 0x00000000000 Ending Address: 0x001FFFFFFFF Range Size: 8 GB Physical Array Handle: 0x0044 Partition Width: 1
We only have a single RAM module with 8 GB of total memory capacity available in one of the RAM sockets.
Using /proc/meminfo Virtual File
The /proc folder is a special type of file system that contains virtual information about your computer. You can view these virtual folders through the command line, but you cannot modify them directly. They do not physically exist on your hard drive, so you cannot delete them or create new ones. However, you can open them and see what they contain. To get into the /proc folder, you must enter the following command: sudo su -c “cd /proc/”
Inside the /proc directory there is a special virtual folder called meminfofile which can be opened by typing cat into the terminal. It has information about our physical memory. Let’s open it using cat −
To illustrate the use of the “read” utility, let’s look at an example where we want to know the total RAM size of our system. First, we need to run the following commands −
Command
$ cat /proc/meminfo | head -n 3
Output
MemTotal: 8021048 kB MemFree: 4542960 kB MemAvailable: 5155668 kB
We’ve printed only the lines that interest us by specifying the line count (-n) with the help of the ‘he’ (or ‘header’) option. The sizes are printed out in kilobytes and will give us an idea of how much space we’re currently taking up.
Suppose we’re trying to write a bash script where we need to read the physical RAM from the /proc/memfile file and then use grep to get the total memory.
#!/bin/bash total_ram () < local totalram=$(cat /proc/meminfo | grep -i 'memtotal' | grep -o '[[:digit:]]*') echo $totalram >ram_size=$(total_ram) echo "Total RAM: $ram_size kB"
Next, we’ll save our script and make it executable.
Command
$ chmod +755 totalram.sh $ ./totalram.sh
Output
Conclusion
We looked at different command line options and tools that can help determine the physical RAM size of our Linux systems.
We discussed the minimal free space and its alternative vmstats commands. Then we examined the top program to see various system information. We then looked at the dmidescribe utility and how we can get the physical memory information from its DMI tables.
Afterwards, we learned what the /proc directory is and how we could read the mem info file to see if there was any memory available. We then learned about two graphical tools that we could use to monitor our system’s resources.
how to determine the available physical memory in linux
I’m trying to figure if my software running on linux suffers from memory leak . I’ve tried to measure the available physical memory as found in /proc/meminfo (see below) but could understand which field(s) represents the available memory and what is the relation between MemFree, Cached, Buffers, Active, Inactive .
cat /proc/meminfo MemTotal: 124128 kB MemFree: 62872 kB Buffers: 0 kB Cached: 15624 kB SwapCached: 0 kB Active: 38724 kB Inactive: 11148 kB SwapTotal: 0 kB SwapFree: 0 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 34272 kB Mapped: 14640 kB Slab: 5564 kB SReclaimable: 424 kB SUnreclaim: 5140 kB PageTables: 504 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 62064 kB Committed_AS: 57936 kB VmallocTotal: 655360 kB VmallocUsed: 1016 kB VmallocChunk: 654328 kB
5 Answers 5
This is simpler command to check memory usage:
/proc/meminfo is for overall system memory information. /proc/[pid]/status has the memory usage info for an individual process. (it’s also in /proc/[pid]/stat in a more machine parseable format).
In particular, VmData (size of data segment) and VmStk (size of stack segments) are most likely of use to you. Or just use ps or top instead of trying to read the data directly yourself.
The other numbers are likely to just be confusing, because the overall system memory usage is complicated by shared memory, various kinds of buffers, etc.
get available memory in gb using single bash shell command
following command returns available memory in kilobytes cat /proc/meminfo | grep MemFree | awk ‘< print $2 >‘ can some one suggest single command to get the available memory in gb?
6 Answers 6
Just a slight modification to your own magical incantation:
P.S.: Dear OP, if you find yourself invoking grep & awk in one line you’re most likely doing it wrong ;> . Same with invoking cat on a single file; that’s hardly ever warranted.
Most simple is the following :
Following is the output Screenshot :
free - displays the total amount of free and used physical and swap mem‐ ory in the system, as well as the buffers and caches used by the ker‐ nel. The information is gathered by parsing /proc/meminfo. The dis‐ played columns are: total Total installed memory (MemTotal and SwapTotal in /proc/meminfo) used Used memory (calculated as total - free - buffers - cache) free Unused memory (MemFree and SwapFree in /proc/meminfo) shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo, available on kernels 2.6.32, displayed as zero if not available) buffers Memory used by kernel buffers (Buffers in /proc/meminfo) cache Memory used by the page cache and slabs (Cached and Slab in /proc/meminfo) buff/cache Sum of buffers and cache available Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, avail‐ able on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)