0% found this document useful (0 votes)
46 views

Final Exam OS

The document discusses operating system memory and deadlocks. It begins by defining a deadlock as when one process is waiting for a resource held by another process, creating a circular dependency. It then provides an example of a deadlock involving three processes and three resources. It outlines the four necessary conditions for a deadlock: mutual exclusion, hold and wait, no preemption, and circular wait. It describes strategies for deadlock prevention such as avoiding mutual exclusion or circular wait conditions. Finally, it discusses deadlock avoidance techniques like the resource allocation graph and Banker's algorithm that allow an operating system to predict and prevent deadlocks from occurring by maintaining safe process execution states. It also covers deadlock detection methods using

Uploaded by

chowsaj9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Final Exam OS

The document discusses operating system memory and deadlocks. It begins by defining a deadlock as when one process is waiting for a resource held by another process, creating a circular dependency. It then provides an example of a deadlock involving three processes and three resources. It outlines the four necessary conditions for a deadlock: mutual exclusion, hold and wait, no preemption, and circular wait. It describes strategies for deadlock prevention such as avoiding mutual exclusion or circular wait conditions. Finally, it discusses deadlock avoidance techniques like the resource allocation graph and Banker's algorithm that allow an operating system to predict and prevent deadlocks from occurring by maintaining safe process execution states. It also covers deadlock detection methods using

Uploaded by

chowsaj9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

Operating-System-Memory

CSEC-227
Chowdhury Sajadul Islam

Msc-F23_Final_slides: 2-6, 10-14, 20, 22, 23, 29, 35, 37


1. Introduction to Deadlock
A deadlock can occur in almost
any situation where processes
share resources. It can happen in
any computing environment, but it
is widespread in distributed
systems, where multiple
processes operate on different
resources.
In this situation, one process may
be waiting for a resource already
held by another process.
Deadlock is similar to a chicken
and egg problem. Let’s see an
example of deadlock:

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Suppose there are three
and
three resources, R1, R2, and R3.

Now, suppose

In such a case, P1 won’t proceed


without R2 and will wait
indefinitely because P2 can’t
release resource 2 until it gets R3,
which P3 holds. The same is true
for P1 and P3. Thus, it’s an ideal
example of a deadlock situation in
OS.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


3. Necessary Conditions for Deadlock
The following four conditions hold simultaneously:

1. The first condition is mutual exclusion. In this condition, we can’t


share a resource among the different processes at the same time.

For example, if two people want to print a paper simultaneously, this


process can not be done. One has to wait until the system releases the
print (resource). Thus, we can assign a resource to only one process at a
time.

2. The second necessary condition for deadlock is


. In this condition, a
. Here, the
It’s in a waiting state.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


3. Necessary Conditions for Deadlock
3. The third condition is . If a process holds a resource,
then the resource can not be taken away forcefully from the process
until it releases the resource. This statement also holds when the
process is in a waiting state.

4. The final condition for deadlock is the circular wait. Let’s assume the
process P1 is waiting for a resource R2. Now that particular resource R2
is already held by a process P2. Process P2 is waiting for the resource,
held by the next process. This will continue until the last process is
waiting for the resource held by the first process.

The circular wait condition creates a circular chain and puts all the
processes in a waiting state.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


4. Deadlock Prevention
If the OS can avoiding any one of the four conditions , a deadlock will
not occur.

4.1. No Mutual Exclusion


It means more than one process can have access to a single resource at
the same time. It’s impossible because if multiple processes access the
same resource simultaneously, there will be chaos. Additionally, no
process will be completed. So this is not feasible. Hence, the OS can’t
avoid mutual exclusion.

Let’s take a practical example to understand this issue. Jack and Jones
share a bowl of soup. Both of them want to drink the soup from the
same bowl and use a single spoon simultaneously, which is not feasible.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Deadlock Prevention
4.2. No Hold and Wait
To avoid the hold and wait, there are many ways to acquire all the
required resources before starting the execution. But this is also not
feasible because a process will use a single resource at a time. Here, the
resource utilization will be very less.

Before starting the execution, the process does not know how many
resources would be required to complete it. In addition to that, the bus
time, in which a process will complete and free the resource, is also
unknown.

Another way is if a process is holding a resource and wants to have


additional resources, then it must free the acquired resources. This way,
we can avoid the hold and wait condition, but it can result in starvation.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Deadlock Prevention
4.3. Removal of No Preemption
One of the reasons that cause the deadlock is the no preemption. It means the
CPU can’t take acquired resources from any process forcefully even though that
process is in a waiting state. If we can remove the no preemption and forcefully
take resources from a waiting process, we can avoid the deadlock. This is an
implementable logic to avoid deadlock.
For example, it’s like taking the bowl from Jones and give it to Jack when he
comes to have soup. Let’s assume Jones came first and acquired a resource and
went into the waiting state. Now when Jack came, the caterer took the bowl from
Jones forcefully and told him not to hold the bowl if you are in a waiting state.
4.4. Removal of Circular Wait
In the circular wait, two processes are stuck in the waiting state for the resources
which have been held by each other. To avoid the circular wait, we assign a
numerical integer value to all resources, and a process has to access the resource
in increasing or decreasing order.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


5. Deadlock Avoidance
Deadlock avoidance methods help the OS to avoid the occurrence of deadlock.
The OS will maintain a log of the maximum required resources needed for a
process in the whole life cycle before starting the execution. The OS will
continually check the system’s state before allocating any newly requested
resource to any process.

Basically, in the deadlock avoidance, the OS will try not to be in cyclic wait
condition. If the OS can allocate all the requested resources to the process
without causing the deadlock in the future, that is known as a safe state. And if
the OS can’t allocate all the requested resources without causing the deadlock in
the future, that is known as an unsafe state.
5.1. Resource Allocation Graph (RAG) Algorithm
Using RAG, it’s possible to predict the occurrence of deadlock in an OS.
The resource allocation graph is the pictorial view of all allocated resources,
available resources, and OS’s current state. We can figure out how many
resources are allocated to each process and how many resources will be needed
in the future. Thus, we can easily avoid the deadlock.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


5. Deadlock Avoidance
As every graph has vertices and edges, in the same way, RAG also has vertices
and edges. RAG has two vertices: process vertex and resource vertex, and two
edges: assignment edge and request edge. Mostly, we represent vertices with a
rectangular shape and edges with a circular shape:

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


