How Windows Memory is managed

Source: Internet
Author: User

First, the concept of memory

1. Physical Memory: A memory strip plugged into the motherboard. He is fixed, how large the memory bar is, and how large the physical memory is (except for integrated graphics systems).

However , if the program runs a lot or the program itself is large, it can lead to a lot of physical memory consumption, and even the exhaustion of physical memory.

2. Virtual Memory: virtual memory is the partition of a page file on the hard disk, which acts as memory.

When the program is running, some resources have not been used or open several programs at the same time to operate only one of the programs, the system does not have to plug all the resources of the program in the physical memory, so the system will be temporarily unused resources in the virtual memory, wait for the need to be transferred out.

When the program runs, it needs to read out the code of the program from memory. The location of the code must be in physical memory to be able to be run, because the current operating system has a very many programs running, memory can not be completely put down, so the concept of virtual memory.

Put the infrequently used pieces of the program into virtual memory, when it is necessary to use it in the load to the main storage (physical memory). This is what memory management needs to do, and there's another thing to do with memory: compute the physical location of the program fragment in main memory for CPU scheduling.

3. Theoretical basis for virtual memory viability:1. All memory access addresses in the process are logical addresses that are dynamically converted to physical addresses at run time, which means that a process can be swapped in or out of memory, allowing processes to occupy different areas of memory at different times during execution. 2, a process can be divided into many blocks, in the execution process, these blocks do not need continuous physical memory. 4. Benefits of using virtual memory:1. Keep multiple processes in memory. Because only some of its blocks are loaded into any particular process, there is plenty of room for more processes to be placed. 2, the process can be larger than the total space of memory. The size of the memory space that the program occupies is one of the biggest limitations in programming. With virtual memory based on paging or fragmentation, these tiles can be loaded separately by some override policy.

Second, the Windows memory management methods are mainly divided into: page management, Segment management, section page management.

1. Fixed partitionDescription: During the system generation phase, memory is divided into many static partitions.   A process can be loaded into a partition greater than or equal to its size.   Advantage: Simple to implement, with minimal operating system overhead. Disadvantage: Due to internal fragmentation, the use of memory is not sufficient; The maximum number of active processes is fixed. 2. Dynamic partitioningDescription: Partitions are created dynamically so that each process can be loaded into a partition that is exactly the same size as itself.  Advantage: There is no internal fragmentation; You can use memory more fully. Disadvantage: Processor utilization is low due to the need to compress external fragments.

3. Page Management: The basic principle of page-style management is to divide the virtual space of each process into several pages of equal length;

Page management divides the memory space into pieces or pages according to the size of the page, then sets the page virtual address and memory address to one by one corresponding page table, and solves the problem of discrete address transformation by the corresponding hardware address transformation mechanism.

Page management uses the request paging or the pre-paging technology to realize the unified management of internal and external storage. You do not need to mount all the pages of a process, and each time you simply mount the page that the process needs to run into a page box that is not necessarily contiguous in memory, the non-resident page automatically calls into memory when it is needed later.

The advantage is that there is no outer fragment, and each inner fragment does not exceed the size of the page.

The disadvantage is that the program is all loaded into memory and requires appropriate hardware support. For example, Address transformation mechanism page fault generation and selection of obsolete pages, etc. require the corresponding hardware support. This increases the cost of the machine and increases the system overhead.

4. Segment Management: The basic idea of segment management is to segment the program in terms of content or process functions, each with its own name.

A user job or process includes a segment that corresponds to a two-dimensional linear virtual space, which is a two-dimensional virtual memory. The segment manager allocates memory in segments and then translates the segment virtual address into the physical address of the actual memory through the address mapping mechanism.

You do not need to load all segments of a process, and each time you simply load the required segments of the process into a dynamic partition that is not necessarily contiguous in memory, the non-resident segment automatically calls into memory when needed.

The advantage is that it can be written and compiled separately, can be different protection for different types of segments, can be shared by segment, including code sharing through dynamic links.

The disadvantage is that it produces fragmentation.

5. Section-page Management: in order to achieve section-page management, the system must establish a segment table for each job or process to manage memory allocation and release, missing segment processing, and so on.

In addition, a segment is divided into several pages. Each segment must create a page table to transform the virtual pages in the segment into the actual pages in memory. Obviously the same as the page management, the page table should also have corresponding to implement page break processing and pages protection and other functions of the table entries.

Segment management with page management is a combination of the two, so they have the advantage of both.

In turn, however, the complexity and overhead increase as management software grows. Additional hardware required and memory usage increased. Make the speed drop down.

segmentation and paging have their advantages:
    • Paging is transparent to the programmer, it eliminates external fragments, so it can use memory more efficiently, and blocks that move in or out of memory are fixed and equal in size.
    • Fragmentation is visible to programmers, with the ability to handle ever-growing data structures and the ability to support sharing and protection.
    • In a page-style system, the user's address space is divided by programmers into many segments. Each segment is divided into many fixed-size pages at once, and the length of the page is equal to the size of the In-memory page box.
    • From the programmer's point of view, the logical address is still composed of a segment number and a segment offset, from a system perspective, the segment offset can be treated as a page number and page offset in the specified segment.

The difference between a page and a paragraph:

Similarity: Discrete allocation, address mapping mechanism to implement address translation

(1) The page is the physical unit of information, paging is to achieve discrete distribution, reduce the amount of memory, improve memory utilization, or because of the needs of the system management, rather than the needs of users. Paragraph is the logical unit of information, it contains a set of relatively complete information, the purpose of segmentation is to better meet the needs of users.

(2) The page size is fixed and determined by the system, the logical address is divided into the page number and the page address two parts, is the machine hardware implementation, the length of the segment is not fixed, but decided by the user to write the program, usually by the compilation system in the source program compiled according to the nature of the information to divide.

(3) The system address in the page is one-dimensional, that is, a single linear address space, the programmer can only use an identifier to represent an address. The job address space for a segment is two-dimensional, and the programmer needs to give the segment name when identifying an address, and the address within the segment.

How Windows Memory is managed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.