0% found this document useful (0 votes)
10 views2 pages

OS Final 2

Uploaded by

mreviewplay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

OS Final 2

Uploaded by

mreviewplay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Deadlock • Resource preemption Optimal - choose the page that will not be used for

- The os is taking care on resource allocation a) Select a victim process. b) Role back the victim the longest period of time. - guarantees the lowest
- A deadlock is a situation where a set of processes process to a safe state. c) Ensure that starvation will possible page fault rate for a fixed number of frames.
are blocked because each process is holding a not occur on the same processes. LRU least-recently-used - needs additional
resource and waiting for another resource acquired Memory-Management Strategies hardware to memorize the time when each
by some other process A Memory unit stores binary information (data, frame/page has been recently used
- Operation step = request > uses/owns > release instruction) in groups of bits called words. 5. Allocation of Frames
- OS deals with deadlock in one of three ways : 1. • Memory cell: A device or an electrical circuit used to Global replacement generally results in greater
Protocol to prevent or avoid 2. Allow the system to store a single bit (0 or 1). system throughput and is therefore the more
enter a deadlock state > detect > recover 3. Ignore • Memory word: A group of bits (cells) in a memory commonly used method.
the problem and pretend that deadlock never occur that represents instructions or data of some type. Non-uniform memory access (NUMA) is a shared
(most of OS do this) —---- 1K = 210 = 1024 memory architecture used in today’s multiprocessing
Necessary conditions - all happen > deadlock • Main memory and registers (direct-access storage (multiple CPUs) systems. Therefore, a process
1. Mutual exclusion: at least one resource is not devices) are the only general-purpose storage that should be allocated the frames in the memory that
sharable 2. Hold and wait: A process holding at least the CPU can access directly. belongs to the process’s running CPU.
one resource is waiting to acquire additional • Memory management is the functionality of an Thrashing is the situation that a system has to swap
resources held by other processes 3.No preemption: operating system which handles or manages primary pages (between the memory and the disk) at such a
A resource can be released only voluntarily memory and moves processes back and forth higher rate that major chunk of CPU time is spent in
(completed the task) 4.Circular wait between main memory and disk during execution. swapping (instead of running processes). Increasing
So, deadlock prevention • The essential requirement of memory management the degree of multiprogramming (to increase CPU
1.No mutual exclusion: all resources are sharable is to provide ways to dynamically allocate portions of utilization) beyond a particular point can cause
2.No hold and wait: create protocol 3.Allow memory to processes at their request, and free it for thrashing. • Increasing number of processes loaded
preemption 4.No circular wait reuse when no longer needed. into memory → free frames are lowered.
- The main idea of deadlock avoidance is to let the • An address seen by the memory unit—that is, the File System
operating system plans ahead (determine) on the one loaded into the memory address register of the A file system is about the space management in
resource allocation: memory—is commonly referred to as a physical nonvolatile storage devices.
Algorithm for Deadlock avoidance address. A file system consists of two distinct parts:
1.Resource-Allocation-Graph Algorithm - few • The set of all logical addresses generated by a • A collection of files • A directory structure
instance of each resource type program is a logical address space. A file is an abstraction entity and a logical view
-request (dotted arrow) > accept (arrow) • The set of all physical addresses corresponding to provided by the operating system.
these logical addresses is a physical address space. -The operating system and application programs
OS knows number of resource type and instances, • The mapping from logical to physical addresses is should recognize and promptly open files < file type
need, plan to allocate one by one done by a hardware device called the • The per-process open-file table stores information
2. Banker’s memory-management unit (MMU). of the files that are open by a process.
- It is proposed for resource-allocation problems with - Swapping is a technique to increase the number of
multiple instances of each resource type. processes running concurrently.
2.1 Safety algorithm - Standard swapping is not used in modern operating
Finish[i] == false and Needi ≤ Work systems
2.2 Resource-Request Algorithm In contiguous memory allocation, each process is
Requesti ≤ Needi contained in a single section of memory that is • The system-wide open-file table stores the open-file
Requesti ≤ Available contiguous to the section containing the next entry and the open count
Then, run safety algorithm process.- fixed-sized partitions • Partitioning is useful for limiting the sizes of
If safe state > allow this request -Variation-Partition Scheme > main mem isn’t divided individual file systems.
Deadlock detection into partitions hole • Each quarter contains a file system.
1. Wait-For Graph External fragmentation > Compaction – The goal is • Directory • Files
- all resource types have a single to shuffle the memory contents so as to place all free • The users know/call this quarter as a volume (in
instance memory together in one large block –Segmentation computer). • A volume can be thought of as a virtual
- if the wait-for graph contains a and Paging disk. • A volume consists of files and a volume table
cycle, there is a deadlock in the • The physical memory is divided into fixed-size of contents (also known as a device directory or
system. blocks called frames. • The logical memory is divided directory)
2.Deadlock Detection Algorithm into fixed-size blocks called pages. • The difference between a partition and volume. • A
Requesti ≤ Work Binary Notations of Paging Logical Addresses partition is a space crafted out of a disk. • A volume is
**Request แทน need • For example, if m=4 and n=2, the a partition that has been formatted into a filesystem.
Invoking/running a deadlock detection algorithm will logical space consists of: Two-Level Directory
incur considerable overhead in computation time. • 4 pages • Each page has the size of 4 • Master file directory (MFD) which is separated into
Therefore, when we should run a deadlock algorithm bytes. users. • User file directory (UFD) which consists of a
must be considered carefully. • If a deadlock occurs - The frame table is used to keep record set of directories according to each user.
frequently, then, the algorithm might be invoked which frame is free or allocated Tree-Structure Directory - A user can access
frequently. • In case that a deadlock occurs, the Virtual-Memory Management (sub)directories and files of another user.
number of processes involved in the deadlock cycle Virtual memory is a technique that allows the the Unix uses “/” while Windows uses “\” to
might grow as time passes. The sooner we can execution of processes that are not completely in specify a series of directories and the file
detect, the smaller the damage causes. memory; parts of it may be in disk >> increase Acyclic-Graph Directory ex.GG drive - shared
degree of multiprogramming directories or files. There will be more than one path
Recovery from deadlock • Access to a page marked invalid causes a page name to the shared file/directory.
-inform the operator that a deadlock has occurred fault.
and to let the operator deal with the deadlock A reference string is a string of memory reference.
manually. In the other word, a reference string is a sequence of
-let the system recover from the deadlock pages in the disk that are loaded into memory and
automatically (explained in this section). read/executed by the CPU
• Process termination • Belady’s anomaly • For some page-replacement
a) Abort all deadlocked processes. algorithms, the page-fault rate may increase as the
b) Abort one process at a time until the deadlock number of allocated frames increases.
cycle is eliminated- incurs considerable overhead
General -Graph Directory Information Transfer to I/O Devices
• It is a tree structure that allows a cycle occurring in A. I/O instructions: Each byte or word of information
the directory structure. is transferred via an instruction to put it into the
• A problem will happen, for example, when we are data-in or data-out register
searching inside one of these directories. We will B. Memory-mapped I/O: a memory address space is
encounter an infinite loop. • As a solution, for the shared by CPU and I/O devices.
above problem, we can limit the number of directories Characteristics of I/O Devices
that will be accessed during a search. 1. Data-transfer mode: • A character-stream device
transfers a byte at a time. (Ex., monitor) • A block
device transfer a block of bytes at a time. (Ex., disk)
Implementing Directories 2. Access method (to data, e.x., read, write): • A
• For the contiguous allocation - file names, their sequential (Ex., tape, modem) • A random-access
starting blocks, their lengths. device (Ex., CD-ROM, disk)
• For the linked-list allocation - file names, their 3. Data transfer schedule: • A synchronous device
starting blocks, their ending blocks. predictable response times in coordination with other
Protection > Permissions • For the i-node allocation - file names, their blocks aspects of the system(Ex., tape) • An asynchronous
Group = A set of users who are sharing the file and storing the i-node tables device exhibits irregular or unpredictable response
need similar access is a group, or work group. 1) Linear List - time-consuming to execute. times not coordinated with other computer events.
• Full Control allows a user to read, write, modify, 2) Hash Table (Ex., keyboard)
execute, change attributes, permissions, and take 4. Sharing: • A sharable device can be used
ownership of the file. • Modify allows a user to read, concurrently by several processes or threads. (Ex.,
write, modify, execute, and change the file’s monitor, keyboard) • A dedicated device is owned by
attributes. • Read & Execute will allow a user to a process or a thread per time. (Ex., tape) 5. I/O
display the file’s data, attributes, owner, and direction: • A read-write device (Ex., disk) • A
permissions, and run the file if its a program. • Read read-only device. (Ex., mouse, keyboard) • A
- To create a file, we search the free-space list for the
will allow a user to open the file, view its attributes, write-only device (Ex., monitor) 6. Device speed
required amount of space and allocate that space to
owner, and permissions. • Write will allow a user to • A programmable interval timer is the hardware to
the new file
write data to the file, append to the file, and read or measure elapsed time and, then, generate an
Free-Space Management - Bit Vector
change its attributes. interrupt (sent to other hardware) to trigger
If the block is free, the bit is 1; if the block is
operations.
allocated, the bit is 0. - start at physical block 0
device driver is an add-on software such that a
Input and Output (I/O) System computer system can interact with a device properly.
Two main jobs of a computer system are I/O -It makes the I/O subsystem independent of devices
(input/output) and processing. - OS to manage and and their controllers
control I/O operations and I/O devices. Two types of I/O system calls:
- Device drivers are the key such that the OS 1. Synchronous systems calls: 1.1. Blocking I/O -
recognizes those devices. process will wait until the job finishes 1.2 Nonblocking
- A device controller is a hardware unit with I/O bus or - process waits for a little time and execute next
port to provide a hardware interface between a command 2. Asynchronous - return immediately
device and the computer. Vectored I/O - system calls that perform multiple
I/O devices can connect to a computer system via a operations involving multiple locations/addresses.
File System Layout connection point called a port (serial ports or parallel I/O Scheduling a) improve overall performance, b)
Sector 0 of the disk is called the MBR (Master Boot ports). •via a set of wires called a bus. • Three basic be fair among processes, c) reduce the average
Record) and is used to boot the computer. The end types of buses are widely used in computer systems: waiting time.
of the MBR contains the partition table. This table • The PCI (Peripheral Component Interconnect) bus The os has a device-status table to keep track all I/O
gives the starting and ending addresses of each connects high-speed high bandwidth devices to the requests
partition. memory and CPU subsystems. • An expansion bus kernel buffer is a memory area that stores data being
Implementing Files connects relatively slow devices, such as the transferred between two devices or between a device
Linked-List Allocation keyboard and serial and USB ports. • A SCSI (small and an application
computer system interface) bus connects a number 1. To cope with a speed mismatch between two or
of SCSI devices to a common SCSI controller more devices who are exchanging data. > Double
Device Controller • A device controller is an buffering means that two buffers are used in data
electronic component that can operate a port, a bus, transfer between I/O devices.
or a device. 2. To provide adaptations for devices that have
• A device controller typically consists of four different data-transfer sizes
registers: • The data-in register is read by the CPU to 3. To support copy semantics for application I/O - the
get input. • The data-out register is written by the version of the data written to disk is guaranteed to be
CPU to send output. • The status register contains the version at the time of the application system call
Linked-List bits that can be read by the CPU. These bits indicate - A spool is a buffer that holds output for a device,
Allocation using states, such as whether the current command has such as a printer, that cannot accept interleaved data
a Table in completed, whether a byte is available to be read streams from many applications.
Memory from the data-in register, and whether a device error Error Handling
file allocation has occurred. • The control register can be written by I/O system call will return one bit of information about
table (FAT) in the CPU to start a command or to change the mode the status of the call identifying either success or
main mem of a device. failure
I/O cycle/operation I/O Protection • Some applications might
• Polling-based I/O cycle - busy-waiting accidentally issue illegal/harmful instructions to I/O
• Interrupt-driven I/O cycle - device controller will devices or the system. • To prevent users from
send a signal to notify the CPU when the controller performing these illegal/harmful instructions, we
index-node and devices are ready for service define all I/O instructions to be privileged instructions.
(i-node) for each file stored in the disk - The CPU hardware has a wire called the User program exe system call > os check > valid, os
interrupt-request line that CPU will sense after return the control to the user program
executing every instruction.

You might also like