5. Deadlock Avoidance
There is a limitation with the RAG algorithm that it’ll only work if all the
resources have a single instance. If there is more than one instance of a resource,
it’ll not be certain in determining the deadlock. There will be the possibility of
forming the circle, but it may lead to a deadlock. So, in that situation, we use the
Banker’s algorithm to determine the deadlock.
For example, let two processes P1,
P2, and two resources R1, R2:
Here, P1 uses R1, and it’ll use R2
in the future, denoted as a dotted
line. At the current time, it’s free. P2
is requesting R2, but OS will not
allocate that, as it’ll be needed for
P1 later. So it’ll avoid the formation
of a circle. Thus, it avoids the
probability of deadlock occurrence.
But from the above solution, R2 will
not be in use. Hence, resource
utilization will be less.
Chowdhury Sajadul Islam-----------UU------------- CSEC-227
5.2. Banker’s Algorithm
When resources have multiple instances, we use the Banker’s algorithm. It is
known as the Banker’s algorithm because banks follow it to manage the
resources in such a manner so that they’ll never be out of resources and avoid
getting into an unsafe state. Banks use this algorithm before allocating or
sanctioning any loan in the banking system.

In this algorithm, we need some predetermined data, such as the maximum


required resources from each process to complete the life cycle and the total
available resources in the OS. From that data, it’ll make a safe sequence. If the
OS runs all the processes in that sequence, it’ll avoid the occurrence of deadlock.

This algorithm maintains a matrix of total available resources, maximum


required resources for each process, total allocated resources to each process,
and currently required resources.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


6. Deadlock Detection and Avoidance

In this method, the OS assumes that a deadlock will occur in the future. So it
runs a deadlock detection mechanism with a certain interval of time, and when
it detects the deadlock, it starts a recovery approach.

The main task of the OS is


to detect the deadlock.
There’re two methods of
detection which we’ve
already covered before.

Here, we use the same


methods with some
improvisations:

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


6. Deadlock Detection and Avoidance
In the wait-for graph method, the OS checks the formation of a circle. It’s
somehow the same as the resource allocation graph (RAG) with some
differences. Mostly it causes confusion between the RAG and Wait-for graph.

The main difference between a RAG and a wait-for graph is the number of
vertices each graph contains. A RAG graph has two vertices: resource and
process. A wait-for graph has one vertex: process.We can also create a wait-for
graph using a RAG:

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


6. Deadlock Detection and Avoidance
The wait-for graph is not making a circle, which means it’ll not lead the system
to a deadlock. For multiple instance resources, we use the Safety algorithm,
which uses the same approach as the Banker’s algorithm. But it doesn’t have a
maximum required resource matrix. It has only three matrices: allocated,
available, and current requirement matrix.

Now, as soon as the OS detects a deadlock, it’ll start the recovery method. There
are two main approaches to recover from a deadlock:

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


6.1. Optimist Approach

An example of the optimist approach is the resource and process preemption. In


this approach, the OS will select some processes and preempt their resources,
thereafter allocate them to other processes. Thus, the OS will try to break the
circle.

One disadvantage of this approach is there is a possibility that the same process
may become the victim of preemption. In this condition, the process will be
stuck in starvation.

Another approach in which the OS will roll back to a certain safe state where
deadlock hasn’t occurred. But for this, OS has to maintain some logs up to which
it was in a safe state.
One of the disadvantages of this method is that there is no decision parameter to
select the order of the rollback of the processes.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


6.2. Pessimist Approach

One pessimist approach is to abort all the deadlocked processes. This is the
simplest way of breaking the cycle to recover from the deadlock, but it’s also the
most costly way of handling deadlock. In this method, we kill all the processes,
and the OS will either discard them or restart a portion of the processes later as
per requirement.

Also, we can abort the one process at a time till we eliminate deadlock from the
system.

In this method, the OS kills one process at a time, and it selects the process
which has done the least work. After that, it runs the deadlock detection
algorithm to verify if the deadlock is recovered. If it is not recovered, then it will
keep killing the processes till the deadlock is eliminated.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


7. Deadlock Ignorance
This is one of the widely used methods to handle the deadlock. In this method,
the OS assumes that deadlock will never occur. If there is a condition of
deadlock, the OS will reboot the system. This method is very popular where OS
is for the end-users.

Deadlock ignorance approaches are used in Linux and Windows-based OS


where users are directly in contact with the system.

In this lesson, I discussed the concept of deadlock in OS thoroughly. I presented


an example to illustrate the idea behind deadlock in OS.

Furthermore, we explored various approaches to prevent, avoid, detect, and


ignore deadlock.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Dead Lock 1(a)
In the discussion of Unix SysV IPC, we noted that semaphore
creation (semget) and initialization (semctl) are not atomic
operations.
*) What does this mean?
Atomic operations can only be executed in their entirety without
danger of preemption by an interrupt.
*) In general, what problem could this lead to?
Non-atomicity of the semaphore creation and initialization
operations implies that a potential race condition exists in which
two processes could create the same semaphore and initialize it to
different values. This could lead one of these processes to
potentially incorrect behavior.
Chowdhury Sajadul Islam-----------UU------------- CSEC-227
Memory
DeadPortioning
Lock
*) How did you avoid this problem in your solution?
All semaphores should be created by the main process before the children are divided.
Hence, as pointed out in the IPC notes, no race is possible, provided the semaphores are
created with a key of IPC_PRIVATE. If a non-private key value is used, another
process could potentially create a race condition. However, there was no need to use
public keys in this assignment.
*) Briefly describe Stevens' solution and explain how it overcomes this problem.
Stevens uses a trio of semaphores to achieve atomic creation and initialization. The
semaphore value itself is stored in the first, an initialized flag is stored in the second,
and the third (mutex) is used to enforce mutual exclusion on the setting of the second.
A request is issued consisting of two operations: wait for mutex to be zero (as it should
be on creation), then increment it to 1. Because semop () is atomic, the call will succeed
only if both parts succeed, i.e., mutual exclusion is achieved. At this point, Stevens'
code verifies that the semaphore has not yet been initialized.
The first semaphore can then be initialized with the desired value and the second
semaphore can be set to indicate that the trio has been initialized.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory management
The operating system of a computer needs to keep track of where data
is stored in main memory (RAM). Usually, instructions and data will be
stored initially on non-volatile media such as a hard disk. The
operating system will then load the data and instructions to the main
memory so that the data can be processed and the instructions can be
executed.
Operating systems handle multiple memory management operations,
including tracking the status of memory allocation, determining
storage requirements, and controlling memory usage.

Tracking the status of memory allocation: Memory is divided up


into physical address spaces. The OS initially marks each space as free.
When required, the OS loads data into these spaces and marks them as
allocated. When the data or instructions are no longer needed, the OS
marks the spaces as free again, which allows the data that is stored in
these spaces to be overwritten.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory Allocation
Main memory is a hardware resource with physical addresses used to
locate areas in which data and instructions can be stored.

