Midterm Exam 2

810:143(g)

November 19th, 2001

 

This exam is closed book.  However, you may use one sheet (8 ˝ x 11 inches, both sides) of previously prepared notes.  There are 7 questions on this exam.  You will answer six of the seven questions for a total of 45 points.  The time limit is 50 minutes. 

 

 
 

1.        (2 pts each = 10 points) Explain the major differences between the members of each pair

 

·         track vs. cylinder

The surface of a single platter is divided into circular tracks.

A cylinder is the collection of "similar" tracks across all platter surfaces. In recent discussions, we discussed a cylinder as being all the tracks that can be read without movement of the read/write arms.

 

·         internal fragmentation vs. external fragmentation

 

External fragmentation is unallocated space in memory, or on a disk.  The problem arises when we develop many small spaces between allocated segments, none of which are big enough to allocate to a process.

Internal fragmentation is unused space within a segment of allocated memory.  This arises when we choose to allocate a slightly larger segment of memory to a process rather than the smaller segment it actually requested due to the cost of maintaining the "leftovers."  (eg if a process need 97 bytes of memory we may choose to allocate a 100 byte block in its entirety rather than try to keep track of the 3 bytes left over.)

 

·         proportional frame allocation vs. equal frame allocation

Assume 50 free frames, and two processes of 90 and 10 pages (p1 and p2 respectively).  In proportional allocation we give each process a number of frames in proportion to its needs.  Thus, p1 would be allocated 45 frames while p2 would be allocated 5 frames.  In equal frame allocation we simply divide free frames among the proccesses requesting them.  Thus, both p1 and p2 would be allocated 25 frames.

 

·         physical memory vs. logical memory

Logical memory is the memory and its location as viewed by the process or a user.  For example, we view the final byte of a 100 byte program to be contained in memory address 99 (assuming 1 byte addresses and counting starting at 0).

Physical memory is the actual main memory and its location as seen by the OS.  For example, our previous process may be loaded starting at physical memory location 2435.  Thus, the final byte of the program is contained at memory address 2544.

 

·         paging vs. swapping

In both, you are moving code between secondary storage and main memory.  The difference lies in the amount of "stuff" moved and how this effects further execution of the process.  In paging, you are exchanging pages (a portion) of the process.  After paging out a page, the process in question can continue to execute.  In swapping, you are exchanging the entire process.  To swap out a process, the OS must suspend the entire process, move its code and any status information out to secondary storage.  The process in question can not continue to execute until the process is swapped back in at a later time.

 

2.        (9 points) A process references five pages, A, B, C, D, and E in the following order:

A B C D A B E A B C D E

Start with an empty main memory with three page frames.  Show the proper state of memory after each page reference in this sequence using the optimal page replacement algorithm, and indicate the total number of page faults.  Repeat this problem using the FIFO and LRU algorithms.

 

Optimal (7 faults)

 

  A   B   C   D   A   B   E   A   B   C   D   E  
    A   A   A   A           A           C   C    
        B   B   B           B           B   D    
            C   D           E           E   E    

 

 

LRU (10 faults)

 

  A   B   C   D   A   B   E   A   B   C   D   E  
    A   A   A   D   D   D   A           A   D   D
        B   B   B   A   A   B           B   B   E
            C   C   C   B   E           C   C   C

 

 

FIFO (9 faults)

 

  A   B   C   D   A   B   E   A   B   C   D   E  
    A   A   A   D   D   D   E           E   E    
        B   B   B   A   A   A           C   C    
            C   C   C   B   B           B   D    

 

 

3.         (8 points) Explain what is meant by each of the following:

 When a process spends more time paging than it does executing.

 

 

·         Belady’s anomaly

When  increasing the number of frames available to a process does not reduce the number of page faults (happens most with FIFO).

 

·         Locality of reference

 During any particular phase of execution, the process references only a relatively small fraction of its pages.

  

·         Valid/invalid bit

 (Answer depends a little bit on context).

The valid/invalid bit is an addition to the page table which indicates the "status" of a page.  A page marked invalid means the OS failed to bring the page into memory.  This can be for two reasons.  Either the page is not a valid memory reference (page tables are a set size and may contain references to pages that are not actually part of the current process) or the page has not yet been loaded into local memory.

 

4.        (8 points) Suppose the read/write head is at track 97, moving toward track 199 (the highest numbered track on the disk) and the disk request queue contains read/write requests for sectors on tracks 84, 155, 103, 96 and 197, respectively.  What is the total number of head movements to satisfy the requests using:

 

FCFS

 

 97 to 84 to 155 to 103 to 96 to 197 = 244

 

SSTF

 

 97 to 96 to 103 to 84 to 155 to 197 = 140

  

SCAN

 

 97 to 103 to 155 to 197 to 199 to 96 to 84 = 217

 

LOOK

 

 

 97 to 103 to 155 to 197 to  96 to 84 = 213

 

 

CHOOSE TWO OF THE FOLLOWING THREE PROBLEMS

 

5.      (5 points) Consider a memory management system with demand paging. You know the following characteristics of the system:

If, 80% of all memory accesses are served from the TLB and 10% of the remaining accesses cause a page fault, what's the effective access time? (In other words, what's the average time it takes to serve a memory access from the above distribution?)

 

     0.8 * (0.1 + 1)  +

     0.2*0.9 * (0.1 + 1 + 1) +

     0.2*0.1 * (0.1 + 1 +20,000 + 1)

 

    = 401.3

 

 

6.         (5 points) Under what circumstances do page faults occur? Describe the actions taken by the operating system when a page fault occurs.

 

A page fault occurs when a process addresses a page whose valid/invalid bit is set to invalid.  (I also accepted it if you said that this happens when a process addresses a point in logical memory that is not currently in physical memory although this is not completely accurate).

 

When this occurs, the OS traps, suspending the process.  It checks to see if the reference itself is legal (the reference is to a page not currently in memory) or illegal (the reference is to a page that doesn't actually exist).  Of the reference was illegal, the process is aborted.  If the reference was legal, the OS prepares to bring the needed frame into physical memory.  If there is a frame available from the free frame list, then the page is simply loaded.  If there is not a free frame available, the OS selects a current frame as a victim (using a page replacement algorithm), MAY write this frame back to secondary storage, and loads the needed page into the newly available frame.  Finally, the page table is updated to reflect this modification, and the process's execution is restarted from the line which caused the trap.

 

 

7.        (5 points) Assume that you have a page-reference string for a process with m frames (initially all empty).  The page-reference string has a length p while n distinct page numbers occur in it.  Answer these questions for any page replacement algorithm:

a)       What is the lower bound on the number of page faults? Why?

  n.  Each page must be loaded at least once.

 

 

b)       What is the upper bound on the number of page faults? Why?

 p.  At worst, each time a page reference arises, it needs to be loaded into a frame.