Download presentation
Presentation is loading. Please wait.
Published bySuhendra Darmali Modified over 5 years ago
1
Management From the memory view, we can list four important tasks that the OS is responsible for ; To know the used and unused memory partitions To allocate memory spaces for the processes To monitor the swapping operation between the main and the secondary memory Protect the allocated memory partitions from the unauthorised usage by the different processes
2
Basic Hardware of Memory
Basically, all the memory managing services are done to organize the of the memory by the processes. Each process should has it’s separated memory space. This is done by the OS through the allocation of two registers. These registers are the BASE register and the LIMIT register. The BASE register will contain the starting address of the process and the LIMIT register will contain the size of the process. OS is the only one that monitors and changes the values of these registers by using the privilege instructions, which are allowed only in the kernel mode. It is clear that the OS uses these registers to protect the memory spaces of the processes that are found in the main memory. An example, to explain this is illustrated following two figures.
3
The Addressing Space for a Process
in the Memory
4
The Use of Base and Limit registers
The monitoring mechanism used by the OS to protect the memory spaces of the processes The Use of Base and Limit registers
5
Memory Allocation : We said that the OS will know and protect the space of each process through the BASE and LIMIT registers. But before the defining of these registers, we may ask how OS allocates the memory space itself for such a process. OS depends upon two main algorithms to allocate memory spaces to the processes. 1) Fixed partitions 2) Variable partitions
6
Fixed partitions method : In this method, the memory is divided in advance into different fixed sizes. The OS will load any process that comes in the partition that is enough for it. But if that partition is not available then the process will be put in the queue that linked to this partition as shown in the following figure (a). This technique is called multiple queues. The problem with this technique is the accumulation of the processes on a queue while there are other queues suitable for the processes in the busy queue. This is clear in the figure (a) since queue 1 ,4 are busy while queue 3 is empty. The solution for this problem is to use the single queue technique as shown in the figure (b). In this technique all processes are put in one queue and one of them is selected when any partition be free. However, there are two approach to select from between the processes in that single queue, these are 1) first fit : to select the first suitable process 2) best fit : to select the process with nearest size comparing with the free partition The disadvantage of the fixed partition method : is the problem of internal fragmentation . That happens when the partition is bigger than the process since the rest of the partition can not be used for any allocation
7
The Fixed Partitions of the Memory
Multiple input queues Single input queues 700 K Partition 3 Partition 2 Partition 4 400 K 200 K 100 K 0 K Operating system Partition 1 (a) (b) Partition 1 Operating system The Fixed Partitions of the Memory
8
Variable partition method : In this method the OS looks to the memory as one space excluding the space that is allocated to the OS itself as shown in the figure of slide no. 9. This figure is an example showing how the OS allocates the spaces for 7 different sizes processes that come to the memory in different times. The Variable partition method is more efficient than the fixed partition method but it is more complicated. It is more efficient because the process will take what it needs not more so there is no internal fragmentation. And It is more complicated because the partitions will change in size and location with time. However, there are three technique to select the suitable partition for any process that want a space of memory to use, these techniques are : 1) first fit : select the first free space that is enough for the process 2) best fit: select the free space that is most near to the size of the process 3) worst fit : select the free space that is most far to the size of the process The disadvantage of the variable partition method is the problem of the external fragmentation , that is because some spaces that make up between the processes are small and not useful for use. This problem might be solved by compaction operation that is done by the OS from time to time when necessary, and as shown in the figure on slide no. 10
9
The variable Partitions of the Memory
10
Compaction operation to solve the problem of external fragmentation
11
The swapping As we know, the OS works in multi processes environment. And normally, The main memory is small, so it can not contain all the processes at any time. From another side, some of the processes in the main memory sometime become inactive, so the OS may decide to move out these processes to certain secondary memory called suspended processes store . In this case a space in the main memory becomes available and the OS may bring a new process from the input queue or may bring a suspended process that was moved out previously. The operation of bringing a process out of the main memory and bringing another process in its place is called swapping as shown in the figure of slide no. 12. The swapping is very important activity that is done by the OS under the following conditions: 1) if the process was waiting for I/O operation for long time then it better to swap it temporarily out the suspended store and swap another process in another process 2) if the process was waiting for a response from a user for long time then it better to swap it temporarily out the suspended store and swap another process in another process 3) if the process was waiting in the ready state then it is better to keep it in the memory without swapping 4) The OS must take care when selects a process from the suspended store to be swapped in. This depends on the importance of each process and if it is ready to swap in or not.
12
Swapping of Processes between Main and Backing Memory
13
The paging Till now we are talking about the principle that the process consists of one piece. So the OS must find a partition in the main memory that is equal or bigger than the process’s size. This principle can be broken by the idea of paging. In this case the process is divided into fixed size pieces called pages. In the same time the main memory is also divided into frames with size same as the page size. Here, the process can be put in the main memory as pages in different locations as shown in the figure of slide no. 13. It is clear that the memory is managed better with paging than before, that is because : 1) we don’t need to put all the process in one place 2) the problem of external fragmentation is reduced 3) we can put many processes in the main memory at the same time in more efficient way
14
Free Frames Allocation for Pages
Main memory Back store Frames Free Frames Allocation for Pages
15
Dynamic Address Translation
The important question in paging technique is how to translate the logical address into physical address. First of all this operation is called Dynamic Address Translation . In this operation the process’s space is divided into pages with page size defined by the system administrator and fed to the OS. Now, each instruction in any page is reached by the page number [p] and the displacement [d] within the page as shown in figure (a) of slide no. 16. Then, this page number is used to search the page table to know the frame number [ f ] where the OS put that page in. Then, this frame number will be added to the displacement [d] to reach the real location in the main memory as shown in figure (b) of slide no. 16.
16
Dynamic Addressing Translation For Paging Method
17
Segmentation As we said in paging technique, the process is divided into pages by the administrator without taking care to the boundaries of each page. In other words, the same page may contains data of different importance or different characteristics. This will affect the security of the data when there is sharing on these data between two processes as shown in the figure of slide no. 18. In segmentation technique, this problem is solved since the division of the process into segments is done by the process owner himself. For example, figure of slide no. 19 shows a typical division of a process. Here, the data security is insured because the programmer will know exactly the contents of each segment.
18
The problem of data security in paging technique
Process 1 Page0 Page1 Page2 Page3 Page4 Page5 Page6 Process 2 needs data from page 4 of process 1 code Process 1 data This page contains shared and unshared information The problem of data security in paging technique
19
Division of Program into Segments
20
Dynamic Address Translation
Like the paging technique, there is also an operation that translate the logical address into real address, which is also called Dynamic Address Translation . Figure of slide no. 21 shows the idea behind this translation. The translation starts when the processor produces a logical address that consists of two parts. These two parts are the segment number ( a number given to each segment in the process when it is loaded in the memory ) and the displacement [d] within this segment. The OS will use the segment number to search the segment table ( there a segment table for each process in the memory). This table consists of records so that each record belongs to a segment within the process. The record itself consists of two parts where the first part is the base address and the second part is the limit address. The displacement will be compared with the limit value to check for error ( if the displacement > limit ) . If the displacement is okay then the base address ( the starting address in the memory) will be added to the displacement to get the real address in the memory.
21
Dynamic Addressing Translation For Segmentation Method
22
Figure in the slide no. 23 shows an example for a process that consists of 5 segments. These segments are loaded in the memory according to information of the records shown in the segment table. Summary talk, we can compare between the paging and segmentation as below Paging segmentation 1) The process is divided by the administrator the process is divided by the owner 2) No external fragmentation but internal no internal fragmentation but fragmentation external fragmentation Not necessary the process to be loaded in same as paging one place Problem of data sharing the problem is solved
23
Practical Example for Segmentation Method
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.