Linux swap space Explained with Examples | What is the swap space | How does the swap space work

This video explains the following topics.
What is the swap space?
How does swap work?
How Linux uses the swap space
Linux swap space
swap space in Linux
When Linux uses the swap space
When Linux does not use the swap space
What is the threshold value on the swap space
This video is based on the following tutorial.
www.computernetworkingnotes.c...
Linux swap space
Developers developed Linux primarily for server systems. A server system runs multiple services simultaneously. Sometimes, a process may use more memory than expected. For example, a university website hosted on a Linux server may consume more memory on exam results day. This type of memory spike is natural on server systems. Any service may use more memory at its peak time. Linux uses swap space to deal with the lack of physical memory. A swap space is a hard disk space. Linux uses it to extend the physical memory.
How does swap work?
The system divides RAM into smaller chunks known as memory pages. It assigns memory pages to the service or process running in the CPU. CPU executes services or applications in a round-robin fashion.
A round-robin fashion schedules all processes in a queue. It assigns a quantum (allowed CPU time slot) to each process in the queue. If the process does not end in its time slot, the CPU pauses it and takes the upcoming process from the queue. If the subsequent process does not finish in its time slot, the CPU pauses it and picks the upcoming process from the queue.
Let us take an example. A CPU has two processes to execute. A quantum is 100 milliseconds. The first process needs 350 milliseconds, and the second process needs 140 milliseconds to complete.
The CPU executes the first process. After 100 milliseconds, it suspends the first process and starts the second process. It runs the second process for 100 milliseconds. After 100 milliseconds, it pauses the second process and resumes the first process. It runs the first process for another 100 milliseconds. After 100 milliseconds, it again stops the first process and starts the second process. The second process needs only 40 milliseconds to complete. It allocates the remaining 60 milliseconds of the time slot to the first process. In the time slot, the first process also ends. Since no other process is running, the CPU becomes ideal. The CPU repeats this cycle each time it gets new processes to run.
Every process needs memory pages on RAM to store its data. An application can run many processes simultaneously. The more applications you run, the less memory remains available for other applications. If no memory is left, you can not start a new process.
The swap space solves this problem. As explained earlier, the CPU runs only one process at a given time and keeps all other processes paused. If the swap space is available, the system moves ideal processes' data to the swap space.
Threshold
A swap space resides on the hard disk. A hard disk is a secondary memory. It cannot replace the primary memory. Secondary memory is slower than primary memory.
The CPU uses the primary memory to process the data. It does not access data directly from the hard disk. It means the CPU will process an application's data only when the data is available on RAM. If the operating system uses the swap space, it has to move out the ideal application's data and move in the active application's data every quantum. It creates a lot of overhead. It decreases the system's performance instead of improving it. Because of this, the system uses the swap space only when it has a shortage of RAM. It defines a threshold value for RAM.
It uses the swap space only when the uses of the RAM crosses the threshold.
Key points:-
The swap space is a hard disk space. The system uses it to store idle memory pages.
Since the swap space resides on the hard disk, it is slower than with RAM.
The swap space is an essential part of Linux configuration.
The system automatically configures a threshold value if the swap space is available.
The system will use the swap space only when the use of RAM reaches the threshold.
As long as the use of the RAM remains below the threshold, the system does not use the swap space.

Пікірлер: 12

  • @dark_red_blood
    @dark_red_blood6 ай бұрын

    Best tutorial I've seen in a while. I came for swap space and learned much more.(round robin). Thank you.

  • @computernetworkingnotesyoutube

    @computernetworkingnotesyoutube

    6 ай бұрын

    Glad it was helpful!

  • @nikis7453
    @nikis74536 ай бұрын

    Great video! Wouldn't the 'paging space/memory' be exactly the same as 'swap space'? More likely in Windows terms :)

  • @computernetworkingnotesyoutube

    @computernetworkingnotesyoutube

    6 ай бұрын

    Yes, exactly

  • @anand-nb4bb
    @anand-nb4bb6 ай бұрын

    Hi Bro can you please 🙏make a tutorial on Kerberos & NTLM how it works & how to authenticate using it on windows & Linux also explain different command it has. please its a request.

  • @computernetworkingnotesyoutube

    @computernetworkingnotesyoutube

    6 ай бұрын

    Sure, I will do it. But it will take some time, maybe a month or two, as I have a few projects already lined up.

  • @mc-not_escher
    @mc-not_escher6 ай бұрын

    I’ve been running Linux without swap on 8GB of RAM for about 6 years with an SSD and btrfs. No complaints here. [Edit: Photoshop and Vim taking up that much space 😂 what world do you live in?]

  • @computernetworkingnotesyoutube

    @computernetworkingnotesyoutube

    6 ай бұрын

    Thanks for your feedback, Ya, of course, you can run Linux without swap space. As I mentioned in the video, Linux uses the swap space only when it has a shortage of RAM. If all running applications use RAM below the threshold value, Linux does not use the swap space. So far, the values for Photoshop and Vim used in the video are concerned; they are only for explanation. They have nothing to do with the actual RAM they use.

  • @SHIROmori3
    @SHIROmori36 ай бұрын

    just buy more ram^^

  • @computernetworkingnotesyoutube

    @computernetworkingnotesyoutube

    6 ай бұрын

    An effective but costly solution

  • @Elixz89
    @Elixz896 ай бұрын

    Runs Linux -> starts Photoshop 😅

  • @computernetworkingnotesyoutube

    @computernetworkingnotesyoutube

    6 ай бұрын

    Thanks for your feedback, Application names used in this video are only for explanation. You can think of any application. So far, Photoshop is concerned; it does not support Linux directly. If you want to install and run Photoshop on Linux, you can do it through the Wine package. It allows you to run any Windows-based software.