Midterm Review - University of Iowahomepage.divms.uiowa.edu/.../midterm-review.pdf · Midterm...

Post on 15-Aug-2020

11 views 0 download

Transcript of Midterm Review - University of Iowahomepage.divms.uiowa.edu/.../midterm-review.pdf · Midterm...

Midterm Review

Logistics• Exam on:

• Friday, Nov 20th (in class)• Tuesday, Nov 17th (in my office 15:00)

• Covers: Chapters 1 — 5 • The exam is closed book. No calculators, no laptops, no computing devices! • You may bring one (letter-size) pages of notes • The exam may include:

• multiple choice • fill-in-the answer questions• short programming problems (you should use pseudocode)

• Show all your work: • state assumptions• details your steps

2

WhatisanOperatingSystem?

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

WhatisanOperatingSystem?

• Topdownview– Provideabstractionstoapplicationprograms

• Bottomupview– Managepiecesofcomplexsystem

• Alternativeview– Provideorderly,controlledallocationofresources

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

HardwareAbstraction

Figure1-6.Someofthecomponentsofasimplepersonalcomputer.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Processors

Figure1-7.(a)Athree-stagepipeline.(b)AsuperscalarCPU.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Memory• There is a trade-off between access time and capacity • How can we take advantage of the memory hierarchy to achieve high

performance? • caching and locality principle

7

Cost

Chapter 2: Processes & Threads

The Process Model

9

Figure2-1.(b)Conceptualmodeloffourindependent,sequentialprocesses.

Process CreationFour principal events that cause processes to be created:

1. System initialization 2. Execution of a process creation system call by a running process 3. A user request to create a new process 4. Initiation of a batch job

10Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Process TerminationTypical conditions which terminate a process: 1.Normal exit (voluntary). 2.Error exit (voluntary). 3.Fatal error (involuntary). 4.Killed by another process (involuntary).

11

Process States (1)• Three states a process may be in:

1.Running (actually using the CPU at that instant).2.Ready (runnable; temporarily stopped to let another process run).3.Blocked (unable to run until some external event happens).

12

Process States

13

Types of processes• CPU-bound processes

• spend of their time performing computations

• IO-bound processes • spend most of the time being blocked for IO

• Note: the speed of CPUs is increasing faster than that of IO devices • over time, processes become IO bound

14

ProcessStates(3)

Figure2-3.Thelowestlayerofaprocess-structuredoperatingsystemhandlesinterruptsandscheduling.Abovethatlayerare

sequentialprocesses.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

ImplementationofProcesses(1)

Figure2-4.Someofthefieldsofatypicalprocesstableentry.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Implementation Notes• Process creation is typically expensive • Processes are interrupted numerous times during their execution

• for each interrupt, the process must save its state to be resumed later • >> context switches are expensive!

17

ImplementationofProcesses(2)

Figure2-5.Skeletonofwhatthelowestleveloftheoperatingsystemdoeswhenaninterruptoccurs.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

ModelingMultiprogramming

Figure2-6.CPUutilizationasafunctionofthenumberofprocessesinmemory.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

ThreadUsage(2)

Figure2-8.AmultithreadedWebserver.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

ThreadUsage(3)

Figure2-9.AroughoutlineofthecodeforFig.2-8.(a)Dispatcherthread.(b)Workerthread.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

TheClassicalThreadModel(1)

Figure2-11.(a)Threeprocesseseachwithonethread.(b)Oneprocesswiththreethreads.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

TheClassicalThreadModel(2)

Figure2-12.Thefirstcolumnlistssomeitemssharedbyallthreadsinaprocess.Thesecondonelistssomeitemsprivateto

eachthread.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

TheClassicalThreadModel(3)

Figure2-13.Eachthreadhasitsownstack.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

User space vs. kernel threads• User space threads

• pros:• inexpensive thread switch times• applications can better manage their own threads than the OS

• complications:• how to handle blocking system calls?• how to handle page faults?• how to handle “run-away” threads?

• Kernel threads • cons:

• thread switches are expensive (why?)• the above issues are not a challenge (why?)

• complications:• what happens when a process forks?

25

CategoriesofSchedulingAlgorithms

1. Batch.2. Interactive.3. Realtime.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

SchedulingAlgorithmGoals

Figure2-40.Somegoalsoftheschedulingalgorithmunderdifferentcircumstances.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

SchedulinginBatchSystems

• First-ComeFirst-Served• ShortestJobFirst• ShortestRemainingTimeNext

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

ShortestJobFirst

