Fatmawati Ahmad Zaenuri / Shutterstock

Linux Team 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 team

Team 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 Columns

Let’s run free no options and see what we get:

  свободно 

loose command in terminal window

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 Total — ( Free + Buffers + Cache ).
  • Free : The amount of unused memory. Why not Total = Used + Free? We will explain this shortly.
  • shared : memory used by the file system tmpfs .
  • 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

Wide Display

To split scores Buff/cache into their own columns, use the option -w (wide):

  свободный -w 

free -w in a terminal window

This is the result. Instead of a column Buff/cache we get a column Buffers 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.

General column

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 

less /proc/meminfo in a terminal window

The output is a single list of names and values.

Output of the less /proc/meminfo command in a terminal window

Column used

Here’s where it starts to get interesting.

Index » 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 Buffers and Cache .

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».

free column

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.

General column

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 df .

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 tmpfs .
  df -h --total --type = tmpfs 

df -h --total --type=tmpfs in terminal window

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, created pam_systemd to store temporary files for this user with userid 1000. This is the current user, user dave.

Buffer and Cache Columns

columns Buffer and Cache only appear if you have used -w (wide). Without option — w numbers from these two columns are combined into a column Buff/cache .

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:

You can see why it makes sense to compress the memory used for buffer and cache areas into one column Buff/cache . They are like two parts of the same thing. A cache area would be useless without a buffer area providing an index to its contents.

Available column

The available column is the sum of the column Free plus parts of the columns Buffers and Cache (or column Buff/cache ), which can be immediately released. Column Available is an approximation, not an exact figure. This is a reasonable and accurate estimate, but should not be taken to the last byte.

Changing Display Units

To change the units in which numbers are displayed, use one of the following options.

For example, to use human-readable values, use the parameter -h :

  бесплатно -h 

free -h in a terminal window

free will use the most appropriate unit for each value. As you can see, some values ​​are displayed in megabytes and some are displayed in GiB.

Total display

Option --total freely display a total row that sums values ​​from columns Total , Used and Free columns Mem and Swap .

  free -h --total 

free -h --- total in terminal window

Count option

Option -c (count) allows you to run a certain number of times with a pause of one second between each. To run twice free use this command:

  свободный -h -c 2 

loose -h -c 2 in terminal window

Works for free all the time

If you want to see how a particular application affects memory usage, it can be helpful to constantly run free . This allows you free work in a terminal window while launching, using, and then closing the application under study.

Option -s (seconds) defines the duration of the pause between each launch free . To run the program continuously with a three second pause between updates, use this command:

  бесплатно -s 3 

free -s 3 in terminal window

Click Ctrl+C to stop the process and return to the command line.

Combining Count and Seconds

To be able to free run with a specified pause between each update, but stop after a certain number of reports, combine options -s (seconds) and -c (amount). To run five times with a two-second pause between updates, use this command:

  свободный -s 2 -c 5 

free -s 2 -c 5 in a terminal window

After five updates appear, the process ends on its own and you are returned to the command line.

self-completion of the command free -s 2 -c 5 in the terminal window

Separation of low and high memory

It’s currently useless, but if you’re running Linux on a 32-bit machine, it might be useful. It separates memory usage from low memory and high memory.

On a 32-bit Linux operating system, the processor can handle up to 4 GB of memory. The memory is divided into small memory and upper memory. Out of memory is directly mapped to part of the kernel address space. High memory has no direct kernel mapping. Large memory usually exceeds 896 MB.

This means that the kernel itself (including its active modules) can only use out of memory. User processes — anything that is not the kernel itself — can potentially use low and high memory.

On a 64-bit computer, no values ​​for high memory will be displayed:

  бесплатно -h -l 

loose -h -l in terminal window

Memories are made of this

Short review:

Похожие записи