sequential search method

Sequential search method:

Supplement: Introduction of loop first adaptation algorithm

Every time a process is allocated space, it starts searching from the next block of the free area just allocated last time. For example, the initialized memory free area is the max size entered by the user. Before recycling, only the last block must be free Yes, but after recycling, the table you set (here is a table set up, you can also use two tables, but one can solve the problem, there is no need to use two tables), after allocating from the area code of the free area , mark this block, the next allocation will start from the marked block and look down, allocate if it matches, and then mark the allocated free area number, the difference from the first adaptation algorithm is here

1. The first (first) adaptation algorithm ( first fit, FF )

In layman's terms, it is: put the process in the low-address free area as much as possible, and if it can't be put down, the address will gradually increase.
For each deposit, search for a satisfactory free area from the lowest address to the highest address. That is, each storage starts from 0.

features

  • The algorithm preferentially uses the low-address part of the free area, creates many small free areas in the low-address space, and reserves a large free area in the high-address space.
  • Select the free area that meets the application length requirements and has the smallest starting address.
  • Free areas are recorded in the free area table in ascending order of start address.

advantage

  • Try to use the low address space, so that a large free area may be formed at the high address. Creates conditions for allocating large memory spaces for large jobs that arrive later.

shortcoming

  • Larger free regions at lower addresses may be delimited.
  • The low-address part is continuously divided, leaving many hard-to-use, small free partitions, called fragments.

Second, the next adaptation algorithm ( next fit, NF )

This algorithm is improved on the basis of the FF algorithm, which is generally similar to the FF algorithm, but the difference is that: the FF algorithm starts
from 0 to find a free area that meets the requirements for each storage;
the NF algorithm continues each storage The next address of the last allocated area;

features

  • This algorithm is an improvement of FF algorithm.
  • Picks the first satisfiable free region starting from the next position in the region from the last allocation of free space.

advantage

  • Free area distribution and distribution is more even.

shortcoming

  • Large free regions may be separated, resulting in large jobs arriving later without large free regions.

3. Best fit algorithm ( best fit, BF )

This algorithm is similar to the FF algorithm. Whenever a process applies for space, the system searches from the head.
The free area is recorded from small to large, and each search starts from the smallest until the smallest free area that meets the requirements is found.

features

  • When allocating memory space, take the free area that meets the application requirements and has the smallest length.
  • Free areas are recorded in the free area table in order of length "from small to large".

advantage

  • Try not to split large free regions.

shortcoming

  • A lot of free space that is too small to be used later, known as external fragments, may form.

4. Worst fit algorithm ( worst fit, WF )

This algorithm is opposite to the BF algorithm. BF uses the smallest free area to store things, while WF uses the largest free area to store.

features

  • When allocating space, select the free area that meets the application requirements and has the "maximum" length.
  • Free areas are recorded in the free area table in order of length "from large to small".

advantage

  • Avoid formation of external debris

shortcoming

  • Will separate large free areas, which may not be able to meet the requirements of processes with long storage space.

example

In the figure below, the leftmost one is the initial state of the memory. Now it is necessary to put 4 processes into the input well one by one, and wait for the system to put them into the memory.
JOB1 30K
JOB2 50K
JOB3 20K
JOB4 60K
Red: space already occupied.
Green: free space.
Yellow: the space occupied by the above 4 processes.

02

Guess you like

Origin blog.csdn.net/weixin_54882070/article/details/129217403