Commands for Memory Management in Linux. The /proc/meminfo file contains all the information related to memory. To view this file use the cat command: This command outputs a 2 2. The top command., and free command., and vmstat command.
If you want to make top a bit more memory-friendly, issue the command top -o %MEM, which will cause top to sort all processes by memory used (Figure 2). Figure 2: Sorting process by memory used in top. The top command also gives you a real-time update on how much of your swap space is being used.
What is memory management in Linux?
The subsystem of Linux memory management is responsible to manage the memory inside the system. It contains the implementation of demand paging and virtual memory. It contains memory allocation for user space programs and kernel internal structures.
Linux considers unused memory to be wasted memory. So it will use as much memory as possible to speed up the performance on the system. The related caches and buffers contain typically data related to the file system. That is also why a second run of the find command in the same directory runs much quicker.
Before we get into the nitty-gritty, it’s important to know that there are two types of memories in Linux. Physical memory is the actual memory present in the machine. While Virtual memory is a layer of memory addresses that map to physical addresses. Virtual memory is usually bigger than physical memory. Linux kernel uses Virtual memory.
When Linux uses system RAM, it creates a virtual memory layer to then assigns processes to virtual memory. Virtual memory is actually a combination of both RAM and swap space; swap space is a section of your hard drive designated as available for use in case usable RAM runs out.
How to see the amount of free and used memory on Linux?
You may only need to see the amount of free and used memory on your system. For that, there is the free command. The free command displays: From your terminal window, issue the command free. The output of this command is not in real time. Instead, what you’ll get is an instant snapshot of the free and used memory in that moment (Figure 3).