memory allocation policies author aniket phatak. ameya gawde. daishik mehta. memory allocation...

28

Upload: noel-barrett

Post on 20-Jan-2016

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit
Page 2: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Memory Allocation Policies

AuthorAniket Phatak.Ameya Gawde.Daishik Mehta.

Memory Allocation policies like Next fit, Best fit, Worst fit.

Page 3: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Objectives: After interacting with this Learning object; you will be able to:

1. Identify the best placement algorithm

2. Construct the first fit, best fit, next fit and worst fit algorithm.

1. Identify the worst placement algorithm.

Page 4: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Master layout or diagram Make a schematic diagram of the concept

Explain the animator about the beginning and ending of the process.

Draw image big enough for explaining.

In above image, identify and label different components of the

process/phenomenon. (These are like characters in a film)

Illustrate the basic flow of action by using arrows. Use BOLD

lines in the diagram, (minimum 2pts.)

In the slide after that, provide the definitions of ALL the labels

used in the diagram

5

3

2

4

1INSTRUCTIONS SLIDE

Page 5: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Master Layout 1

5

3

2

4

1Truck

Truck

Car

Car

Car

Scooter

Scooter

PARKING AREA

Images from the foll site: http://darkdemon.org/bolt/sticks/

www.fotosearch.com/FSP628/803054/ www.speedysigns.com/decals/graphic_decal_8894.htm

Fig 1:

Page 6: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Master Layout 2

5

3

2

4

1Truck

Truck

Car

Car

Car

Scooter

Scooter

PARKING AREA

Images from the foll site: http://darkdemon.org/bolt/sticks/ www.fotosearch.com/FSP628/803054/ www.speedysigns.com/decals/graphic_decal_8894.htm

Fig 1: Best Fit

Comes 2nd

Comes 1st

Comes 3rd

Comes 4th

Comes 5th

Comes 6th

Truck

Truck

Car

Car

Car

Scooter

Scooter

PARKING AREA

Fig 2: Next Fit

Comes 2nd

Comes 1st

Comes 3rd

Comes 4th

Comes 5th

The truck coming 6th does not get parking

Page 7: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Master Layout 3

5

3

2

4

1Truck

Truck

Car

Car

Car

Scooter

Scooter

PARKING AREA

Images from the foll site: http://darkdemon.org/bolt/sticks/ www.fotosearch.com/FSP628/803054/ www.speedysigns.com/decals/graphic_decal_8894.htm

Fig 3: Worst fit

Comes 2nd

Comes 1st

Comes 3rd

Comes 4th

Comes 5th

Comes 6th

Both the trucks don’t get parking

Page 8: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Master Layout 4

5

3

2

4

1Truck

Truck

Car

Car

Car

Scooter

Scooter

PARKING AREA

Images from the foll site: http://darkdemon.org/bolt/sticks/ www.fotosearch.com/FSP628/803054/ www.speedysigns.com/decals/graphic_decal_8894.htm

Fig 4: First fit

Comes 2nd

Comes 1st

Comes 3rd

Comes 4th

Comes 5th

Comes 6th

The truck does not get parking

Page 9: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Master Layout 5

5

3

2

4

1 Fig 4a: Next fit

Fig 4b: Worst fit

100 K

500K

200K

300K

388K

100 K

500K

200K

300K

388K

176K

Page 10: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Master Layout 6

5

3

2

4

1 Fig 4c: Best fit

100 K

500K

200K

300K

600K88K

100 K

500K

200K

300K

600K88K

83K 426K

100 K

500K

200K

300K

600K

88K

83K

88K

Fig 4d: First fit

100 K

500K

200K

300K

600K

288K

100 K

500K

200K

300K

600K

288K

183K

426K

100 K

500K

200K

300K

600K

176K

183K

100 K

500K

200K300K

600K183K

176K

Page 11: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Definitions of the components:

5

3

2

4

1Memory management:- It is the process of partitioning and allocating partitions to various

processes.Partition:- It is the block of memory that can be fixed or made dynamically.Fragmentation:-The left over space inside the partition is called fragmentation.

External Fragmentation: External fragmentation is the phenomenon in which free storage becomes divided into many small pieces over time.

For example, in dynamic memory allocation, a block of 1000 bytes might be requested,but the largest contiguous block of free space has only 300 bytes. Even if there are ten blocks of 300 bytes of free space, separated by allocated regions, one still cannot allocate the

