Operating system-swapping between memory and external memory

 

1. Introduction of swap

In a multi-program environment , there may be two problems as follows:

  1. Some processes in the memory may be blocked (due to waiting for I/O or other reasons), but the process takes up a lot of memory space, and even all processes in the memory are blocked.
  2. In the above situation, there are still some jobs waiting on the external memory to be transferred into the memory , but because the memory space has been occupied by the blocked processes, these jobs waiting on the external memory cannot be transferred into the memory for execution.

Appealing the two issues will result in a serious waste of system resources, and system throughput (the amount of work completed per unit time) will decrease. To solve this problem, swapping was introduced.

2. Concept

Refers to swap memory is still not the process is running or being less than a program and data, transferred to the external memory on (in linux, have / swap swap partition dedicated user), in order to make sufficient The memory is used by jobs waiting in the external memory.

3. Swap classification

According to the unit of exchange , the exchange can be divided into the following three categories:

  1. Process swap (overall swap): Swap based on the process.
  2. Page swap (partial swap): swap in units of pages.
  3. Swap in segments (partial swap): Swap in units of segments.

The overall swap is mainly used for time-sharing systems , while the main purpose of partial swaps is to support virtual storage systems .

4. Process swap

In order to realize the process swap, there are three major functions to be realized by the operating system:

  1. Swap space management
  2. Process swap out
  3. Process swap in

4.1. Management of swap space (disk space of external storage)

The operating system with swap function usually divides external storage into file area and swap area .
The file area is used to store files, and the swap area stores the processes swapped out from memory.
The focus of the file area is the utilization of external storage space . In order to improve the utilization of external storage space in the file area, the file area uses a discrete allocation method .
The key point of the swap zone is the speed of swapping in and out . In order to increase the speed of swapping in and out of the swap zone, the swap zone adopts a continuous allocation method .
In order to manage the free disk partitions in the swap area, a free partition table/chain similar to that used in dynamic partition allocation can be used.
As for the allocation algorithm of free disk partitions in the swap area, the dynamic partition allocation algorithm can also be used for reference.

4.2 Process swap out

(1) Select is blocked state at and lowest priority processes swapped out as the process
(2) boot disk
transfer (3) processes the programs and data to disk

4.2 Process swap in

(1) The operating system regularly checks the status of all processes
(2) Finds the process in the ready state
(3) Finds the process with the longest swap-out time as the swap-in process
(4) swaps the process into memory

Guess you like

Origin blog.csdn.net/qq_41371349/article/details/108353367