When a program is executed, a series of logical addresses are produced.


The total of these logical addresses makes up the logical address space
of that process.

The OS has to map the logical address space to the physical address
space and manage memory usage between the processes as appropriate,
for example, via paging, segmentation, and the use of virtual memory.
In computer systems design, the concept of memory hierarchy is an
enhancement to organize the computer's memory such that access time
to memory is minimized. Memory hierarchy was developed based on a
software program's behavior known as locality of references.The figure
below depicts the different levels of memory hierarchy :

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory Hierarchy Design and its Characteristics

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory Hierarchy Design and its Characteristics
This Memory Hierarchy Design is divided into 2 main types:

r Secondary Memory
This level is comprised of peripheral storage devices which are
accessible by the processor via I/O Module.
r Primary Memory
This level is comprised of memory that is directly accessible by the
processor. We can infer the following characteristics of Memory
Hierarchy Design from the above figure:
Capacity:
As we move from top to bottom in the hierarchy, the capacity increases.
Access Time:
This represents the time interval between the read/write request and
the availability of the data. As we move from top to bottom in the
hierarchy, the access time increases.
Chowdhury Sajadul Islam-----------UU------------- CSEC-227
Memory Hierarchy Design and its Characteristics

In erly computer systems that were designed without the idea of


memory hierarchy design, the speed gap increased between the CPU
registers and main memory due to difference in access time. This
results in lower system performance, an enhancement was required.
This enhancement was memory hierarchy design which provided the
system with greater performance. One of the most significant ways to
increase system performance is to minimize how far down the memory
hierarchy one has to go to manipulate data. If we can keep system using
lower numbered levels (higher up the hierarchy) then we get better
performance.

As we move up the hierarchy - from bottom to top - the cost per bit
increases i.e. internal memory is costlier than external memory.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory Manager
The memory manager of an operating system handles the main
memory of a computer, especially RAM. In this way, the memory
manager must perform a myriad of activities to enable the processing
units to access code and data and then execute processes. Next, we
briefly describe some relevant activities of the memory manager:

Validation of requests: The memory manager checks the validity of a


memory request and if the claimant has the proper permissions to
request memory allocations
Allocation: The searching of free memory portions that satisfy a
particular memory request, allocating them with the required resources
Deallocation: The deallocation of memory of terminated or idle
processes or jobs of a processes
Defragmentation: The rearrangement of memory to establish more
usable free memory portions

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory Mapping
Memory mapping refers to the allocation strategies to allocate a
program to the main memory. In early systems, the general strategy
was the straightforward mapping of a requested program to physical
positions in contiguous spaces of the main memory. Thus, even
memory addresses accessed by the programs corresponded to physical
memory addresses.
As the programming possibilities increased, the programs grew bigger
in terms of how much memory they occupy. Many programs,
eventually, got bigger than the available memory in the computer
systems. So, allocating an entire program in memory and direct
mapping the program to physical memory positions turned unfeasible.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory Mapping
This context promoted the creation of virtual memory. With virtual
memory, a program can be divided into multiple pieces mapped to
virtual addresses. These pieces of programs, in turn, are on-demand
allocated and deallocated in the physical memory, linking only the
necessary virtual addresses to physical addresses.

The following image exemplifies a memory allocation in early systems


and virtual memory-enabled systems:

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory Mapping

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory management
Determining storage requirements
It is rare that the data needed for a process can fit in a single memory
location. Therefore, the OS needs to determine how much memory to
allocate to each process that is running, based on the requirements of
its programming. The OS then reserves blocks of addresses for each
process to use.

Memory is a finite resource. As more processes use memory, less free


space will be available. Portions of memory may need to be freed in
order to provide memory access for other processes. The OS manages
swapping between processes and their memory space in order to
provide memory access as required.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory management
The memory management in early computer systems is, in general,
quite simple. Let’s see few pieces of information about the most
common memory management schemes of these systems next.

The Single User Contiguous is the first and simplest scheme of memory
management. In such a case, the memory manager allocates all the
available memory to a unique program. So, the memory manager can
only allocate a new program if it already deallocated the previous one.

The Fixed Partitions scheme divides the available memory into fixed-
size partitions, thus allowing multiple and simultaneous allocations of
programs. These memory partitions are defined on the computer
system startup and aren’t modified unless it reboots. The memory
manager, in this case, adopts a partition memory table to track the
memory and determine on which partition a specific program should
be allocated.
Chowdhury Sajadul Islam-----------UU------------- CSEC-227
Memory management
The Dynamic Partitions scheme divides the computer memory into
dynamically specified partitions, avoiding memory-wasting scenarios. A
partition memory table is also required here. However, this scheme enables the
memory manager to modify the memory table lines (partitions) during the
execution of a computer system. Memory management schemes with partitions
demand a strategy to allocate programs. Let’s see two of them:

First Fit Allocation: The memory manager allocates a program on the first
found partition with sufficient memory
Best Fit Allocation: The memory manager finds the best partition to allocate a
program. The best fit refers to allocating a program in the smallest free
partition possible (fixed partitions) or maintaining the maximum free memory
in a contiguous partition (dynamic partitions)
All the schemes used in early systems, however, have a common problem: they
store the entire program in the main memory and can’t execute a program
bigger than the available physical memory. This problem boosted the
development of new memory management schemes based on virtual memory.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory Allocation
Paging
The logical address space is divided into memory units called pages.
When a page is loaded into the main memory, it is stored in a page
frame, which is a block of sequential addresses that is the same size
(has the same number of addresses) as a page. Paging allows memory
to be allocated in a non-contiguous manner — this means that pages of
the same process do not need to be stored together, but can be
allocated wherever there is free space in the main memory. A page table
is used to keep track of which page frame is allocated to each page.

Segmentation
The memory blocks that are allocated to processes are divided into
segments of different sizes to fit the varying memory requirements of
each process. The segments do not need to be stored continuously
across a fixed address space, and they can be moved in and out of
memory as required.
Chowdhury Sajadul Islam-----------UU------------- CSEC-227
Memory Allocation
The OS tracks the allocation of memory for each process using a
segment table, which records where each segment required for a process
is physically located.