requested block of 1000 bytes, and the allocation request will fail.

Internal fragmentation: Internal fragmentation is where the memory manager allocates more for each allocation than is actually requested.

For example, in many file systems, each file always starts at the beginning of a cluster, because this simplifies organization and makes it easier to grow files. Any space left over between

the last byte of the file and the first byte of the next cluster is a form of internal fragmentation called file slack or slack space.

Paging: Paging is a memory management technique that permits the physical address space of a program to be non-contiguous. Paging allocates memory in fixed-size chunks called pages.

Compaction: Compaction attacks the problem of fragmentation by moving all the allocated blocks to one end of memory, thus combining all the holes.

Page 12: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Explain the process1

5

3

2

4

In this step, use an example to explain the concept. It can be an analogy, a scenario, or an action which explains this concept/process/topic

Try to use examples from day-to-day life to make it more clear

You have to describe what steps the animator should take to make your concept come alive as a series of moving images.

Keep the examples simple to understand, and also to illustrate/animate.

Page 13: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Analogy / Scenario / Action1

5

3

2

4

Example: Parking Space Management

Consider a scooter, car and truck are looking out space for parking. They arrive in the order mentioned below:

ScooterCarTruckScooterCarTruck

The parking spaces are available for each one of them as per their size constraints. (Fig 1)

In the space for truck parking, a car and a scooter can be parked or even two scooters besides truck itself.

Similarly, for car parking two scooters can be parked other than itself.

Click on play to see the Best fit, Worst fit and Next fit.

Page 14: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Stepwise description of process

The goal of the IDD is to provide instructions to an animator who is not a expert.

You have to describe what steps the animator should take to make your concept come alive as a moving visualization.

Use one slide per step. This will ensure clarity of the explanation.

Add a image of the step in the box, and the details in the table below the box.

You can use any images for reference, but mention about it's copyright status

The animator will have to re-draw / re-create the drawings

Add more slides as per the requirement of the animation

1

5

3

2

4

Page 15: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Step 1: Analogy 1

5

3

2

4

Action

Description of the action

Text

First show the empty parking lot (master layout 1).

Then show the text 1.

In Master layout 2 fig 1:

Show a scooter coming (1st) from the top right corner and gets parked in the scooter’s parking place.

Show the car coming (2nd) from the same place and gets parked in the car parking area.

Show the truck coming (3rd) and gets parked in the truck parking area.

This continues for one more scooter (4th), car (5th) and truck (6th) coming in the same order.

Text 2 appears

The animation disappears and step 2 is shown.

1. Let us see how the best fit memory allocation policy works in the parking lot analogy.

2. Best Fit: In this algorithm, closest minimum available memory block is allocated to process.

Page 16: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Step 2: Analogy 1

5

3

2

4

Action

Description of the action

Text

First show the empty parking lot (master layout 1).

Then show the text 1.

In master layout 2 fig 2:

Show a scooter coming (1st) from the top right corner and gets parked in the trucks parking place.

Show the car coming (2nd) getting parked next to the scooter in the same truck parking area.

Show the truck coming (3rd) getting parked in the second truck parking area.

This continues for one more scooter (4th), car (5th) and truck (6th) the truck comes and does not get parking so leaves the parking lot

Text 2 appears

Text 3 appears

The animation disappears and step 2 is shown.

1. Let us see how the Next fit memory allocation policy works in the parking lot analogy.

2. The second truck does not get parking in the next fit memory allocation policy.

3. Next Fit: In this algorithm, memory is scanned from current location for next available block that has sufficient space to accommodate it.

Page 17: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Step 3: Analogy 1

5

3

2

4

Action

Description of the action

Text

First show the empty parking lot (master layout 1).

Then show the text 1.

In master layout 3 fig 3:

Show a scooter coming (1st) from the top right corner and gets parked in the trucks parking place.

Show the car coming (2nd), gets parked in the second truck parking area.

Show the truck coming (3rd) goes away when it does not get parking.

This continues for one more scooter (4th), car (5th) and truck (6th) the truck comes and does not get parking so leaves the parking lot

Text 2 appears

Text 3 appears

The animation disappears and step 2 is shown.

1. Let us see how the Worst fit memory allocation policy works in the parking lot analogy.

2. Both the trucks do not get parking in the worst fit memory allocation policy.

