School of Computing, University of Leeds, 22/23
XJCO2211
Operating Systems
Coursework: Memory Management
Deadline: 16th Nov 2022
This assignment is worth 20% of the final module grade. Your submission must include the final version of your code.
Introduction
This coursework is a combination of a programming task, a short report that explains your implementation, and a set of questions to answer. The key learning objectives are to:
●understand the importance of memory management
●improve the ability to program components in an operating system
●understand the basic principle of memory allocation in both user space and kernel space
●
Assessment & Submission
There will be TWO assignments on Minerva for the TWO parts of your coursework. You will be required to submit both your code and the associated answers to the corresponding assignments. You will also be required to demonstrate the codes you have produced.
Code Submission: Upload your code to the assignment (Memory Management (Code)) either as a single C file named “USERNAME.c” or if you use multiple source files, as a .ZIP named “USERNAME.zip”.
Report Submission: Upload the report as a PDF named “USERNAME_report.pdf” to the Turnitin assignment (Memory Management (Report)) on the module VLE.
Demonstration: You will be assigned a 5 minute time slot during one of the lab sessions for you to demonstrate your codes. For all submissions received before the deadline your assigned slot will be available on 16/11/2022.
Disclaimer
This is intended as an individual piece of work and, while discussion of the work is encouraged, plagiarism in any form is strictly prohibited. The answers you hand in must be your own work. Standard late penalties apply for work submitted after the deadline.
The Task
Task 1: Programming (Memory Allocation and Free)
Your task is to familiarise the memory usage monitoring and develop functions similar to the native malloc and free that can satisfy the following specification. The features of the memory management programs in C and the marks for demonstrating each feature are shown below.
1.Estimating memory usage using the free or vmstat tool [2 marks]
a.Login to your Linux systems, open a terminal and type man free or man vmstat. Read and understand the meanings of different arguments.
b.Run commands, e.g., free -m argument. How much memory and free memory are in your system?
c.Create a program memory_consumption.c that uses a certain memory (the number of Megabytes) used will be indicated as an input of a command line argument. The program could allocate an array and constantly stream through the array. The program could run either indefinitely or for a given time period.
d.Monitor the runtime memory usage over time when the program is running. Tune the memory usage in the program and examine what happens when a large amount of memory is used.
2. Implementing a malloc function [4 marks]
a.The malloc function allocates a specific number of bytes and returns a pointer to the allocated memory. If the requested size is zero, the malloc() return either NULL or a unique pointer value that can be passed to free at a later stage
b.It should have the prototype void*_malloc (size_t size)
c.It should return a void pointer to the start of the allocated memory
d.It should allocate memory on the heap and split up regions of memory to avoid over-allocation
e.The pointer returned should be well aligned with any kind of variable
3. Implementing a free function [4 marks]
a.The free function frees the memory space pointed to by the parameter which must have been returned by a previous call to _malloc. Otherwise, or if free has already been called upon the pointer before, undefined behaviour occurs. If the pointer is NULL, no operation will be performed.
b.It should have the prototype void*_free(void*ptr)
c.It should free the memory and make it available for subsequent allocations
d.It should merge necessary regions of memory to reduce memory fragmentation
e.It should return the memory to the operating system when it is appropriate
Your implementation should be contained in a new file called memory_management.c and a header file memory_management.h. Your files should be located in the user directory. The header file should include the function definitions and any structs necessary in your implementation.
Submit your code for the completed solution to Minerva. [Total: 10 marks]
Task 2: Summary Report
Write a report on your implementation for Task 1 with a maximum length of 5 sides of A4. You should reference any additional materials that you have used, including any tutorials or documentation. Your report should be formatted with the main text body in Arial point size 11, 1.5 line spacing, your name in the header and page number in the footer.
In your report you should discuss:
●How you achieved the features outlined in Task 1 and your design decisions.
●The main design principle and explanations of your code.
●Reflect on what you’ve learned.
Submit your report to Minerva as a PDF.
The report will be marked as follows:
Coverage 2
Understanding 3
Depth (completeness, detail, comparison) 8
Referencing 3
Report structure 2
Writing quality 2 [Total: 20 marks]