Collection
zero Useful+1
zero

Memory space

Terminology in the field of computer science
Memory is computer system One of the main parts , used to save the program and data when the process is running, also known as executable memory. In a computer, memory space generally refers to the main memory space (physical address space) or the memory space allocated by the system for a user program. The methods of expanding memory space generally include increasing memory size and virtual memory.
Chinese name
Memory space
Foreign name
Memory Space
Discipline
computer
Definition
The system allocates memory space for a user program
Relevant terms
Memory
Field
computer system

Module Introduction

Announce
edit
address space (address space) indicates the memory size occupied by any computer entity [1] The assembly module of the program formed after the source program is assembled or compiled and then processed by the link editor, and the module converted to the relative address, which is addressed in the order of 0 as the base address. Relative address is also called logical address or virtual address. The space composed of relative address in the program is called logical address space. The relative address space is converted to the absolute address space through the address relocation mechanism. The absolute address space is also called the physical address space [2] Memory space generally refers to the main memory space (physical address space) or the memory space allocated by the system for a user program. The system allocates memory space for a user program in four ways: single continuous allocation, fixed partition allocation, dynamic partition allocation, and dynamic relocation partition allocation.

Allocation method

Announce
edit
Single continuous distribution
This is the simplest storage management method, but it can only be used in single user, single task operating systems. When using this storage management method, the memory can be divided into two parts: the system area and the user area. The system area is only provided for the OS, and is usually placed in the low address part of the memory; The user area refers to all the memory space except the system area, which is provided for users. Although many of the early single user and single task operating systems were configured with memory protection mechanisms to prevent user programs from damaging the operating system, several common single user operating systems in recent years, such as CP/M, MS-DOS and RT11, have not taken memory protection measures. This is because, on the one hand, it can save hardware, and on the other hand, it is feasible. In a single user environment, the machine is monopolized by one user, and there is no possibility of interference from other users; At this time, the possible destruction is only the user program itself to destroy the operating system. The consequences are not serious, but will affect the operation of the user program. The operating system is also easy to reload memory by restarting the system. [3]
Fixed partition allocation
Fixed partition allocation is the simplest storage management mode that can run multiple programs. This is to divide the memory user space into several fixed size areas, and load only one job in each partition. In this way, the user space is divided into several partitions, allowing several jobs to run concurrently. When there is an idle partition, you can select a job of appropriate size from the backup job queue in the external storage to load the partition. When the job ends, you can find another job from the backup job queue to transfer to the partition.
Method of partition
The user space of memory can be divided into several fixed size partitions in the following two ways:
(1) The partitions are equal in size, even if all memory partitions are equal in size. Its disadvantage is lack of flexibility, that is, when the program is too small, it will waste memory space; When the program is too large, a partition is not enough to load the program, so the program cannot run. However, this method is still used to control multiple identical objects with one computer, because the memory space required by these objects is equal. For example, the furnace temperature group control system uses a computer to control multiple identical smelting furnaces.
(2) Partitions are not equal in size. To overcome the disadvantage of equal partition size and lack of flexibility, the memory area can be divided into several smaller partitions, moderate partitions and a few large partitions. In this way, appropriate partitions can be allocated according to the size of the program.
memory allocation
To facilitate memory allocation, partitions are usually queued by size and a partition usage table is created for them. Each table entry includes the starting address, size, and status (whether allocated or not) of each partition. When a user program is to be loaded, the memory allocator retrieves the table, finds a partition that meets the requirements and has not been allocated, assigns it to the program, and then sets the status of the table entry to "allocated"; If a partition of sufficient size is not found, memory allocation for the user program is denied.
Dynamic partition allocation
Dynamic partition allocation, also known as variable partition allocation, is a partition method for dynamic memory partition. This partitioning method does not partition the memory in advance, but dynamically builds partitions according to the size of the process when the process loads the memory, and makes the size of the partition just meet the needs of the process. Therefore, the size and number of partitions in the system are variable.
Dynamic partitioning is good at the beginning of allocation, but it will result in many small memory blocks later. As time goes by, more and more fragments will be generated in memory, and the utilization rate of memory will decline. These small memory blocks are called external fragments, which means that the storage space outside all partitions will become more and more fragmented, which is just opposite to the internal fragments in fixed partitions. Overcoming external fragmentation can be solved through Compact technology, that is, the operating system moves and reorganizes processes from time to time. However, this requires the support of dynamic relocation registers and is relatively time-consuming. The compact process is actually similar to the disk organizer in Windows, but the latter is compact in external storage space.
When a process loads or swaps into main memory, if there are multiple free blocks of sufficient size in the memory, the operating system must determine which memory block to allocate to the process. This is the allocation strategy of dynamic partitions. Consider the following algorithms:
First First algorithm: idle partitions are linked in the order of increasing address. When allocating memory, search in order to find the first free partition whose size can meet the requirements.
Best Fit algorithm: the idle partition forms the partition chain by increasing its capacity, and finds the first idle partition that can meet the requirements.
Worst Fit algorithm: also known as Largest Fit algorithm, idle partitions are linked in the order of decreasing capacity. Find the first free partition that can meet the requirements, that is, select the largest partition.
Next Fit algorithm: also called Cyclic first adaptation algorithm , evolved from the first adaptation algorithm. The difference is that when allocating memory, the search continues from the position where the last search ended.
Among these methods, the first adaptation algorithm is not only the simplest, but also usually the best and fastest. In the initial version of UNIX system, the first adaptation algorithm was used to allocate memory space for processes, which was implemented using array data structure (rather than linked list). However, the first adaptation algorithm will result in many small free partitions in the low address part of the memory, which will pass through each time the search is allocated, thus increasing the search overhead.
Neighborhood adaptation algorithm tries to solve this problem, but in fact, it often causes the allocation of space at the end of the memory (because in one pass scanning, when the front part of the memory is used and then released, it will not participate in the allocation) to split into small fragments. It is generally worse than the first adaptation algorithm.
Although the best adaptation algorithm is called "best", its performance is usually poor, because each best allocation will leave a small memory block that is difficult to use, and it will produce the most external fragments.
Worst case adaptation algorithm and Best fit algorithm On the contrary, if you select the largest available block, it seems that fragmentation is the least likely to occur, but the largest continuous memory is divided, which will quickly lead to no available large memory blocks, so the performance is also very poor.
Dynamic relocation partition allocation
In continuous allocation mode, a system or user program must be loaded into a continuous memory space. If there are only several small partitions in the system, even if the sum of their capacities is greater than the program to be loaded, the program cannot be loaded into memory because these partitions are not adjacent. Such small partitions that cannot be used are called "fragments" or "fragments".
If you want to load jobs, you can use one method: move all the jobs in the memory so that they are adjacent to each other. In this way, you can splice the originally scattered small partitions into a large partition. At this time, you can load jobs into the region. This method is called "splicing" or "compact", in which multiple scattered small partitions are spliced into a large partition by moving the job location in the memory. Because the position of some compact user programs in the memory has changed, if the address of the program and data is not modified (transformed) at this time, the program will not be executed. For this reason, the moved program or data must be relocated after each "pickup".
In the dynamic running mode, all the addresses after the job is loaded into the memory are still relative addresses. The conversion of relative addresses into physical addresses is postponed until the program instructions are actually executed. In order that the address conversion will not affect the execution speed of instructions, it must be supported by a hardware address conversion mechanism, that is, a relocation register must be added to the system to store the starting address of the program (data) in the memory. When the program is executing, the memory address actually accessed is formed by adding the relative address and the address in the relocation register.

