OS代写:COMP3080-Memory-Allocation

Requirement

The program you will write will read a file which contains memory allocation requests and memory free operations. The allocation and free operations will be made against an initially empty fixed sized free memory pool. The program must support three allocation policies:

  • First fit linked list
  • Best fit linked list
  • Buddy system power of 2 block allocation (using a minimum allocation of 32 bytes)

Your program must:

  1. Accept three command line arguments, such that argv[1] is the policy to use, argv[2] is the total memory free pool size and argv[3] is the name of the file containing the allocation and free requests. The memory size of the total free pool for the main test cases will be 1 MByte, and 512KB. You may use other sizes in any additional experiments you attempt, but make sure you describe your configuration and results in your write-up.
  2. Read each line of the input file in argv[3] and carry out one of the following actions:
  3. Make a memory allocation if enough memory is available to satisfy an allocation request.
  4. Return memory to a linked list and carry out any coalescing (buddying up) required.
  5. Refuse the allocation only if there is not enough memory to satisfy it in any available free partition. Refused requests are remembered, so that you know to take no action when you see the corresponding free operation in the input stream. (For each alloc there is a free.)
  6. Generate one line of output for each line of input, providing information about which request this is, how the request was handled, what the total amount of free space after the request is, and what the size of the largest free partition after the request is. Sample input and output files are shown below.
  7. So you should submit 6 files, each containing your output for the 1MB and 512KB cases for all three algorithms, and a final summary in your write-up that provides the results of each test in a format similar to:
    1
    2
    3
    First Fit 1MB: Total Allocations 490 of 500
    First Fit 512KB: Total Allocations 374 of 500
    Best Fit 1MB: Total Allocations 492 of 500

INPUT FORMAT:

1
2
3
4
5
6
7
8
SERIAL-NUM   REQUEST   SIZE   SERIAL-MATCH
1 alloc 20000
2 alloc 100000
3 alloc 5050
4 free 2
5 alloc 70500
6 free 1
7 alloc 400000

OUTPUT FORMAT:

1
2
3
4
5
6
7
8
9
MANAGEMENT POLICY = First Fit       POOL SIZE = 512 KB
SERIAL-NUM REQUEST SIZE ALLOC-ADDR TOTAL-FREE LARGEST-PART
1 alloc 20000 0 504288 504288
2 alloc 100000 20000 404288 404288
3 alloc 5050 120000 399238 399238
4 free 100000 499238 399238
5 alloc 70500 20000 428738 399238
6 free 20000 0 448738 399238
7 alloc 400000 -1 448738 399238