1. Data Structure of the page table
Page number |
Flag |
Primary storage block number |
Modify bit |
External Store address |
Struct pageitem {unsigned pageid; // The Job page number unsigned outmaddr; // The address bool state where the page is stored; // whether the page is transferred to memory. If not, the blockid and modify fields are invalid. Unsigned blockid; // The physical memory block number bool modify corresponding to the page; // whether the page has been modified };
Initial page table structure:
0 1 5 011 11 1 8 012 12 1 9 013 03 1 10 015 04 0 0 017 05 0 0 025 06 0 0 212 07 0 0 213 0
2. Command Data Structure
Operation |
Page number |
Unit number (offset) |
struct Instruction{ string OPC; unsigned OPAPageID; unsigned OPAUnitID;};
Command sequence table:
+ 0 040 + 1 050*2 016 storage 3 022 take 0 054-6 040 shift 4 052 + 5 022 storage 1 034 take 7 056 + 4 002 take 6 076
3. Address Translation Algorithm
4. webpage disconnection mechanism Algorithm
Use the FIFO replacement algorithm. The flowchart is as follows:
Queue Entry and Exit:
Page Orientation |
0 |
1 |
2 |
3 |
0 |
6 |
4 |
5 |
1 |
7 |
4 |
6 |
Page |
0 |
0 |
0 |
0 |
|
1 |
2 |
3 |
6 |
4 |
|
5 |
|
1 |
1 |
1 |
|
2 |
3 |
6 |
4 |
5 |
|
1 |
|
|
2 |
2 |
|
3 |
6 |
4 |
5 |
1 |
|
7 |
|
|
|
3 |
|
6 |
4 |
5 |
1 |
7 |
|
6 |
5. source program
# Define_crt_secure_no_warnings # include <iostream> # include <queue> # include <vector> # include <string> # include <cassert> usingnamespace STD; const intpage_number = 8; // Number of pages occupied by the job const intblock_number = 4; // The maximum number of parts allocated to the job by the system const intblock_size = 64; // structpageitem {unsigned pageid for each length of the primary storage; // The Job page number unsigned outmaddr; // The address bool state where the page is stored; // whether the page is transferred to the memory. If the page is not transferred to the memory, the blockid and modify fields are invalid. Unsigned blockid; // memory corresponding to the page Physical block number bool modify; // whether the page has been modified // default constructor pageitem (): pageid (0), blockid (0), State (false ), modify (false), outmaddr (0) {}// constructor pageitem (unsigned _ pageid, unsigned _ blockid, bool _ state, bool _ modify, unsigned _ outmaddr ): pageid (_ pageid), blockid (_ blockid), State (_ state), modify (_ modify), outmaddr (_ outmaddr) {}}; structinstruction {string OPC; unsigned opapageid; unsigned opaunitid;}; // define oqueue Block_numbervoidinterrupt (vector <pageitem> & pagetable, queue <unsigned> & fifoqueue, const unsigned visitpageid) {assert (batch oqueue. size () <= block_number); // If (batch oqueue. size () = block_number) // if the team is full, replace it with the value of {unsigned num = bytes oqueue. front (); // the page number of the queue header num pagetable [num]. state = false; If (pagetable [num]. modify) {cout <"page" <num <"modified, written back to disk" <Endl ;}cout <"Paging "<Num <" to disk "<Endl; Specify oqueue. pop (); pagetable [visitpageid]. blockid = pagetable [num]. blockid;} // pagetable [visitpageid]. outmaddr = // when the team is not satisfied, the physical block number cout allocated to the page should be provided based on the memory allocation algorithm <"Incoming page" <visitpageid <Endl; pagetable [visitpageid]. state = true; pagetable [visitpageid]. modify = false; encrypted oqueue. push (visitpageid); // actually the memory partition table should be modified} intmain (INT argc, char ** argv) {freopen ("cin.txt", "r", stdin ); vector <pagei TEM> pagetable (page_number); // The page table of the job in the memory <unsigned> queue oqueue; // The Block queue allocated by the system for the job, the element is the page number for (INT I = 0; I <page_number; ++ I) {CIN> pagetable [I]. pageid> pagetable [I]. state> pagetable [I]. blockid> pagetable [I]. outmaddr> pagetable [I]. modify; If (pagetable [I]. state) {queue oqueue. push (I) ;}} instruction INS; int CNT = 1; while (CIN> ins. OPC> ins. opapageid> ins. opaunitid) // specifies {cout <"Execution Command "<CNT ++ <Endl; unsigned visitpageid = ins. opapageid; // The access page number in the capture command, from Mar if (INS. opapageid> = page_number) {cout <! "<Endl; // should an exception be thrown? Return 1;} while (! Pagetable [visitpageid]. State) {cout <"generate page disconnection! "<Endl; interrupt (pagetable, kerberoqueue, visitpageid); // page missing Interrupt Processing // must be repeated? Visitpageid = ins. opapageid; // The access page number in the capture command, from Mar if (visitpageid> = page_number) {cout <"produces out-of-bounds interruption! "<Endl; // should an exception be thrown? Return 1 ;}} unsigned visitblockid = pagetable [visitpageid]. blockid; unsigned realaddr = visitblockid * block_size + INS. opaunitid; cout <"absolute address is" <realaddr <Endl; If (INS. OPC = "save") {pagetable [visitpageid]. modify = true;} cout <Endl;} return 0;}/* cin.txt: 0 1 5 01111 1 8 01212 1 01303 1 10015 04 0 0 01705 0 02506 0 0 21207 0 0 2130 + 0 040 + 1 050*2 016 storage 3 022 0 054 -6 040 shift 4 052 + 5 022 store 1 034 take 7 056 + 4 002 take 6 076 */
6. Running result
Execute Command 1 absolute address is 360 Execute Command 2 absolute address is 562 Execute Command 3 absolute address is 592 Execute Command 4 absolute address is 662 Execute Command 5 absolute address is 374 Execute Command 6 generate missing page interrupted! Page 0 has been modified, write back disk page 0 to disk page 6 absolute address is 360 Execute Command 7 generate page missing interruption! Page 1 was modified and written back to disk page 1 to disk page 4 the absolute address is 564 Execute Command 8, resulting in page-missing interruptions! Page 2 to disk transfer page 5 absolute address is 598 Execute Command 9 generate page-missing interruption! Page 3 was modified and written back to disk page 3 to disk transfer page 1 the absolute address is 674 Execute Command 10, resulting in page-missing interruptions! Page 6 to disk transfer page 7 absolute address is 376 Execute Command 11 absolute address is 514 Execute Command 12 generate page interruption! Page 4 to disk transfer page 6 absolute address is 588 press any key to continue...