Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Aptitude
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • DBMS
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Algorithms
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
Open In App
Next Article:
Overlays in Memory Management
Next article icon

Overlays in Memory Management

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

overlays
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

Next Article
Overlays in Memory Management

S

Samit Mandal
Improve
Article Tags :
  • Misc
  • Operating Systems
  • GATE CS
Practice Tags :
  • Misc

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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences