290 likes | 409 Views
Memory Management Problems / Answers. Chapter 7 Revised April 15, 2008. Answer Problem 7.2. If main memory is 2 24 bytes and each fixed size partition is 2 16 bytes, there are 2 24 / 2 16 = 2 8 partitions.
E N D
Memory ManagementProblems / Answers Chapter 7 Revised April 15, 2008
Answer Problem 7.2 • If main memory is 224 bytes and each fixed size partition is 216 bytes, there are 224 / 216 = 28 partitions. • Addressing of the partitions is from 00000000...11111111 requiring 8 bits. So the pointers in the page table should be 8 bits long.
Answer Problem 7.6First Fit First-fit – 10M First-fit – 20M First-fit – 40M
Answer Problem 7.6Best Fit Best-fit – 10M Best-fit – 20M Best-fit – 40M
Answer Problem 7.6Next Fit Most recently added block Next-fit – 40M Next-fit – 20M Next-fit – 10M
Answer Problem 7.6Worst Fit – Largest Free block Worst-fit – 40M Worst-fit – 20M Worst-fit – 10M
Answer Problem 7.7Buddy System Worst-fit – 20M Worst-fit – 10M Request A– 70K – Split 1 M until find- best fit block
Answer Problem 7.7Buddy System Request A– 70K – Split 1 M until find- best fit block Place request A– 70K in 128K block 70K
Answer Problem 7.7Buddy System 35K 35K Request B– 35K – Split 128 K block 35K 70K 70K PlaceB– 35K – in 128 K block 70K 35K
Answer Problem 7.7Buddy System 35K 35K 70K Request C– 80K – Split 256 K block 35K 70K 35K Place C– 80K – in 128K block 70K 35K 80K
Answer Problem 7.7Buddy System 35K 35K Return A – 70K – remove 70K 70K 35K 70K 35K 80K 35K 80K
Answer Problem 7.7Buddy System 35K 35K Request D – 60K – place in 64K block 35K 35K 80K 35K 60K 80K
Answer Problem 7.7Buddy System 35K 35K return B – 35K – remove 35K process 35K 35K 60K 80K 60K 80K
Answer Problem 7.7Buddy System 35K 35K return D – 60K – remove 80K process; merge empty 64K buddies into 128K block 35K 60K 60K 80K 80K
Answer Problem 7.7Buddy System 35K 35K return D – 60K –then, merge empty 128K K buddies into 256K block 35K 60K 60K 80K 80K
Answer Problem 7.7Buddy System 35K 35K return C – 80K –remove 80K process, merge empty 128K buddies into 256K block 35K 60K 60K 80K 80K
Answer Problem 7.7Buddy System return C – 80K –then merge empty 256K buddies into 512K block
Answer Problem 7.7(b) 1 M 7.7(b) 512 K 256 K 128 K 64 K 60K 80K
Answer Problem 7.8 7.8(a) Buddies come in pairs, left buddy and right buddy. They each have the same size some 2 k . The starting address of the left buddy has to be a multiple of the block size from which blocks of size 2 kcame from. That block size is 2 k+1 . Let the starting address of the left buddy be x. The address of the right buddy is x + 2 k. The address of the right-buddy is not a multiple 2 k+1and that address has a remainder of 2k when divided by 2 k+1 . To determine whether or not some buddy address is the address of a left buddy or a right buddy divide it by 2 k+1 . If the division has a remainder of zero the buddy address is a left buddy address. If the division has a remainder of 2 k the buddy address is a right buddy address .
Answer Problem 7.8 7.8(a) (a) Problem gives an address of 0110111100002 = 177610 . Block size is given as 4 = 2 2. Test whether or not address is left or right buddy address. Divide address by 2 3 = 8. 8 divides evenly into 1776 so the address 1776 is a left-buddy address. So to get address of its right buddy add 4 to the left-buddy address So the right buddy address is 1780 = 11011110100 2. (b) Problem gives an address of 0110111100002 = 177610 . Block size is given as 16 = 2 4. Test whether or not address is left or right buddy address. Divide address by 2 5 = 32. 32 does not divide evenly into 1776 and has remainder of 16. 1776 is a right-buddy address. So to get address of its left buddy subtract 16 from the right-buddy address So the right buddy address is 1776-16 = 1760 = 110111000002. That block size is 2 k+1 . Let the starting address of the left buddy be x. The address of the right buddy is x + 2 k. The address of the right-buddy is not a multiple 2 k+1and that address has a remainder of 2k when divided by 2 k+1 . To determine whether or not some buddy address is the address of a left buddy or a right buddy divide it by 2 k+1 . If the division has a remainder of zero the buddy address is a left buddy address. If the division has a remainder of 2 k the buddy address is a right buddy address .
Answer Problem 7.9 7.9 Condition for left-buddy address: buddyk( x) = x + 2 k if x mod 2 k+1 = 0 Condition for right-buddy address: buddyk( x) = x - 2 k if x mod 2 k+1 = 2 k Where x is a given address.
Answer Problem 7.12 210 bytes 210 bytes 210 bytes 216 pages • The number of the addresses in 216 pages is 216 * 210 bytes per page= 226 . It takes 26 bits to represent theses byte addresses 232 bytes
Answer Problem 7.12 210 bytes 210 bytes 210 bytes 216 pages (b) A frame in physical memory is the same size as a page 210 bytes 232 bytes Frame 210 bytes
Answer Problem 7.12 210 bytes 210 bytes 210 bytes 216 pages (c) There are 232 / 210 = 222 frames in physical memory. 22 bits are required to address the frames 232 bytes Frame 210 bytes 0010 1001 0011 1010 0110 01 Example of frame address =67548110 Frame # 67548110
Answer Problem 7.12 (d) Since the logical address space contains 216 pages the page table must have an entry for each page. It must have 216 entries. 210 bytes 216 pages 232 bytes Frame 210 bytes 0010 1001 0011 1010 0110 01
232 bytes Frame size 210 bytes 0010 1001 0011 1010 0110 01 Example of frame address =67548110 Frame # 67548110
232 bytes 0010 1001 0011 1010 0110 01 Frame size 210 bytes (e) 22 bits for the frame # + 1 bit for valid/ not-valid = 23 bits
Answer Problem 7.12 (e) Since the logical address contains 216 space contains entries for 216 pages. 210 bytes 216 pages 232 bytes Frame 210 bytes 0010 1001 0011 1010 0110 01 Example of frame address =67548110 Frame # 67548110
Memory Management Requirements • OS needs to know location of process control info, execution stack and entry point of program to begin execution • OS must deal with memory references within program • Branch instructions • data reference instructions • Memory addresses found in code must be translated into physical addresses