4600  - Operating Systems, Summer 2000
Project 4 - Minix Memory Management


- --------------------------------------------------------------------------
                 PROJECT DUE DATE:  August 4th at 2pm

   PLEASE NOTE THAT THIS ASSIGNMENT IS DUE AT THE BEGINNING OF CLASS ON
   THE DATE STATED ABOVE.  YOU MUST TURN IN YOUR PROJECT REPORT AT THIS
   TIME.  NO PROJECTS SLID UNDER THE OFFICE DOOR WILL BE ACCEPTED.
- --------------------------------------------------------------------------


PROJECT DESCRIPTION
- --------------------------------------------------------------------------
The purpose of this project is to learn how Minix allocates and frees
memory for processes.  We will be modifying Minix to perform a more
thorough search for available memory when attempting to EXEC a new
process.

Before beginning this project, it is recommeded that you:

    o  Perform a minix_backup to save your old project files
    o  Perform a minix_DESTROY to remove all old Minix files
    o  Perform a minix_setup to install a fresh copy of Minix
    o  Read section 4.7.5 of your textbook and examine the code
       in /src/mm/exec.c and /src/mm/alloc.c to fully understand
       how Minix currently implements memory allocation.

When a process forks in Minix, a copy of the process's data and stack
segments are made for the child process.  A text segment is not needed as
it is shared with the parent.  When a process performs an exec system
call, however, Minix must determine the size of the new program (text,
data, and stack) and allocate memory for this new program.  Currently,
Minix checks to see if there is enough memory for the new program before
releasing the memory currently held by the process.  However, since the
current process is performing an exec, the memory currently held by this
process will not be needed upon completion of the exec call.

You are to modify Minix to include the memory currently held by a process
performing an exec as part of the available memory for the new program.
This is exercize 4.26 in your textbook.

A simple solution to this problem might be to release the current
process' memory before testing for an adequate hole, but if there was
still not a large enough hole for the new process to execute, there
would be no process to return to since we released its memory.  This
solution is therefore inadequate.

Take note of adjacent holes and the ability to merge adjacent holes when
developing your solution.

When you have successfully completed this project, Minix will be capable
of exec'ing larger processes than it could before.  To test your solution,
two test programs are provided.  Copy each of these to your /src/tools
directory and compile them with mcc.  Then sunread both of them into Minix
and run 'project4'.  If your solution is correct, you will see too_big
executing while project4 waits for it.  If your solution is wrong, you
will receive an EXEC error.

To help you complete this project, here's a list of the files
you will either need to modify or create to complete this project:

/src/tools/project4.c (provided below)
/src/tools/too_big.c  (provided below)
/src/mm/exec.c
/src/mm/alloc.c

NOTE: Depending on your solution, you may find it necessary to modify
additional files not listed here.

==========================================================================
You must do your project independently.  No copying of code will be
tolerated.  Copying will result in a grade of zero, and will be reported
to the student honor court.
==========================================================================



TEST PROGRAM (project4.c)
- --------------------------------------------------------------------------
#include  /* (errno.h) */
#include  /* (stdio.h) */

int array[1000][200];

int main() {

    int result, status;

    printf("project4 forking...\n");
    result = fork();

    if (result > 0) {
        printf("project4 waiting...\n");
        waitpid(result, &status, 0);
        printf("project4 done.\n");
    } else if (result < 0) {
        printf("fork failed.\n");
    } else {
      result = execl("too_big", "too_big", (char *) 0);
      printf("EXEC FAILED: %s\n",
          (errno == EAGAIN)? "NOT ENOUGH MEMORY": "ERROR");
    }
}


TEST PROGRAM (too_big.c)
- --------------------------------------------------------------------------
#include   /* (stdio.h) */

int array[1000][256];

int main() {
    printf("+ too_big created.\n");
    printf("+ too_big sleeping...\n");
    sleep(2);
    printf("+ too_big done.\n");
}


PROJECT REPORT REQUIREMENTS
- --------------------------------------------------------------------------
The report should consist of three parts:

Part 1: Describe any errors in your program and their locations in the
        code.  This is very important for partial credit.  If the program
        does not run, your description of the errors may be the only way
        to get partial credit.  You MUST use the report in conjunction
        with the code printout to describe the location of both logical
        and/or semantic errors that are stopping the code from running.
        If you are unsure what the error is, please state so. If there is
        any part of the assignment that you have not completed, please
        note so clearly in the report (even if your program runs).  If
        your program runs perfectly and is complete, then simply note
        that.

        If we find an error or incomplete program that was not described,
        it will result in additional LOST POINTS (not just for the error,
        but also for not mentioning it).

Part 2: Provide a printout of your code.  It is suggested that you use
        the output generated by minix_diff as your code listing.