3. Worst Fit: In this concept, maximum available memory is allocated to the process demanding for it. Thus, it is logically contrasting to best fit algorithm.

Page 18: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Step 4: Analogy 1

5

3

2

4

Action

Description of the action

Text

First show the empty parking lot (master layout 1).

Then show the text 1.

In master layout 4 fig 4:

Show a scooter coming (1st) from the top right corner and gets parked in the trucks parking place.

Show the car coming (2nd), gets parked in the same truck parking area.

Show the truck coming (3rd) gets parked in the second truck parking area.

This continues for one more scooter (4th), car (5th) and truck (6th) the truck comes and does not get parking so leaves the parking lot

Text 2 appears

Text 3 appears

The animation disappears and step 2 is shown.

1. Let us see how the First fit memory allocation policy works in the parking lot analogy.

2. The last truck does not get parking in the first fit memory allocation policy.

3. First Fit: In first Fit the data fits into memory by scanning from the beginning of available memory to the end, until the first free space which is at least big enough to accept the data is found. This space is then allocated to the data. Any left over becomes a smaller, separate free space

Page 19: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Animation design

Please see the design template provided in the next slide.

This is a sample template, and you are free to change as per your design requirements.

Try and recreate the sections/subsections as shown in the template.

1

5

2

4

3

Page 20: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Want to know more…(Further Reading)

Definitions

Formula with derivation (if any)

Graphs/Diagram(for reference)

Animation Area

Test your understanding (questionnaire)

Lets Learn!

Concepts

Assumptions (if any)

Lets Sum up (summary)

Instructions/ Working area

Suggestions

Did you know? (entry behaviour)

Keywords

Radio buttons (if any) Drop down (if any)

Value inputs (if any)

Enter Play/pause Restart

Feedback below the animation

What will you learn

Summative evaluation

If any of them are not mentioned in the IDD deleted

Page 21: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Interactivity and Boundary limits In this section, you will add the ‘Interactivity’ options to the animation.

Use the template in the next slide to give the details.

Insert the image of the step/s (explained earlier in the Section 3) in the box, and provide the details in the table below.

The details of Interactivity could be: Types: Drop down, Slider bar, Data inputs etc. Options: Select one, Multiple selections etc Boundary Limits: Values of the parameters, which won’t

show results after a particular point Results: Explain the effect of the interaction in this column

Add more slides if necessary

1

2

5

3

4

Page 22: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Interactivity option: Step No: 51

5

3

2

4

Interactivity type and action

Questions and Options

Boundary limits

Feedback

Results and output

Radio button (for fit algorithms)

Drag and drop

For the given partition of memory blocks and memory process sizes choose the memory allocation policy and complete the memory allocation process by dragging and dropping the process sizes

____

If the learner is taking more than 2 tries for one process size the following hint is shown

For Best Fit: In this algorithm, closest minimum available memory block is allocated to process.

For Worst Fit: In this concept, maximum available memory is allocated to the process demanding for it. Thus, it is logically contrasting to best fit algorithm.

For Next Fit: In this algorithm, memory is scanned from current location for next available block that has sufficient space to accommodate it.

For First Fit: In this algorithm, memory is scanned from the first location for next available block that has sufficient space to accommodate it.

If Best fit allocation policy is chosen then ref to fig 4c (master layout 6)

If Next fit allocation policy is chosen then ref to fig 4a (master layout 5)

If Worst fit allocation policy is chosen then ref to fig 4b (master layout 5)

If First fit allocation policy is chosen then ref to fig 4d (master layout 6)

Output: (for worst fit and first fit algorithm)

The request for 426K will be rejected in case of next fit and worst fit algorithm because any single partition is less than 426K

Partition of memory blocks Process sizes

212K

112K

412K

426K

Page 23: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Interactivity option: Step No: 6

Interactivity type and action

Questions and Options

Boundary limits

Results

Data Input

For the given partition of memory blocks and memory process sizes choose the memory allocation policy and complete the memory allocation process by dragging and dropping the process sizes

No of process: 2-4

Process size: 50K- 350K

No of process:

2-4

Process size:

25K to 350K

Best fit: the 1st process size will go into the slot same as its size or little bigger than its size. And the same for the second one and so on. Eg: if the process sizes are 75K, 125K, 225K and 314K. 75K gets in slot 100K, 125K in 200K, 225K in 300K and 314K in 350K.

