Knowledge points in this chapter: 1. Relocation 2. Fixed partition Storage Management 3. Variable partition Storage Management 4. Page Storage Management 5. Segment Storage Management 6. Virtual Memory
Self-study requirements: it is clear that the function of storage management is to manage the user regions in the primary storage; measure the test taker's understanding about how to implement storage protection, address translation, and primary storage space allocation and recovery in different management modes, compare the features of various management methods, and master the implementation principles and methods of virtual memory.
Key points: features of various management modes; primary storage allocation in variable partitioning ModeAlgorithmAs well as mobile technology, implementation of paginated virtual storage management and page scheduling algorithms, and implementation of segmented virtual storage management.
The storage and management of the operating system is like a large landlord managing a large Manor. When a farmer needs to rent a field, the landlord allocates a land for his planting (User zone allocation ). When the ground grows fruit (after the result is returned, the landlord still has to reclaim the land (for allocation ).
In order to manage this field, the landlord also needs to manage the door of the farm. All the land that is to be planted must be managed by the landlord so that he can determine the actual field to work according to his needs. (Convert a logical address to a physical address)
There are also some areas that everyone can use together, such as the landlord's garden and tool room. You can go in or use them, but you are not allowed to change any existing stuff, every farmer can only eat in his own land. If someone dares to fish in another land or the landlord's garden, be careful when the wolf dog they raise jumps out. (Sharing and protection)
Of course, it is not enough for a large land. To make more money, landlords rent out all the land, he tried to dig out the Dongdong land in a field that some farmers had not planted for the time being and put it in the warehouse first. This is enough, but the landlord said, this is "virtual storage ".)
Do you mean this landlord is good or bad ??
Overview: This chapter discusses the management of the primary storage space. The primary bucket is divided into two parts: System zone and user zone. Storage Management features include: Allocation and de-configuration of primary storage space, address conversion, primary storage space zone sharing and protection, and expansion of primary storage space.
1. Relocation (comprehension)
1. differentiate logical and absolute addresses.
Absolute address: In the primary memory, the unit is byte. In the primary memory with a capacity of N, each unit has a unique number from 0 to n-1, the unique ID is the physical address of the primary storage.
For example, the 128 MB memory is 1024 × 1024 × 134217728 = 134217727 bytes, so its absolute memory address ranges from 0.
Note that the landlord of the estate marks his land.
Logical Address:ProgramIn the designed system, for the convenience of users, each user is allowed to think that the program and data of their jobs are stored in a continuous space starting from 0. In this way, the address used in the user program is the logical address.
Regardless of the number of places in the landlord's estate, the Gender marks the land as long as he remembers how many places he needs and marks the land he planted. The landlord thought, as long as you can work, you don't need to know my details ).
2. Relocation (address conversion method)
In order to ensure the proper execution of the job, the command and data storage in the job must be relocated according to the primary storage area assigned to the job, this process of converting a logical address to an absolute address is called "relocation" or "address conversion ". There are two methods of relocation: static relocation and dynamic relocation.
Zhuang Yuan's main road: static relocation is relatively simple. I would like to say that I would like to rent one hundred plots of land, plant vegetables in 1st plots of land, and plant radish in two plots, potatoes need to focus on 3rd plots ...... Then we have to raise ducks in 28th plots of land. After that, we need to pull the duck dung from 28 plots of land to the fish ponds in 49th blocks to feed the fish ...... Let me just say, all right. You can go in, and you will be given the 101-200 plots on the left of the farm to you. In the future, where do you want to raise duck fish, you have to follow the number I gave you. 100 is added to each address. Let alone I didn't make it clear.
As for dynamic relocation, the banker smiled and said: I can do this too. What I can do so: When Li Si rented a land, I did not ask him to directly take him to a free place. Send someone to remember the first address of the place. For example, 100. The stupid guy Li Si shouted, "Boss, I want to catch fish on the 32th !" The person next to him listened and immediately told him, "Oh, you have already split the ground. The starting plot is No. 100. Then you will get No. 132 !" In this way, every time Li Si looks for a place, he asks someone else to calculate it for him. In this way, he will not find the wrong location. There is also a benefit, that is, if someone bid better, I can ask him to move to another place to work and ask someone else to calculate his position, so he doesn't have to remember the physical address after moving the place.
(1) static relocation
When loading a job, convert all the instruction addresses and data addresses in the job into absolute addresses. This type of conversion is completed in a centralized manner before the job starts. address translation is not required during job execution. So it is called "static relocation ".
(2) Dynamic Relocation
When a job is loaded, the job is directly loaded into the assigned primary region without address translation. During job execution, each time a command is executed, the address translation mechanism of the hardware is converted to an absolute address. This method of address translation is dynamically completed during job execution, so it is called dynamic relocation.
Dynamic Relocation is implemented by the combination of software (operating system) and hardware (address translation organization. The dynamic relocation system supports "program floating", but static relocation does not.
Ii. Fixed partition Storage Management (understanding)
Partition storage management refers to the management of user areas in the memory as a continuous area or into several continuous areas. The storage management of one partition was used earlier, and then developed into multi-partition storage management. You can manage multiple partitions in a fixed or variable manner.
1. Principles of fixed partition Storage Management
A fixed Partition means that after the primary storage space is divided into several continuous partitions, the size and number of these partitions remain unchanged.
Fixed partition management uses a "primary storage allocation table" to describe the situation of each partition. The partition table is used to record the changes in partition usage for the load and end jobs.
2. How to Implement storage protection
Fixed partition management allows you to mount a job in static relocation mode. The loader converts the logical address in the job to an absolute address. Check whether the absolute address is in the specified partition. If yes, load the job. Otherwise, it cannot be loaded. If the job loaded into the primary storage partition occupies the processor (note that it is running), the process scheduler (not the loader) you must store the upper and lower limit addresses of the job's partition into the "lower limit register" and "upper limit register", so that you can determine whether the absolute address used exceeds the limit during instruction execution, achieve the purpose of storage protection.
3. There are several ways to improve the utilization of primary storage space:
(1) partitions are arranged in order of size, so that the job always uses the minimum partition that meets the requirements.
(2) partition based on the size and frequency of frequently-occurring jobs.
(3) The queue is arranged into multiple queues according to the job's demand for the primary storage space, specifying the correspondence between the queue and the partition. That is to say, the size of the job can only be placed in the size of the partition, even if there is a larger partition empty, it is not allowed to enter.
Iii. Management of variable partitions (comprehension)
Variable means that the partition size and position are not fixed, but the partition size is allocated according to the master inventory required by the job.
1. Primary storage allocation and de-configuration (recovery)
During system initialization, in addition to the portion occupied by the operating system, the entire user zone is a large idle zone, which can be allocated in sequence according to the size of the space required by the job until it is insufficient.
When the job ends, its occupied partitions are withdrawn. This idle zone can be re-allocated based on the size of the new job. Therefore, the number and size of occupied partitions and Free Zones in the primary memory are changing. You can use two tables, "allocated Partition Table" and "Idle Partition Table" to record and manage them.
2. Common allocation algorithms
First, adapt to the allocation algorithm: Simply put, it is to search in a partition table in order and allocate it when a large idle zone is found. However, such an allocation algorithm may form many non-consecutive idle zones, resulting in many "fragments", reducing the utilization of the primary storage space.
Optimal adaptive allocation algorithm: This algorithm always selects a minimum idle zone that can meet the job requirements. However, this algorithm may form some very small idle areas and thus cannot be used. This will also affect the primary memory utilization.
Worst adaptive allocation algorithm: this algorithm is the opposite of the above algorithm. It always selects the largest idle value for job use, so that the remaining space is not too small.
3. Address Translation and storage protection
When the variable partition mode is used for management, the dynamic relocation mode is generally used for loading jobs. That is, the address of each read command must be changed once. The conversion depends on hardware. There are two registers: Base Address Register and limit length register. The limit length register stores the length of the partition occupied by the job, and the base address register stores the start address of the partition occupied by the job, these two values determine the location and size of a partition.
During the conversion, the logical address is compared with the limit length value. If no value is exceeded, the access address is valid. When the base address register value is added, the absolute address is obtained, otherwise, an "address out of bounds" interruption occurs. Achieve the purpose of storage protection.
For shared programs, the hardware provides two sets of limited-length registers and base register. During access, the addresses in the access and operation areas are converted.
4. Application of mobile technology
What mobile technology needs to "move" is jobs in the primary storage space. Move a job to another primary storage space (similar mobile technology is applied in disk sorting). The biggest advantage of this is that it can merge some idle areas.
However, pay attention to the following issues when using mobile technology.
Mobile will increase system overhead. Therefore, we need to minimize the number of moves.
Moving is conditional. if a job is waiting to transmit information with the peripheral device during execution, it cannot be moved. Therefore, when moving the job, you must first determine whether the job exchanges information with peripherals.
4. Page-based storage management (comprehension)
1. How to paging and partitioning
There are two terms in page-based storage management: "page" and "Block". The "Block" is for hardware, that is, to divide the memory into several equal-size zones, each zone is called a block. Correspondingly, in the program, the logical address is "paged", and its size is consistent with that of each block.
In fact, the page size is determined by the block size. For a program, its logical address is still the same as the original sequential address. The page number is used as the page number based on the number of digits of the block.
When allocating space, you can determine the number of pages based on the job length. Based on the number of pages, you can allocate the corresponding number of blocks in the primary storage, as long as it is an idle block, even if it is not adjacent. In the "page table", you can find the corresponding page number and block number based on the page table to obtain the absolute address.
2. webpage management is used to make full use of the primary storage space, and pages do not need to be moved for continuous space. This improves system efficiency.
3. page table construction and functions
Each job loaded into the primary storage has a page table, indicating the correspondence between the page number in the logical address of the job and the occupied primary storage block number. The length of the page table is determined by the number of pages owned by the page. The row number corresponds to the page number, and the row records the block number in the primary storage.
The page table is the basis for hardware address conversion. Each time a command is executed, the page table is searched based on the page number in the logical address and converted to an absolute address.
In a multi-channel programming system, each job that enters the primary storage has a page table, A hardware "page table control register" is used to record the location and length of the page table of each job so that the page table can be converted simultaneously during job conversion.
4. Structure and Function of a quick table
A Fast table is a part of the clone of a page table. Each row contains a page number and its corresponding block number. The whole fast table is stored in a small-capacity high-speed cache. During access, the fast table and memory are searched at the same time, because the speed of a quick table is fast, and frequently used pages are registered in the quick table, the execution speed can be greatly improved.
5. Page-based address translation
(Why not use a block allocation table to record data and use a map? Because there are many primary storage blocks, this can save space and improve efficiency. A Bitmap uses a single digit (0 or 1) to indicate the Usage Status of a block. A single character is 32 bits and can represent 32 blocks. In order, you can record a large number of block states in the primary memory with only a small memory segment)
6. Use a map to allocate and recycle a page-based storage space
Page-based storage management divides the primary storage space into many fixed-size blocks. When installing a job, you can use a map to show which blocks are used and which are not used.
Block number = font size X Font size + bit number
Font size = [I/font length] (that is, the block number I divided by the font length is rounded up)
Position Number = I mod font length (that is, the block number I divided by the word length to take the remainder ).
V. segmented Storage Management (comprehension)
1. segmentation of the middle section of the segmented Storage
Segment management is provided based on people's requirements for segment preparation in the program. The logical address used for programming is composed of two parts: "segment number" and "segment address". The format is the same as page management. But they are actually different:
Page-based storage management provides continuous logical addresses that are automatically paged by the system. Job segments in segment-based storage management are determined by users. Each segment is independently programmed, so the logical addresses between segments are discontinuous.
2. Distribution of segmented storage space
This allocation method is the same as that for variable partition management. The difference is:
In the variable partition management mode, each job is divided into one partition, and the segment management is divided into a continuous space for each segment of a job. (Segment management is more detailed ).
3. Structure and Function of field tables
A field table consists of three parts: the field number, the current segment length, and the start address. Because the row number recorded in each row can correspond to the field number of the program, the field number is actually omitted and does not occupy the storage space.
Like other management methods, the information recorded in the field table is used for address translation and storage protection. The table of a field table acts as the base address/limit length register.
4. Address Translation for Segment Storage Management
This conversion process is similar to address translation in the form of variable partitions, but the base address/limit length register is replaced by the table categories in the field table.
Absolute address = locate the starting address + intra-segment address in the field table based on the field number (if the intra-segment address exceeds the limit, a "out-of-range address" procedural interruption event is generated to achieve storage protection)
In a multi-channel programming system, each job that enters the primary storage has a field table. Therefore, there is also a hardware "field table control register" to record the location and length of each job's field table in the primary storage.
Vi. Virtual Memory (understanding)
1. What is virtual memory?
Virtual Memory is a design technique used to "Expand" the primary storage capacity, it uses the features that can be executed only when a job loads part of information and the Local Features Shown in program execution, with the help of large-capacity auxiliary storage, small primary storage space can accommodate large logical address space jobs.
The capacity of the virtual memory is determined by the address structure of the Computer (number of bus digits.
2. Implementation Principle of Virtual Memory
It works as follows: first, the job information is retained on the disk. When a job request is loaded, only part of the information is first loaded into the primary storage, if the information to be accessed is not in the primary storage during job execution, try to load the information into the primary storage.
3. Implementation of paging virtual memory
Page-based virtual storage management is implemented based on page-based storage management. First, store the job information as a copy on the disk. During job execution, some pages of the job information are loaded into the primary storage. If the accessed page is already in the primary storage during job execution, the address is converted to an absolute address. Otherwise, the operating system loads the current required page into the primary storage.
4. Common page scheduling algorithms: FIFO, LRU, and LFU
When there is no idle block on the home page, In order to load a page, you must call up a page in the primary storage according to an algorithm and call the page to be loaded. This is page scheduling. Common algorithms include the first-in-first-out scheduling algorithm (FIFO), least recently used scheduling algorithm (LRU), and least recently used scheduling algorithm (LFU ).
Special attention should be paid to master the LRU algorithm and how to schedule it.
5. page missing interruption rate
If the total number of page visits during page execution is a, and the number of pages accessed by F has not been loaded into the primary storage, the number of page failures is F, F = f/, here F is called the page missing interruption rate. The following factors affect page disconnection:
Number of primary storage blocks allocated to a job-number of blocks n = f =
Page size-page size limit F then
Programming Method -- localization degree limit F Accuracy
Page Scheduling Algorithm
6. Implementation of segmented virtual memory
Based on Segment Storage Management, segment virtual storage retains the information of each segment of a job on the disk. When a job is executed, the segment or segment to be executed is loaded into the primary storage. In actual use, you also need to perform table queries, address translation, "interrupted CIDR blocks", and scheduling (including calling, loading, and moving.