Figure2-41.Anexampleofshortestjobfirstscheduling.(a)Runningfourjobsintheoriginalorder.(b)Runningtheminshortestjobfirstorder.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

SchedulinginInteractiveSystems

• Round-RobinScheduling• PriorityScheduling• MultipleQueues• ShortestProcessNext• GuaranteedScheduling• LotteryScheduling• Fair-ShareScheduling

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Round-RobinScheduling

Figure2-42.Round-robinscheduling.(a)Thelistofrunnableprocesses.(b)ThelistofrunnableprocessesafterBusesupitsquantum.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

B CA

time 100 101 103

FCFS

BA

time 2 5 103

Round Robin

C A C

Scenario #1

A

A100ms

B1ms

C 2ms

Ready Queue

Avg:101.3

Avg:36.7

Scenario #2

B CA

time 10 20 30

FCFS

BA

time 28 29 30

Round Robin

C A CB ... BA C A CB

A10ms

B10ms

C 10ms

Avg:20

Avg:29

Ready Queue

Scenario #1

Avg:101.3

A100ms

B1ms

C 2ms

Avg:36.7

1 3 103

STCFAvg:35.7

B CA

time 100 101 103

FCFS

BA

time 2 5 103

Round Robin

C A C A

AB C

Ready Queue

Scenario #2

B CA

time 10 20 30

FCFS

BA

time 28 29 30

Round Robin

C A C

Avg:20

B ... BA C A CB

A10ms

B10ms

C 10ms

Avg:29

B CA

time 10 20 30

STCFAvg:20

Ready Queue

HybridImplementations

Figure2-17.Multiplexinguser-levelthreadsontokernel-levelthreads.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Independent and Cooperating Threads• Independent thread: one that can't affect or be affected by the rest of the

universe • Its state isn't shared in any way by any other thread• Deterministic: input state alone determines results• Reproducible• Can stop and continue with no bad effects (only time varies)

• Cooperating threads: those that share state • Behavior is nondeterministic: depends on relative execution sequence and

cannot be predicted in advance• Behavior may be irreproducible

37

Cooperating threads• Basic assumption for cooperating threads is that the order of some operations

is irrelevant; certain operations are independent of certain other operations. • Examples:

• Thread 1: A = 1;Thread 2: B = 2;

• Thread 1: A = B+1;Thread 2: B = 2*B;

38

Atomic Operations• Before we can say ANYTHING about cooperating threads, we must know that

some operation is atomic: it either happens in its entirety without interruption, or not at all. Cannot be interrupted in the middle. • References and assignments are atomic in almost all systems. A=B will always

read a clean value for B and set a clean value for A (but not necessarily true for arrays or records).

• In uniprocessor systems, anything between interrupts is atomic.• If you don't have an atomic operation, you can't make one. Fortunately, hardware

designers give us atomic ops.• If you have any atomic operation, you can use it to generate higher-level

constructs and make parallel programs work correctly. This is the approach we'll take in this class.

39

Critical Section Problem• Definition: n processes repeatedly execute a critical and then non-critical

section of code

• Goals: • mutual exclusion - no two processes execute at the critical section at the same time• livelock - if two processes are trying to enter the critical section at least one succeeds• no unnecessary delay - if a process is trying to enter its critical section and the others

are in their non-critical section, the first process should not be prevented from entering its critical section

• eventual entry - a process attempting to enter the critical section will eventually succeed

40

process CS[i = 1 to N] {while (true) {

entry protocolcritical sectionexit protocolno critical section

}}

Critical Section Problem

• Two types of properties: • safety: mutual exclusion, livelock, no unnecessary delay• liveness: eventual entry

41

process CS[i = 1 to N] {while (true) {

entry protocolcritical sectionexit protocolno critical section

}}

CS 140 Lecture Notes: Concurrency 42

Too Much Milk

Roommate A 3:00 Arrive home: no milk 3:05 Leave for store 3:10 Arrive at store 3:15 Leave store 3:20 Arrive home, put milk away

CS 140 Lecture Notes: Concurrency 43

Too Much Milk

Roommate A Roommate B 3:00 Arrive home: no milk 3:05 Leave for store 3:10 Arrive at store Arrive home: no milk 3:15 Leave store Leave for store 3:20 Arrive home, put milk away Arrive at store 3:25 Leave store 3:30 Arrive home: too much milk!

CS 140 Lecture Notes: Concurrency 44

Computerized Milk Purchase

1 if (milk == 0) { 2 if (note == 0) { 3 note = 1; 4 buy_milk(); 5 note = 0; 6 } 7 }

