Resource Sharing and Management:Need for Scheduling and Mutual Exclusion.

Module 6: Resource Sharing and Management

The main motivation for scheduling various OS services is to maximize the usage of CPU resource, memory, and other IO resources. Consider the usage of a printer as an output resource. A user takes printouts only once in a while. A printer usage, therefore, can be shared amongst many users. The motivation to share a resource may come from several reasons. Sharing enhances utilization of resources immensely.

Sharing a resource is imperative in cases where we have a very expensive and specialized resource. For instance, an image processing resource, connected to a computer system, is a special resource. Such a resource is used in short periods of time, i.e. it is sparingly used. Similarly, in the context of a large project, there may be a file or a data-base which is shared amongst many users. Such a shared file may need to be updated from several sources. The shared file is then a shared resource. In this case, the sequencing of updates may be very critical for preserving data integrity and consistency. It may affect temporal semantics of the shared data. This is particularly true in transaction processing systems. In this chapter we shall study how the resources may be scheduled for shared usage. In particular, we shall study two very important concepts relating to mutual exclusion and deadlocks.

6.1 Need for Scheduling

Resources may be categorized depending upon the nature of their use. To enforce temporal sharing of a common resource, the OS needs a policy to schedule its usage. The policy may depend upon the nature of resource, frequency of its use and the context of its usage. In the case of a printer, the OS can spool printout requests. Printing, additionally, requires that once a process is engaged in printing, it must have its exclusive usage till it finishes the current print job. If that is not the case then the printouts from the printer shall be garbled. Some specialized resources, like a flat-bed plotter, require an elaborate initial set-up. So once assigned to a process, its usage better not be pre-empted. A process that gets such a resource should be permitted to keep it till either the process terminates or releases the resource. This is also true of a transaction which updates a shared data record. The transaction should complete the record's update before another process is given the access to the record.

Processes may need more than one resource. It is quite possible that a process may not be able to progress till it gets all the resources it needs. Let us suppose that a process P1 needs resources r1 and r2. Process P2 needs resources r2 and r3. Process P1 can proceed only when it has both r1 and r2. If process P2 has been granted r2 then process P1 has to wait till process P2 terminates or releases r2. Clearly, the resource allocation policy of an OS can affect the overall throughput of a system.

6.2 Mutual Exclusion

The mutual exclusion is required in many situations in OS resource allocation. We shall portray one such situation in the context of management of a print request. The print process usually maintains a queue of print jobs. This is done by maintaining a queue of pointers to the files that need to be printed. Processes that need to print a file store the file address (a file pointer) into this queue. The printer spooler process picks up a file address from this queue to print files. The spooler queue is a shared data structure amongst processes that are seeking the printer services and the printer spooler process. The printer spooler stores and manages the queue as shown in Figure 6.1. Let us consider just two

clip_image001

Figure 6.1: An example of mutual exclusion.

processes Pi, Pj that need to use printer. Let Ps denote the printer spooler process. The shared queue data area is denoted by Q. Let us now envision the situation as depicted below:

  • Pi accesses Q and finds that a certain slot qs is free.
  • Pi decides to copy in this area the address of the file it needs to print.
  • Next Pj accesses Q and also finds the slot qs is free.
  • Pj decides to copy in this area the address of file it needs to print.
  • Pi copies the address of the area from which a file needs to be printed.
  • Next Pj copies the address of the area from which a file needs to be printed.
  • Ps reaches the slot at qs and prints the file pointed to by the address in qs.

On examining the above sequence we find that both the processes Pi, and Pj may record that their print jobs are spooled. As a matter of fact only the job from Pj was spooled. The print job of Pi never gets done. If we had mutual exclusion then either process Pi or process Pj , but not both, could have had an access to qs . A point to be noted here is that Q is a shared data area (a resource) used by three processes Pi, Pj , and Ps. It also establishes an inter-process communication (IPC) between processes that need printing and the process which prints. Access to shared data resource that establishes inter-process communication must be mutually exclusive. We shall later revisit mutual exclusion in more detail in Section 6.5. There we shall discuss how to ensure mutually exclusive access to resources. For now let us examine the conditions for deadlocks.

Comments

Popular posts from this blog

Input Output (IO) Management:HW/SW Interface and Management of Buffers.

Introduction to Operating Systems:Early History: The 1940s and 1950s

Input Output (IO) Management:IO Organization.