Overlays in Memory Management
Last Updated :
28 Apr, 2025
Overlays are a memory management technique used to efficiently manage limited memory by loading only necessary parts of a program into memory at a time. This allows larger programs to run smoothly, even when the available memory is smaller than the program's size.
The basic idea behind overlays is to load only the portion of a program that is needed for the current task. The unused parts of the program are stored on disk or other storage and are loaded into memory as needed. Once a part of the program finishes executing, it is unloaded from memory, freeing up space for the next part to be loaded. This method allows programs to be larger than the available physical memory, without running into memory constraints.
In fixed partitioning, each process is assigned a fixed-sized partition. If a process exceeds the size of the partition, it cannot span across multiple partitions, leading to inefficient memory usage. Overlays solve this issue by allowing parts of the program to be loaded and unloaded as needed, making better use of the available memory.
How Overlays Work:
Overlay- The program is divided into smaller modules or segments.
- Only the module needed at a specific time is loaded into memory.
- Once the module finishes executing, it is unloaded, and another module is loaded into the same space.
- The program remains functional as only the necessary parts are in memory at any given time.
Example of Overlays: Assembler with Two Passes
Consider the example of an assembler that works in two passes. In this case, only one pass can be performed at a time. The assembler finishes the first pass, and once it's completed, it moves on to the second pass. Let's assume the available main memory size is 150 KB and the total code size is 200 KB. Here's how the program is structured:
- Pass 1: 70 KB
- Pass 2: 80 KB
- Symbol Table: 30 KB
- Common Routine: 20 KB
Problem:
Since the total code size is 200 KB, and the available memory is 150 KB, it is not possible to load both passes into memory at the same time. Therefore, we need to use the overlays technique to efficiently manage the memory.
How Overlays Work in This Case:
In this example, only one pass is needed at a time. Both passes always require the symbol table and common routine. So, the overlays technique works by loading one pass at a time, along with the shared symbol table and common routine, and then swapping out the pass once it is done.
Memory Requirements:
For Pass 1:
- Pass 1 = 70 KB
- Symbol Table = 30 KB
- Common Routine = 20 KB
- Overlays Driver = 10 KB
Total memory required for Pass 1 = 70 KB + 30 KB + 20 KB + 10 KB = 130 KB.
For Pass 2:
- Pass 2 = 80 KB
- Symbol Table = 30 KB
- Common Routine = 20 KB
- Overlays Driver = 10 KB
Total memory required for Pass 2 = 80 KB + 30 KB + 20 KB + 10 KB = 140 KB.
Minimum Partition Size:
Since Pass 1 requires 130 KB and Pass 2 requires 140 KB, the minimum partition size required for this overlay process is 140 KB. This allows us to load either pass into memory along with the shared resources (symbol table, common routine, and overlays driver) without exceeding the available memory.
Overlays Driver:
The overlays driver is the user's responsibility. The operating system does not provide an automatic mechanism for swapping the different parts of the program in and out of memory. The user must manually manage the overlay process.
- The user must load the required part (either Pass 1 or Pass 2) into memory.
- After one pass completes, the user must unload that pass from memory and load the next pass.
- The overlays driver facilitates this by managing the swapping of code in and out of memory.
Question -
The overlay tree for a program is as shown below:Â

What will be the size of the partition (in physical memory) required to load (and run) this program?Â
(a) 12 KB (b) 14 KB (c) 10 KB (d) 8 KBÂ
Explanation -Â
Using the overlay concept we need not actually have the entire program inside the main memory.Only we need to have the part which are required at that instance of time, either we need Root-A-D or Root-A-E or Root-B-F or Root-C-G part. Â
Root+A+D = 2KB + 4KB + 6KB = 12KB
Root+A+E = 2KB + 4KB + 8KB = 14KB
Root+B+F = 2KB + 6KB + 2KB = 10KB
Root+C+G = 2KB + 8KB + 4KB = 14KB
So if we have 14KB size of partition then we can run any of them.Â
Answer -(b) 14KBÂ
Advantages of using overlays include:
- Increased memory utilization: Overlays allow multiple programs to share the same physical memory space, increasing memory utilization and reducing the need for additional memory.
- Reduced load time: Only the necessary parts of a program are loaded into memory, reducing load time and increasing performance.
- Improved reliability: Overlays reduce the risk of memory overflow, which can cause crashes or data loss.
- Reduce memory requirement
- Reduce time requirement
Disadvantages of using overlays include:
- Complexity: Overlays can be complex to implement and manage, especially for large programs.
- Performance overhead: The process of loading and unloading overlays can result in increased CPU and disk usage, which can slow down performance.
- Compatibility issues: Overlays may not work on all hardware and software configurations, making it difficult to ensure compatibility across different systems.
- Overlap map must be specified by programmer
- Programmer must know memory requirement
- Overlapped module must be completely disjoint
- Programming design of overlays structure is complex and not possible in all cases
Similar Reads
Memory Allocation Techniques | Mapping Virtual Addresses to Physical Addresses
Prerequisite : Requirements of Memory Management System, Logical and Physical Address Memory Allocation Techniques:To store the data and to manage the processes, we need a large-sized memory and, at the same time, we need to access the data as fast as possible. But if we increase the size of memory,
5 min read
Paging in Operating System
Paging is the process of moving parts of a program, called pages, from secondary storage (like a hard drive) into the main memory (RAM). The main idea behind paging is to break a program into smaller fixed-size blocks called pages.To keep track of where each page is stored in memory, the operating s
8 min read
Page Table Entries in Page Table
A Page Table is a data structure used by the operating system to keep track of the mapping between virtual addresses used by a process and the corresponding physical addresses in the system's memory. A Page Table Entry (PTE) is an entry in the Page Table that stores information about a particular pa
7 min read
Inverted Page Table in Operating System
Most Operating Systems implement a separate page table for each process, i.e. for the 'n' number of processes running on a Multiprocessing/ Timesharing Operating System, there is an 'n' number of page tables stored in the memory. Sometimes when a process is very large and it occupies virtual memory
7 min read
Segmentation in Operating System
A process is divided into Segments. The chunks that a program is divided into which are not necessarily all of the exact sizes are called segments. Segmentation gives the user's view of the process which paging does not provide. Here the user's view is mapped to physical memory. Types of Segmentatio
4 min read
Partition Allocation Methods in Memory Management
In the operating system, the following are four common memory management techniques. Single contiguous allocation: Simplest allocation method used by MS-DOS. All memory (except some reserved for OS) is available to a process. Partitioned allocation: Memory is divided into different blocks or partiti
4 min read
Non-Contiguous Allocation in Operating System
Non-contiguous allocation, also known as dynamic or linked allocation, is a memory allocation technique used in operating systems to allocate memory to processes that do not require a contiguous block of memory. In this technique, each process is allocated a series of non-contiguous blocks of memory
6 min read
Fixed (or static) Partitioning in Operating System
Fixed partitioning, also known as static partitioning, is one of the earliest memory management techniques used in operating systems. In this method, the main memory is divided into a fixed number of partitions at system startup, and each partition is allocated to a process. These partitions remain
8 min read
Variable (or Dynamic) Partitioning in Operating System
In operating systems, Memory Management is the function responsible for allocating and managing a computerâs main memory. The memory Management function keeps track of the status of each memory location, either allocated or free to ensure effective and efficient use of Primary Memory. Below are Memo
4 min read
Buddy System - Memory Allocation Technique
Static partition techniques are limited by having a fixed number of active processes, and space use may not be optimal. The buddy system is a memory allocation and management technique that uses power-of-two increments. In this article, we are going to discuss the Buddy System in detail along with e
9 min read