📄 implement
字号:
.de P1.DS...de P2.DE...de UL.lg 0.if n .ul\%\&\\$3\f3\\$1\fR\&\\$2.lg...de UC\&\\$3\s-1\\$1\\s0\&\\$2...de IT.lg 0.if n .ul\%\&\\$3\f2\\$1\fR\&\\$2.lg...de SP.sp \\$1...hw device.TLUNIX Implementation.AU "MH 2C-523" 2394K. Thompson.AI.MH.ABThis paper describes in high-level terms theimplementation of the resident.UXkernel.This discussion is broken into three parts.The first part describeshow the.UXsystem views processes, users, and programs.The second part describes the I/O system.The last part describes the.UXfile system..AE.NHINTRODUCTION.PPThe.UXkernel consists of about 10,000lines of C code and about 1,000 lines of assembly code.The assembly code can be further broken down into200 lines included forthe sake of efficiency(they could have been written in C)and 800 lines to perform hardwarefunctions not possible in C..PPThis code represents 5 to 10 percent of what hasbeen lumped into the broad expression``the.UXoperating system.''The kernel is the only.UXcode thatcannot be substituted by a user to hisown liking.For this reason,the kernel should make as few realdecisions as possible.This does not mean to allow the usera million options to do the same thing.Rather, it means to allow only one way todo one thing,but have that way be the least-common divisorof all the options that might have been provided..PPWhat is or is not implemented in the kernelrepresents both a great responsibility and a great power.It is a soap-box platform on``the way things should be done.''Even so, if``the way'' is too radical,no one will follow it.Every important decision was weighedcarefully.Throughout,simplicity has been substituted for efficiency.Complex algorithms are used only iftheir complexity can be localized..NHPROCESS CONTROL.PPIn the.UXsystem,a user executes programs in anenvironment called a user process.When a system function is required,the user process calls the systemas a subroutine.At some point in this call,there is a distinct switch of environments.After this,the process is said to be a system process.In the normal definition of processes,the user and system processes are differentphases of the same process(they never execute simultaneously).For protection,each system process has its own stack..PPThe user process may executefrom a read-only text segment,which is shared by all processesexecuting the same code.There is no.IT functionalbenefitfrom shared-text segments.An.IT efficiencybenefit comes from the factthat there is no need to swap read-onlysegments out because the originalcopy on secondary memory is still current.This is a great benefit to interactiveprograms that tend to be swapped whilewaiting for terminal input.Furthermore,if two processes areexecutingsimultaneouslyfrom the same copy of a read-only segment,only one copy needs to reside inprimary memory.This is a secondary effect,becausesimultaneous execution of a programis not common.It is ironic that this effect,which reduces the use of primary memory,only comes into play when there isan overabundance of primary memory,that is,when there is enough memoryto keep waiting processes loaded..PPAll current read-only text segments in thesystem are maintained from the.IT "text table" .A text table entry holds the location of thetext segment on secondary memory.If the segment is loaded,that table also holds the primary memory locationand the count of the number of processessharing this entry.When this count is reduced to zero,the entry is freed along with anyprimary and secondary memory holding the segment.When a process first executes a shared-text segment,a text table entry is allocated and thesegment is loaded onto secondary memory.If a second process executes a text segmentthat is already allocated,the entry reference count is simply incremented..PPA user process has some strictly privateread-write datacontained in itsdata segment.As far as possible,the system does not use the user'sdata segment to hold system data.In particular,there are no I/O buffers in theuser address space..PPThe user data segment has two growing boundaries.One, increased automatically by the systemas a result of memory faults,is used for a stack.The second boundary is only grown (or shrunk) byexplicit requests.The contents of newly allocated primary memoryis initialized to zero..PPAlso associated and swapped witha process is a small fixed-sizesystem data segment.This segment contains allthe data about the processthat the system needs only when theprocess is active.Examples of the kind of data containedin the system data segment are:saved central processor registers,open file descriptors,accounting information,scratch data area,and the stack for the system phaseof the process.The system data segment is notaddressable from the user processand is therefore protected..PPLast,there is a process table withone entry per process.This entry contains all the dataneeded by the system when the processis.IT notactive.Examples arethe process's name,the location of the other segments,and scheduling information.The process table entry is allocatedwhen the process is created, and freedwhen the process terminates.This process entry is always directlyaddressable by the kernel..PPFigure 1 shows the relationshipsbetween the various process controldata.In a sense,the process table is thedefinition of all processes,becauseall the data associated with a processmay be accessedstarting from the process table entry..KS.sp 2.44i.sp 2v.ceFig. 1\(emProcess control data structure..KE.NH 2Process creation and program execution.PPProcesses are created by the system primitive.UL fork .The newly created process (child) is a copy of the original process (parent).There is no detectable sharing of primary memory between the two processes.(Of course,if the parent process was executing from a read-onlytext segment,the child will share the text segment.)Copies of all writable data segmentsare made for the child process.Files that were open before the.UL forkaretruly shared after the.UL fork .The processes are informed as to their part in therelationship toallow them to select their own(usually non-identical)destiny.The parent may.UL waitfor the termination ofany of its children..PPA process may.UL execa file.This consists of exchanging the current text and datasegments of the process for new text and datasegments specified in the file.The old segments are lost.Doing an.UL execdoes.IT notchange processes;the process that did the.UL execpersists,butafter the.UL execit is executing a different program.Files that were openbefore the.UL execremain open after the.UL exec ..PPIf a program,say the first pass of a compiler,wishes to overlay itself with another program,say the second pass,then it simply.UL exec sthe second program.This is analogousto a ``goto.''If a program wishes to regain controlafter.UL exec inga second program,it should.UL forka child process,have the child.UL execthe second program, andhave the parent.UL waitfor the child.This is analogous to a ``call.''Breaking up the call into a binding followed bya transfer is similar to the subroutine linkage inSL-5..[griswold hanson sl5 overview.].NH 2Swapping.PPThe major data associated with a process(the user data segment,the system data segment, andthe text segment)are swapped to and from secondarymemory, as needed.The user data segment and the system data segmentare kept in contiguous primary memory to reduceswapping latency.(When low-latency devices, such as bubbles,.UC CCD s,or scatter/gather devices,are used,this decision will have to be reconsidered.)Allocation of both primaryand secondary memory is performedby the same simple first-fit algorithm.When a process grows,a new piece of primary memory is allocated.The contents of the old memory is copied to the new memory.The old memory is freedand the tables are updated.If there is not enough primary memory,secondary memory is allocated instead.The process is swapped out onto thesecondary memory,ready to be swapped in withits new size..PPOne separate process in the kernel,the swapping process,simply swaps the otherprocesses in and out of primary memory.It examines theprocess table looking for a processthat is swapped out and isready to run.It allocates primary memory for thatprocess andreads its segments intoprimary memory, where that process competes for thecentral processor with other loaded processes.If no primary memory is available,the swapping process makes memory availableby examining the process table for processesthat can be swapped out.It selects a process to swap out,writes it to secondary memory,frees the primary memory,and then goes back to look for a processto swap in..PPThus there are two specific algorithmsto the swapping process.Which of the possibly many processes thatare swapped out is to be swapped in?This is decided by secondary storage residencetime.The one with the longest time out is swapped in first.There is a slight penalty for larger processes.Which of the possibly many processes thatare loaded is to be swapped out?Processes that are waiting for slow events(i.e., not currently running or waiting fordisk I/O)are picked first,by age in primary memory,again with size penalties.The other processes are examinedby the same age algorithm,but are not taken out unless they areat least of some age.This addshysteresis to the swapping andprevents total thrashing..PPThese swapping algorithms are themost suspect in the system.With limited primary memory,these algorithms cause total swapping.This is not bad in itself, becausethe swapping does not impact theexecution of the resident processes.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -