Unit-5 Part1
Unit-5 Part1
Unit-5 Part1
System
Unit – V
Dr.A.Kathirvel
Professor & Head/IT - VCEW
Unit - V
Structures – Design Issues – Threads – Process
Synchronization – Processor Scheduling – Memory
Management – Reliability / Fault Tolerance; Database
Operating Systems – Introduction – Concurrency
Control – Distributed Database Systems –
Concurrency Control Algorithms.
Motivation for Multiprocessors
Enhanced Performance -
Concurrent execution of tasks for increased
throughput (between processes)
Exploit Concurrency in Tasks (Parallelism
within process)
Fault Tolerance -
graceful degradation in face of failures
Basic MP Architectures
Single Instruction Single Data (SISD) -
conventional uniprocessor designs.
Single Instruction Multiple Data (SIMD) -
Vector and Array Processors
Multiple Instruction Single Data (MISD) -
Not Implemented.
Multiple Instruction Multiple Data (MIMD)
- conventional MP designs
MIMD Classifications
Tightly Coupled System - all processors
share the same global memory and have
the same address spaces (Typical SMP
system).
Main memory for IPC and Synchronization.
Loosely Coupled System - memory is
partitioned and attached to each processor.
Hypercube, Clusters (Multi-Computer).
Message passing for IPC and synchronization.
MP Block Diagram
Interconnection Network
MM MM MM MM
Memory Access Schemes
• Uniform Memory Access (UMA)
– Centrally located
– All processors are equidistant (access times)
• NonUniform Access (NUMA)
– physically partitioned but accessible by all
– processors have the same address space
• NO Remote Memory Access (NORMA)
– physically partitioned, not accessible by all
– processors have own address space
Other Details of MP
Interconnection technology
Bus
Cross-Bar switch
Multistage Interconnect Network
Caching - Cache Coherence Problem!
Write-update
Write-invalidate
bus snooping
MP OS Structure - 1
Separate Supervisor -
all processors have their own copy of the kernel.
Some share data for interaction
dedicated I/O devices and file systems
good fault tolerance
bad for concurrency
MP OS Structure - 2
• Master/Slave Configuration
– master monitors the status and assigns work to
other processors (slaves)
– Slaves are a schedulable pool of resources for
the master
– master can be bottleneck
– poor fault tolerance
MP OS Structure - 3
Symmetric Configuration - Most Flexible.
all processors are autonomous, treated equal
one copy of the kernel executed concurrently
across all processors
Synchronize access to shared data structures:
Lock entire OS - Floating Master
Mitigated by dividing OS into segments that normally
have little interaction
multithread kernel and control access to resources
(continuum)
MP Overview
MultiProcessor
SIMD MIMD
System/Memory Bus
Issues:
• Memory contention Main 50ns I/O
• Limited bus BW INT Memory Bridge subsystem
• I/O contention
• Cache coherence
System Functions ether
(timer, BIOS, reset)
scsi
Typical I/O Bus:
• 33MHz/32bit (132MB/s) video
• 66MHz/64bit (528MB/s)
Some Definitions
Parallelism: degree to which a multiprocessor
application achieves parallel execution
Concurrency: Maximum parallelism an
application can achieve with unlimited
processors
System Concurrency: kernel recognizes multiple
threads of control in a program
User Concurrency: User space threads
(coroutines) provide a natural programming
model for concurrent applications. Concurrency
not supported by system.
Process and Threads
Process: encompasses
set of threads (computational entities)
collection of resources
Thread: Dynamic object representing an
execution path and computational state.
threads have their own computational state: PC,
stack, user registers and private data
Remaining resources are shared amongst threads
in a process
Threads
Effectiveness of parallel computing depends on
the performance of the primitives used to
express and control parallelism
Threads separate the notion of execution from
the Process abstraction
Useful for expressing the intrinsic concurrency
of a program regardless of resulting
performance
Three types: User threads, kernel threads and
Light Weight Processes (LWP)
User Level Threads
• Definition:
// remainder section
}
Does it satisfy mutual exclusion?
How about progress and bounded waiting?
How to fix this?
Bounded-Waiting TestAndSet
Mutual exclusion
• Shared variable Proof: can two processes pass the
boolean waiting[n]; while loop (and enter critical section)
boolean lock; // initialized false. at the same time?
• Solution: Entry Section Bounded Waiting
do { Limited time in waiting for other
waiting[i] = TRUE;
processes.
while (waiting[i] &&
TestAndSet(&lock); What is waiting[] for? When does
waiting[i] = FALSE; waiting[i] set to FALSE?
Proof: how long does Pi’s wait till
// critical section Exit Section waiting[i] becomes FALSE?
j=(i+1)%n; Progress
while ((j!=i) && !waiting[j]) Proof: exit section unblocks at least
j=(j+1)%n; one process’s waiting[] or set the lock
to FALSE.
If (j==i) lock = FALSE;
else waiting[j] = FALSE;
// reminder section
} while (TRUE);
Swap Instruction
• Definition:
User process
User space
System V
Software 4.3 BSD emulator HP/UX
emulator
layer emulator emulator Other
emulator
Microkernel Kernel space
The kernel manages five principal
abstractions:
1. Processes.
2. Threads.
3. Memory objects.
4. Ports.
5. Messages.
Process Management in Mach
Thread
Low 31 31
:Free :Busy
Count: 6 Count: 7
Hint: 2 Hint: 4
Memory Management in Mach
Mach has a powerful, elaborate, and highly flexible memory
management system based on paging.
The code of Mach’s memory management is split into three
parts. The first part is the pmap module, which runs in the
kernel and is concerned with managing the MMU.
The second part, the machine-independent kernel code, is
concerned with processing page faults, managing address
maps, and replacing pages.
The third part of the memory management code runs as a
user process called a memory manager. It handles the logical
part of the memory management system, primarily
management of the backing store (disk).
Virtual Memory
The conceptual model of memory that Mach user
processes see is a large, linear virtual address space.
The address space is supported by paging.
A key concept relating to the use of virtual address
space is the memory object. A memory object can be
a page or a set of pages, but it can also be a file or
other, more specialized data structure.
An address space with allocated regions,
mapped objects, and unused addresses
Unused
Stack region
Unused
Data region
Unused
Text region
System calls for virtual address
space manipulation
Allocate Make a region of virtual address space usable
Mapped
file
Operation of Copy-on-Write
Physical memory
Prototype’s address space Child’s address space
7 RW 7 RO 7
6 6 6
5 5 5
4 4 4
3 3 3
RO
2 2 2
1 1 1
0 0 0
Operation of Copy-on-Write
7 RW 7 7
R
6 6 O 6
5 5 5
4 4 4
3 3 3
RO
2 2 2
1 1 1
0 0 0
Advantages of Copy-on-write
1. some pages are read-only, so there is no
need to copy them.
2. other pages may never be referenced, so
they do not have to be copied.
3. still other pages may be writable, but the
child may deallocate them rather than using
them.
Disadvantages of Copy-on-write
1. the administration is more complicated.
2. requires multiple kernel traps, one for each
page that is ultimately written.
3. does not work over a network.
External Memory Managers
Each memory object that is mapped in a process’ address
space must have an external memory manager that controls
it. Different classes of memory objects are handled by
different memory managers.
Three ports are needed to do the job.
The object port, is created by the memory manager and will
later be used by the kernel to inform the memory manager
about page faults and other events relating to the object.
The control port, is created by the kernel itself so that the
memory manager can respond to these events.
The name port, is used as a kind of name to identify the
object.
Distributed Shared Memory in Mach
The idea is to have a single, linear, virtual
address space that is shared among processes
running on computers that do not have any
physical shared memory. When a thread
references a page that it does not have, it
causes a page fault. Eventually, the page is
located and shipped to the faulting machine,
where it is installed so that the thread can
continue executing.
Communication in Mach
The basis of all communication in Mach is a kernel data
structure called a port.
When a thread in one process wants to communicate with a
thread in another process, the sending thread writes the
message to the port and the receiving thread takes it out.
Each port is protected to ensure that only authorized
processes can send it and receive from it.
Ports support unidirectional communication. A port that can
be used to send a request from a client to a server cannot also
be used to send the reply back from the server to the client. A
second port is needed for the reply.
A Mach port
Message queue
Current message count
Maximum messages
Receiving thread
Sending
thread
send receive
port Kernel
Capabilities
A B
process
thread
Capability 1 Port 1
with RECEIVE 2 X
2
right kernel
3 Port 3
4 Y 4
Allocate Create a port and insert its capability in the capability list
Destroy Destroy a port and remove its capability from the list
Message size
Capability index for destination port
Header
Capability index for reply port
Descriptor 1
Message Data field 1
body
Descriptor 2
Data field 2
Complex message field descriptor
Bits1 1 1 1 12 8 8
Number of Data field size Data field type
in the data field In bits
Timestamps
Unique number is assigned to a transaction or a data object and is
chosen from a monotonically increasing sequence.
Commonly generated using Lamport’s scheme
Lock based algorithms
Static locking
Two Phase Locking (2PL)
Problems with 2PL: Price for Higher concurrency
2PL in DDBS
Timestamp Based locking
Conflict Resolution
Wait Restart Die Wound
Non-two-phase locking
Timestamp Based Algorithms
Basic timestamp ordering algorithm
Thomas Write Rule (TWR)
Multiversion timestamp ordering algorithm
Conservative timestamp ordering algorithm
Thank U