Operating Systems 2 – Memory Manager

ShaunOperating Systems CourseLeave a Comment

Video Tutorial


Blog Tutorial

Hello my name is Shaun and in this tutorial we shall begin with the memory manager and look at three old schemes of memory management.

Single user contiguous was the first scheme of memory management and it wasn’t very efficient in terms of performance. A single job would reserve the entire memory space, this job would be processed and then the memory was cleared, allowing the next job to be loaded. If the job size was larger than the space available in the RAM it could simply not be executed. This scheme is considered impractical for today’s modern operating systems as it would be very slow to process all of the jobs on demand.

But what if you wanted to store two or three jobs in the memory? This is when fixed partitions came along, allowing allocated partitions to contain more than a single job at one time. All of the partitions were stored in a Partition Memory Table, to keep track of partition usage. The sizes of these partitions were static (meaning they could not be changed). Unless the system was rebooted, so you could see how this would be a problem!

A dynamic solution was necessary to avoid having to reboot the computer every time you want to process a job. Dynamic partitions available memory is still kept in contiguous blocks but jobs are only given as much memory as they request when they are loading for the processing, this has proven a significant improvement over fixed partitions because memory is not wasted in the partition. Unfortunately this is not a complete solution.

Both fixed and dynamic partitions need some way to allocate jobs to the available partitions. There are two ways to do this. First fit quite simply finds the first partition that has sufficient storage space, not taking into account how much memory could be wasted in the allocated partition. Best fit first looks for the smallest partition resulting in more space for other jobs; resulting in slower performance but better efficiency.

So when a job has completed processing it is then removed from memory, also known as de-allocation. With a fixed partition this is fine it is simply cleared, but when using a dynamic partition it gets more complex to free up memory as it tries to join together adjacent blocks.

So looking at these simple allocation schemes we can see there are still problems. Each one required the memory manager to store the entire program in the main memory at contiguous locations. We need to find a way to avoid having to keep the whole program in memory to run and the restriction of storing the programs contiguously. What if we could divide the jobs into separate smaller chunks, we can!

Virtual memory is the solution and we shall look at the evolution of four memory allocation schemes. Let us start with Paged memory allocation, allowing us to divide the job into equal sized parts. The sections of a disk are known as sectors or blocks and the sections of main memory are known as page frames. Before executing a program the memory manager makes some preparation. First it determines how many pages are in the program and then it locates enough empty page frames in the main memory so that it can pass all the pages into them.

The adjacent memory blocks do not have to be loaded in as adjacent memory blocks, they can be stored in any available page frame in the main memory. Now this is a more efficient scheme but it does come with complications. We need a way to keep track of all of the page locations; which increases complexity in the operation.

Through the use of 3 tables stored in the part of the main memory we can keep an eye on locations of various jobs. The job table is a dynamic list that contains 2 values; the size of the job and the Page map table location of that job. The Page map table contains important information for each of the pages (the page number and its corresponding page frame memory address). Finally the memory map table has one entry for each page frame listing both its location and a status informing whether it is in a busy or free state.

Now we have an understanding of Paged map allocation we can now see how Demand paging works. Very similar to the previous but the main difference is that pages are loaded on demand meaning that pages are only brought into memory when they are actually needed. The page map table we looked at before increases with three more columns; one to determine if the page is already in memory (known as the status), the second to check if the page has been modified, and a third to check if the page has been referenced recently.

How do we determine replacement of pages? By using a page replacement policy; First in first out, least recently used, least frequently used and most recently used are replacement policies used to change pages based on a specific algorithm. These are all pretty self-explanatory and are crucial to the efficiency of the system.

So we have looked at Page map allocation and demand paging but what else is there? Well we have looked at separating the jobs into pages. What if we could break it down even further? We can!

Segmented Memory allocation splits the job into separate segments that reflect the nature and structure of the code. Usually when you view a script it is separated into individual functions or sub routines that can be called one at a time. You may have a function called add that makes a calculation of two numbers and a function called divide. We can call these one after the other and they will run in the chosen order. Now take all of these functions and label them as segments. Instead of using a page map table we now have a segment map table that makes a list of all of the varied sized segments that need to be put in the main memory to process.

Now we move on to the final scheme, it is a mixture of segmented and demand paging memory allocation. It offers the logical benefits of the segmentation idea as well as the physical benefits of paging. There is no new logic involved but there are some minor modifications to point out. It makes use of both the segment map table and page map table plus additional information of authority to read, write and execute a file. A major disadvantage of this is the overheads and complexity of adding in more tables to handle the load.

Why is virtual memory a good thing? Well let’s say we currently have RAM that is fully occupied and has no time for jobs waiting to be slotted into it, because we use segmentation and paging we can exceed memory capacity by turning to the backup memory (The hard drive) a slower alternative it can act as an extension to the RAM.

We have come a long way in memory but at an increased processing cost the operating system can provide a more efficient service to allow the CPU (the central processing unit) to handle jobs with better timeframes and effectiveness. I have been (name) and in the next episode we will move on to the process manager. Do not forget to subscribe to the SMKS channel.

Leave a Reply

Your email address will not be published.