Virtual memory
The operating system can extend the limited physical space of memory
by using other storage in the computer. For example, a hard disk can act
as virtual memory: the operating system can swap parts of a process
that are not currently in use from the main memory into an allocated
space on the hard disk, then swap it back into main memory when it is
needed.
This has the benefit of extending the memory available, and it might appear that
swapping instructions and data out of main memory into secondary storage
means that a vast quantity of memory is potentially available. However,
accessing a secondary storage medium, such as the hard drive, is considerably
slower than accessing main memory, therefore it may slow down the computer
system’s performance.
Chowdhury Sajadul Islam-----------UU------------- CSEC-227
Requirements of Memory Management System
Memory management keeps track of the status of each memory location,
whether it is allocated or free. It allocates the memory dynamically to the
programs at their request and frees it for reuse when it is no longer needed.
Memory management is meant to satisfy the following requirements:

The available memory is generally shared among a number of


processes in a multiprogramming system, so it is not possible to know in
advance which other programs will be resident in main memory at the time of
execution of his program. Swapping the active processes in and out of the main
memory enables the operating system to have a larger pool of ready-to-execute
process.

When a program gets swapped out to a disk memory, then it is not always
possible that when it is swapped back into main memory then it occupies the
previous memory location, since the location may still be occupied by another
process. We may need to relocate the process to a different area of memory.
Thus there is a possibility that program may be moved in main memory due to
swapping.
Chowdhury Sajadul Islam-----------UU------------- CSEC-227
Requirements of Memory Management System

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Requirements of Memory Management System
The figure depicts a process image. Every process looks like this in memory.
Each process contains: 1) process control blocks; 2) a program entry point - this
is the instruction where the program starts execution; 3) a program section; 4) a
data section; and 5) a stack. The process image is occupying a continuous region
of main memory. The operating system will need to know many things including
the location of process control information, the execution stack, and the code
entry. Within a program, there are memory references in various instructions
and these are called logical addresses.

After loading of the program into main memory, the processor and the operating
system must be able to translate logical addresses into physical addresses.
Branch instructions contain the address of the next instruction to be executed.
Data reference instructions contain the address of byte or word of data
referenced.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Requirements of Memory Management System
Protection – There is always a danger when we have multiple programs
executing at the same time - one program may write to the address space of
another program. So every process must be protected against unwanted
interference if one process tries to write into the memory space of another
process - whether accidental or incidental. The operating system makes a trade-
off between relocation and protection requirement: in order to satisfy the
relocation requirement the difficulty of satisfying the protection requirement
increases in difficulty.
It is impossible to predict the location of a program in main memory, which is
why it is impossible to determine the absolute address at compile time and
thereby attempt to assure protection. Most programming languages provide for
dynamic calculation of address at run time. The memory protection requirement
must be satisfied by the processor rather than the operating system because the
operating system does not necessarily control a process when it occupies the
processor. Thus it is not possible to check the validity of memory references.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Requirements of Memory Management System
Sharing – A protection mechanism must allow several processes to access the
same portion of main memory. This must allow for each processes the ability to
access the same copy of the program rather than have their own separate copy.

This concept has an advantage. For example, multiple processes may use the
same system file and it is natural to load one copy of the file in main memory
and let it shared by those processes. It is the task of memory management to
allow controlled access to the shared areas of memory without compromising
the protection. Mechanisms are used to support relocation supported sharing
capabilities.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Requirements of Memory Management System

Logical organization – Main memory is organized as linear or it can be a one-


dimensional address space which consists of a sequence of bytes or words. Most
of the programs can be organized into modules, some of those are unmodifiable
(read-only, execute only) and some of those contain data that can be modified.
To effectively deal with a user program, the operating system and computer
hardware must support a basic module to provide the required protection and
sharing. It has the following advantages:
Modules are written and compiled independently and all the references from
one module to another module are resolved by the system at run time.
Different modules are provided with different degrees of protection.
There are mechanisms by which modules can be shared among processes.
Sharing can be provided on a module level that lets the user specify the sharing
that is desired.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Requirements of Memory Management System
Physical organization – The structure of computer memory has two levels
referred to as main memory and secondary memory. Main memory is relatively
very fast and costly as compared to the secondary memory. Main memory is
volatile. Thus secondary memory is provided for storage of data on a long-term
basis while the main memory holds currently used programs. The major system
concern between main memory and secondary memory is the flow of
information and it is impractical for programmers to understand this for two
reasons:
The programmer may engage in a practice known as overlaying when the main
memory available for a program and its data may be insufficient. It allows
different modules to be assigned to the same region of memory. One
disadvantage is that it is time-consuming for the programmer.
In a multiprogramming environment, the programmer does not know how
much space will be available at the time of coding and where that space will be
located inside the memory.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory Portioning- 1(b)
Program binaries in many systems are typically structured as
follows. Code is stored starting with a small fixed virtual address
such as 0. The code segment is followed by the data segment that
is used for storing the program variables. When the program
starts executing, the stack is allocated at the other end of the
virtual address space and is allowed to grow towards lower virtual
addresses. What is the significance of the above structure on the
following schemes?
*. Contiguous-memory allocation
*. Pure segmentation
*. Pure paging

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Memory Portioning
*) Contiguous-memory allocation requires the operating system to
allocate the entire amount of the virtual address space to the program
when it starts executing. This could be much higher than the actual
memory requirements of the process.
*) Pure segmentation gives the operating system flexibility to assign a
small amount to each segment at program startup time and extend the
segment if required.
*) Pure paging does not require the operating system to allocate the
maximum amount of the virtual address space to a process at startup
time, but it still requires the operating system to allocate a large page
table spanning all of the program’s virtual address space.
When a program needs to expand the stack or the heap, it needs to
allocate a new page but the corresponding page table entry is pre-
allocated.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


final
Memory Portioning
Assume that you are monitoring the rate at which the pointer in the clock
algorithm (which indicates the candidate page for replacement) moves.
What can you say about the system if you notice the following behavior:
*. Pointer is moving fast. *. Pointer is moving slow.
Answer:
If the pointer is moving fast, then the program is accessing a large number of
pages simultaneously. It is most likely that during the period between the point
at which the bit corresponding to a page is cleared and it is checked again, the
page is accessed again and therefore cannot be replaced. This results in more
scanning of the pages before a victim page is found.
If the pointer is moving slow, then the virtual memory system is finding
candidate pages for replacement extremely efficiently, indicating that many of
the resident pages are not being accessed.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


