1. Overview of computer systems 1. Overview of Computer Systems 2. Concepts of Operating Systems 2. Concepts of Operating Systems 3. Functions of Operating Systems 3. Functions of Operating Systems 4. Brief History of Operating Systems 4. Brief History of Operating Systems 5. Operations classification of Systems 5 Classification of operating systems 6 research views of operating systems 6 research views of Operating Systems 7 Development History of Windows 7 Development History of Windows 1 design 1 Operating System Design 2 Windows2000/XP operating system model 2 Windows2000/XP operating system model 3 Windows2000/XP architecture 3 Windows2000/XP architecture Operating System 1 Operating System Overview 1 Operating System Overview 2 Windows2000/XP architecture 2 Windows2000/XP architecture 3 process and processor management 3 process and processor management
Home> storage system> basic principles of Storage Management |
Courseware chapterChapter 2 Operating System OverviewChapter 2 architecture of Windows 2nd/XPChapter 4 Process and processor managementChapter 4 Storage SystemChapter 4 File SystemChapter 1 I/O SystemsChapter 2 networkChapter 2 Windows Application Design |
4.1 basic principles of Storage Management 4.1.1 Memory Management Method
Memory Management mainly includes memory allocation and recovery, address transformation, memory expansion, Memory sharing and protection.
The following describes the basic concepts and principles of continuous distribution storage management, coverage and exchange technology, and page-based and segmented storage management.
1. Continuous Distribution of Storage Management Methods
Continuous Allocation refers to allocating continuous memory space for a user program. There are two methods for continuous distribution: single continuous Storage Management and partitioned storage management.
(1) single continuous Storage Management
In this mode, memory is divided into two areas: System zone and user zone. The application is loaded into the user area, and all the space in the user area can be used. It is the simplest and applicable to single-user and single-task operating systems. This method is used for CP/M and DOS 2.0 or lower. The biggest advantage of this method is ease of management. However, there are also some problems and deficiencies, such as a waste of memory for programs requiring less memory space; all programs are loaded, so that the rarely used part of the program also occupies a fixed amount of memory.
(2) partitioned Storage Management
To support multi-channel program systems and time-sharing systems and concurrent execution of multiple programs, partition-based storage management is introduced. Partitioned Storage Management divides the memory into partitions of equal or unequal sizes. The operating system occupies one of the partitions, and the remaining partitions are used by applications. Each application occupies one or more partitions. Although partitioned Storage Management supports concurrency, it is difficult to share memory partitions.
Partition-based storage management brings about two new problems: internal fragmentation and external fragmentation. The former is used for unused space in the partition, and the latter is used for idle partitions that are difficult to use between partitions (usually small idle partitions ). To achieve partitioned storage management, the data structure maintained by the operating system is a partition table or a partition linked list. The table items generally include the starting address, size, and status (whether allocated) of each partition ).
A common technology used in partitioned storage management is memory compression (compaction), which moves the occupied partitions to one end of the memory and then combines the idle partitions into one free partition. This technology provides a certain degree of flexibility, but also has some drawbacks, such as: memory data migration for occupied partitions, CPU usage ~ T-inch; if the program in the occupied partition is "floating", the relocation requires hardware support.
1) fixed partition (nxedpartitioning ).
A fixed partition divides the memory into several continuous partitions of a fixed size. Partition size can be equal: This method is only suitable for concurrent execution of multiple identical programs (processing multiple objects of the same type ). The partition size can also be different: there are multiple small partitions, moderate partitions, and a small number of large partitions. Allocate idle and Appropriate Partitions Based on the program size. This technology is easy to implement with low overhead. There are two main disadvantages: waste of internal fragments; Fixed Total number of partitions, limiting the number of concurrent programs.
2) Dynamic partitioning ).
Dynamic partition is characterized by dynamic partition creation: it is allocated according to its initial requirements when the program is loaded, or allocated or changed through system calls during its execution. Compared with a fixed partition, it has the following advantages: no internal fragments. However, it introduces an external fragment. The distribution of dynamic partitions is to find an idle partition. Its size must be greater than or equal to the requirements of the program. If it is greater than the requirement, the partition is divided into two partitions, one of which is the required size and marked as "occupied", and the other is the remaining part and marked as "idle ". The order of partition allocation is usually from low-end memory to high-end. When releasing a dynamic partition, you must note that the adjacent idle partitions are merged into a large idle partition.
The following lists several common Partition Distribution algorithms:
First adaptation method (nrst-fit): searches for the first partition in the memory order and finds the first partition that meets the requirements for allocation. The algorithm has good performance in allocating and releasing time, and large idle partitions can be retained in the memory. However, as low-end partitions continue to be divided, more small partitions will be generated, and the search time overhead will increase during each allocation.
Next adaptation method (next-fit): searches from the last allocated partition in the memory Order (start from the last {partition time }, find the first partition that meets the requirements for allocation. The algorithm has good performance in allocation and release time, which makes the distribution of free partitions more even, but it is not easy to retain large idle partitions.
Best-fit: searches for partitions from the beginning in the memory order, and finds the idle partitions with the smallest difference in size and requirements for allocation. In some cases, external fragments are small. However, the advantage of many external fragments is that large idle partitions can be retained.
Worst-fit: Find the largest idle partition in the order of memory and allocate it. There is basically no small idle partition left, and it is not easy to form external fragments. However, because a large number of idle partitions are not retained, it is difficult to meet the requirements when a process with a large memory requirement needs to run.
2. Coverage and Exchange Technology
The purpose of Overlay Technology is to run large programs in a small amount of available memory. This technology is commonly used in multi-channel program systems and used in conjunction with partition-based storage management. The principle of coverage technology is very simple. Several code segments or data segments of a program occupy public memory space by time. Code and data of the necessary parts (common functions) of the program are stored in the memory; optional parts (not commonly used functions) are usually stored in the external memory (overwrite files) and loaded into the memory only when necessary. Modules that do not have a call relationship do not need to be loaded into the memory at the same time, so that they can overwrite each other. The disadvantage of overwrite technology is that during programming, the overwrite relationship between the program module and the program module must be divided to increase programming complexity. overwrite files must be loaded from external storage to save time. There are two methods to implement overwriting: library implementation or operating system support.
When multiple programs are concurrently executed, swapping technology can send temporarily unexecutable programs to external storage to obtain free memory space for loading new programs, or the read person is saved in external storage and in the ready state. The switch unit is the address space of the entire process. Exchange technology is often used in multi-channel program systems or small time-sharing systems, it is also used in conjunction with partitioned storage management, also known as roll-in/roll-out ). One of its advantages is to increase the number of concurrent programs and provide users with the appropriate response time. Compared with the coverage technology, another significant advantage of the exchange technology is that it does not affect the program structure. Exchange technology also has its own shortcomings, such as: Switching and switching out control increase processor overhead; the entire address space of the program is swapped, without considering the statistical characteristics of address access during execution.
3. Page-based and segmented Storage Management
In the previous storage management methods, the space allocated to the process is continuous and the addresses used are physical addresses. If a process can be dispersed into many discontinuous spaces, memory compression can be avoided and fragments can be reduced. Based on this idea, the process address space is separated from the actual storage space by introducing the Logical Address of the process to increase the flexibility of storage management. The basic concepts of address space and storage space are defined as follows:
Address Space: The target program compiled by the source program exists in the address range defined by it. This range is called address space. An address space is a set of logical addresses.
Storage space: a set of physical units that store a series of information in the primary storage. The number of these units is called a set of physical addresses.
Based on the basic unit used for allocation, discrete allocation management can be divided into the following three methods:
Segment Storage Management and segment-page storage management. Segment-and-page storage management is the product of the first two combinations.
(1) page-based storage management
1) Basic principles. Divides the logical address space of a program into pages of a fixed size, and physical memory into pageframe of the same size ). When a program is loaded, any page can be stored in the memory of any page box, these page boxes do not need to be consecutive, thus achieving discrete distribution. This method requires hardware support from the CPU to map logical and physical addresses. In the page storage management mode, the address structure consists of two parts: the first part is the page number, the latter part is the page address, as shown in 4-2.
The advantage of this management method is that there are no external fragments, and each internal fragment cannot exceed the page size. The biggest improvement of several management methods discussed earlier is that a program does not need to be stored continuously. In this way, it is easy to change the size of the space occupied by the Program (mainly refers to the increase of dynamically generated data as the program runs, and the requested address space increases accordingly ). The disadvantage is that the program still needs to be fully loaded into the memory. If there is not enough memory, the program cannot be executed.
2) Data Structure of page management. When the webpage system is created, the operating system assigns a page box for all pages in the process. When a process is revoked, all the page boxes allocated to it are withdrawn. During the running of the program, if the process is allowed to dynamically apply for space, the operating system also needs to allocate a physical page for the space requested by the process. To complete these functions, the operating system must record the system memory
The actual page box usage. During process switching, the operating system also correctly switches the ing between two different process address spaces to the physical memory space. This requires the operating system to record the related information of each process page table. In order to complete the above functions, the following data structure is generally used in a page-based system.
Process page table: maps the logical page number (address space of the current process) to the physical page number (actual memory space.
Each process has a page table that describes the physical pages occupied by the process and the logical order.
Physical page table: the entire system has a physical page table that describes the allocation and usage of physical memory space. Its data structure can adopt a map and a list of idle pages.
Request table: the entire system has a request table that describes the location and size of each process page table in the system. For address conversion, it can also be combined into the PCB (Process Control Block) of each process.
3) Page Management address transformation
In a page system, the address given by the command is divided into two parts: the logical page number and the on-page address. The memory management unit (MMU) in the CPU obtains the physical page number by checking the process page table based on the Logical page number, add the box number on the physical page and the address on the page to form a physical address (see Figure 4-3 ). The above process is usually completed directly by the hardware of the processor without the involvement of software. Generally, the operating system only needs to load the first address of the Process page table into the processor-specific register during process switching. Generally, page tables are stored in the primary storage. In this way, each time the processor accesses an operand in the memory, it needs to access the memory twice. The first query is used to find a page table and convert the Logical Address of the operand to the physical address. The second query completes the real read/write operations. It takes a lot of time. To shorten the search time, you can load the page table from the memory into the associated memory (such as the quick table) in the CPU to perform Content-based search. The address conversion process is: after the CPU provides a valid address, the address translation Organization automatically sends the page number to the user table and compares the page number with all the page numbers in the table, in addition, this comparison is performed at the same time. If there is a page number that matches this, it indicates that the page table items of the page to be accessed are in the quick table. Therefore, you can directly read the physical page number corresponding to the page, so that you do not need to access the page table in the memory. Because the access speed of the associated memory is much faster than that of the memory.
(2) segmented Storage Management
1) Basic principles.
In the Segment Storage Management, the address space of the program is divided into several segments, so that each process has a two-dimensional address space. In the dynamic partition allocation method described above, the system allocates a continuous memory space for the entire process. In the Segment Storage Management System, a continuous partition is allocated for each segment, and each segment in the process can be stored in different memory partitions consecutively. When a program is loaded, the operating system allocates the required memory for all segments. These segments do not need to be contiguous. Physical memory management uses the dynamic partition management method. When allocating physical memory for a specific segment, you can use methods such as the first adaptation method, the next adaptation method, and the best adaptation method. When recycling the space occupied by a certain segment, pay attention to merging the reclaimed space with its adjacent space. Segment Storage management also requires hardware support to map logical addresses to physical addresses. Programs are divided into multiple modules by segments, such as code segments, data segments, and shared segments. In this way, you can write and compile a file of the source program separately, and use different protection measures for different types of segments, or share them by segment. In general, the advantage of segment-based storage management is that there are no internal fragments, and external fragments can be eliminated through memory compression to facilitate Memory Sharing. The disadvantage is the same as that of page-based storage management. All processes must be loaded into the memory.
2) Data Structure of segment management.
To achieve segment management, the operating system needs the following data structure to map the process address space to the physical memory space and track the usage of the physical memory, so that the memory space can be allocated properly when a new segment is loaded.
· Process Field table: describes each segment that constitutes the process address space. It can be an index pointing to table items in the system field table. Each segment has a base address ).
· System field table: all occupied segments of the system.
· Idle segment table: All idle segments in the memory can be combined into the system segment table.
3) address change for segment management.
In the segment management system, the address space of the entire process is two-dimensional, that is, its logical address consists of the segment number and the segment address. To map the logical address of a process to a physical address, the processor searches for the field table in the memory and adds the segment address to the first address obtained by the segment number, obtain the actual physical address (see Figure 4-4 ). This process is also directly completed by the processor's hardware. The operating system only needs to load the first address of the Process Field table into the specific register of the processor during process switching. This register is generally called a field table address register.
4. Differences between a page and a segment System
There are many similarities between a webpage and a segment system. For example, both use discrete distribution and address ing mechanism to implement address transformation. However, there are also many differences in concept between the two, mainly manifested in:
· The page is the physical unit of information. The page is used to achieve discrete distribution, reduce the external zero header of memory, and improve the memory utilization. In other words, pagination is only required by system management, not by users. Segment is the logical unit of information. It contains a set of relatively complete information. The purpose of segmentation is to better meet user needs.
· The page size is fixed and determined by the system. The logical address is divided into two parts: the page number and the address in the page, which are implemented by the machine hardware. The length of the segment is not fixed and is determined by the program you write. It is usually divided by the compilation system based on the nature of the information when compiling the source program.
· The address space of a page system is one-dimensional, that is, a single linear address space. Programmers only need to use one identifier to represent an address. The address space of a segmented job is two-dimensional. When identifying an address, the programmer must provide both the segment name and the intra-segment address.
Operating principle 10. features, characteristics, and advantages and disadvantages of page-based storage management and segment-based storage management. A: The basic idea of page management is: to make better use of the "zero Header" Problem in partition storage management, a job can be stored in discontinuous memory blocks, it can also run continuously. It allows only the common parts in the user's job to be transferred, and the non-common parts do not reside in the memory for a long time, effectively improving the memory utilization. Working principle of page-based storage management: A. Divide real pages: Divide physical memory into "blocks" with fixed locations and the same size ). B. Divide virtual pages: divide the user's logical address space into pages of the same size to become virtual pages of virtual space. C. Create a page table: sometimes called a page table or page ing table (PMT ). Each job registers according to the virtual page number. Its basic content has a feature bit (indicating whether the page is in memory, real page number, and the corresponding external address. D. address conversion: Convert the Logical Address of the virtual page to the physical address of the real page, and change it to the physical address during the execution of the process sequence. This is a dynamic job relocation, generally, the IP address translation mechanism (hardware) completes. Features: allows a job to be stored in a discontinuous memory block while ensuring continuous operation of the job. It does not need to move the information in the memory, but can better solve the problem of zero header. Advantage: A. Jobs are not required to be stored in contiguous memory blocks, effectively solving zero-header issues. B. allow a user job to load the memory not once but according to the need. The memory is not frequently used in the job and does not reside for a long time. C. virtual storage is provided so that the user's job address space is no longer limited by the size of the memory available space. Disadvantages: A. Page Management is not perfect in terms of Memory sharing and protection. B. The page size is the same, and the location cannot be dynamically increased. C. It usually takes several page breaks to fully transfer the required information to the memory. The basic idea of segmented storage management is to divide a program into segments based on the content or process (function) relationship. Each segment has its own name. The segments contained by a user job or process correspond to a two-dimensional linear virtual space, that is, a two-dimensional virtual memory. The segment manager allocates memory in segments, and then converts the segment virtual storage address to the actual address in the memory through the address ing mechanism. Like page-Based Management, segment-based management only stores frequently accessed segments in the memory, and stores those segments that will not be accessed in the future, the two-dimensional virtual memory is automatically transferred to the memory as needed. Memory is allocated according to the logical unit-segment of the job. It is suitable for the logic structure of the program and facilitates the user to set the program. Working principle of Segment Storage Management: A. Two-Dimensional address space, such as segment number (s), page number (p), and unit number in the page (d ); b. The system creates two tables, one field table for each job, and one page table for each segment. The segment table indicates the location of the page table in the memory. C. The address translation mechanism is similar to the page mechanism, only add a field number. Features: A. Each segment is divided into several pages and managed on a page basis without consecutive pages. B. Use the segmentation method to allocate management jobs and use the paging method to allocate management memory. Advantages: it facilitates segment sharing and protection, dynamic growth of segments, and dynamic connections. Disadvantage: in order to eliminate the dynamic growth of the zero header and allowed segments, it takes a lot of CPU time to move the job segments in the memory, and the size of the segment also brings difficulties to external memory management.