OS Chap 6, OS Chap 7, OS Chap 8, OS Chap 9 & 10, OS Chap 11
What is demand paging?
Demand paging is a page fetch policy in which a page is brought into main memory only when it is referenced, i.e., pages loaded only when they are demanded during program execution. Pages not accessed are never brought into main memory.
Define FIFO, SSTF, SCAN, C-SCAN
FIFO: Items are processed from the queue in sequential first-come-first-served order. SSTF: Select the disk I/O request that requires the least movement of the disk arm from its current position. SCAN: The disk arm moves in one direction only, satisfying all outstanding requests enroute, until it reaches the last track in that direction (end of disk). The service direction is then reversed and the scan proceeds in the opposite direction, again picking up all requests in order. C-SCAN: Similar to SCAN, but restricts scanning to one direction only. Thus, when the last track has been visited in one direction, the arm is returned to the opposite end of the disk and the scan begins again.
What are some reasons to allow two or more processes to all have access to a particular region of memory?
If a number of processes are executing the same program, it is advantageous to allow each process to access the same copy of the program rather than have its own separate copy. Also, processes that are cooperating on some task may need to share access to the same data structure.
Discuss the concept of dynamic scheduling
In dynamic scheduling, the scheduling decisions are made at run-time, thus permitting the number of threads in the process to be altered dynamically. The scheduling responsibility of the OS is primarily limited to processor allocation, and it proceeds according to the following policy: When a job requests processors, 1. If there are idle processors, use them to satisfy the request. 2. If the job that is making the request is a new arrival, allocate it a single processor by taking one away from any job currently allocated more than one processor. 3. If any portion of the request cannot be satisfied, it remains outstanding until either a processor becomes available for it or the job rescinds the request. Upon release of one or more processors (including job departures), 1. Scan the current queue of unsatisfied requests for processors. 2. Assign a single processor to each job in the list that currently has no processors. 3. Then scan the list again, allocating the rest of the processors on an FCFS basis
If purely priority-based scheduling is used in a system, what are the problems that the system will face?
In pure priority-based scheduling algorithms, a process with a higher priority is always selected at the expense of a lower-priority process. The problem with a pure priority scheduling scheme is that lower-priority processes may suffer starvation. This will happen if there is always a steady supply of higher-priority ready processes. If the scheduling is non-pre-emptive, a lower priority process will run to completion if it gets the CPU. However, in pre-emptive schemes, a lower priority process may have to wait indefinitely in the ready or suspended queue.
What is the difference between internal and external fragmentation?
Internal fragmentation refers to the wasted space internal to a partition due to the fact that the block of data loaded is smaller than the partition. External fragmentation is a phenomenon associated with dynamic partitioning and refers to the fact that a large number of small areas of main memory external to any partition accumulates.
Why can't you disallow mutual exclusion in order to prevent deadlocks?
Mutual exclusion restricts the usage of a resource to one user at a time. If mutual exclusion is disallowed, then all non-sharable resources become sharable. While this may not hamper some activities (like a read-only file being accessed by a number of users), it poses serious problems for activities that require non-sharable resources (like writing to a file). Preventing mutual exclusion in these situations gives undesirable results. Also, there are some resources (like printers) that are inherently non-sharable, and it is impossible to disallow mutual exclusion. Thus, in general, mutual exclusion cannot be disallowed for practical purposes.
What are the three conditions that must be present for deadlock to be possible?
Mutual exclusion. Only one process may use a resource at a time. Hold and wait. A process may hold allocated resources while awaiting assignment of others. No preemption. No resource can be forcibly removed from a process holding it.
What are the four conditions that create deadlock?
Mutual exclusion: Only one process may use a resource at a time. Hold and wait: A process may hold allocated resources while awaiting assignment of others. No preemption: No resource can be forcibly removed from a process holding it Circular wait: A closed chain of processes exists, such that each process holds at least one resource needed by the next process in the chain
List and briefly define three techniques for performing I/O.
Programmed I/O: The processor issues an I/O command, on behalf of a process, to an I/O module; that process then busy-waits for the operation to be completed before proceeding. Interrupt-driven I/O: The processor issues an I/O command on behalf of a process, continues to execute subsequent instructions, and is interrupted by the I/O module when the latter has completed its work. The subsequent instructions may be in the same process, if it is not necessary for that process to wait for the completion of the I/O. Otherwise, the process is suspended pending the interrupt and other work is performed. Direct memory access (DMA): A DMA module controls the exchange of data between main memory and an I/O module. The processor sends a request for the transfer of a block of data to the DMA module and is interrupted only after the entire block has been transferred.
What requirements is memory management intended to satisfy?
Relocation, protection, sharing, logical organisation, physical organisation.
Briefly define shortest-process-next scheduling.
SPN is a non-pre-emptive policy in which the process with the shortest expected processing time is selected next.
Briefly define shortest-remaining-time scheduling.
SRT is a pre-emptive version of shortest-process-next (SPN). In this case, the scheduler always chooses the process that has the shortest expected remaining processing time. When a new process joins the ready queue, it may in fact have a shorter remaining time than the currently running process. Accordingly, the scheduler may pre-empt whenever a new process becomes ready
Briefly define feedback scheduling
Scheduling is pre-emptive (on time quantum) basis, and a dynamic priority mechanism is used. When a process first enters the system, it is placed in RQ0 (see Figure 9.4 of textbook or Slides). After its first execution, when it returns to the Ready state, it is placed in RQ1. Each subsequent time that it is pre-empted, it is demoted to the next lower priority queue. A shorter process will complete quickly, without migrating very far down the hierarchy of ready queues. A longer process will gradually drift downward. Thus, newer, shorter processes are favoured over older, longer processes. Within each queue, except the lowestpriority queue, a simple FCFS mechanism is used. Once in the lowest-priority queue, a process cannot go lower, but is returned to this queue repeatedly until it completes execution.
List some of the methods that may be adopted to recover from deadlocks.
Some methods to recover from deadlocks are: a. Abort all deadlocked processes. Though this is a common solution adopted in operating systems, the overhead is very high in this case. b. Back up each deadlocked process to some previously defined checkpoint and restart all processes. c. Detect the deadlocked processes in a circular-wait condition. Successively abort deadlocked processes until the circular wait is eliminated and the deadlock no longer exists. d. Successively preempt resources until the deadlock no longer exists
What are the advantages of organising programs and data into modules?
Some of the advantages of organising programs and data into modules are: 1. Modules can be written and compiled independently. All references from one module to another can be resolved by the system at run time. 2. Each module can be given different degrees of protection (like read only, read-write, execute only, read-write-execute, etc.). The overhead associated with this is quite nominal. 3. A module can be shared among different processes by incorporating appropriate mechanisms.
List and briefly define five different categories of synchronisation granularity
1. Fine: Parallelism inherent in a single instruction stream 2. Medium: Parallel processing or multitasking within a single application 3. Coarse: Multiprocessing of concurrent processes in a multiprogramming environment 4. Very Coarse: Distributed processing across network nodes to form a single computing environment 5. Independent: Multiple unrelated processes
What scheduling criteria affect the performance of a system?
1. Turnaround Time: 2. Response Time: 3. Waiting Time: 4. Deadlines: 5. Throughput: 6. Processor utilisation:
Briefly define FCFS (First Come First Served) scheduling.
As each process becomes ready, it joins the ready queue. When the currently-running process ceases to execute, the process that has been in the ready queue the longest is selected for running. Non-pre-emptive
What is the difference between block-oriented devices and stream-oriented devices? Give a few examples of each.
Block-oriented devices store information in blocks that are usually of fixed size, and transfers are made one block at a time. Generally, it is possible to reference data by its block number. Disks and tapes are examples of block-oriented devices. Stream-oriented devices transfer data in and out as a stream of bytes, with no block structure. Terminals, printers, communications ports, mouse and other pointing devices, and most other devices that are not secondary storage are stream oriented.
What are the drawbacks of using either only a pre-cleaning policy or only a demand cleaning policy?
Cleaning refers to determining when a modified page should be written out to secondary memory. Two common cleaning policies are demand cleaning and pre-cleaning. There are problems with using either of the two policies exclusively. This is because, on the one hand, pre-cleaning involves a page being written out but remaining in the main memory until the page replacement algorithm dictates that it can be removed. Therefore, while precleaning allows the writing of pages in batches, it makes little sense to write out hundreds or thousands of pages only to find that the majority of them have been modified again before they are replaced. The transfer capacity of secondary memory is limited in this method; it is wasted in unnecessary cleaning operations. On the other hand, with demand cleaning, the writing of a dirty page is coupled to, and precedes, the reading in of a new page. This technique may minimise page writes, but it results in the fact that a process that suffers a page fault may have to wait for two-page transfers before it can be unblocked. This may decrease processor utilisation
What grain size of parallelism is appropriate for a multiprogrammed uniprocessor?
Coarse grained or very coarse grained parallelisms are appropriate for a multiprogrammed uniprocessor. In this situation the synchronisation between processes is at a very gross level. Thus, it can easily be handled as a set of concurrent processes whose interaction among themselves is limited. The processes get CPU time in the uniprocessor system in accordance with any scheduling algorithm they might use.
What is a Linux Elevator? Point out some problems associated with it
The Linux Elevator is the default disk scheduler in Linux 2.4. It maintains a single queue for disk read and write requests, and it performs both sorting and merging functions on the queue. To put it simply, it keeps the list of requests sorted by block number. Thus, the drive moves in a single direction as the disk requests are handled, satisfying each request as it is encountered. The elevator scheme has two problems: (1) A distant block request can be delayed for a substantial time because the queue is dynamically updated. (2) A stream of write requests (e.g., to place a large file on the disk) can block a read request for a considerable time and thus block a process. Typically, a write request is issued asynchronously. That is, once a process issues the write request, it need not wait for the request to be satisfied. When an application issues a write, the kernel copies the data into an appropriate buffer, to be written out as time permits. Once the data are captured in the kernel's buffer, the application can proceed. Hence, for a read operation, the process must wait until the requested data are delivered to the application before proceeding.
What is the difference between demand cleaning and pre-cleaning?
With demand cleaning, a page is written out to secondary memory only when it has been selected for replacement. A pre-cleaning policy writes modified pages before their page frames are needed so that pages can be written out in batches.
State some utilities of buffering.
a. Buffering smooths peaks in I/O demand. b. It alleviates the differences in coordination that may crop up due to a disparity in the speeds of the producer and the consumer of a data stream. c. Buffering adapts devices that have different data-transfer sizes to transfer data among themselves
Which considerations determine the size of a page?
a. Page size versus page table size b. Page size versus TLB usage c. Internal fragmentation of pages d. Page size versus disk access
Briefly define round-robin scheduling.
A clock interrupt is generated at periodic intervals. When the interrupt occurs, the currently running process is placed in the ready queue, and the next ready job is selected on a FCFS basis. Pre-emptive
What is the main function of a dispatcher? Give some examples of events when it is invoked.
A dispatcher, or a short-term scheduler, allocates processes in the ready queue to the CPU for immediate processing. It makes the fine-grained decision of which process to execute next. It has to work very frequently since, generally, a process is executed in the CPU for a very short interval. The dispatcher is invoked whenever an event that may lead to the blocking of the current process occurs. It is also invoked when an event that may provide an opportunity to preempt a currently running process in favour of another occurs. Examples of such events include clock interrupts, I/O interrupts, operating system calls, and signals (e.g., semaphores).
Identify the advantages and disadvantages of pre-emptive scheduling.
Advantages: 1. It ensures fairness to all processes regardless of their priority in most cases. 2. It reduces the monopolisation of the CPU by a large process. 3. It increases the scheduling capacity of the system. 4. Depending on the CPU time the process needs, it also gives a quick response time for processes. Disadvantages: 1. Pre-emption is associated with extra overhead due to increased contextswitch, increased caching, increased bus-related costs etc. 2. Pre-emptive scheduling results in increased dispatcher activities and, subsequently, more time for dispatching.
Why is the principle of locality crucial to the use of virtual memory?
Algorithms can be designed to exploit the principle of locality to avoid thrashing. In general,the principle of locality allows algorithms to predict which resident pages are least likely to be referenced in the near future and are therefore good candidates for being swapped out.
What is the difference between a page and a segment?
An alternative way in which the user program can be subdivided is segmentation. In this case, the program and its associated data are divided into a number of segments. It is required that all segments of all programs be of the same length, although there is a maximum segment length.
In a fixed-partitioning scheme, what are the advantages of using unequal-size partitions?
By using unequal-size fixed partitions: 1. It is possible to provide one or two quite large partitions and still have a large number of partitions. The large partitions can allow the entire loading of large programs. 2. Internal fragmentation is reduced because a small program can be put into a small partition.
How can the hold-and-wait condition be prevented?
Can be prevented by making a process request all its required resources at one time and blocking until all requests can be granted simultaneously. Inefficient in a few ways: 1) A process may be held up for a long time waiting for all of its resource requests to be filled, when it could have proceeded with only some of the resources 2) Resources allocated to a process may be unused for a long time, denying access to other processes. 3) Process may not know in advance what resources will be required 4) With modular programming or a multithreaded structure, an application would need to be aware of all resources that will be requested at all levels or in all modules to make simultaneous requests
Why would you expect improved performance using a double buffer rather than a single buffer for I/O?
Double buffering allows two operations to proceed in parallel rather than in sequence. Specifically, a process can transfer data to (or from) one buffer while the operating system empties (or fills) the other.
Give examples of reusable and consumable resources.
Examples of reusable resources are processors, I/O channels, main and secondary memory, devices, and data structures such as files, databases, and semaphores. Examples of consumable resources are interrupts, signals, messages, and information in I/O buffers
For which kinds of applications is gang scheduling of threads most useful?
Gang scheduling is most useful for medium-grained to fine-grained parallel applications whose performance severely degrades when any part of the application is not running while other parts are ready to run. It is also beneficial for any parallel application, even one that is not performance sensitive.
What is the difference between a page and a frame?
In a paging system, programs and data stored on disk or divided into equal, fixed-sized blocks called pages, and main memory is divided into blocks of the same size called frames. Exactly one page can fit in one frame
How is processor scheduling done in the batch portion of an OS?
Processor scheduling in a batch system, or in the batch portion of an OS, is done by a longterm scheduler. Newly submitted jobs are routed to disk and held in a batch queue from which the long-term scheduler creates processes and then places these in the ready queue so that they can be executed.
What is the purpose of a translation lookaside buffer?
The TLB is a cache that contains those page table entries that have been most recently used. Its purpose is to reduce the need to go to disk to retrieve a page table entry
How can the circular-wait condition be prevented?
The circular-wait condition can be prevented by defining a linear ordering of resource types. If a process has been allocated resources of type R, then it may subsequently request only those resources of types following R in the ordering.
What are the differences between a blocking I/O and a non-blocking I/O?
The differences between the two can be explained as follows: If the I/O instruction is blocking, then the next instruction that the processor executes is from the OS, which will put the current process in a blocked state and schedule another process. On the other hand, if the I/O instruction from the process is non-blocking, then the processor continues to execute instructions from the process that issued the I/O command.
What is the difference between a resident set and a working set?
The resident set of a process is the current number of pages of that process in main memory. The working set of a process is the number of pages of that process that have been referenced over a specified time window.
How does the use of virtual memory improve system utilisation?
The use of virtual memory improves system utilisation in the following ways: a. More processes may be maintained in main memory: The use of virtual memory allows the loading of only portions of a process into the main memory. Therefore, more processes can enter the system, thus resulting in higher CPU utilisation. b. A process may be larger than all of main memory: The use of virtual memory theoretically allows a process to be as large as the disk storage available, however, there will be system constraints (such as address space) that will limit the size
Explain thrashing.
Thrashing is a phenomenon in virtual memory schemes, in which the processor spends most of its time swapping pieces rather than executing instructions.
What is relocation of a program?
To relocate a program is to load and execute a given program to an arbitrary place in the memory; therefore, once a program is swapped out to the disk, it may be swapped back anywhere in the main memory.
Briefly define highest-response-ratio-next scheduling.
When the current process completes or is blocked, choose the ready process with the greatest value of R, where R = (w + s)/s, with w = time spent waiting for the processor and s = expected service time. Favours short processes, long processes increase R (by increasing w) over time, and so avoid starvation. Non-pre-emptive