On Linux, this is done at the kernel and hardware levels. The CPU has a hardware component called the Memory Management Unit (MMU) that converts physical memory addresses into virtual addresses. These addresses are independent of where they are physically located on the computer. These address spaces are called “pages” and can be located in memory, on the hard disk or on the SSD. The operating system considers these addresses to be a large pool of memory called the “address space”. Linux supports virtual memory, which is the use of a hard disk as an extension of memory so that the effective size of usable memory grows accordingly. The kernel writes the contents of a currently unused block of memory to disk so that the memory can be used for another purpose. When the original contents are needed again, they are read back into memory. We have mentioned below the steps to manage virtual memory in Linux.

Steps to Manage Virtual Memory in Linux

Linux Memory Management Commands

Command /proc/meminfo

Step 1: The /proc/meminfo file contains all memory-related information. To view this file use cat command🇧🇷 Step 2: For get physical memory using the proc/meminfo file: Step 3: To get the physical memory of proc/meminfo file usage:

the superior command

Step 1: The top command allows you to monitor processes and system resource usage in Linux🇧🇷 It provides a dynamic, real-time view of the system. As you run the command, you will notice that the values ​​in the output constantly change. This happens because the values ​​are displayed in real time. Step 2: you can move up and down the list using the up/low arrow keys and use q to exit🇧🇷

free command

Step 1: The free command shows the amount of free and used memory on the system. It’s a simple and compact command. It tells you how much free memory you have on your system. It also informs you about the total amount of physical and paged memory on your system. Step 2: The values ​​of each field are in Kibibyte (KiB)🇧🇷 Kibibyte is not the same as Kilobyte.

vmstat command

Step 1: vmstat is a performance monitoring tool on Linux. It provides useful information about processes, memory, block IO, paging, disk and CPU scheduling. It reports statistics about your system’s virtual memory.

Increase virtual memory in Linux

Step 1: Determine the amount of free space available with the “df” command🇧🇷 Decide the swap file size based on the amount of free space. Step 2: Create a swap file of the previously decided size with the command “sudo dd if=/dev/zero of=/mnt/swapfile bs=1M count=1024” where 1024 is the size of the swap file in megabytes and the full name of the swapfile is /mnt/swapfile. Step 3: Format the swap file with the command “sudo mkswap /mnt/swapfile🇧🇷 Step 4: Activate the swap file with the command “sudo swapon /mnt/swapfile🇧🇷 Step 5: The new swap file will not be used after a reboot unless the system is instructed to use the swap file. Edit the /etc/fstab file and add the following line in /etc/fstab to make the swap file persistent across reboots “/mnt/swapfile no swap sw 00.”

Final Words

We hope you enjoy our article on how to Manage virtual memory in Linux. These are some commands you can use in Linux to manage your memory. These commands provide important information about your memory. You can play around with all the commands by following the individual instructions to get a general idea of how to Play around with processes in Task Manager. This is all completely transparent; programs running on Linux only see the largest amount of available memory and don’t realize that parts of them are on disk from time to time.

How to Manage Virtual Memory on Linux - 3How to Manage Virtual Memory on Linux - 5How to Manage Virtual Memory on Linux - 78How to Manage Virtual Memory on Linux - 73