1. Homepage
  2. Programming
  3. [2021] PSU - CMPSC 473 Operating Systems - Project2 Malloc Lab: Writing a Dynamic Storage Allocator

[2021] PSU - CMPSC 473 Operating Systems - Project2 Malloc Lab: Writing a Dynamic Storage Allocator

Engage in a Conversation
PSUCMPSC 473Operating SystemsThe Pennsylvania State UniversityProgramming HelpMalloc Lab

CMPSC473, Spring 2021
Malloc Lab: Writing a Dynamic Storage Allocator
CourseNana.COM

1 Introduction CourseNana.COM

In this lab, you will be writing a dynamic storage allocator for C programs, i.e., your own version of the malloc, free, and realloc functions. You are encouraged to explore the design space creatively and implement an allocator that is correct, space efficient, and fast. CourseNana.COM

The only file you will be modifying is mm.c. Modifications in other files will not be used in the grading. You will be implementing the following functions: CourseNana.COM

bool mm init(void)
void* malloc(size t size)
void free(void* ptr)
void* realloc(void* oldptr, size t size) bool mm checkheap(int lineno) CourseNana.COM

You are encouraged to define other (static) helper functions, structures, etc. to better structure your code. CourseNana.COM

2 Programming Rules CourseNana.COM

IMPORTANT: You are required to implement a heap checker (see Section 5) that will be graded. The heap checker will help you debug your code. CourseNana.COM

IMPORTANT:You are  required  to write comments for all   ofyourcodeincludingtheheapchecker.Addi- tionally, you need to write a file comment at the top of the file describing your overall malloc design. See Section 7 for grading details. CourseNana.COM

IMPORTANT: You must show your partial work on this assignment by periodically committing and submitting (i.e., pushing) your code to git. This will be used both for grading the checkpoints as well as ensuring academic integrity. CourseNana.COM

You are not allowed to change any of the interfaces in mm.c. 1 CourseNana.COM

You are not allowed to invoke any memory-management related library calls or system calls. For example, you are not allowed to use sbrk, brk, or the standard library versions of malloc, calloc, free, or realloc. Instead of sbrk, you should use our provided mem sbrk. CourseNana.COM

Your code is expected to work in 64-bit environments, and you should assume that allocation sizes and offsets will require 8 byte (64-bit) representations. CourseNana.COM

You are not allowed to use macros as they can be error-prone. The better style is to use static functions and let the compiler inline the simple static functions for you. CourseNana.COM

You are limited to 128 bytes of global space for arrays, structs, etc. If you need large amounts of space for storing extra tracking data, you can put it in the heap area. CourseNana.COM

3 Description of the dynamic memory allocator functions CourseNana.COM

mm init: Before calling malloc, realloc, calloc, or free, the application program (i.e., the trace- driven driver program that will evaluate your code) calls your mm init function to perform any necessary initializations, such as allocating the initial heap area. The return value should be true on success and false if there were any problems in performing the initialization. CourseNana.COM

malloc: The malloc function returns a pointer to an allocated block payload of at least size bytes. The entire allocated block should lie within the heap region and should not overlap with any other allocated chunk. If the requested size is 0 or if mem sbrk is unable to extend the heap, then you should return NULL. Similar to how the standard C library (libc) always returns payload pointers that are aligned to 16 bytes, your malloc implementation should do likewise and always return 16-byte alignedpointers. CourseNana.COM

free: The free function frees the block pointed to by ptr. It returns nothing. This function is only guaranteed to work when the passed pointer (ptr) was returned by an earlier call to malloc, calloc, or realloc and has not yet been freed. If ptr is NULL, then free should do nothing. CourseNana.COM

realloc: The realloc function returns a pointer to an allocated region of at least size bytes with the following constraints. CourseNana.COM

·        if ptr is NULL, the call is equivalent to malloc(size); CourseNana.COM

·        if size is equal to zero, the call is equivalent to free(ptr); CourseNana.COM

