/Teaching/System Level Programming/Assignments/A5

Task: Memory Layout and Demand Paging

Complete 15 independent C programming experiments by filling the gaps in the supplied templates. The experiments explore the memory layout and behaviour of 64-bit programs.

Topics

  • Global and static initialization.
  • Heap allocation, allocation failure, and demand paging.
  • Stack memory, page size, and address layout.
  • Access to memory from different threads.
  • Private, shared, and read-only memory mappings.

Working with the experiments

Use the student handout ASSIGNMENT.md and the supplied templates and supporting files from A5/.

  1. Read the handout and each experiment’s instructions. Before running each program, write down numerical predictions for its output, the locations of its code and relevant objects, and its memory use at each stage. Give hexadecimal addresses, address differences, and memory totals and changes in bytes or KiB as precisely as you can. State your assumptions and show your calculations.
  2. Edit only the gaps in the supplied templates. Retain the supplied measurement code and pauses.
  3. Build and run each experiment separately. Use a recent, default-configured 64-bit Ubuntu Linux environment and the course toolchain (gcc/g++ 13.x or later).
  4. Use separate local investigation copies to print addresses and add memory measurements. Include code, relevant global and local objects, pointer variables and the storage they point to, and the first and last bytes of arrays or allocations where applicable. Label the thread or process for each address. You may add this instrumentation outside the gaps in these investigation copies; keep the supplied output format and gap-only edits in your submitted files.
  5. Compare every prediction with the measured result, then repeat the experiment. If an absolute address changes between runs, determine by how much. Investigate every mismatch until you can explain it.

Follow the handout’s requirements for volatile unsigned char arrays and writes. For the allocation-failure experiment, use the supplied local memory limit: (ulimit -v 131072; ./allocation_failure).

Submission

Submit the 15 completed .c files in A5/ in your repository using the A5 submission tag. Commit the source files, push your work and the tag to the server, and check the server feedback. Do not submit binaries. You may update the A5 tag throughout the semester.

Automated assessment

The submitted programs are assessed automatically. Each experiment is worth 0.2 points, giving an A5 assignment score of 3 points in total. Tests compare memory measurements, program output, and executable sizes.

Support

If you have questions regarding this assignment, attend the question hours and try Discord and slp.isec@tugraz.at as a final resort.