OS Unit 3
OS Unit 3
Swapping has been subdivided into two concepts: swap-in and swap-
out.
● Swap-out is a technique for moving a process from RAM to the
hard disc.
● Swap-in is a method of transferring a program from a hard disc
to main memory, or RAM.
Process of Swapping
● When the RAM is full and a new program needs to run, the
operating system selects a program or data that is currently in
RAM but not actively being used.
● The selected data is moved to secondary storage, freeing up
space in RAM for the new program
● When the swapped-out program is needed again, it can be
swapped back into RAM, replacing another inactive program or
data if necessary.
Real Life Example of Swapping
Imagine you have a disk (RAM) that is too small to hold all your
books and papers (programs). You keep the most important items on
the desk and store the rest in a cabinet (secondary storage). When you
need something from the cabinet, you swap it with something on your
desk. This way, you can work with more items than your desk alone
could hold.
Memory allocation
Memory allocation in an operating system refers to the process of
assigning memory spaces to programs or processes during their
execution. The operating system must efficiently allocate and manage
memory to ensure that processes get the memory they need without
wasting resources or interfering with each other.
Types of Memory Allocation:
Memory fragmentation
Memory fragmentation in an operating system refers to the
phenomenon where free memory is split into small, non-contiguous
blocks over time, which can lead to inefficient memory utilization.
Fragmentation occurs when memory is allocated and deallocated
dynamically, leaving gaps of unused memory that are not large
enough to satisfy new memory allocation requests.
There are two main types of fragmentation:
1. External Fragmentation: