Assignment 7, due Apr. 2

Part of the homework for 22C:112, Spring 2010
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list! All assignments will be due at the start of class on the day indicated (usually a Friday). The only exceptions to this rule will be by advance arrangement unless there is what insurance companies call "an act of God" - something outside your control. Homework must be turned in on paper and in class! Late work may be turned in to the teaching assistant's mailbox, but see the late work policy. Never push late work under someone's door!

  1. Background: Read the Unix manual pages on the mmap() and shmat() system calls. These system calls were added to Unix as afterthoughts, and since there were multiple development thinking in the same direction, both got added and developed user communities. You may need to read the man pages for some of the commands listed in the see also sections to answer all of the following. (Note: These were independently developed and added to different versions of Unix independently, and each developed a user community -- as a result, most Unixes today support both.)

    a) These do many of the same things. Describe the common core of functionality they share, from the user's perspective. (0.5 points)

    b) With reference to the memory map of the calling process, describe how the start argument of the mmap() function must operate. For full credit, your description must explain why start operates as a hint. (0.5 points)

  2. Background: In a classical virtual memory system for a computer with just one address space, the user's page number is also used as the sector number on the disk used as backing storage when that page is not held in a frame of main memory.

    In a system that supports the mmap system call, a different approach must be used. If you know from the start that you are going to support mmap(), you should use mmap() to link the code, static and stack segments to their backing storage as well as using it for files that a user elects to access through mmap().

    a) When the time comes to move a page between main memory to backing store, how does the system find the appropriate disk address. You may need to invent some auxiliary data structures besides the page table in order to make this feasible. Assume that there is no pre-computation of disk addresses associated with each virtual address. Your answer must relate what you know about file systems to what you know about virtual memory. (0.5 points)

    b) Explain the potential improvement in system performance that would result from pre-computing the disk address associated with each page-table entry. Your discussion must build on part A by explaining the part of the cost of accessing a page that is avoided by this precomputation, and estimating its potential best-case and worst-case magnitude. (0.5 points)

    c) How would your answer to the first two parts of this problem change if you had enforce the constraing that mmaped files must start on a hardware segment boundary (assuming a paged-segmented virtual memory model). (0.5 points)

  3. Background: Suppose you use mmap() to bring a file into your address space, and you build data structures in that file, linked lists, trees and similar things. Each time you map that file into your address space, you give the system the same hint about start, but the system is not guaranteed to take the hint. It could use a different starting address each time.

    A Problem: What can you do, as a programmer, to tolerate this? Solve the problem in C. (0.5 points)

Machine Problem 4, due Apr. 7

Write a program that uses mmap() to read and list a text file to the screen. It should take the file name as a command line argument, and it should output the lines with a leading dash on each line.

As usual, submit your source file as mp4.c.