OS Project Requirements

Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due

OS Project Requirements
Semester 2 2023-2024

Attention: This is a teamwork. The contribution of each member will be put in the excel file released with this document. You must write the code alone by yourself, no talking with friends not in your group, no copying from the Internet or other resources. If a group copies any piece of code from another group, both groups are given 0, no matter whether the copied one knows or not. It is student’s responsibility to prevent his work from being copied.

Please read the whole document before you start.

Requirements
This project will involve designing a program simulating the management of virtual memory. You should do this project on a computer running on a Linux system.

This project translates logical addresses to physical addresses for a virtual address space of size 216 = 65,536 bytes. Your program will

1) read from a file containing logical addresses and,
2) translate each logical address to its corresponding physical address, according to inputted frame size and total number of frames in physical memory, and
3) output the value of the byte stored at the corresponding physical address.

In the process of translation from the logical address to physical address, following issues are considered:

1) TLB (TLB hit, TLB miss),
2) page table (page reference, page fault),
3) page-replacement, and
4) pure demand paging

Assumptions:

1) TLB: 16 entries.
2) Only one process is considered, no multiple processes.
3) Memory page replacement algorithm: FIFO
4) Pure demand paging is considered
5) Use arrays to simulate TLB, page table, and memory.
6) Backing store will not use memory to simulate. Simply use backstore.bin file as the backing store.
Materials
Several files used in the project are provided.
1. Project requirements document
2. addresses.txt: A file that contains logical addresses which simulate the stream of addresses generated from CPU. This file is a text file.
3. backingstore.bin: A file that contains the contents of a process in its logical space. The first data has the logical address 0. At most 216 bytes are included in this file.
Guidelines
1. Input frame size (use number of bits to represent) and total number of frames in physical memory.

The inputs should satisfy the following three conditions:

i. Total size of physical memory must be power of 2.
ii. The size of physical memory must be smaller than logical space in this project.
If the inputs do not satisfy any of these conditions, a warning message is given and system should require the user to input again.
Suggestion: You can try with fixed frame size and memory size first in the project and then generalize your work.

2. Decide the bits used for page no.

After the user inputs the frame size, you can now decide the bits used for page no. In this project, the virtual address space of size 216 = 65,536 bytes. If the user inputs 10 as the number of bits to represent frame (page) size in Guidelines 1, then 6 bits represent page no. Refer to the following diagram from the lecture slides (ch9-slide 28). [Hint: You can use unsigned short int as the type of logical address.]
3. Decide the page table size

This can be determined after the bits for page no. is known. The page table should be initialized so that the valid-invalid bits are i (you do not have to really put i there. You can define a value to indicate invalid) for all entries at the beginning because no pages have been loaded into memory at the beginning.Page 3 of 5

4. Translate the logical addresses to physical address following the steps below until all the addresses in addresses.txt have been visited.
1) Read an address from address.txt
2) Check if the page no. is in TLB (at beginning, TLB is also empty. It should be initialized too), if not, go to step 3); otherwise do the translation. Give the following output:

[TLB] (LA) logical address -> (PA) physical address: data

Where logical address, physical address and data should be replaced with the corresponding values. Data is the data stored in that physical address. Data is of one byte, so you can define data to the of char type. Addresses are in decimal format. Same requirements apply for other outputs.
3) Check the page table. If valid-invalid bit is i, go to step 4); otherwise, do the translation. Give the following output:

[Page Table] (LA) logical address -> (PA) physical address: data

Where logical address, physical address and data should be replaced with the corresponding values. Then update TLB to include this page. Use FIFO policy here to replace a page no. and its frame in TLB.

4) Page is not in memory. If there is no free frame in memory, go to step 5); otherwise, according to logical address, find the corresponding page in backingstore.bin, load the whole page into a free frame in the memory.

Memory is allocated from low address to high address. Give the following output (please set indentation before the following output, replace ‘\t’ with 4 spaces): \t [Load Page] Page page no. -> Frame frame no.

Where page no. and frame no. should be replaced with actual number. Then update page table and TLB (Use FIFO policy to replace a page no. and its frame in TLB). Go back to Step 2).

Refer to following diagrams for the workflow.

ch9-slide 38
Ch10-slide 15
5) No free frames are in the memory. Use FIFO algorithm, replace a page in memory with the new one. Give the following output (replace ‘\t’ with 4 spaces): \t [Replace page] Frame frame no.: Page replaced page no. -> Page loaded page no.

where frame no., replaced page no., and loaded page no. should use actual numbers. Refer to FIFO example in the slides ch10-slide 34 for the replacement algorithm. Then update page table. If the replaced page is in TLB, it will be replaced by the new one (not FIFO here). [Hint: The replaced page in

TLB now might not be the oldest one]. Go back to Step 2).
5. Beside the above required outputs, in the end, your program needs to generate a file stat.txt including the following information:
1) page-fault rate — The percentage of page faults.
2) TLB hit rate — The percentage of TLB hits.
3) Memory image -- give the page numbers which are stored in memory. Each row contains 16 frames. The format refers to the given sample.
stat.txt format sample:
page-fault rate: 1.0
TLB hit rate: 0.0
Memory image:
Frame 0 ~ Frame 15: 11 22 33 44 55 66 77 88 99 0 12 23 34 45 56 67
Frame 16 ~ Frame 31: 78 89 90 1 21 31 41 51 61 -1 -1 -1 -1 -1 -1 -1
……
Note: -1 means no page is loaded into that frame.
6. Run the program
Since the output contains a lot of information, you can output the results to a file.
Suppose your file name is mmu.c, and you compile the file using the command
$ gcc -o mmu mmu.c
then you can run the program in the following way
$ ./mmu > output.txt
Then the output of the program will be in a file output.txt.
Non-Functional Requirements
Your program must follow the non-functional requirements below.
1. Use fopen(), fread(), fseek(), and fclose() to search and read a page from backingstore.bin.
2. Your program can include stdio.h and stdlib.h. You can also include .h that you Page 5 of 5 have defined by yourself. No other standard libs are included.
3. The program should be modularized with multiple functions, e.g, you can define functions checkTLB, updateTLB, checkPageTable, updatePageTable, loadPage, replacePage and so on.
Submission
1. You should submit .c and .h files (if you have defined .h file) only.
2. Fill in the attached excel file for the contribution of each member.

发表评论

电子邮件地址不会被公开。 必填项已用*标注