free shows how much of your computer’s memory is being used and how much is still available for use by programs. His conclusion may be confusing to the uninitiated, but we’ll show you how to figure it out.
free displays a summary of memory usage in the terminal window. it doesn’t have many options or tricks, and it doesn’t take much time or effort to learn how to use it. However, learning how to properly interpret the information it provides is a different story. It’s too easy to get confused because
free tells you.
This is partly due to terminology, such as the difference between «free» and «available», and partly due to the internal workings of the memory and file system management routines of the Linux kernel. If you have spare memory that the kernel can use effectively, it borrows it for its own purposes. Until you need it.
We’re going to dive into the underlying mechanics and procedures of data processing so you can appreciate what’s going on under the hood and how it all affects your random access memory (RAM) usage.
free no options and see what we get:
It’s ugly. On your computer, you will be able to stretch the terminal window. Here is the output in a neat table:
общее количество свободного общего доступного баффа / кэша доступно Память: 2038576 670716 327956 14296 1039904 1187160 Своп: 1557568 769096 788472
The numbers are given in kibibytes, which is 1024 bytes. Team on Manjaro
free called an alias
free -m . It makes
free use mebibytes which is 1,048,576 bytes. Other distributions default to kibibyte.
The top line reports system memory, the bottom line reports swap space. We’ll introduce the columns here and then look at them in more detail shortly. The columns for the memory string are as follows:
- Total : The total amount of physical memory installed on your computer.
- used : calculated from
- Free : The amount of unused memory. Why not Total = Used + Free? We will explain this shortly.
- shared : memory used by the file system
- buff/cache : memory used for buffers and cache.
- Available : This is an estimate of the memory available to serve memory requests from applications, any other running software on your computer, such as the graphical desktop environment, and Linux commands.
For row swap columns:
- Total : The size of the swap partition or swap file.
- used : amount of swap space used.
- Free : remaining (unused) swap space
To split scores
Buff/cache into their own columns, use the option
This is the result. Instead of a column
Buff/cache we get a column
Cache . Here are the numbers in the table:
общий доступный свободный кеш общих буферов Mem: 2038576 683724 265708 14660 94568 994596 1160420 Обмен: 1557568 761416 796152
Let’s see what the numbers in the columns represent.
It’s simple. This is how much RAM you have installed on the motherboard. This is a precious resource that all running processes are fighting for. At least they will fight if the core doesn’t judge.
By the way, the place where
free collects information, is a pseudo-file
/proc/meminfo . You can view this file yourself with the following command:
меньше / proc / meminfo
The output is a single list of names and values.
Here’s where it starts to get interesting.
Used represents what you’re probably expecting, plus a bunch of other stuff. This is the memory that is allocated to processes, used by user programs, and used by things like the GNOME or KDE desktop environments. There are no surprises. But it also includes numbers
RAM that is not being used for something is empty memory. The kernel uses spare RAM to store caches and buffers that allow it to run more efficiently. So this RAM is being used for something by the kernel, not something in user space.
If a request for memory is received that can only be serviced by giving up some RAM that the kernel is using for its own devices, then this happens unhindered. Freeing up this RAM and using it for other applications will not affect correct work your Linux system — nothing will break, but it may affect performance systems.
So this column really means «all RAM that is used by something, even if it can be reclaimed instantly».
This column indicates the amount of RAM that is not being used by anything. Because in the column
Used contains «Buffers and Cache» values, it is not uncommon for perfectly functioning Linux systems to have very little RAM listed as «free».
This is not necessarily a bad thing, and almost certainly means that you have a perfectly functioning system that is properly throttling RAM usage. That is, RAM is used by applications and other processes in user space, as well as by the kernel in an effort to make your computer perform as fast as possible.
Pictured in a column
Shared presented memory designed to store file systems based on
tmpfs RAM. These are file systems that are created in memory to ensure the efficient functioning of the operating system. To see which file systems
tmpfs are present, use the command
Options we use:
-h(human): Use reasonable, most appropriate units.
--total: display a row with totals at the bottom of the output.
--type=tmpfs: report only filesystems
df -h --total --type = tmpfs
The first thing that catches your eye when you look at these values is that they are many times larger than the number in the column.
Shared . The sizes shown here are the maximum sizes of these file systems. In reality, each of them takes only as much memory as they need. Figure in a column
Shared is the belief for using memory.
What do these file systems contain? Here’s a quick breakdown:
- / run : contains many temporary files such as PID files, systemd logging that does not need to be preserved across reboots, Unix domain socket information, FIFOs, and daemon management.
- /dev/shm : This allows for POSIX-compliant memory management on Debian and Linux distributions.
- /run/lock : contains lock files. They are used as indicators to let the system know that a file or other share is in use. They contain the PID of the process using that resource.
- /sys/fs/cgroup : This is the centerpiece of the circuit that manages the control groups. Processes are organized into hierarchical groups according to the types of resources they use. This allows you to control the use of resources by processes and limit them.
- /run/user/121 : This is the folder created by pam_systemd to store temporary files for the user. In this case, the user ID is 121. Note that «user» can be a regular user, a daemon, or some other process.
- /run/user/1000 : this is a folder,
createdpam_systemd to store temporary files for this user with userid 1000. This is the current user, user dave.
Buffer and Cache Columns
Cache only appear if you have used
-w (wide). Without option —
w numbers from these two columns are combined into a column
These two areas of memory interact and depend on each other. The cache area contains (mostly) data that has been read from the hard drive. It is saved in case you need to access it again. It’s faster to do this by retrieving this data from the cache than by reading it from the hard drive. The cache may also contain data that has been modified but not yet written back to the hard disk, or values that have been computed and not yet saved to a file.
To keep track of various pieces of files and data storage, the kernel creates an index in the cache area, in the buffer area. Buffers are parts of memory that contain a disk block and other information structures. They contain data about the data that is stored in the cache area. So buffers are the metadata for the cache.
When a request is made to read a file, the kernel reads the data in the buffer data structures, looking for the file or file fragment that was requested. If it is found, the request is served from the cache area pointed to by the buffer data structures. If it is not in the cache and not in the metadata in the buffers memory area, the file is read from the hard disk.
Structures in the buffer memory area: