CS3013 Project 4b

Memory Accounting

Due date: Tuesday, October 11th by 11:59pm


This project is designed to give you some experience in the use of some of the memory management tools.


Index


Memory Accounting

You are to evaluate memory use in conjunction with forked processes and spawned threads. This evaluation proceeds in several steps with questions for each step.

Write a program that declares a two-dimensional array of 4096x4096 bytes. Make one pass through the entire array, going across the columns and setting values, and then print information about the page faults using getrusage(). Report the minor (soft) and major (hard) page faults separately. Make a second pass through the same array and again, print page fault information. Remember that the statistics for getrusage() are not reset each call but rather accumulate over the life of a process.

Question 1: Why did you obtain many minor page faults the first time through the array? Did you obtain more minor or major page faults for the second pass? Why or why not?

Create a similar program that goes down the rows first, causing the elements to be accessed a column at a time rather than a row at a time. Compile and re-run the previous test.

Question 2: How do your results differ from the previous results? Why are they the same or different?

Create a new program that creates a new process via a fork() call before walking through the array. Both processes then walk through the array as in the first step.

Question 3: How do your results differ from the initial results? Why are they the same or different?

Create a similar program that creates a new thread via a pthread_create() call before walking through the array. Both threads then walk through the array as in the first step. Don't worry if there are race conditions here.

Question 4: How do your results differ from the previous results with fork()? Why are they the same or different?

Create a test program that contains a recursive function with a single argument, the number of times to recurse. The function should contain a local array of 4 Kbytes. Before recursing, the function should set elements in the array so the page is actually faulted into memory. Test your program compared with values returned by the getrlimit() call.

Question 5: Are the results consistent with the resource limit? Use the system call setrlimit() to increase the stack and explore further in your answer.


Hints

The following system calls might be useful:

You might consider trying your code with a while() loop rather than for() loop to see if there is a difference due to compiler optimizations.

You might try allocating different sized memory chunks and perhaps doing only single row/single column initialization and see if there are differences.


Hand In

You must hand in the following:

The turnin (/cs/bin/turnin) for proj4 is "proj4". When turnin, also include file "group.txt" which contains the following:

        group_name
        login_name1  last_name1, first_name1
        login_name2  last_name2, first_name2
        ...

Also, before you turnin tar up (with gzip) your files. For example:

        mkdir proj4
        cp * proj4  /* copy all your files to submit to proj1 directory */
        tar czf proj4.tgz proj1

then:

        scp proj4.tgz login_name@ccc:~/
        ssh login_name@ccc    /* will ask your ccc passwd */
        /cs/bin/turnin submit cs3013 proj4 proj4.tgz

Return to 3013 Home Page

Send all project questions to the cs3013-staff at cs.wpi.edu mailing list.

Send all Fossil administrative questions to the fossil at cs.wpi.edu mailing list.