| Description |
In this project, you will learn about Memory management. First, you will implement
some memory allocation/deallocation schemes. Then, you will improve these allocation
schemes by implementing compaction/defragmentation within your memory management system.
Last, you will time and evaluate the allocation schemes. When done with this MP, you should end up with at least two files: MemoryManager.h and MemoryManager.c. We are providing a very basic test program to help understand the overall interface, but you should modify it to run more extensive tests on your code. Ultimately, you will provide a framework for allocating and deallocating memory. You will also print timing information. Example output is provided here. You do not need to match the output exactly. Additionally, the addresses and distances between your addresses may vary. Part 1: Memory Management InfrastructureFor part 1, you should implement at least two files: MemoryManager.c and MemoryManager.h.Your memory management subsystem will implement the following memory allocation schemes: First-Fit, Best-Fit, Worst-Fit and Next-Fit, as described in Tannenbaum, chapter four (especially section 4.2.2 pages 382-383). You will provide the user with an interface for making memory allocation requests and also for freeing up memory that is no longer needed by the user. In order to accomplish this, you need to implement the following five functions:
typedef enum AllocationAlgorithm
{
FIRST_FIT,
BEST_FIT,
WORST_FIT,
NEXT_FIT,
} Algorithm;
In order to simulate the memory management, you must allocate a contiguous chunk of memory
corresponding to the size passed into the InitializeMemory function. Then, whenever
the user calls MyMalloc or MyFree, all the memory they access should be within
the contiguous memory chunk you allocated initially.One of the jobs of the memory management subsystem is to service memory requests by matching the size of the request with a large enough hole, from which to satisfy the request. The hole should be chosen corresponding to the selected memory allocation scheme (First-fit, Best-fit, Worst-fit, or Next-fit). Note that when freeing memory, you must coalesce with the neighboring memory if possible, as shown in Figure 4-6, on page 382 in Tannenbaum. (i.e. If two or more holes would be adjacent after a call to MyFree, they should be merged into one hole). In addition to the required array for the simulated system memory, you can use any data structure(s) you want to implement the allocation algorithms. Figure 4-5 in Tanenbaum (page 381) shows two data structures, but you may decide to modify or change anything. You should try to implement structures to provide efficient searching for the appropriate holes in the chosen allocation scheme. However, you will not be graded on efficiency; although you have the option for extra credit if you do implement it under the no malloc's outside of InitializeMemory constraint, as stated. Part 2: CompactionImplement compaction in your memory manager. Compacting memory attempts to move the allocated memory so that the remaining holes can be combined into a larger hole. Your memory manager should automatically compact memory under the following two conditions:
NOTE: in order to allow us to more precisely test part 1, compaction must be implemented as an optional choice. To do this, add an integer parameter to the InitializeMemory function. This should correspond to the fragmentation threshold (e.g. a value of 75 corresponds to 75%). A value of 100 or higher means no compaction should be performed. In order to implement compaction, you must somehow store the addresses of all the pointers you return from MyMalloc (as noted in part 1). Then, you need to update these pointers so that the caller will point to the updated memory location. For uniformity, implement the compaction as a separate function called, Compact (or something equivalent). Part 3: Timing and EvaluationSimilar to past MPs, we want to measure various execution times of your implementation. Follow the sample output provided in terms of what you must print out. You should provide the following times:
Like MP2 & MP3, use clock_gettime as used in Example 9.8 in R&R to time the various requested behaviors. These results should be included in your output, similar to the sample output. Note: You will need to provide a brief analysis in the README file as described below. |
| Given Code |
test.c: Sample test program. Note:
We will use our own test.c for testing your implemntation. Sample output, same link from above |
| Deliverable |
This assignment is expected to be completed via pair programming. You are
encouraged to form a group of 2, although you may elect to work alone. Newsgroup
communication about general issues is allowed. Please post any questions on the
given code on the newsgroup. You should use the CSIL Linux machines to do the
assignment.
You are strictly required to use C. For this MP, you must create MemoryManager.c and MemoryManager.h. You are welcome to create other files if desired. Additionally, create a makefile which compiles your files and links them with test.c to create an executable called, memory_test. Create a README file as well, detailing any problems encountered during program design or execution. Include in the README the following information:
|
| Handin |
Use Compass to electronically handin an archive containing the files listed above (makefile,
MemoryManager.h, MemoryManager.c, and README - and any others you created) under the
"MP4 Handin" assignment. This must be done before 4pm on Monday, 17 April.
Every hour late is minus 2% credit. No submissions accepted after 4pm on Tuesday, 18 April. |
| Grading Criteria |
|
| Clarifications |
|