File System
Consider a file system where a file can be deleted and its disk
space reclaimed while links to that file still exist. What problems
may occur if a new file is created in the same storage area or with
the same absolute path name? How can these problems be
avoided?
Let F1 be the old file and F2 be the new file. A user wishing to access F1
through an existing link will actually access F2. Note that the access protection
for file F1 is used rather than the one associated with F2.
This problem can be avoided by insuring that all links to a deleted file are
deleted also. This can be accomplished in several ways:
*. maintain a list of all links to a file, removing each of them when the file is
deleted
*. keep the links, removing them when an attempt is made to access a
deleted file
*. maintain a file reference list (or counter), deleting the file only after all links
or references to that file have been deleted.
Chowdhury Sajadul Islam-----------UU------------- CSEC-227
Final
Consider a file system that uses a modified contiguous-allocation
scheme with support for extents. A file is a collection of extents, with
each extent corresponding to a contiguous set of blocks. A key issue in
such systems is the degree of variability in the size of the extents. What
are the advantages and disadvantages of the following schemes?

1. All extents are of the same size, and the size is predetermined.
2. Extents can be of any size and are allocated dynamically.
3. c. Extents can be of a few fixed sizes, and these sizes are
predetermined.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


If all extents are of the same size, and the size is predetermined,
then it simplifies the block allocation scheme. A simple bit map
or free list for extents would suffice. If the extents can be of any
size and are allocated dynamically, then more complex allocation
schemes are required. It might be difficult to find an extent of the
appropriate size and there might be external fragmentation. One
could use the Buddy system allocator discussed in the previous
chapters to design an appropriate allocator. When the extents can
be of a few fixed sizes, and these sizes are predetermined, one
would have to maintain a separate bitmap or free list for each
possible size. This scheme is of intermediate complexity and of
intermediate flexibility in comparison to the earlier schemes.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Interrupts 2(a) +Slide 20
When multiple interrupts from different devices appear at about the same time, a
priority scheme could be used to determine the order in which the interrupts
would be serviced. Discuss what issues need to be considered in assigning
priorities to different interrupts.
Answer: A number of issues need to be considered in order to determine the priority
scheme to be used to determine the order in which the interrupts need to be serviced.
First, interrupts raised by devices should be given higher priority than traps generated
by the user program; a device interrupt can therefore interrupt code used for handling
system calls.
Second, interrupts that control devices might be given higher priority than interrupts
that simply perform tasks such as copying data served up a device to user/kernel
buffers, since such tasks can always be delayed.
Third, devices that have realtime constraints on when its data is handled should be
given higher priority than other devices. Also, devices that do not have any form of
buffering for its data would have to be assigned higher priority since the data could be
available only for a short period of time.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


File System
Ex 2(b)
Consider a system where free space is kept in a free-space list.
*. Suppose that the pointer to the free-space list is lost. Can the system
reconstruct the free-space list? Explain your answer.
*. Consider a file system similar to the one used by UNIX with indexed
allocation. How many disk I/O operations might be required to read the
contents of a small ? Assume that none of the disk blocks is currently
being cached.
Ans:
*. In order to reconstruct the free list, it would be necessary to perform
“garbage collection.” This would entail searching the entire directory structure
to determine which pages are already allocated to jobs. Those remaining
unallocated pages could be re-linked as the free-space list.

*. The free-space list pointer could be stored on the disk, perhaps in several
places.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


File System 3(a)
Explain why logging metadata updates ensures recovery of a file system after a
file system crash.
Answer: For a file system to be recoverable after a crash, it must be steady or
must be able to be made consistent. Therefore, we have to prove that logging
metadata updates keeps the file system in a consistent or able-to-be-consistent state.
For a file system to become inconsistent, the metadata must be written
incompletely or in the wrong order to the file system data structures. With metadata
logging, the writes are made to a sequential log. The complete transaction is written
there before it is moved to the file system structures. If the system crashes during
file system data updates, the updates can be completed based on the information in
the log. Thus, logging ensures that file system changes are made completely (either
before or after a crash). The order of the changes are guaranteed to be correct
because of the sequential writes to the log. If a change was made incompletely to
the log, it is discarded, with no changes made to the file system structures.
Therefore, the structures are either consistent or can be trivially made
consistent via metadata logging replay.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


3(b)
An experimental addition to UNIX allows a user to connect a watch-
dog program to a file. The watchdog is invoked whenever a program
requests access to the file. The watchdog then either grants or denies
access to the file. Discuss two pros and two cons of using watchdogs
for security.
Answer:
The watchdog program becomes the primary security mechanism for file
access. Because of this we find its primary benefits and detractions. A benefit
of this approach is that you have a centralized mechanism for controlling
access to a file - the watchdog program. By ensuring the watchdog program
has sufficient security techniques, you are assured of having secure access to
the file. However, this is also the primary negative of this approach as well -
the watchdog program becomes the bottleneck. If the watchdog program is not
properly implemented (i.e. it has a security hole), there are no other backup
mechanisms for file protection.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


4(a)
The UNIX program COPS scans a given system for possible security
holes and alerts the user to possible problems. What are two potential
hazards of using such a system for security? How can these problems
be limited or eliminated?

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Your company is building a computer network, and you are asked to write an algorithm for
achieving distributed mutual exclusion. Which scheme will you use? Explain your choice.
Answer: The options are a (1) centralized, (2) fully-distributed, or (3) token-passing approach.
We reject the centralized approach as the centralized coordinator becomes a bottleneck. We also
reject the token- passing approach for its difficulty in re-establishing the ring in case of failure.
We choose the fully-distributed approach for the following reasons:
• Mutual exclusion is obtained.
• Freedom from deadlock is ensured.
• Freedom from starvation is ensured, since entry to the critical section is scheduled according to
the timestamp ordering.
• The number of messages per critical-section entry is 2 × (n − 1).
This number is the minimum number of required messages per
critical-section entry when processes act independently and
concurrently.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Your company is building a computer network, and you are asked to develop a scheme
for dealing with the deadlock problem.
a. Would you use a deadlock-detection scheme or a deadlock- prevention scheme?
b. If you were to use a deadlock-prevention scheme, which one would you use?
Explain your choice.
c. If you were to use a deadlock-detection scheme, which one would you use? Explain
your choice.
Answer:
a. Would you use a deadlock-detection scheme, or a deadlock- prevention scheme?

Ans: We would choose deadlock prevention as it is systematically easier to prevent


deadlocks than to detect them once they have occurred.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


*. If you were to use a deadlock-prevention scheme, which one would
you use? Explain your choice.
A simple resource-ordering scheme would be used; preventing
deadlocks by requiring processes to acquire resources in order.

*. If you were to use a deadlock-detection scheme which one would


