operating systems prof. navneet goyal department of computer science & information systems bits,...

19
Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Upload: joelle-weatherhead

Post on 16-Dec-2015

222 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Operating SystemsProf. Navneet GoyalDepartment of Computer Science & Information SystemsBITS, Pilani

Page 2: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Topics for Today•Thrashing•Working Set

Page 3: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Thrashing

•Swapping out a piece of a process just before that piece is needed

•The processor spends most of its time swapping pieces rather than executing user instructions

Page 4: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Principle of Locality•Program and data references within a

process tend to cluster•Only a few pieces of a process will be

needed over a short period of time•Possible to make intelligent guesses

about which pieces will be needed in the future

•This suggests that virtual memory may work efficiently

Page 5: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Locality In A Memory-Reference Pattern

Page 6: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Thrashing•If a process does not have “enough”

pages, the page-fault rate is very high. This leads to:▫low CPU utilization▫operating system thinks that it needs

to increase the degree of multiprogramming

▫another process added to the system

•Thrashing a process is busy swapping pages in and out

Page 7: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Thrashing (Cont.)

Page 8: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Demand Paging and Thrashing

•Why does demand paging work?Locality model▫Process migrates from one locality to another▫Localities may overlap

•Why does thrashing occur? size of locality > total memory size

Page 9: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Working-Set Model• working-set window a fixed number of page

references Example: 10,000 instruction

•WSSi (working set size of Process Pi) =total number of pages referenced in the most recent (varies in time)▫ if too small will not encompass entire locality▫ if too large will encompass several localities▫ if = will encompass entire program

•D = WSSi total demand frames • if D > m Thrashing• Policy if D > m, then suspend one of the processes

Page 10: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Working-set model

Page 11: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Keeping Track of the Working Set• Approximate with interval timer + a reference

bit• Example: = 10,000▫Timer interrupts after every 5000 time units▫Keep in memory 2 bits for each page▫Whenever a timer interrupts copy and sets the

values of all reference bits to 0▫If one of the bits in memory = 1 page in

working set• Why is this not completely accurate?• Improvement = 10 bits and interrupt every

1000 time units

Page 12: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Page Size•Smaller page size, less amount of

internal fragmentation•Smaller page size, more pages required

per process•More pages per process means larger

page tables•Larger page tables means large portion

of page tables in virtual memory•Secondary memory is designed to

efficiently transfer large blocks of data so a large page size is better

Page 13: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Page Size•Small page size, large number of

pages will be found in main memory•As time goes on during execution, the

pages in memory will all contain portions of the process near recent references. Page faults low.

•Increased page size causes pages to contain locations further from any recent reference. Page faults rise.

Page 14: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani
Page 15: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Frame Allocation: Issues

• Smaller no. of frames to a process – more processes can reside in MM – increases probability that OS will find at least one ready process

• Despite Principle of Locality, Page faults rate will be high

• Beyond a certain size, additional allocation will have no noticeable effect on page fault rate because of Principle of Locality

Page 16: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Frame Allocation Schemes

• Fixed Allocation– Equal Allocation– Proportional Allocation

• Priority Allocation

Page 17: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Fixed AllocationEqual allocation – e.g., if 100 frames and 5 processes,

give each 20 pages.Proportional allocation – Allocate according to the size

of process.

mS

spa

m

sS

ps

iii

i

ii

for allocation

frames ofnumber total

process of size

5964137

127

564137

10

127

10

64

2

1

2

1

a

a

s

s

m

Page 18: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Priority Allocation

• Use a proportional allocation scheme using priorities rather than size.

• If process Pi generates a page fault,– select for replacement one of its frames.– select for replacement a frame from a process

with lower priority number.

Page 19: Operating Systems Prof. Navneet Goyal Department of Computer Science & Information Systems BITS, Pilani

Global vs. Local Allocation

•Global replacement – process selects a replacement frame from the set of all frames; one process can take a frame from another.

•Local replacement – each process selects from only its own set of allocated frames.