·        if ptr is not NULL, it must have been returned by an earlier call to malloc, calloc, or realloc. The call to realloc changes the size of the memory block pointed to by ptr (the old block) to size bytes and returns the address of the new block. Notice that the address of the new block might be the same as the old block, or it might be different, depending on your implementation, the amount of internal fragmentation in the old block, and the size of the reallocrequest. CourseNana.COM

The contents of the new block are the same as those of the old ptr block, up to the minimum of the old and new sizes. Everything else is uninitialized. For example, if the old block is 8 bytes and the new block is 12 bytes, then the first 8 bytes of the new block are identical to the first 8 bytes of the old block and the last 4 bytes are uninitialized. Similarly, if the old block is 8 bytes and the new block is 4 bytes, then the contents of the new block are identical to the first 4 bytes of the oldblock. CourseNana.COM

These semantics match the the semantics of the corresponding libc malloc, realloc, and free functions. Run man mallocto view complete documentation. CourseNana.COM

4 Support Functions CourseNana.COM

The memlib.c package simulates the memory system for your dynamic memory allocator. You can invoke the following functions in memlib.c: CourseNana.COM

void* mem sbrk(int incr): Expands the heap by incr bytes, where incr is a positive non-zero inte- ger. It returns a generic pointer to the first byte of the newly allocated heap area. The semantics are identical to the Unix sbrk function, except that mem sbrk accepts only a non-negative integer argument. You must use our version, mem sbrk, for the tests to work. Do not use sbrk. CourseNana.COM

void* mem heap lo(void): Returns a generic pointer to the first byte in the heap. CourseNana.COM

void* mem heap hi(void): Returns a generic pointer to the last byte in the heap. CourseNana.COM

size_t mem heapsize(void): Returns the current size of the heap in bytes. CourseNana.COM

size_t mem pagesize(void): Returns the system’s page size in bytes (4K on Linux systems). CourseNana.COM

void* memset(void* ptr, int value, size t n): Sets the first n bytes of memory pointed to by ptr to value. CourseNana.COM

void* memcpy(void* dst, const void* src, sizet n): Copies n bytes from src to dst. CourseNana.COM

5 Heap Consistency Checker CourseNana.COM

Dynamic memory allocators are notoriously tricky beasts to program correctly and efficiently. They are difficult to program correctly because they involve a lot of untyped pointer manipulation and low-level manipulation of bits and bytes. You will find it very helpful to write a heap checker mm checkheap that scans the heap and checks it for consistency. The heap checker will check for invariants which should always be true. CourseNana.COM

Some examples of what a heap checker might check are: CourseNana.COM

Is every block in the free list marked as free?
Are there any contiguous free blocks that somehow escapedcoalescing? Is every free block actually in the free list?
Do the pointers in the free list point to valid free blocks?
Do any allocated blocks overlap?
Do the pointers in a heap block point to valid heap addresses? CourseNana.COM

You should implement checks for any invariants you consider prudent. It returns true if your heap is in a valid, consistent state and false otherwise. You are not limited to the listed suggestions nor are you required to check all of them. You are encouraged to print out error messages when the check fails. You can use dbg printf to print messages in your code in debug mode. To enable debug mode, uncomment the line #define DEBUG. CourseNana.COM

To call the heap checker, you can use mm checkheap( LINE ), which will pass in the line number of the caller. This can be used to identify which line detected a problem. CourseNana.COM

You are required to implement a heap checker for your code, both for grading and debugging purposes. See Section 7 for details on grading. CourseNana.COM

6 Testing your code CourseNana.COM

First, you need to compile/build your code by running: make. You need to do this every time you change your code for the tests to utilize your latest changes. CourseNana.COM

To run all the tests after building your code, run: make test.
To test a single trace file
after building your code, run: ./mdriver -f traces/tracefile.rep. CourseNana.COM

Each trace file contains a sequence of allocate, reallocate, and free commands that instruct the driver to call your malloc, realloc, and free functions in some sequence. CourseNana.COM

Other command line options can be found by running: ./mdriver -h To debug your code with gdb, run: gdb mdriver. CourseNana.COM

7 Evaluation
You will receive zero points if: CourseNana.COM