Worst fit: the 1st process size will go into the biggest slot. And the same for the second one and so on. Eg: if the process sizes are 75K, 125K, 225K and 314K. 75K will get placed in 350K, 125K in 300K, 225K in 350K (as 225K is left n is bigger than 200K) and 314K will not get placed.

Next fit: the 1st process size will go into the first slot which has the space for it. second one into a slot which is bigger than it after the 1st slot and so on. Eg: if the process sizes are 75K, 125K, 225K and 314K. Then 75 K will go into the second slot. Now the next slot for 125K will be 350K, next slot for 225K will be 300K and 314K will not be placed anywhere.

Next fit: the 1st process size will go into the first slot which has the space for it. second one into a slot which is bigenough for it from the top again and so on. Eg: if the process sizes are 75K, 100K, 25K and 314K. Then 75 K will go into the second slot, 100K will be in 115K slot, 25K will be 50K slot and 314K will be in 350K slot.

1

5

3

2

4

Partition of memory blocks Process sizesNo of Process:50K

100K

115K

350K

300K

200K

Page 24: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Interactivity option: Step No: 7

Interactivity type and action

Questions and Options B

oundary limitsR

esults

Data Input

Input the number and size of the process and see the best placement algorithm and worst fit algorithm

No of process: 2-4

Process size: 50K- 350K

No of process:

2-4

Process size:

25K to 350K

The worst placement algorithm for any process is best fit: (once learner clicks on the button show the best fit algorithm) Best fit: the 1st process size will go into the slot same as its size or little bigger than its size. And the same for the second one and so on. Eg: if the process sizes are 75K, 125K, 225K and 314K. 75K gets in slot 100K, 125K in 200K, 225K in 300K and 314K in 350K.

The best placement algorithm for any process is worst fit: (once learner clicks on the button show the worst fit algorithm) Worst fit: the 1st process size will go into the biggest slot. And the same for the second one and so on. Eg: if the process sizes are 75K, 125K, 225K and 314K. 75K will get placed in 350K, 125K in 300K, 225K in 350K (as 225K is left n is bigger than 200K) and 314K will not get placed.

1

5

3

2

4

Partition of memory blocks Process sizesNo of Process:50K

100K

115K

350K

300K

200K

Best placement algorithm

Worst placement algorithm

Page 25: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

INSTRUCTIONS SLIDE

Questionnaire to test the user A small, (5 questions) questionnaire can

be created in the next slide, to test the

user's comprehension.

This can be an objective type

questionnaire.

It can also be an exercise, based on the

concept taught in this animation.

Please give the answer key also.

Page 26: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Questionnaire1. Which is the best placement algorithm?

Answers: a) Worst fit b) Best fit c) Next fit d) None of them

2. Which is the worst placement algorithm?

Answers: a) Next fit b) Best fit c) Worst fit d) None of them

3. Probability of getting hole of bigger size after allocating memory to a process is high

in:

Answers: a) First fit b) Best fit c) Worst fit d) Probability is same in all

4. Let there be N block in memory. So in multiprogramming environment the degree of multiprogramming is bounded by:

Answers: a) N-1 b) N/2 c) N+1 d) N

5. External fragmentation is caused mainly by:

Answers:

a) Worst-fit and Best-fit b) First-fit and Worst-fit c) First-fit & Best-fit d) None of the above.

1

5

2

4

3

Page 27: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Links for further reading

Reference websites:

Books:

Operating Systems Internals & Design Principles-William Stallings.

Operating System Concepts- Silberschatz, Galvin, Gagne.

Modern Operating Systems- Andrew S. Tanenbaum.

Research papers:

Page 28: Memory Allocation Policies Author Aniket Phatak. Ameya Gawde. Daishik Mehta. Memory Allocation policies like Next fit, Best fit, Worst fit

Summary:

1. Best Fit: In this algorithm, closest minimum available memory block is allocated to process.

1. Worst Fit: In this concept, maximum available memory is allocated to the process demanding for it. Thus, it is logically contrasting to best fit algorithm.

1. Next Fit: In this algorithm, memory is scanned from current location for next available block that has sufficient space to accommodate it.

1. Worst-fit algorithm is the best placement algorithm because it results in less amount of fragmentation.

1. Best-fit is the worst placement algorithm because it scans the entire memory space resulting in more time