CMPSCI 377: Operating Systems

Homework 2

Due: November 25, 2008


  1. Assume that the list of holes in a variable partitions memory system contains the following entries (in the given order): 190 KB, 550 KB, 220 KB, 420 KB, 650 KB, 110 KB. Consider the following sequences of requests (in the given order): A = 210 KB, B = 430 KB, C = 100 KB, D = 420 KB. Determine which holes would be allocated to which request by each of the following schemes: first fit, best fit and worst fit? What is the average hole size for each scheme at the end of the allocation sequence?
  2. : Consider a logical address space of 256 pages of 512 words each, mapped onto a physical memory of 64 frames. Assume the architecture is word-addressed (i.e., each address in the memory addresses a word).
    (i) How many bits are there in the logical address?
    (ii) How many bits are there in the physical address?
  3. In a 32-bit machine we subdivide the virtual address into 4 segments as follows:
    [ 10-bits | 8-bits | 6-bits | 8-bits ]
    We use a 3-level page table, such that the first 10-bit are for the first level and so on.
    1. What is the page size in such a system?
    2. What is the size of a page table for a process that has 256K of memory starting at address 0?
    3. What is the size of a page table for a process that has a code segment of 48K starting at address 0x1000000, a data segment of 600K starting at address 0x80000000 and a stack segment of 64K starting at address 0xf0000000 and growing upward?
  4. A computer system has a 36-bit virtual address space with a page size of 8K, and 4 bytes per page table entry.
    1. How many pages are in the virtual address space?
    2. What is the maximum size of addressable physical memory in this system?
    3. If the average process size is 8GB, would you use a one-level, two-level, or three-level page table? Why?
    4. Compute the average size of a page table in question 3 above.
  5. Consider the following piece of code which multiplies two matrices: int a[1024][1024], b[1024][1024], c[1024][1024];
      multiply()
    {
       unsigned i, j, k;
       for(i = 0; i < 1024; i++)
           for(j = 0; j < 1024; j++)
               for(k = 0; k < 1024; k++)
                   c[i][j] += a[i,k] * b[k,j];
    }
    
    Assume that the binary for executing this function fits in one page, and the stack also fits in one page. Assume further that an integer requires 4 bytes for storage. Compute the number of TLB misses if the page size is 4096 and the TLB has 8 entries with a replacement policy consisting of LRU.
  6. Consider the following program fragment:
    s1.wait; 
    a++; 
    s2.wait; 
    v++; 
    s2.signal; 
    s1.signal;
    
    (s1, s2 are semaphores). Now, consider two threads running this fragment of code simultaneously, can there be a deadlock? Why, or why not?
  7. Consider the following program fragment:
    if(a > 0) 
        s1.wait; 
    else 
        s2.wait; 
    b++; 
    s3.wait; 
    if(b < 0 && a <= 0) 
        s1.wait; 
    else if(b >= 0 && a > 0) 
        s2.wait; 
    else 
        s4.wait; 
    a++; 
    s4.signal;  
    s3.signal; 
    s2.signal; 
    s1.signal;
    
    s1, s2, s3 and s4 are semaphores. Now, consider two threads running this fragment of code simultaneously, can there be a deadlock? Why, or why not?
  8. List two advantages and disadvantages of virtual memory/paging?
  9. What is a page fault? List all steps performed by the OS upon a page fault?
  10. Current page sizes are 4K bytes of 8K bytes. What are the implications of bigger page sizes? What about smaller page sizes?

  11. Last modified: Sat Nov 15 09:34:59 EST 2008