Task: Memory Mapping
Navigate to the labs/lab-04/tasks/copy/ directory, and open the support/src directory. Here you will find these files:
read_write_copy.cin which you will implement copying withread/writesyscallsmmap_copy.cin which you will implement copying usingmmapbenchmark_cp.shscript which runs the two executablesmmap_copyandread_write_copy
-
Complete the implementations for the
read_write_copy.candmmap_copy.cfiles. The goal is to copy thein.datfile toout.datusing theread/writesyscalls andmmaprespectively. Check your work by running thechecker.shscript in thesupport/tests/directory. -
Once you have a working implementation, run the
benchmark_cp.shscript to compare the performance of the two approaches. The output should look like this:student@os:~/.../drills/tasks/copy/support$ ./benchmark_cp.sh Benchmarking mmap_copy on in.dat time passed 54015 microseconds Benchmarking read_write_copy on in.dat time passed 42011 microsecondsRun the script a few more times. As you can see, there isn’t much of a difference between the two approaches. Although we would have expected the use of multiple system calls to cause overhead, it’s too little compared to the memory copying overhead.
-
Add a
sleep()call to themmap_copy.cfile after the files were mapped. Rebuild the program and run it. On a different console, usepmapto view the two new memory regions that were added to the process, by mapping thein.datandout.datfiles.
If you’re having difficulties solving this exercise, go through this reading material.