Storage management of experimental five operating systems

Source: Internet
Author: User
Tags blank page

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.

Iii. contents of the experiment

This experiment assumes that the memory space has been divided into blocks, the target program does not care about the memory block size and other underlying details, simply by the algorithm to allocate memory blocks. The program should implement the following functions:

1, memory initialization. Assuming that there are N of memory blocks, the initialized memory space should be partially used, which can be done with random numbers or other algorithms inside the program.

2, the program should be able to accept user input process information, and allocate memory for it, return the allocation results (success or failure), note that here should consider the illegal input and processing accordingly.

3, the program can reclaim the memory space occupied by the user-specified process, therefore, the program may need to assign each process a unique process number and give detailed information.

4, can visually and reasonably display the memory allocation situation.

5, the program interface friendly, easy to operate and view the results of the operation.

Four. Experiment code

1#include <iostream>2 using namespacestd;3 #defineINVALID-1//defining struct Types4 structPl_type5{//Page Table Structure6     intPn//Page Number7     intfn//Page Frame number8     intTime//Access Time9  }; Ten     structFl_type One{//page Frame Structure A         intPn//Page Number -         intfn//Page Frame number -         structFl_type *next;//Link Pointers the     };  -         //Defining structure Variables -Pl_type pl[ +];  -Fl_type fl[ +],*free_head,*busy_head,*Busy_tail; +         intpage[ +];//access the string (the page number that holds each instruction) -         intTotal_pages;//Access String length +         intDiseffect;//number of page faults A         //Initialize function: Initialize page table and page frame chain at         //Parameter TOTAL_PF is the number of memory page frames assigned to the user process -         voidInitializeintTOTAL_PF) -         {     -             inti;  -diseffect=0;//page fault number initialized to 0 -         //Create a blank page table in          for(i=0;i< +; i++)   -         {          toPl[i].pn=i;//Page Number +Pl[i].fn=invalid;//The page frame number is-1, (at first, the page has not been loaded into the page frame) -pl[i].time=-1;  the}//Create an idle page frame chain *          for(i=0; i<total_pf;i++)    $         { Panax Notoginsengfl[i-1].next=&fl[i];//establish a link between fl[i-1] and Fl[i] -fl[i-1].fn=i-1;  the         }     +fl[total_pf-1].next=null;//null pointer at the end of the list Afl[total_pf-1].fn=total_pf-1;//page Frame number of the end node thefree_head=&fl[0];//free page frame chain head pointer to fl[0] +         }  -         voidLRU (intTOTAL_PF) $         {        $             intI,j,min,minj,present_time;  -Present_time=0;  - Initialize (TOTAL_PF);  the              for(i=0; i<total_pages;i++)   -             {       Wuyi                 if(pl[page[i]].fn==INVALID) the{//page Failure -diseffect++;  Wu                     if(free_head==NULL) -{//no free page frames Aboutmin=32767;  $                          for(j=0; j<total_pages;j++)              -{//find the minimum value of time -                             if(Min>pl[j].time && pl[j].fn!=INVALID) -                             {        Amin=Pl[j].time;  +minj=J;  the                             }             -                         }             $free_head=&fl[pl[minj].fn];//free up one page frame thepl[minj].fn=INVALID;  thepl[minj].time=-1;  thefree_head->next=NULL;  the                     }      -pl[page[i]].fn=free_head->fn;//have free page frames, change to valid inPl[page[i]].time=present_time;//Time is current thefree_head=free_head->next;//free page frame chain head pointer move forward the                 }        About                 Else         thePl[page[i]].time=present_time;//Time is current thepresent_time++;  the             }   +cout<<"LRU:"<<diseffect<<"("<< (float) diseffect/total_pages<<")"; -         } the         voidGetrefstring (void)Bayi         {    the             inti;  thecout<<"the access string entered ends with '-1 '!"<<Endl;  -cout<<"Please enter the access string:";  -              for(i=0;i< +; i++)    the             {        theCin>>Page[i];  the                 if(page[i]==-1)         the                      Break;  -             }       theTotal_pages=i;//Accessing the string size thecout<<"Access string Size:"<<i<<endl<<"the Access string is:";  the              for(i=0; i<total_pages;i++)94cout<<page[i]<<" ";  thecout<<endl<<Endl; the         }   the         intMain ()98         {     About             intF;  - getrefstring (); 101              for(f=2; f<=total_pages;f++)      102{//number of page frames from 3 page frames to total_pages page frames103cout<<"if assigned to a process"<<f<<"page frames, page faults (fault rate):"; 104 LRU (f);  thecout<<Endl; 106             }  107System"Pause"); 108         return 0;109}

Five. Running results

Six. Experimental summary

This experiment has better deepened my understanding of basic paging storage. It also improves the coding capability.

Storage management of experimental five operating systems

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.