In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the Linux virtual memory how to understand the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Linux virtual memory how to understand the article will have a harvest, let's take a look.
Define
In order to correctly understand the working principle of the virtual memory manager and sharpen the knife without mistakenly chopping firewood, let's first understand the composition of virtual memory. While it is beneficial to the concept of low-level composition of virtual memory, it is necessary to learn more about how virtual memory works and how its performance can be optimized.
What is virtual memory made of?
Figure 1. Composition diagram of advanced virtual memory subsystem
The complexity of the virtual memory subsystem in Linux systems is extremely complex, but we can learn more about virtual memory through the following components:
MMU
Memory management unit (MMU, Memory Management Unit, hereinafter referred to as MMU) is the physical hardware basis for implementing a virtual memory system. MMU allows software to map to a physical address through an alias address, usually more than one. This is done by using paging (pages) and paging table (paging table: paging table is a data structure that cuts the memory space into paging form to store the correspondence between virtual memory and physical memory in order to use the virtual memory technology of computer operating system). MMU uses a portion of memory to translate the mapping of virtual addresses to physical addresses through a series of lookup tables (Table lookups).
Zoned Buddy Allocator (regional memory allocator did not find a Chinese standard translation, Buddy Allocator temporarily translated as friend memory allocator)
The area memory allocator is responsible for the paging storage management of the entire virtual memory system. This part of the code manages the linked list of consecutive physical memory pages and maps them to MMU's paging table (page tables), which provides a valid physical address when other systems and core subsystems request a physical address (the mapping of physical address to virtual memory address is handled by the higher layer of the virtual memory system). From the name of the friend memory allocator, we can infer the algorithm that the subsystem uses to maintain the free list. All physical pages in memory are sorted and grouped into the list by the friend memory allocator. Each list represents 2n paged clusters, where n increases gradually with each one. If there are no requests in the request list, the next request in the package will be divided into two isolated clusters and returned to the requestor when the next request arrives. When the allocation returns the request to the friend allocator, the inversion process begins; notice that the friend memory allocator also manages the memory area of the memory pool that defines different uses. Currently, the friend memory allocator can manage access to the following three memory pools:
The DMA- area contains the initial 16MB space of memory, which is used as space for legacy devices (legacy devices) to operate directly on memory.
This part of the NORMAL- includes the next 16MB-to-1GB memory address, which is used as the internal data structure of the kernel and the space for the system and users to allocate.
This part of HIGHMEM- contains addresses above 1GB and is reserved for operating system allocation (such as file system buffering, user space allocation, etc.).
Slab allocator
The Slab allocator provides a more available front-end implementation to cooperate with the Buddy (partner algorithm) allocator, which is mainly used to respond to requests for more flexible memory (not the commonly used 4KB) in some parts of the kernel. The Slab allocator allows kernel components to create memory object caches of a given size. The Slab allocator is responsible for putting as many cached objects on one page as possible and monitoring which objects have been freed and which memory has been allocated. When there is a memory allocation request but no memory is available in the page, the Slab allocator requests more pages from the Buddy allocator to satisfy the allocation request. This makes it easier for kernel components to use memory. With this approach, many components that use only a small amount of memory do not need their own code to implement memory management, thus not wasting a lot of pages. The Slab allocator can only allocate memory from the DMA and NORMAL areas.
Kernel thread
The last component of the virtual memory subsystem is the kernel thread, including: kscand, kswapd, kupdated, and bdflush. These threads are responsible for the recovery and management of the memory being used. All pages in virtual memory have an associated state (for more information on memory state machines, see the section "Page Lifecycle") generally speaking, active threads related to virtual memory in the kernel are responsible for trying to move pages out of RAM. They regularly check the RAM to try to identify and release inactive memory, so that this part of the memory can be used for other purposes in the system.
The life cycle of the page
All memory managed by virtual memory is marked with a status. These states help virtual memory know what to do with a given page in a variety of situations. Depending on the needs of the current system, virtual memory may be based on the state machine (figure 2. The virtual memory page state machine) transfers the page from one state to the next. Using these states, virtual memory can determine what the operating system does to a page at a certain time, and it can also decide what to do with the page. These states of special significance are as follows
1.FREE-all pages that can be assigned start in this state. This state tells virtual memory that this page is not used for any purpose and can be allocated.
2.ACTIVE-the page has been assigned by the Buddy allocator and then enters the ACTIVE state. This state tells virtual memory that the page has been allocated and that it has been used by the memory process or the user process.
3. INACTIVE DIRTY-this status indicates that this page has been abandoned by the process that asked to allocate it, and that it has become a candidate to be removed from main memory. The kscand task periodically scans pages in memory and notes the total time the page has been in memory since it was last visited. If the kscand task finds that the page has been visited since it last scanned the page, it will increase the value of the page's age counter, otherwise it will decrease the value of the page's age counter. When the kscand task finds that the age counter for this page has a value of 0, it sets the status of the page to INACTIVE DIRTY. Pages in the INACTIVE DIRTY state are saved in the list of pages to be cleared.
4. INACTIVE LAUNDERED-this is a temporary state in which the page has been selected to be removed from main memory, while the contents of the page will be saved on disk. Only pages in the INACTIVE DIRTY state can enter this state. Once the disk IZP O operation (write disk operation) is completed, the state of the page is transferred to INACTIVE CLEAN, and in the INACTIVE CLEAN state, the page may be released or rewritten for other purposes. If the page is accessed during the (write) disk operation, its state will become ACTIVE.
5. INACTIVE CLEAN-the page in this state has been erased from memory. This means that the contents of this page have been synchronized to disk. As a result, this page may be freed by virtual memory or rewritten for other purposes.
This is the end of the article on "how to understand the virtual memory of Linux". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to understand the virtual memory of Linux". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.