Page 159 - DCAP103_Principle of operating system
P. 159

Principles of Operating Systems



                   Notes         A variant of this swapping policy is used for priority-based scheduling algorithms. If a higher-
                                 priority process arrives and wants service, the memory manager can swap out the lower-priority
                                 process so that it can load and execute the higher-priority process. When the higher-priority
                                 process finishes, the lower-priority process can be swapped back in and continued. This variant
                                 of swapping is sometimes called roll out, roll in.
                                 Normally a process that is swapped out will be swapped back into the same memory space
                                 that it occupied previously. This restriction is dictated by the method of address binding.
                                 If  binding  is  done  at  assembly  or  load  time,  then  the  process  cannot  be  moved  to  different
                                 locations. If execution-time binding is being used, then a process can be swapped into a different
                                 memory space, because the physical addresses are computed during execution time. Swapping
                                 requires a backing store. The backing store is commonly a fast disk. It must be large enough to
                                 accommodate copies of all memory images for all users, and it must provide direct access to
                                 these memory images. The system maintains a ready queue consisting of all processes whose
                                 memory images are on the backing store or in memory and are ready to run. Whenever the
                                 CPU scheduler decides to execute a process, it calls the dispatcher. The dispatcher checks to see
                                 whether the next process in the queue is in memory. If not, and there is no free memory region,
                                 the dispatcher swaps out a process currently in memory and swaps in the desired process. It
                                 then reloads registers as normal and transfers control to the selected process.
                                 The context-switch time in such a swapping system is fairly high. To get an idea of the context-
                                 switch time, let us assume that the user process is of size 1MB and the backing store is a standard
                                 hard disk with a transfer rate of 5 MB per second. The actual transfer of the 1 MB process to or
                                 from memory takes 1000 KB/5000 KB per second = 1 /5 second = 200 milliseconds.
                                 Assuming that no head seeks are necessary and an average latency of 8 milliseconds, the swap
                                 time takes 208 milliseconds. Since we must both swap out and swap in, the total swap time is
                                 then about 416 milliseconds. For efficient CPU utilization, we want our execution time for each
                                 process to be long relative to the swap time. Thus, in a round-robin CPU-scheduling algorithm,
                                 for example, the time quantum should be substantially larger than 0.416 seconds. Notice that the
                                 major part of the swap time is transfer time. The total transfer time is directly proportional to
                                 the amount of memory swapped. If we have a computer system with 128 MB of main memory
                                 and a resident operating system taking 5 MB, the maximum size of the user process is 123 MB.
                                 However, many user processes may be much smaller than this size-say, 1 MB. A 1 MB process
                                 could be swapped out in 208 milliseconds, compared to the 24.6 seconds for swapping 123 MB.
                                 Therefore, it would be useful to know exactly how much memory a user process is using, not
                                 simply how much it might be using. Then, we would need to swap only what is actually used,
                                 reducing swap time. For this method to be effective, the user must keep the system informed
                                 of any changes in memory requirements. Thus, a process with dynamic memory requirements
                                 will need to issue system calls (request memory and release memory) to inform the operating
                                 system of its changing memory needs.

                                 Swapping is constrained by other factors as well. If we want to swap a process, we must be sure
                                 that it is completely idle. Of particular concern is any pending I/O. A process may be waiting
                                 for an I/O operation when we want to swap that process to free up its memory. However, if the
                                 1/0 is asynchronously accessing the user memory for I/O buffers, then the process cannot be
                                 swapped. Assume that the 1/0 operation was queued because the device was busy. Then, if we
                                 were to swap out process PI and swap in process P2, the I/O operation might then attempt to
                                 use memory that now belongs to process P2. The two main solutions to this problem are never
                                 to swap a process with pending I/O, or to execute 1/0 operations only into operating-system
                                 buffers. Transfers between operating-system buffers and process memory then occur only when
                                 the process is swapped in. The assumption that swapping requires few, if any, head seeks needs
                                 further explanation. We postpone discussing this issue until where secondary-storage structure
                                 is covered. Generally, swap space is allocated as a chunk of disk, separate from the file system,
                                 so that its use is as fast as possible. Currently, standard swapping is used in few systems. It
                                 requires  too  much  swapping  time  and  provides  too  little  execution  time  to  be  a  reasonable




        152                               LOVELY PROFESSIONAL UNIVERSITY
   154   155   156   157   158   159   160   161   162   163   164