Memory Swapping

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
21 hours 25 minutes
Difficulty
Intermediate
CEU/CPE
21
Video Transcription
00:00
>> Hey Cybrarians, and welcome back to
00:00
the Linux plus course here at Cybrary.
00:00
I'm your instructor Rob Goelz.
00:00
In today's lesson, we're going to
00:00
be covering memory swapping.
00:00
Upon completion of this lesson,
00:00
you are going to be able to understand
00:00
the purpose of swap space,
00:00
as well as explain how the tools mkswap,
00:00
swapon, and swapoff are used.
00:00
We talked about the Out Of Memory killer,
00:00
>> the OOM killer,
00:00
>> but there is another technique that can be used when
00:00
memory is running low and this is known as swapping.
00:00
Now, memory is divided into pages,
00:00
and when a system needs more memory,
00:00
it can take memory pages away from idle processes.
00:00
What happens then is that
00:00
those idle pages get written to disk,
00:00
and the disk location where
00:00
idle pages wind up and get written
00:00
to is a partition that is known as
00:00
swap space or just swap for short.
00:00
Now, once the process is no longer idle,
00:00
the pages get copied back into memory from disk,
00:00
they get swapped back in to memory.
00:00
Generally, the swap partition is
00:00
handled when we set up a Linux distribution.
00:00
When we do the install, it's usually created for us.
00:00
To see the current swap devices,
00:00
we can run swapon -s.
00:00
>> However, if we decide down the road that we want to add
00:00
>> more swap space or maybe we
00:00
want to add it on another partition,
00:00
we have to do this in three steps.
00:00
The first thing we do is we create
00:00
a new partition tagged as swap,
00:00
and we saw this before when we were talking
00:00
about the F disk and G disk commands,
00:00
then we can create the partition,
00:00
and then we can give it that information,
00:00
and tell it it's a swap partition.
00:00
Then we're going to use the mkswap command,
00:00
we do mkswap,
00:00
and we specify the partition number.
00:00
For example, if this was on sdb1,
00:00
we would do /dev/sdb1,
00:00
mkswap /dev/sdb1,
00:00
and then we actually have to turn
00:00
swapon for that partition as well,
00:00
and we do that by doing a swapon,
00:00
>> dev, and partition.
00:00
>> For example, again, swapon /dev/sdb1
00:00
>> would turn that swap on that partition.
00:00
>> Now, if you decide that you want to remove
00:00
a swap device, you run swapoff.
00:00
For example, swapoff /dev/sdb1
00:00
>> would turn off swap on that device,
00:00
>> and then you could do the work of removing that,
00:00
making sure that the partition is deleted,
00:00
and so on and so forth as need be.
00:00
But with that, in this lesson,
00:00
we covered the purpose of swap space
00:00
and how Linux performs swapping,
00:00
and then we talked about how the tools mkswap, swapon,
00:00
and swapoff are used in order
00:00
to create and remove swap partitions.
00:00
Thanks so much for being here,
00:00
>> and I look forward to seeing you in the next lesson.
Up Next