CS 140 Lecture Notes: Concurrency 45

Still Too Much Milk Thread A: Thread B: 1 if (milk == 0) { 2 if (note == 0) { 3 if (milk == 0) { 4 if (note == 0) { 5 note = 1; 6 buy_milk(); 7 note = 0; 8 } 9 } 10 note = 1; 11 buy_milk(); 12 note = 0; 13 } 14 }

CS 140 Lecture Notes: Concurrency 46

Second Attempt

Thread A:

1 if (note == 0) { 2 if (milk == 0) { 3 buy_milk(); 4 } 5 note = 1; 6 }

Thread B:

1 if (note == 1) { 2 if (milk == 0) { 3 buy_milk(); 4 } 5 note = 0; 6 }

CS 140 Lecture Notes: Concurrency 47

Third Attempt

Thread A:

1 noteA = 1; 2 if (noteB == 0) { 3 if (milk == 0) { 4 buy_milk(); 5 } 6 } 7 noteA = 0;

Thread B:

1 noteB = 1; 2 if (noteA == 0) { 3 if (milk == 0) { 4 buy_milk(); 5 } 6 } 7 noteB = 0;

CS 140 Lecture Notes: Concurrency 48

Fourth Attempt

Thread A:

1 noteA = 1; 2 if (noteB == 0) { 3 if (milk == 0) { 4 buy_milk(); 5 } 6 } 7 noteA = 0;

Thread B:

