TMC 1234: Operating Systems Session 2013/2014, Semester 2 TUTORIAL 3 1. Explain the differences between a page memory allocation scheme and a segment memory allocation scheme. A paged memory allocation scheme jobs are divided into fixed-size partition called pages (physically divided). A segmented memory allocation scheme jobs are divided into a number of distinct logical units called segments (logically divided). 2. List the memory allocation scheme that required the entire job to be stored in main memory. Memory allocation scheme that required the entire job to be stored in main memory: i. Single User Contiguous Scheme ii. Fixed partition iii. Dynamic partition iv. Paged memory allocation 3. List down the step on how to calculate the exact address of the instruction of byte 214 in main memory when using paged memory allocation. Assume that each page size is 100 and use the below Page Map Table (PMT) for Job 1. Job Page No 0 1 2 3 Page Map table for Job 1 Page Frame No 8 10 5 11 For example, to find the exact location of byte 214 (where the system will find the value to load to Register 1), the operating system will do the following:i. Compute the page number and displacement of the requested byte 2 100 214 200 14 Page number = 2 and Displacement =14 ii. iii. iv. Go to PMT (Page Map Table) and retrieve the appropriate page frame number. Compute the starting address of the page frame by multiplying the page frame number times the page frame size. ADDR_PAGE_FRAME = PAGE_FRAME_NUMBER * PAGE_SIZE = 5*100 Finally, calculate the exact address of the instruction in memory by adding the displacement to the starting address. INSTR_ADDR_IN_MEM = ADDR_PAGE_FRAME + DISPL INSTR_ADDR_IN_MEM = 500 +14 4. Describe how the function of the Page Map Table (PMT) differs in paged vs. segmented/demand paging memory allocation. In both memory allocation schemes, the PMT tracks page assignments to page frames, but in the paged scheme the PMT is referenced directly from the Job Table, and in segmented/demand paged, it is referenced from the Segment Map Table (SMT), which is referenced from the Job Table. 5. Demand paging allows the user to run jobs with less memory than the size of the job. How is this possible? Demand paging allows user to run jobs with less main memory than the size of the job by manipulating a high-speed direct access storage device. Pages will be passed quickly from secondary storage to main memory and back again. Therefore, it gives the appearance as if the jobs required always in main memory when, in reality they are swapped back when other jobs need the place in main memory and will be stored back when required. This is also known as virtual memory implementation. 6. What is the cause of thrashing? Too many page fault causes thrashing. Page fault caused by inefficient page replacement policy, or the size of working set is too small. CPU may spend the majority of its time taking care of page swaps, leaving little time for useful work. 7. What is the working set? A job’s working set is the set of pages residing in memory that can be accessed directly without incurring a page fault. 8. Given that main memory is composed of three page frames for public use and that a seven-page program (with pages a, b, c, d, e, f, g) requests pages in the following order: a, b, a, c, d, a, e, f, g, c, b, g a. Using the FIFO page removal algorithm, do a page trace analysis indicating page faults with asterisks (*). Then compute the failure and success ratios. (The first-in page, the oldest swappable page, is shown in bold.) Page request Page fault Page Frame 1 Page Frame 2 Page Frame 3 a b a c d a e f g c b g * * * * * a a a a d d b b b b a c c c * d a e * f a e * f g e * f g c * b b g g c c Failure ratio = 10 / 12 = 83% Success ratio = 2 / 12 = 17% b. Increase the size of memory so it contains four page frames for public use. Using the same page requests as above and FIFO, do another page trace analysis and compute the failure and success ratios. Page request Page fault Page Frame 1 Page Frame 2 Page Frame 3 Page Frame 4 a b a c d a e f g c b g * * * * a a a a a a b b b b b c c c d d * e b c d * e f c d * e f g d * e f g c * b f g c b f g c Failure ratio = 9 / 12 = 75% Success ratio = 3 / 12 = 25% c. Did the result correspond with your intuition? Explain. The extra page frame increases performance only fractionally (8%), even though one might think it should be much better. The improvement would be much greater if the program had a small working set, which might minimize the number of page faults (especially if the working set consisted of four pages). 9. Given that main memory is composed of three page frames for public use and that a program requests pages in the following order: a, d, b, a, f, b, e, c, g, f, b, g a. Using the FIFO page removal algorithm, perform a page trace analysis indicating page faults with asterisks (*). Then compute the failure and success ratios. (The first-in page, the oldest swappable page, is shown in bold.) Page request Page fault Page Frame 1 Page Frame 2 Page Frame 3 a * a d b a f b e c * * * * * a a a f f f f d d d d d e e b b b b b c Failure ratio = 9 / 12 = 75% Success ratio = 3 / 12 = 25% g * g e c f * g f c b g * g g f f b b b. Using the LRU page removal algorithm, perform a page trace analysis and compute the failure and success ratios. (The least recently used page is shown in bold.) Page request Page fault Page Frame 1 Page Frame 2 Page Frame 3 a * a d b a f b e c g f * * * * * * * a a a a a e e e f d d d f f f c c c b b b b b b g g Failure ratio = 9 / 12 = 75% Success ratio = 3 / 12 = 25% b g * f f b b g g c. Which is better? Why do you think it is better? Can you make general statements from this example? Why or why not? It is curious here that the two algorithms result in such miserable success ratios, even though we would expect LRU to be more efficient. Clearly, with seven pages competing for three page frames, and with no obvious working set, there will be many page faults. Look for an original analysis for this answer. 10. Given that main memory is composed of four page frames for public use, use the following table to answer all parts of this problem: Page Frame 0 1 2 3 Time When Loaded 126 230 120 160 Time When Last Referenced 279 280 282 290 Referenced bit Modified Bit 0 1 1 1 0 0 1 1 a. The contents of which page frame would be swapped out by FIFO? Page Frame 2. b. The contents of which page frame would be swapped out by LRU? Page Frame 0 11. Given three subroutines of 700, 200, and 500 words each, if segmentation is used then the total memory needed is the sum of the three sizes (if all three routines are loaded). However, if paging is used then some storage space is lost because subroutines rarely fill the last page completely, and that results in internal fragmentation. Determine the total amount of wasted memory due to internal fragmentation when the three subroutines are loaded into memory using each of the following page sizes: a. 100 words b. 600 words c. 700 words d. 900 words a. Subroutine Needs Internal Fragmentation. S1 with 700 words 7 pages of 100 words 0 words S2 with 200 words 2 page of 100 words 0 words S3 with 500 words 5 pages of 100 words 0 words Total 0 words b. Subroutine Needs Internal Fragmentation. S1 with 700 words 2 pages of 600 words 500 words S2 with 200 words 1 page of 600 words 400 words S3 with 500 words 1 page of 600 words 100 words Total c. Subroutine Needs 1000 words Internal Fragmentation S1 with 700 words 1 page of 700 words 0 words S2 with 200 words 1 page of 700 words 500 words S3 with 500 words 1 page of 700 words 200 words Total d. Subroutine Needs 700 words Internal Fragmentation. S1 with 700 words 1 page of 900 words 200 words S2 with 200 words 1 page of 900 words 700 words S3 with 500 words 1 page of 900 words 400 words Total 12. Given the following Segment Map Tables for two jobs: SMT for Job 1 Segment Number 0 1 2 3 4 Memory Location 4096 6144 9216 2048 7168 1300 words SMT for Job 2 Segment Number 0 1 2 Memory Location 2048 6144 9216 a. Which segments, if any, are shared between the two jobs? Three segments are shared by both jobs, those starting at locations: 2048, 6144 and 9216. b. If the segment now located at 7168 is swapped out and later reloaded at 8192, and the segment now at 2048 is swapped out and reloaded at 1024, what would the new segment tables look like? SMT for Job 1 Segment Memory Number Location 0 4096 1 6144 2 9216 3 1024 4 8192 SMT for Job 2 Segment Memory Number Location 0 1024 1 6144 2 9216