Linux and the swap space !
A computer cannot use programs and data unless they are stored in RAM. RAM is volatile memory; that is, the data stored in RAM is lost if the computer is turned off. Hard drives are magnetic media used for long-term storage of data and programs. Magnetic media are nonvolatile; the data stored on a disk remains even when power is removed from the computer. The CPU (central processing unit) cannot directly access the programs and data on the hard drive; it must be copied into RAM first, and that is where the CPU can access its programming instructions and the data to be operated on by those instructions. During the boot process, a computer copies specific operating system programs, such as the kernel and init or systemd, and data from the hard drive into RAM, where it is accessed directly by the computer’s processor, the CPU.
There is a unique space in Linux called swap space which is active when the RAM is full. In general RAM and swap space combinedly are called the total amount of memory. The primary function of swap space is to substitute disk space for RAM when RAM fills up. Swap space is the hard drive (magnetic media). Some portions of hard drives are treated as swap space. This helps the machine use the hard drive as an alternative for RAM, but it should not be considered as a replacement for RAM. If any process in the system needs more memory resources, at first RAM becomes full after that all the inactive pages of RAM are moved to the swap space. Swap space is slower than RAM since they are hard drives. Swap space is built in such a way that high-priority processes will execute within the RAM and others will execute within the swap space. Generally, the system admin allocates a certain amount of swap space based on the size of RAM.
But there is a lagging problem between swap space and RAM when the RAM gets free. To address and tackle this, I have curated an algorithm that will automatically increase and decrease the swap space and there will be no lag between them. I will publish the algorithm in my next article.
Er. Rabin Raj Gautam