What is Cached Memory vs Used Memory

Linux is a popular open-source operating system, and one of its key features is the efficient memory management system that helps optimize system performance. The system memory in Linux can be broadly classified into two types: Used and Cached. 

This article will discuss the purpose of these two memories along with the key differences:

  • What is a Cached Memory?
  • How Does Cached Memory Work?
  • How to Check the Cached Memory in Linux?
  • What is a Used Memory?
  • How Does Used Memory Work?
  • How to Check Used Memory in Linux?
  • Difference Between Cached Memory and Used Memory

What is a Cached Memory?

Cached memory, also known as disk cache, is used by the operating system to store frequently accessed data from secondary storage devices such as hard drives and SSDs. The operating system stores a copy in RAM when data is accessed from secondary storage. This makes it faster to access the data in the future, as it doesn’t have to be read from a slower secondary storage device.

How Does Cached Memory Work?

When an application needs to read data from a secondary storage device, it sends a request to the operating system. The operating system checks to see if a copy of the data is stored in cache memory. If it is, the operating system retrieves the data from the cache memory and returns it to the application. If the data is not in cache memory, the operating system reads it from the secondary storage device and stores a copy in cache memory for future access.

How to Check the Cached Memory in Linux?

A user can check the cached memory in Linux by using the following commands in the terminal:

Using the free Command

The “free” command is used to display the memory-related information in human-readable format via the “h” option:

$ free -h

The cache memory can be seen in the highlighted part of the above image.

Using the top Command

The top command can also be used to provide information on the used and available memory on Linux OS by typing:

$ top

The cache memory can be seen in the highlighted part of the above image.

What is a Used Memory?

Used memory cannot be reclaimed by the system as it is actively used by various processes. Whenever a new process or application is started, it requests a certain amount of memory from the system. Once the process is completed, the system releases this memory, making it available for other processes.

How Does Used Memory Work?

When an application is launched, the operating system assigns it a portion of the computer’s RAM known as a memory address. The application stores data at this memory address so that the processor can access it quickly. As more applications are opened and more data is stored in RAM, the number of used memory increases. If the computer runs out of available memory, it may slow down or even crash.

How to Check Used Memory in Linux?

The same above commands can be used to display the information regarding used memory as below:

Using the free Command

Type the free command again in the terminal to display the information regarding the used memory:

$ free -h

The used memory can be seen by looking at the highlighted part of the above image.

There are two different types of memories as can be seen in the above image which are the main memory and the swap memory. The swap memory will be used to store data when no more main memory is left, and more information about it can be accessed by reading this article.

Using the top Command

The top command can also be used to provide information of the used and available memory on Linux OS by typing:

$ top

The used memory can be seen by looking at the highlighted part of the above image.There are some other commands as well that can provide the information of the available memory by reading this article.

Difference Between Cached Memory and Used Memory

The main difference between cached memory and used memory is how the memory is being used. Used memory is being actively used by the system, while cached memory is used to store frequently accessed data for quick access.

Another difference is how the memory is managed by the system. Used memory is managed by the operating system, which allocates and deallocates memory as needed. Cached memory, on the other hand, is managed by the system’s cache manager, which decides what data to cache and when to flush the cache.

Conclusion

While cached memory and used memory may seem similar, they refer to different types of memory usage. Used memory is actively being used by the system, while cached memory is used to store frequently accessed data for quick access. By understanding the differences between these two types of memory usage, you can better understand the performance of your system and optimize it for better performance.