Table of contents
1.
Introduction
2.
What is overlay in OS?
2.1.
Example of Overlays
3.
Usage of Overlays
4.
How does Overlays Work?
5.
Advantages of overlays in OS
6.
Disadvantages of overlays in OS
7.
Frequently Asked Questions
7.1.
What is the overlay effect in OS?
7.2.
What is the use of overlay in OS?
7.3.
What is memory management overlay?
7.4.
What's the difference between swapping and overlays?
7.5.
What are the types of overlays?
7.6.
What is overlapping in operating system? 
8.
Conclusion
Last Updated: Aug 1, 2024
Medium

Overlays in Memory Management

Author Sanjana Yadav
1 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Overlays in Memory Management

Memory Management is the operating system function that assigns and manages the computer's primary memory.  The capacity of the computer's memory was one of the key constraints imposed on programmers in the early days of computers. The application could not be loaded if it was larger than the available memory, severely limiting program size. The earliest and most fundamental mechanism for storing many processes in main memory is the Fixed Partitioning Technique. The underlying problem with fixed partitioning is that the size of a process is restricted by the maximum partition size, which implies that one process can never span another. The obvious solution would be expanding the available RAM, but this would significantly raise the cost of the computer system. So, earlier individuals have employed a method known as Overlays to tackle this problem.

What is overlay in OS?

Overlays in Memory Management operate on the premise that when a process runs, it does not consume the complete program at the same time but rather a subset of it.

Then, the overlaying concept is that you load whatever component you want, and when the section is completed, you unload it, which means you pull it back and get the new part you require and execute it.

Overlaying is defined as "the process of inserting a block of computer code or other data into internal memory, replacing what is already there."

It is a method that permits applications to be larger than the primary memory.

Because of the limitations of physical memory (internal memory for a system-on-chip) and the absence of virtual memory features, overlaying is generally employed by embedded systems.

Also See, FCFS Scheduling Algorithm

Example of Overlays

Let us take the example of an Assembler.

Consider that an assembler has two passes.

Having two passes indicates that it will only be performing one thing at a time, either the first or second pass.

 

This indicates that it will complete the first pass first, followed by the second pass.

Assume that the available main memory is 170KB and the overall code size is 230KB.

 

Pass 1.......................80KB

Pass 2.......................90KB

Symbol table.................30KB

Common routine...............20K

 

It is not feasible to utilize two passes at the same time since the overall code size is 230KB, and the primary memory size is 170KB.

So, we need to use the overlays technique here :

 

Overlays Driver: Overlaying is completely user-dependent. Even what component is necessary for the first pass should be written by the user. 

And after the first pass is completed, the user should write the code to take out pass 1 and load pass 2. This responsibility of the user is known as Overlays driver.

Suppose the Overlays driver is 10KB. 

Now we need to find out the minimum partition size required.

 

So, total memory needed for Pass 1=Pass1+Symbol Table+Common routine

                                                         = (80+30+20+10)KB= 140KB

Similarly, total memory needed for pass 2=(90+30+20+10)KB=150KB

So, To run the code easily, we need to have a partition of a minimum size of 150KB.
 

Must Read Process Management in OS

Usage of Overlays

  • Overlaying needs programmers to divide their object code into numerous independent portions known as overlays that are laid out in a tree structure.
  • Sibling segments, or those at the same depth level, share the same memory, referred to as the overlay area or the destination region.
  • When an overlay is required, an overlay manager, which is either part of the operating system or part of the overlay software, loads it from external memory into its target region. Often linkers provide support for overlays.
  • This technique requires the programmers to specify which overlay to load at different circumstances.

 

For example, the overlay tree for a program is as shown below:

Overlays in OS

Using the overlay approach, we don't need to keep the complete application in the main memory.

Only the component necessary at that point in time is required.

Either we need  Root-P-S or Root-P-T or Root-Q-U or Root-R-V part.

Root+P+S = 2KB + 4KB + 6KB = 12KB

Root+P+T = 2KB + 4KB + 8KB = 14KB

Root+Q+U = 2KB + 6KB + 2KB = 10KB

Root+R+V = 2KB + 8KB + 4KB = 14KB

So, if we have a partition of size 14KB, we may execute any of them.                                                                

How does Overlays Work?

Overlays are graphical elements that float above the main content on a webpage or application. They can be used for various purposes such as displaying menus, dialogs, notifications, or tooltips. Overlays typically dim or blur the background to draw attention to the overlay content. They can be triggered by user actions like clicking a button or hovering over an element. JavaScript, CSS, and HTML are often used to create and manage overlays, ensuring they are responsive and visually appealing.

Advantages of overlays in OS

  • It reduced the need for memory.
  • Reduced the time required.
  • Enables dynamic loading and unloading of modules as needed.
  • Enhances overall system performance.

Disadvantages of overlays in OS

  • The programmer must specify the overlap map.
  • The programmer must be aware of the memory requirements.
  • Modules that overlap must be totally separate.
  • Overlay programming structure is complicated and not always possible.


You can also read about the interleave memory. and Memory hierarchy in computer network

Frequently Asked Questions

What is the overlay effect in OS?

In operating systems, the overlay effect allows running programs larger than available memory by loading only essential program parts into memory as needed, swapping out others. This optimizes memory usage, enabling efficient execution of large applications

What is the use of overlay in OS?

Overlays are typically used in embedded systems due to physical memory limitations, internal memory for a system-on-chip, and the lack of virtual memory resources.

What is memory management overlay?

Adding a block of computer code or other data to replace existing data in internal memory is memory management overlaying. Applications that are larger than the main memory can be run. Based on information from another map layer, overlays infer the characteristics of features in a map layer.

What's the difference between swapping and overlays?

When the entire process is moved to the disc, swapping takes place. Swapping in memory management serves to increase the amount of memory accessible compared to the computer hardware. Overlaying is "inserting a block of computer code or other data into internal memory, replacing what is already there."

What are the types of overlays?

There are two types of overlaying. These two types are modal overlays and non-modal overlays. Before returning to the program, a modal overlay requires interaction from the user. Users cannot interact with the website until a particular action is taken or the overlay is closed. 

What is overlapping in operating system? 

In operating systems, overlapping refers to the technique of allowing the execution of multiple operations simultaneously. This can occur in various contexts, such as the overlapping of input/output operations with CPU processing, enhancing overall system efficiency by minimizing idle time and maximizing resource utilization.

Conclusion

Overlays are a crucial technique in memory management that enable the execution of programs larger than the available physical memory. By dynamically loading and unloading program segments as needed, overlays optimize memory usage and ensure efficient application performance. This method is particularly valuable in systems with limited memory resources, providing a balance between resource constraints and the need for complex, large-scale program functionalities. Overall, overlays enhance system capabilities and performance, making them a fundamental aspect of effective memory management.


On the other hand, learning never ceases, and there is always more to learn. So, keep learning and keep growing, ninjas!

Recommended Readings:


Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, etc. on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Good luck with your preparations!

Live masterclass