you break any of the programming rules in Section 2 your code does not compile/build
your code is buggy and crashes the driver CourseNana.COM

Otherwise, your grade will be calculated as follows: CourseNana.COM

50 pts Checkpoint 1 (Due: Sun., Feb. 28, 11:59:59 PM): This part of the assignment simply tests the correctness of your code. Space utilization and throughput will not be tested in this checkpoint. Your grade will be based on the number of trace files that succeed. CourseNana.COM

100 pts Checkpoint 2 (Due: Sat., Mar. 06, 11:59:59 PM): This part of the assignment requires that your code is entirely functional and tests the space utilization (60 pts) and throughput (40 pts) of your code. Each metric will have a min and max target (i.e., goal) where if your utilization/throughput is above the max, you get full score and if it is below the min, you get no points. Partial points are assigned proportionally between the min and max. CourseNana.COM

·        Spaceutilization(60pts):Thespaceutilizationiscalculatedbasedonthepeakratiobetweentheaggregate amount of memory used by the driver (i.e., allocated via malloc or realloc but not yet freed via free) and the size of the heap used by your allocator. You should design good policies to minimize fragmentation in order to increase this ratio. CourseNana.COM

·        Throughput (40 pts): The throughput is a performance metric that measures the average number of operations completed per second. As the performance of your code can vary between executions and between machines, your score as youre testing your code is not guaranteed. The performance testing will be performed on the W204 cluster machines to ensure more consistent results. CourseNana.COM

100 pts Final submission (Due: Fri., Mar.12, 11:59:59 PM): This part of the assignment is graded identically as Checkpoint 2, except that the grading curve has not been significantly reduced as is the case with Checkpoint 2. CourseNana.COM

50 pts CourseNana.COM

Code demo and comments (Due: Fri., Mar. 12, 11:59:59 PM): As part of the final submission, we will be reviewing your heap checker code and comments through your code. You will need to upload a 4-5 minute CourseNana.COM

demo video describing your design choice, data structures and heap checker code and upload it on canvas (one demo video per team). The TAs can ask you to schedule an appointment to meet them via zoom to answer additional questions about your project after the deadline, if necessary. Your heap checker will be graded based on correctness, completeness, and comments. The comments should be understandable to a TA. The demo will show correctness. Your explanation of the heap checker and your malloc design will determine the degree to which your checker is checking invariants. CourseNana.COM

There will be a balance between space efficiency and speed (throughput), so you should not go to extremes to optimize either the space utilization or the throughput only. To receive a good score, you must achieve a balance between utilization and throughput. CourseNana.COM

Grades will be assigned by running your code on W204 machines. So, please check that your code runs on those machines. CourseNana.COM

  CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
PSU代写,CMPSC 473代写,Operating Systems代写,The Pennsylvania State University代写,Programming Help代写,Malloc Lab代写,PSU代编,CMPSC 473代编,Operating Systems代编,The Pennsylvania State University代编,Programming Help代编,Malloc Lab代编,PSU代考,CMPSC 473代考,Operating Systems代考,The Pennsylvania State University代考,Programming Help代考,Malloc Lab代考,PSUhelp,CMPSC 473help,Operating Systemshelp,The Pennsylvania State Universityhelp,Programming Helphelp,Malloc Labhelp,PSU作业代写,CMPSC 473作业代写,Operating Systems作业代写,The Pennsylvania State University作业代写,Programming Help作业代写,Malloc Lab作业代写,PSU编程代写,CMPSC 473编程代写,Operating Systems编程代写,The Pennsylvania State University编程代写,Programming Help编程代写,Malloc Lab编程代写,PSUprogramming help,CMPSC 473programming help,Operating Systemsprogramming help,The Pennsylvania State Universityprogramming help,Programming Helpprogramming help,Malloc Labprogramming help,PSUassignment help,CMPSC 473assignment help,Operating Systemsassignment help,The Pennsylvania State Universityassignment help,Programming Helpassignment help,Malloc Labassignment help,PSUsolution,CMPSC 473solution,Operating Systemssolution,The Pennsylvania State Universitysolution,Programming Helpsolution,Malloc Labsolution,