Extension Method

Announce
edit

virtual memory

virtual memory It is a technology of computer system memory management. It makes the application think that it has continuously available memory (a continuous and complete address space). In fact, it is usually divided into multiple physical memory fragments, and some are temporarily stored outside Disk storage Data exchange when necessary. Compared with the system without virtual memory technology, the system with this technology makes it easier to write large programs physical memory (e.g RAM )It is also more efficient to use.
Virtual memory Storage information is automatically scheduled and managed by hardware and operating system. Its working process includes 6 steps:
a central processor The logical address of the access main memory is decomposed into group number a and intra group address b, and the address transformation of group number a is performed, that is, the logical group number a is used as an index, and the address transformation table is checked to determine whether the group information is stored in main memory.
② If the group number is already in Main storage And then execute ④; If the group number is not in the main memory, check whether there is a free area in the main memory. If there is no free area, transfer out a temporarily unused group to the secondary memory to transfer this group of information into the main memory.
③ Read the desired group from the secondary memory and send it to the free area of main memory, and then record the free physical group number a and logical group number a in the address transformation table.
④ Read the physical group number a corresponding to the logical group number a from the address transformation table.
⑤ Get the physical address from the physical group number a and the byte address b in the group.
⑥ Access necessary information from main memory according to physical address.
There are three scheduling modes: paging, segment, and segment page. Page scheduling is to divide the logical and physical address space into fixed size pages. The main memory is numbered in page order, and each independently addressed program space has its own page number order. By scheduling each page of the program in the secondary memory, it can be loaded into different page positions in the main memory discretely, and can be retrieved one by one according to the table. The advantage of page scheduling is that the bits in the page are small, the page table is transparent to programmers, the address transformation is fast, and the call in operation is simple; The disadvantage is that each page is not an independent module of the program, which is not convenient for program and data protection. Segment scheduling is to divide the address space according to the logical structure of the program. The length of the segment is arbitrary and can be extended. Its advantages are that it eliminates memory bits, is easy to realize storage protection, and is convenient for dynamic assembly of the program; The disadvantage is that the transfer in operation is complex. The combination of these two methods constitutes a segment page scheduling. In segment page scheduling, the physical space is divided into pages, the program is divided into modules, and each segment is divided into pages as small as the physical space page. Segment page scheduling combines the advantages of segment and page scheduling. Its disadvantage is that it increases the hardware cost and the software is more complex. Most large-scale general-purpose computer systems adopt segment page scheduling.

Physical address extension

Physical Address Extension (PAE for short), also known as physical location extension, is x86 A function of the processor that allows a central processor stay 32-bit operating system Access more than 4GB of physical memory.
PAE is Intel Pentium Pro And above CPU (including all new Pentium series processors except the version of Pentium M with a bus frequency of 400MHz), other compatible processors, such as Velociraptor (Athlon) and AMD The newer models of CPUs also support PAE.
The x86 processor adds an additional address line to select the increased memory, so the size of the physical memory is increased from 32 bits to 36 bits. The maximum physical memory increased from 4GB to 64GB.
32-bit Virtual address Linear address )It does not change, so general application software can continue to use 32-bit instructions; If using Flat Memory Mode The address space of these software is also limited to 4GB. For operating system Page Table Map the 4GB address space to the 64GB physical memory process Generally, it is different. In this way, the increased physical memory can still work even if it cannot be used by a single program.