1 noteB = 1; 2 while (noteA == 1) { 3 // do nothing 4 } 5 if (milk == 0) { 6 buy_milk(); 7 } 8 noteB = 0;

CS 140 Lecture Notes: Concurrency 49

Too Much Milk With Locks

Both threads:

struct lock l;

...

lock_acquire(&l); if (milk == 0) { buy_milk(); } lock_release(&l);

CS 140 Lecture Notes: Locks 50

Producer/Consumer, v1char buffer[SIZE]; int count = 0; int putIndex = 0, getIndex = 0; struct lock l; lock_init(&l); void put(char c) { lock_acquire(&l); count++; buffer[putIndex] = c; putIndex++; if (putIndex == SIZE) { putIndex = 0; } lock_release(&l); }

char get() { char c; lock_acquire(&l); count--; c = buffer[getIndex]; getIndex++; if (getIndex == SIZE) { getIndex = 0; } lock_release(&l); return c; }

CS 140 Lecture Notes: Locks 51

Producer/Consumer v2char buffer[SIZE]; int count = 0; int putIndex = 0, getIndex = 0; struct lock l; lock_init(&l); void put(char c) { lock_acquire(&l); while (count == SIZE) { lock_release(&l); lock_acquire(&l); } count++; buffer[putIndex] = c; putIndex++; if (putIndex == SIZE) { putIndex = 0; } lock_release(&l); }

char get() { char c; lock_acquire(&l); while (count == 0) { lock_release(&l); lock_acquire(&l); } count--; c = buffer[getIndex]; getIndex++; if (getIndex == SIZE) { getIndex = 0; } lock_release(&l); return c; }

CS 140 Lecture Notes: Locks 52

Producer/Consumer v3char buffer[SIZE]; int count = 0; int putIndex = 0, getIndex = 0; struct lock l; struct condition dataAvailable; struct condition spaceAvailable;

lock_init(&l); cond_init(&dataAvailable); cond_init(&spaceAvailable); void put(char c) { lock_acquire(&l); while (count == SIZE) { cond_wait(&spaceAvailable, &l); } count++; buffer[putIndex] = c; putIndex++; if (putIndex == SIZE) { putIndex = 0; } cond_signal(&dataAvailable, &l); lock_release(&l); }

char get() { char c; lock_acquire(&l); while (count == 0) { cond_wait(&dataAvailable, &l); } count--; c = buffer[getIndex]; getIndex++; if (getIndex == SIZE) { getIndex = 0; } cond_signal(&spaceAvailable, &l); lock_release(&l); return c; }

T1 T2 T3

MemoryManagement

Chapter3

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Memory

• ParaphraseofParkinson’sLaw,‘‘Programsexpandtofillthememoryavailabletoholdthem.’’

• Averagehomecomputernowadayshas10,000timesmorememorythantheIBM7094,thelargestcomputerintheworldintheearly1960s

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

NoMemoryAbstraction

Figure3-1.Threesimplewaysoforganizingmemorywithanoperatingsystemandoneuserprocess.Otherpossibilitiesalsoexist

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

RunningMultipleProgramsWithoutaMemoryAbstraction

Figure3-2.Illustrationoftherelocationproblem.(a)A16-KBprogram.(b)Another16-KBprogram.(c)Thetwoprogramsloadedconsecutivelyintomemory.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

BaseandLimitRegisters

Figure3-3.Baseandlimitregisterscanbeusedtogiveeachprocessaseparate

addressspace.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Swapping(1)

Figure3-4.Memoryallocationchangesasprocessescomeintomemoryandleaveit.Theshadedregionsareunusedmemory

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Swapping(2)

Figure3-5.(a)Allocatingspaceforagrowingdatasegment.(b)Allocatingspaceforagrowingstackandagrowingdatasegment.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

MemoryManagementwithBitmaps

Figure3-6.(a)Apartofmemorywithfiveprocessesandthreeholes.Thetickmarksshowthememoryallocationunits.The

shadedregions(0inthebitmap)arefree.(b)Thecorrespondingbitmap.(c)Thesameinformationasalist.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

MemoryManagementwithLinkedLists

Figure3-7.Fourneighborcombinationsforthe terminatingprocess,X.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

MemoryManagementAlgorithms

• Firstfit• Nextfit• Bestfit• Worstfit• Quickfit

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

VirtualMemory

• Thereisaneedtorunprogramsthataretoolargetofitinmemory

• Solutionadoptedinthe1960s,splitprogramsintolittlepieces,calledoverlays– Keptonthedisk,swappedinandoutofmemory

• Virtualmemory:eachprogramhasitsownaddressspace,brokenupintochunkscalledpages

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Paging(1)

Figure3-8.ThepositionandfunctionoftheMMU.HeretheMMUisshownasbeingapartoftheCPUchipbecause

itcommonlyisnowadays.However,logicallyit couldbeaseparatechipandwasyearsago.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Paging(2)

Figure3-9.Therelationbetweenvirtualaddressesandphysicalmemoryaddressesisgivenbythepagetable.Everypagebeginsonamultipleof4096andends4095addresseshigher,so4K–8Kreallymeans4096–8191

and8Kto12Kmeans8192–12287

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Paging(3)

Figure3-10.Theinternal operationoftheMMUwith164-KBpages.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

StructureofaPageTableEntry

Figure3-11.Atypicalpagetableentry.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

SpeedingUpPaging

Majorissuesfaced:1.Themappingfromvirtualaddresstophysicaladdressmustbefast.2.Ifthevirtualaddressspaceislarge,thepagetablewillbelarge.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

TranslationLookasideBuffers

Figure3-12.ATLBtospeeduppaging.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

MultilevelPageTables

Figure3-13.(a)A32-bitaddresswithtwopagetablefields.(b)Two-level

pagetables.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

PageReplacementAlgorithms• Optimalalgorithm• Notrecentlyusedalgorithm• First-in,first-out(FIFO)algorithm• Second-chancealgorithm• Clockalgorithm• Leastrecentlyused(LRU)algorithm• Workingsetalgorithm• WSClockalgorithm

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

ClockPageReplacementAlgorithm

Figure3-16.Theclockpagereplacementalgorithm.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

SimulatingLRUinSoftware

Figure3-17.TheagingalgorithmsimulatesLRUinsoftware.Shownaresixpagesforfiveclockticks.Thefiveclockticksarerepresentedby(a)to(e).

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

WorkingSetAlgorithm(1)

Figure3-18.Theworkingsetisthesetofpagesusedbythekmostrecentmemoryreferences.Thefunctionw(k,t)isthesizeoftheworkingsetattimet.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

WSClockAlgorithm(1)

Figure3-20.OperationoftheWSClockalgorithm.(a)and(b)giveanexampleofwhathappenswhenR=1.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

WSClockAlgorithm(2)

Figure3-20.OperationoftheWSClockalgorithm.(c)and(d)giveanexampleofR=0.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

WorkingSetAlgorithm(2)

Figure3-19.Theworkingsetalgorithm.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

SummaryofPageReplacementAlgorithms

Figure3-21.Pagereplacementalgorithmsdiscussedinthetext.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

PageFaultHandling(1)

1. Thehardwaretrapstokernel,savingprogramcounteronstack.

2. Assemblycoderoutinestartedtosavegeneralregistersandothervolatileinfo

3. systemdiscoverspagefaulthasoccurred,triestodiscoverwhichvirtualpageneeded

4. Oncevirtualaddresscausedfaultisknown,systemcheckstoseeifaddressvalidandtheprotectionconsistentwithaccess

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

PageFaultHandling(2)

5. Ifframeselecteddirty,pageisscheduledfortransfertodisk,contextswitchtakesplace,suspendingfaultingprocess

6. Assoonasframeclean,operatingsystemlooksupdiskaddresswhereneededpageis,schedulesdiskoperationtobringitin.

7. Whendiskinterruptindicatespagehasarrived,tablesupdatedtoreflectposition,andframemarkedasbeinginnormalstate.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

PageFaultHandling(3)

8. Faultinginstructionbackeduptostateithadwhenitbeganandprogramcounterisreset

9. Faultingprocessisscheduled,operatingsystemreturnstoroutinethatcalledit.

10.Routinereloadsregistersandotherstateinformation,returnstouserspacetocontinueexecution

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Segmentation(1)Examplesoftablesgeneratedbycompiler:1.Thesourcetextbeingsavedfortheprintedlisting2.Thesymboltable,namesandattributesofvariables.3.Thetablecontainingintegerandfloating-pointconstantsused.4.Theparsetree,syntacticanalysisoftheprogram.5.Thestackusedforprocedurecallswithincompiler.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Segmentation(2)

Figure3-30.Inaone-dimensionaladdressspacewithgrowingtables,onetablemaybumpintoanother.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Segmentation(3)

Figure3-31.Asegmentedmemoryallowseachtabletogroworshrinkindependentlyoftheothertables.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

Segmentation(4)

Figure3-32.Comparisonofpagingandsegmentation

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

SegmentationwithPaging:MULTICS(1)

Figure3-34.TheMULTICSvirtualmemory.(a)Thedescriptorsegmentpointedtothepagetables.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

SegmentationwithPaging:MULTICS(2)

Figure3-34.TheMULTICSvirtualmemory.(b)Asegmentdescriptor.Thenumbersarethefieldlengths.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

SegmentationwithPaging:MULTICS(3)

Figure3-35.A34-bitMULTICSvirtualaddress.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

SegmentationwithPaging:MULTICS(4)

Figure3-36.Conversionofatwo-partMULTICSaddressintoamainmemoryaddress.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

SegmentationwithPaging:MULTICS(5)

Figure3-37.AsimplifiedversionoftheMULTICSTLB.TheexistenceoftwopagesizesmadetheactualTLBmorecomplicated.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

FileSystems

Chapter4

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

FileOperations

1. Create2. Delete3. Open4. Close5. Read6. Write

7. Append8. Seek9. Getattributes10. Setattributes11. Rename

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

HierarchicalDirectorySystems

Figure4-7.Ahierarchicaldirectorysystem.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

DirectoryOperations

1. Create2. Delete3. Opendir4. Closedir

5. Readdir6. Rename7. Link8. Unlink

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

FileSystemLayout

Figure4-9.Apossiblefilesystemlayout.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

ImplementingFilesContiguousLayout

Figure4-10.(a)Contiguousallocationofdisk spaceforsevenfiles.(b)Thestateofthe

diskafterfilesDandFhavebeenremoved.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

ImplementingFilesLinkedListAllocation

Figure4-11.Storingafileasalinkedlistofdiskblocks.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

ImplementingFilesLinkedList–TableinMemory

Figure4-12.Linkedlistallocationusingafileallocationtableinmainmemory.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

ImplementingFilesI-nodes

Figure4-13.Anexamplei-node.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

ImplementingDirectories(1)

Figure4-14.(a)Asimpledirectorycontainingfixed-sizeentrieswiththediskaddressesandattributesinthedirectoryentry.(b)A

directoryinwhicheachentryjustreferstoani-node.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

ImplementingDirectories(2)

Figure4-15.Twowaysofhandlinglongfilenamesinadirectory.(a)In-line.(b)Inaheap.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

JournalingFileSystems

StepstoremoveafileinUNIX:1.Removefilefromitsdirectory.2.Releasei-nodetothepooloffreei-nodes.3.Returnalldiskblockstopooloffreediskblocks.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

DiskSpaceManagement(1)

Figure4-20.Percentageoffilessmallerthanagivensize(inbytes).

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

FileSystemConsistency

Figure4-27.Filesystemstates.(a)Consistent.(b)Missingblock.(c)Duplicateblockinfreelist.(d)Duplicatedatablock.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.

DiskSpaceManagement(2)

Figure4-21.Thedashedcurve(left-handscale)givesthedatarateofadisk.Thesolidcurve(right-handscale)givesthediskspaceefficiency.Allfilesare4KB.

Tanenbaum&Bo,ModernOperatingSystems:4thed.,(c)2013Prentice-Hall,Inc.Allrightsreserved.