Memory Management Exercise


Modern memory management techniques can have a significant impact on program performance. This exercise illustrates the importance of coding loops carefully to take advantage of paging and caching systems used on most modern computers. The program memhog.c (see codes section of OS page) initializes a large square matrix to 0. The program takes one parameter, which should be set to 0 or 1. The value of 1 causes the program to initialize the matrix row by row. Any other value causes the program to initialize the program column by column.

The program performs two initializations of the same matrix. Each initialization is timed in memhog.c, and the values are printed. The program memhog.c can be compiled and executed with the mh script. The script runs the program using the /usr/bin/time utility. This utility provides the user and system times required by the program. It also gives the number of minor and major page faults produced by the program. In Linux, a major page fault is a fault that requires a copy of a page from disk. A minor fault requires a page table update and possibly frame allocation, but no disk copy.

Run the Program and Collect Data

Run this program in the Linux Lab only. Do not try to run it on the remote login computer.

Use the mh script to run the program with for matrix sizes set to 1000, 3000, 5000 and 7000. Record the number of minor and major page faults. Also, record the user and system times for each run. In addition, record the run times produced by memhog.c. Next repeat the runs but change the mh script so that initialization is done down the columns. Record the same data.

Answer the Following Questions

1. Why is the first initialization always faster than the second?
2. Compare the number of minor and major page faults for row wise versus column wise initialization.  
3. Is row wise or column wise initialization faster?  Explain why. 
4. Record the memory requirements of memhog.c when size is 5000 and 7000. 
   Hint: Run the program in the background and use the top command.  
   For these values of size is virtual memory needed on your system to run memhog.c? Explain.

Prepare a Report

Write a report that answers the above questions and presents the data requested in graphs or tables.

Due Date

The due date for the paper is December 12.