memory management problems / answers

29
1 Memory Management Problems / Answers Chapter 7 Revised April 15, 2008

Upload: lael-walters

Post on 01-Jan-2016

49 views

Category:

Documents


4 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Memory Management Problems / Answers

1

Memory ManagementProblems / Answers

Chapter 7

Revised April 15, 2008

Page 2: Memory Management Problems / Answers

2

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.

Page 3: Memory Management Problems / Answers

3

Answer Problem 7.6First Fit

20M 20M 40 M 60 M 20M 10M

60 M 40 M 20M 30M

40M

40M

20M 20M 40 M 40 M 10M 10M 20M 10M

60 M 40 M 20M 30M

40M

40M

First-fit – 40MFirst-fit – 20M First-fit – 10M

Page 4: Memory Management Problems / Answers

4

Answer Problem 7.6Best Fit

20M 20M 40 M 60 M 20M 10M

60 M 40 M 20M 30M

40M

40M

20M 20M 40 M 60 M 20M 10M

60 M 40 M 20M 30M

40M

40M

Best-fit – 40MBest-fit – 20M Best-fit – 10M

Page 5: Memory Management Problems / Answers

5

Answer Problem 7.6Next Fit

20M 20M 40 M 60 M 20M 10M

60 M 40 M 20M 30M

40M

40M

20M 20M 40 M 40 M 20M 20M 10M

60 M 40 M 20M 30M

40M

40M

Next-fit – 40M Next-fit – 20M Next-fit – 10M

Most recently added block

Page 6: Memory Management Problems / Answers

6

Answer Problem 7.6Worst Fit – Largest Free block

20M 20M 40 M 60 M 20M 10M

60 M 40 M 20M 30M

40M

40M

20M 20M 40 M 40 M 20M 20M 10M

60 M 20 M 20M 20M 30M

40M

40M

Worst-fit – 40M Worst-fit – 20M Worst-fit – 10M

Page 7: Memory Management Problems / Answers

7

Answer Problem 7.7Buddy System

Request A– 70K – Split 1 M until find- best fit block

Worst-fit – 20M Worst-fit – 10M

1M

512K 512K

256K 256 K 512K

Page 8: Memory Management Problems / Answers

8

Answer Problem 7.7Buddy System

70K

256K 256 K 512K

128K 128K 256 K 512K

Request A– 70K – Split 1 M until find- best fit block

Place request A– 70K in 128K block

Page 9: Memory Management Problems / Answers

9

Answer Problem 7.7Buddy System

Request B– 35K – Split 128 K block

70K

128K 128K 256 K 512K

128K 64 K 64K 256 K 512K

70K

70K

35K

35K35K35K

PlaceB– 35K – in 128 K block

Page 10: Memory Management Problems / Answers

10

Answer Problem 7.7Buddy System

Request C– 80K – Split 256 K block

80K

128K 64 K 64K 256 K 512K

70K

70K

35K

35K35K35K

128K 64 K 64K 128 K 128K 512K

70K 35K

Place C– 80K – in 128K block

Page 11: Memory Management Problems / Answers

11

Answer Problem 7.7Buddy System

Return A – 70K – remove 70K

80K

70K35K35K35K

128K 64 K 64K 128 K 128K 512K

70K 35K

80K

128K 64 K 64K 128 K 128K 512K

35K

Page 12: Memory Management Problems / Answers

12

Answer Problem 7.7Buddy System

Request D – 60K – place in 64K block

60K

35K35K35K

80K

128K 64 K 64K 128 K 128K 512K

35K

80K

128K 64 K 64K 128 K 128K 512K

35K

Page 13: Memory Management Problems / Answers

13

Answer Problem 7.7Buddy System

return B – 35K – remove 35K process

60K

35K35K35K

80K

128K 64 K 64K 128 K 128K 512K

35K

60K 80K

128K 64 K 64K 128 K 128K 512K

Page 14: Memory Management Problems / Answers

