CS 620
Homework 5
Due Date: 04/11/2008 Friday
Note: The program is due by midnight on the due date.
Late Policy:
1 day late -- 5% deducted.
2 days late -- 10% deducted.
3 days late -- 15% deducted.
4 days late -- 20% deducted.
5 days late -- 25% deducted.
> 5 days late -- don't bother!
DESCRIPTION:
The goal of this assignment is to write a simple memory manager
based on the contiguous memory allocation scheme.
This assignment has two parts.
- (70 pts) Write a memory manager that supports contiguous memory
allocation using the best-fit policy.
Assume that
no compaction is performed by the memory manager. You should consider the
following issues while designing your memory manager:
- Efficiency of your search algorithm:
We do not require you to use a specific
algorithm/data structure to implement your searches.
You have the
flexibility of using any search algorithm/data structure that is efficient.
You loose 20 points if you use a design based on a
brute-force linear search.
- Free block coalescing: When a process terminates, the memory
allocated to that process is returned to the list of holes. You should take
care to combine (coalesce) holes that are adjacent to each other and form a
larger contiguous hole. This will reduce the degree of fragmentation
incurred by your memory manager.
Explain all design decisions, the data structures, and
search algorithms in the README file.
- (30 pts) Implement compaction in your memory manager.
Your memory manager should
compact memory every time it sees external fragmentation - this will occur when
a new process asks for memory and your memory manager is unable to allocate it
due to fragmentation. A simple compaction policy that moves all currently
running processes to the start of main memory and creating one hole at the
high region of memory will get you full credit.
Explain your design in the README file.
GETTING STARTED:
Use the following routines as a starting point:
MemoryManager(int bytes)
{ // intialize memory with these many bytes.
}
int allocate(int bytes, int pid)
{ // allocate these many bytes to the process with this id
// assume that each pid is unique to a process
// return 1 if successful
// return -1 if unsuccessful; print an error indicating
// whether there wasn't sufficient memory or whether
// there you ran into external fragmentation
}
int deallocate(int pid)
{ //deallocate memory allocated to this process
// return 1 if successful, -1 otherwise with an error message
}
void printMemoryState()
{ // print out current state of memory
// Example:
// Memory size = 1024 bytes, allocated bytes = 24, free = 1000
// There are currently 10 holes and 3 active process
// Hole list:
// hole 1: start location = 0, size = 202
// ...
// Process list:
// process id=34, start location=203, size=35
// ...
}
Data structures
Your memory manager should maintain two lists: a holeList and a
processList The holeList is a list of holes, with the start location and size of
each hole. The processList is the list of currently active process containing
the process Id, the start location and size of each process. You are free to use
any data structures (arrays, linked list, doubly linked list, etc) to implement
these lists. This decision will also affect the use of search algorithms to
search through these lists.
Input file
You program should take input from a input file and perform actions specified
in the file, while printing out the result of each action. The format of the
input file is as follows:
memorySize //initialize memory to this size
A size pid // allocate so much memory to this process
D pid // deallocate memory for this process
P // print current state of memory
An actual file may look as follows
8192
A 234 1
A 458 2
A 30 3
D 1
P
A 890 4
D 3
P
A 70 5
D 2
D 5
D 4
P
SUBMIT INSTRUCTIONS:
-
You should explain your design choices, data structures, and algorithm
in the README file.
Keep it short and to the point.
- If your implementation does not work, you should also document the
problems in the README, preferably with your explanation of why it does not
work and how you would solve it if you had more time. You should
also comment your code, since you will not get credit if the TA does not
understand your code.
-
Part 1: Create a makefile to build your executable
file. The name of your executable must be bestfit
. Submit all your source files (no object
or executable files), makefile, and README by typing
~cs620/submit 5 file1 file2 file3 ...
where 5 is the number of this assignment.
Note that if you want to resubmit, then you need to use
5a, 5b, ... for assignment number (not 5).
-
Part 2: Create a makefile to build your executable
file. The name of your executable must be bfcompact
. Submit all your source files (no object
or executable files), makefile, and README by typing
~cs620/submit 6 file1 file2 file3 ...
Notice that the assignment number is 6 instead of 5 for this part, otherwize you will
overwrite part 1 files.
Sample Run:
You can get a sample output run
here.
Return to the
CS 620 Home Page