• No results found

lecture 22 chapter 4

N/A
N/A
Protected

Academic year: 2020

Share "lecture 22 chapter 4"

Copied!
30
0
0

Loading.... (view fulltext now)

Full text

(1)

07/10/2020 1

discover yourself

inspire posterity

CHAPTER 4

(2)

Buddy System

1. In buddy systems memory can be divided into

sections, with each location being a buddy of

another location.

2. Whenever possible the buddies are combined to

create a larger memory location.

3. If smaller memory needs to be allocated the

buddies are divided, and then reunited (if possible)

when the memory is returned.

4. In reality the memory is combined and only

broken down when requested.

(3)
(4)
(5)
(6)
(7)
(8)
(9)
(10)
(11)

Buddy System in 1MB memory

(12)

Sequence of Requests

Program A requests memory 34K..64K in size Program B requests memory 66K..128K in size Program C requests memory 35K..64K in size Program D requests memory 67K..128K in size Program C releases its memory

Program A releases its memory Program B releases its memory Program D releases its memory

(13)

If memory is to be allocated

Look for a memory slot of a suitable size

If it is found, it is allocated to the program

If not, it tries to make a suitable memory slot. The system

does so by trying the following:

Split a free memory slot larger than the requested memory size

into half

If the lower limit is reached, then allocate that amount of memory Go back to step 1 (look for a memory slot of a suitable size)

Repeat this process until a suitable memory slot is found

(14)

A binary buddy heap before allocation

A binary buddy heap after allocating a 8 KB block

A binary buddy heap after allocating a 10 KB block; note the 6 KB wasted because of rounding up

(15)

If memory is to be freed

Free the block of memory

Look at the neighbouring block - is it free too?

If it is, combine the two, and go back to step 2 and repeat this

process until either the upper limit is reached (all memory is freed).

(16)

Unfortunately with Buddy Systems there can be

significant internal fragmentation.

Case ‘Program A requests 34k Memory’ – but was assigned

64 bit memory.

The sequence of block sizes allowed is;

1,2,4,8,16…2m

(17)

Page Replacement Algorithms

Decide which memory page to swap out (write to disk) from memory to allocate a new page to memory

The OS has to choose a page to remove from memory to make room for the page that has to be swapped in.

(18)

What if there is no free frame?

Page replacement –find some page in memory, but not

really in use, swap it out

In this case, same page may be brought into memory

several times

(19)

Basic Page Replacement

(20)
(21)

PAGE REPLACEMENT ALGORITHMS

1- FIFO Page Replacement Algorithm 2- Optimal Page Replacement Algorithm 3- The Least Recently Used

4- Not Recently/frequently Used

(22)

Page Replacement Algorithms

FIFO Page Replacement Algorith

m

1. The simplest page-replacement algorithm is a first-in, first-out (FIFO) algorithm.

2. The operating system keeps track of all the pages in memory in a queue, with the most recent arrival at the back, and the earliest arrival in front.

3. A FIFO replacement algorithm associates with each page the time when that page was brought into memory.

4. When a page needs to be replaced, the page at the front of the queue (the oldest page) is selected.

(23)

Page Replacement Algorithms

10/07/202

0 23

Treats page frames allocated to a process as a circular

buffer:

When the buffer is full, the oldest page is replaced. Hence first-in, first-out:

(24)

FIFO Page Replacement Algorithms

10/07/202

0 24

(25)

Page Replacement Algorithms

10/07/202

0 25

1. The first three references (7, 0, 1) cause page faults and are brought into these empty frames.

2. The next reference (2) replaces page 7, because page 7 was brought in first.

3. Since 0 is the next reference and 0 is already in memory, we have no fault for this reference.

4. The first reference to 3 results in replacement of page 0, since it is now first in line.

5. Because of this replacement, the next reference, to 0, will fault.

6. Page 1 is then replaced by page O. This process continues…

(26)

Page Replacement Algorithms

10/07/202

0 26

EXERCISE-1

Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string

In all our examples, the reference string is

1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

(27)

When a page must be replaced, the oldest page is

chosen

• In all our examples, the reference string is

1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

3 frame (9 page faults)

4 frame (10 page faults)

Notice that the number of faults for 4 frames is greater than the number of faults for 3 frames!! This unexpected result is known as Belady’s anomaly

(28)

discover yourself

inspire posterity

(29)

FIFO Illustrating Belady’s Anomaly

(30)

Modeling Page Replacement Algorithms

10/07/2020 30

Belady's Anomaly

FIFO with 3 page frames • FIFO with 4 page frames

P's show which page references show page faults

-It might seem that more page frames, fewer page faults a program will get. - Belady’s discovered that more page frames more will be the page faults.

References

Related documents

While studies have demonstrated that LLCs increase students’ sense of belonging, the goal of this study is to explicitly test via propensity score matching if (a) enrollment in

• Setting the Memory Debug Incremental Starting Time, page 4 • Displaying Memory Leak Information Incrementally, page 4.. Displaying Memory

Beograd, Savez jevrejskih veroispovednih opština Jugoslavije [Association of Jewish Religious Communities of Yugoslavia].

Marxism holds that a !rocess of class conflict and Marxism holds that a !rocess of class conflict and reolutionary struggle %ill result in ictory for the reolutionary struggle

The average profit figures below (Figure 17) are for all types of business generated by firms with an FCA Primary category "Financial Adviser" (as shown in Figure 16 above)

firms and (b) the number of advising staff (as defined earlier) for retail investment business (Figure 12), non-investment insurance (Figure 13) and mortgages 8 (Figure 14),

Private wine tasting for 20 in the Private Room of the Bellevue or Tukwila Total Wine store. Artisan wine

It was during that year that Lions International President Donald Banker came to Baltimore to witness the document sign- ing which created the Multiple District 22 Lions