Part 3: Provide a printout of a sample execution of your program.
        To capture the output, use the "script" command as follows:

          o  Go to your Minix src/tools directory
          o  Issue the command "script project.out" and press enter
          o  Run Minix as usual (sunread, execute your program, etc.)
          o  Exit Minix
          o  Issue the command "exit" and press enter

        This will generate a file in your src/tools directory named
        project.out that contains a log of your Minix session.



ADDITIONAL REQUIREMENTS
- --------------------------------------------------------------------------
In order to receive full credit for this assignment, you must do the
following (in addition to getting the program working correctly and
writing the report):

You must put your full name and CISE username on the front page of your
report.  If you have a cover page, put it on the cover page.  If you do
not have a cover page, put it at the top of your report page.  In any
event, your name and username must be clearly visible on the front page.

You must compile Minix and your test programs prior to the deadline.  Your
compiled programs should be named 'project4' and 'too_big' and your source
code should be named 'project4.c' and 'too_big.c' and should be placed in
your /src/tools directory.

You must comment your code to the extent that someone who is not familiar
with your code can understand what your program does (in other words,
comment everything, and comment thoroughly).  It is important that your
code be distinguishable from code previously existing in Minix.  You MUST
encapsulate your changes in comments marking the beginning and end of the
changes, such as:

/* BEGIN PROJECT X MODIFICATIONS */  (replace X with project number)

/* END PROJECT X MODIFICATIONS */

Remember, you must comment your code IN ADDITION to encapsulating your
code in the BEGIN and END comments.



PROJECT UPDATES AND CHANGES
- --------------------------------------------------------------------------
>From time to time it is necessary to make updates or changes to project
assignments.  If this is deemed necessary, the changes will be mentiond
during the next lecture session, emailed to all students on the cop4600
mailing list, and posted on the class web page.



RUNAWAY MINIX PROCESSES
- --------------------------------------------------------------------------
PLEASE NOTE: Sometimes Minix will not exit properly and you will end up
with 'runaway' minix processes.  This irritates the system group
immensely, and they will begin banning you from CISE machines if you do
not 'clean up' your runaway minix processes.  To do this, follow these
instructions:

1) type  "ps -u $user"
       This will show you all processes you are running on the machine
       you are logged into.  If you see some listed as 'minix', follow
       the next instruction.  If there are no 'minix' processes running,
       you may safely log out.

2) type "kill -9 "
       Where  is the PID of the running minix process.  It is the
       (usually four digit) number in the first column of the ps output.

For example:

> ps -u $user
   PID TTY      TIME CMD
  3010 pts/15   0:01 tcsh
  3855 pts/15   0:04 minix
  3922 pts/17   0:01 tcsh
> kill -9 3855

Always do this before you log out.



GRADING GUIDELINES
- --------------------------------------------------------------------------
1. Report (10%)

   Your report must be clear and concise.  Points will be deducted for
   errors in your program that were not reported or for failure to
   include all three parts of the report.

2. Style (10%)

   The programming style must show readability of your program.  Thus,
   it must be well-organized.  We'll look for how well you use comments,
   how well you modularize the program, how meaningful the use and
   naming of constants and variables are, which variables should be
   global or local, etc.

   When modifying Minix, style is very important.  Make your code look
   similar to the original Minix code, but add many more comments.
   You should use highly visible comments that separate the code you
   add to Minix from the pre-existing code, as well as line-by-line
   comments describing the code you add (excluding simple statements).

3. Functionality (80%)

   It is very important that Minix and your program compile.  If they
   do not compile without errors, your program will be considered
   non-functional.

   NOTE: If your program compiles but you did not make an effort to
   implement most of the features required, your program is still
   incomplete.  In other words, turning in a program that technically
   compiles but performs none of the functions requested is not
   permitted.

   If the program compiles but doesn't run we will use the report to
   understand the errors and give partial credit.

   If your program compiles and runs, we will test it according to the
   project description and give you points based on how well you
   implemented all that was required.



HOW TO SUBMIT YOUR PROJECT
- ------------------------------------------------------------------------
This project is due at the beginning of class on the date given at the top
of this description.  You must compile Minix and your test program(s) by
the deadline.  Make certain your test program(s) is/are named correctly
(see above).  We will archive your Minix directory soon after the
deadline.  You must stop work on your project at the time class begins.
We will use a script to check the timestamps on your files.

Additionally, you must turn in your report (described above) by the
project deadline.  You must turn in your report to the instructor during
class.  Please do not slide projects under the office door.

IMPORTANT:  It is important that you do not access your Minix files or
            directories after the project deadline until instructed to do
            so by the TAs or instructor.  All Minix directories will be
            archived after the deadline, and we will check file timestamps
            to make certain no files were modified after the deadline.