Operating Systems
Sample Exam 2 Solutions


  1. (30 pts) Short Answer.

    1. (10 pts) List 3 algorithms for managing memory with contiguous segmented allocation. Do these algorithms require compaction to work? Why or why not?

      First fit, worst fit, and best fit. No, they can work without compaction because if they can not fit a process, they can just wait until another process fininishes to start the requesting process. (2 pts extra credit for: However, they must coallesce adjacent free memory blocks, or fragmentation of the memory will eventually prevent allocation.

    2. (10 pts) Explain the difference between logical and physical addresses.

      Logical addresses are with respect to the process and must be mapped to a physical location. For example in virtual memory systems, logical address can be larger than the physical address space and in segmentation, the segment number has no physical analogue. Physical addresses must exactly correspond to a hardware location.

    3. (10 pts) What is swapping and when is it used?

      The OS swaps processes by taking all their pages and copying them to a special place on disk (into the swap space). The OS uses swapping to manage how many process are in memory at once, i.e., when too many processes are in memory at once. The OS thus sacrifies the performance of the swapped process to enable other process to run and get the memory they need.

  2. (20 pts) Performance of Paged Systems. This question asks you to compute the effective memory access time (ema) in symbolic terms for different hardware implementations of paging with and without virtual memory. Let ma be the time to read or write a value in memory. Define other terms as you need them. First assume the process and its page table fit and stay in memory while the program executes, and there is no TLB.

    1. (5 pts) What is the ema for this system?

        ema = 2 * ma, memory reference plus page table look up.

    2. (5 pts) Now assume there is a TLB. What is the ema for this system? Include l, the time for the TLB look up in your equation.

        ema = x * (ma + l) + (1-x) * 2 * ma

        where x be the probability of a TLB hit. x * (ma + l) is the time with a TLB hit, and (1-x) 2 * ma is the miss. l is not included in the miss time since the memory page table look up happens in parallel with the TLB look up.

    3. (5 pts) Now consider a virtual memory system with a TLB where the process can grow larger than the memory, and the page may not be in memory. What is the ema now? Assume that the page table is always in memory.

        ema = x * (ma + l) + (1-x) (y * 2 * ma + (1-y) (pf + 2 * ma))

        where x be the probability of a TLB hit, y the probability the referenced page is in memory, and pf the page fault time. The TLB miss time is now the sum of probability of a page hit in memory (y * 2 * ma), and the page miss (pf + ma) which includes the memory access as well as the page fault time. The page fault time includes the time to read the page in, and write the replaced page on to disk if it was modified. (Including these symbolic times and probabilities is also correct.)

    4. (5 pts) Now what is the ema for the same system except that the page table entry itself may not be in memory?

        b = y * 2 * ma + (1-y) (pf + 2 * ma)
        ema = x * (ma + l) + (1-x) (z * b + (1-z)(pf + b))

        where z is the probability of no page fault of the page table look up. z*b is thus the hit. For the miss, we add the page fault time for the look up, the memory access time for the page look up is already included in b.

  3. (25 pts) Segmentation with Paging. Design a memory management scheme that uses segmentation with paging.

    1. Specify and justify the number of segments.

      I choose 3 segments: one for the code (so it can be shared between processes), one for the heap (so it can be shared between threads), and one for the stack (threaded programs will share this stack).

    2. Specify the translation of logical to physical addresses.

      The segment number needs two bits, which the compiler tacks on the front of the logical address. This scheme supports virtual memory as well, where the rest of the address is allowed to grow larger than the memory. The translation of the remainder of the address chops the logical address into two parts: the page (p) and the offset into the page (d). A page contains 2d bytes. The number of pages is dependent on the logical space I design; with a physical memory size of 2k and no virtual memory, the system needs at most k bits. With virtual memory it can be larger.

    3. Specify hardware support to make address translation fast. (Draw a picture.)

      I would want to use associative memory (registers) for the 3 segment entries, and a TLB for the page table entries. The quickest organization really would be to index a TLB with the segment number and the page number together.

  4. (25 pts) Memory Management versus Disk Management. Memory management and disk management have some key similarities and differences that result from their physical characteristics and from the access patterns each expects and supports well. Using at least 3 points of comparison, describe some of their similarities and differences.

    1. The major physical difference between memory and disk, is that random accesses to memory takes the same time as sequential access, where as on the disk, each access requires a seek, so random accesses are significantly slower than nearby accesses (accesses with sequential locality.)

    2. However, both disk and memory expect to see sequential access and thus store more than one addressable word; disks use a sector (a.k.a. a block) and memory uses pages.

    3. Disk and memory are optimized for different sizes of objects. Most files are small and smaller than a block, so most data fits in a single block on disk. Files larger than a block are organized with links in Unix for example, which are slower to follow than direct access on a random access. Most processes are large and larger than a page, and logically are contiguously allocated. Both disk and memory tend to choose some internal fragementation over external fragmentation to simplify allocation and freeing.

    4. The above physical difference has consequences on where we place data in memory and data on disk. In memory, it does not matter where the OS places a page, (although which pages are in memory is important since the OS tries to keep pages in memory if it expects them to be used again; page replacement algorithms implement this function). On disk, the OS wants to place the most frequently accessed files and/or directories in the middle of the disk to keep seek times as quick as possible.