Operating System - Memory management

Chapter IV memory management

summary:In recent years,with the development of computer technology,system software and application software have expanded rapidly in terms of types and functions.Although the storage capacity has been expanding continuously,it still cannot meet the needs of modern software development.Thus,memory remains a valuable and scarce resource.How to manage it effectively not only directly affects the utilization rate of memory,but also has a significant impact on the system performance.The main object of memory management is memory.

* Hierarchy of memory

A three-layer structure of the memory, the CPU registers (register), main memory (cache, main memory, disk cache), a secondary storage (fixed disk, removable storage media);

Handler are acquired from the main memory the instruction and data acquisition instruction into the instruction register, the data into the data register; register stores operand address register for accelerating the speed of address translation; cache memory and processing for relaxation the contradiction between the machine; disk cache for temporarily storing a portion of the disk frequently used data and information, in order to reduce the number of disk accesses

* Load and convergence programs

Object modules produced by the compiler -> Linker -> Load Module -> Load Programs -> Memory

Program loader

Absolute load mode, the program was compiled, the program will know what position resides in memory; relocatable loaded manner, to modify each relocation entry address according to the memory address location is loaded, add the appropriate bias shift amount; dynamically loaded at runtime, the address translation program to postpone really want to execute when to convert the relative address to the absolute address

Linker

Statically linking, performed when the executable file, symbolic address recorded in the target module, and the rewritten instruction number used directly in the executable file; dynamic linking is loaded, the user will compile the source code, the load when memory, edge into the edge of convergence; run-time dynamic linking, who was not used during execution of the target module will not be loaded into memory and is linked to the load module, so that not only can speed up loader process, but also saves a lot of memory space

* Continuous allocate storage management

A single continuous distribution, can only be used for single-user, single-tasking operating system; a fixed partition is assigned, the memory is divided into a number of equal or unequal size of partitions, each application process takes up one or several partitions, operating system occupies a zone ; number of dynamic partition allocation, partition size variable partitions and partitions are variable, depending on the size and number of operations to dynamically partition

Fixed partitions exist in the debris, total number of partitions fixed, limits the number of procedures performed concurrently, --- partition table recording partition size and usage

Dynamic partitioning presence of extracellular debris, free partition table is not yet allocated partition --- setting table entry (partition number, partition size, sector address, state), free partition chain --- achieve free partition allocation and link

Dynamic partition allocation algorithm based on the order of search elements

First fit algorithm FF, free partition Yaoan address free partition table (free area chain) is from low to high ranking, retained the large partition, retained a large part of the free zone high site, but difficult to leave the low address range used free partition and each site from low to start looking; fantasy first fit algorithm NF, find from last free area next free area to start looking, free partition distributed more evenly and look for a small cost, but the lack of large spare partitions; most good adaptation algorithm BF, free partitions in ascending order, the outer pieces becomes as small as possible so as to minimize the remaining free; WF worst fit algorithm, all unassigned from the selected partition and equal and greater than the maximum job size divisions required to members; free partition sorted by descending size, the maximum remaining free area, lack of large free partitions

Dynamic partition allocation algorithm based index search elements

Adapt quickly (quick fit) algorithm based on the length of required memory, find the most suitable free list management index table; the buddy system (buddy system) has been allocated partition or free partition size is 2 k of this power, divide the application table 1024 and recycling; hashing algorithm to establish a hash function to construct a hash table partition size is not idle keywords. A free list head pointer list partition Each entry

Dynamic partition allocation relocatable

Compact, user program memory change occurs in the relocation required; dynamic relocation, dynamic fashion into operation, the address conversion instruction execution, the hardware required to support address translation mechanism provides relative address processor, memory relocation provided register; dynamic relocation partition allocation algorithm based on dynamic partition allocation algorithm adds compact

* Swap

System to all user jobs stored on the disk (external memory), you can only load a memory into the job, when the job of a time slice is used up, it will be transferred to the backup memory queue waiting for the mountain, and from backlog transferred to another job to run into the memory