you use? Explain your choice.
If we were to use a deadlock detection algorithm, we would choose
a fully-distributed approach as the centralized approach provides for a
single point of failure.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Consider the centralized and the fully distributed approaches to dead- lock
detection. Compare the two algorithms in terms of message complexity.
Answer: The centralized algorithm for deadlock detection requires individual
processors or sites to report its local waits-for graph to a centralized manager. The
edges in the waits-for graph are combined and a cycle detection algorithm is performed
in the centralized man- ager. The cost of this algorithm is the cost of communicating the
various waits-for graph to the centralized server. In the distributed approach, each site
builds its own local waits-for graph and predicts whether there is a possibility of a cycle
based on local observations. If indeed there is a possibility of a cycle, a message is sent
along the various sites that might constitute a cyclic dependency. Multiple sites that are
potentially involved in the cyclic dependency could initiate this opera- tion
simultaneously. Therefore, the distributed algorithm is sometimes better than the
centralized algorithm and is sometimes worse than the centralized algorithm in terms of
message complexity. It is better than the centralized algorithm since it does not
communicate the entire local waits-for graph to the centralized server. (Also note that
that there could be performance bottlenecks due to the use of the centralized server in
the centralized algorithm.) However, the distributed algorithm could incur more
messages when multiple sites are simultaneously exploring the existence of a cyclic
dependency.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Derive an election algorithm for bidirectional rings that is more efficient
than any others. How many messages are needed for n processes?
Answer: The following algorithm requires O(n log n) messages. Each node
operates in phases and performs:
• If a node is still active, it sends its unique node identifier in both directions.
• In phase k, the tokens travel a distance of 2k and return back to their points
of origin.
• A token might not make it back to the originating node if it encounters a
node with a lower unique node identifier.
• A node makes it to the next phase only if it receives its tokens back from the
previous round.
The node with the lowest unique node identifies is the only that will be active
after log n phases.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


3(c)
The Linux 4.15.0 kernel can be built with no virtual memory system.
Explain how this feature may appeal to designers of real-time systems.
Answer: By disabling the virtual memory system, processes are
guaranteed to have portions of its address space resident in physical
memory. This results in a system that does not suffer from page faults
and therefore does not have to deal with unanticipated costs
corresponding to paging the address space. The resulting system is
appealing to designers of real-time systems who prefer to avoid
variability in performance.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Under what circumstances is the rate monotonic scheduling inferior to
earliest deadline first scheduling in meeting the deadlines associated
with processes?
Answer: Consider two processes P1 and P2 where p1 = 50, t1 = 25 and
p2 = 75, t2 = 30. If P1 were assigned a higher priority than P2 , then the
following scheduling events happen under rate monotonic scheduling.
P1 is scheduled at t = 0, P2 is scheduled at t = 25, P1 is scheduled at
t = 50, and P2 is scheduled at t = 75. P2 is not scheduled early enough
to meet its deadline. The earliest deadline schedule performs the following
scheduling events: P1 is scheduled at t = 0, P2 is scheduled at t = 25, P1 is
scheduled at t = 55, and so on. This schedule actually meets the deadlines
and therefore earliest deadline first scheduling is more effective than the rate
monotonic scheduler.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


interrupt 2(b)+
What are the various components of interrupt and dispatch latency?
Answer: The interrupt latency comprises of the time required to save
the state of the current process before invoking the specific interrupt
service handler. It therefore comprises of the following tasks:
determine the interrupt time, perform the context switch, and jump to
the appropriate ISR. The dispatch latency corresponds to the time
required to stop one process and start another process. It might
typically comprise of the following tasks: preemption of any process
running in the kernel, release of resources required by the process to
be scheduled, and the context switch cost corresponding to scheduling
the new process.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


interrupt
Explain why interrupt and dispatch latency times must be bounded
in a hard real-time system.
Answer: Interrupt latency is the period of time required to perform the
following tasks:
save the currently executing instruction, determine the type of interupt,
save the current process state, and then
invoke the appropriate interrupt service routine. Dispatch latency is the
cost associated with stopping one process and starting another.
Both interrupt and dispatch latency needs to be minimized in order to
ensure that real-time tasks receive immediate attention. Furthermore,
sometimes interrupts are disabled when kernel data structures are being
modified, so the interrupt does not get serviced immediately. For hard
real-time systems, the time-period for which interrupts are disabled must
be bounded in order to guarantee the desired quality of service.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Consider two processes, P1 and P2 , where p1 = 50, t1 = 25, p2 =
75, and t2 = 30.
a. Can these two processes be scheduled using rate monotonic
scheduling? Illustrate your answer using a Gantt chart.
b. Illustrate the scheduling of these two processes using earliest-
deadline-first (EDF) scheduling.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Answer: If P1 were assigned a higher priority than P2 , then
the following scheduling events happen under rate monotonic
scheduling.
P1 is scheduled at t = 0, P2 is scheduled at t = 25, P1 is scheduled
at t = 50, and P2 is scheduled at t = 75. P2 is not scheduled early
enough to meet its deadline. If P1 were assigned a lower priority than
P2 , then the following scheduling events happen under rate
monotonic scheduling. P2 is scheduled at t = 0, P1 is scheduled at t =
30, which is
not scheduled early enough to meet its deadline. The earliest deadline
schedule performs the following scheduling events: P1 is scheduled at
t = 0, P2 is scheduled at t = 25, P1 is scheduled at t = 55, and so on.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Consider the ring protection scheme in MULTICS. If we were to
implement the system calls of a typical operating system and store
them in a segment associated with ring 0, what should be the values
stored in the ring field of the segment descriptor? What happens
during a system call when a process executing in a higher-numbered
ring invokes a procedure in ring 0?
request deadline cylinder

R1 57 77
R2 300 95
R3 250 25
R4 88 28
R5 85 100
R6 110 90
R7 299 50
R8 300 77
R9 120 12
R10 212 2

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Answer: Batch 1 (, R4, R5, R1), batch 2 (R6, R9), and batch 3 (R2,
R3, R7, R8, R10). Within batch 1, requests are scheduled as: (R5, R1,
R4) Within batch 2, requests are scheduled as: (R9, R6) Within batch
3, requests are scheduled as: (R2, R8, R7, R3, R10)

Repeat the preceding question, but this time batch requests that have
deadlines occurring within 75 milliseconds of each other.
Answer: The batches are as follows: Batch 1: (R1), Batch 2: (R4, R5,
R6, R9), Batch 3: (R10), Batch 4: (R2, R3, R7, R8)

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


What operating principle is used by the CineBlitz system in performing
admission control for requests for media files?
Answer: Cineblitz differentiates clients into two classes: those that
require realtime service and those do not. The resources are allocated
such that a fraction of it is reserved for realtime clients and the rest are
allocated to non-realtime clients. Furthermore, when a client requires
realtime service enters the system, it is admitted into the system only if
there are sufficient resources to service the new client. In particular,
when a client makes a request, the system estimates the service time
for the request and the request is admitted only if the sum of the
estimated service times for all admitted requests does not exceed the
duration of service cycle T .

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


