Project 5A: Memory Allocation Policies- MaUFiX (Option A)
Assignment Day | November 09, 2016 (Wednesday - midnight) |
Due Date | November 29, 2016. (Tuesday before class) |
Collaboration Policy - Read Carefully
You may work on this project with a partner, and you are encourage to discuss the assignment with other students or teams on the email list. You may consult (but not copy) any outside resources you including books, papers, web sites and people (but no penguins or sea urchins).
All team members need to provide the name of their partner in their partner.txt file (and say "none" if there is no partner).
If you use resources other than the class materials, indicate what you used along with your answer.
You have probably guessed it by now - every project will have a similar paragraph to the one above but with slight variations, of-course.
If you work on your own - you will get a 5% bonus provided that your base grade is above 60%). As this will require more effort.
Lessons to date: 1) Participate on the google MINIX group, it is a fantastic resource, 2) Use google - you won't get penalized - it is a win-win tool 3) Use the class list, but to get a reply - be courteuous and outline what resources you have tried before posting, e.g., I tried searching on google for "add a server to MINIX", I posted on the google MINIX but I did not get a reply 4) MISC - IF you do work on a team - and get stuck - try to use your partner's set-up, backup frequently - your kernel will crash - and it will crash often.
Objective:
The main goal for this project is to modify the MINIX 3 memory system to implement several different allocation strategies: first fit (done), next fit, worst fit, best fit, and random fit.
Now - in order to implement this project you need to downgrade to MINIX version 3.1.2 so the files modifed, data structures are the same. It is available (here). So when the description refers to current it refers to version 3.1.2.
(it is possible that the later 3.1.3a may work too).
You must implement:
- A system call to select the allocation algorithm.
- The various allocation algorithms.
- A user process to collect and process statistics.
You will run a synthetic workload to evaluate the performance of the allocation algorithms that you have developed (this is available as a link below)
Just like the previous project you will experiment with operating system kernels, and to do work in such a way that may very well crash the (simulated) computer. You'll get experience with modifying a kernel, and may end up with an OS that doesn't work, so you'll learn how to manage multiple kernels, at least one of which works.
Basics
The goal of this assignment is to give you additional experience in modifying MINIX 3 and to gain some familiarity with memory management. In this assignment you are to implement ALL allocation policies: first fit (which is already done, but will need to be made to live peacefully with the new algorithms), next fit, worst fit, best fit, and random fit.
You can find discussions of these algorithms in either the text book (or in just about any other operating systems text). Briefly, first fit chooses the first hole in which a segment will fit, starting its search from the beginning of the free list each time (this is what MINIX 3 currently uses); next fit is the same as first fit, except the search starts from the last hole you picked; best fit chooses the hole that is the tightest fit; and, conversely, worst fit chooses the hole that is loosest fit; random fit chooses a random hole among those that the page will fit into, you can design any algorithm you would like to manage and select the random hole.
You need to implement a system call that will allow the selection of the allocation policy. Note that the policy has a global effect on the system, since it applies to all processes. Such a system call should only be executable by root, so you should check the effective uid of the process making the call. The default policy should be first fit.
Details
In this project, you will modify the memory allocation policy for MINIX. The current MINIX allocation policy is simple: it implements first fit only. Changing this policy should mostly involve modifying code in servers/pm/alloc.c (All of the source code, except where specified explicitly, is in /usr/src).
There needs to be a system call to select the allocation policy. You may create your own system call or modify an existing system call. Your design document should contain the details of how you're going to implement this.
You will implement a user process that will gather statistics regarding the number and the size of the holes. You can get this information via the system call getsysinfo (see servers/pm/misc.c). You should gather this information once per second and compute the number of holes, their average size, the standard deviation of their size, and the median of their size. This information will be printed to a file in the following format:
"%d\t%d\t%.2f\t%.2f\t%.2f\n", t, nholes, avg_size_in_mb, std_dev_size_in_mb, median_in_mb
Your program should take one argument: the name of a file to print to. You should use fopen and fprintf to print the lines to the log file. The value for t should start at 0, and increment each time a line is printed.
This experiment wouldn't be much fun without a workload. Since memory allocation in MINIX is pretty much static (pre-allocated data segment sizes), Prof Long's class created a set of programs for you that will use differing amounts of memory. The main program, memuse, will fork off a bunch of other processes that use memory in differing amounts for varying amounts of time. Feel free to modify the code if you like. Further details on specific experiments to run will follow shortly; we will supply specific workloads for you to run against all three (or more) memory allocation algorithms.
Deliverables
You must hand in a compressed tar file of your project directory, including your design document. You must do a "make clean" before creating the tar file. In addition, you should include a README file to explain anything unusual to the teaching assistant. Your code and other associated files must be in a single directory; the TA will copy them to his MINIX installation and compile and run them there. You should have two subdirectories in your tar file below your main directory: one containing the kernel source files from the servers/pm directory, and the other containing your user program.
Do not submit object files, assembler files, or executables. Every file in the tar file that could be generated automatically by the compiler or assembler will result in a 5 point deduction from your programming assignment grade.
Your design document should be called design.txt (if plain ASCII text, with a maximum line length of 75 characters) or design.pdf (if in Adobe PDF), and should reside in the project directory with the rest of your code. Formats other than plain text or PDF are not acceptable; please convert other formats (MS Word, LaTeX, HTML, etc.) to PDF. Your design document should describe the design of your assignment in enough detail that a knowledgeable programmer could duplicate your work. This includes descriptions of the data structures you use, all non-trivial algorithms and formulas, and a description of each function including its purpose, inputs, outputs, and assumptions it makes about the inputs or outputs.
Hints
- START EARLY! You should start with your design, and check it over with the course staff.
- Experiment! You're running in an emulated system—you can't crash the whole computer (and if you can, let us know...).
- You may want to edit your code outside of MINIX (using
your favorite text editor) and copy it into MINIX to
compile and run it. This has several advantages:
- Crashes in MINIX don't harm your source code (by not writing changes to disk, perhaps).
- Most OSes have better editors than what's available in MINIX.
- START EARLY!
- Look over the operating system code before writing your design document (not to mention your code!). Leverage existing code as much as possible, and modify as little as possible. For this assignment, you should write less than 100 lines of kernel code (unless you do extra allocation algorithms). You might also look at the kernel code to learn how to implement a system call by seeing how it's done already.
- Test your implementation. To do this, you might want to write several programs that consume various amounts of memory. Keep in mind that a smart compiler will optimize away an empty loop.
- Your allocation must be dynamically selected using a system call. That means the code for every policy must be part of the operating system.
- Did we mention that you should START EARLY!
This project doesn't require a lot of coding (typically fewer than 200 lines of code), but does require that you understand how to use MINIX and how to use basic system calls.
You should do your design first, before writing your code. To do this, experiment with the existing shell template (if you like), inserting debugging print statements if it'll help. It may be more "fun" to just start coding without a design, but it'll also result in spending more time than you need to on the project.
IMPORTANT: As with all of the projects this quarter, the key to success is starting early. You can always take a break if you finish early, but it's impossible to complete a 20 hour project in the remaining 12 hours before it's due....
Submitting:
Submitting:
|
Design Document:
Your design document should describe the design of your assignment in enough detail that a knowledgeable programmer could duplicate your work. This includes descriptions of the data structures you use, all non-trivial algorithms and formulas, and a description of each function including its purpose, inputs, outputs, and assumptions it makes about the inputs or outputs. A sample design document is available here.