What is an Operating System? A program between computer users users and computer hardware hardware
T To o manage and use computer har hardware dware in an efcient manner
Operating system goals:
T To o provide an env environment ironment or users to execute execute programs in a convenient and efcient manner T To o ensure the cor correct rect operation o the computer system system
OS is a resource allocator
anages all resources
!ecides between con"icting re#uests or efcient and air ai r resource use
OS is a control program
$ontrols execution execution o programs to prevent errors and improper use o the computer
system (OS OS)) is software that manages manages computer hardware and hardware and software software resources resources and provides An operating system ( common services services for computer programs. programs. The operating system is an essential component of the the system software in software in a computer system. Application programs usually require an operating system to function. Time-sharing operating systems schedule tasks for efficient use of the system and may also include accounting Time-sharing software for cost allocation of processor time, mass storage, printing, and other resources. For hardware functions such as input and output and memory allocation, allocation, the operating system acts as an intermediary !"#!$# $# etween programs and the computer hardware,!"#! although the application code is usually e%ecuted directly y the
hardware and frequently makes a a system call call to an &' function or e interrupted y it. &perating systems can e found on many devices that contain a computerfrom cellular phones and phones and video game consoles consoles to to supercomputers supercomputers and and we servers.. servers %amples of popular modern operating systems include include Android, Android, *'+ *'+,, i&' i&',, inu% inu%,, &' , , / /,, 0icrosoft 1indows, 1indows, 1indows 3hone, 3hone, and and 4*0 56&'. 56&'. All these e%amples, e%cept 1indows, 1 indows, 1indows 3hone and 56&', share roots
!2#
in 7/4 7/4..
Operating System Components 8ernel
o
3rogram e%ecution
4nterrupts
0odes
0emory management
9irtual memory
0ultitasking
+isk access and file systems
+evice drivers
o
/etworking
o
'ecurity
o
7ser interface :raphical user interfaces
For detail ;refer http;66en.wikipedia.org6wiki6&perating<system
Processes A program is a passive thing -- just a file on the disk with code that is potentially is potentially runnable. runnable. A process is one instance of a program in execution; execution; at any instance, there may be many processes running copies of a single program e.g., an editor!" each is a separate, independent process.
Process A
=
Processor: %rovides a set o instructions along with the capability o automatically executing a series o those instructions&
=
Thread: A minimal sotware processor in whose context a series o instructions can be executed& Saving a thread context implies stopping the current execution execution and saving all the data needed to continue the execution at a later stage&
=
Process: A sotware processor in whose context one or more threads may be executed& 'xecuting a thread( means executing a series o instructions in the context o that thread&
Introduction to threads
Thread is a light weighted process& process&
The analogy: analogy: thread is to process process as process process is to machine&
'ach thread runs strictly se#uentially and has its own program counter and stac) to )eep trac) o where it is&
Threads share share the $%* +ust as processes processes do: ,rst one thread thread runs( then another does&
Threads can create create child threads and can bloc) waiting or system calls to complete&
All threads have exactly the same address space& They share code section( data section( and OS resources -open ,les . signals/&
They share the same global global variables& One thread can can read( write( or even completely wipe out another thread0s stac)&
Threads can be in any one o several states: running( b bloc)ed( loc)ed( ready( ready( or terminated&
There is no protection protection between threads: -1/ it is immpossible
-2/ it should not be necessary: a process is always owned by a single user( who has created multiple threads so that they can cooperate( not ,ght&
a) Thre Threee pro proce cess sses es wi with th one one tthr hrea ead d eeac ach. h. three threads
b) On Onee pro proce cess ss with with
Process Scheduling
3n a multiprogramming system( all the processes that run on a particular system see) or the $%* time&
4ence there is a need o $%* scheduling algorithm that reduces the ollowings as ar as possible&
Average Av erage waiting time tim e
Average Av erage response time and
Average Av erage turn around time
CPU/Process Scheduling The assignment of physical processors to processes allows processors to accomplish work. The problem of determining when processors should be assigned and to which processes is called processor scheduling or CPU scheduling. When more than one process is runable, the operating system must decide which one first. The part of the operating system concerned with this decision is called the scheduler, and algorithm it uses is called the scheduling algorithm.
is the component of the operating system that is responsile for deciding whether the currently running process should The process scheduler is continue running and, if not, which process should run ne%t. There are four events that may occur where the scheduler needs to step in and make this decision;
".
The current process goes from the running to to the waiting state state ecause it issues an 46& request or some operating system request that cannot e satisfied immediately.
$.
The current process terminates.
2.
A ttime imerr iinte nterru rrupt pt cau causes ses the schedu scheduler ler to run and decide decide tha thatt a proces process s has has run run for its all allott otted ed int interv erval al of time time and and it is tim time e tto o mo move ve it from the running to to the ready state. state.
>.
An 46 46& & ope opera rati tion on is co comp mple lete te fo forr a pro proce cess ss th that at re requ ques este ted d itit and and th the e pro proce cess ss now now mo moves ves ffro rom m tthe he waiting to to the ready state. state. The scheduler may then decide to preempt the currently-running process and move this newly-ready newly- ready process process into the running state. state.
Goals of Scheduling (objecties!
n this section we try to answer following !uestion" What the scheduler try to achie#e$ %any ob&ecti#es must be considered in the design of a scheduling discipline. n particular, particula r, a schedule schedulerr should cconsider onsider fai fairness, rness, effi efficiency ciency,, resp response onse time time,, turnaround time, throughput, etc., 'ome of these goals depends on the system one is using for e(ample batch system, interacti#e system or realtime system, etc. but there are also some goals that are desirable in all systems. General Goals
Fairness *airness is important under all circumstances. + scheduler makes sure that each process gets its fair share of the CPU and no process can suffer indefinite postponement. postponem ent. ote that gi gi#ing #ing e!u e!ui#alent i#alent o orr e!ual ttime ime is not fair. Think o off safety control and payro and payroll ll at at a nuclear plant. Enforcement Policy Enforcement The scheduler has to make sure that system-s policy is enforced. *or e(ample, if the local policy is safety then the safety the safety contro controll pro processes cesses must must be able to run whene#er they want to, e#en if it means delay in payro in payroll ll pro processes cesses.. Efficiency 'cheduler should keep the system or in particular CPU) busy cent percent of the time when possible. f the CPU and all the nput/Output de#ices can be kept running all the time, more work gets done per second than if some components are
idle.
Response Time Time + scheduler should minimi0e the response time for interacti#e user. Turnaround + scheduler should minimi0e the time batch users must wait for an output. Throughput + scheduler should ma(imi0e the number of &obs processed per unit time.
+ little thought will show that some of these goals are contradictory. t can be shown that any scheduling algorithm that fa#ors some class of &obs hurts another class of &obs. The amount of CPU time a#ailable is finite, after all. Preemptie "s #onpreemptie #onpreemptie Scheduling
The 'cheduling algorithms can be di#ided into two categories with respect to how they deal with clock interrupts. Nonpreemptive Nonpreemptive Scheduling
+ scheduling discipline is nonpreempti#e if, once a process has been gi#en the CPU, the CPU cannot be taken away from that process. *ollowing are some characteristics of nonpreempti#e scheduling
1& 3n nonpree nonpreemptive mptive s system( ystem( sho short rt +obs a are re mad made e to wait by longer +obs but the overall treatment o all processes is air& 2& 3n nonpree nonpreemptive mptive s system( ystem( rresponse esponse times times are more predictable because incoming high priority +obs can not displace waiting +obs& 5& 3n nonpreem nonpreemptive ptive scheduling( scheduling( a sc schedular hedular ex executes ecutes +obs iin n the ollowing two situations& a& When a process process sw switch itches es rom run running ning sta state te to the waiting state& b& When a pr proces ocess s ter termina minates& tes& Preemptive Scheduling Preemptive
+ scheduling discipline is preempti#e if, once a process has been gi#en the CPU can taken away.
The strategy of allowing processes that are logically runable to be temporarily suspended is called Preempti#e 'cheduling and it is contrast to the 1run to completion1 method.
Inter process Communication
Process of communication between two processes that reside in same or different systems.
2.g. communication of client and ser#er ◦
3ere a process of client communicates with another process of ser#er for a specific purpose.
IPC - Cooperating Processes
Independent process process cannot affect or be affected by the e(ecution of another process.
Cooperating process process can affect or be affected by the e(ecution of another process
+d#antages of process cooperation Communication)
◦
nformation sharing
◦
Computation speedup
◦
%odularity
◦
Con#enience
4angers of process cooperation Communication) ◦
4ata corruption, deadlocks, increased comple(ity
◦
5e!uires processes to synchroni0e their processing
Purposes for IPC
4ata Transfer
'haring 4ata
2#ent notification
5esource 'haring and 'ynchroni0ation
Process Control
Mechanisms used for communication and synchronization synchronization
the different ways of communication between the processes.
essage Passing
'hared %emory
5PC
Remote Procedure Call !RPC"
5PC is an interaction between a client and a ser#er
Client in#okes procedure on se#er
'er#er e(ecutes the procedure and pass the result back to client
Calling process is suspended blocked) and proceeds only after getting the result from ser#er
RPC # otivation
Transport layer message passing consists of two types of primiti#es" send and recei#e ◦
%ay be implemented in the O' or through addon libraries
%essages are composed in user space and sent #ia a send) primiti#e.
When processes are e(pecting a message they e(ecute a recei#e) primiti#e. ◦
4ifferences in data representation, need to understand messagepassing process, etc.
Programming is simplified if processes can e(change information using techni!ues that are similar to those used in a shared memory en#ironment.
The Remote Procedure Call !RPC" odel
+ highle#el network communication interface
6ased on the singleprocess procedure call model.
Client re$uest" formulated as a procedure call to a function on the ser#er.
Server%s reply" formulated as function return
Conventional Procedure Calls
7. nitiated nitiated when when a process process calls calls a function function or or procedur proceduree 8. The caller caller is 9suspended: 9suspended: until the called called functio function n completes. completes. ;. +rguments +rguments < return return address address are are pushed pushed onto onto the process process stack. =. >ariables local local to the called called function function are pushed pushed on the stack stack ?. Contro Controll passes passes to the the ccall alled ed funct function ion @. The called called function function e(ecutes, e(ecutes, returns returns #alues) #alues) either either through through parameters parameters or in registers. A. The The stac stack k iiss popp popped ed.. B. Callin Calling g fu funct nction ion resumes resumes e(ecut e(ecuting ing
6igure: %rinciple of 7%$ between a client and server program& program&
RPC and Client-Server Client-Server
5PC forms the basis of most clientser#er systems.
Clients formulate re!uests to ser#ers as procedure calls
Server%s reply" formulated as function return
Pro&lem 'ith Conventional RPC
+ccess Transparency in not maintained odern RPC
odern RPC
7. The client client procedu procedure re calls the client client stub stub in the normal normal way way. 8. The client client stub builds builds a message message includin including g parameters, parameters, name name or number number of procedu procedure re to be called etc and calls the local operating system. The packaging of arguments into a network message is called marshaling . ;. The client-s client-s as sends the message message to the remote remote O' #ia a system system call to the local local kernel. To transfer the message some protocol either connectionless or connection oriented) are used. =. The remot remotee O' gi#es gi#es the the message message to the the ser#er ser#er stub. stub. ?. The ser#er ser#er stub stub unpack unpackss the parameters parameters and and calls calls the ser#er ser#er.. @. The ser#er ser#er does does the the work and return returnss the result result to to the stub. A. The ser#er ser#er stub stub packs packs it it in a message message and calls its its local local O'. B. The ser#e ser#er-s r-s O' send sendss the messag messagee to the clien client-s t-s O'. O'. . The clien client-s t-s O' gi#e gi#ess the messag messagee to the clien clientt stub. stub.
7D. The stub unpacks the result and returns to the waiting client procedure.
RPC Issues( )inding
+ local kernel calls remote kernel in 5PC along with some parameters through a particular port.
The local kernel must know the remoteEs port through which it is communicating with.
The process of finding out or assigning the port and corresponding system client or ser#er) is called binding.
)inding
4etermines remote procedure and machine on which it will be e(ecuted Checks compatibility of the parameters passed 4ynamic 6inding Use 6inding 'er#er
"irtual machine 4n computing, a virtual machine ( emulation of of a particular computer system. s ystem. 9irtual machines machine (#$ #$)) is an emulation operate ased on thecomputer thecomputer architecture and architecture and functions of a real rea l or hypothetical computer, and their implementations may involve speciali5ed hardware hardware,, software software,, or a comination of oth. ?lassification of virtual machines can e ased on the degree to which they implement functionality of targeted real machines. That way, system virtual machines (also machines (also known as full virtuali5ation virtuali5ation 90s) provide a complete sustitute for the targeted real machine and a level of functionality required for the e%ecution of a complete operating system. complete system. &n the other hand, process hand, process virtual machines are machines are designed to e%ecute a single computer program y single program y providing an astracted and platform-independent platfor m-independent program e%ecution environment. +ifferent virtuali5ation techniques are used, ased on the desired usage. Native execution is execution is ased on direct virtuali5ation of the underlying raw hardware, thus it provides multiple @instances@ of the same architecture architecture a a real machine is ased on, on , capale of running complete operating systems. s ystems. 'ome virtual machines can also also emulate emulate different different architectures and allow e%ecution of software applications and operating systems written for another ?37 ?37 or or architecture. Operating system–level virtualization virtualization allows resources of a computer to e partitioned via kernel kernels support for multiple isolated isolated user space instances, space instances, which are usually calledcontainers called containers and and may look and feel like real machines from the end users point of view.
'ome computer architectures are capale of hardware-assisted virtuali5ation, virtuali5ation, which enales efficient full virtuali5ation y using virtuali5ation-specific hardware capailities, primarily from f rom the host ?37s.
edit## Definitions!edit A virtual machine (90) (90) is a software implementation of a machine machine (for e%ample, a computer) that e%ecutes programs like a physical machine. 9irtual machines are separated into two maBor classes, ased on their use and degree of correspondence to any real machine;
•
A system virtual machine provides machine provides a complete complete system platform platform which supports the e%ecution of a !"#
complete operating system (&') system (&').. These usually emulate an e%isting architecture, and are uilt with the purpose of either providing a platform to run programs where the real hardware is not availale availal e for use (for e%ample, e%ecuting on otherwise osolete platforms), or of having multiple instances of virtual machines leading to more efficient use of computing resources, oth in terms of energy consumption and cost effectiveness (known as hardware virtuali5ation, as virtuali5ation, the key to a a cloud computing computing environment), or oth.
•
A process A process virtual machine (also, machine (also, language virtual machine) is designed to run a single single program program,, which means that it supports a single process process.. 'uch virtual machines are usually closely suited to one or more programming languages and uilt with the purpose of providing program portaility and fle%iility (amongst other things). An essential characteristic of a virtual machine is that the software running inside is limited limit ed to the resources and astractions provided y the virtual machineit cannot reak out of its virtual environment.
A 90 was originally originally defined y y 3opek and :olderg :olderg as @an efficient, isolated duplicate of a real machine@. ?urrent use includes virtual machines which have no direct correspondence to any real hardware. !$#
System virtual machines!edit edit## See also: Hardware virtualization virtualization and Comparison of platform virtual machines 'ystem virtual machine advantages;
•
0ultiple &' environments can co-e%ist on the same primary hard drive, with a virtual partition that allows sharing of files generated in either the @host@ operating system or @guest@ virtual environment. AdBunct software installations, wireless connectivity, and remote replication, such as printing and fa%ing, can e generated in any of the guest or host operating systems. Cegardless of the system, all files are stored on the hard drive of the host &'.
•
Application provisioning, maintenance, high availaility and disaster recovery are are inherent in the virtual machine software selected.
•
?an provide provide emulated emulated hardware hardware environments different from the hosts hosts instruction set architecture set architecture (4'A), through emulation or y using using Bust-in-time Bust-in-time compilation. compilation.
The main disadvantages of 90s are;
•
•
A virtual machine is less efficient efficient than an actual machine when it accesses the host hard hard drive indirectly. 1hen multiple 90s are concurrently running on the hard drive of the actual host, adBunct virtual machines may e%hiit a varying and6or unstale performance (speed of e%ecution and malware protection). This depends on the data load imposed on the system y other 90s, unless the selected 90 software provides provides temporal isolation among virtual machines. machines.
•
0alware protection for 90s are not necessarily compatile with the @host@, and may require separate software.
0ultiple 90s running their own guest operating system are frequently engaged for server consolidation in order to avoid interference from separate 90s on the same s ame actual machine platform. The desire to run multiple operating systems was the initial motivation for virtual machines, so as to allow time-sharing among several single-tasking operating systems. 4n some respects, a system virtual machine can e considered a generali5ation of the concept of virtual memory memory that historically preceded it. 4*0s 4*0s ?36?0' ?36?0',, the first systems to allow full virtuali5ation,, implemented time sharing virtuali5ation sharing y providing each user with a single-user operating system, the the ?0' ?0'.. 7nlike virtual memory, a system virtual machine entitled the user to write privileged instructions in their code. This approach had certain advantages, such as adding input6output devices not allowed y the standard system. !2# As technology evolves virtual memory for purposes purposes of virtuali5ation, new systems of memory overcommitment may overcommitment may e applied to manage memory sharing among multiple virtual machines on one actual computer operating system. 4t may e possile to share @memory pages@ that have identical contents among multiple 90s that run on the same actual machine. This may result in mapping them to the same physical page, y a technique known k nown as as 8ernel 'ame3age 0erging.. This is particularly useful for read-only pages, such as those that contain code segments. 4n particular would 0erging e the case of multiple virtual machines running the same or similar software, software liraries, we servers, middleware components, etc. The guest operating systems do not need to e compliant with the host hardware, therey making it possile to run different operating systems on the same computer (e.g., 0icrosoft 1indows, 1indows, inu% inu%,, or previous versions of an operating system s ystem to support future software. The use of virtual machines to support separate guest operating systems is popular in regard to emedded systems. systems. A typical use would e to support an actual-time operating system system simultaneously with a preferred comple% operating system, such as inu% or 1indows. Another use would e for novel and unproven software still in the developmental stage, such as as sando% sando%.. 9irtual machines have other advantages for operating system development, and may include improved deugging access and faster reoots.!>#
%rocess virtual machines!edit# See also: Application also: Application virtualization !un"time system system and Comparison of application virtual machines A process 90, sometimes sometimes called an application virtual machine, machine, or #anaged !untime $nvironment (0C), (0C), runs as a normal application inside a host &' and supports a single process. 4t is created when that process is started and destroyed when it e%its. 4ts purpose is to provide a platform platform-independent -independent programming environment that astracts away details of the underlying hardware or operating system, and allows a program to e%ecute in the same way on any platform. A process 90 provides provides a high-level astraction D that of a a high-level programming language language (compared to the low-level 4'A astraction of the system 90). 3rocess 90s are implemented using an an interpreter E performance comparale to compiled programming languages is achieved y the use of Bust-in-time Bust-in-time compilation. compilation. This type of 90 has ecome popular with the the ava programming language, language, which is implemented using the the ava virtual machine.. &ther e%amples include the 3arrot virtual machine, machine machine , and the ./T Framework, Framework, which runs on a 90 called the ?ommon anguage Cuntime. the Cuntime. All of them can serve as an astraction layer for any computer language. A special case of process 90s 90s are systems that astract over the communication communication mechanisms of a (potentially heterogeneous) computer cluster . 'uch a 90 does not consist of a single process, ut one process per physical machine in the cluster. They are designed to ease the task of programming concurrent applications y letting the programmer focus on algorithms rather than the communication mechanisms provided y the interconnect and the &'. They do not hide the fact that communication takes place, and as such do not attempt to present the cluster as a single machine.!citation needed #
7nlike other process 90s, these systems do not provide a specific programming language, ut are emedded in an e%isting languageE typically such a system provides indings for several s everal languages (e.g., ? and F&CTCA/ F&CTCA/). ).!citation %amples are 390 (3arallel (3arallel 9irtual 0achine) 0achine ) and 034 (0essage (0essage 3assing 4nterface ). They are not strictly virtual
needed #
machines, as the applications running on top still have access to all &' services, and are therefore not confined to the system model.
$emory management 4n operating systems, 4n systems, memory management is management is the function responsile for managing the computers primary memory. memory. !"#;;pp-"GHD$GI !"#
The memory management function keeps track of the status of each memory location, either allocated or or free free.. 4t determines how memory is allocated among am ong competing processes, deciding who gets memory, when when they receive it, and how much they are allowed. 1hen memory is allocated it determines which memory locations will e assigned. 4t tracks when memory is freed or unallocated and and updates the status. &ontents !hide hide## " 0emory
•
management techniques
o
"." 'ingle
o
".$ 3artitioned allocation
o
".2 3aged
o
".> 'egmented
•
$
'ee also
•
2
Ceferences
contiguous allocation
memory management memory management
Memory management techniques!edit edit##
Single contiguous allocation !edit edit## Single allocation is allocation is the simplest memory management technique. All the computers memory, usually with the e%ception of a small portion reserved for the operating system, is availale to the single application. applicati on. 0'-+&' 0'-+&' is an e%ample of a system which allocates memory in this way. An An emedded system running system running a single application might also use this technique. A system using single contiguous allocation may still still multitask multitask y y swapping swapping the the contents of memory to switch among users. arly versions of the 0usic 0usic operating operating system used this technique.
edit## %artitioned allocation!edit %artitioned allocation divides allocation divides primary memory into multiple memory partitions, partitions, usually contiguous areas of memory. ach partition might contain all the information for a specific Bo Bo or task task.. 0emory management consists of allocating a partition to a Bo when it starts and unallocating it when the Bo ends. 3artitioned allocation usually requires some hardware support to prevent the Bos from interfering with one another or with the operating system. The 4*0 'ystem62JG 'ystem62JG used aloc&"and"&ey aloc&"and"&ey technique. &ther systems used used 'ase and 'ounds registers 'ounds registers which contained the limits of the partition and flagged invalid accesses. The 7/49A? ""GI ""GI Storage (imits !egister had had separate ase6ound sets for instructions and data. The system took advantage of memory !$#;;2-2 interleaving to place what were called the i 'an& and interleaving and d 'an& in in separate memory modules. !$#
3artitions may e either static , that is defined at 4nitial 3rogram oad (43) oad (43) or 'oot time or time or y the computer operator , or dynamic , that is automatically created for a specific Bo.4*0 Bo. 4*0 'ystem62JG &perating 'ystem 'ystem #ultiprogramming with a )ixed Num'er of *as&s (0FT) *as&s (0FT) is an e%ample of static partitioning, and #ultiprogramming with a +aria'le Num'er of *as&s (09T) *as&s (09T) is an e%ample of dynamic. 09T and successors use the term region region to to distinguish dynamic partitions from !2#;;K2 static ones in other systems. systems.!2#
3artitions may e relocata'le relocata'le using using hardware typed memory , like the the *urroughs ?orporation *HHGG, *HHGG, or ase and ounds registers like the the 3+3-"G 3+3-"G or :-J2H :-J2H.. Celocatale partitions are ale to e compacted to to provide larger chunks of contiguous physical memory. ?ompaction moves @in-use@ areas of memory to eliminate @holes@ or unused areas of !>#;;L> memory caused y process termination in i n order to create larger contiguous free f ree areas. areas. !>#
'ome systems allow partitions to e swapped out to to secondary storage to storage to free additional memory. arly arly versions of 4*0s *ime Sharing Option 4*0s Option (T'&) swapped users in and out of a single single time-sharing time-sharing partition. partition.!H#
%aged memory management!edit edit## #ain article: article: +irtual memory %aged allocation divides allocation divides the computers primary memory into fi%ed-si5e units called page called page frames, frames, and the programs virtual address space space into into pages pages of of the same si5e. The hardware hardware memory management unit maps unit maps pages to frames. f rames. The physical memory can e allocated on a page asis while the t he address space appears contiguous. 7sually, with paged memory management, each Bo runs in its own address space. Mowever, there are some some single address space operating systems systems that run all processes within a single address space, such as as 4*0 i, i, which runs all processes within a large address space, and 4*0 4*0 &'69'$ '9', '9', which ran all Bos in a single "J0i* virtual address space. 3aged memory can e demand"paged when when the system can move pages as required etween primary and secondary memory.
Segmented memory management !edit edit## #ain article: article: #emory segmentation Segmented memory is is the only memory management technique that does not provide the users program with a linear !"#;;p."JH and contiguous address space.@!"# Segments Segments are are areas of memory that usually correspond to a logical grouping of
information such as a code procedure or a data array. 'egments require hardware support in the form of a segment ta'le which ta'le which usually contains the physical address of the segment in memory, its si5e, and other data such as access protection its and status (swapped in, swapped out, etc.)
'egmentation allows etter access protection than other schemes ecause memory references are relative to a specific segment and the hardware will not permit the application to reference memory not defined for that segment. 4t is possile to implement segmentation with or without paging. 1ithout paging support the segment is the physical unit swapped in and out of memory if required. 1ith paging support the pages are usually the unit of swapping and segmentation only adds an additional level of security. Addresses in a segmented system usually consist of the segment id and and an offset relative to the segment segment ase address, defined to e offset 5ero. The 4ntel 4ntel 4A-2$ 4A-2$ (%IJ) architecture allows a process to have up to "J,2I2 segments of up to >:i* each. 4A-2$ segments are sudivisions of the computers linear address space, space, the virtual address space provided y the paging hardware. !J# The 0ultics 0ultics operating system is proaly the est known system implementing segmented memory. 0ultics 0ultics segments are sudivisions of the computers physical computers physical memory of of up to $HJ pages, each page eing "8 2J-it words in si5e, resulting in a ma%imum segment si5e of "0i* (with L-it ytes, as used in 0ultics). A process could have up to >G>J segments.
$emory management (#e%t! Me mo mo r yma n ag e m me e n ti st h ef u n c t i o n al i t yo fa nop e r a t i n gs y s t e m wh i c hh a nd l e so rma n ag e sp r i ma r yme m mo o r y .Me m mo o r yma n ag e me me n tk e e p st r a c k o fe ac han de v er ym me e mo mo r yl o c at i o ne i t h eri ti sa l l o cat e dt os omepr o ce sso ri ti sf r e e.I tc he ck sho w mu chm me e mo mo r yi st obeal l o ca t e dt opr o ce ss es . I td ec i d eswh i c hp r o c e s swi l l g etme mo mo r ya twh att i me .I tt r a c k swh en e v ers o m me eme m mo o r yg et sf r e edo ru n al l o c at e da ndc o r r e s po nd i n gl yi tu pd at e s t hes t at us .
Me mo mor yma ma na ge me me ntp r o v i d espr o t e ct i o nb yu s i n gt wor e g i s t e r s ,aba ser e g i s t era ndal i mi tr e gi s t e r .Th eb as er e gi s t e rh ol d st h es ma ma l l e s tl e ga l p hy s i c al me mo mo r yad dr e ssan dt h el i mi tr e gi s t e rs p ec i fi est h es i z eo ft h er a ng e.Fo re x amp l e ,i ft h eb as er e gi s t e rh ol d s3 00 00 0a ndt h el i mi tr e gi s t e r i s1 20 90 00 ,t h ent h epr o gr a mc a nl e ga l l ya c c es sa l la dd r e s s esf r o m3 00 00 0t h r o u g h4 11 99 9.
I n s t r u c t i o nsa ndda t at ome me m mo o r ya d dr e s s esc a nb ed on ei nf o l l o wi n gwa y s
Comp mpi l et i me -Wh eni ti sk no wnatc omp i l et i mewh er et h ep r o c es swi l l r e si d e,c omp i l et i mebi n di n gi sus edt oge ner a t et h ea bs ol u t e
•
code.
Loadt i me -Wh eni ti sno tk no wnatc omp i l et i mewh er et h ep r o c es swi l lr e si d ei nm me e m mo o r y ,t h ent h ec omp i l e rg en er a t e sr e l o ca t a bl e
•
code.
•
Execut i on t i me -I ft h ep r o c e s sc a nb emo v e dd u r i n gi t sex e c u t i o nf r o mo n e me m mo o r ys e g me me n tt oa n ot h er ,t h e nb i n d i n gmu s tb e d el a y e dt obedo neatr u nt i me
Dynami mi cLoadi ng I nd yn ami cl o ad i n g,ar ou t i n eofapr o gr am i sno tl o ad edun t i l i ti sc al l e db yt hepr og r a m m. .Al lr ou t i n esar ek eptondi s ki nar e l o ca t a bl el o adf o r ma t . Th ema i npr o g r a mi sl o a de di n t ome me mo mo r ya ndi se x e c u t e d.Ot h err o ut i n e sme t h o dso rmo d ul e sar el o a de do nr e q ue s t .Dy n a mi mi cl o a di n gma k e s b et t e rme mo mo r ys p ac eut i l i z at i o na ndun us edr o ut i n esa r en e v erl o ad ed .
Dy nami cLi nk i ng L i n k i n gi st h ep r o c e s sofc o l l e c t i n ga ndc o m mb b i n i n gv a r i o usmo mo du l e so fc o d ea ndd at ai n t oaex e c ut a bl efil et h atc a nb el o ad edi n t ome m mo o r ya nd e x ec ut e d.Op er a t i n gs y s t e mc anl i n ks y s t e ml e v ell i b r a r i e st oap r o gr a m. m.Wh Wh eni tc o m mb b i n est h el i b r a r i e sa tl o adt i me ,t h el i n ki n gi sc al l e ds t a t i c l i nk i n ga ndwhe nt h i sl i n ki ngi sdo nea tt het i meofe x ec ut i o n,i ti sc al l eda sd yn ami cl i nk i n g.
I ns t at i cl i n k i n g,l i b r a r i e sl i n k eda tc omp i l et i me ,s op r o gr a mc od es i z eb ec ome sb i g ge rwh er e asi nd yn ami cl i n ki n gl i b r a r i e sl i n k eda te x ec ut i o n t i mes op r o g r a mc o des i z er e ma i n ss m ma a l l e r .
Logi c al v er s usPhy s i c al Addr es sSpac e Anad dr e s sg en er a t e db yt h eCPUi sal o gi c a la dd r e s swh er e asad dr e s sa c t u al l ya v ai l a bl eonm me e m mo o r yu ni ti sap h y si c a la dd r e s s.L og i c a la dd r e s s i sa l s okn ownaVi r t u al a dd r e s s .
Vi r t u ala ndp hy s i c a la d d r e s s e sa r et h es a m me ei nc o m mp p i l e t i mea ndl o ad t i mea dd r e s s b i n di n gs c h eme s .Vi r t u ala ndp hy s i c a la d d r e s s e sd i ff eri n e x e c ut i o nt i mea dd r e s s b i n di n gs c h eme .
Th es eto fa l ll o gi c ala dd r e s s esge ne r a t e db yap r o gr am i sr e f e r r e dt oasal o gi c a la dd r e s ssp ac e.Th es e to fa l lp hy s i c a la dd r e s s esc or r e sp on di n g t ot h es el o gi c al a dd r e s s esi sr e f e r r e dt oa sap hy s i c al a dd r e s ss pa ce .
Th er u n t i mema ma p pi n gf r o mv i r t u a lt oph y s i c a la d dr e s si sd on ebyt h eme mo mo r yma ma n ag e me me n tu n i t( MMU)wh i c hi saha r d wa r ede v i c e .MMU u s e s f o l l o wi n gme ch an i s mt oc on v er t v i r t u al a dd r e s st op hy s i c a la dd r e s s .
•
Th ev a l u ei nt h eb as er e gi s t e ri sad de dt oev e r ya dd r e s sge ne r a t e db yaus erp r o c es swh i c hi st r e at e da so ffs eta tt h et i mei ti ss en tt o me mo mor y .Fo re x amp l e ,i ft h eb as er e gi s t e rv a l u ei s1 00 00 ,t h ena na t t e mp mp tb yt h eu se rt ous ea dd r e s sl o ca t i o n1 00wi l l b ed yn ami c a l l yr e al l o ca t e d t ol o ca t i o n1 01 00 .
•
Th eu se rp r o gr a md ea l swi t hvi r t u al a dd r e s s es ;i tn ev ers e est h er e al p hy s i c al a dd r e s s es .
Swappi ng Swa p pi n gi same c h an i s mi nwh i c hap r o c e s sc a nb es wa p pe dt e mp mp o r a r i l yo uto fma i nm me e m mo o r yt oab a c k i n gs t o r e,a n dt h e nb r o u gh tb a c ki n t o me m mo o r yf o rc o n t i n ue de x e c ut i o n.
Ba c k i n gs t o r ei sau s ua l l yah ar dd i s kdr i v eora nyo t h ers e c on da r ys t o r a gewh i c hf a s ti na c c es san dl a r g ee no ug ht oac c o mm mmo da t ec o pi e so fa l l me m mo o r yi ma ge sf o ra l l u s er s .I tmu s tb ec a pa bl eofp r o v i d i n gd i r e c ta c c es st ot h es em me e m mo o r yi ma ge s .
Ma j o rt i mec o ns umi n gp ar to fs wa pp i n gi st r a ns f e rt i me .T o t a lt r a ns f ert i mei sdi r e ct l ypr o po r t i o na lt ot h ea mo mo un to fme mo mo r ys wa pp ed .L e tu s a s s umet h att h eu s erp r o c es si sofs i z e1 00 KBa ndt h eb ac k i n gs t o r ei sas t a nd ar dha r dd i s kwi t ht r a ns f e rr a t eo f1MBp ers e c on d.Th ea c t u al t r a ns f e ro ft h e1 00 Kp r o c es st oorf r o m me mo mo r ywi l l t a k e
100KB/1000KBpersecond
=1/ 10second
=10 0mi mi l l i s ec on ds
Memor yAl l oc at i on Ma i nme me m mo o r yu s u al l yh ast wopa r t i t i o ns
•
Low Memor y -Op er a t i n gs y s t e mr e si d esi nt h i sme mo mo r y .
•
Hi ghMe Mem mo or y -Us e rp r o c es s e st h enhe l di nh i g hm me e m mo o r y .
Op er a t i n gsy s t e mu s est h ef o l l o wi n gme me m mo o r ya l l o c at i o nm me e c ha ni s m m. .
S. N .
Memor yAl l oc at i on
Descr i pt i on
I nt h i st y peofal l oc at i on,r el oc at i onr eg i s t ers chemei sus edt o p r o t e c tu s e rp r o c es s e sf r o me ac ho t h er ,a ndf r o mc h an gi n g 1
Si ngl epa r t i t i onal l oca t i on
o pe r a t i n gs y s t e mc od ea ndd at a.Re l o ca t i o nr e gi s t erc on t a i n sv a l u e ofs ma ma l l e stph ys i c al a dd r e sswh er ea sl i mi tr eg i s t erc ont a i n sr an geof l o gi c al a dd r e s s es .Ea chl o gi c a la d dr e ssmu mu stb el e sst h ant h el i mi t r e gi s t e r .
I nt h i st y peo fa l l o ca t i o n,ma i nme mo mo r yi sdi v i d edi n t oan umb ero f 2
Mul t i pl epa r t i t i on a l l oc at i on
fi x ed s i z edp ar t i t i o nswh er ee ac hp ar t i t i o ns ho ul dc o nt a i no nl yon e pr o ce ss .Wh enap ar t i t i o ni sf r e e,ap r o c es si ss el e ct e df r o mt h e i n pu tq u eu ea ndi sl o ad edi n t ot h ef r e ep ar t i t i o n.Wh ent h ep r o c es s t e r m mi i n at e s,t hepar t i t i o nb ec ome sav ai l a bl ef oran ot h erpr oc es s .
Fr agment at i on Aspr o c e s s esa r el o a de da n dr e mo mo v e df r o m me mo mo r y ,t h ef r e e me mo mo r ys p a c ei sbr o k e ni n t ol i t t l ep i e c e s .I th a pp e nsaf t e rs o me me t i me st h at p r o c e s s esc a nn o tb eal l o c a t e dt ome mo mo r ybl o c k sc on s i d e r i n gt h e i rs ma ma l ls i z ea n dme m mo o r yb l o c k sr e m ma a i n sun u s ed .Th i spr o b l e mi sk no wna s F r a g me me nt a t i o n.
Fr a gme nt a t i o ni soft wot y pe s
S. N .
1
2
Fr agment at i on
Descr i pt i on
Ex t e r na l
T o t a lme m mo o r ys p ac ei sen ou ght os a t i s f yar e qu es to rt or e s i d eap r o c es s
f r a gme nt a t i on
i ni t ,buti ti snotc ont i guoussoi tc annotbeus ed.
I nt e r na lf r a g m me e nt a t i on
Me mo mo r yb l o c kas s i g ne dt opr o c es si sb i g ge r .So m me epo r t i o no fme m mo o r yi s l e f tu nu s edasi tc a nn otb eu s edb yan ot h erp r o c es s .
Ex t e r n a lf r a gme nt a t i o nc a nb er e du c edbyc o m mp p ac t i o no rs h u ffleme me m mo o r yc o n t e nt st opl a c ea l lf r e eme m mo o r yt o ge t h eri non el a r g eb l o c k .T oma ma k e c omp ac t i o nf e as i b l e ,r e l o ca t i o ns ho ul dbedy na mi mi c .
Pagi ng Ex t e r n a lf r a gme nt a t i o ni sav o i d edb yu s i n gp ag i n gt e c hn i q ue .P ag i n gi sat e c hn i q uei nwh i c hp h y si c a lme m mo o r yi sbr o k eni n t ob l o c k so ft h es a me me s i z ec a l l e dp ag es( s i z ei spo we ro f2 ,b et we en5 12by t e sa nd81 92by t e s ) . Wh enapr o c es si st obeex e c ut e d,i t ' sc or r e s po nd i n gp ag esar el o ad ed i n t oan ya v ai l a bl em me e mo mo r yf r a m me e s .
L o gi c a la d dr e s ss pa c eo fap r o c e s sc a nb en o nc o n t i g u ou sa n d ap r o c e s si sal l o c a t e dp h y s i c a lme m mo o r ywh e ne v e rt h ef r e eme m mo o r yf r a m me ei s a v ai l a bl e .Op er at i n gs y s t e mk e ep st r a cko fa l l f r e ef r a me me s.Op er a t i n gs y s t e mn ee dsnf r e ef r a m me e st or u nap r o gr am o fs i z enp ag es .
Ad dr e s sge ne r a t e db yCPUi sd i v i d edi n t o
Pagenumber( p) -p a gen u m mb b e ri sus e da sani n d exi n t oap a get a b l ewh i c hc on t a i n sba s ea d dr e s so fe a c hp a gei np h y s i c a l
•
memor y .
•
Pageoffset( d) -p a geoff s e ti sc o m mb b i n e dwi t hba s ea d dr e s st od e fi net h ep h y s i c a lme m mo o r yad d r e s s .
Fo l l o wi n gfi gu r es ho wt h ep ag i n gt a bl ear c h i t e ct u r e .
Segment at i on Se gme nt a t i o ni sat e c hn i q uet ob r e akme me m mo o r yi n t ol o gi c a lp i e c eswh er ee ac hp i e c er e pr e s en t sag r o upo fr e l a t e di n f o r ma t i o n.F ore x a mp mp l e, d at a s e g me me n t so rc o d es e g me me n tf o re a c hpr o c e s s ,d a t as eg me me n tf o ro p e r a t i n gs y s t e ma n ds oon .Se g me me n t a t i o nc a nb ei mp l e m me e nt e du s i n go rwi t h o ut u s i n gp ag i n g.
Un l i k epa gi ng ,s e gmen ta r eh av i n gv ar y i ngsi z esandt h usel i mi nat e si nt er na lf r ag m me en t a t i o n.Ex t e r n al f r agme nt at i onst i l l e xi s t sbutt ol e ss ere xt e nt .
Ad dr e s sge ne r a t e db yCPUi sd i v i d edi n t o
Segme mentnum mb ber( s) -s e g m me e n tn u m mb b e ri su s eda sani n d exi n t oas eg m me e n tt a b l ewh i c hc on t a i n sba s ea d dr e s sofe a c hs e g me me n ti n
•
p hy s i c a lme m mo o r ya n dal i mi to fs e gme nt .
Segmentoffset( o) -s e gme nto ffs e ti sfi r s tc h ec k e da ga i n s tl i mi ta ndt h eni sc omb i n edwi t hb as ea dd r e s st od efi n et h ep h y si c a l memo mor yaddr ess.
&eadloc' 4n an an operating system, a deadlock is a situation which occurs when a process process or thread thread enters enters a waiting waiting state state ecause a resource resourcerequested requested is eing held y another waiting process, which in turn is waiting for another resource. 4f a process is unale to change its state indefinitely ecause the resources requested y it are eing used us ed y another waiting process, then the system is said to e in a deadlock.
#CSS)*+ CO#&ITIO#S ),, oft hes ef ourmust happensi mul t aneous l yf oradeadl oc kt ooc c ur : &)&,OC-C.)*)CT*IS)TIO# $utual e%clusion On eo rmo r et h anoner e so ur c emu s tb eh el dbyapr o ce ssi nan ons har a bl e( e x c l u si v e ) mode. .old and ait Apr oc es shol dsar es our c ewhi l ewai t i ngf oranot herr es our c e. #o Preemption Th er ei sonl yv ol un t a r yr e l e as eo far e sou r c e-no bo dyel s ec anma k eap r o ce ssgi v eu pa r e s o u r c e . Circular ait Pr oc es sAwai t sf orPr oc es sBwai t sf orPr oc es sC. . . .wai t sf orPr oc es sA.
ev ent i on Pr Dono tal l o w oneoft hef ourc ondi t i onst ooc c ur . $utual e%clusion0 a)Aut omat i c al l yhol dsf orpr i nt er sandot hernons har abl es . b)Shar edent i t i es( r eadonl yfil es )don' tneedmut ual ex c l us i on( andar en’ ts us cept i bl et o deadl oc k . ) c )Pr ev ent i onnotpos si bl e,s i nc es omedev i c esar ei nt r i ns i c al l ynons har abl e.
.old and 1ait0 a)Col l ec tal l r es our c esbef or eex ec ut i on.
b )Apa r t i c ul a rr e so ur c ec ano nl yber eq ues t e dwhennoot h er sar ebe i n gh el d .As e qu en ce ofr es our c esi sal wa y sc ol l ec t edbegi nni ngwi t ht hes ameone. c )Ut i l i z at i oni sl ow,s t ar v at i onpos s i bl e.
#o preemption0 a)Rel eas ean yr es our c eal r eadybei nghel di ft hepr oc es scan' tgetanaddi t i onal r es our c e. b)Al l owpr eempt i on-i faneededr es our c ei shel db yano t herpr oc es s ,whi c hi sal s owai t i ng ons omer es our c e,s t eal i t .Ot her wi s ewai t .
Circular 1ait0 a )Nu mb mbe rr e so ur c esa ndonl yr eq ues ti nas c end i ngor d er . b)EACHoft hes epr e v ent i ont ec hni quesma ma ycaus eadec r eas ei nut i l i z at i onand/ or r es our c es .Fort hi sr eas on,pr ev ent i oni s n' tnec es sar i l yt hebes tt ec hni que. c )Pr ev ent i oni sgener al l yt heeas i es tt oi mpl ement .
Examples chicken or egg@ egg@ prolem. prolem.!># 4t can e also Any deadlock situation can e compared to the classic @@chicken considered a parado%ical @?atch-$$ @?atch-$$@@ situation.!H# A real world e%ample would e an illogical statute passed !"#!J# J# y the the 8ansas 8ansas legislature in the early $Gth century, centur y, which stated; !"#!
2
1hen two trains approach each other at a crossing, oth shall come to a full stop and neither shall start up again until the other has gone.
3
A simple computer-ased e%ample is as follows. follows. 'uppose a computer has three ?+ drives and three processes. ach of the three processes holds one of the drives. 4f each process now requests another drive, the three processes will e in a deadlock. ach process will e waiting for the @?+ drive released@ event, which can e only caused y one of the other waiting processes. Thus, it results in a circular chain. chain. 0oving onto the source code level, a deadlock can occur even in the case of a single thread and one resource (protected y a mute% mute%). ). Assume there is a function func,-. func,-. which which does some work on the resource, locking the mute% at the eginning and releasing it after its done. /e%t, someody creates a different function func/-. func/-. following following that pattern on the same resource (lock, do work, release) ut decides to include a call to func,-. func,-. to to delegate a part of the Bo. 1hat will happen is the mute% will e locked once when enteringfunc/-. enteringfunc/-. and and then again at the call to func,-. func,-.,, resulting in a deadlock if the mute% is not reentrant reentrant (i.e. (i.e. the plain @fast mute%@ variety). variet y).
Necessary conditions A deadlockers situation can arise if all of the followi following ng conditions hold simultaneously in a system; !"# ". $utual '(clusion" '(clusion" At least one resource must e held in a non-shareale mode. !"# &nly one process can use the resource at any given instant of time.
*ait or +esource )olding" A )olding" A process is currently holding at least one resource and $. )old and *ait or requesting additional resources which are eing held y other processes. 2. o o %reemption %reemption"" a resource can e released only voluntarily y the process holding it. >. &ircular *ait" *ait" A A process must e waiting waiting for a resource which is eing held y another process, which in turn is waiting for the first process to release the resource. 4n general, there is a a set set of of waiting processes, 3 N O3 ", 3$, ..., 3/P, such that 3" is waiting for a resource held y 3 $, 3$ is !"#!K# K# waiting for a resource held y 32 and so on until 3/is waiting for a resource held y y 3".!"#!
These four conditions are known as the &offman conditions from conditions from their first description in a "LK" article y dward :. ?offman, r. !K# 7nfulfillment of any of these conditions is enough to preclude a deadlock from occurring.
Avoiding database deadlocks An effective way to avoid dataase deadlocks is to follow this approach from the &racle ocking 'urvival :uide; Application developers can eliminate all risk of enqueue deadlocks y ensuring that transactions requiring multiple resources always lock them in the same order.!I# This single sentence needs much e%planation to understand the recommended solution. First it highlights the fact that processes must e inside a transaction for deadlocks to happen. /ote that some dataase systems can e configured to cascade deletes which creates an implicit transaction which then can cause deadlocks. Also some some +*0' +*0'vendors vendors offer row-level locking, a type of record locking which locking which greatly reduces the chance of deadlocks, as opposed to page level locking, which creates many times more locks. 'econd, y @multiple resources@ this means more than one row in one or more tales. An e%ample of locking in the same order would e to process all 4/'CT' first, all 73+AT' second, and all +T' last and within processing each of these handle all parent p arent tale changes efore children tale changesE and process tale changes in the same order such as alphaetically or ordered y an 4+ or account numer. Third, eliminating all risk of deadlocks is difficult to achieve as the +*0' +*0' has has automatic lock escalation features that raise row level locks into page locks which can e escalated to tale locks. Although the risk or chance of e%periencing a deadlock will not go to 5ero as deadlocks tend to happen more on large, high-volume, comple% systems, it can e greatly greatl y reduced and when required the software can e enhanced to retry transactions when a deadlock is detected. Fourth, deadlocks can result in data loss if the software is not developed to use transactions on every interaction with a +*0' +*0' and the data loss is difficult to locate and creates une%pected errors and prolems. +eadlocks are a challenging prolem to correct as they result in data loss, are difficult to isolate, create une%pected prolems, and are time consuming to fi%. 0odifying every section of software code in a large system that access the dataase to always lock resources in the same order when the order is inconsistent takes significant resources and testing to implement. implemen t. That and the use of the strong word @dead@ in front of whom0 # lock are some of the reasons why deadlocks have a @this is a ig prolem@ reputation. !according to whom0#
Deadlock handling!edit edit## 0ost current operating systems cannot prevent a deadlock from occurring. !"# 1hen a deadlock occurs, different operating systems respond to them in different non-standard manners. 0ost approaches work y preventing one of the four ?offman conditions from f rom occurring, especially the fourth one. !L# 0aBor approaches are as follows.
gnoring deadlock!edit# 4n this approach, it is assumed that a deadlock will never occur. This is also an application of the &strich !L#!"G# "G# algorithm..!L#! algorithm This approach was initially used y 04/4 04/4 and and 7/4 7/4..!K#This is used when the time intervals
etween occurrences of deadlocks are large and the data loss incurred each time is tolerale.
etection!edit edit## 7nder deadlock detection, deadlocks are allowed to occur. Then Then the state of the system is e%amined to detect that a deadlock has occurred and susequently it is corrected. An algorithm is employed that tracks resource allocation and process states, it rolls ro lls ack and restarts one or more of the processes in order to remove the detected deadlock. +etecting a deadlock that has already occurred is easily easil y possile since the resources that each process has locked and6or currently requested are known to the resource scheduler of the operating system.!"G# +eadlock detection techniques include, ut are not limited to, model chec&ing . This approach constructs a finite statestate-model on which it performs a progress analysis and finds all possile terminal sets in the model. These then each represent a deadlock. After a deadlock is detected, it can e corrected y using one of the following methods; ". %rocess /e /ermination" rmination" &ne &ne or more processes involved in the deadlock may e aorted. 1e can choose to aort all processes involved in the deadlock. This ensures that deadlock is resolved with certainty and speed. *ut the e%pense is high as partial computations will e lost. &r, we can choose to aort one process at a time until the deadlock is resolved. This approach has high overheads ecause after each aort an algorithm must determine whether the system is still in deadlock. 'everal factors must e considered while choosing a candidate for termination, such as priority and age of the process. $. +esource %reemption" Cesources %reemption" Cesources allocated to various processes may ma y e successively preempted and allocated to other processes until the deadlock is roken.
%revention# #ain article: 1eadloc& prevention algorithms +eadlock prevention works y preventing one of the four ?offman conditions from occurring. •
Cemoving the mutual e(clusion condition e(clusion condition means that no process will have e%clusive access to a resource. This proves impossile for resources that cannot e spooled spooled.. *ut even with spooled
resources, deadlock could still occur. Algorithms that avoid mutual e%clusion are called called non-locking synchroni5ation algorithms. synchroni5ation •
The hold and wait or wait or resource holding conditions holding conditions may e removed y requiring processes to request all the resources they will need efore starting up (or efore emarking upon upo n a particular set of operations). This advance knowledge is frequently difficult to satisfy and, in any case, is an inefficient use of resources. Another way is to require processes to request resources only when it has none. Thus, first they must release all their currently held resources efore requesting all the resources they will need from scratch. This too is often impractical. 4t is so ecause resources may ma y e allocated and remain unused for long periods. Also, a process requiring a popular resource may have to wait indefinitely, as such a resource may always e allocated to some process, resulting in in resource starvation.!"# (These algorithms, such as starvation. as seriali5ing tokens, tokens, are known as the all"or"none algorithms.) algorithms.)
•
The no no preemption preemption condition condition may also e difficult or impossile to avoid as a process has to e ale to have a resource for a certain amount of time, or the processing outcome may e inconsistent or thrashing thrashing may occur. Mowever, inaility to enforce preemption may interfere with a priority algorithm. algorithm. 3reemption of a @locked out@ resource generally implies a rollack rollack,, and is to e avoided, since it is very costly in overhead. Algorithms that allow preemption include lock-free and wait-free algorithms and algorithms and optimistic concurrency control. control.This condition may e removed as follows ; 4f a process holding some resources and requests for some another resource(s) which cannot e immediately allocated to it, then y releasing all the currently eing held resources of that process.
•
The final condition is the circular wait condition. wait condition. Approaches that avoid circular waits include disaling interrupts during critical sections and using a hierarchy to determine apartial a partial ordering ordering of resources. 4f no ovious hierarchy e%ists, even the memory address of resources has een used to determine ordering and resources are requested in the increasing order of the enumeration. !"# +iBkstras solution can solution can also e used.
Avoidance!edit edit## This section may contain content that is repetitive or redundant of te(t elsewhere in the article.. 3lease help article help improve it y it y merging similar te%t or removing repeated statements. -Septem'er /2,3.
+eadlock can e avoided if certain information aout processes are availale to the operating system efore allocation of resources, such as which resources a process will consume in its lifetime. For every resource request, the system sees whether granting gr anting the request will mean that the system will enter an unsafe unsafe state, state, meaning a state that could result in deadlock. The system then only grants requests that will lead to safe safe states states..!"# 4n order for the system to e ale to determine whether the ne%t state will e safe or unsafe, it must know in advance at any time; •
resources currently availale
•
resources currently allocated to each process
•
resources that will e required and released y these processes in the future
4t is possile for a process to e in an unsafe state ut for this not to result in a deadlock. The notion of safe6unsafe states only refers to the a'ility of of the system to enter a deadlock state or not. For e%ample, if a process requests A which which would result in an unsafe state, ut releases * which would prevent circular wait, then the state is unsafe ut the system is not in deadlock. &ne known algorithm that is used for deadlock avoidance is the the *ankers algorithm, algorithm, which requires resource usage limit to e known in advance.!"# Mowever, for many systems it is impossile to know in advance what every process will request. This means that deadlock avoidance is often impossile. Two other algorithms are 1ait6+ie and 1ound61ait, each of which uses a symmetry-reaking technique. 4n oth these algorithms there e%ists an older process (&) and a younger process (Q). 3rocess age can e determined y a timestamp at process creation time. 'maller timestamps are older processes, while larger timestamps represent younger processes.
*ait0ie
*ound0*ait
& needs a resource held y Q
& waits
Q dies
Q needs a resource held y &
Q dies
Q waits
Another way to avoid deadlock is to avoid locking, for e%ample y using /on-locking synchroni5ation or synchroni5ation or Cead-copy-update Cead-copy-update..
File systems and operating systems 0any 0any operating systems include systems include support for more than one file system. 'ometimes the &' and the file system are so tightly interwoven it is difficult to separate out file system functions. There needs to e an interface provided y the operating system software etween the user and the file system. This interface can e te%tual (such as provided y a command line interface, interface , such as the the 7ni% shell, shell, or &pen90' +?) or graphical (such as provided y a graphical user interface, interface , such as as file rowsers). 4f graphical, the metaphor of the folder , containing documents, other files, and nested folders is often used (see also; directory directory and folder).
1ni( and 1ni(-like operating systems !edit edit## 7ni%-like operating systems create a virtual file system, which makes all the files on all the devices appear to e%ist in a 7ni%-like single hierarchy. This means, in those systems, there is one root directory, directory, and every file e%isting on the system is located under it somewhere. 7ni%-like systems can use a CA0 disk or disk or network shared resource as its root directory. 7ni%-like systems assign a device name to each device, ut this is not how the files on that device are a re accessed. 4nstead, to gain access to files on another device, the operating system must first e informed where in the directory tree those files should appear. This process is called called mounting mounting a a file system. For e%ample, to access the files on a a ?+-
C&0 C&0,, one must tell the operating system @Take @Take the file system from this ?+-C&0 and make it i t appear under such-andsuch directory@. The directory given to the operating system is called the mount point D D it might, for e%ample, e /media. The /media directory e%ists on many 7ni% systems (as specified in the Filesystem Mierarchy 'tandard) 'tandard ) and is intended specifically for use as a mount m ount point for removale media such as ?+s, +9+s, 7'* drives or floppy disks. 4t may e empty, or it may contain sudirectories for mounting individual devices. :enerally, only the administrator (i.e. the (i.e. root user ) may authori5e the mounting of file systems. 7ni%-like operating systems often include software and tools that assist in the mounting process and provide it new 7ni%-like functionality. 'ome of these strategies have een coined @auto-mounting@ as a reflection of their purpose.
•
4n many situations, file systems other than the root need to e availale as soon as the operating system has ooted has ooted.. All 7ni%-like systems therefore provide a facility for mounting file systems at oot time. 'ystem administrators define these file systems in the configuration file fsta administrators fsta (vfsta' vfsta' in in 'olaris 'olaris)), which also indicates options and mount points.
•
4n some situations, there is no need to mount certain file systems at oot time, time, although their use may e desired thereafter. There There are some utilities for 7ni%-like systems that allow all ow the mounting of predefined file systems upon demand.
•
Cemovale media have ecome very common with with microcomputer platforms. They allow programs and data to e transferred etween machines without a physical physic al connection. ?ommon e%amples include 7'* flash drives, ?+-C&0s drives, ?+-C&0s,, and +9+s +9+s.. 7tilities have therefore een developed to detect the presence and availaility of a medium and then mount that medium without any user intervention.
•
3rogressive 7ni%-like systems have also introduced a concept called supermounting supermountingEE see, for e%ample, e%ample, the inu% supermount-ng proBect. proBect . For e%ample, a floppy disk that has een supermounted can e physically removed from the system. 7nder normal circumstances, the disk should have een synchroni5ed and then unmounted efore its removal. 3rovided synchroni5ation has occurred, a different disk can e inserted into the drive. The system automatically notices that the disk has changed and updates the mount point contents to reflect the new medium.
•
An automounter will automatically mount a file system when a reference is made to the directory atop which it it should e mounted. This is usually used for file systems on network servers, rather than relying on events such as the insertion of media, as would e appropriate for removale media.
Linux 4 4edit e dit 5 inu% supports many different file systems, ut common choices for the system disk on a lock device include the e%tR inu% family (such as e%t$ e%t$,, e%t2 e%t2 and and e%t> e%t>), ), F' F',, F' F',, CeiserF' CeiserF'and and trfs trfs.. For raw flash without a a flash translation layer (FT) (FT) or 0emory Technology +evice (0T+), +evice (0T+), there is is 7*4F' 7*4F',, FF'$ FF'$,, and and QAFF' QAFF',, among others. 'quashF' 'quashF' is a common compressed read-only file system. Solaris4 edit edit 5 The 'un 0icrosystems 0icrosystems 'olaris operating system in system in earlier releases defaulted to (non-Bournaled or non-logging) non-logging) 7F' 7F' for for ootale and supplementary file systems. 'olaris defaulted to, supported, and e%tended 7F'. 'upport for other file systems and significant enhancements were added over time, including 9eritas 'oftware ?orp. 'oftware ?orp. (ournaling) 9%F' (ournaling) 9%F',, 'un 0icrosystems (?lustering) F' F',, 'un 0icrosystems (ournaling) 7F', and 'un 0icrosystems (open source, poolale, "$I it compressile, and error-correcting) SF' SF'..
8ernel e%tensions were added to 'olaris to allow for ootale 9eritas 9eritas 9%F' 9%F' operation. operation. ogging or ournaling ournaling was was added to 7F' in 'uns 'uns 'olaris K. K. Celeases of 'olaris "G, "G, 'olaris %press, %press, &pen'olaris &pen'olaris,, and other open source variants of the 'olaris operating system later supported ootale ootale SF' SF'.. ogical 9olume 0anagement 0anagement allows for spanning a file system across multiple devices for the purpose of adding redundancy, capacity, capacity, and6or throughput. egacy environments in 'olaris may use use 'olaris 9olume 0anager (formerly (formerly known as as 'olstice +isk'uite) +isk'uite). 0ultiple operating systems (including 'olaris) may use use 9eritas 9olume 0anager . 0odern 'olaris ased operating systems eclipse ecli pse the need for 9olume 0anagement through leveraging virtual storage pools in SF' SF'.. OS X 44 edit edit 5 &' uses a file system inherited from classic 0ac &' &' called called MF' 3lus. 3lus. Apple also uses the term @0ac &' %tended@. MF' 3lus is a metadata metadata-rich -rich and and case-preserving case-preserving ut ut (usually) case-insensitive case-insensitive file system. +ue to the 7ni% roots of
!"H#!"J# !"H#! "J#
&' , 7ni% permissions were added to MF' 3lus. ater versions of MF' 3lus added added Bournaling to Bournaling to prevent corruption of the file system structure and introduced a numer of optimi5ations to the allocation algorithms in an attempt to defragment files automatically without requiring an e%ternal defragmenter. Filenames can e up to $HH characters. MF' 3lus uses uses 7nicode 7nicode to store filenames. &n &' , the the filetype filetype can come from the the type code, code, stored in files metadata, or the the filename e%tension. e%tension.
MF' 3lus has three kinds of links; 7ni%-style hard links, links, 7ni%-style symolic links links and and aliases aliases.. Aliases are designed to maintain a link to their original file even if they are moved or renamedE they are not interpreted y the file system itself, ut y the File 0anager code in in userland userland.. &' also supported the 7F' 7F' file file system, derived from the *'+ *'+ 7ni% Fast File 'ystem via /eT'T3 /eT'T3.. Mowever, as of 0ac &' eopard, eopard , &' could no longer e installed on a 7F' volume, v olume, nor can a pre-eopard system installed on a 7F' volume e upgraded to eopard. !"K# As As of 0ac &' ion ion 7F' support was completely dropped. /ewer versions of &' are capale of reading and writing to the legacy FA FAT T file systems ("J 2$) common on 1indows. They are also capale of reading the the newer /TF' /TF' file file systems for 1indows. 4n order to write write to to /TF' file systems on &' versions prior to "G.J ('now eopard) third party software is necessary. 0ac &' "G.J ('now eopard) and later allows writing to /TF' file systems, ut only after a non-trivial system setting change (third party software e%ists that automates this). this).!"I#
Finally, &' supports reading and writing of the e%FAT e%FAT file file system since 0ac &' 'now eopard, starting from version "G.J.H.!"L#
%&-2S!edit edit## 3?-*'+ is 3?-*'+ is a desktop version of Free*'+, which inherits Free*'+ Free*'+s SF' SF' support, support, similarly to Free/A' Free/A'.. The new graphical installer of 3?-*'+ 3?-*'+ can can handle 6 handle 6 - root root . on 7)S and CA4+-S pool installs and and disk encryption using encryption using :eli :eli right right 7)S andCA4+-S from the start in an easy convenient (:74 ( :74)) way. The current 3?-*'+ L.GU 4sotope dition has SF' filesystem version H and SF' storage pool version $I.
%lan 3!edit edit## 3lan L from *ell as treats as treats everything as as a file, and accessed as a file would e (i.e., no ioctl ioctl or or mmap mmap); ); networking, graphics, deugging, authentication, capailities, encryption, and other services are accessed via 4-& operations on on file descriptors.. The descriptors The L3 L3 protocol removes the difference etween local and remote files.
These file systems are organi5ed with the help of private, per-process namespaces, allowing each process to have a different view of the many file systems that provide resources in a distriuted system. The 4nferno operating system system shares these concepts with 3lan L.
$icrosoft *indows!edit edit##
+irectory listing in a a 1indows 1indows command command shell
1indows makes use of the FA FAT T, /TF' /TF',, e%FAT e%FAT and and CeF' CeF' file file systems (the last of these is only supported and usale in1indows in 1indows 'erver $G"$E $G"$ E 1indows cannot oot from it).
1indows uses a a drive letter astraction astraction at the user level to distinguish one disk or partition from another. For e%ample, thepath the path C:\WINDOWS represents a directory WINDOWS on the partition represented y the letter ?. +rive ?; is most commonly used for the primary hard disk partition, on which 1indows is usually installed and from which it oots. This @tradition@ has ecome so firmly ingrained that ugs e%ist in many applications which make assumptions that the drive that the operating system is installed on is ?. The use of drive letters, and the tradition of using usi ng @?@ as the drive letter for the primary hard disk partition, can e traced to 0'-+&' 0'-+&',, where the letters A and * were reserved for up to two floppy disk drives. This in turn derived from ?360 ?360 in in the "LKGs, and ultimately from 4*0s ?36?0' ?36?0' of of "LJK. FA FAT T 4 4 edit edit 5 #ain article: article: )ile Allocation *a *a'le 'le The family of FA FAT T file systems is supported y almost all operating systems s ystems for personal computers, including all versions of 1indows 1indows and and 0'-+&' 0'-+&'663? +& +&' ' and +C-+&' +C-+&'.. (3? +&' is an &0 version of 0'-+&', 0'-+&' was originally ased on on '?3 '?3s IJ-+&' IJ-+&'.. +C-+&' was ased on +igital Cesearch Cesearchs ?oncurrent +&', +&', a successor of ?360IJ.) The FAT IJ. FAT file systems are therefore well-suited as a universal e%change format etween computers and devices of most any type and age. The FAT file system traces its roots ack to an (incompatile) I-it FAT precursor in 'tandalone +isk *A'4? *A'4? and the short-lived 0+&'604+A' short-lived 0+&'604+A' proBect.!citation needed # &ver the years, the file system has een e%panded from from FAT"$ FAT"$ to to FAT"J FAT"J and and FAT2$ FAT2$.. 9arious features have een added to the file system including sudirectories sudirectories,, codepage codepagesupport, support, e%tended attriutes, attriutes, and and long filenames. filenames. Third parties such as +igital Cesearch have incorporated optional support for deletion tracking, and volume6directory6fileased multi-user security schemes to support file and directory passwords and permissions such as read6write6e%ecute6delete access rights. 0ost of these e%tensions are not supported y 1indows. 1 indows. The FAT"$ FAT"$ and FAT"J FAT"J file systems had a limit on the numer of entries in the the root directory of directory of the file system and had restrictions on the ma%imum si5e of FA FATT-formatted formatted disks or partitions partitions..
FAT2$ T2$ addresses the limitations in FAT"$ FAT"$ and FAT"J, FAT"J, e%cept for the file si5e limit of close to > :*, ut it remains limited FA compared to /TF'. FAT"$, FA T"$, FAT"J FAT"J and FAT2$ FAT2$ also have a limit of eight characters for the file name, and three characters for the e%tension (such as as .e%e .e%e). ). This is commonly referred to as the I.2 filename filename limit. limit. 9FAT 9FAT,, an optional e%tension to FAT"$, FAT"J and FAT2$, introduced in in 1indows LH LH and 1indows /T 2.H, 2.H, allowed long file names (F/ ( F/)) to e stored in the FAT file system in a ackwards compatile fashion. NTFS 4 edit 5 4 edit #ain article: article: N*)S /TF',, introduced with the /TF' the 1indows /T operating /T operating system in "LL2, allowed A? allowed A?-ased -ased permission control. &ther features also supported y y /TF' /TF' include hard links, multiple file streams, attriute inde%ing, quota tracking, sparse files, encryption, compression, and reparse points (directories working as mount-points for other file systems, symlinks, s ymlinks, Bunctions, remote storage links). exFAT 44 edit dit e 5 #ain article: article: ex)A* e%FAT is e%FAT is a proprietary and patent-protected file system with certain advantages over /TF' with regard to file system overhead.. overhead e%FAT is not ackward compatile with FAT file systems such as FAT"$, FAT"J or FAT2$. The file system is supported with newer 1indows systems, such as 1indows 'erver $GG2, 1indows 9ista, 1indows $GGI, 1indows K, 1indows I, and more recently, support has een added for 1indows 3. 3.!$G# e%FAT e%FA T is supported in 0ac &' starting with version "G.J.H ('now eopard). !"L# 'upport in other operating systems is sparse since 0icrosoft has not pulished the specifications of the file system and implementing support for e%FAT requires a license.
The 3rospero File 'ystem is a file system ased on the 9irtual 'ystem 0odel. !$"# The system was created y +r. *. ?lifford /euman of the 4nformation 'ciences 4nstitute at the 7niversity of 'outhern ?alifornia. !$$#
•
C'C F file system system - written in A:& in A:& JI
•
The file system of the the 0ichigan Terminal 'ystem (0T') 'ystem (0T') is interesting ecause; (i) it provides @line files@ where record lengths and line numers are associated as metadata with each record in the file, lines can e added, replaced, updated with the same or different length records, and deleted anywhere in the file without the need to read and rewrite the entire fileE (ii) using program keys files may e shared or permitted to commands and programs in addition to users and groupsE and (iii) there is a comprehensive file locking mechanism that protects !$2#!$># $># oth the files data and its metadata. metadata. !$2#!