EECS678 Project 3 - Buddy

如有需要,请联系vx: codingtutor

Introduction
The operating system needs to manage the memory usage, knowing which memory has been allocated and to who. In this project you will implement a Buddy memory allocation which will be used in a simulator to keep track of free pages of memory.

There are several files given to you:

Files:
buddy.c and buddy.h: Files associated with the Buddy memory allocator. These two files are where you will do all of your work for this project.
list.h: Implementation of a list data structure nominally a part of the linux kernel.
Makefile: Associated Makefile for the lab. Need to change STUDENT_LASTNAME variable to your (and your partner’s) last name(s). Used for making submission file as well as testing your script.
project3-Description: A more in-depth explanation of the Buddy Memory Allocation.
run_tests.bash: Bash script to run the test cases.
simulator.c: You should not edit this file. This file is the discrete event simulator that, when ran, will interact with your buddy library. You can find more information on how to run this at the end of this web page. This file will be replaced by our autograder, so any changes you make will be ignored.
test-files/test_sample*.txt and test-files/result_sample*.txt: There are two given examples where test_sample*.txt is the input and result_sample*.txt is the resulting output. You are free to write more example tests for testing but you will be graded on a pool of tests not given to you.
Compile and Run
To only compile the buddy allocator use:
$ make
To generate this documentation in HTML use:
$ make doc
To run the buddy executable use:
$ ./buddy < test-files/test_sample.txt
What to Implement
Allocation
void* buddy_alloc (int size);
On a memory request, the allocator returns the head of a free-list of the matching size (i.e., smallest block that satisfies the request). If the free-list of the matching block size is empty, then a larger block size will be selected. The selected (large) block is then splitted into two smaller blocks. Among the two blocks, left block will be used for allocation or be further splitted while the right block will be added to the appropriate free-list.
Free
void buddy_free(void *addr);
Whenever a block is freed, the allocator checks its buddy. If the buddy is free as well, then the two buddies are combined to form a bigger block. This process continues until one of the buddies is not free. How to find buddy and check if the buddy is free? Suppose we have block B1 of order O, we can compute the buddy using the formula below.
B2 = B1 XOR (1 << O)
We provide a convenient macro BUDDY_ADDR() for you.
Testing
Be sure you thoroughly test your program. We will use different test files than the ones provided to you. We have provided a simple test case to demonstrate how to write the test cases. We have also provided a testing script runtests.sh which will run all of your test files in the test-files directory. To execute all of your tests in that directory, simply use either:
$ make test
or
$ ./run_tests.sh
All test files must be located in the test-files directory and have the prefix “test_” (i.e. test_sample2.txt). The file test_sample2.txt has the following lines in it:
a = alloc(44K)
free(a)
This test case allocates a 64 kilo-byte block of memory and assigns it to the variable ‘a’. If the ‘K’ in the size argument is removed, then this call will only request 44 bytes. This test case then releases the block that is assigned to ‘a’ with the free command. Variable names can only be one character long, alphabetic letters. Output must match exactly for credit. We have provided some sample output from our implementation in the test-files directory. All files that you wish to compare tests against should be located in the test-files directory and must match the name of its corresponding test file with the prefix “result_” instead of “test_”. These result files should be manually created by hand. Nothing you add to the code should print to standard output by the time you submit the project.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值