Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
COMP30023: Computer Systems
Project 1: Process and Memory Management
Released: March 22, 2024
1 Background
2 Process Manager Overview
The process manager runs in cycles. A cycle occurs after one quantum has elapsed. The process manager has its own notion of time, referred to from here on as the simulation time. The simulation time (TS) starts at 0 and increases by the length of the quantum (Q) every cycle. For this project, Q will be an integer value between 1 and 3 (1 ≤ Q ≤ 3).
At the start of each cycle, the process manager must carry out the following tasks in sequence:
1. Identify all processes that have been submitted to the system since the last cycle occurred and add them to the process queue in the order they appear in the process file. A process is considered to have been submitted to the system if its arrival time is less than or equal to the current simulation time Ts.
2. Identify whether the process (if any) that is currently running (i.e., was given CPU time in the previous cycle) has completed its execution. If it has:
– The process’s state is updated (see Section 3)
– The process is removed from the process queue
– The process’s memory is deallocated
3. Determine the process that runs in this cycle. This decision is made based on the scheduling algorithm (round robin) and the memory allocation strategy. This step entails:
– Updating the state of the process that is currently running (if any) and the state of the newly allocated process (see Section 3)– Updating the process queue if needed
A detailed explanation of this stage is given for each task.
4. Increment the simulation time by Q seconds.
3 Process Lifecycle
2. A process is in a READY state after it has arrived (arrival time less than or equal to the simulation time). READY processes are considered by the scheduling algorithm as candidates to be allocated to the CPU.
3. The process that has been selected to use the CPU enters a RUNNING state.
4. After running for one quantum,
– If the process has completed its execution, the process is terminated and moves to the FINISHED state.– If the process requires more CPU time and there are other READY processes, the process transitions back to the READY state to await more CPU time.– If the process requires more CPU time and there are no other READY processes, the process remains in the RUNNING state and runs for another quantum.
4 Process Scheduling
4.1 Task 1: Round-Robin Scheduling with Infinite Memory
In round-robin scheduling, processes execute on the CPU one quantum at a time. The scheduler allocates the CPU to the process at the head of the process queue (i.e., the process enters the RUNNING state). After one quantum has elapsed, the process returns to the READY state, moves to the tail of the process queue, and the CPU is allocated to the next process in the queue (i.e., the new head of the queue).
There are two special cases in which a process does not transition from RUNNING to READY at the end of a quantum (as defined in Section 3):
1. There are no other processes in the queue, and the process requires more CPU time. The process remains in a RUNNING state and continues to use the CPU for another quantum.2. The process completed its execution. The process transitions to the FINISHED state and is removed from the process queue.
Note that, based on the order in which the process manager performs tasks (Section 2), a process that has exhausted its quantum is placed at the tail of the process queue after newly arrived processes have been inserted into said queue.
5 Memory Management
To accomplish this, you will extend the round-robin scheduler implemented in Task 1 to consider the memory requirements of a process before it is able to enter the RUNNING state. When it is a process’ turn to execute (as determined by the round-robin algorithm), the process manager must first allocate memory to the process by following one of the following strategies:
• Allocating a contiguous block of memory (Task 2)• Allocating all the pages of the process to frames in memory (Task 3)• Allocating a subset of the pages of the process to frames in memory (Task 4)
5.1 Task 2: Round-Robin Scheduling with Contiguous Memory Allocation
A process for which memory allocation cannot be currently met should remain in a READY state, and be moved from the head to the tail of the process queue. Within the same cycle, the scheduler must continue to iterate over the process queue until it finds a process that can execute (i.e., memory has been allocated). Note that it is only after a process has successfully transitioned from READY to RUNNING or when the process queue is empty that the process manager moves on to the next cycle, and hence, the next quantum.
- The memory capacity of the simulated computer is static. For this project, you will assume a total of 2048 KB is available to allocate to user processes.
- The memory requirement (in KB) of each process is known in advance and is static, i.e., the amount of memory a process is allocated remains constant throughout its execution.
- For simplicity, you will assume memory is addressed in blocks of 1 KB. Memory addresses in the system are therefore in the range [0..2048).
- When allocating a memory block, always allocate the block starting at the lowest memory address of a memory hole. For example, a block of 10 KB needs to be allocated. The identified memory hole (according to first-fit) is [10..30]. The memory block should then be allocated to addresses [10..19].
- Once a process terminates, its memory must be freed and merged into any adjacent holes if they exist.
1. The round-robin scheduler determines process p is the next process to be allocated to the CPU.
2. Before allocating the process to the CPU, the process manager checks whether p has been allocated memory.
(a) If p’s memory has already been allocated, p gets to use the CPU for the corresponding quantum.(b) If p’s memory has not been allocated, the process manager attempts to allocate a contiguous block.
i. If successful, p gets to use the CPU for the corresponding quantum.
ii. If the allocation is unsuccessful (i.e., there is no sufficient memory in the system at this time), p does not execute, remains in a READY state, and is moved to the tail of the process queue. The scheduler looks for another process to execute by returning to step 1.
5.2 Task 3: Round-Robin Scheduling with Paged Memory Allocation
This task assumes a paged memory system with swapping. The memory required by a process is divided into pages, and physical memory is divided into frames. Pages that are mapped to frames in memory are considered to be allocated.
Before a process runs on the CPU, all of its pages must be allocated to frames in memory. If there are not enough empty frames to fit a process’s pages, then pages of another process or processes need to be swapped to disk to make space for the process. When choosing a process to swap, you must choose the process that was least recently executed among other processes (excluding the current one) and evict all of its pages. If there is still not enough space, continue evicting all pages of other processes following the least-recently executed policy until there is sufficient space.
- • You will assume a total of 2048 KB is available to allocate to user processes.
- The memory requirement of each process (in KB) is known in advance and is static, i.e., the amount of memory a process requires, and hence the number of pages, remains constant throughout its execution.
- Once a process terminates, all of its pages must be evicted from memory (i.e., deallocated).
- The size of pages and frames is 4 KB.
- Each frame is numbered, starting from 0 and increasing by 1. For the assumed memory size of 2048 KB, there are 512 pages in total, with page numbers from 0 to 511.
- Pages should be allocated to frames in increasing frame number. For example, if a process requires 3 pages to be allocated, and frames 0, 1, 5, 8, and 9, are free (or were freed via swapping). The process pages must be mapped to frames 0, 1, and 5.
1. The round-robin scheduler determines process p is the next process to be allocated to the CPU.2. Before allocating the process to the CPU, the process manager checks whether p’s pages are allocated in memory.
(a) If p’s pages are allocated, p uses the CPU for the corresponding quantum.(b) If p’s pages have not been allocated and there are not enough free frames in memory, the process manager evicts the pages of one or more processes following the least-recently executed policy.(c) Once there are sufficient free frames in memory, the process manager allocates p’s pages and p runs on the CPU for the corresponding quantum.
5.3 Task 4: Round-Robin Scheduling with Virtual Memory Allocation
This task will assume a paged system with swapping similar to that in Task 3. However, we will now consider the case of virtual memory providing the illusion of a larger-than-available memory to processes.
You will now assume that a process does not need all pages to be allocated before it is allowed to execute. In this task, a process can be executed if at least 4 of its pages are allocated (or all pages in case of processes requiring less than 4 pages). If there are more than 4 frames available at the time of allocation(or reallocation), the process manager must allocate as many pages as possible.
For example, if a process requires 7 pages and there are 6 frames available, the process manager must allocate 6 of the 7 pages to the available frames. If a process requires 7 pages and there are 10 frames available, the process manager must allocate all 7 pages to the free frames.
Similar to swapping, if there are not enough empty frames for the process that is scheduled to be executed, pages of the least recently executed process need to be evicted one at a time until there are 4 empty pages (or less if the process requires less than 4 pages). The lowest numbered frames belonging to the least recently executed process must be evicted first. For example, if the least recently executed process was allocated frames 1,5,7,9, and 2 frames need to be evicted, frames 1,5 must be evicted. This is in contrast to Task 3, where all pages of the least recently executed process would be evicted.
- You will assume a total of 2048 KB is available to allocate to user processes.
- Once a process terminates, any allocated pages must be evicted from memory (i.e., deallo cated).
- The size of pages and frames is 4 KB.
- Each frame is numbered, starting from 0 and increasing by 1. For the assumed memory size of 2048 KB, there are 512 pages in total, with page numbers from 0 to 511.
- Pages should be allocated to frames in increasing frame number. For example, if a process requires 3 pages to be allocated, and frames 0, 1, 5, 8, and 9, are free (or were freed via swapping). The process pages must be mapped to frames 0, 1, and 5.
1. The round-robin scheduler determines process p, requiring n pages, is the next process to be allocated to the CPU.2. Before allocating the process to the CPU, the process manager checks whether p has at least 4 (n ≥ 4) or all (n < 4) pages allocated.
(a) If p’s page allocation requirements are met, p uses the CPU for the corresponding quantum.(b) If p’s page allocation requirements are not met and there are not enough free frames in memory, the process manager evicts just enough pages to meet the page allocation requirements of p following the least-recently executed policy.(c) Once there are sufficient free frames in memory, the process manager allocates p’s pages and p runs on the CPU for the corresponding quantum.
6 Program Specification
Your program must be called allocate and take the following command line arguments. The arguments can be passed in any order but you can assume that all the arguments will be passed correctly, and each argument will be passed exactly once.
Usage: allocate -f <filename> -m (infinite | first-fit | paged | virtual) -q (1 | 2 | 3)
-f filename will specify a valid relative or absolute path to the input file describing the processes.
-m memory-strategy where memory-strategy is one of {infinite, first-fit, paged, virtual}.
-q quantum where quantum is one of {1, 2, 3}.
The input file, filename, contains the list of processes to be executed, with each line containing a process. Each process is represented by a single space-separated tuple (time-arrived, process-name, service-time, memory-requirement).
- The file will be sorted by time-arrived which is an integer in [0, 2 32) indicating seconds.
- All process-names will be distinct uppercase alphanumeric strings of minimum length 1 and maximum length 8.
- The first process will always have time-arrived set to 0.
- service-time will be an integer in [1, 2 32) indicating seconds.
- memory-requirement will be an integer in [1, 2048] indicating KBs of memory required.
- The file is space delimited, and each line (including the last) will be terminated with an LF (ASCII 0x0a) control character.
- Simulation time will be an integer in [0, 2 32) indicating seconds.
In addition, no assumptions may be made about the length of the file name (filename).
You can read the whole file before starting the simulation or read one line at a time.
The allocate program is required to simulate the execution of processes in the file processes.txt using the round-robin scheduling algorithm and the infinite memory strategy with a quantum of 3 seconds.
The program should simulate the execution of 3 processes where process P4 arrives at time 0, needs 30 seconds of CPU time to finish, and requires 16 KB of memory; process P2 arrives at time 29, needs 40 seconds of time to complete and requires 64 KB of memory, etc.
7 Expected Output
In order for us to verify that your code meets the above specification, it should print to standard output (stderr will be ignored) information regarding the states of the system and statistics of its performance. All times are to be printed in seconds.
7.1 Execution transcript
• When a process runs on the CPU (this includes the first time and every time it resumes its execution):
– ‘time’ refers to the simulation time at which CPU is given to the process;– ‘pname’ refers to the name of the process as specified in the process file;– ‘rtime’ refers to the remaining execution time for this process;– ‘musage’ is a (rounded up) integer referring to the percentage of memory currently occupied by all processes, after pname has been allocated memory;– ‘addr’ is the memory address (between [0, 2048)) at which the memory allocation for pname starts at;– ‘frames’ is a list of frame numbers (given in increasing order) that are allocated to the current process, separated by commas.
In the case of infinite memory (Task 1, -m infinite), your program should not print out any information about memory allocation or usage. That is, mem-usage, allocated-at, and mem-frames should not be printed.
An example of the simplified output would be:
In the case of first-fit (Task 2, -m first-fit), your program should not print out the set of allocated frames. That is, mem-frames should not be printed.
In the case of paged (Task 3, -m paged) and virtual memory(Task 4, -m virtual), your program should not print out the memory allocation address. That is, allocated-at should not be printed.
An example of the simplified output would be:
20,RUNNING,process-name=P4,remaining-time=10,mem-usage=50%,mem-frames=[0,1,2]
In cases in which pages of more than one process are evicted, Only one EVICTED event should be printed. This means your program should never print two EVICTED events in two consecutive lines.
In the cases of infinite memory (Task 1, -m infinite) and first-fit (Task 2, -m first-fit), no EVICTED events should be printed.
7.2 Task 5: Performance Statistics
8 Marking Criteria
|
Task |
Marks |
|
Task 1: Round-robin + infinite memory (Section 5) |
3 |
|
Task 2: Round-robin + first-fit (Section 5.1) |
3 |
|
Task 3: Round-robin + paged memory (Section 5.2) |
3 |
| Task 4: Round-robin + virtual memory (Section 5.3) |
3 |
|
Task 5: Performance statistics (Section 7.2) |
1 |
|
Build quality |
1 |
|
Quality of software practices |
1 |
|
TOTAL |
15 |
Assessment of Tasks 1-5 Tasks 1, 2, 3, 4, and 5 will be assessed through automated testing. We will compile your code and run it against a set of test cases. We will compare the output produced by your program against the expected output of each test case. This is why it is essential that you follow the specification and produce output exactly as outlined in Section 7.1.
You will be given access to a subset of the test cases used to assess your project as well as their expected outputs. Half of the marks for Tasks 1-5 will be awarded based on this subset of visible test cases. The other half of the marks will be determined based on a different subset of hidden test cases not available to you.
Because we compile and run your code, it is a requirement that your code compiles and runs on the provided VMs and produces deterministic output. Code that does not meet these requirements cannot be assessed and hence will receive 0 marks (at least) for Tasks 1 - 5.
- The repository must contain a Makefile that produces an executable named “allocate”, along with all source files required to compile the executable. Place the Makefile at the root of your repository, and ensure that running make places the executable there too.
- Make sure that all source code is committed and pushed.
- Running make clean && make -B && ./allocate <...arguments> should execute the sub mission.
- Compiling using “-Wall” should yield no warnings.
- Running make clean should remove all object code and executables.
- Do not commit allocate or other executable files (see Practical 1). Scripts (with .sh extension) are exempted.
- The automated test script expects allocate to exit with status code 0 (i.e. it successfully runs and terminates).
Quality of software practices Factors considered include:
- Proper use of version control, based on the regularity of commit and push events, their content and associated commit messages (e.g., repositories with a single commit and/or noninformative commit messages will lose 0.5 marks).
- Quality of code, based on the choice of variable names, comments, formatting (e.g. con sistent indentation and spacing), and structure (e.g. abstraction, modularity).
- Proper memory management, based on the absence of memory errors and memory leaks.
9 Submission
Provide attribution in references.txt, and a copy (of the original versions) of both reused and external code in your submission, under an ext/ subdirectory. Code which we have provided on the LMS of this subject is exempt.
You may use standard libraries (e.g. to read files, sort, parse command line arguments2 etc.).
GitHub The use of GitHub is mandatory. Your submission will be assessed based using the code in your Project 1 repository (proj1-〈usernames...〉) under the subject’s organization.
We strongly encourage you to commit your code at least once per day. Be sure to push after you commit. This is important not only to maintain a backup of your code, but also because the git history may be considered for matters such as special consideration, extensions and potential plagiarism. Proper use of git will have a positive effect on the mark you get for quality of software practices.
1. Push your code to the repository named proj1-〈usernames...〉 under the subject’s organization, https://github.com/feit comp30023-2024.
Executable files (that is, all files with the executable bit that are in your repository) will be removed before marking. Hence, ensure that none of your source files have the executable bit.
Ensure your code compiles and runs on the provided VMs. Code that does not compile or produce correct output on VMs will typically receive very low or 0 marks.
3. Ensure that the commit that you submitted to the LMS is correct and accessible from a fresh clone of your repository. An example of how to do this is as follows:
git clone [email protected]:feit-comp30023-2024/proj1-<usernames...> proj1
Please be aware that we will only mark the commit submitted via the LMS. It is your responsibility to ensure that the submission is correct and corresponds to the commit you want us to mark.
For example, a submission made 1 hour after the deadline is considered to be 1 day late and carries a deduction of 2 marks.
Leaving it to the last minute usually results in a submission that is a few minutes to a few hours late, or in the submission of the incorrect commit hash. Either case leads to late penalties.
Forgetting to submit via the LMS or submitting the wrong commit hash will result in a late penalty that will apply regardless of the commit date.
We will not give partial marks or allow code edits for either known or hidden cases without applying a late penalty (calculated from the deadline).
You are required to submit supporting evidence such as a medical certificate. In addition, your git log file should illustrate the progress made on the project up to the date of your request.
10 Testing
Testing Locally: You can clone the sample test cases to test locally, from: feit-comp30023-2024/project1.
Continuous Integration Testing: To provide you with feedback on your progress before the deadline, we have set up a Continuous Integration (CI) pipeline on GitHub with the same set of test cases.
The requisite ci.yml file has been provisioned and placed in your repository, but is also available from the .github/workflows directory of the project1 repository linked above.
11 Team Work
12 Collaboration and Plagiarism
You cannot copy work from another another student or team. Do not share your code and do not ask others to give you their programs. Do not post your code on the subject’s discussion board Ed. The best way to help your friends in this regard is to say a very firm “no” if they ask to see your program. See https://academicintegrity.unimelb.edu.au for more information.
Note that soliciting solutions via posts to online forums, whether or not there is payment involved, is also Academic Misconduct. You should not post your code to any public location while the assignment is underway or prior to the release of the assignment marks.