4(a)
Linux runs on a variety of hardware platforms. What steps must the
Linux developers take to ensure that the system is portable to different
processors and memory-management architectures, and to minimize
the amount of architecture-specific kernel code?
Answer: The organization of architecture-dependent and architecture-
independent code in the Linux kernel is designed to satisfy two design
goals: to keep as much code as
possible common between architectures and to provide a clean way of
defining architecture-specific properties and code. The solution must of
course be consistent with the overriding aims of code maintainability
and performance.
There are different levels of architecture dependence in the kernel, and
different techniques are appropriate in each case to comply with the
design requirements. These levels include:

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


CPU word size and endianness These are issues that affect
the porta- bility of all software written in C, but especially so for an
operating system, where the size and alignment of data must be
carefully arranged.
CPU process architecture Linux relies on many forms of hardware
support for its process and memory management. Different processors
have their own mechanisms for changing between protection domains
(e.g., entering kernel mode from user mode), rescheduling processes,
managing virtual memory, and handling incoming interrupts.
The Linux kernel source code is organized so as to allow as much of
the kernel as possible to be independent of the details of these
architecture- specific features. To this end, the kernel keeps not one
but two separate subdirectory hierarchies for each hardware
architecture. One contains the code that is appropriate only for that
architecture, including such functionality as the system call interface
and low-level interrupt management code.
Chowdhury Sajadul Islam-----------UU------------- CSEC-227
The second architecture-specific directory tree contains C header files that are
descriptive of the architecture. These header files contain type definitions and
macros designed to hide the differences between architectures. They provide
standard types for obtaining words of a given length, macro constants defining
such things as the architecture word size or page size, and function macros to
perform common tasks such as converting a word to a given byte-order or
doing standard manipulations to a page table entry.
Given these two architecture-specific subdirectory trees, a large portion of the
Linux kernel can be made portable between architectures. An attention to
detail is required: when a 32 bit integer is required, the programmer must use
the explicit int32 type rather than assume than an int is a given size, for
example. However, as long as the architecture specific header files are used,
then most process and page-table manipulation can be performed using
common code between the architectures.
Code that definitely cannot be shared is kept safely detached from the main
common kernel code.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


In Linux, shared libraries perform many operations central to the op- erating system.
What is the advantage of keeping this functionality out of the kernel? Are there any
drawbacks? Explain your answer. Answer: There are a number of reasons for
keeping functionality in shared libraries rather than in the kernel itself. These include:
Reliability. Kernel-mode programming is inherently higher risk than user-mode
programming. If the kernel is coded correctly so that protection between processes is
enforced, then an occurrence of a bug in a user-mode library is likely to affect only the
currently executing process, whereas a similar bug in the kernel could conceivably
bring down the entire operating system.
Performance. Keeping as much functionality as possible in user- mode shared
libraries helps performance in two ways. First of all, it reduces physical memory
consumption: kernel memory is non-pageable, so every kernel function is permanently
resident in physical memory, but a library function can be paged in from disk on
demand and does not need to be physically present all of the time. Although the library
function may be resident in many processes at once, page sharing by the virtual
memory system means that at most once it is only loaded into physical memory.
Second, calling a function in a loaded library is a very fast oper- ation, but calling a

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


kernel function through a kernel system ser- vice call is much more expensive.
Entering the kernel involves changing the CPU protection domain, and once in the
kernel, all of the arguments supplied by the process must be very care- fully checked
for correctness: the kernel cannot afford to make any assumptions about the validity of
the arguments passed in, whereas a library function might reasonably do so. Both of
these factors make calling a kernel function much slower than calling the same
function in a library.

Manageability. Many different shared libraries can be loaded by an application. If


new functionality is required in a running system, shared libraries to provide that
functionality can be installed without interrupting any already-running processes.
Similarly, existing shared libraries can generally be upgraded without re- quiring any
system down time. Unprivileged users can create shared libraries to be run by their
own programs. All of these attributes make shared libraries generally easier to manage
than kernel code.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


There are, however, a few disadvantages to having code in a shared library. There are
obvious examples of code which is completely un- suitable for implementation in a
library, including low-level function- ality such as device drivers or file-systems. In
general, services shared around the entire system are better implemented in the kernel
if they are performance-critical, since the alternative — running the shared service in a
separate process and communicating with it through interprocess communication —
requires two context switches for every service re- quested by a process. In some
cases, it may be appropriate to prototype a service in user-mode but implement the
final version as a kernel routine.
Security is also an issue. A shared library runs with the privileges of the process
calling the library. It cannot directly access any resources inaccessible to the calling
process, and the calling process has full access to all of the data structures maintained
by the shared library. If the service being provided requires any privileges outside of a
normal process’s, or if the data managed by the library needs to be protected from
normal user processes, then libraries are inappropriate and a separate server process (if
performance permits) or a kernel implementation is required.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


4(a)
The directory structure of a Linux operating system could comprise of
files corresponding to different file systems, including the Linux /proc
file system. What are the implications that arise from having to support
different file system types on the structure of the Linux kernel?
Answer: There are many implications to having to support different
file system types within the Linux kernel. For one thing, the file system
interface should be independent of the data layouts and data
structures used within the file system to store file data. For another
thing, it might have to provide interfaces to file systems where the file
data is not static data and is not even stored on the disk; instead, the
file data could be computed every time an operation is invoked to
access it as is the case with the /proc file system. These call for a fairly
general virtual interface to sit on top of the different file systems.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


In what ways does the Linux setuid feature differ from the setuid
feature in standard Unix?
Answer: Linux augments the standard setuid feature in two ways.
First, it allows a program to drop and reacquire its effective uid
repeatedly. In order to minimize the amount of time that a program
executes with all of its privileges, a program might drop to a lower
privilege lower-level. However, when it needs to perform privileged
operations, it can switch to its effective uid.

Second, Linux allows a process to take on only a subset of the rights


of the effective uid. For instance, an user can use a process that
serves files without having control over the process in terms of being
able to kill or suspend the process.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


4(b)
Describe the management scheme of the virtual memory
manager. How does the VM manager improve performance?
Answer: The VM Manager uses a page based management scheme.
Pages of data allocated to a process that are not in physical memory
are stored in either paging files on disk or mapped to a regular file on a
local or remote file system. To improve performance of this scheme, a
privileged process is allowed to lock selected pages in physical
memory preventing those pages from being paged out. Furthermore,
since when a page is used, adjacent pages will likely be used in the
near future, adjacent pages are prefetched to reduce the total number
of page faults.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


