Memory allocation strategy and allocation method

Click to open the link

----- When allocating memory for a process, 3 issues will be involved:

1) Determination of the minimum number of physical blocks; 2) Allocation strategy of physical blocks; 3) Allocation algorithm of physical blocks .

1. Determination of the minimum number of physical blocks

-- The minimum number of physical blocks mentioned here refers to the minimum number of physical blocks required to ensure the normal operation of the process .

-- When the number of physical blocks allocated by the system to the process is less than this value , the process will not run.

-- The minimum number of physical blocks that a process should obtain is related to the hardware structure of the computer and depends on the format, function and addressing mode of the instruction .

2. Physical block allocation strategy

-- In the request paging system, two memory allocation strategies can be adopted, namely fixed and variable allocation strategies. When permuting, two strategies can also be adopted, namely global permutation and local permutation .

   The following three applicable strategies can then be combined.

1) Fixed Allocation Local Replacement (Fixed Allocation, Local Replacement)

---- This refers to the type of process (interactive or batch, etc.), or according to the programmer's or program administrator's recommendation, to allocate a certain number of physical blocks to each process, which will be maintained throughout the operation period .

no longer change. When this strategy is adopted, if a process finds a page missing during operation, it can only select one page out of the n pages in the memory of the process , and then transfer another page to ensure that it is allocated to the process.

The memory space of the process does not change (fixed allocation).

---- The difficulty in implementing this strategy is that it is difficult to determine how many physical blocks should be allocated to each process. If it is too small, page faults will occur frequently, reducing the throughput of the system; if it is too much, it will

However, the number of processes resident in the memory is reduced, which may cause the CPU to be idle or other resources to be idle, and it will take more time to implement process swap.

2) Variable Allocation Global Replacement (Variable Allocation, Global Replacement)

This is probably the easiest physical block allocation and replacement strategy to implement and is used in several OSes. When adopting this strategy, each process in the system is first allocated a certain number of physical blocks , while

The OS itself also maintains a queue of free physical blocks. When a process finds a page missing, the system takes out a physical block from the free physical block queue and assigns it to the process, and loads the (missing) page to be called in.

into it. In this way, all processes that generate page faults (interrupts) will obtain new physical blocks. Only when the physical blocks in the queue of free physical blocks are exhausted, the OS can select a page from memory, which page

It may be the page of any process in the system. In this way, the physical block of that process will naturally decrease, thereby increasing its page fault rate.

3) Variable Allocation Local Replacement (Variable Allocation, Local Replacement)

This is also based on the type of the process or according to the requirements of the programmer. Each process is allocated a certain number of physical blocks, but when a process finds a page missing, it is only allowed to select from the memory pages of the process.

A page is swapped out so that it will not affect the running of other processes . If a process is running frequently with page faults, the system needs to allocate several additional physical blocks for the process until the process

The page fault rate is reduced to an appropriate level; on the contrary, if the page fault rate of a process is particularly low during the running process, the number of physical blocks allocated to the process can be appropriately reduced at this time, but the page fault rate should not be caused.

significantly increased.

---- Global means that when a page is replaced, the swapped page may be the page of any process in the memory, and the local part can only be the page of the current (page missing) process.

---- Fixed allocation means that the physical blocks allocated for a process are fixed, and variable allocation means that the number of allocated physical blocks can be adjusted according to the page fault rate.

3. Physical block allocation algorithm

-- When using a fixed allocation strategy, how to allocate all the physical blocks available for allocation in the system to each process, the following algorithms can be used.

1) Average distribution algorithm

-- This is to evenly distribute all available physical blocks in the system to each process. For example, when there are 100 physical blocks in the system and 5 processes are running, each process can get 20 physical blocks.

This approach seems fair, but it is not, because it does not take into account the size of each process itself .

If there is a process with a size of 200 pages and only 20 blocks are allocated to it, it must have a high page fault rate; while another process has only 10 pages, but 10 physical blocks are idle and unused.

2) Proportional Allocation Algorithm

-- This is the algorithm for allocating physical blocks proportionally to the size of the process . If there are n processes in the system and the number of pages of each process is Si, the sum of the number of pages of each process in the system is:

    S=S1+S2+...+Si+...+Sn-1+Sn (i=1~n) Assuming that the total number of physical blocks available in the system is m, then the number of physical blocks that can be allocated by each process is bi, then there are:

    bi=(Si*m)/S where b should be rounded and it must be greater than the minimum number of physical blocks.

3) Allocation algorithm considering priority

-- In practical applications, in order to ensure that important and urgent tasks can be completed as soon as possible, more memory space should be allocated for it. The usual approach is to take all physical blocks in memory available for allocation

Divided into two parts: one part is allocated to each process in proportion; the other part is allocated to each process after appropriately increasing its corresponding share according to the priority of each process.

In some systems, such as important real-time control systems , each process may be allocated its physical blocks entirely by priority .

4. Paging strategy

---- Pre-paging strategy and demand paging strategy

---- Determine where to load the page from

The external memory in the request paging system is divided into two parts: the file area and the swap area (the file area for storing files and the swap area for storing swap pages).

Usually, continuous allocation is used for the swap area, and discrete allocation is used for the file area. Therefore, the disk I/O speed of the swap area is higher than that of the file area. Where to transfer is divided into 3 situations:

-- 1) The system has enough space in the swap area, and all the required pages can be loaded from the swap area. Before the process runs, the files related to the process need to be copied from the file area to the swap area.

-- 2) The system lacks enough swap area space, and the files that will not be modified are directly transferred from the file area . When these pages are swapped out, they do not need to be swapped out because they have not been modified.

When reloading, it is still directly loaded from the file area. For those parts that may be modified , when they are swapped out, they need to be transferred to the swap area , and later they need to be transferred from the swap area.

-- 3) Unix way. All pages that have not been run should be loaded from the file area. Pages that have been run but have been swapped out are placed in the swap area, and are loaded from the swap area when they are loaded. Unix system running

Pages are shared, so the page requested by a process may have been loaded into memory by other processes, and there is no need to load it from the swap area.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324693465&siteId=291194637