Buddy System Memory Management Example
Buddy System Memory Management Example
Semester 3
Course Code BCS303 CIE Marks 50
Memory Management: Memory management strategies: Background; Swapping;
Contiguous memory allocation; Paging; Structure of page table; Segmentation.
Virtual Memory Management: Background; Demand paging; Copy-on-write; Page
replacement; Allocation of frames; Thrashing.
Q. 07 a What is TLB? Explain TLB in detail with a paging system with a neat diagram.
b With the help of a neat diagram, explain the various steps of address binding.
Q. 08 a What is demand paging? Explain the steps in handling page faults using the appropriate
diagram.
Q.7 a. What is paging? Explain with neat diagram paging hardware with TLB?
b. What are the commonly used strategies to select a free hole from the available holes?
q.8. a. With a neat diagram? Describe the steps in handling the page fault.
1|Page
Introduction to memory and memory units
Memory is the storage space in a computer where data and instructions are kept. It is divided into
small units called cells, and each cell has a unique address.
Storage element (Cell): Stores 1 bit of data. Register: A memory location made of cells.
Capacity: Total number of bits a memory can store. Reading: Retrieving data. Writing: Storing data.
Memory is essential because it allows computers to store both temporary data (used while processing)
and permanent data (like system programs).
A word is a group of bits where a memory unit stores binary information. A word with a group of 8
bits is called a byte.
A memory unit consists of data lines, address selection lines, and control lines that specify the
direction of transfer.
Data lines provide the information to be stored in memory. The control inputs specify the direct
transfer. The k-address lines specify the word chosen.
2|Page
Types of Computer Memory
1. Cache Memory: Very fast storage, close to CPU, stores frequently used data.
2. RAM (Random Access Memory): Volatile, read/write, temporary data storage on motherboard.
3. ROM (Read Only Memory): Non-volatile, stores permanent system instructions, read-only.
6. Hybrid Memory: Combines RAM and Flash for efficiency and reduced power use.
It is also referred to as main memory or internal memory. It is a computer system's temporary storage
component which is directly accessible by the central processing unit (CPU). It houses data for
immediate processing.
Characteristics
High-speed access.
3|Page
Limited capacity relative to secondary storage.
Advantages
Directly accessible by CPU: No intermediate steps are required for data transfer.
Disadvantages
Limited storage capacity: compared to secondary storage, primary memory is relatively small.
Secondary memory or external memory serves as long-term storage for data and programs. Unlike
primary memory, it is not directly accessible by the CPU and requires input/output operations.
Characteristics
Examples: Hard Disk Drives(HDD), Solid-State Drives(SSD), Optical drives(CD, DVD, Blu-ray).
Advantages
Disadvantages
Data Storage: Store temporary data (RAM) and permanent data (ROM).
Quick Access: CPU retrieves stored data and instructions for fast processing.
Data Transfer: Move data between CPU, RAM, and storage devices.
4|Page
Reliability: Non-volatile memory (ROM/EEPROM) keeps data safe even without power.
The size of the memory unit affects its speed, power, and capabilities. without a memory unit, the
processor would have to wait longer for data retrieval.
Memory management is a critical aspect of operating systems that ensures efficient use of the
computer's memory resources. It controls how memory is allocated and deallocated to processes,
which is key to both performance and stability. Below is a detailed overview of the various
components and techniques involved in memory management.
Memory Management
Logical Address Space: The logical address space is the set of all addresses that a process can generate
using its CPU. It defines the range of memory locations available to the process from its perspective.
Physical Address Space: The physical address space is the set of all actual memory addresses in the
main memory (RAM). It represents the real locations where data and instructions are stored.
5|Page
Static and Dynamic Loading
Loading a process into the main memory is done by a loader. There are two different types of loading
:
Static Loading: Static Loading is basically loading the entire program into a fixed address. It requires
more memory space.
Dynamic Loading: Dynamic loading loads program routines into memory only when they are needed.
This saves memory by not loading unused routines. The routines remain on disk in relocatable(can be
loaded at any memory location) format until called. It allows better memory utilization, especially for
large programs.
Static Linking: All required modules are combined into one executable. No runtime dependency; some
OSes support only this method.
Dynamic Linking: Uses a stub (small code) for library calls. At runtime, the stub checks if the routine is
in memory; if not, it loads it.
Swapping
Swapping moves processes between main memory and secondary memory to manage limited
memory space. It allows multiple processes to run by temporarily swapping out lower priority
processes for higher priority ones. The swapped-out process resumes once it's loaded back. Transfer
time depends on the amount of data swapped.
Swapping
Memory management techniques are methods used by an operating system to efficiently allocate,
utilize, and manage memory resources for processes. Various techniques help the operating system
manage memory effectively. They can be broadly categorized into:
6|Page
Memory Management with Monoprogramming (Without Swapping)
This is the simplest memory management approach the memory is divided into two sections: One
part of the operating system. The second part of the user program
Since interrupt vectors are usually placed in low memory, the OS is often loaded there.
A memory partition scheme with a fixed number of partitions was introduced to support
multiprogramming. this scheme is based on contiguous allocation
Partition Table: Once partitions are defined operating system keeps track of the status of memory
partitions it is done through a data structure called a partition table.
7|Page
Contiguous Memory Allocation
Contiguous memory allocation is a memory management method where each process is given a single,
continuous block of memory. This means all the data for a process is stored in adjacent memory
locations.
This method allows processes to be broken into smaller parts, which are placed in different, non-
adjacent memory locations. Techniques for non-contiguous memory allocation include:
Paging: The process is divided into fixed-size blocks called "pages," and the memory is divided into
blocks of the same size called "frames." The operating system keeps a page table to map logical pages
to physical frames.
Segmentation: The process is divided into segments of varying sizes, such as code, data, stack, etc. The
operating system maintains a segment table to map logical segments to physical memory.
Fragmentation
Fragmentation occurs when processes are loaded and removed from memory, leaving small
unusable gaps. These gaps cannot be allocated to new processes because they are either too small
or scattered.
Types of Fragmentation:
Internal Fragmentation: Wasted space inside allocated memory blocks when a process is given more
memory than it needs.
External Fragmentation: Free memory exists but is divided into small scattered blocks, preventing
allocation of large contiguous space.
Efficient memory allocation is essential for optimal performance. There are several strategies for
allocating memory blocks:
1. Fixed Partition Allocation: Memory is divided into fixed-sized partitions, and each partition can
hold only one process. The OS keeps track of free and occupied partitions using a partition table.
2. Dynamic Partition Allocation: Memory is divided into variable-sized partitions based on the size of
the processes. This helps avoid wastage of memory but can result in fragmentation.
3. Placement Algorithms: When allocating memory, the OS uses placement algorithms to decide
which free block should be assigned to a process:
First Fit: Allocates the first available partition large enough to hold the process.
Best Fit: Allocates the smallest available partition that fits the process, reducing wasted space.
Worst Fit: Allocates the largest available partition, leaving the largest remaining space.
Next Fit: Similar to First Fit but starts searching for free memory from the point of the last allocation.
8|Page
Logical and Physical Address in Operating System
In operating systems, memory is accessed using logical (virtual) addresses and physical addresses,
which the Memory Management Unit (MMU) maps to manage memory efficiently.
Logical Address
A logical address is generated by the CPU while a program runs. It represents the address from the
process’s perspective and does not exist physically, hence it is also called a virtual address.
The logical address space is the set of all logical addresses a process can generate. Programs use logical
addresses to reference memory, and the MMU translates them into physical addresses when
accessing actual memory.
Physical Address
A physical address is the real location in main memory (RAM) where data or instructions are stored.
The physical address space consists of all physical addresses corresponding to logical addresses.
The MMU performs address translation using a page table, mapping each logical page to a physical
frame. This allows processes to access memory transparently, without knowing actual memory
locations.
Both logical and physical addresses are used to identify a specific location in memory.
Both logical and physical addresses can be represented in different formats, such as binary,
hexadecimal, or decimal.
Both logical and physical addresses have a finite range, which is determined by the number of bits
used to represent them.
The Memory Management Unit (MMU) is a hardware component in the computer system that
handles all memory and caching operations associated with the CPU. Its main function is to
translate logical (virtual) addresses generated by the CPU into physical addresses in main memory.
Logical addresses provide abstraction, so processes don’t need to know physical locations.
Logical addresses are mapped to physical addresses via the page table.
9|Page
Memory Management
Memory Management Techniques are basic techniques that are used in managing the memory in
the operating system. They are classified broadly into two categories:
Contiguous memory allocation is a memory allocation strategy. As the name implies, we utilize this
technique to assign contiguous blocks of memory to each task. Thus, whenever a process asks to
access the main memory, we allocate a continuous segment from the empty region to the process
based on its size. In this technique, memory is allotted in a continuous way to the processes.
Contiguous Memory Management has two types:
10 | P a g e
Lets understand these in detail.
In the fixed partition scheme, memory is divided into fixed number of partitions. Fixed means
number of partitions are fixed in the memory. In the fixed partition, in every partition only one
process will be accommodated. Degree of multi-programming is restricted by number of partitions
in the memory. Maximum size of the process is restricted by maximum size of the partition. Every
partition is associated with the limit registers.
Maximum process size should always be less than equal to maximum partition size.
If a process of 19kb wants to allocate and we have free space which is not continuous we are not able
to allocate the space.
11 | P a g e
Internal Fragmentation is found in fixed partition scheme. To overcome the problem of internal
fragmentation, instead of fixed partition scheme, variable partition scheme is used.
In the variable partition scheme, initially memory will be single continuous free block. Whenever the
request by the process arrives, accordingly partition will be made in the memory. If the smaller
processes keep on coming then the larger partitions will be made into smaller partitions.
In variable partition schema initially, the memory will be full contiguous free block
Memory divided into partitions according to the process size where process size will vary.
1. Compaction
Moving all the processes toward the top or towards the bottom to make free available memory in a
single continuous place is called compaction. Compaction is undesirable to implement because it
interrupts all the running processes in the memory. It also consumes CPU time (overhead).
12 | P a g e
2. Non-contiguous memory allocation
Physical address space: Main memory (physical memory) is divided into blocks of the same size called
frames. frame size is defined by the operating system by comparing it with the size of the process.
Logical Address space: Logical memory is divided into blocks of the same size called process pages.
page size is defined by hardware system and these pages are stored in the main memory during the
process in non-contiguous frames.
Internal Fragmentation in OS
Internal Fragmentation is the wastage of memory that occurs when fixed-sized memory blocks are
allocated to processes, but the process does not use the entire allocated block. The unused portion
inside the allocated block remains idle, resulting in poor memory utilization.
Fixed Block Allocation: When processes request memory, they are often assigned blocks larger than
required. The unused space within the block is wasted.
Uniform Block Sizes: If all processes get the same memory size, smaller processes leave large unused
portions.
Management Overheads: Some systems reserve extra memory for bookkeeping, which also adds to
internal fragmentation.
Example: Let's assume that the system that is being used assigns the memory in blocks of sizes being
multiples of 4(like 12, 24, 32,..). In this system when a process P1 requests an amount of memory that
is not a multiple of 4, it is assigned a memory block of value of the nearest higher multiple.
13 | P a g e
A process requests 29 KB.
Performance Degradation: More I/O operations due to scattered partially filled blocks.
Virtual Memory Issues: Partially filled pages can increase page faults.
As Internal Fragmentation is nothing but a problem there isn't any significant advantage that it
provides to the system. But there are a couple of things that favor causing it, which are:
As the allocation always occurs in a fixed size only the allocation becomes fast and simple.
When the overhead calculation for the system is done it outputs to be pretty predictable which in
return gives a predictable performance. The overhead calculation is accurate as the overhead caused
by the Internal Fragmentation is already well known.
There are several ways to avoid Internal fragmentation. Some of them are mentioned below.
Variable-Sized Blocks: Create memory blocks of different sizes and allocate the best-fit block for each
process, reducing unused space.
Dynamic Memory Allocation: Assign only the exact memory required by a process, so little to no
memory is wasted.
External Fragmentation in OS
External fragmentation is a problem in memory management where free memory is divided into
small, non-contiguous blocks. Even though there may be enough total free memory to run a new
program, the memory is scattered in tiny pieces, so it's impossible to find a single, large block for the
program to use. This leads to wasted memory and poor system performance.
External fragmentation is caused by the dynamic allocation and deallocation of processes. Imagine
memory as a long parking lot.
Then, some of these cars leave, creating empty spaces (free memory).
These empty spaces are of different sizes and are scattered throughout the lot.
14 | P a g e
If a new, large truck (a new process) arrives, it can't find a single, continuous space big enough to
park, even though the total empty space in the lot is more than enough.
This is exactly how external fragmentation works. The "holes" in the memory are too small and
separated to be useful for larger processes.
Compaction: Rearranges processes in memory to merge free spaces into larger contiguous blocks.
Best-Fit Allocation: Assigns the smallest available block that fits a process, reducing wasted space
(though not eliminating fragmentation completely).
Lets consider a memory space having 4 processes, each of them requires different amount of
memory to execute, as shown in Figure 1.
Figure 1
Now suppose Process 1 and Process 3 have been completed, so now there are free places available,
as shown in Figure 2.
Figure 2
Now, if we want to run another process (Process 5) requiring memory 50 KB, we will not be able to
do it, although there is enough memory to run Process 5 as the memory is not contiguous, as shown
in Figure 3.
15 | P a g e
Figure 3
Variable Process Sizes: Different processes need different amounts of memory, leaving uneven gaps
when loaded/unloaded.
Allocation & Deallocation: When processes finish, freed blocks may not be adjacent, creating
scattered holes.
Non-Uniform Release: Memory released at irregular points leads to gaps of unpredictable sizes.
Allocation Strategies: Best-fit and worst-fit may worsen fragmentation by leaving behind many small
unusable holes.
Fixed Partitioning: Fixed-sized partitions cause mismatches between process size and partition size,
leading to internal and external fragmentation.
High Process Turnover: Frequent loading and removal of processes leaves memory fragmented over
time.
Below mentioned are the solutions of External Fragmentation that are mentioned below.
1. Memory Compaction
Memory compaction includes rearranging the items in memory to unite free memory hinders and
make bigger contiguous memory regions. This is the closely guarded secret:
Process Relocation: Moves processes closer together to eliminate or reduce gaps, creating larger
contiguous free memory blocks.
Benefits: Directly reduces external fragmentation, increasing the chance of allocating memory
without gaps.
Challenges: Can be resource-intensive, may disrupt running processes, and frequent compaction can
impact system performance.
16 | P a g e
2. Paging
Paging is a memory management technique that divides physical memory into fixed-size blocks called
pages. It helps overcome external fragmentation and simplifies memory allocation.
Page Size: Memory is divided into equal-sized pages, preventing small unusable gaps.
Virtual Memory: Allows processes to use non-contiguous physical memory while seeing it as a single
contiguous space.
Page Table: The OS maintains a page table that maps virtual addresses to physical addresses.
Page Replacement: When memory is full, pages can be swapped between main memory and disk to
free space.
Flexibility: Variable-sized allocation lets processes request memory as needed, not limited to fixed
blocks.
Efficient Utilization: Small gaps may appear, but overall memory use can still be better than fixed-sized
allocation.
Simplicity: Strategies like first-fit or best-fit are easy and fast to implement, reducing overhead.
Dynamic Growth: Supports applications that expand memory usage over time by allocating differently
sized blocks.
Memory Consumption: Small, unusable intervals of memory accumulate, making it difficult to allocate
large chunks of memory even if there is sufficient free space
Reduced Performance: Over time, fragmentation can slow down memory allocation processes, as the
system must search for enough free space.
Need for Constant Wear: To prevent cracking, the system control may need to rotate (compress)
repeatedly, which can take time to wear down
Limits Program Growth : As memory fragmentation occurs, it can prevent the memory usage of
programs from expanding, causing inefficiency or corruption
The Buddy Allocation System is a memory management technique that divides a large memory block
into smaller power-of-two blocks called buddies.
If a request comes in, the block is repeatedly split until a suitable size is reached.
When memory is freed, its buddy is checked — if also free, they merge back to form a larger block.
Below are the steps involved in the Buddy System Memory Allocation Technique:
17 | P a g e
Divide memory into blocks of size power-of-two (2, 4, 8, 16, 32, 64, …).
On a request, find the smallest block that fits. If too large, split until the required size is reached.
Illustration
We can see that if we further divide 32 in half it will be 16, which is less than 18 i.e. insufficient to
store 18, therefore we can't split the memory further and 32 will become our leaf node.
Scalability: Handles large memory efficiently by splitting into smaller blocks and adjusting dynamically.
Efficient Splitting & Merging: Blocks split into equal buddies when allocated; merged back when both
are free.
Power-of-Two Blocks: Memory divided into 1KB, 2KB, 4KB… simplifies splitting and merging.
Efficient memory use, reduced fragmentation, and fast allocation/deallocation. Drawback: internal
fragmentation (allocated block may be larger than needed). Useful for OS, especially in embedded
systems with limited memory.
Let total memory = 2U2U and a request of size SS. It will be handled as:
18 | P a g e
Else, recursively divide the block into two equal buddies until the smallest suitable block is found.
The system also keeps a record of all the unallocated blocks and can merge these different-sized blocks
to make one big chunk.
Additional rules:
Splitting Rule: Always allocate the left buddy (lower address) first.
The following figure illustrates the implementation of buddy system, considering a 1024k (1-
megabyte) initial block and the process requests as shown at the left of the table.
Flow of allocation
19 | P a g e
Types of Buddy System
The Buddy System is a memory allocation method where blocks are split and merged for efficient use.
Different types of Buddy Systems exist to suit specific needs and optimizations in various systems.
On request, the nearest larger block is chosen and split repeatedly into equal halves (buddies) until
the required size is reached.
Example: If total memory = 256KB and request = 25KB nearest power of two is 32KB.
A variation of the buddy system where memory blocks are divided into sizes based on Fibonacci
numbers instead of powers of two.
Zi = Z(i-1)+Z(i-2)
On a memory request, the system finds the smallest Fibonacci block that can satisfy it.
Like binary buddies, free blocks can be merged (coalesced) into larger Fibonacci-sized blocks.
In a weighted peer system, each memory block is associated with a weight, which represents its size
relative to other blocks. When a memory allocation request occurs, the system searches for the
appropriate block considering the size of the requested memory and the weight of the available
blocks.
In a traditional buddy system, memory is divided into blocks of fixed size, usually a power of 2, and
allocated to these blocks but the tertiary buddy system introduces a third memory structure, which
allows flexibility large in memory allocation.
20 | P a g e
Advantages
Drawbacks
Note: These non-contiguous blocks of memory can be located anywhere in the physical memory.
Non-contiguous allocation involves the use of pointers to link the non-contiguous memory blocks
allocated to a process. These pointers are used to keep track of the memory blocks allocated to the
process and to locate them during the execution of the process.
Non-Contiguous Allocation
21 | P a g e
Paging: It breaks processes into equal-sized pages and maps them to memory frames, mainly to
eliminate external fragmentation.
Segmentation: It divides processes into variable-sized logical segments (like code, data, stack),
supporting protection, sharing, and logical organization.
Segmented Paging: A hybrid technique that first divides processes into logical segments and then
splits each segment into fixed-size pages, combining the benefits of segmentation and paging.
It has the advantage of reducing memory wastage but it increases the overheads due to address
translation, which results in slow execution.
Note: Paging avoids external fragmentation but may suffer from internal fragmentation.
A process is divided into parts that can be stored in different free spaces of main memory (not
necessarily consecutive).
Example: If a process P=4KBP=4KB and memory has two free slots of 2KB2KB each, contiguous
allocation fails (no spanning allowed). In non-contiguous allocation, PP is split into two 2KB2KB parts,
each fitting into the free slots.
In contiguous allocation:
In Non-Contiguous allocation:
The process can be divided into different parts hence filling the space in the main memory.
In this example, process PP can be divided into two parts of equal size -> 2KB2KB.
Hence one part of process PP can be allocated to the first 2KB2KB space of main memory and the
other part of the process can be allocated to the second 2KB2KB space of main memory.
22 | P a g e
In what manner we divide a process to allocate them into main memory? The process is divided after
analyzing the number of empty spaces and their size in the main memory. But, it has some challenge:
Dividing processes dynamically based on changing free space is time-consuming as their sizes changing
every time due to execution of already present processes in main memory.
In order to avoid this time-consuming process, we divide our process in secondary memory in advance
before reaching the main memory for its execution. Every process is divided into various parts of equal
size called Pages. We also divide our main memory into different parts of equal size called Frames. It
is important to understand that:
Rule: pageSize=frameSize.
Example with Paging: If frame size = 2KB2KB, processes P1P1 and P2P2 (22 pages each) can be stored
alternately across free frames in memory.
Resolvent main memory, In main memory the sequence of storage of pages are: First page of P1 ->
First page of P2 -> Second page of P1 -> Second page of P2
23 | P a g e
Pages Distribution
Note: Non-contiguous allocation (via paging) divides processes into pages and memory into frames,
ensuring flexible and efficient use of memory without requiring consecutive space.
Reduced Internal Fragmentation : Memory blocks are allocated as per process needs; unused space
inside blocks is minimized.
Flexible Allocation : Processes can be loaded wherever free memory is available, without requiring a
large continuous block.
Better Memory Utilization : Small gaps in memory can be efficiently used to fit parts of different
processes.
Supports Dynamic Loading & Growth : Processes that expand (like stack/heap) can take memory from
scattered free blocks.
Enables Virtual Memory : Forms the basis of schemes like paging and segmentation, allowing
processes to use more memory than physically available.
External Fragmentation : Free memory may be broken into many small scattered blocks, making it
hard to allocate large memory requests.
Overhead of Address Mapping : Requires complex data structures (page tables, segment tables or
linked lists) to keep track of allocated blocks.
Slower Access : Address translation and pointer chasing increase access time compared to contiguous
allocation.
Memory Management Overhead : Additional hardware (MMU : Memory Management Unit) and OS
routines are needed for mapping logical to physical addresses.
Complex Deallocation : Releasing and merging free memory blocks is more complicated, increasing OS
overhead.
Possibility of Page Faults (in Paging-based systems) : Since data is scattered, a needed page may not
be in memory, causing delays.
24 | P a g e
Paging in Operating System
Paging is the process of moving parts of a program, called pages, from secondary storage into the main
memory (RAM). The main idea behind paging is to break a program into smaller fixed-size blocks called
pages.
The whole process does not have to be in main memory, some pages can be present and some pages
can be loaded when needed. It allows more processes and even processes larger than main memory
to run.
To keep track of where each page is stored in memory, the operating system uses a page table. This
table shows the connection between the logical page numbers and the physical page frames (actual
locations in RAM).
Note: The memory management unit uses the page table to convert logical addresses into physical
addresses, so the program can access the correct data in memory.
Paging addresses common challenges in allocating and managing memory efficiently. Why paging is
needed as a Memory Management technique:
Memory isn’t always available in a single block: Programs often need more memory than what is
available in a single continuous block. Paging breaks memory into smaller, fixed-size pieces, making it
easier to allocate scattered free spaces.
Processes size can increase or decrease: programs don’t need to occupy continuous memory, so they
can grow dynamically without the need to be moved.
25 | P a g e
Terminologies Associated with Memory Control
Logical Address Space or Virtual Address Space: The Logical Address Space, refers to the set of all
possible logical addresses that a process can generate during its execution.
Physical Address Space: The Physical Address Space refers to the total range of addresses available in
a computer's physical memory (RAM).
Logical to physical address mapping: Paging divides a process's logical address space into fixed-size
pages. Each page maps to a frame in physical memory, enabling flexible memory management.
Fixed page and frame size: Pages and frames have the same fixed size. This simplifies memory
management and improves system performance.
Page table entries: Each logical page is represented by a page table entry (PTE). A PTE stores the
corresponding frame number and control bits.
Number of page table entries: The page table has one entry per logical page. Thus, its size equals the
number of pages in the process's address space.
Page table stored in main memory: The page table is kept in main memory. This can add overhead
when processes are swapped in or out.
Working of Paging
When a process requests memory, the operating system allocates one or more page frames to the
process and maps the process's logical pages to the physical page frames. When a program runs, its
pages are loaded into any available frames in the physical memory.
Working of Paging
26 | P a g e
Each program has a page table, which the operating system uses to keep track of where each page is
stored in physical memory. When a program accesses data, the system uses this table to convert the
program's address into a physical memory address.
If Logical Address Space = 128 M words = 27 * 220 words, then Logical Address = log2 227 = 27 bits
If Physical Address Space = 16 M words = 24 * 220 words, then Physical Address = log2 224 = 24 bits
The mapping from virtual to physical address is done by the Memory Management Unit
(MMU) which is a hardware device and this mapping is known as the paging technique.
The Physical Address Space is conceptually divided into a number of fixed-size blocks, called frames.
The Logical Address Space is also split into fixed-size blocks, called pages.
Example
Page number(p): Number of bits required to represent the pages in Logical Address Space or Page
number
Page offset(d): Number of bits required to represent a particular word in a page or page size of
Logical Address Space or word number of a page or page offset.
Frame Number(f): Number of bits required to represent the frame of Physical Address Space or
Frame number frame
Frame Offset(d): Number of bits required to represent a particular word in a frame or frame size of
Physical Address Space or word number of a frame or frame offset.
Physical Address = (Frame Number << Number of Bits in Frame Offset) + Frame Offset
where "<<" represents a bitwise left shift operation.
27 | P a g e
Hardware implementation of Paging
The hardware implementation of the page table can be done by using dedicated registers. But the
usage of the register for the page table is satisfactory only if the page table is small. If the page table
contains a large number of entries then we can use TLB(translation Look-aside buffer), a special, small,
fast look-up hardware cache.
When this memory is used, then an item is compared with all tags simultaneously. If the item is found,
then the corresponding value is returned.
Main memory access time = m, If page table are kept in main memory, Effective access time = m(for
page table) + m(for particular page in page table)
Advantages of Paging
Eliminates External Fragmentation: Paging divides memory into fixed-size blocks (pages and frames),
so processes can be loaded wherever there is free space in memory. This prevents wasted space due
to fragmentation.
Efficient Memory Utilization: Since pages can be placed in non-contiguous memory locations, even
small free spaces can be utilized, leading to better memory allocation.
Supports Virtual Memory: Paging enables the implementation of virtual memory, allowing processes
to use more memory than physically available by swapping pages between RAM and secondary
storage.
Ease of Swapping: Individual pages can be moved between physical memory and disk (swap space)
without affecting the entire process, making swapping faster and more efficient.
Improved Security and Isolation: Each process works within its own set of pages, preventing one
process from accessing another's memory space.
28 | P a g e
Disadvantages of Paging
Internal Fragmentation: If the size of a process is not a perfect multiple of the page size, the unused
space in the last page results in internal fragmentation.
Increased Overhead: Maintaining the Page Table requires additional memory and processing. For
large processes, the page table can grow significantly, consuming valuable memory resources.
Page Table Lookup Time: Accessing memory requires translating logical addresses to physical
addresses using the page table. This step increases memory access time, although TLBs can help
reduce the impact.
I/O Overhead During Page Faults: When a required page is not in physical memory (page fault), it
needs to be fetched from secondary storage, causing delays and increased I/O operations.
Segmentation
It reflects the user’s view of memory rather than the computer’s physical organization, making it easier
to manage and protect processes.
1. Variable-sized divisions: Segments can have different lengths, depending on the program’s
requirements.
2. Logical division of memory: Segments represent meaningful units like code, stack, data, or modules.
3. Two-part address: A logical address consists of:
4. Protection and sharing: Different segments can have access rights (read, write, execute) and can be
shared among processes.
6. External fragmentation: Can occur when free memory is divided into small scattered blocks.
Virtual Memory Segmentation: Each process is divided into a number of segments, but the
segmentation is not done all at once. This segmentation may or may not take place at the run time of
the program.
Simple Segmentation: Each process is divided into a number of segments, all of which are loaded into
memory at run time, though not necessarily contiguously.
29 | P a g e
There is no simple relationship between logical addresses and physical addresses in segmentation. A
table stores the information about all such segments and is called Segment Table.
It maps a two-dimensional Logical address into a one-dimensional Physical address. It's each table
entry has:
Base Address: It contains the starting physical address where the segments reside in memory.
Segment Limit: Also known as segment offset. It specifies the length of the segment.
Segmentation
30 | P a g e
The address generated by the CPU is divided into:
Segment offset (d): Number of bits required to represent the position of data within a
segment.
Reduced Internal Fragmentation: Segments are sized as per program needs, minimizing wasted
space.
Better CPU Utilization: Entire modules are loaded at once, improving performance.
Closer to User’s View: Programs can be divided into logical modules, matching how users think.
User-Controlled Size: Segment size is defined by the user, unlike fixed page size in paging.
Security & Separation: Segments help isolate sensitive data and operations.
Slower Access: Two memory lookups (segment table + main memory) increase access time.
Segmentation Faults: Errors may occur if a program tries to access memory outside its segment.
Page Table
A Page Table is a data structure that maps virtual addresses (used by processes) to physical addresses
(actual locations in memory). The size and format of a PTE vary by system architecture and OS, but it
always contains enough information for efficient memory management and protection.
Note: Each mapping in the table is stored in a Page Table Entry (PTE), which Information Stored in
Page Table Entry
A Page Table Entry (PTE) stores the necessary metadata about a page, allowing the system to manage
memory safely and efficiently. The exact format and size of a PTE depend on the system’s architecture
(32-bit, 64-bit) and the operating system implementation, but typical fields include the following:
1. Frame Number
31 | P a g e
Present (1): Page is in physical memory.
Absent (0): Page fault occurs when accessed and the OS must load it from disk.
3. Protection Bits
Read (R)
Execute (X)
4. Referenced Bit
5. Caching Enabled/Disabled
Use case example: Disable caching for memory-mapped I/O (keyboard or hardware registers) to
always get fresh data.
If set (1), the page must be written back to disk when evicted; otherwise, it can be discarded.
If each PTE takes 4 bytes, total Page Table size ≈220×4 bytes=4 MB≈220×4 bytes=4 MB
Note: For 64-bit systems, a flat page table becomes too large, so hierarchical structures (multi-level
page tables) are used to manage memory efficiently.
Efficient Memory Use: Only allocates frames for pages that are actually used.
Protection: Control over access permissions helps prevent illegal memory access.
32 | P a g e
Address Translation: Seamless mapping of virtual to physical addresses with little programmer
involvement.
Scalability: Hierarchical page tables (e.g., 4-level page table in x86-64) handle huge address spaces
without huge memory overhead.
Virtual memory is a memory management technique used by operating systems to give the
appearance of a large, continuous block of memory to applications, even if the physical memory (RAM)
is limited and not necessarily allocated in contiguous manner. The main idea is to divide the process
in pages, use disk space to move out the pages if space in main memory is required and bring back the
pages when needed.
A program doesn’t need to be fully loaded in memory to run. Only the needed parts are loaded.
Programs can be bigger than the physical memory available in the system.
Virtual memory creates the illusion of a large memory, even if the actual memory (RAM) is small.
It uses both RAM and disk storage to manage memory, loading only parts of programs into RAM as
needed.
This allows the system to run more programs at once and manage memory more efficiently.
When a program runs, it uses virtual addresses (not real memory locations).
The computer system converts these virtual addresses into physical addresses (actual locations in
RAM) while the program runs.
33 | P a g e
Types of Virtual Memory
In a computer, virtual memory is managed by the Memory Management Unit (MMU), which is often
built into the CPU. The CPU generates virtual addresses that the MMU translates into physical
addresses. There are two main types of virtual memory: Paging and Segmentation
1. Paging
Paging divides memory into small fixed-size blocks called pages. When the computer runs out of RAM,
pages that aren't currently in use are moved to the hard drive, into an area called a swap file. Here,
When a page is needed again, it is swapped back into RAM, a process known as page swapping.
This ensures that the operating system (OS) and applications have enough memory to run.
Page Fault Service Time: The time taken to service the page fault is called page fault service time. The
page fault service time includes the time taken to perform all the above six steps.
Page and Frame: Page is a fixed size block of data in virtual memory and a frame is a fixed size block
of physical memory in RAM where these pages are loaded.
Think of a page as a piece of a puzzle (virtual memory) While, a frame as the spot where it fits on the
board (physical memory).
When a program runs its pages are mapped to available frames so the program can run even if the
program size is larger than physical memory.
2. Segmentation
Segmentation divides virtual memory into segments of different sizes. Segments that aren't currently
needed can be moved to the hard drive. Here,
The system uses a segment table to keep track of each segment's status, including whether it's in
memory, if it's been modified and its physical address.
Segments are mapped into a process's address space only when needed.
Virtual memory has the following important characteristics that increase the capabilities of the
computer system.
Increased Effective Memory: It enables a computer to have more memory than the physical memory
using the disk space. This allows for the running of larger applications.
34 | P a g e
Memory Isolation: Virtual memory allocates a unique address space to each process, such separation
increases safety and reliability based on the fact that one process cannot interact with another.
Efficient Memory Management: Virtual memory also helps in better utilization of the physical
memories through methods that include paging and segmentation.
Simplified Program Development: For case of programmers, they can program ‘as if’ there is one big
block of memory and this makes the programming easier and more efficient in delivering more
complex applications.
Manual Configuration: For tuned up users, the setting of the custom size can sometimes boost up the
performance of the system. The initial size is usually advised to be set to the minimum value of 1.
SSD Placement: If this is feasible, the page file should be stored in the SSD instead of the HDD as a
storage device. It has better read and write times and the virtual memory may prove beneficial in an
SSD.
Separate Drive: Regarding systems having multiple drives involved, the page file needs to be placed
on a different drive than the OS and that shall in turn improve its performance.
Performance Monitoring: Employ the software tools used in monitoring the performance of the
system in tracking the amounts of virtual memory.
Regular Maintenance: Make sure there is no toolbar or other application running in the background,
take time and uninstall all the tool bars to free virtual memory.
Sufficient RAM: If for instance your system has a big physical memory,
Example: 16GB and above then it would be advised to freeze the page file in order to
minimize SSD usage. But it should be done, carefully and only if the additional signals that one decides
to feed into his applications should not likely use all the available RAM.
System Configuration: Change some general properties of the system concerning virtual memory
efficiency. This also involves enabling additional control options in Windows.
Regular Updates: Ensure that your drivers are run in their newest version because new releases
contain some enhancements and issues regarding memory management.
35 | P a g e
Benefits of Using Virtual Memory
Supports Multiprogramming & Larger Programs : Virtual memory allows multiple processes to reside
in memory at once by using demand paging. Even programs larger than physical memory can be
executed efficiently.
Maximizes Application Capacity : With virtual memory, systems can run more applications
simultaneously, including multiple large ones. It also allows only portions of programs to be loaded at
a time, improving speed and reducing memory overhead.
Eliminates Physical Memory Limitations : There's no immediate need to upgrade RAM as virtual
memory compensates using disk space.
Boosts Security & Isolation : By isolating the memory space for each process, virtual memory enhances
system security. This prevents interference between applications and reduces the risk of data
corruption or unauthorized access.
Improves CPU & System Performance: Virtual memory helps the CPU by managing logical
partitions and memory usage more effectively. It allows for cost-effective, flexible resource allocation,
keeping CPU workloads optimized and ensuring smoother multitasking.
Slower Performance: Virtual memory can slow down the system, because it often needs to move data
between RAM and the hard drive.
Risk of Data Loss: There is a higher risk of losing data if something goes wrong, like a power failure or
hard disk crash, while the system is moving data between RAM and the disk.
More Complex System: Managing virtual memory makes the operating system more complex. It has
to keep track of both real memory (RAM) and virtual memory and make sure everything is in the right
place.
36 | P a g e
What is Demand Paging in Operating System?
Demand paging is a technique used in virtual memory systems where pages enter main memory only
when requested or needed by the CPU. OS loads only the necessary pages of a program into memory
at runtime, instead of loading the entire program into memory at the start. Here, A page fault
occurred when the program needed to access a page that is not currently in memory.
The operating system then loads the required pages from the disk into memory and updates the page
tables accordingly.
This process is transparent to the running program and it continues to run as if the page had always
been in memory.
Pure demand paging is a specific implementation of demand paging. In on-demand paging only, no
pages are initially loaded into memory when the program starts and all pages are initially marked as
being on disk.
Operating systems that use pure demand paging as a memory management strategy do so without
preloading any pages into physical memory prior to the commencement of a task.
Demand paging loads a process's whole address space into memory one step at a time, bringing just
the parts of the process that are actively being used into memory from disc as needed.
It is useful for executing huge programs that might not fit totally in memory or for computers with
limited physical memory. If the program accesses a lot of pages that are not in memory right now, it
could also result in a rise in page faults and possible performance overhead.
Operating systems frequently use caching techniques and improve page replacement algorithms to
lessen the negative effects of page faults on system performance as a whole.
Working Process of Demand Paging: Let us understand this with the help of an example. Suppose we
want to run a process P which have four pages P0, P1, P2 and P3. Currently, in the page table, we have
pages P1 and P3.
37 | P a g e
The operating system's demand paging mechanism follows a few steps in its operation:
Program Execution: Upon launching a program, the operating system allocates a certain amount of
memory to the program and establishes a process for it.
Creating Page Tables: To keep track of which program pages are currently in memory and which are
on disk, the operating system makes page tables for each process.
Handling Page Fault: When a program tries to access a page that isn't in memory at the moment, a
page fault happens. In order to determine whether the necessary page is on disk, the operating system
pauses the application and consults the page tables.
Page Fetch: The operating system loads the necessary page into memory by retrieving it from the disk
if it is there.
The page's new location in memory is then reflected in the page table.
Resuming The Program: The operating system picks up where it left off when the necessary pages are
loaded into memory.
Page Replacement: If there is not enough free memory to hold all the pages a program needs, the
operating system may need to replace one or more pages currently in memory with pages currently
in memory. on the disk. The page replacement algorithm used by the operating system determines
which pages are selected for replacement.
Page Cleanup: When a process terminates, the operating system frees the memory allocated to the
process and cleans up the corresponding entries in the page tables.
Demand paging can improve system performance by reducing the memory needed for programs and
allowing multiple programs to run simultaneously.
When a program needs a part that isn’t in the main memory, the operating system must fetch it from
the hard disk, which takes time and pauses the program.
This can cause delays and if the system runs out of memory, it will need to frequently swap pages in
and out, increasing delays and reducing performance.
If a program needs a page that isn’t currently in memory, the system fetches it from the hard disk.
Several algorithms manage this process:
FIFO (First-In-First-Out): Replaces the oldest page in memory with a new one. It’s simple but can cause
issues if pages are frequently swapped in and out, leading to thrashing.
LRU (Least Recently Used): Replaces the page that hasn’t been used for the longest time. It reduces
thrashing more effectively than FIFO but is more complex to implement.
LFU (Least Frequently Used): Replaces the page used the least number of times. It helps reduce
thrashing but requires extra tracking of how often each page is used.
38 | P a g e
MRU (Most Recently Used): Replaces the page that was most recently used. It’s simpler than LRU but
not as effective in reducing thrashing.
Random: Randomly selects a page to replace. It’s easy to implement but unpredictable in
performance.
Demand paging
It loads pages from disk into main memory only when they are needed by a program.
This approach saves memory space by keeping only the required pages in memory, reducing memory
allocation costs and improving memory use.
However, the initial access time for pages not in memory can delay program execution.
Pre-paging
It loads multiple pages into main memory before they are needed by a program.
It assumes that if one page is needed, nearby pages will also be needed soon.
Pre-paging can speed up program execution by reducing delays caused by demand paging but can lead
to unnecessary memory allocation and waste.
A page fault occurs when a program attempts to access data or code that is in its address space but is
not currently located in the system RAM. This triggers a sequence of events where the operating
system must manage the fault by loading the required data from secondary storage into RAM.
Note: Page faults are essential for implementing virtual memory systems that provide the illusion of
a larger contiguous memory space.
39 | P a g e
Steps for Page Fault Handling
Trap to Kernel: The computer hardware traps to the kernel and program counter (PC) is saved on the
stack. Current instruction state information is saved in CPU registers. The hardware detects the page
fault when the CPU attempts to access a virtual page that is not currently in physical memory (RAM).
Save State Information: An assembly program is started to save the general registers and other volatile
information to keep the OS from destroying it.
Determine Cause of Fault: Operating system finds that a page fault has occurred and tries to find out
which virtual page is needed. Sometimes hardware register contains this required information. If not,
the operating system must retrieve PC, fetch instruction and find out what it was doing when the fault
occurred.
Validate Address: Once virtual address caused page fault is known, system checks to see if address is
valid and checks if there is no protection access problem.
Allocate Page Frame: If the virtual address is valid, the system checks to see if a page frame is free. If
no frames are free, the page replacement algorithm is run to remove a page.
Handle Dirty Pages: If frame selected is dirty, page is scheduled for transfer to disk, context switch
takes place, fault process is suspended and another process is made to run until disk transfer is
completed.
Load Page into Memory: As soon as page frame is clean, operating system looks up disk address where
needed page is, schedules disk operation to bring it in.
Update Page Table: When disk interrupt indicates page has arrived, page tables are updated to reflect
its position, and frame marked as being in normal state.
Restore State and Continue Execution: Faulting instruction is backed up to state it had when it began,
and PC is reset. Faulting is scheduled, operating system returns to routine that called it. Assembly
Routine reloads register and other state information, returns to user space to continue execution.
Demand Paging: Accessing the page that is not currently loaded in the memory (RAM).
Invalid Memory Access, it occurs when a program tries to access that memory which is it's beyond
access boundaries or not allocated.
Process Violation: when a process tries to write to a read-only page or otherwise violates memory
protection rules.
Minor Page Fault: Occurs when the required page is in memory but not in current process's page table.
Major Page Fault: Occurs when the page is not in memory and must be fetched from disk.
Invalid Page Fault: It happens when the process tries to access an invalid memory address.
40 | P a g e
Thrashing: If occurrence of page fault is frequent then the system spends more time to handle it than
executing the processes, and because of which overall performance also degrades.
Increased Latency: Fetching pages from disk takes more time than accessing them in memory, which
causes to more delays.
CPU Utilization: If the Page fault occur excessively than it can reduce CPU Utilization as the processor
waits for for memory operations to complete or remain idle which is not efficient.
Modern operating systems use both physical memory (RAM) and virtual memory to manage processes
efficiently. Swap space (also called paging space or swap file) plays a key role in this memory
management strategy. It is a dedicated area on the hard disk used by the operating system as an
extension of physical RAM
Swapping
Note: Swap space enables the OS to handle memory more flexibly, supporting the illusion of a larger
memory than physically available, thus improving multitasking and stability of the system.
When physical memory (RAM) is full, the OS selects some memory pages that are inactive or least
recently used (using algorithms like LRU – Least Recently Used).
These pages are written from RAM to the swap space on the disk.
When those pages are needed again, they are read back from the swap space into RAM.
This process of moving pages between RAM and disk is called swapping or paging.
Note: Despite its usefulness, accessing swap space is much slower than RAM due to disk I/O delays.
41 | P a g e
Optimal Swap Space Size
A general rule of thumb recommends swap space size to be about 1.5 times the size of physical RAM.
However, the exact swap size depends on the system's use case:
Systems with high RAM and low memory usage may need less swap.
Memory-intensive applications or environments with many background processes may require more
swap.
Note: Modern systems with large amounts of RAM often use much smaller swap sizes, just to handle
exceptional cases.
Virtual Memory Extension: Allows processes to operate as if there is more memory available than the
system physically has.
Increased System Stability: Prevents system crashes when RAM is exhausted by providing additional
space.
Efficient Multitasking: Frees up physical memory for more active processes and critical operations.
Supports Memory-Intensive Applications: Enables running large applications that require more
memory than physically available.
Performance Degradation: Reading from and writing to swap space is orders of magnitude slower than
accessing RAM.
Disk Space Consumption: Swap space occupies significant hard disk space, which may reduce space
available for files and applications.
Thrashing: Excessive swapping (when the system spends most of its time swapping pages rather than
executing useful tasks) severely hampers performance.
Data Loss Risk: If a power failure occurs while a page is in swap space and not yet committed back to
disk, data may be lost.
42 | P a g e
Page Replacement Algorithms in Operating Systems
In an operating system that uses paging, a page replacement algorithm is needed when a page fault
occurs and no free page frame is available. In this case, one of the existing pages in memory must be
replaced with the new page.
The virtual memory manager performs this by: Selecting a victim page using a page replacement
algorithm. Marking its page table entry as “not present.” If the page was modified (dirty), writing it
back to disk before replacement.
The efficiency of a page replacement algorithm directly affects the page fault rate, which in turn
impacts system performance.
This is the simplest page replacement algorithm. In this algorithm, the operating system keeps track
of all pages in the memory in a queue, the oldest page is in the front of the queue. When a page needs
to be replaced page in the front of the queue is selected for removal.
Example 1: Consider page reference string 1, 3, 0, 3, 5, 6, 3 with 3-page frames. Find the number of
page faults using FIFO Page Replacement Algorithm.
Initially, all slots are empty, so when 1, 3, 0 came they are allocated to the empty slots ---> 3 Page
Faults.
Then 5 comes, it is not available in memory, so it replaces the oldest page slot i.e 1. ---> 1 Page Fault.
6 comes, it is also not available in memory, so it replaces the oldest page slot i.e 3 ---> 1 Page Fault.
43 | P a g e
2. Optimal Page Replacement
In this algorithm, pages are replaced which would not be used for the longest duration of time in the
future. Example: Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4-page frame.
Find number of page fault using Optimal Page Replacement Algorithm.
Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots ---> 4 Page faults
0 is already there so ---> 0 Page fault. when 3 came it will take the place of 7 because it is not used for
the longest duration of time in the future---> 1 Page fault.
0 is already there so ---> 0 Page fault. 4 will takes place of 1 ---> 1 Page Fault.
Now for the further page reference string ---> 0 Page fault because they are already available in the
memory. Optimal page replacement is perfect, but not possible in practice as the operating system
cannot know future requests. The use of Optimal Page replacement is to set up a benchmark so that
other replacement algorithms can be analyzed against it.
In this algorithm, page will be replaced which is least recently used. Example Consider the page
reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 3 with 4-page frames. Find number of page faults
using LRU Page Replacement Algorithm.
44 | P a g e
Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots ---> 4 Page faults.
0 is already there so ---> 0 Page fault. when 3 came it will take the place of 7 because it is least recently
used ---> 1 Page fault.
Now for the further page reference string ---> 0 Page fault because they are already available in the
memory.
In this algorithm, page will be replaced which has been used recently. Belady's anomaly can occur in
this algorithm.
Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty slots ---> 4 Page faults
when 3 comes it will take place of 0 because it is most recently used ---> 1 Page fault
45 | P a g e
Thrashing
Thrashing occurs when the operating system spends more time swapping pages between main
memory and disk than executing processes. This leads to excessive page faults and a significant drop
in CPU utilization.
High degree of multiprogramming: Too many processes are loaded into memory.
This repeated cycle of low CPU utilization → more processes → more page faults is called Thrashing.
Locality Model
For example, when a function is called, instructions, local variables, and global references define a
locality.
If the number of frames allocated to a process covers its current locality → few page faults.
If frames are fewer than the locality size → frequent page faults → thrashing.
Thrashing happens when active localities of multiple processes cannot fit into memory
simultaneously.
Based on the Locality Model: a process uses a set of pages (locality) actively at a time.
If enough frames are allocated to cover the current locality few page faults.
46 | P a g e
Working Set (WSSᵢ) = pages referenced in the last Δ references (window size).
Cases:
If D ≤ m i.e No thrashing.
Accuracy depends on Δ:
PFF is a technique to control thrashing by directly monitoring the page fault rate of processes.
Working:
Define an upper limit and a lower limit for acceptable page fault rate.
If fault rate > upper limit, give more frames to the process.
If no free frames are available suspend some processes and reallocate frames.
47 | P a g e
In paging, internal fragmentation arises because memory is divided into fixed-size frames, and processes may not completely fill these frames, leaving unused space in each . This results in inefficient memory utilization as not all allocated space is used by the process. The scattered partially filled frames can also increase the number of I/O operations, leading to performance degradation and increased page faults in virtual memory systems .
Demand paging involves loading only the necessary pages of a program into physical memory when the pages are accessed by the CPU. It avoids loading the entire program, thus optimizing memory use and allowing more programs to run simultaneously . However, frequent page faults can occur, potentially leading to thrashing and system performance degradation as the system spends more time swapping pages than executing processes .
Pure demand paging can negatively impact system performance because it loads pages into memory only when needed, increasing the likelihood of page faults when a program accesses a non-resident page . This results in frequent disk accesses, which are much slower than RAM access, thus increasing latency and reducing CPU utilization as the CPU must wait for memory operations to complete before proceeding .
Non-contiguous memory allocation reduces external fragmentation by allowing a process to occupy non-adjacent frames in memory, facilitating better utilization by fitting scattered free spaces . This improves flexibility and reduces the need for contiguous blocks, which is beneficial for large processes that may not fit contiguous spaces . However, it introduces complexity in memory management as it requires robust mapping tables like page tables or segment tables . Conversely, contiguous allocation is simpler but can lead to high external fragmentation if large contiguous space is not available .
Fixed partition allocation results in internal fragmentation because memory is divided into fixed-sized partitions, and a process may not use the entire allocated partition, leading to wasted space inside the partition . In contrast, dynamic partition allocation adapts partition sizes to match process sizes, reducing internal fragmentation; however, it is susceptible to external fragmentation, leaving scattered free spaces in memory that may not fit new processes .
Segmented paging combines the benefits of segmentation and paging by first dividing processes into logical segments and then further splitting each segment into fixed-size pages . It reduces memory wastage and supports logical organization, protection, and sharing. However, it introduces overheads in address translation due to its complex mapping requirements, leading to slower execution as each reference involves multi-level address translation .
Virtual memory creates the illusion of a large memory space by using disk storage as an extension of RAM, managing memory through paging or segmentation without requiring the full program to reside in physical memory at once . This enables larger programs to run on systems with limited RAM. However, it challenges the system with potential slower performance due to disk I/O operations, increased risk of data loss in case of failure during data movement, and added complexity in managing both virtual and physical memory .
Non-contiguous memory allocation, such as paging and segmentation, addresses external fragmentation by allowing processes to be allocated in scattered memory locations rather than contiguous blocks . This allocation scheme uses page tables or segment tables to logically link the various non-adjacent blocks, maintaining the logical continuity of processes while eliminating the need for large contiguous free spaces .
The page table is essential for translating virtual addresses to physical addresses, facilitating efficient memory use by only allocating frames for pages that are used . In large address spaces, flat page tables become too large, so hierarchical page tables are employed, which manage memory efficiently by narrowing down needed entries and avoiding large memory overheads .
The buddy system manages memory by dividing it into blocks of a power of 2. It allows quick allocation and deallocation, efficiently uses memory, and coalesces free blocks to reduce fragmentation . Despite its efficiency, it suffers from internal fragmentation due to its fixed-size block constraint, which may allocate larger blocks than necessary, leaving unused space .