Upload
sreedevi-yashpal
View
218
Download
0
Embed Size (px)
Citation preview
8/19/2019 mem alloc and process scheduling grogramming
1/27
Dynamic Storage-Allocation Problem
• First-ft: Allocate the frst hole that is bigenough
• Best-ft: Allocate the smallest hole that isbig enough; must search entire list, unlessordered by size – Produces the smallest leftover hole
• Worst-ft: Allocate the largest hole; mustalso search entire list –
Produces the largest leftover hole
How to satisfy a request of sizen from a list offree holes?
First-fit and best-fit better than worst-fit in terms
of speed and storage utilization
8/19/2019 mem alloc and process scheduling grogramming
2/27
Data Structures:
Free list & allocation list
8/19/2019 mem alloc and process scheduling grogramming
3/27
First Fit :
i/:! re"uired memory## $%
• First-ft: Allocate the frst hole that isbig enough
8/19/2019 mem alloc and process scheduling grogramming
4/27
After rst t
8/19/2019 mem alloc and process scheduling grogramming
5/27
'est Fit :
i/:! re"uired memory## (%
• Best-ft: Allocate the smallest holethat is big enough; must search entirelist, unless ordered by size
8/19/2019 mem alloc and process scheduling grogramming
6/27
After 'est Fit
8/19/2019 mem alloc and process scheduling grogramming
7/27
)orst Fit :
i/:! re"uired memory## (%
• Worst-ft: Allocate the largest hole;must also search entire list
8/19/2019 mem alloc and process scheduling grogramming
8/27
After )orst Fit
8/19/2019 mem alloc and process scheduling grogramming
9/27
De allocation
• De allocates the re"uested rocessfrom allocation list to free list
• i/:! rocess no
• *g: +
8/19/2019 mem alloc and process scheduling grogramming
10/27
After de allocation
8/19/2019 mem alloc and process scheduling grogramming
11/27
Process
• a rogram in eecution, -hich formsthe basis of all comutation
• rocess eecution must rogress inse"uential fashion
• Program is assive entity, rocess is
active – Program becomes rocess -hen
eecutable le loaded into memory
8/19/2019 mem alloc and process scheduling grogramming
12/27
Process Scheduling
• .aimize P0 use, "uic1ly s-itch rocesses
onto P0 for time sharing• Process scheduler selects among available
rocesses for net eecution on P0
• .aintains scheduling queues of rocesses – Job queue 2 set of all rocesses in the system
– Ready queue 2 set of all rocesses residing inmain memory, ready and -aiting to eecute
– Device queues 2 set of rocesses -aiting for an3/4 device
– Processes migrate among the various "ueues
8/19/2019 mem alloc and process scheduling grogramming
13/27
P0 Scheduler
• Selects from among the rocesses in ready "ueue,
and allocates the P0 to one of them – 5ueue may be ordered in various -ays
• P0 scheduling decisions may ta1e lace -hen arocess:
+6S-itches from running to -aiting state
76S-itches from running to ready state
86S-itches from -aiting to ready
96erminates
• Scheduling under + and 9 is nonreemtive
• All other scheduling is reemtive –.onsider access to shared data
–.onsider reemtion -hile in 1ernel mode
–.onsider interruts occurring during crucial 4S activities
8/19/2019 mem alloc and process scheduling grogramming
14/27
onreemtive scheduling
• 0nder nonreemtive scheduling,once the P0 has been allocated to arocess, – the rocess 1ees the P0 until it
releases the P0 either by terminatingor by s-itching to the -aiting state6
8/19/2019 mem alloc and process scheduling grogramming
15/27
Scheduling riteria• !P" utili#ation 2 1ee the P0 as busy as ossible
• $hroughut 2 < of rocesses that comlete theireecution er time unit
• $urnaround time 2 amount of time to eecute aarticular rocess
• Waiting time 2 amount of time a rocess has been-aiting in the ready "ueue
• Resonse time 2 amount of time it ta1es from-hen a re"uest -as submitted until the rstresonse is roduced, not outut =for time!sharing
environment>
8/19/2019 mem alloc and process scheduling grogramming
16/27
Scheduling Algorithm 4timizationriteria
• .a P0 utilization
• .a throughut
• .in turnaround time
• .in -aiting time
• .in resonse time
8/19/2019 mem alloc and process scheduling grogramming
17/27
First-!ome% First-Served &F!FS'Scheduling
Process 'urst ime
P1 79 P2 8
P3 8 • Suose that the rocesses arrive in the order:
P1 , P2 , P3 he ?antt hart for the schedule is:
• )aiting time for P1 @ %; P2 @ 79; P3 @ 7
• Average -aiting time: =% B 79 B 7>/8 @ +
P1 P2 P3
24 27 300
8/19/2019 mem alloc and process scheduling grogramming
18/27
FFS Scheduling =ont6>
Suose that the rocesses arrive in the order:
P2 , P3 , P1
• he ?antt chart for the schedule is:
• )aiting time for P1= C;
P2 @ %
;P3= 8
• Average -aiting time: =C B % B 8>/8 @ 8
• .uch better than revious case
• !onvoy e(ect ! short rocess behind long rocess – onsider one P0!bound and many 3/4!bound rocesses
P1P3P2
63 300
8/19/2019 mem alloc and process scheduling grogramming
19/27
Shortest!ob!First =SF> Scheduling
• Associate -ith each rocess the
length of its net P0 burst – 0se these lengths to schedule the
rocess -ith the shortest time
• SF is otimal 2 gives minimumaverage -aiting time for a given set
of rocesses – he diEculty is 1no-ing the length of the
net P0 re"uest
– ould as1 the user
8/19/2019 mem alloc and process scheduling grogramming
20/27
*amle of SF ProcessArr iva e'urst ime
P1 %6% C
P2 76%
P3 96%
P4 $6% 8• SF scheduling chart
• Average -aiting time @ =8 B +C B ( B %> / 9 @
P4 P3P1
3 160 9
P2
24
8/19/2019 mem alloc and process scheduling grogramming
21/27
Determining Gength of et P0 'urst
• an only estimate the length 2
should be similar to the reviousone
– hen ic1 rocess -ith shortestredicted net P0 burst
• Preemtive version called
shortest-remaining-time-frst
8/19/2019 mem alloc and process scheduling grogramming
22/27
*amle of Shortest-remaining-time-frst
• o- -e add the concets of varying arrival times andreemtion to the analysis
ProcessA arri Arrival ime 'urst ime
P1 %
P2 + 9
P3 7 ( P4 8 $
• Preemptive SF ?antt hart
• Average -aiting time @ C6$ msec
P1 P1P2
1 170 10
P3
265
P4
am e o or es rema n ng
8/19/2019 mem alloc and process scheduling grogramming
23/27
am e o or es -rema n ng-time-frst ProcessA arri Arrival ime 'urst ime
P1 %
P2 + 9
P3
7 (
P4 8 $
• Heeat the follo-ing until cl1 I sumburst
• For rocess + to n
•
hec1 PJiK6atimeIcl1 and JiK6rtimeL% – oy the rocess JiK into ready "ueue r"JMK
– Select min from ready "ueue6= for sMf min=burst> forriority min=ri>
–
3f reemting the rocess in eecution rint ganttchart
– Do rocess scheduling• Decrement r"JMK6rtime of rocessing rocess
• 3ncrement r"JILMK6 -time of other rocesses in r"
• 3ncrement cl1
8/19/2019 mem alloc and process scheduling grogramming
24/27
Priority Scheduling
• A riority number =integer> is associated -ith eachrocess
• he P0 is allocated to the rocess -ith the highestriority =smallest integer ≡ highest riority> –
Preemtive – onreemtive
• *"ual riority rocesses are scheduled in FFS order
• Problem ≡ Starvation 2 lo- riority rocesses may
never eecute
• Solution ≡ Aging 2 as time rogresses increase theriority of the rocess
8/19/2019 mem alloc and process scheduling grogramming
25/27
*amle of Priority Scheduling
ProcessA arri 'urst ime Priority
P1 +% 8 P2 + +
P3 7 9
P4 + $
P5$ 7• Priority scheduling ?antt hart
• Average -aiting time @ 67 msec
P2 P3P5
1 180 16
P4
196
P1
H d H bi =HH>
8/19/2019 mem alloc and process scheduling grogramming
26/27
Hound Hobin =HH>
• *ach rocess gets a small unit of P0 time =timequantum ">, usually +%!+%% milliseconds6 Afterthis time has elased, the rocess is reemtedand added to the end of the ready "ueue6
• 3f there are n rocesses in the ready "ueue andthe time "uantum is q, then each rocess gets
+/n of the P0 time in chun1s of at most q timeunits at once6 o rocess -aits more than =n!+>qtime units6
• imer interruts every "uantum to schedule net
rocess• Performance
– q large ⇒ F3F4
– q small ⇒ q must be large -ith resect to
contet s-itch, other-ise overhead is too high
8/19/2019 mem alloc and process scheduling grogramming
27/27
*amle of HH -ith ime 5uantum @ 9
Process 'urst ime
P179
P2 8
P3 8
• he ?antt chart is:
• yically, higher average turnaround than SF, but betterresponse
• " should be large comared to contet s-itch time
• " usually +%ms to +%%ms, contet s-itch I +% usec
P1 P2 P3 P1 P1 P1 P1 P1
0 4 7 10 14 18 22 26 30