









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










What is Program Swapping?
Process Swap Area
Main Memory
Process
Main Memory
Swap Area
Swap Out
Swap In
Handle by direct call (2024 ) on the procedure xswap (4368)
Handle by direct call (2034 ) on the procedure swap (5196)
Process 0
Process …
Process …
Process 0
Sched
Sched spends most of its time waiting in one of the following situation
called by “newproc”.
•There is atleast one process swapped out and ready to run but it
hasn’t been out more than 3 seconds and none of the process
present in main memory is inactive or has been more than 2 seconds.
•The situation can be changed by a call to “sleep”
Find the process ready to run,select the longest one
A search made for the process which is ready to run and has been swapped out for the longest time
Sched Procedure
There is no such process, situation A holds
main memory area for to hold data segment if text segment needs to be present also text segment the size needs to be increased
If it has adequate size text and data then goto found2(2031)
If the process is waiting for event of low precedence &which is not locked and state is swait or sstop but not ssleep then goto swap out
If image to be swapped in has been <3 sec ,B holds
Search for the process which is loaded but not locked whose state is srun or ssleep (waiting for high precedence) and been in mem for longest time
Process swapped out is < sec ,situation B holds Swap out using xswap and process image is flagged as not loaded
Read the text seg into mm Swap( addr within swap area, mm addr, size, direction indicator)
Release disk swap area to the available list,record mm addr,set the sload reset the accumulated time indicator
There are three files whose contents are essential to UNIX
input/output:
This file declares two structures:
“struct buf”
This structure is buffer header and serves as a buffer control block
Position on free list Major+minor device name transfer count
block # on device returned after I/O words not transferred
Status flags
The buf structure may be divided into three
sections:
“struct buf” (continued)
Flags
List pointer
The File “conf.c”
“Swbuf” controls swapping input and output
Swbuf in “bio.c”
Swbuf Continued (An Example)
The code for swap displays some of the problems of race conditions when several processes are running together
A
Process “A” initiates a swapping operation
A
A
Flags==B_BUSY | B_PHYS | rdflg
Swbuf Continued (An Example)
A
B
Process “B” initiates a swapping operation
Flags==B_BUSY | B_PHYS | rdflg
B
Swbuf Continued (An Example)
A
B
Wake up
Wake up
What happens next depends on the order in which A and B are reactivated
Flags== B_BUSY | B_PHYS | rdflg | B_DONE
Sets Flags to
Swbuf Continued (An Example)
Case 1: A goes first:
•“B_DONE” is set (so no more sleeping is needed) (^) •“B_WANTED” is reset (so there is no wakeup)
Process “A” finishes up and sets: Flags==B_PHYS | rdflg | B_DONE
A A
A
B
Process B can now finish
Swbuf Continued (An Example)
Case 2: B goes first:
•Finds “B_BUSY” •Turns “B_WANTED” on
Goes to sleep again leaving: Flags==B_BUSY | B_PHYS | rdflg | B_DONE | B_WANTED
Process “A” starts again: it finds B_WANTED on •Process A calls “wakeup”
Summary
•The “buff” structure in “buf.h” is buffer header and serves as a buffer control block. •“Swbuf” (an instance of the buf structure) controls the process of swapping input and output.