Memory Management Problems / Answers

Post on 01-Jan-2016

43 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

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

1

Memory ManagementProblems / Answers

Chapter 7

Revised April 15, 2008

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

17

Answer Problem 7.7Buddy System

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

512K 512K

256K 256K 512K

1M

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

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 .

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 .

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.

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

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

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

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

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

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

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

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

top related