Storage Management Labs

Source: Internet
Author: User

First, the purpose of the experiment

Continuous memory allocation forms many "fragments", although many fragments can be stitched together into usable chunks of space through a "compact" approach, with a significant overhead. If you allow a process to be loaded directly into many non-contiguous partitions, you do not need to be "compact". Based on this idea, a discrete distribution method is produced.

If the base unit of a discrete allocation is a page, it is called paging storage management, and if the base unit of a discrete allocation is a segment, it is called a segmented storage management method.

In the way of paging storage management, if the page redemption function is not available, it is called basic paging storage management, or pure paging storage management, it does not have the function of supporting virtual memory, it requires that each job is loaded into memory to run.

This experiment through the program simulation operating system basic paging storage management, further understand the principle and characteristics of this memory allocation method, deepen the mastery of theoretical knowledge.

Second, the experimental requirements

1, the C language or the Java language program to simulate the operating system of memory basic paging storage Management mode

2, the program to be able to properly "memory" for "allocation" and "recycling", can accept user input, display memory allocation, and have a certain degree of fault-tolerant ability.

3, each person completes the experiment content independently on time.

Third, the experimental method

#include <iostream>#include<iostream.h>#include<iomanip.h>#include<ctype.h>#defineN 6#defineM 4struct{    intLnumber; intFlag; intPnumber; intwrite; intDnumber;} Page[n];intP[m];inthead;voidInitialvoid); Intdo_mmap (int);voidDo_page_fault (int);voidRun_first_instructon (int);voidRun_a_instruction (int);voidPrint_page_and_fifoqueue (void); main () {intladdress,paddress; intLnumber,ad,pnumber;    Print_page_and_fifoqueue (); Run_first_instructon (0x0000); cout<<"Enter the logical address of the next instruction (0~32767) ( -1 to end)"<<Endl; CIN>>laddress;  while(laddress>32767) {cout<<"input Error! Please re-enter the logical address of the next instruction (0~32767) ( -1 to end)"<<Endl; CIN>>laddress; }     while(laddress!=-1) {Lnumber=laddress>>Ten; Lnumberif(page[lnumber].flag==1) {paddress=Do_mmap (laddress); cout<<paddress<<"output the converted physical Address"<<Endl;         Run_a_instruction (paddress); cout<<"this directive executes whether to modify the page lnumber="<<lnumber<<"(y/n?)"; CharChange ; CIN>>Change ; if(ToLower (change) = ='y') {Page[lnumber].write=1; Print_page_and_fifoqueue (); }         }          Else{cout<<lnumber<<"output The page number of the page--indicates that the hardware generated a fault"<<Endl;          Do_page_fault (Lnumber); Continue; } cout<<"Enter the logical address of the next instruction ((0~32767), -1 to end) \ n"; CIN>>laddress;  while(laddress>32767) {cout<<"worse (0~32767) ( -1 to end)"<<Endl; CIN>>laddress;} } cout<<"process run end!"<<Endl; System ("PAUSE"); return 0; } voidInitialvoid) {     inti;  for(i=0; i<=5; i++) {Page[i].lnumber=i; if(i<=m-1) {cout<<"Enter the page number as"<<i<<"physical block number of the memory (pre-loaded in the first four pages):"; CIN>>Page[i].pnumber; Page[i].flag=1; }} head=0;  for(i=0; i<=m-1; i++) P[i]=i;} Voidprint_page_and_fifoqueue (void) {    inti; cout<<"Output Page Table! \ n"; COUT&LT;&LT;SETW (Ten) <<"Lnumber"&LT;&LT;SETW (9) <<"Flag"&LT;&LT;SETW (Ten) <<"Pnumber"&LT;&LT;SETW (Ten) <<"Write"&LT;&LT;SETW (Ten) <<"Dnumber"<<Endl;  for(i=0; i<=n-1; i++) cout&LT;&LT;SETW (7) &LT;&LT;PAGE[I].LNUMBER&LT;&LT;SETW (Ten) &LT;&LT;PAGE[I].FLAG&LT;&LT;SETW (Ten) &LT;&LT;PAGE[I].PNUMBER&LT;&LT;SETW (Ten) &LT;&LT;PAGE[I].WRITE&LT;&LT;SETW (Ten) <<page[i].dnumber<<Endl; cout<<"output FIFO pair column: \ n"; cout&LT;&LT;SETW (Ten) <<"NO"&LT;&LT;SETW ( +) <<"Page (lnumber in main memory) \ n"; cout<<"head="<Endl; for(i=0; i<=m-1; i++) cout&LT;&LT;SETW (Ten) &LT;&LT;I&LT;&LT;SETW ( the) <<p[i]<<Endl;} Intdo_mmap (intladdress) {intlnumber, ad, Pnumber, paddress; Lnumber=laddress>>Ten; ad=laddress&0x3ff; Pnumber=Page[lnumber].pnumber; paddress=pnumber<<Ten|ad; returnpaddress;} Voidrun_a_instruction (intpaddress) {cout<<paddress<<"output Physical Address--Indicates completion of instruction execution"<<Endl;}  Voidrun_first_instructon (intladdress) {intlnumber, ad, Pnumber, paddress; Lnumber=laddress>>Ten; if(page[lnumber].flag==1) paddress=Do_mmap (laddress); cout<<paddress<<"output the converted physical Address"<<Endl;  Run_a_instruction (paddress); cout<<"whether this directive executes (0x0000) modifies the page that is located lnumber="<<lnumber<<"(y/n?)"; CharChange ; CIN>>Change ; if(ToLower (change) = ='y') {Page[lnumber].write=1; Print_page_and_fifoqueue (); } cout<<"******** The first instruction execution is completed (address 0x0000) ***********"<<Endl;} Voiddo_page_fault (intlnumber) {intJ; J=P[head]; P[head]=Lnumber; Head= (head+1)%M; if(page[j].write==1) Write_to_harddisk (j); Page[j].flag=0; Page[lnumber].flag=1; Page[lnumber].write=0; Page[lnumber].pnumber=Page[j].pnumber;cout<<lnumber<<"output This page-indicates that the page is in main memory"<<Endl;cout<<"Press any key to view page table Page[n] and FIFO queue information after page substitution"<<Endl; System ("PAUSE"); Print_page_and_fifoqueue (); }

Iv. Summary of the experiment

Experiment is difficult to understand, because of learning too much knowledge, and can not learn everything, I hope I can slowly in-depth understanding.

Storage Management Labs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.