10
Silberschatz, Galvin and Gagne 2002 9.1 Operating System Concepts Dynamic Storage Allocation Algorithms for Allocation First-Fit Best-Fit Worst-Fit Algorithm for Delete Fifty-Percent Rule

Dynamic Storage Allocation

  • Upload
    kolton

  • View
    105

  • Download
    0

Embed Size (px)

DESCRIPTION

Dynamic Storage Allocation. Algorithms for Allocation First-Fit Best-Fit Worst-Fit Algorithm for Delete Fifty-Percent Rule. Dynamic Storage-Allocation Problem. First-fit : Allocate the first hole that is big enough. - PowerPoint PPT Presentation

Citation preview

Page 1: Dynamic Storage Allocation

Silberschatz, Galvin and Gagne 20029.1Operating System Concepts

Dynamic Storage Allocation

Algorithms for Allocation First-Fit Best-Fit Worst-Fit

Algorithm for Delete Fifty-Percent Rule

Page 2: Dynamic Storage Allocation

Silberschatz, Galvin and Gagne 20029.2Operating System Concepts

Dynamic Storage-Allocation Problem

First-fit: Allocate the first hole that is big enough. Best-fit: Allocate the smallest hole that is big enough;

must search entire list, unless ordered by size. Produces the smallest leftover hole.

Worst-fit: Allocate the largest hole; must also search entire list. Produces the largest leftover hole.

How to satisfy a request of size n from a list of free holes.

First-fit and best-fit better than worst-fit in terms of speed and storage utilization.

50-percent rule: Given N allocated blocks another 1/2N will be lost due to fragmentation 1/3 of memory lost.

Page 3: Dynamic Storage Allocation

Silberschatz, Galvin and Gagne 20029.3Operating System Concepts

Fragmentation

External Fragmentation – total memory space exists to satisfy a request, but it is not contiguous.

Internal Fragmentation – allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used.

Reduce external fragmentation by compaction Shuffle memory contents to place all free memory together in one

large block. Compaction is possible only if relocation is dynamic, and is done at

execution time. I/O problem

Latch job in memory while it is involved in I/O. Do I/O only into OS buffers.

50-percent rule – Given N allocated blocks another 1/2N will be lost due to fragmentation 1/3 of memory lost.

Page 4: Dynamic Storage Allocation

Silberschatz, Galvin and Gagne 20029.4Operating System Concepts

Best Fit vs. First Fit

Memory sizes 1300 and 1200 Requests: 1000, 1100, 250

Request First-Fit Best-Fit 1300, 1200 1300, 1200 1000 300, 1200 1300, 200 1100 300, 100 200, 200 250 50, 100 stuck

Page 5: Dynamic Storage Allocation

Silberschatz, Galvin and Gagne 20029.5Operating System Concepts

Best Fit vs. First Fit

Memory sizes 1300 and 1200 Requests: 1100, 1050, 250

Request First-Fit Best-Fit 1300, 1200 1300, 1200 1100 200, 1200 1300, 100 1050 200, 150 250, 200 250 stuck 0, 200

Page 6: Dynamic Storage Allocation

Silberschatz, Galvin and Gagne 20029.6Operating System Concepts

First-Fit Method

Request a block of size N. Returns first available block of size N. If no block available, then returns NULL

AVAIL points to first available block

1. [Initialize] Q AVAIL

2. [End of list?] P Next(Q); If P = NULL return(NULL).

3. [Check size.] if Size(P) N goto 4 else Q P; goto 2.

4. [Reserve block.] K Size(P) – N.

if K = 0 Next(Q) Next(P) else Size(P) K;

Return(P+K).

Page 7: Dynamic Storage Allocation

Silberschatz, Galvin and Gagne 20029.7Operating System Concepts

First-Fit Method

Improvements In step 4, if K < c (small constant) return block of size N +

K.

Roving pointer. Start next search where previous search ended. This prevents accumulation of small blocks in the beginning of AVAIL.

Page 8: Dynamic Storage Allocation

Silberschatz, Galvin and Gagne 20029.8Operating System Concepts

Free

Assume AVAIL is sorted by memory location (if P NULL, Next(P) > P).

return block of size N beginning at location P0.

1. [Initialize.] Q AVAIL.2. [Advance P.] P Next(Q).

if P = NULL or P > P0 goto 3 else Q P and repeat.3. [Check upper bound.]

if P0 + N = P and P NULL N N + Size(P); Next(P0) Next(P) else Next(P0) P.

4. [Check lower bound.] if Q + Size(Q) = P0 Size(Q) Size(Q) + N; Link(Q) Link(P0) else Link(Q) Po; Size(P0) N.

Page 9: Dynamic Storage Allocation

Silberschatz, Galvin and Gagne 20029.9Operating System Concepts

Improvements to Free

Use doubly linked list and tags to free in constant time.

Page 10: Dynamic Storage Allocation

Silberschatz, Galvin and Gagne 20029.10Operating System Concepts

Fifty Percent Rule

If allocation and deletion are used continually in such a way that the system tends to an equilibrium condition, where there are N reserved blocks in the system, on the average, each equally likely to be the next one deleted, and where the probability that allocating a new block does not change the number of blocks is p, then the average number of available blocks tends to approximately 1/2pN.

N = A + B + C (number of reserved blocks) M = ½(2A + B + ), {0,1,2} (number of available blocks) Average change in M when a block is freed is (C-A)/N and when

a block is allocated is (1-p) C - A - N + Np = 0 2M = N + A - C +

A B C C B A B B B C B B