What is the purpose of the Windows16 execution environment? What limitations
are imposed on the programs executing inside this environment? What are the
protection guarantees provided between different applications executing inside
the Windows16 environment? What are the protection guarantees provided
between an application executing inside the Windows16 environment and a 32-bit
application?
Answer: Windows 16 execution environment provides a virtual envi- ronment for
executing 16-bit applications that use the Window 3.1 kernel interface. The
interface is supported in software using stub routines that call the appropriate
Win32 API subroutines by converting 16-bit addresses into 32-bit addresses. This
allows the system to run legacy applications. The environment can multitask with
other processes on Windows XP. It can contain multiple Windows16 applications,
but all applications share the same address space and the same input queue.
Also one can execute only one Windows16 application at a given point in time. A
Windows16 application can therefore crash other Windows16 applications by
corrupting the address space but they cannot corrupt the address spaces of
Win32 applications. Multiple Windows16 execu- tion environments could also
coexist.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Describe two user-mode processes that Windows provides to enable it
to run programs developed for other operating systems.
Answer: Environmental subsystems are user-mode processes
layered over the native executable services to enable Windows XP to
run programs developed for other operating systems. (1) A Win32
application called the virtual DOS machine (VDM) is provided as a
user-mode process to run MSDOS applications. The VDM can execute
or emulate Intel 486 instructions and also provides routines to emulate
MSDOS BIOS services and provides virtual drivers for screen,
keyboard, and communication ports. (2) Windows-on-windows
(WOW32) provides kernel and stub routines for Windows 3.1
functions. The stub routines call the appropriate Win32 subroutines,
converting the 16-bit addresses into 32-bit addresses.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


How does the NTFS directory structure differ from the directory
structure used in Unix operating systems?
Answer: The NTFS namespace is organized as a hierarchy of direc-
tories where each directory uses a B+ tree data structure to store an
index of the filenames in that directory. The index root of a directory
contains the top level of the B+ tree. Each entry in the directory
contains the name and file reference of the file as well as the update
timestamp and file size. The Unix operating system simply stores a
table of entries mapping names to i-node numbers in a directory file.
Lookups and updates require a linear scan of the directory structure in
Unix systems.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


What were the various optimizations used to minimize the discrepancy
between CPU and I/O speeds on early computer systems?
Answer: An optimization used to minimize the discrepancy between
CPU and I/O speeds is spooling. Spooling overlaps the I/O of one job
with the computation of other jobs. The spooler for instance could be
reading the input of one job while printing the output of a different job
or while executing another job.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


Chowdhury Sajadul Islam-----------UU------------- CSEC-227
Consider the multilevel feedback queue used by CTSS and
Multics. Consider a program that consistently uses 7 time units
every time it is scheduled before it performs an I/O operation and
blocks. How many time units are allocated to this program when
it is scheduled for execution at different points of time?
Answer: Assume that the process is initially scheduled for one time
unit. Since the process does not finish by the end of the time quantum,
it is moved to a lower level queue and its time quantum is raised to
two time units. This process continues till it is moved to a level 4 queue
with a time quantum of 8 time units. In certain multilevel systems,
when the process executes next and does not use its full time
quantum, the process might be moved back to a level 3 queue.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


What are the implications of supporting BSD functionality in user
mode servers within the Mach operating system?
Answer: Mach operating system supports the BSD functionality in
user mode servers. When the user process makes a BSD call, it traps
into kernel mode and the kernel copies the arguments to the user level
server. A context switch is then made and the user level performs the
requested operation and computes the results which are then copied
back to the kernel space. Another context switch takes place to the
original process which is in kernel mode and the process eventually
transitions from kernel mode to user mode along with the results of the
BSD call. Therefore, in order to perform the BSD call, there are two
kernel crossings and two process switches thereby resulting in a large
overhead. This is significantly higher than the cost if the BSD
functionality is supported within the kernel.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


I/O Operation5(a)
Consider the following I/O scenarios on a single-user PC.
*. A mouse used with a graphical user interface
*. A tape drive on a multitasking operating system (assume no device
pre-allocation is available)
*. A disk drive containing user files
*. A graphics card with direct bus connection, accessible through
memory-mapped I/O

For each of these I/O scenarios, would you design the operating system
to use buffering, spooling, caching, or a combination? Would you use
polled I/O, or interrupt-driven I/O? Give reasons for your choices.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


I/O Operation
*. A mouse used with a graphical user interface.
Buffering may be needed to record mouse movement during times when higher-priority
operations are taking place.
Spooling and caching are inappropriate.
Interrupt driven I/O is most appropriate.
*. A tape drive on a multitasking operating system (assume no device pre-allocation
is available).
Buffering may be needed to manage throughput difference between the tape drive and
the source or destination of the I/O,
Caching can be used to hold copies of data that resides on the tape, for faster access.
Spooling could be used to stage data to the device when multiple users desire to read
from or write to it.
Interrupt driven I/O is likely to allow the best performance.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


I/O Operation
*. A disk drive containing user files.
Buffering can be used to hold data while in transit from user space to the disk, and visa
versa.
Caching can be used to hold disk-resident data for improved performance.
Spooling is not necessary because disks are shared-access devices.
Interrupt-driven I/O is best for devices such as disks that transfer data at slow rates.
*. A graphics card with direct bus connection, accessible through memory-mapped
I/O.
Buffering may be needed to control multiple access and for performance (double-
buffering can be used to hold the next screen image while displaying the current one).
Caching and spooling are not necessary due to the fast and shared-access natures of the
device.
Polling and interrupts are only useful for input and for I/O completion detection,
neither of which is needed for a memory-mapped device.

Chowdhury Sajadul Islam-----------UU------------- CSEC-227


I/O blocking & nonblocking
Generally, blocking I/O is appropriate when the process will only be waiting
for one specific event. Examples include a disk, tape, or keyboard read by an
application program.
Non-blocking I/O is useful when I/O may come from more than one source
and the order of the I/O arrival is not predetermined. Examples include
network daemons listening to more than one network socket, window
managers that accept mouse movement as well as keyboard input, and I/O-
management programs, such as a copy command that copies data between I/O
devices.
In the last case, the program could optimize its performance by buffering the
input and output and using non-blocking I/O to keep both devices fully
occupied.
Non-blocking I/O is more complicated for programmers, because of the
asynchonous meeting that is needed when an I/O occurs. Also, busy waiting is
less efficient than interrupt-driven I/O, so the overall system performance
would decrease.
Chowdhury Sajadul Islam-----------UU------------- CSEC-227

You might also like