Os Chapter 5

You might also like

Download as pdf
Download as pdf
You are on page 1of 30
Memory Management Chapter Outcomes... Des Describe the working of specified memory management function. © Explain characteristic of the given memor Write algorithm for the given page replac Calculate page fault for the given page ret [Learning Objectives... To understand Basic Concepts of Memory and Memory Management in OS. To study Virtual Memory, Paging, Segmentation, Fragmentation etc. © Tolearn various Page Replacement Algorithm such as FIFO, LRU etc. 5.0 | INTRODUCTION 'S-16, 18, W-16, 18} + Ina computer system, there may be multiple processes executing at the same time and every process that needs to execute, requires a certain amount of memory. * Memory management is one of the important function of operating system which helps in allocating the main memory space to the processes and their data at the time of their execution. The main task of memory management is efficient memory utilization. + Memory management is the functionality of an operating system which handles or manages primary memory and moves processes back and forth between main memory and disk during execution. . . + To improve the utilization of the CPU and the speed of the computer's response to its users, we must keep several processes in memory i.e., we must share memory. Thus, multi-programming creates need of memory management. : + Memory management is responsible for allocating memory to processes and for protecting the memory allocated to each process from undesired access by other process. a * ‘Along with the allocation of memory space, memory management also perform the activities such as Upgrading the performance of the computer system, Enabling the execution of multiple eeeat tt form varing the same memory space among different processes and so on. ._ Hoesses at the same time ar ory management schemes handle the allocation of memory iffersar ereconses On completion of process execution, the memory is de-allocated and made available to another process. : “BASIC OF MEMORY MANAGEMENT = ting system is important because of it directly affects the execution wn time of a process depends on the availability of data in the main y management techniques. "ement technique. ference string, Memory management in opera’ time of a process. The executio memory. form the memory management in such a manner that the . ust perform g sucl Therefore, an operating system ™ ain memory. rot 8. i -esent in the mi sl data is aay agement system ensures accuracy, availability and consistency of the effective memory ‘memory to the main memory. data imported from the secondary [5.11 Operating Syst a . tions and it is the Storage SP2Ce inthe Overview of Memory tore data and instruction processing are stored. ; ipused to sto ns requ ; + Memory in computer system is ea and instructions oo executing iter: Ina computer, where data is to be pro cee main memory i th omramber of processes MUSt De Kept jn +The operating system must co" the processor ; ; are ' multiprogramming system, in order to sh ystem (See FB: 5,1). Memory consists of eared , mputer 5) + Memory is central to the operation ofa moist reat large array of words or bytes, each with itso UZ + The CPU fetches instructions from memory according to the 10 value of the program counter. | (5,, Memory ie ae These instructions may cause | “ additional loading from and Los storing to specific memory ~ : ; oe cama jig 5s Central Nature of Memory in a Computer Sy + Memory management is achieved through memory management algorithms. Each memory ‘management algorithm requires its own hardware support. + Both the CPU and ‘I/O system interact with memory. Interaction is achieved through a programm, sequence of reads or writes to specific memory addresses. The CPU fetches from and stores in Compiler or } Compile time memory. Assembler. + Addresses in the source program are generally symbolic. A compiler will typically bind these symbol addresses to re-locatable addresses, + The linkage editor or loader will bind these re- locatable addresses to absolute addresses. Each Linkage binding is a mapping from one address space to editor another. These absolute addresses loaded into memory to be executed. poe + AS program executes it accesses program aid instructions and data from memory by generating these absolute addresses. Eventually the program terminates, its memory space is declared available and the ‘next program may be loaded and Execution executed. time : Fig 5.2: Mutt (Run time) i-ste Functions of Memory Management '*P Processing of a User Program + Memory management specifies how to util, management is the functionality of an operatinn memory in ; an ern memory (RAM) and moves processes back and wsvete™ Which harvcient Manner. Memory forth by ‘andes execution. etween main + If we want to achieve the efficient memory utilizat; memory and disk during agement responsibilities functions: “ation We have to fol 4. Process Isolation: Process isolation means contro ow and memory of other process. Tolling of o, 2, Tracking of Memory Locations: Memory ma following storage man : ae nagem, location, regardless of either it is allocated ent kee memory is tobe allocated to processes, *O™* Procesg v4 Of each ang ry i At is eve m0! 3. Automatic Allocation and Management: Memory g Bot chassis Forities of the process. Otherwise the pr Should by Prpaation and the memory utilization, °°" Waiting win Wecated aye utiliza increase gy y2mically based on the and it decreases the CPU or manages primary * = i. Memory Management 4. bong Term Storage: Long term storage of process will reduce the memory utilization: rt of Modular Programming: A program is divided into number of modules, if the OF is not sufficient for the cringe we can load at least sore of the modules instead of the entire program. This will increase CPU utilization and mernory utilization protection and Access Control: Do not apply the protection mechanisms and access control to ail the processes, better to apply to the important applications only. It will save the execution time. Keeping Status of Main Memory Locations: Memory management keeps track of the status of each memory location, whether itis allocated or free pune Partitioning far multiprocessing two or more jobs should simultaneously be placed in the main memory. So the nemory should partitioned into a number of sections, This partitioning is called as partitioned ‘pemory management. in memory Partitioning, memory is divided into a umber of FegioRs or Partitions. Each region may fave one program to be executed. when a region is free, a program is selected from the job queue and loaded into the free region, When it terminated, the region becomes available for another program. + Memory is divided into two sections, one for user ané one for resident monitor of the operating system as shown in Fig. 5.3. + Commonly resident monitor place in low memory 32k and user program is executing in high memory. Fig. 5.3: Resident Monitor * Weneed to protect the monitor code and data from changes by the user program. This protection sust be provided by the hardware and can be implemented in several ways. The general approach is every address (instruction and data) generated by the user program is compared with a fence address. lfthe generated address is greater than or equal to the fence, then it is a legitimate reference to user emory and is sent to the memory unit as usual. * lWthe generated address is less than fence, the address is an illegal ‘ference to monitor memory. "The reference is intercepted and trap [55] Aderess ‘operating system is generated. The “eerating system will then take the riate action. Notice that every ‘lerence to memory by the user Trap, addressing error = ram must be checked. Fig. 5.4: Hardware Address Protection for a Resident Monitor The operating system executing in monitor mode, is generally given unrestricted access to both tor and user memory. This provision allows the operating system to load ser programs inte ‘St memory, dump them out incase of errors, access and modify parameters of system calls and so 0 The fence register contains the address of the fence and is used to check the correctness of all user auiory references. Te major Temory management schemes are possible. Each approach divides memory into a ier of regions or partitions. These schemes are Static (Fixed Sized) Memory Partitiontng ( duttion ee d number of Tasks (MPT)) and Dynamic (Variable) Memory It ith Fixe "tioning er mattiprogrammming with Variable number of Tasks (Mv) Operating Systems static (Fixed Sized) Memo the memory is « Instatic memory partitioning not change as the system runs: + Each partition in static memory partitionin f multiprogra™ programs to be exec! nged memory PB er of fixed sized partitions and gy exactly one process. SO the number of ) depends on the number of partitions, aamely, equal sized partitions (See g, contains ming) rtitioning 1 There are two alternatives for B= ji tions (See Fig: 5:5 (>) 5.5 (a)) and unequal sized partitions ( Fig. 5.5 (@)) eq AB ory awe ial os 22MB fe zowe ‘Small 18MB j__—4 me Medium > tamah-——] 12.8 ame Operating 8MB ‘Operating Large ern 0 pe 0 (a) Equal size Partitions () Unequal Size Partitions Fig. 5.5 eduling in Fixed Sized Memory Partitions: .duler takes into account the Job Sch : as jobs enter the system, they are Put into a job queue. The job sche memory requirement of each job and the swailable regions in determining which jobs are allocated memory. ed into a region. It can then complete for the CPU. When job «When a job is allocated space, it is loa terminates, it releases its memory region, which the job scheduler ma} from the job queue. «A number of variations are possible in allocation of memory to jobs. One st jobs on entry to system, according to its memory requirements. User sp mount of memory required the system can attempt to determine memory require automatically. = For example, a memory of 32K words might be divided into regions of the following sizes: y then fill with another job rategy is to classify al ecifies the maximum sments Resident Monitor = 12K Very small jobs = 2K ‘Average jobs = 6K Large jobs = 12K == STAR] 8 «If we have three user memory regions of sizes 2k, 6K, and 12K we need three queues namely 2, Q6 and QI2, (See Fig. 5.6 (a). «An incoming job requiring 4K of memory ~=- [redid] 012 would be appended to Q6, a new job needing 8K would be put in Q12, and a job of 2K would goin Q2. Each queue is scheduled separately. + Since each queue has its own memory region, there i i fae ee , there is no competition bet tego xiao qe een renee gion of that size is available. eae Fig. 5.6 (a): MFT with Separate Queues for Each Regio” operating Systm 55 Memory Manager suppose that we had FCFS job scheduler and —— Fegions of 2K, 6K, anc 12K. We would first resign job1 (SK) to the 6X regions and job? (2K) ie the 2K regions. Since our next job requires 3K, we need the 6K regions. since 6K regions are being used by jobi, we paust wait until job1 terminates, then job3 will be allocated the 6K regions. Job4 is then allocated to 12K regions and so on. advantages of Fixed Partitioning: mentation of fixed partitioning is Monitor 1. Impl simple. oe Fig. 5.6 (b): Mi Queue 2. In fixed partitioning the overhead of processing is also low thes alet Ls 3. Fixed partitioning makes efficient utilization of processor and 1/0 devices pisadvantages of Fixed Memory Partitioning: umber of tthe main problem with the fixed partitioni rertitons, and how to Meeeteine ther sizes eee 2. Fixed partitioning limits the degree of multiprogramming which in turn may reduce the effectiveness of short-term scheduling. 3, Ifa whole partition is currently not being used, then it is called an external fragmentation. And if a partition is being used by a process requiring some memory artition size, then itis... smaller than the P: called an internal fragmentation. Fig 5.6(€) [s.13.2| Dynamic (variable) Memory Partitioning i mtn fixed partitions we have to deal with the problem of determining the number and sizes of 7 sland external fragmentation if we use variable partitioning instead. partitions to minimize intern then partition sizes may Vary dynamically. ; pe ante partitions can vary in number and sie tn vaste mame partitioning the amount of mer allocated is excl ee ofan ; pres 7 se ple indicate oe dered as one large Block of rograms and is consi The operating system keeps a tal i rth available for user P! for a hole large en ailable to sal jonitor oF ough for this job. If we find one: tisty future requests: f 40K. This situation Jeaves: occupied. Initially all memory is available memory, a hole: h © When a job arrives an emory, WE a we allocate only as much as is needed, keeping" + For example, assume 256K memory available am 216K for user programs oO 216K 40K | 5 256K b tte 5.7 ey i i locate fi n immediately al ™memg Given the job queue in Fig. 5.7 and FCFS job scheduling, we C2! Y ty job1, 2 and 3 creating the memory map of ea) a terminate at time 5 unit, releasing its Memon We have 26K of external fragmentation. Jol allocation shown in Fig. 5.8 (b). edule the next job, job4 CA CRAIESIe “hen yee 4 j and sche 5,8 (d) an ed He festa ene time 10 unit to produce ( led, producing Fig. 5.8 (e). 0 0 0 7 Monitor Monitor Monitor Monitor Monitor ro 40k 40k] 40K 40K) ot Job 1 Jot Job 1 Job 1 rel K| 100k! ZA 100k' 100K) 100k | wl =r poco Allocate z Raostt] “Job 1 ob 2 emirates Job 4] Job 4 |terminates| Job4 | Job5 | Joba : 470K 170K, 170K Zz 2o0k| 200k| 200k 200k Job 3 | Job 3 Job 3 230k py 230K| y 30H 230k] 25K 256K 256k 256K (e) (a) (e) Fig. 5: Example Memory Allocation and Job Scheduling for MVT Dynamic Storage Allocation: Disk space can be viewed as a large array of disk blocks, At any given time some of these blocks are allocated to files and others are free. Disk space seen as a each segment is a contiguous set of disk . The dynamic storage allocation problem is how to There are many solutions to thie problem. t to allocate, tegies mr the set of available holes are firet bent fe andworst fi 1 Rem Ht Allocate the frst hole (or free bck) one 's big enough for the n, ‘s, Searching we rope rfc tin rte rc Sa in : 2 Best Fit: Allocate the smallest hole thar i beech resee Oe Fits itis generally faster. ept ordered by size. This strategy prea” thesmallest ee 3. Worst Fit: Allocat alle st left one the entire list, unless the lists te the largest hole. i ver hole, size. 8 Again we must search the entire list, untess it i sorted bf * First fit and best fit are better than nt i generally faster. Worst fit in p, oth time a: Example 1: Consider the following mem, requirement of 3 KB, Locate this process" °"Y ™&P and assume a n, (i) First fit algorithm alloca Sw Process Pa comes witha memo” tes from the 19 KB block. (i) Best fit algorithm allocates from the 4 KB + block. (ii) Worst first algorithm allocates from the 16 KB block. nd storage utilization, First fit # yn: New memory arra, os auto pample 2: Consider a swapping system | B, 18KB, 7kB, cory order: 10KB, 4KB, 20K ent requests for (i) 12 KB Ngements L os th respect to each a | 10) a Lee aa 9KB, 12KB ay KB for first — Memory Management gorithm will be as follows: os rer [trees ioe 13 | aKa Worst Fit ory Consists of the following hole sizes in ind 15KB. Which hole is taken for successive fit, best fit and worst fit, os 0s a ~ 10 KB 10 KB 4KB 412kB Tess 4kKB 4KB 7KB 18 KB 18 KB 18KB 10KB eee sh hs 12KB 10 KB 9KB 9KB 15kB 9KB 12KB 12KB 18 KB KB 15 KB 15 KB 20KB 4kB Initial memory First fit Best fit Worst ft “emory arrangements for 10 KB job are as follows: — ~ es oS 4KB 410 KB 10 KB = 7KB 18 KB 4KB one 20KB 918 18kB ae ~ el 18 pee t toe Ko voKe 7K | 7e me 18 KB 9KB 9KB ee | 18 KB 7KB 12K8 ke — +——_} 20KB 4KB 15 KB none Bost ft 45KB La Leet Initial memory Sperating Systems 5 Memery Marsan, Memory arrangements for 9 KR job are as follows os. oD oS 5 | 10KB ane “Ke 18 10K 20 KB 20KB 9x8 eee L 18KB 18KB 10KB, 12K 7 Ke 7B 12 KB 10kB 8kB 9KB 15KB oKB 12kB 12 kB 18KB 7ke | 15KB | 15Ke 20KB | Initial memory First ft Best ft In first fit allocate the first hole that enough for the job. In best fit, we arrange all holes iz ascending order to allocate the smallest hole this are big enough for the job. In worst fit, we arrange allholes in descending order to allocate the largest hole this are big enough for the job. Free Holes Allocation _First Fit Best Fit Worst Fit 12KB 20KB 12KB 20KB 10 KB 10KB 10 KB 20KB | 9kB | 10KB OKB 20KB Case 2: Suppose all three jobs arrived at same time, then the allocation of these jobs in first fit, best fit and worst fits are: 12kB 12KB 15 KB 18KB 15 KB ion of 12KB, 10K a: —_88 " a __ Memory Mar loca 284 9Kb jobs in, First it: —_____Memory Management [eos eter, 4kB L—9s__| Pi | 7a] = 4Ke 7K t+——_ E lo. — 7KB 9B |}—— | 7 | 9kB Le 9KB 10 KB ——| a Eo 10K8 fee 12ka 18K ne 12KB eee 18KB 18KB 20KB 20 KB 20KB location of 12KB, 10KB and 9Kb jobs in Best Fit: OS ‘OS as 2 Ke 12K8 | Kay [Stee Bis] [Siee> 56] Ties 40 KB _10KB ks siree> 8 KB | “ 8 KB ‘KB 15 KB 15 KB [ee oe 12KB 12KB 12K8 10 KB 10 KB 10 KB 9KB 9KB 9KB 7TKB 7KB 7KB 4KB 4KB KB i 3 9K jobs in Worst Fit: Allocation of 12KB, 10KB an< bi Facial Taal Worst Fit FirstFit | Best Fit ara 12KB 20KB [126 / 10 KB 18 KB 10 KB 35KB | SC 96 _ mming with a Fixed number of Tasks) ttepatison of Static Memory Partin au eeutiprogramming wit ning, memory i reral partitions of t size never changes. ‘ow at run time, —_ re, number OF | vary dynami Can g grow or: ‘shrink at run time. _ _st0 Memory utilization | Poor - | Division of memory |The division of memory into | Partitions number of partitions and its size is made in the beginning prior to the execution of user programs and os“ 0 | Good. a ‘The size and the number op partitions are decided during thy run time by the operating system, remains fixed thereafter. - | Degree of multi- | Limited and fixed. Vary depending on program size, programming | - - Implementation Difficult. | Eas: temal Hane Fragmentation Suffers from internal fragmen-| Suffers from external fragmen, tation, - tation. ae 9. | Overhead Eliminates the overhead of run- | Runtime overhead of allocation of | time allocation of partitions. partitions. = (10. | Example IBM 360, DOS etc. 1BM OS. HZi Free Space Management Techniques only a limited amount of disk space, files. * To keep track of free disk space, the file system maintains records all disk blocks, which are free. To create a file, we search the free 5] new file. This space is the removed added to the free space list. The process of looking after and mana; Files are created and deleted frequently during the operation of a computer system. Since t here is it is necessary to reuse the space from deleted files for ney a free space list. The free space list pace list for the required amount of space and allocate it to the from the free space list. When a file is deleted, its disk space is ging the free blocks of the disk is called free space management. The methods are used in fr List, Grouping and Counting. EERE sit vector + The free space list may not be implemented as D- Each block in bit ma allocated the bit is ‘1’. For example, consider a disk where blocks 2, 3, 4, 5, 8, ; alist; it is implemented as a Bi map is series or collection of bits where each bit corresponds to a disk block, p is represented by one bit. If the block is free, ee space management techniques are Bit Vector, Linked fs it Map or Bit Vector. Bit the bit is ‘0’, if the block is the free space bit map would be, n000011000d00rIOoNN AIGGsi eee fo[sTaTs [41s le [a [els ala asia las (1liTeTofofolititototolotote afa 0 = Free block 1= Allocated block The main benefit of bitmap is that it is relativel n consecutive free blocks on the disk. Unfortunately, bit vectors are inefficient accesses. Keeping it main memory is poss for larger ones, Advantages of Bit Map/Bit Vector: 1. It is simple and efficient me 2. Abit map requires lesser space as it uses 1 bit per block Disadvantages of Bit Map/Bit Vector. 1. Extra space required to store bit map. 2. It may require a special hardware su which bit is 0. 3. Bit map are inefficient unless the for recovery needs. Pport to do bit operation i.e, finding out wh ¥y simple and efficient to find the first free blocks of thod to find the first free block or n-consecutive free blocks on tit jich bit is 1 and 'yare kept in main memory and are written to disk occasionallY operating Systems FREE inked rist oe Linked list is another techni : anothe que for fi management in which, the free disk bloc nce linked together ie. a free block contains pointer to the next free block — + Inlinked list technique, link all together, keeping a pointer eee block. This block contains a Pointer to the a free disk block, and so on, Snext + In our example we wou! block 2, as the first free contain a pointer to blo: block 4, which would po: on. Free space head id keep a pointer to block. Block 2 would ck 3, which point to int to block 5 and so + Linked list scheme is not efficient; to traverse the list, each block must be read, which requires substantial 1/0 time. Advantages of Linked Free Space List: 1. Ifa file is to be allocated a free block, the operating sy the free space list and move the head pointer to the ne 2. No disk fragmentation as every block is utilized. Disadvantages of Linked Free Space List: 1. Itis not very efficient scheme as to traverse the list; we must read each block requiring substantial time 2. Pointers use here will also consume disk space. Additional memory is therefore required. em \f the free list method. ing i i ification of the free list method. * Grouping is a free space management technique for a modification o! ‘ i ificati i f'n’ free blocks in + Ingrouping, there is a modification of this approach would store the addresses o! the firse fee block. The first n-1 of these is actually free. The last one isthe disk address of another block containing the addzesses of another ‘n' free block. . The ieeperaee ot this implementation is that the addresses of a large number of free blocks can be found quickly. technique, in which a disk block of ing free space management technique een Eee Srey free oeks end a block containing free block pointers will get free when those blocks are used. : 7 First free 20 al »O OO] Fig. 5.9: Linked Free Space List on Disk stem can simply allocate the first block ia ext free block in the list. Es [se 215, Fs Le Kal Block 130 Block 17 Free bIOcKS 2: | 6 361 05.26 2 127 53 251 215 23 2 Fig. 5.10 = Memory Managemen, Operating Systems a 5.1.4.4] Counting + Counting is also a technique for free sp: be allocated of freed simultaneously, par - her than keeping a lst of 'n’ free dlak oddresens, we keep the address of first free block anq + Thus rather than er ‘n’ of free contiguous blocks which follows it. Each entry in the free space list then consis, number ‘n’ of free co1 of a disk address and a count. / : ‘Although each entry requires more space than would a simple disk address, the overall list + although eac! shorter, as long as the count is generally greater than 1. i free space mana . .. 5.11 shows an example of counting c ae ter, keep a counter saying how many block are free contiguously after that free block beh dean Contiguous chunk start address ace management. Generally several contiguous blocks may ticularly when contiguous allocation is used. be gement technique. Fig. 5.11 besides the free ‘Count ean UY vd =~ yA oft feqs[«[sfeq7[e]e fof n|2js Used Free EA veervat MEMORY Eaten era + Virtual memory is a technique which allows the execution of [>>> E Processes that may not be completely in memory. Page 1 + Virtual memory is a memory [Pageo management technique that LA provides an idealized abstraction of 4 the storage resources that are | * actually available on a given machine which creates the illusion to users of a very large (main) memory. + Virtual memory is the separation of | Page n user logical memory from physical t__] memory. This separation allows an Nae Memory Physical extremely large virtual memory to : ee ee be provided for programmers when _i8- 5-12: Virtual Memory that is larger than Physical Memory only a smaller physical memory is available. OOu00 oo000 goo000 + Virtual memory makes the task of programming much e. needs to worry about the amount of physical memory avi implemented by demand paging. + Itcan also be implemented in a segmentation system, performance, if it is usec carelessly. T because the programmer no longeT lable. Virtual memory is commonly not easy to implement, and may decrease nq Systoms —____s13 she basic idea behind virtual memo; exceed the amount of physical mem, Memory Management "Y Is that the combined size of the program, data and stack may a ory available for it. The operating system keeps those part | reston the disk. Parts of the program currently in use in main memory, and the a Introduction to Paging ing is a memo: ‘i Paging "Y Management technique by which a computer stores and retrieves data from secondary storage for use in main memory. In pag 8, ; the operating system retrieves data from secondary storage in same-size blocks called pages, . Paging is an important part of virtual memory implementa- tions in modern operating Frame number systems, using secondary Page 0 of o} storage to let programs exceed Page 1 [a 1 oa the size of available physical Page 2 2 tay 3 2 menor [Pave 3] Page table + The basic idea behind paging is 3 Bea Logical memory that when a process is swapped 4 [Peet the pager only loads into memory those pages that it expects the process to need. ® * Paging permits a programs 7 [Pages memory :c be non-contiguous, Physical memory thus allowing a program to be Fig. 5.13: Paging Model of Logical and Physical Memory allocated physical memory wherever it is available. + Every address generated by the oe i fo parts CPU is divided into two p: Logical namely, a page number (p) and sexess |-——___ a page offset (4). ae sth ‘The page number is used as an index into a page table. The Page table contains the base address of each page in Physical memory. This base — address is combined with page offset to define the physical — address that is sent to memory Unit. Page table Fig. 5.14: Paging Hardware Physical memory is broken into fixed size blocks called frames. Logical memory is also broken into blocks of the same size called Pages. When a program is to be executed, its pages are loaded into any available frames, and the page table is defined to translate from user pages to memory frames. + For example, using a page size of 4 words and physical memory of 32 words (8 pages) we show how the user's view of memory can be mapped into physical memory. Logical address 0 is page 0 offset =a 0. We find that page 0 is in frame 5. Page table i + Thus logical address 0 maps to a physical address 20 = (5 x 4 + 0). Logical address 4 is pagel, offset 0. Logical address 4 maps to Physicalmemery physical address (6x4+0)=24. pig. 5.15: Paging Example for a 32-word Memory with 4-word Page, Physical Memory Address = (Frame Number x Page Size) + Page Offset T Logical Frame | Page | Physical Address = Physical Address | 190 | Page| “no | size | ffSet | (rrame Number x Fage Size) + Offset | Address 0 atolls |4/o (5x4) +0 20 3 du |eomes 4] 3 (5x4) +3 , 2 6 g[1 6 4/2 (6x4)+2 26 10 k |] 2 1 4 2 | (1x4)+2 T 6 some physical address. Each ‘ress is mapped by paging hardware to ben fraimes available in memory, 8° Needs One frame. Thus if the job requires n pages, there must + The page of job is loaded int. table for this job and goon. Using a raging es frame can be allocated to.a job tha implemented as a set of dedicated registers Allocation of Free Frames: " + Fig. 5.16 shows allocation of free frames, a Segmentation 3, Paging eliminates fragment, 5, Memory used more efficien 4, Paging increases memo) «, support higher degree of mu} estas of Paged Memory Allocation; 4 Page Address mapping hardwai 2, Internal fragmentation still ex; ation, tly. al TY And processor 1 lization, tiprogramming Te usually j : Sually increases the cost of the computer s, though in last page ‘ored in memory location, Like paging segmentation is also a memo: aprogram. Insegmentation, the entire logical addres segment having a number anda length. The length of a segment may range from 0 to some maximum value as specified by the hardware and may also change during the execution. The user specifies each logical address consisting of 2 segment number (s) and an offset (d). Asegment is a logical unit such as main program, procedure, | Subroutine / Procedure Function - | function, method, object, local variables, global _variables, common block, stack, symbol table, arrays etc., as shown in Fig. 5.1: A segment is defined as, a logical grouping of instruct- tions. A logical address space is @ collection of segments. Every Program/job is collection of segments such as subroutine, array etc. Fig. 5.17: Us words. Rather user prefers to view memory as a dering among segments. Fig. 5.18 shows ry Management scheme that implements the user's view of 88 space is considered as a collection of segments with each ——— | |. Logical ‘Segment 2 ? Address Space ‘Segment 0 (See Global | Segment 3 data area Local data area ‘Segment 1 's View of a Program array of asa linear ry no necessary or i mo) User does not think of memory a5 8 to collection of variable sized se8™ Segmentation hardware. Each segment has a name an Within the segment. The user SP! Alogical address consists of 1 Fer to 5 Segment number is used 25 3° base and a segment limit. must be bel The offset ‘d’ of the logic® Tegal, itis the operating system: If Oe ie i The segm™ hysi f the de maa memory of own in Fig. 529. We have ne segments numbered from 0 through . jtuation 5) i as shown in Fig. 5. ample, consider the siti stored in physical memory g. 5.19. 4. The se, are a ements th, Address specify both the segment name and the offset Bt address by two quantities a segment name and an offset int number ‘s' and an offset into that segment ‘d’, The table. Each entry of segment table has a segment da lens ecifies eacl parts a segme! egment tween O and the segment limit. If it is not we trap to added to the segment base to produce the address in rent table is thus essentially an array of base/limit * The segment table has a sep: entry for each segment, giving the beginning address of the segment in physical memory (the base) and the length of that segment (the for example segment 2 is 40 beginning of locat reference to word $3 of segment 2 is mapped on to location 4300 +53 = 4353. A reference to segment 3, word ‘852 is mapped to 3200 (the base of segment 3) + 852 = 4052. A reference to word 1222 of Trap addressing error pesmneat 0) ould este ater, Fig. 5.18: Segmentation Hardware to the operating system, since this segment is only 1000 words long. Yi} Uy Yj WMA on Tad Segment 0 Segment] 2400 Uf Yyyy Tmt [Base] Uf 0} 1000 | 1400 LL. 3200 7 400 | 6300 400 | 4300 3} 1100 | 3200 Beoment 4| 1900 | 4700 | 4300 ‘Segment table peament 2 00 Segment 4 Logical adaress space Physical mer Fig.5.19: Example of td Advantages of Segmentation: eof Seementation 1. Eliminate Fragmentation: By movin, /Fragm 8 segm: combined into single true area Sments around, fragmented memory space can 2. Provides Virtual Memory: By keeping only the actively useq total address space size may exceed the physi ‘Sed segments in mai jobs 4. Dynamic Linking and Loading: At ; explicitly referenced SAC sum time it ti 5, Facilitate Shared Segments, (data area and 6, Enforced control access (i, Read, Wri 7, Itprovides a convenient way of organ . ages of Segmentation: Disad yan fers from external fragmentation, I translation ie. conversion fro “on, as regards Paging. 7 erowing segments, s ‘he subroutines and data area whet Procedures), For xecuted) "example (square root routine). ™ logical addres, ea TT r y, a 5 ; considerable compaction over " Momary Management ghminate fragmentation 0 Is incurred in order to support dynamic segment gromth and increased complexity in the operati snereased hardware Cost processor ume ‘OF overhead for ad for address mapping qhere isa difficulty in managing variabl ble ize he maximum size of segments imitediyine ea a fed by the size of main rm ypeseeen Paging and Segmentation oiled ¢) Pang a e | Segmentation in paging. the main memo ry is pa to page frames (or blocks). iS partitioned In segmentation, the air in paging, the logical address partitioned into segments S : Space is divided | In s f into pages by the compiler or MMU ae i segmentation the logical ad4r divided into segments as syecified Oy ‘he 4 $ 6 1 mamnory Management Unit) ~The OS maintains a pa {user /programnmet ge_maj 0 s OS maneins between frames and cee alsin apo Ca E apping purpose 4 Paging suffer fom internal Geo eniati alisaeoenion suff from om age breaks on suffers from “rating See aor enppart _| fragmentation Ss port the user's view of | Se i ports user's 2 gmentation supports users Hew 7 memory | 1 | 2| 3 | 4 | Frames | 7h Ae (3). This most unexpect Meron Maras ult rate may increase as the number of allocate 5 fa erg more memory to @ Process would improye ie algorithms, the Pa ment For some page replacement ago gi frames increases. We woul performance. vantages of FIFO Page Replacement 1. Itis simple to implement. 2. Itiseasiest algorithm 3, Easy tounderstand and execute : ssadvantages of FIFO Page Replacement Algorithm 1. Itisnot very effective 2. System needs to track of each frame. 3, Its performance is not always good 4, Itsuffers from Belady’s anomaly. 5, Bad replacement choice increases the page fer Optimal Page Replacement Algorithm an optimal page replacement algorithm has the lowest page fault rate of all algorithms and would never suffer from Belady's anomaly. + Optimal replacement algorithm states replace that page which will not be used for the longest period of time. + Forexample consider the following reference string ,7, 0, 1, 2, 0,3, 0, 4, 2,3, 0,3,2,1,2,0,1,7,0,1 + The first three reference cause faults which fill the three empty frames. The reference to page 2 replaces page 7, because 7 will be used until reference 18, whereas page 0 will be used at 5 and page at . a a to page a replaces page 1, as page 1 will be the last of the three pages in memory tobe again. With only nine page faults, optimal replace i 0 algorithm, which had 15 faults Pp placement is much better than a FIF The optimal page replacement al; is diffi i i i Eee eat gorithm is difficult to implement, because it requires future Algorithm: fault rate and slow process execution. 2 o 120 | a. hlUrTrt“‘ | Referencestring>{1|2/3|4/2 2 5 2 2 3/4) 5) Frames | Reticle ee est eb | 1 1 a[1[1[l4[4i5)5 5 [a 373 [2 2t2tefalalatalalafate 3 | ['s a[al2[2[2/2[2|ats Page Fault allele aaa, Total Page Faults 10. Fig. 5.33 — ee Summary: Consider the reference string: 7, 0, 1,2, 0,3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 9, 1,7, 0,1, oaks The NRU page replacement algorithm is an algorithm that favors keeping pages in memory thet have been recently used. NRU page replacement algorithm works on the principle, when a page is referenced, a referenced bit is set for that page, marking it as referenced. Similarly, when a page is modified (written to), 2 modified bit is set. The setting of the bits is usually done by the hardware, although it is possible 0 doo on the software level as well. Ata certain fixed time interval, a timer interrupt triggers and clears the referenced bit of all the Pages, so only pages referenced within the current timer interval are marked with a referenced bit NRU page replacement algorithm requires that each page have two additional status bits 'R’ and © called reference bit and change bit respectively. The reference bit (R) is automatically set to 1 when set to 1 whenever the page is modified. These bit: memory reference. When a page fault occurs, the memo classes based on Rand M bits. When a page needs to be replaced, the operatin, 3. referenced, modified 2. referenced, not modified 1. not referenced, modified 0. not referenced, not modified Although it does not seem possible for a page to be modified yet not referenced, this happens whe!™# class 3 page has its referenced bit cleared by the timer interrupt. lever the page is referenced. The change bit (M) is 's are stored in the PMT and are updated on every ry manager inspects all the pages and divides them into 4 ig system divides the pages into four classes: The NRU algorithm picks a Reterence sing 70 1 2 random page from the lowest category for removal. So out of Fy the above four page categories, BIE the NRU algorithm will replace LI UI LJ j not-referenced, not-modified stan ifsuch a page exists. page if such a Pag vt eeectun . not-referenced (within the last timer int s intensely referenced. algorithm implies that a modified but Note that this © rant than a not-modified page that | page is less imp eee ad Y sgesoen aerstand et on eS easy to understand. 4 ti efficient to implement, Algorithm: t gamle 4: Consider the page reference string: 2, 3,9 + 2.3, 2,4, 5 for the following replacement algorithy, 5,2, 4,539 : r assum 5,2. of! Suton: Using FIFO Page Replacement Algorith, ME three frames? (i) pipe ate many page faults (Reference String > | 213 m: )Iru (iii) Optimal | Frames Veit iela let; | J _ | 1 _—— L| | 1 ir esi! Leah alle = hai _ 2 | | 3) 213) 5] 515 3i3l3/3 3 : Si |iea) 825 |e2)|e28 9ael cells Page Fault ll 2} 2 | 4 | va 4 2 —— rare +——+ sotal Number of Page fault using three frames-9 “ _* Using LRU Page Replacement Algorit Reference String» | 2 | Te oe ee 7 av 8.21 Tzlslz Frames | ee een | Sees 1 | | I d | 1 i —— i shes eel ie |e 28 (22) 2|2/2 [s[3l3 [3 2 —__| pag) 13/2) eSellesdjaseles 5|5 5 3 a[a [a [eal 2/2 [2 _Pageraut = [viv] [viv v vivi_t Total Number of Page fault using three frames=7. - 7 Using Optimal Page Replacement Algorithm: - | Reference string>|2/3/2/1|5/2/4/s)3|]2/s|2 Frames lea jt | | ler | I [edna | eRe oahest a2l2}2l2l2l2|sl4lelaiaia Ee aleze|e2t ae 4 | *3/3[3|3/3|313/3|*2) 2/2 _ alee pot eom [a2 [Sebo oale ota _ Page Fault Te ea\ee al 11 which algorithm makes t ime ‘Allocation of processes 212K, 417K, 112K and 426) tL at — : pw No memory partitons Fig. 5.35 “Allocation of processes 212K, 417K, 112K and 426K in Best Fit are: Memory partitions | 100 K 500K [ oor Processes | 212K [ark [vex | 26 Fig. 5.36 Allocation of processes 212K, 417K, 112K and 426K in Worst Fit ar Memory partitions rox | 500k | 200K | 300K | g00k y cae Processes | 212K | 47K | | K nek | | | [1K | 426K No memory : partition Fig. 5.37 Best fit algorithm makes most efficient use of memo: bgcte ele eitays tits pas is meant by memory management? +t functi ‘ aa functions of memory management in o 7 ats memory partitioning? What are its t ee “stem Enplain MFT and MVT with example. Alsocomba, at is fragmentation? Explain withitstyee What is paging? Define it Define page and frame in paging What is free space management? Describe bit map with example With the help of diagram describe linked jj What is virtual memory? Explain diagrarnm What is page fault? Enlist its steps ay With help of example describe pa, disadvantages: () FStin frst out, i) Lease S™ENt algorithms ‘ cently s with their advantages 4” ed, PONY AHEUR BEES F wnat is segmentation? stat, ite _ — Memory Management plain the FIFO, Optimal Pits any two oO merits and d a n 030423103. List the dra ea LRU page lemerits, i acks of, consider a swapping syste each i ™ in whi order: 10KB, 4KB, 20KB, qgic Which mem » BKB, 7) }ory consists of the following hol t requ . 7KB, fe following hole sizes in memory segment requests for: (1) 12 \_ SKB, 12KB and 15KB, Which hole is taken for successive Placement algorithms for the reference string 7.012 algorithm. 10K8, (3)9 KB for first fit, best fit . explain different approaches weet" 9 always possible it, best fit and worst fit edt ‘ g. Epa cifferent pees replacement algorthan free space list in dynamic storage allocation. 19. Expla’ , Optimal a m. ® 930423105.List the cama Page replacement algorithms for the reference string 7 012 What is segmentation? Enlist its aden eorthm: advantages and disadvantages. igement techniques. ring 1, 2, 3, 4,5,3, 4,1, 6,7, 8,7, 8,9, 7, 8, 9,5,4,5. How many page ent algo: yt P A cee Ley Enlist free space memory mana Consider the page reference st faults occur for FIFO repk (Summer 2036) 4. Describe concept of virtual memory with suitable example. ans. Refer to Section 5.2. 2. Write in short on basic memory management. . Refer to Section 5.1. Ans. 3, Describe optimal page replacement algorithm with example. mm Ans. Refer to Section 5.3.2. me Winter 2016 1. Explain the concept of variable memory partitioning with example. Ans, Refer to Section 5.1.3.2 2. What are the different responsibilities of memory management? Explain. Ans. Refer to Section 3.0. _ ‘Summer 2017) Ans. Refer to Section 5.1.4 2. Differentiate between paging an _Ans. Refer to Page 5.17. _ 1. Explain bit map free-space management technique. am segmentation, (any six points) ma ——— {winter 2017) 1. Explain FIFO (First In First Out) Page replacement algorithm for reference strinj : i cs 7012030423103. 1 the time when that page was bought into ith each page the 8 2 Ans, A FIFO replacement associate’ 1 Cog the oldest page is chosen. It maintains a FIFO queue memory. When the pager a We replace the page at the head of the queue. When a page is eae ee ao ory. hgert it atthe tail of the queue, yught int le. Consider three frames are available Page fault 11. Page hit 2. perating Sys 520 operating Systems 530, pare paging and segmentation memory Mi 2. Comj ‘Ans. Refer to Page 5.17. 3 Describe the concept of virtual memory with suitabl Ans. a {Summer 2018 | 4. Explain “Bitmap” method in free space management tec] ‘Ans. Refer to Section 5.1.4.1 ‘Ans. Refer to Section 3.0. 3. Give difference external fragmentation and int Sr.No. __Internal Fragmentation 1. |It refers to unused space from space allocated to any process. Internal fragmentation occurs when memory block allocated to a process is bigger in size than the required size. 3. | Itoccurs when fixed size memory blocks are allocated to the processes. 4. |It uses fixed memory partitioning technique all partitions are of same size. anagement techniques: je example. fan o 2. Explain major activities of memory management component 0! ternal fragmentation. (four points) Following table compares internal and external fragmentations memory. nique. perating system External Fragmentation fragmentation refers to unused space from the memory that is not allocated to any process. __| ‘External fragmentation occurs when free memory block is available but is less than the size required by the processes waiting to be loaded in External It occurs when variable size memory space are allocated to the processes dynamically. It uses variable partitioning technique each block is of variable in size. ter 2018) 1. Whatis the concept of paging? Ans. Refer to Section 5.2.1. 2. Explain static and dynamic memory partitioning method, Ans. Refer to Sections 5.1.3.1 and 5.13.2. 3. Explain memory management in detail Ans. Refer to Section 3.0. 4. Describe virtual memory management, ‘Ans. RefertoSection52, [Summer 2019] 41. Explain concept of virtual memory with diagram, Ans. Refer to Section 5.2. 2. Differentiate between segmentation and Ans. Refer to Page 5.17 Paging, (any 6 points), fa

You might also like