Levelling - Rise and fall - Height of instrument method
POS - File Systems & Deadlocks Prevention
1. POS - File System & Deadlocks
Presenter Rohit Jain
2. File System
• It is the way in which files are named and where they are placed logically for
storage and retrieval.
• A file system is used to control how information is stored and retrieved.
• Without file system, information placed in a storage area would be one large body
of information with no way to tell where one piece of information stops and the
next begins.
• A file system defines the structures and the rules used to read, write and maintain
information stored on a disk.
3. Aspects of File system
• Space management
• Filename
• Directories
• Metadata
• Restricting and permitting access
4. Space Management
• The File system is responsible for organizing files and directories and keeping
track of which areas of the media belongs to which file and which are not being
used.
• Slack Space
• File system fragmentation occurs when unused space or single files are not
contiguous. As file are deleted the space they were allocated eventually is
considered available for use by other files.This created alternating used and
unused areas of various sizes.
5. File Names
• A filename is used to identify a storage location In the file system. Most file
system have restrictions on the length of filenames. In some file system filenames
are case sensitive.
6. Directories
• File system typically have directories (folders) which allow user to group files into
separate collection.
• Directory structure may be linear or allow hierarchies where directory may contain
sub directory.
7. Metadata
• Meta Data is data about data and in filesystem it is associated as bookkeeping
information is typically associated with each file within a file system.The length of
the data contained in a file may be stored as the number of blocks allocated for
the file or as the byte count.
8. Restricting and Permitting access
• There are several mechanisms used by file system to control access to data.
Usually the intent is to prevent reading or modifying files by user or group of users.
Another reason is to ensure data is modified in a controlled way so access may be
restricted to a specific program.
• For Example Includes Password stored in the metadata of the file.
9. Types of File System
• Disk File system
• Flash File system
• Database file system
• Network file system
• Special file system
10. Disk file system
• A disk file system takes advantages of the ability of disk storage media to
randomly address data in a short amount of time.
• Additionally Consideration include the speed of accessing data following that
initially requested and the anticipation that the following data may be requested.
• For example ext3, NTFS, UDF etc.
11. Flash file system
• A flash file system considers the special abilities, performance restrictions of flash
memory devices.
• Frequently a disk file system can use a flash memory device as the underlying
storage media but it is much better to use a file system that is Specifically
designed for a flash device.
12. Database File system
• In this file are identified be their characteristics, like type, author or any other Rich
metadata instead of hierarchical structured management..
• IBM DB2 is a database file system.
13. Network File system
• A network file system is a file system that acts as a client for a remote file access
protocol, providing access to files on a server.
• For example AFS, FTP,WebDAV.
14. Shared Disk File system
• A shared disk file system is one in which a number of machine all have access to
the same external disk subsystem.
• The file system arbitrates access to that subsystem, Preventing write collisions.
• For example GFS 2 , GPFS etc.
15. Special File system
• A special File system presents non-file elements of an OS as files so they can be
acted on using system APIs.This is most commonly done in Unix Like Operating
System but devices are given file names in some non-unix-like Operating systems
as well.
17. File Operations
• Creata :- Find spaces on disk and make entyr in directory
• Write : wirte to file requires positioning with ithe file
• Read : read from file involves positioning within the file
• Delete :- Delete Directory enry, redaim disk space
• Reposition Move read / write position.
18. Files access Methods
• Sequential :- readNext, writenext, Reset
• Direct :- readRecord N,WirteRecord N PostoionAt N, reset
• Indexed :- readRecord Key,Write Record Key , PositionAt Key, reset
19. File AllocationTable
• Where the OS record s how the disk spece is used,
• Location of FAT near the beginning og the volume
• Locatoin of FAT is specified in the boot sector
20. FATTypes
• FAT12 :-The earliest version the file system, FAT12 allow a partition to containg up
to 4096MB/ (212) clusters
• FAT16 :- oldest, created for DOS, supported by most OS’s cannot be installed on
partitions laeger than 2 GB, or on hard dreives larger than 4 GB
• FAT32 :- Supports disk from 512MB to 2TB, compatible with windows98 upto
latest.
21. NTFS
• NewTechnology File System
• Better File Security ( Encryption File system)
• Disk Compressoin – can compress a file/ folder
• NTFS volmes can not be accessed by DOS
22. Operating System FAT16 FAT32 NTFS
Windows XP
Windows 2000
Windows NT
Windows 95, 98, ME
Windows 95
MS-DOS
24. Disk Scheduling
• The OS is responsible for using hardware efficiently for the disk drives
• Access time
Total access time = seek time + rotational delay + data transfer time
Seek time – time required to move the disk arm to the required track
Rotational delay – time required to rotate the disk to the required sector
Data transfer time – time to read/write data from/to the disk
• Disk bandwidth is the total number of bytes transferred, divided by the total time between the first request for
service and the completion of last transfer.
• OS maintains queue of request, per disk or device.
25. Disk SchedulingAlgorithms
SeveralAlgorithms exist to schedule the servicing of disk I/O requests.
• FCFS
• SSTF
• SCAN
• C-Scan
• Look
• C-Look
Queue = 98, 183, 37, 122, 14, 124, 65, 67
Head starts at 53
26. First Come First Serve
• Handle I/o request Sequentially
• Fair at all Processes
• Approaches reandom scheduling in performance scheduling in performance if
there are many processes/ request.
27. Shortest SeekTime First
• Selects the request with the minimum seek time from the current head position.
• SSSTF scheduling is a form of SJF scheduling may cause starvation of some
requests.
28. SCAN
• The disk arm starts at one end of the disk , and moves toward the other end,
servicing requests until it get to the other end of the disk, where the head
movement is reversed and servicing continues.
• It moves in both directions until both ends
• Tends to stay more at the ends so more fair to the extreme cylinder requests
29. C-SCAN
• The head moves from one end of the disk to the other, servicing requests
as it goes.When it reaches the other end, however, it immediately returns
to the beginning of the disk, without servicing any requests on the return
trip.
• Treats the cylinders as a circular list that wraps around from the last
cylinder to the first one.
• Provides a more uniform wait time than SCAN; it treats all cylinders in
the same manner.
30. C- Look
• Look version of C-Scan.
• Arm only goes as far as the last request in each direction, then reverses
direction immediately, without first going all the way to the end of the
disk.
• In general, Circular versions are more fair but pay with a larger total seek
time.
• Scan versions have a larger total seek time than the corresponding Look
versions.
31. Selecting a Disk SchedulingAlgorithm
• Performance depends on the number and types of requests.
• Requests for disk service can be influenced by the file-allocation method.
• The disk-scheduling algorithm should be written as a separate module
of the operating system, allowing it to be replaced with a different
algorithm if necessary.
• With low load on the disk, It’s FCFS anyway. SSTF is common and has a
natural appeal – good for medium disk load.
32. • SCAN and C-SCAN perform better for systems that place a heavy load
on the disk; Less starvation.
• Either SSTF or LOOK is a reasonable choice for the default algorithm.
33. Dead Lock
• Deadlock: processes waiting indefinitely
with no chance of making progress.
• Starvation: a process waits for a long time
to make progress.
34. Deadlocks
• Deadlock applications not just OS
– Network
• Two processes may be blocking a send message
to the other process if they are both waiting for a
message from the other process
» Receive/waiting blocks writing
– Databases.
– Spooling/streaming data.
35. Deadlock Characterization
• Mutual exclusion: Only one process at a time can use a resource.
• Hold and wait: A process holding at least one resource is waiting to
acquire additional resources held by other processes.
• No preemption: A resource can be released only voluntarily by the
process holding it, after that process has completed its task.
• Circular wait: there exists a set {P0, P1, …, P0} of waiting
processes such that P0 is waiting for a resource that is held by P1,
P1 is waiting for a resource that is held by
P2, …, Pn–1 is waiting for a resource that is held by
Pn, and P0 is waiting for a resource that is held by P0.
36. Resource-Allocation Graph
• V is partitioned into two types:
– P = {P1, P2, …, Pn}, the set consisting of all
the processes in the system.
– R = {R1, R2, …, Rm}, the set consisting of
all resource types in the system.
request edge – directed edge P1 Rj
assignment edge – directed edge Rj
Pi
•
•
A set of vertices V and a set of edges E.
40. Basic Facts
• If graph contains no cycles no deadlock.
• If graph contains a cycle
– if only one instance per resource type,
then deadlock.
– if several instances per resource type, possibility
of
deadlock.
41. Methods for Handling Deadlocks
• Ensure that the system will never enter
a deadlock state.
• Allow the system to enter a deadlock state
and
then recover.
• Ignore the problem and pretend that
deadlocks never occur in the system; used by
most operating systems, including UNIX.
42. Deadlock Prevention
• Mutual Exclusion – not required for sharable
resources; must hold for nonsharable
resources.
• Hold and Wait – must guarantee that whenever
a process requests a resource, it does not hold
any other resources.
– Require process to request and be allocated all its
resources before it begins execution, or allow process
to request resources only when the process has none.
– Low resource utilization; starvation possible.
43. Deadlock Prevention
• No Preemption –
– If a process that is holding some resources requests
another resource that cannot be immediately allocated to
it, then all resources currently being held are released.
– Preempted resources are added to the list of resources
for which the process is waiting.
– Process will be restarted only when it can regain its old
resources, as well as the new ones that it is requesting.
• Circular Wait – impose a total ordering of all
resource types, and require that each
process requests resources in an increasing
order of enumeration.
44. Deadlock Avoidance
• Simplest and most useful model requires that each process
declare the maximum number of resources of each type
that it may need.
• The deadlock-avoidance algorithm dynamically examines
the resource-allocation state to ensure that there can
never be a circular-wait condition.
• Resource-allocation state is defined by the number of
available and allocated resources, and the maximum
demands of the processes.
Requires that the system has some additional a priori
information available.
45. Banker’s Algorithm
Multiple instances
Each process must a priori claim of the maximum use.
When a process requests a resource it may have to wait.
When a process gets all its resources, it must return them in a
finite amount of time.
46. Data Structures for Banker’s Algorithm
n = number of processes, and m = number of resources types
Available: vector of length m.
• If Available[j ] = k, there are k instances of resource type Rj
available.
Max: n × m matrix.
• If Max[i , j ] = k, then process Pi may request at most k instances of
resource type Rj .
Allocation: n × m matrix.
• If Allocation[i , j ] = k then Pi is currently allocated k instances of
Rj .
Need: n × m matrix.
• If Need[i , j ] = k, then Pi may need k more instances of Rj to
complete its task Need[i , j ] = Max[i , j ] − Allocation[i , j ]
47. Resource-Request Algorithm for Process Pi
Requesti= request vector for process Pi . If Requesti [j ] = k, then
process Pi wants k instances of resource type Rj .
1. If Requesti ≤ Needi , go to step 2. Otherwise, raise error
condition, since process has exceeded its maximum claim.
2. If Requesti ≤ Available, go to step 3. Otherwise Pimust wait, since
resources are not available.
48. Resource-Request Algorithm for Process Pi
• If safe: the resources are allocated to Pi
• If unsafe: Pi must wait, and the old resource-allocation state is restored
3. Pretend to allocate requested resources to Pi
state as follows:
Available = Available − Requesti
Allocationi = Allocationi + Requesti Needi = Needi
− Requesti
49. Banker’s Algorithm Example
5 processes: P0 through P4
3 resource types:
• A (10 instances), B (5 instances), and C (7
instances)
Snapshot at time
T0
50. Banker’s Algorithm Example
(2/2)
The content of the matrix Need is defined to be Max −
Allocation
Is the system safe? (P1, P3, P4, P2, P0) satisfies safety
criteria.
52. Single Instance of Each Resource Type
Maintain wait-for graph.
• Nodes are processes.
• Pi → Pj if Pi is waiting for Pj
.
Periodically invoke an algorithm that searches for a cycle in
the graph.
If there is a cycle, there exists a
deadlock.
An algorithm to detect a cycle in a graph requires an
O(n2)
operations, where n is the number of vertices in the
graph.
55. Process Termination
Abort all deadlocked processes.
Abort one process at a time until the deadlock cycle is eliminated
In which order should we choose to abort?
Priority of the process.
How long process has computed, and how much longer to completion.
Resources the process has used. Resources process
needs to complete.
How many processes will need to be terminated. Is process
interactive or batch.
56. Resource Preemption
Selecting a victim: minimize cost
Rollback: return to some safe state, restart process for that state.
Starvation: same process may always be picked as victim, include
number of rollback in cost factor.
57. Summary
Four simultaneous conditions: mutual exclusion, hold and wait, no preemption,
circular wait
Deadlock prevention:
Deadlock avoidance: resource-allocation algorithm, banker’s algo- rithm
Deadlock detection: Wait-for graph
Deadlock recovery: process termination, resource preemption
Notas do Editor
By separating the information into individual pieces and giving each piece a name, the information is easily separated and identified. Taking its name from the way paper based information system are named, each piece of information is called a “file” The structure and logic rules used to manage the groups of information their names is called a “file system”.
Different structure and logic, properties of speed, flexibility, security, size.
Iso file system of disk
Different storage devices with differene media.
Hard drive is coated with magnetic film.
File system are used to implement type of data store, retrieve and update.
File system referse to either he abstract data structures used to define files, actual software or firmware.
When a file is created and there is not an area of contiguous space available for its initial allocation the space must be assigned in fragments. When a file is modified such that it becomes larger it may exceed the space initially allocated to it, another allocation must be assigned elsewhere and the file becomes fragmented.
Modern File system have wide range of chatacter.
File system might store the file creation time, the time it was last modified or the last time it was backed up. Other information can include the file's device type (e.g. block, character, socket, subdirectory, etc.), its owner user ID and group ID, its access permissions and other file attributes (e.g. whether the file is read-only, executable, etc.).
Methods for encrypting file data are sometimes included in the file system. This is very effective since there is no need for file system utilities to know the encryption seed to effectively manage the data.
Name :- Provide Handle for reference
Dos (8 char + 3 ext.),
Windows ( unlimited Length)
Unix ( spaces tricky, no extension needed)
Type:- Indicates how the file should be treated
DOS/Windows rely on extension, can map extensions to programs
Mac associates creator attribute with each file (OS X?)
UNIX uses "magic number", first few bytes of file specify file type
For example
MS-DOS Filsnames
Name 1 to 8 char
Extension 1 to 3 char
Dos only uses uppercase without spaces and special character.
Recovery features-each file operation broken down into atomic transactions.
maintains a transaction log – updates disk after each transaction
if failure occurs during a transaction, info is sufficient to complete or rollback
if a bad sector is found when writing, will automatically map to a different sector
Full Format lays down new tracks and sectors, Verifies the integrity of each sector.
By doing a surface scan – OS will put dummy data into sectors and then try to read the sector
Quick Format: -
Remove files
Does not check for defective sectors
Seek time is the time for the disk are to move the heads to the cylinder containing the desired sector.
Rotational latency is the additional time waiting for the disk to rotate the desired sector to the disk head.