1 / 38

MEMORY MANAGEMENT Presented By :- Lect. Puneet Gupta G.P.C.G. Patiala

MEMORY MANAGEMENT Presented By :- Lect. Puneet Gupta G.P.C.G. Patiala. Operating System

jakeem-reid
Download Presentation

MEMORY MANAGEMENT Presented By :- Lect. Puneet Gupta G.P.C.G. Patiala

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MEMORY MANAGEMENT Presented By:- Lect. Puneet Gupta G.P.C.G. Patiala

  2. Operating System A operating system is a set of master programs which is desired to control entire operations of computer. Operating System is a general purpose software which is involved in each and every activity of the computer. The various functions of operating system are • Interface between user and hardware • Peripheral Management • Memory Management • Process Management

  3. Memory Memory refers to the physical devices used to store the data temporary or permanent. There are two types of memories that are 1. Primary Memory:- These are internal memory of computer. They are very fast. The two types of primary memory are RAM and ROM. 2. Secondary Memory:- These are physical devices to store program and data. They are slow to access with higher memory capacity. The various types of secondary memories are tape, magnetic disks and optical discs.

  4. Principals of Memory Management The various aim and principals of memory management are • To provide the memory space to enable many processes to be executed at same time. • To protect the processes from each other. • To provide satisfactory level as performance to users. • To make addressing of memory space transparent for an programmer.

  5. Address Binding Each program resides on a disk but it must be brought to memory for execution. The process has to be moved between disk and memory. Thus different memory address are used at different location. The process of changing the addresses during storage is called binding. The various types of binding are • Compile Time Binding • Load Time Binding • Execution Time Binding

  6. Physical and Logical Address 1. Physical Address:- The actual addresses that refer to actual physical location of the main memory are called physical addresses. 2. Logical Address:- The addresses generated by CPU are called Logical addresses. The logical and physical addresses are same at compile time and load time binding. But it differs at Execution time binding. The mapping of logical address to physical addresses is done by hardware device called Memory Management Unit.

  7. Relocation The logical addresses are converted into physical addresses by the help of relocation register present in Memory Management Unit or by relocating linkers and loader. The ability to load and execute a given program to arbitrary place in memory is called relocation. The user program supplies logical address must be mapped to physical addresses before they are used. The types of Relocation are • Static Relocation • Dynamic Relocation

  8. Relocation The types of Relocation are • Static Relocation :- The Static Relocation is performed before or during the loading of program into memory. This is done by relocating linkers and relocating loaders. • Dynamic Relocation :- The Dynamic relocation is performed during the execution of the program. This is done by the help of the hardware support called Memory management Unit (MMU).

  9. Relocation Logical Address Physical Address 346 14346 MMU +

  10. Partitioning The Operating System manages the main memory by dividing the memory into regions of fixed or variable size is called Partitioning. It manages the main memory efficiently. The two types of partitions are • Static Partition:- The whole memory is divided into fixed sized frame is called static partition. • Dynamic Partition:- The memory is divided into variable sized frame according to page size is called dynamic partition.

  11. Partitioning Example 0 0 10 10 15 15 20 30 33 38 40 40 47 50 50 Static Partition Dynamic Partition

  12. Fragmentation Fragmentation is a process in which storage space is used inefficiently, reducing capacity and often performance. Fragmentation leads to storage space being wasted, and the term also refers to the wasted space itself. The two types of fragmentation are 1. External fragmentation 2. Internal fragmentation This problem is overcome by using Disk defragmentation.

  13. Contiguous Memory Allocation Each logical object is placed in physical memory at consecutive addresses is called contiguous memory allocation. Generally memory is partitioned and any process requesting memory is allocated a partition. On termination, process release memory partition to a free pool of memory. There are number of scheme which can be used for a system but we can rate efficiency of a particular memory management scheme like wasted memory, time complexity, memory access overheads.

  14. Static Partitioned Memory Allocation The memory partition are created sometime before the execution of user programs these partitions remain fixed. This approach is known as Static Partitioned Memory Allocation. The number and size of partitions is fixed during system generation process by considering 1. Capacity of memory, 2. Degree of multiprogramming, 3. Size of program.

  15. Dynamic Partitioned Memory Allocation The memory partition are created dynamically in response to process requests. This approach is known as Dynamic Partitioned Memory Allocation. The partition creation process goes on till the whole memory has been utilized. Whenever a process requests for memory partition, memory management of operating system creates a suitable partition to allocate to the process. It selects the greater or equal size to process, allocate the memory and keeps the record in PDT.

  16. Algorithms • First Fit:- OS searches the first partition large enough to store process. • Next Fit:- The memory manager keep a pointer on the free list to store process. • Best Fit:- Memory manager searches free list from beginning to end and selects the smallest possible portion to hold process. • Worst Fit:- The memory manager scans the free list and allocate the largest memory block to create partition to store process.

  17. Swapping The process of a suspended or preempted process in main memory with a new process is called swapping. When all memory partitions have been allocated and there is need to allocate a partition to a process, a suspended or preempted processes is taken out from the memory in order to bring new process. Swapping is used to implement the multi programming in the system which have less hardware support for memory management. Swapping is done by module called Swapper

  18. Swapping Swap out Swap in

  19. Compaction The process of relocating all partitions into one end of memory and to combine holes into large free area is called compaction. When the memory becomes fragmented, solution is to relocate all partition into one end using compaction. All the effected processes are suspended and they are copied from one to another area of memory. It can be performed whenever possible or only when needed. System compacts memory when large free area is return or there is failure to allocate memory.

  20. Paging Paging is a memory management scheme that permits the physical address space of a process to be non contiguous. In paging physical memory is divided into fixed sized partitions called frames. Virtual address space is also divided into blocks of same size called pages. A page map table is used for address translation. The virtual address of a process is divided into two parts that are • Page number (p) • Page offset (d)

  21. Paging

  22. Segmentation Segmentation is memory management scheme in which the address space of single process is divided into blocks that may be placed into non contiguous area of memory. Due to external fragmentation the waste memory increases which should be reduced in system by using the segmentation to utilize the memory in proper manner. Segment descriptor table is use to record the details of different segment belonging to different process area in memory. It is flexible and easy to use.

  23. Segmentation The translation from virtual to physical address in main memory is done as follows. • The segment number of virtual address is used to access the segment descriptor table. • It is checked that whether the offset of segment is within bound of segment. • The base address of segment is obtained from SDT. • The offset of the virtual address is added to physical base address to get actual physical address.

  24. Segmentation

  25. Virtual Memory The secondary memory that is used to keep the portions of address spaces of currently executing process is called virtual memory. The portions are shifted to and fro between main memory and virtual memory. Virtual memory is a technique that allows the execution of processes that may not be completely in memory. By this method CPU can execute the program as large as physical memory.

  26. Virtual Memory The various issue that are specific to virtual memory concept are • Allocation Policy:- decides how much real memory to be allocated to each process. • Fetch Policy :- decides when and which items are to be brought to main memory. • Replacement Policy:- decides which item should replaced with new memory. • Placement policy:-decides about placement of an incoming item in physical memory.

  27. Demand Paging A demand paging system is similar to a paging system with swapping. Processes reside on secondary memory. When we want to execute a process, we swap it into memory. A swapper swaps the page into memory only when it needed. It avoids reading into memory pages that will not be used anyway thus decreasing the swap time and amount of physical memory needed. The hardware support for demand paging is page table and secondary memory which is same as in paging and swapping.

  28. Page Replacement To reduce the page faults occurrence, we used the technique of page replacement. In this if no frame is free, the OS finds the one that is not in used and make it free. Then this freed frame is used to hold the page which is faulted. The routine for page replacement are • Find the location of desired page on disk. • Find a free frame a. if there is a free frame, use it. b. if there is no free frame, use a page

  29. Page Replacement replacement algorithm to select the victim frame and write victim page to disk change the page and frame table accordingly. 3. Read the page to free frame, change the page and frame tables. 4 . Restart the user process. The algorithm used for page replacement are a. FIFO Page Replacement, b. LRU page Replacement, c. Optimal Page Replacement

  30. First In First Out FIFO replacement algorithm is the simplest replacement algorithm. In this page which is the oldest one is replaced with the new page. It use the page queue in which the page at the head is replaced with the page inserted at the tail. It is implement by using the FIFO queue. There is Belady anomaly problem with FIFO replacement algorithm. The number of page faults are increases with increase in number of frames in main memory.

  31. First In First Out Example:- Consider the main memory consists of 3 frames for FIFO Page Replacement algorithm and input pattern of memory pages. 7 0 1 2 0 3 0 4 2 3 0

  32. Optimal Page Replacement The Optimal Page Replacement algorithm replace the page that will not be used for longest period of time. The page which might not be used for longer time is replaced with the new page. This replacement algorithm has lowest page fault rate. This algorithm is difficult to implement as it requires future knowledge of the reference string. It overcome the belady’s anomaly.

  33. Optimal Page Replacement Example:- Consider the main memory consists of 3 frames for Optimal Page Replacement algorithm and input pattern of memory pages. 7 0 1 2 0 3 0 4 2 3 0

  34. Least Recently Used The least recently used algorithm will replace the page that has not been used for longest period of time. LRU replacement. LRU chooses that page which has not been used for the longest period of time. This algorithm is looking backward in time, rather than forward that is used in Optimal page replacement. The two implementation for LRU are Counters and Stack.

  35. Least Recently Used Example:- Consider the main memory consists of 3 frames for LRU Page Replacement algorithm and input pattern of memory pages 7 0 1 2 0 3 0 4 2 3 0

  36. Summary • Memory refers to the physical devices used to store the data temporary or permanent. • The process of changing the addresses during storage is called binding. • The binding is of three types are Compile Time, Load Time, Execution Time Binding. • The actual addresses that refer to actual physical location of main memory are called physical addresses. • The addresses generated by CPU are called Logical addresses.

  37. Summary • The OS manages the main memory by dividing the memory into regions of fixed or variable size is called Partitioning. • The secondary memory that is used to keep the portions of address spaces of currently executing process is called virtual memory. • A demand paging system is similar to a paging system with swapping • The algorithm used for page replacement are FIFO Page Replacement, LRU page Replacement, Optimal Page Replacement.

  38. Thanks

More Related