To change the type of overall swap, intermediate processor scheduling is actually swap memory function to solve the problem of a shortage of memory; page on the exchange, is the basis of demand paging request and segmented memory management

Process swapped out (suspended) and the transducer (activated) 1. Select the process is swapped out, the sleep state or the blocked state selecting process, if a plurality, selecting the lowest priority swapped out process; 2. Process swap out process, only for a non-shared programs and data segments, application swap space, the application is successful startup disk, the process of transfer programs and data onto a disk swap space

View all PCB collection process state, ready to find out it has been swapped out process, if more than one, then select swapped out to disk longest time as the process of change into the process, and application memory

* Paged memory management

Without a compact, you can take full advantage of the memory space three discrete distribution: paging storage management, storage management segment, segment paged memory management

Page: Paging storage management logical address space of a process into several pages, numbered from zero to each page; address structure: page number P + displacement amount W is; Page Table: implement address mapping from the page number to a physical block number

And two multi-level page table method to perform a discrete allocation page table two page tables, solves the problem without the need for large tracts of continuous memory page table space, but does not address the less memory space to store large page table problem;

For 64-bit machine, not suitable for two page table

Inverted page tables to reduce the page table memory space occupied, each one physical block (frame) is provided a page table entry, the physical block sorting press; in accordance with the process ID and the page number, the page table retrieving inverted. If the match, the page table entry number i identifies the physical block number of the page where

* Segmented memory management

The basic principle of the system is segmented in each segment are addressed from 0, and using a contiguous address space. Is determined by the length of the segment corresponding to the length of the logical block, the length of each segment are not equal. In the system, similar to the paging system, the need to establish a mapping table for each process segment, i.e. the segment table, in a village, an aryl group of registers, in order to facilitate improved switching speed;

The difference between paging and segmentation 1. A page is a physical unit of information;. 2 and fixed page size determined by the system; 3 Paging user program address space is one-dimensional; segment segment is a logical unit of information, comprising a meaning relatively complete set of information, the length of the segment is not fixed, sub-system, the address space of the user program is two-dimensional, it is necessary to segment names, but also the segment address

Sharing information segment is a logical unit of information, and therefore a projecting section system is easy to realize the advantage of the shared segment. That allows several processes to share one or more segments, and the protection of the segment is also very simple. In the paging system, although it can implement the program and data sharing

Summary of chapter exercises

4.1 Why To configure the hierarchical memory?

A plurality of memory may make the hardware capable of operating at both ends of a memory in parallel; multi-level memory structure, in particular Cache technology, the structure is the best scheme to mitigate the impact on system performance memory bandwidth; various buffer memories provided inside the microprocessor, reduce the pressure on memory access. Increasing the number of registers in the CPU memory greatly ease the pressure.

4.7 Why introduce dynamic relocations? How to achieve?

During program execution, whenever access instructions or data, logical address accessed by the program and data into a physical address, introduces dynamic relocation; specific method it is added to the system a relocation register used to load Inspiration program address in memory, the program is executed, when the real memory address to access the relative address relocation register address and the sum, in order to achieve dynamic relocation.

4.9 When used first to adapt the algorithm to reclaim memory, which has several possible scenarios? How to deal with these situations?

When recovery of memory, we put the first site to be recovered memory area to get free partition list than to find the insertion point (in accordance with an algorithm for constructing spare partition chain), left if you want to reclaim the memory and the insertion point right or both are adjacent, then to merge into a region adjacent to the region, not adjacent been inserted into it as a separate region, and modify the values ​​of the relevant data structure.

4.21 How to achieve address translation when the paging system?

First, the process is run from the PCB in the process page table and a page table start address into the page table length register when the process is to access the data in a logical address, the address of the index tab is an effective means automatically address (logical address) into the industry page number and address. Page number and page tables to register in the page table compared to if the page number is larger then the access violation, thrown interrupted. Otherwise, use the page number, start address and page table page table entry corresponding to the length of the calculated position of the page table to obtain the physical block number. The block number and the physical page address into a physical address register at the same time, combining physical address.

Guess you like

Origin www.cnblogs.com/SHNLQS-1273196803/p/11070165.html