The following introduces a concept.:
Page: A fixed-length data block, which is stored in second-level memory (such as a disk ). Data pages can be temporarily copied to the pages in the memory.
Section:A variable-length data block is stored in the secondary storage. The entire segment can be temporarily copied to the available area (segment) of the memory, or the segment can be divided into many pages, copy the page to the memory separately (combining multipart paging ).
Relocation: It is the process of converting the logical address space of the program into the actual physical address space in the memory.
Operating system storage should be divided into at least two levels: memory and external storage. Memory provides fast access, which is relatively expensive and is volatile and cannot be stored permanently. External Storage is slower than memory, but cheaper and non-volatile. It can store programs and data for a long time. The smaller memory is used to save the currently used programs and data.
During the most basic operations of memory management, the processor loads the program into the memory for execution.
Fixed Partition:
Principle: Also known as the fixed-length partition or static partition mode, it is the simplest storage management technology to meet the needs of multi-channel programming. Basic Idea: divide the user jobs that enter the primary storage into a continuous storage area and load the jobs into this continuous storage area. If multiple jobs are attached to the primary storage, they can be executed concurrently.
There are two difficulties in using a fixed partition with the same size: the program may be too large to be placed in one partition, and the memory utilization is very low. The data block to be loaded is smaller than the partition size, which leads to a waste in the partition and becomes an "Internal fragment ". For partition policies with different sizes, the simplest way is to allocate each process to the smallest partition that can accommodate it.
Currently, there are basically no scenarios for using fixed partitions.
Advantages: Easy to implement, with minimal operating system overhead required
Disadvantages: Internal fragments exist, insufficient memory usage, and the maximum number of active processes is fixed.
Variable Partition: Variable partition storage management does not pre-divide user areas in the memory into several fixed
When the job requires Memory loading, it determines whether to allocate a partition for the job based on the size of the job and the current memory space usage. Therefore, the partition size is not pre-fixed, but divided by job demand. The number and position of partitions are not pre-determined. It effectively overcomes the waste caused by vacant memory in the fixed partition mode.
1. Primary storage space allocation and recovery
When the system starts, the entire user zone can be considered as a large idle zone. When a job needs to be loaded, a partition from the idle area that is consistent with the job size is allocated to the job according to the memory demand of the job. The remaining part is still in the idle area. When the idle area can meet the requirements (that is, the idle area length> = job length), the job can be loaded; otherwise, the job cannot be loaded temporarily. Figure 3.9 shows the storage space allocation for a variable partition.
After the memory-loaded job is executed, the occupied partition is reclaimed into a free zone, which can be used to load other jobs. As jobs are loaded and evacuated, the memory space is divided into many partitions, some are occupied by jobs, and some are idle. 3.10. The number and size of free zones in the memory are constantly changing.
The system sets a "Free Zone table" to record the start address and length of the free zone. When a job is loaded into the memory, find the "unallocated" column in the idle area table to find a free area that can accommodate the job. If the idle area is longer than the job length, it is divided into two parts, one part is allocated to the job, and the other part is still registered in the table as the idle area. If the idle area is equal to the job length, the status of this topic is changed to "null" after allocation. After a job is withdrawn from the occupied partition, the starting address and length of the area should be registered in the "empty" column, and the status should be changed to "unallocated ". If the recovered area is adjacent to a free area, it should be merged into a partition and then registered. 3.11.
Common memory allocation algorithms for variable partitioning are: "First adaptive" allocation algorithm, "best adaptive" allocation algorithm, and "worst adaptive" allocation algorithm.
1. First adapt to the allocation algorithm
For each allocation, the idle Partition Table is queried sequentially and allocated when the idle partition meeting the length requirement is found. The advantage is that it is easy to implement. The disadvantage is that it is possible to cut large idleness into many small idleness to form many discontinuous "fragments ". The fragment length may not meet the job requirements, reducing the memory usage.
The improved method allows you to register the Free Zone in the Free Zone table from small to large by address order, which facilitates large jobs. The problem is that when the blank area is returned, the appropriate location in the table must be inserted by address.
2. optimal adaptive allocation algorithm
Select a minimum idle area that can meet the requirements of all idle areas according to the job requirements. This ensures that a larger area is not separated, making it easier to load large jobs. Implementation Method: register the Free Zone in the Table in ascending order of length, and find it in the order of the Free Zone table during allocation. The disadvantage is that the fragments may be smaller and cannot be used. During recycling, you must also follow the length limit.
3. The worst adaptive allocation algorithm
This algorithm always selects one of the largest free zones for job use, so that the remaining part is not too small and can still be used for allocation. Implementation Method: the items in the free area table are listed in descending order of the free area length and allocated in order. Figure 3.12 shows an example of the preceding allocation algorithm.
Ii. Address Translation and storage protection
When the variable partition mode is used, the dynamic relocation mode is generally used to load the job. Therefore, you must have the hardware address translation organization support. The hardware sets two dedicated control registers: base register and limit register, as well as some addition and comparison lines. 3.13.
When a job can occupy a processor, the process scheduling sends the first address of the partition occupied by the job (such as a) to the base address register, the maximum address occupied by the job partition (such as a + k) send to the limit length register. Each time the CPU executes a command, the hardware address translation organization converts the logical address to an absolute address. The absolute address must meet the following formula:
Base Address Register content <= absolute address <= Limit register content
Otherwise, an address out-of-bounds interruption occurs and the program is stopped.
In a multi-channel programming system, only one base address register and limit length register and psw are required. when changing the current running process, pay attention to protecting and restoring the on-site information, it is generally stored in the PCB of each process.
Iii. Mobile Technology
The variable partitioning method is supported by hardware address translation devices, and dynamic relocation is usually used for loading jobs. Therefore, you can change the storage area of memory jobs when necessary. This kind of work is called "mobile" and is done by the operating system. 3.14.
Mobile technology is mainly used for the following two purposes:
1. Scattered Free Zones
Using mobile technology, scattered free zones can be connected to form a large free zone to facilitate new jobs.
2. Facilitate job dynamic memory expansion
A job requires memory expansion during execution. As long as the adjacent job is moved, the memory occupied by the continuous zone can be increased.
To complete the above work, we need to do two things: first, move the program in the memory, and then modify the base address register and limit length register content of the corresponding job as appropriate.
Of course, moving will increase the system overhead, and cannot move the job at will. For example, if a job is waiting for peripheral I/O data, it cannot be moved. This is because the information exchange between the peripheral device and the memory is based on the absolute address. If the storage area is changed, the exchange between the job and the peripheral device is not correct. Another example is that dynamic memory expansion may cause deadlocks. For example, the memory is occupied by a and B processes. If a requests dynamic memory expansion and does not meet the requirements, it waits. B also applies for dynamic memory expansion. If B does not meet the requirements, it also waits. So a deadlock occurs!