Presentation is loading. Please wait.

Presentation is loading. Please wait.

Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium.

Similar presentations


Presentation on theme: "Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium."— Presentation transcript:

1 Memory Management OS Fazal Rehman Shamil

2 swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium term scheduler. Medium term scheduler removes process from CPU for duration and reduce the degree of multiprogramming. And after some time these process can again be reintroduced into main memory.

3 swapping Process execution will again be resumed from the point it left CPU. This scheme is called swapping. More generally we can say swapping is removing of process from memory to secondary memory and again back to main memory.

4 Example: Assume a multiprogramming environment with Round-Robin CPU scheduling algorithm. When a quantum expires, the memory manager will start to swap out the process that just finished, and swap in another piece to the memory space that has been freed.

5 In the meantime, CPU scheduler will allocate a time slice to some other process in memory. When each process finishes its quantum it will be swapped back with another process.

6 Swapping can be implemented in various ways. For example, swapping can be priority based. That means if a higher priority process arrives and wants service, the memory manager can swap out the lower priority process to the secondary memory so that it higher priority process can be loaded to main memory for execution.

7 As soon higher priority process finishes, the lower priority process will be swapped back to main memory and execution will be continued. Sometimes swapping is also called roll out, roll in.

8

9 Contigious memory allocation One of the simplest methods for memory allocation is to divide memory into several fixed-sized partitions. Each partition may contain exactly one process. In this multiple-partition method, when a partition is free, a process is selected from the input queue and is loaded into the free partition. When the process terminates, the partition becomes available for another process. The operating system keeps a table indicating which parts of memory are available and which are occupied. Finally, when a process arrives and needs memory, a memory section large enough for this process is provided.

10 Contigious memory allocation When a process needs to execute, memory is requested by the process. The size of the process is compared with the amount of contiguous main memory available to execute the process. If sufficient contiguous memory is found, the process is allocated memory to start its execution. Otherwise, it is added to a queue of waiting processes until sufficient free contiguous memory is available.

11 this approach can suffer from external as well as internal memory fragmentation.

12 Fragmentation In computer storage, fragmentation is a phenomenon in which storage space is used inefficiently, reducing capacity or performance and often both. The exact consequences of fragmentation depend on the specific system of storage allocation in use and the particular form of fragmentation.

13 Fragmentation External fragmentation: Total memory space is enough to satisfy a request or to reside a process in it, but it is not contiguous so it can not be used.

14

15 Fragmentation Internal fragmentation: Memory block assigned to process is bigger. Some portion of memory is left unused as it can not be used by another process.

16 Task 2 Write a program that takes three memory partitions and programmer itself decides the sizes for each memory allocation. The user input the size of three different process. According to size of process, the program tells that which process can allocate memory partition, and which process can’t allocate memory. Also program tells the total external fragmentation of the program.

17 Task 3 You are allocated burst size for each process and to each group members, Now consider burst sizes as a resources, and check that whether a system is in safe state or not. Also apply banker’s algorithm to all and check that deadlock occurs or not.

18 Paging Both fix and variable partitions create problems of external and internal fragmentation. These are not better techniques that can be used for memory management. Paging is another memory management technique used to fix this problem.

19 Using paging physical memory is divided into small equal fixed size blocks called frames. Each process is divided into blocks called pages that are of the same size as frames. A frame can hold one page of data. Individual pages and frames are identified by unique numbers known as page numbers and frame numbers respectively.

20 When a process is to be executed, its pages are loaded into any available memory frames from the backing store. Page frames used for the process need not be contigious. In memory, smaller process require few frames, while large processes require more frames. Paging eliminates external fragmentation, but there may be some internal fragmentation.

21 Backing store is also divided into fixed sized blocks that are of the same size as memory frames.. Size of page and frames are determined by hardware. Size of page is typically from 512 bytes to 8kb, depending on the computer architecture.

22 Page table Os maintains a page table for each process. Page table holds the frame location for each page of process. It contains one entry for each page of process. When a process is entered into a system, it number of pages is examined. If the process has ‘n’ pages, then ‘n’ frames must be available in memory. When process pages are allocated to the available frames in memory, then the frame numbers allocated to the pages are entered into the page table of the process.

23

24

25 Overlying Overlying is a technique that is used to execute a program even if the system has insufficient physical memory. Therefore to implement the overlying, the programmer splits the program into pieces or segments, called overlays, such that no two overlying segments need to be in memory at the same time.

26 Overlying Overlay 0 would start running first and when it is done, it would call another overlay to execute. Os can manage the program execution by swapping the overlay segments.. Overlays are swapped in and swaped out by the OS

27 Segmentation Is a technique in which a user program can be divided into a number of smaller blocks, called segments. For example,data segments or code segment for each process. Unlike paging, segment are having varying sizes and thus eliminates internal fragmentation. External fragmentation still exists but to lesser extent.

28 Segmentation

29 Segmentation is a technique to break memory into logical pieces where each piece represents a group of related information. For example,data segments or code segment for each process. Unlike paging, segment are having varying sizes and thus eliminates internal fragmentation. External fragmentation still exists but to lesser extent.

30 Virtual memory Virtual memory is a technique that allows the execution of processes which are not completely available in memory. The main visible advantage of this scheme is that programs can be larger than physical memory. Virtual memory is the separation of user logical memory from physical memory. This separation allows an extremely large virtual memory to be provided for programmers when only a smaller physical memory is available. Following are the situations, when entire program is not required to be loaded fully in main memory.

31 Virtual memory If your computer lacks the random access memory (RAM) needed to run a program or operation, Windows uses virtual memory to compensate. Virtual memory combines your computer’s RAM with temporary space on your hard disk. When RAM runs low, virtual memory moves data from RAM to a space called a paging file. Moving data to and from the paging file frees up RAM so your computer can complete its work. The more RAM your computer has, the faster your programs will generally run. If a lack of RAM is slowing your computer, you might be tempted to increase virtual memory to compensate. However, your computer can read data from RAM much more quickly than from a hard disk, so adding RAM is a better solution.

32 Virtual memory Advantages Main advantage of virtual memory is that it allows users to execute processes that are larger than actual size of physical memory. Os keeps necessary parts of process currently in use in main memory and the rest of the program on the backing store. Pieces of the program are swapped in and swapped out between memory and backing store during the program exexcution.

33 Virtual memory Most common methods that implement virtual memory are demand paging and demand segmentation.

34

35 Demand paging Used to implement the virtual memory. This technique has combined features of simple paging and overlying. In a demand paged system, each page of the process is stored contiguously in the paging swap space on 2ndary storage. With demand paging, a page is loaded into main memory only when it is needed. During process execution. As locations in pages are referenced, the pages are copied into memory page frames.

36 A demand paging system is quite similar to a paging system with swapping. When we want to execute a process, we swap it into memory. Rather than swapping the entire process into memory, however, we use a lazy swapper called pager. When a process is to be swapped in, the pager guesses which pages will be used before the process is swapped out again. Instead of swapping in a whole process, the pager brings only those necessary pages into memory. Thus, it avoids reading into memory pages that will not be used in anyway, decreasing the swap time and the amount of physical memory needed.

37 Hardware support is required to distinguish between those pages that are in memory and those pages that are on the disk using the valid-invalid bit scheme. Where valid and invalid pages can be checked by checking the bit.

38 1 means page in memory 0 means page not in memory


Download ppt "Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium."

Similar presentations


Ads by Google