You are on page 1of 9

KSU/CCIS CSC227

Tutorial # 6 Memory Management


SUMMER - 2010

Question # 1:

Assume that the main memory has the following 5 fixed partitions with the following sizes: 100KB,
500KB, 200KB, 300KB and 600KB (in order)
a) Expalin the following allocation algorithms: First-fit, Best-fit and Worst-fit.
b) How would each of the First-fit, Best-fit and Worst-fit algorithms place processes of 212KB,
417KB, 112KB and 426KB (in order)?
c) Compute the total memory size that is not used for each algorithm.
d) Which algorithm makes the efficient use of the memory?

Answer Q 1:

a) Form your book.


b)
Fisrt-fit Best-fit Worst-fit
100K 100K 100K

500K 212K 500K 417K 500K 417K


288K 83K 83K
200k 112k 200K 112K 200K
88K 88K
300K 300K 212K 300K 112K
88K 188K
600K 417K 600K 426K 600K 212K
183K 174K 388K

c) First-fit = 1700 741 = 959


Best-fit = 1700 1167 = 533
Worst-fit = 1700 741 = 959

d) Memeory Utilization Ratio:


First-fit = 741 / 1700 = 43.5%
Best-fit = 1167 / 1700 = 68.6%
Worst-fit = 741 / 1700 = 43.5 %
Best-fit has the most efficient use of the memory.
Question # 2:

Assume that the MMU is using the multiple variable partition schemes. The memory size is 2560KB,
from which the OS uses 400KB. You have the following processes:

Process Size CPU burst


P1 600K 10
P2 1000K 5
P3 300K 20
P4 700K 8
P5 500K 15

Using the First-fit allocation technique and the multiprogramming system (FCFS), do the following
(without using compaction)

a) Load and execute the processes until P5 is loaded (do not terminate P5).
b) Every time a program is loaded, compute the external fragmentation.
c) Assuming P5 is now terminated and P6 requires 1000K, (the P3 and P4 are still in the
memory) how would you compact best the memory so to enable P6 to be loaded?

Answer Q 2:

a) Solution
b) Soultion

Time = 0 Time = 10 Time = 16


OS OS OS
400K 400K 400K
P1 #Free# P4
600K 600K 700K

P2 P2 P5
1000K 1000K 500K

P3 P3 #Free#
300K 300K 400K
P3
300K
#Free# #Free# #Free#
260K 260K 260K
EF = 0 EF = 860K EF = 660K
c) Soutlion

P5 trem P5 trem
OS OS
400K 400K
P4 P4
700K 700K

#Free# P3
900K 300K

P3 #Free#
300K 1160K
#Free#
260K

Can get most free space in less moves if you move P3 up.

Question # 3:

Assume that we have the following jobs to be scheduled using FCFS algorithm with variable partition
memory scheme:

Job Size CPU


J1 50 KB 13
J2 120 KB 3
J3 70 KB 9
J4 20 KB 3
J5 105 KB 8
J6 55 KB 13

Memory size is 256KB; Jobs are initially loaded in memory as follows:

J1 50 KB

J2 120 KB

J3 70 KB
16 KB

Show how the memory will look after scheduling job 6 (assume no memory compaction is allowed)
using both FCFS and Best-fit allocation technique.
Answer Q 3:
J4 20K J4 20K J4 20K
J1 50K #Free# 30K
J5 105K J5 105K
J2 120K J2 120K J6 55K
#Free# 45K
J3 70K J3 70K J3 70K
#Free# 76K
#Free# 16K #Free# 16K #Free# 16K
Time = 0 Time = 13 Time = 16 Time = 25

Question # 4:
Assume that we have the following jobs to be executed on a time-sharing operating system
(Quantum = 4 ms) with a total user memory of 256 KB.

Job No. Arrival time Memory size CPU Time


(ms) (KB) (ms)
1 0 120 8
2 2 70 4
3 2 50 12
4 2 100 12
5 0 40 4
6 2 120 4
7 0 60 8
8 0 30 8

Show how the memory will look after loading Job No 6 using the Best-fit allocation technique with no
compaction.

Answer Q 4:
Question # 5:
Consider a logical address space of 8 pages; each page is 2048 byte long, mapped onto a physical
memory of 64 frames.

a) What are the sizes of the logical and physical spaces?


b) How many bits are there in the logical address and how many bits are there in the physical
address?
c) A 6284 bytes program is to be loaded in some of the available frames= {10, 8, 40, 25, 3, 15,
56, 18, 12, 35}. Show the contents of the programs PMT.
d) What is the size of the internal fragment?
e) Convert the following logical addresses 2249, 5245 and 10512 to physical addresses.

Answer Q 5:

a) Physical space size = 64 * 2048 = 217 bytes.


Logical space size = 8 * 2048 = 214 bytes

b) Logical @ field is 14 bits long.


Physical @ field is 17 bits long.

c) Page size = 2048 bytes, so program is divided into 6284/2048 = 4 pages

PMT
Index Frame # Valid/Invalid
0 10 V
1 8 V
2 40 V
3 25 V
4 I
5 I
6 I
7 I

FL { 3, 15, 56, 18, 12, 35}

d) There is interanl fragment in page number 3,


4 pages * 2048 = 8192 bytes
Program size is 6284
Internal fragment = 8192 6284 = 1908 bytes. (all in page number 3)

e) 2249  <1, 201>  <8, 201>  16585


