Homework Assignment #2

Sample Solutions

 

Problem 9.5

a.        First-fit:

a.        212K put in 500K partition

b.       417K put in 600K partition

c.        112K put in 288K partition (new partition 500K-212K=288K)

d.       426K must wait

 

b.       Best-fit

a.        212K put in 300K partition

b.       417K put in 500K partition

c.        112K put in 200K partition

d.       426K put in 600K partition

 

c.        Worst-fit

a.        212K put in 600K partition

b.       417K put in 500K partition

c.        112K put in 388K partition (600K – 212K = 388K)

d.       426K must wait

 

In this example, Best-fit is turns out to be the best.

 

Problem 9.9

            On a system with paging, a process cannot access memory it does not own because it can only access memory contained in its page table.  Since the page table only contains memory owned by that process, it would be impossible with this method to access anything but owned memory.  It could allow access to nonowned memory by creating a "global" page table which contains each page in memory and a reference to who owns it.  Thus, a process COULD look up memory other than that it owns.  however, this would be a bad practice because it would allow one process to modify the memory of another process which would go against the security principles of the operating system.

Problem 9.10:

a.        400 nanoseconds (200 to access page table and 200 to access word in memory)

b.       Effective access time = 0.75 x (200 ns) + 0.25 x (400 ns) = 250 ns

 

Problem 9.16:

a.        219 + 430 = 649

b.       2300 + 10 = 2310

c.        illegal reference, trap to operating system

d.       1327 + 400 = 1727

e.        illegal reference, trap to operating system

Problem 10.4

        The concept of "good" is highly opinionated.  However, it is a pretty safe argument that for a programming method to be "good" as far as demaind-paging is concerned, it must exhibit "locality of reference" (LOR)

        a)  good.  Stacks tend to have reasonable LOR and are, in fact, used in a page replacement algorithm sometimes.

        b)  Bad.  These would have horrible LOR.

        c)  Good.  We definitely are maintaining LOR.

        d)  Variable, probably bad.  Depends on the size of the search space.

        e)  Good.  Most code is going to maintain LOR.

        f)   Good.  While several frames are needed (one for the vector table and one or more for the routines) most service routines would exhibit good LOR (and are often stored in a low-level, contiguous chunk of memory).

        g)  Bad.  Obviously, this has poor LOR.  References are everywhere.

 

 

Problem 10.5

        EAT=(1-p)*MA + p*pft

 

        200>(1-p)*100+p*pft        pft = .7*20 + .3*8 milliseconds

                                                       = 16.4 milliseconds

                                                        =  16,400,000 nanoseconds

        200>(1-p)*100+p*1640000

            p<0.000006 or less than one fault every 163999 accesses

 

Problem 10.11

 

  1 2 3 4 5 6 7
LRU 20 18 15 10 8 7 7
FIFO 20 18 16 14 10 10 7
OPT 20 15 11 8 7 7 7

 

Problem 11.1

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 also deleted. This can be accomplished in several ways

Problem 11.8

        Automatic opening and closing of files relieves the user from the invocation of these functions, and thus makes it more convenient to the user;  however, it requires more overhead than the case where explicit opening and closing is required.

 

Problem 11.13

This is probably the hardest question on the homework. There is much you can say about access lists and about user control lists, but "Discuss the relative merits ..." is harder.

Access list: Who can access this file?

User control list: What can this user do?

Criteria:

Operations:

Both are essentially the same in many ways. Both Windows and Unix use access lists with very coarse groupings of users, so we have been trained to say that is the right answer. I rather prefer grouping users as owner, group, world to the alternative of grouping files as mine, yours, system. Hence, I tend to prefer the access list approach.

Problem 11.14

The key word in this problem is DISK I/O.  Updating pointers in local memory does not require disk I/O.
                               

  Contiguous Linked Indexed

a.               

201                  

1                     

1

b. (1)             

101                 

52                    

1

c.                 

1                      

2                    

1

d.               

198                   

1                     

0

e. (2)                

98                   

52                   

0

f.                   

0                   

100                  

0

(1) Assuming you are entering between the 50th and 51st block.

(2) Assuming you are deleting the 51st block
 

Problem 12.2

a. 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.
    b. A tape drive on a multitasking operating system (assume no device preallocation 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.
    c. 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.
    d. 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.

 

Problem 12.4

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 rendezvous 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.

 

Problem 12.6

A pure polling environment would be used in an environment where the CPU is waiting on the I/O device completing its operation prior to moving on.  A simple example would be a traffic light system.

 

A pure interrupt driven environment would suit a system where the CPU is busy processing other tasks, and operates the I/O device "on the side" as a sub-task.  The windows print spooler is such an example.  Here the CPU is busy processing the windows environment, which requires high CPU utilization, while sending a file to the printer is a periodic event that can occur in the background.

 

A hybrid system will be one where the CPU is busy processing another task.  When the device is ready for service, it will interrupt the CPU, which then uses polling to handle a short burst of activity from the device.  The poll may timeout, in which case the CPU may revert to the original task and await another interrupt.

 

Problem 13.1

a. New requests for the track over which the head currently resides can theoretically arrive as quickly as these requests are being serviced.

 

b. All requests older than some predetermined age could be forced to the top of the queue, and an associated bit for each could be set to indicate that no new request could be moved ahead of these requests. For SSTF, the rest of the queue would have to be reorganized with respect to the last of these old requests.

 

c. To prevent unusually long response times.

 

d. Paging and swapping should take priority over user requests. It may be desirable for other kernel-initiated I/O, such as the writing of file system metadata, to take precedence over user I/O. If the kernel supports real-time process priorities, the I/O requests of those processes should be favored.

 

Problem 13.2

a. The FCFS schedule is
143, 86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130.
The total seek distance is 7081.

b. The SSTF schedule is
143, 130, 86, 913, 948, 1022, 1470, 1509, 1750, 1774.
The total seek distance is 1745.

c. The SCAN schedule is
143, 913, 948, 1022, 1470, 1509, 1750, 1774, 4999, 130, 86.
The total seek distance is 9769.

d. The LOOK schedule is
143, 913, 948, 1022, 1470, 1509, 1750, 1774, 130, 86.
The total seek distance is 3319.

e. The C-SCAN schedule is
143, 913, 948, 1022, 1470, 1509, 1750, 1774, 4999, 86, 130.
The total seek distance is 9813.

f. The C-LOOK schedule is
143, 913, 948, 1022, 1470, 1509, 1750, 1774, 86, 130.
The total seek distance is 3363.
 

Problem 13.4

a. 7200 rpm gives 120 rotations per second. Thus, a full rotation takes 8.33 ms, and the average rotational latency (a half rotation) takes 4.167 ms.

b. Solving t =0.7561 + 0.2439 (L)^0.5 for t =4.167 gives L = 195.58, so we can seek over 195 tracks (about 4% of the disk) during an average rotational latency.

 

Problem 13.9

The center of the disk is the location having the smallest average distance to all other tracks. Thus after servicing the first request, the algorithm would be more likely to be closer to the center track than to any other particular track, and hence would more often go there first. Once at a particular track, SSTF tends to keep the head near this.  Since tracks near the center are, by definition, closer to the center than those in the edges SSTF is more likely to stay in the center.