Overlays in Memory ManagementOne of the main limitations imposed on programmers in the early days of computers was the size of the computer's memory. If the program was larger than the available memory, it could not be loaded, severely restricting program size. The main problem with fixed partitioning is that the size of a process has to be limited by the maximum size of the partition, which means a process can never span over another. The obvious solution would be to increase the amount of memory available, but this would significantly increase the cost of the computer system. To solve this problem, earlier people have used some solution called Overlays. The concept of overlays is that it will not use the complete program simultaneously whenever a process is running. It will use only some part of it. Then overlays concept says that whatever part you require, you load it, and once the part is done, you just unload it, which means pull it back and get the new part you required and run it. Formally, "The process of transferring a block of program code or other data into internal memory, replacing what is already stored". Sometimes it happens that compared to the size of the biggest partition, the size of the program will be even more. Then, in that case, you should go with overlays. So overlay is a technique to run a program that is bigger than the size of the physical memory by keeping only those instructions and data that are needed at any given time. Divide the program into modules so that not all modules need to be in the memory simultaneously. In memory management, overlays work in the following steps, such as:
Example of OverlaysThe best example of overlays is assembler. Consider the assembler has 2 passes, 2 pass means at any time it will be doing only one thing, either the 1st pass or the 2nd pass. This means it will finish 1st pass first and then 2nd pass. Let's assume that the available main memory size is 150KB and the total code size is 200KB. As the total code size is 200KB and the main memory size is 150KB, it is impossible to use 2 passes together. So, in this case, we should go with the overlays technique.
Overlays driver: The user's responsibility is to take care of overlaying. The operating system will not provide anything. This means the user should write even what part is required in the 1st pass, and once the 1st pass is over, the user should write the code to pull out pass 1 and load pass 2. The user's responsibility in this process is known as the Overlays driver. Overlays driver will help us move out and move in the various parts of the code. Usage of OverlaysConstructing an overlay program involves manually dividing a program into self-contained object code blocks called overlays laid out in a tree structure. Sibling segments, those at the same depth level, share the same memory, called overlay or destination regions. An overlay manager, either part of the operating system or part of the overlay program, loads the required overlay from external memory into its destination region when it is needed. Often linkers provide support for overlays. For example, the overlay tree for a program is as shown below: Using the overlay concept, we need not have the entire program inside the main memory. Only we need to have the part 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 a 14KB size of a partition, then we can run any of them. How does Overlays WorkSuppose you have a computer whose instruction address space is only 64 kilobytes long but has much more memory than others can access, such as special instructions, segment registers, or memory management hardware. Suppose that you want to adopt a program larger than 64 kilobytes to run on this system. One solution is to identify modules (overlays) of your program which are relatively independent and need not call each other directly. Separate the overlays from the main program, and place their machine code in the larger memory. Place your main program in instruction memory, but leave at least enough space there to hold the largest overlay as well. To call a function located in an overlay, you must first copy that overlay's machine code from the large memory into the space set aside for it in the instruction memory and then jump to its entry point there. The above diagram shows a system with separate data and instruction address spaces. The program copies its code from the larger address space to the instruction address space to map an overlay. Since the overlays are shown here all use the same mapped address, only one may be mapped at a time. An overlay loaded into instruction memory and ready for use is called a mapped overlay. Its mapped address is its address in the instruction memory. An overlay not present (or only partially present) in instruction memory is called unmapped, and its load address is its address in the larger memory. The mapped address is also called the virtual memory address (VMA), and the load address is also called the load memory address (LMA). Unfortunately, overlays are not a completely transparent way to adapt a program to limited instruction memory. They introduce a new set of global constraints:
Advantages of OverlaysOverlays in memory management have the following advantages, such as:
Disadvantages of OverlaysOverlays also have some disadvantages, such as:
Next Topicfork() vs exec() |