5245  <2, 1149>  <40, 1149>  83069
10512  <5, 272>  Trap (page is invalid)
Question # 6:

Consider a paged memory of 64 pages of 256 bytes each.


a) What is the size of the logical space and the number of bits of a logical address?
b) Assume that the free frame list is {29, 4, 18, 5, 22, 15, 7, 2} and two programs P1 (4 pages),
P2 (2 pages) are waiting to be loaded. Perform the memory allocation of P1 and P2 and show
their PMTs.
c) Assume that PMT is kept in memory and two register associative memory. The access time
to the memory is 480ns and the access to associative memory is 50ns. What is the effective
access time to the memory if the hit ration in the associative memory is 50%? 90%?
d) Under what condition is an associative memory effective?

Answer Q 6:

a) Logical space size = 64 * 256 = 26 * 28 = 214 bytes


Logical @ field is 14 bits long.

b) PMT of P1 PMT of P2
Index Frame# V/I Index Frame# V/I
0 29 V 0 22 V
1 4 V 1 15 V
2 18 V
3 5 V
FL { 7, 2 }
c) Memory access time = 480 ns.
Associative memory access time = 50 ns.
Effective access time =
(access time for associative memory + access time for memory) * hit probability
+ (access time for associative memory + 2 * access time for memory) * miss
probability

- If hit ration 50%:


EAT = (50 + 480) * 0.50 + ( 50 + 2 * 480) * 0.50 = 265 + 505 = 770
- If hit ration 90%:
EAT = (50 + 480) * 0.90 + ( 50 + 2 * 480) * 0.10 = 477 + 101 = 578

d) A higher hit probability make associative memory effective.


Question # 7:

a) Assume a page size of 1KB, the logical address space is 8KB and the physical address space
is 16KB. Answer the following questions:
i. What is the highest degree of parallelism?
ii. What is the length in bits of the physical address field?
iii. What is the length in bits of the logical address field?
iv. What is the length of the Page Table?

b) Assume that the page size is 128 bytes; the current program size is 635 bytes and the physical
space 2048 bytes. Before the program is loaded the free frame list is {10, 7, 2, 9, 12, 4, 8, 14}.
Answer the following questions after loading the above program in main memory:
i. What is the internal fragment size?
ii. What is the physical address of 128?
iii. What is the physical address of 635?
iv. What is the logical address of the 2-D physical address <10,120>?

Answer Q 7:

a)
v. 16 programs.
vi. 16KB = 24*210 = 214  14 bits
vii. 8KB = 23*210 = 213  13 bits
viii. 23 = 8 pages.
b)
v. 5
vi. 7 * 128 + (128 128) = 896
vii. 12 * 128 + (635 512) = 1659
viii. 120
Question # 8:
Consider the following segment mapping table (SMT)

Segment Base Length (limit)


0 219 600
1 2300 14
2 90 100
3 1327 580
4 1952 96

What are the physical addresses of the following logical addresses?


a) <0, 430>
b) <1, 10>
c) <2, 500>
d) <3, 500>
e) <4, 122>
f) <6, 1952>

Answer Q 8:
a) <0, 430>  219 + 430 = 649
b) <1,10>  2300 + 10 = 2310
c) <2,500>  Trap (500 >= 100)
d) <3,500>  1327 + 500 = 1827
e) <4,122>  Trap (122 >= 96)
f) <6,1952>  Trap (6 is an invalid entry)

Question # 9:
Given a logical address field with the following format:
2 bits 16 bits 8 bits
Seg # Page # Page Offset

Answer the following questions:


a. What is the number of segments?
b. What is the maximum size of the segment?
c. What is the size of a page?
d. What is the maximum number of pages per segment?

Answer Q 9:

a. 22 = 4 segments
b. 216+8 = 224
c. 28
d. 216
Question # 10:

Assume a hardware mechanism using a combined segmentation and paging. The user logical address
space can have up to 8 segments of 64KB each. Each segment can have up to 64 pages of 1024 bytes
each. Given a 4-segment user program P (S0: 4000 bytes, S1: 4000 bytes, S2: 4000 bytes, S3: 4000
bytes) and the free frame list is {12, 23, 32, 45, 57, 64, 72, 81, 99, 103, 120, 124, 108, 90, 85, 78, 67,
55, 46, 33, 25, 16, 8, 27, 38, 49, 51, 62}

Translate the following 1-dimensional logical addresses 6452 and 12846 into 1-dimensional physical
addresses after performing memory allocation.

Answer Q 10:

4000 / 1024 = 4 pages


S0 need 4 pages {12, 23, 32, 45}
S1 need 4 pages {57, 64, 72, 81}
S2 need 4 pages {99, 103, 120, 124}
S3 need 4 pages {108, 90, 85, 78}
Logical address 6452
4000 < 6452 < 7999  S1
6452 4000 = 2452  < S1, 2452>
Page number is (2452 / 1024 = 2) , address in page #2 is (2452 - 1024*2 = 404)  <2, 404>
<2,404> change to frame #  <2,404> = <72,404>
Physical address = 72 * 1024 + 404 = 74132

Logical address 12846


12000 < 12846 < 15999  S3
12846 12000 = 846  <S3, 846>
Page number is (846 / 1024 = 0), address in page #0 is (846 1024 * 0)  <0, 846>
<0, 846> change to frame #  <0, 846> = <108, 846>
Physical address = 108 * 1024 + 846 = 111438

You might also like