14

Answer Problem 7.7Buddy System

return D – 60K – remove 80K process; merge empty 64K buddies into 128K block

60K

35K35K35K

80K

128K 64 K 64K 128 K 128K 512K

60K

80K128K 128 K 128K 128K

512K

Page 15: Memory Management Problems / Answers

15

Answer Problem 7.7Buddy System

return D – 60K –then, merge empty 128K K buddies into 256K block

60K

35K35K35K

80K

128K 64 K 64K 128 K 128K 512K

60K

80K256K 128K 128K

512K

Page 16: Memory Management Problems / Answers

16

Answer Problem 7.7Buddy System

return C – 80K –remove 80K process, merge empty 128K buddies into 256K block

60K

35K35K35K

80K60K

80K256K 128K 128K

512K

256K 256K 512K

Page 17: Memory Management Problems / Answers

17

Answer Problem 7.7Buddy System

return C – 80K –then merge empty 256K buddies into 512K block

512K 512K

256K 256K 512K

1M

Page 18: Memory Management Problems / Answers

18

Answer Problem 7.7(b)

7.7(b)

60K 80K

128K 64 K 64K 128 K 128K 512K

1 M

512 K

256 K

128 K

64 K

Page 19: Memory Management Problems / Answers

19

Answer Problem 7.87.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 k came 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+1 and 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 .

Page 20: Memory Management Problems / Answers

20

Answer Problem 7.87.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 = 11011100000 2.

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+1 and 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 .

Page 21: Memory Management Problems / Answers

21

Answer Problem 7.97.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.

Page 22: Memory Management Problems / Answers

22

Answer Problem 7.12Physical memory

232 bytes

Page size

210 bytes

210 bytes 210 bytes

Logical address

216 pages

(a) The number of the addresses in 216 pages is

216 * 210 bytes per page = 226 . It takes 26 bits to represent theses byte addresses

Page 23: Memory Management Problems / Answers

23

Answer Problem 7.12Physical memory

232 bytes

Page size

210 bytes

210 bytes 210 bytes

Logical address

216 pages

(b) A frame in physical memory is the same size as a page 210 bytes

Frame210 bytes

Page 24: Memory Management Problems / Answers

24

Answer Problem 7.12Physical memory

232 bytes

Page size

210 bytes

210 bytes 210 bytes

Logical address

216 pages

(c) There are 232 / 210 = 222

frames in physical memory. 22 bits are required to address the frames

Frame210 bytes

0010 1001 0011 1010 0110 01

Example of frame address = 67548110

Frame # 67548110

Page 25: Memory Management Problems / Answers

25

Answer Problem 7.12Physical memory

232 bytes

Page size

210 bytes

Logical address

216 pages

(d) Since the logical address space contains 216 pages the page table must have an entry for each page. It must have 216 entries.

Frame210 bytes

0010 1001 0011 1010 0110 01

Page 26: Memory Management Problems / Answers

26

Page # Frame # in main memory

0 Some frame address

1 Some frame address

….. ………………

…… …………………..

6402 67548110

0010 1001 0011 1010 0110 01

Example of frame address = 67548110

Frame # 67548110

Physical memory

232 bytes

Frame size210 bytes

Page 27: Memory Management Problems / Answers

27

Page # Frame # in main memory

0 Some frame address

1 Some frame address

….. ………………

…… …………………..

6402 675481100010 1001 0011 1010 0110 01

Physical memory

232 bytes

Frame size210 bytes(e) 22 bits for the frame # + 1

bit for valid/ not-valid = 23 bits

Page 28: Memory Management Problems / Answers

28

Answer Problem 7.12Physical memory

232 bytes

Page size

210 bytes

Logical address

216 pages

(e) Since the logical address contains 216 space contains entries for 216 pages.

Frame210 bytes

0010 1001 0011 1010 0110 01

Example of frame address = 67548110

Frame # 67548110

Page 29: Memory Management Problems / Answers

29

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