A system memory application method, device, equipment and medium
By adding a mirror memory area between the mirror and non-mirror memory areas of the system memory and setting the mirror memory area as the non-mirror memory area, the OOM problem caused by insufficient mirror memory area is resolved, and the reliability of system memory is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SANGFOR TECH INC
- Filing Date
- 2022-09-29
- Publication Date
- 2026-05-29
AI Technical Summary
When the system memory's mirror area is insufficient, it cannot allocate non-mirror area memory, causing kernel processes to experience OutOfMemory (OOM) errors and affecting the reliability of system memory.
When the mirror memory of the system is insufficient, the kernel process is controlled to access non-mirror memory, and a mirror memory is added between the original non-mirror memory and the mirror memory. The mirror memory is then set as non-mirror memory in order to request the target memory.
This avoids the OutOfMemoryError (OOM) caused by the inability to allocate non-mirror memory when the mirror area memory is insufficient, thus improving the reliability of system memory.
Smart Images

Figure CN115470005B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of memory technology, and in particular to a method, apparatus, device and medium for applying for system memory. Background Technology
[0002] System memory is a crucial component of a computer system, used to store data processed by the central processing unit (CPU) and data exchanged with external storage devices such as hard drives. When system memory fails, it can lead to data loss or system crashes. To improve system memory reliability, memory mirroring is commonly used, dividing system memory into mirrored and non-mirrorized areas.
[0003] Currently, when the mirror area memory is insufficient and non-mirror area memory cannot be allocated, the system kernel process will be unable to allocate memory, resulting in an Out Of Memory (OOM) error.
[0004] Therefore, how to solve the OOM (Out of Memory) phenomenon caused by insufficient memory in the memory mirror area and improve the reliability of system memory is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0005] The purpose of this application is to provide a method, apparatus, device, and medium for allocating system memory. When a kernel process accesses mirror memory in system memory to allocate a first target memory, if the remaining memory in the mirror memory is insufficient to meet the first target memory requirement, the kernel process is controlled to access non-mirror memory to allocate the first target memory, thereby avoiding OutOfMemoryError (OOM) that occurs when non-mirror memory cannot be allocated due to insufficient mirror memory.
[0006] To address the aforementioned technical problems, this application provides a method for applying for system memory, comprising:
[0007] Obtain the kernel process's mirror memory access to the system memory to request the first target memory;
[0008] When the remaining memory in the mirror area is insufficient to meet the first target memory requirement, the kernel process is controlled to access non-mirror area memory to request the first target memory.
[0009] Wherein, the non-mirror area memory is the original non-mirror area memory of each node memory in the system memory, or the non-mirror area memory is the original mirror area memory in each node memory;
[0010] A new mirror memory is added between the original non-mirror memory and the original mirror memory of each node, and the original mirror memory is set as the non-mirror memory.
[0011] Preferably, the size of the newly added mirror area memory is the same as the size of the original mirror area memory.
[0012] Preferably, after obtaining the request from the kernel process to access the mirror area of system memory to request the first target memory, the method further includes:
[0013] Access the mirror area memory in the memory of each node to request the first target memory.
[0014] Preferably, the non-mirror region memory is the original mirror region memory in the memory of each node. Then, when the remaining memory in the mirror region memory does not meet the first target memory requirement, controlling the kernel process to access the non-mirror region memory to request the first target memory includes:
[0015] Access memory regions other than the original non-mirrorized memory region to request the first target memory.
[0016] Preferably, after obtaining the request from the kernel process to access the mirror area of system memory to request the first target memory, the method further includes:
[0017] A new memory region is added to the end of the linked list in the system memory, and the newly added memory region is set as the non-mirror region memory.
[0018] Preferably, the method for allocating system memory further includes:
[0019] Obtain a request from a user process to access non-mirrorized memory in the system to request a second target memory.
[0020] The user process is controlled to access memory regions other than the mirror area memory in order to request the second target memory.
[0021] Preferably, after obtaining the request from the user process to access the mirror area of system memory to request the second target memory, the method further includes:
[0022] Determine if the requested memory page contains a target flag indicating that it should prioritize the allocation of mirror region memory;
[0023] If it exists, the user process is controlled to access the mirror area memory in the memory of each node to apply for the second target memory. It is then determined whether the remaining memory in the mirror area memory meets the second target memory requirement. If not, the user process is controlled to access the non-mirror area memory to apply for the second target memory.
[0024] If it does not exist, proceed to the step of controlling the user process to access other memory regions besides the mirror area memory to request the second target memory.
[0025] To address the aforementioned technical problems, this application also provides a system memory allocation device, comprising:
[0026] The acquisition module is used to acquire the kernel process's request to access the mirror area memory of the system memory in order to request the first target memory;
[0027] The control module is configured to control the kernel process to access non-mirror area memory to request the first target memory when the remaining memory in the mirror area memory does not meet the first target memory requirement.
[0028] Wherein, the non-mirror area memory is the original non-mirror area memory of each node memory in the system memory, or the non-mirror area memory is the original mirror area memory in each node memory;
[0029] A new mirror memory is added between the original non-mirror memory and the original mirror memory of each node, and the original mirror memory is set as the non-mirror memory.
[0030] To address the aforementioned technical problems, this application also provides a system memory application device, including a memory for storing computer programs;
[0031] A processor, used to implement the system memory allocation method as described above when executing the computer program.
[0032] To address the aforementioned technical problems, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the system memory allocation method.
[0033] The present invention provides a method for allocating system memory, comprising: obtaining a request from a kernel process to access mirrored memory in system memory to allocate a first target memory; and, after obtaining the request, determining that the remaining memory in the mirrored memory is insufficient to meet the first target memory requirement, controlling the kernel process to access non-mirrored memory in system memory to allocate the first target memory. The non-mirrored memory is either the original non-mirrored memory of each node's memory in system memory, or a newly added mirrored memory between the original non-mirrored memory and the original mirrored memory of each node's memory, with the original mirrored memory set as non-mirrored memory, in which case the non-mirrored memory is the original mirrored memory of each node's memory. Therefore, the technical solution provided by this invention allows the kernel process to request memory in the original non-mirror region when the remaining memory in the mirror region is insufficient. Alternatively, a mirror region can be added between the original non-mirror region memory and the original mirror region memory in each node's memory, and the original mirror region memory can be set as non-mirror region memory. Thus, when the mirror region memory is insufficient, the memory with the original mirror region memory set as non-mirror region memory can be accessed to request the first target memory. This avoids the OOM phenomenon caused by the inability to request non-mirror region memory when the remaining memory in the traditional mirror region memory is insufficient, thereby improving the reliability of system memory.
[0034] In addition, this application also provides a system memory application apparatus, device and medium, which correspond to the above-described system memory application method and have the same effect. Attached Figure Description
[0035] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0036] Figure 1 A schematic diagram of the hardware architecture of the system memory application device provided in an embodiment of the present invention;
[0037] Figure 2 A flowchart illustrating a system memory allocation method provided in an embodiment of the present invention;
[0038] Figure 3 This is a schematic diagram of a system memory node provided in an embodiment of the present invention;
[0039] Figure 4 This is a schematic diagram of another system memory node provided in an embodiment of the present invention;
[0040] Figure 5 This is a structural diagram of the system memory application device provided in an embodiment of the present invention;
[0041] Figure 6 This is a structural diagram of a system memory application device provided in another embodiment of the present invention. Detailed Implementation
[0042] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.
[0043] The core of this application is to provide a method, apparatus, device, and medium for allocating system memory. When a kernel process accesses a mirrored area in system memory to request a first target memory, if the remaining memory in the mirrored area is insufficient to meet the first target memory requirement, the kernel process is controlled to access a non-mirrored area to request the first target memory. The non-mirrored area is the original non-mirrored area in the memory of each node in system memory, or a mirrored area is added between the original mirrored area and the original non-mirrored area, and then the original mirrored area is set as the non-mirrored area. In this case, the non-mirrored area becomes the original mirrored area, thereby avoiding OOM caused by insufficient mirrored area memory.
[0044] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0045] System memory is a crucial component of a computer system, used to store data processed by the CPU and data exchanged with external storage devices such as hard drives. When system memory fails, it can lead to data loss or system crashes. To improve system memory reliability, memory mirroring is commonly used, dividing system memory into mirrored and non-mirrored areas. Currently, when the mirrored area lacks sufficient memory to allocate non-mirrored memory, it can cause kernel processes to fail to allocate memory, resulting in an OutOfMemoryError (OOM) error.
[0046] To address the OutOfMemoryError (OOM) caused by insufficient mirror memory, this invention provides a method for allocating system memory. When a kernel process accesses mirror memory in system memory to request a first target memory, if the remaining memory in the mirror memory is insufficient to meet the first target memory requirement, the kernel process is controlled to access non-mirror memory to request the first target memory. The non-mirror memory can be the original non-mirror memory in the memory of each node in system memory, or it can be a mirror memory added between the original non-mirror memory and the original mirror memory, with the original mirror memory then set as the non-mirror memory; in this case, the non-mirror memory becomes the original mirror memory.
[0047] For ease of understanding, the hardware architecture to which the technical solution of the present invention applies will be described below. Figure 1 This is a schematic diagram of the hardware architecture of a system memory allocation device provided in an embodiment of the present invention. Figure 1 As shown, in the specific implementation, server 1 is started, and server 1 loads Basic Input Output System (BIOS) information, which includes CPU-related information, hard disk information, memory information, clock information, etc. Based on the product series platform of the server's processor, a memory mirroring support layer for system memory is introduced, dividing the system memory into mirrored memory and non-mirrored memory. Memory mirroring is enabled through the BIOS settings menu in terminal 2 to provide protection for the system. Each process in the system runs in the mirrored area and is adjusted by the system to adapt to the memory mirroring function.
[0048] Figure 2 A flowchart of the system memory allocation method provided in the embodiments of the present invention is shown below. Figure 1 As shown, the method includes:
[0049] S10: Obtain the kernel process's request to access the mirror area of system memory to request the first target memory.
[0050] S11: When the remaining memory in the mirror area is insufficient to meet the first target memory requirement, control the kernel process to access non-mirror area memory to request the first target memory.
[0051] Among them, non-mirror memory refers to the original non-mirror memory of each node in the system memory, or non-mirror memory refers to the original mirror memory of each node.
[0052] A new mirror memory area is added between the original non-mirror memory area and the original mirror memory area in each node's memory, and the original mirror memory area is set as the non-mirror memory area.
[0053] In a specific embodiment, after obtaining the kernel process's request to access the mirrored memory of system memory to apply for the first target memory in step S10, the process proceeds to step S11. When it is determined that the remaining memory in the mirrored memory does not meet the first target memory requirement (i.e., the remaining memory in the mirrored memory is less than the first target memory), the kernel process is controlled to access the non-mirrored memory in system memory to apply for the first target memory. The non-mirrored memory in system memory can be the original non-mirrored memory of each node in system memory, or it can be a newly added mirrored memory between the original non-mirrored and original mirrored memory, with the original mirrored memory set as non-mirrored memory. Therefore, this non-mirrored memory is the original mirrored memory. Thus, when the remaining memory in the mirrored memory does not meet the first target memory requirement, the kernel process can access this non-mirrored memory to apply for the first target memory.
[0054] Figure 3 This is a schematic diagram of a system memory node provided in an embodiment of the present invention. For ease of understanding, it will be described below in conjunction with... Figure 3 The technical solution of the present invention will be described in detail below. For example... Figure 3 As shown, the ZONE region memory in the system memory is selected for explanation. The allocation principle of other memory regions is the same as that of the ZONE memory region. The ZONE region memory includes the memory of N nodes. The memory of each node includes ZONE_MOVABLE region memory and ZONE_NORMAL region memory. Among them, some nodes include ZONE_DMA32 region memory and ZONE_DMA region memory. The ZONE_MOVABLE region memory is a non-mirrorized region memory, and the ZONE_NORMAL region memory is a mirrored region memory.
[0055] It should be noted that the ZONE_DMA32 and ZONE_DMA memory areas can be designated as mirrored or non-mirrored memory areas, depending on the user's actual business needs. It's understandable that mirrored memory provides system protection, so these two memory areas are typically set as mirrored. Regardless of whether they are set as mirrored or non-mirrored memory areas, when the ZONE_MOVABLE and ZONE_NORMAL memory areas are insufficient, they can request to borrow memory from the ZONE_DMA32 and ZONE_DMA memory areas.
[0056] Currently, when a kernel process accesses mirrored memory in system memory to request memory, it starts by accessing the ZONE_NORMAL region memory on each node to request the first target memory. When the ZONE_NORMAL region memory on each node is insufficient to meet the first target memory requirement, i.e., the remaining memory in the mirrored memory is insufficient to meet the required memory, it can request to borrow from the ZONE_DMA32 region memory and the ZONE_DMA region memory. However, since the ZONE_DMA32 region memory and the ZONE_DMA region memory are very small, they are easily fully occupied. When the remaining memory in other memory regions besides the mirrored region memory is insufficient to meet the required memory, due to the top-down memory allocation logic, if the mirrored region memory is insufficient, it cannot access non-mirrored region memory to request memory. In this case, the kernel process cannot allocate memory, resulting in an OutOfMemoryError (OOM).
[0057] It should be noted that the top-down allocation logic of the current kernel process accessing mirror memory to request memory can be as follows: It can start by accessing the mirror memory ZONE_NORMA0 of the starting node Node0, and then sequentially access the mirror memory ZONE_NORMA of each node. If the remaining memory in the mirror memory of any node is insufficient to meet the required memory allocation, it returns to Node0 and continues accessing the memory of Node0 outside of the mirror memory and mirror memory, i.e., accessing the ZONE_DMA32 and ZONE_DMA regions, and so on, sequentially accessing the ZONE_DMA32 and ZONE_DMA regions of each node to request memory. Alternatively, it can start by accessing the mirror memory ZONE_NORMA0 of Node0, proceeding from top to bottom. After accessing Node0, it starts accessing the mirror memory ZONE_NORMA of the next node, and so on, sequentially accessing the non-mirror memory of each node to request memory.
[0058] Therefore, according to the current allocation logic, when the remaining memory in the mirror memory is insufficient, memory in the non-mirror memory cannot be allocated, potentially leading to an OutOfMemoryError (OOM). To address this technical problem, the system memory allocation method provided by this invention, after receiving a request from a kernel process to access the mirror memory of the system memory to allocate the first target memory, if the remaining memory in the mirror memory is insufficient to meet the first target memory requirement, controls the kernel process to directly access the non-mirror memory to allocate the first target memory. Figure 3 As shown, when the memory of the mirror zone ZONE_NORMAL is insufficient, memory from the non-mirror zone ZONE_MOVABLE is requested.
[0059] It's worth noting that the non-mirrorized memory ZONE_MOVABLE accessed by the kernel process at this point refers to the raw non-mirrorized memory of each node in the system memory. However, the ZONE_MOVABLE region in system memory was allocated for hot-addition and memory migration. This means that memory pages in the ZONE_MOVABLE region can be migrated and used when needed. When the ZONE_NORMAL region is insufficient, it can naturally request to borrow from the ZONE_MOVABLE region. However, since some processes accessing the ZONE_NORMAL region have non-migratable memory pages, this can lead to non-migratable pages in the ZONE_MOVABLE region, thus violating the purpose of designing the ZONE_MOVABLE region in the system memory.
[0060] Therefore, due to the characteristics of ZONE_MOVABLE region memory, when the remaining memory in the mirror region is insufficient to meet the first target memory requirement, controlling the kernel process to directly access non-mirror region memory to request the first target memory has certain drawbacks. Therefore, to ensure the characteristics of ZONE_MOVABLE region memory, the system memory allocation method provided in this invention allows the non-mirror region memory accessed by the kernel process to also be the original mirror region memory. Figure 4 This is a schematic diagram of another system memory node provided in an embodiment of the present invention. For ease of understanding, it will be described below in conjunction with... Figure 4 Please provide a detailed explanation.
[0061] like Figure 4As shown, similarly, we will still select the ZONE region memory in system memory for explanation. The allocation principle for other memory regions is the same as that for the ZONE memory region. The ZONE region memory includes the memory of N nodes. Each node memory includes ZONE_MOVABLE region memory and ZONE_NORMAL region memory. Among them, some node memory includes ZONE_DMA32 region memory and ZONE_DMA region memory. The ZONE_MOVABLE region memory is the original non-mirror region memory, and the ZONE_NORMAL region memory is the original mirror region memory. A new ZONE_MIRROR region memory is added between the original non-mirror region memory ZONE_MOVABLE and the original mirror region memory ZONE_NORMAL of each node memory, and the original mirror region memory ZONE_NORMAL is set to non-mirror region memory. Therefore, when the kernel process requests memory, if the remaining memory in the mirror memory ZONE_MIRROR of each node is insufficient to meet the first target memory, the kernel process is controlled to access the memory in the non-mirror memory ZONE_NORMAL according to the top-down request logic to request the first target memory. This avoids the destruction of the characteristics of the ZONE_MOVABLE region memory when requesting memory from the original non-mirror memory ZONE_MOVABLE, and also avoids the OOM phenomenon that occurs when the mirror memory ZONE_MIRROR is insufficient.
[0062] It's important to note that the newly added mirrored memory can be placed between the original non-mirror memory (ZONE_MOVABLE) and the original mirrored memory (ZONE_NORMAL), or it can be placed after the original mirrored memory (ZONE_NORMAL). When the newly added mirrored memory (ZONE_MIRROR) is after the ZONE_NORMAL region, if the mirrored memory (ZONE_MIRROR) is insufficient, the kernel process can be controlled to acquire memory from the non-mirrored memory (ZONE_NORMAL) region. This way, the characteristics of the original non-mirrored memory (ZONE_MOVABLE) are not affected, and OOM (Out of Memory) errors caused by insufficient mirrored memory are avoided. It should also be noted that the size of the newly added mirrored memory (ZONE_MIRROR) is the same as the size of the original mirrored memory (ZONE_NORMAL). The current non-mirror zone memory ZONE_NORMAL can be the same as or different from the original non-mirror zone ZONE_MOVABLE. This invention does not limit this, but it should be noted that the sum of the current non-mirror zone memory ZONE_NORMAL and the current non-mirror zone ZONE_MOVABLE memory is equal to the original non-mirror zone memory size.
[0063] This invention provides a method for allocating system memory, comprising: obtaining a request from a kernel process to access mirrored memory in system memory to allocate a first target memory; and, after obtaining the request, determining that the remaining memory in the mirrored memory does not meet the first target memory requirement, controlling the kernel process to access non-mirrored memory in system memory to allocate the first target memory. The non-mirrored memory is either the original non-mirrored memory of each node's memory in system memory, or a newly added mirrored memory between the original non-mirrored memory and the original mirrored memory of each node's memory, with the original mirrored memory set as non-mirrored memory, in which case the non-mirrored memory is the original mirrored memory of each node's memory. Therefore, the technical solution provided by this invention allows the kernel process to request memory in the original non-mirror region when the remaining memory in the mirror region is insufficient. Alternatively, a mirror region can be added between the original non-mirror region memory and the original mirror region memory in each node's memory, and the original mirror region memory can be set as non-mirror region memory. Thus, when the mirror region memory is insufficient, the memory with the original mirror region memory set as non-mirror region memory can be accessed to request the first target memory. This avoids the OOM phenomenon caused by the inability to request non-mirror region memory when the remaining memory in the traditional mirror region memory is insufficient, thereby improving the reliability of system memory.
[0064] In a specific embodiment, in order to protect the characteristics of the original non-mirrorized region in the system memory, then as follows: Figure 4 As shown, a new mirrored memory region, ZONE_MIRROR, is added between the original non-mirror memory region ZONE_MOVABLE and the original mirrored memory region ZONE_NORMAL. The original mirrored memory region ZONE_NORMAL is then set to non-mirror memory. To avoid altering the original memory state of the system, the size of the newly added mirrored memory region ZONE_MIRROR is the same as the size of the original mirrored memory region. The sum of the sizes of the non-mirrored memory region ZONE_NORMAL and the non-mirrored memory region ZONE_MOVABLE is the same as the size of the original non-mirror memory region. This invention does not limit the percentage of the original non-mirror memory region occupied by the ZONE_NORMAL and ZONE_MOVABLE regions. For ease of understanding, examples will be provided below.
[0065] For example, if the original non-mirror memory size is 60GB and the original mirror memory size is 30GB, and a mirror memory ZONE_MIRROR is added between the original non-mirror memory and the original mirror memory, the size of the mirror memory ZONE_MIRROR will be the same as the size of the original mirror memory, that is, the size of the ZONE_MIRROR area will be 30GB. The sum of the size of the non-mirror memory ZONE_NORMAL and the size of the non-mirror memory ZONE_MOVABLE is 60GB.
[0066] This invention provides a system memory allocation method that adds a mirrored memory region between the original non-mirrored memory region and the original mirrored memory region in each node of the system memory, and sets the original mirrored memory region as the non-mirrored memory region. The non-mirrored memory region then becomes the original mirrored memory region in each node's memory. When the remaining memory in the mirrored memory region is insufficient to meet the first target memory request of the kernel process, the kernel process is controlled to access the non-mirrored memory region in the system memory to request the first target memory. This method ensures the characteristics of the original non-mirrored memory region while avoiding the Out of Memory (OOM) phenomenon caused by insufficient remaining memory in the traditional mirrored memory region, thus improving the reliability of system memory.
[0067] Based on the above embodiments, since the mirror memory has the function of protecting the system and improving the reliability of system memory, the technical solution provided by the present invention, when a kernel process obtains a request to access the mirror memory in the system memory to apply for the first target memory, controls the kernel process to first access the mirror memory of each node in the system memory to apply for the first target memory. When the mirror memory is insufficient, the kernel process is then controlled to access the non-mirror memory to apply for the first target memory.
[0068] like Figure 4 As shown, when the kernel process requests the first target memory, it starts by accessing the mirror memory ZONE_MIRROR0 of node Node0. If the memory of ZONE_MIRROR0 is insufficient, it accesses ZONE_MIRROR1. Thus, it accesses the ZONE_MIRROR region memory of each node in turn to request the first target memory. When the remaining memory of the mirror memory ZONE_MIRROR of each node cannot satisfy the first target memory, it returns to node Node0 and accesses the other memory regions in each node in turn, excluding the mirror memory, to request the first target memory.
[0069] The present invention provides a system memory allocation method that, when a kernel process accesses the mirror area memory in the system memory to allocate the first target memory, controls the kernel process to prioritize accessing the mirror area memory of each node memory in the system memory to allocate the first target memory, thereby improving the reliability of system memory.
[0070] In specific implementation, such as Figure 4 As shown, a mirrored memory region, ZONE_MIRROR, is added between the original non-mirrored memory region ZONE_MOVABLE and the original mirrored memory region ZONE_NORMAL. The original mirrored memory region ZONE_NORMAL is set to non-mirrored memory. When a kernel process requests the first target memory, if the remaining memory in the mirrored memory region ZONE_MIRROR of each node is insufficient to meet the first target memory requirement, the kernel process can access either the non-mirrored memory region ZONE_MOVABLE or ZONE_NORMAL to request the first target memory. However, to protect the characteristics of the ZONE_MOVABLE region in the system memory design, the kernel process is controlled to preferentially access the non-mirrored memory region ZONE_NORMAL to request the first target memory.
[0071] The present invention provides a method for allocating system memory by adding a mirror memory region between the original non-mirror memory region and the original mirror memory region, and setting the original mirror memory region as a non-mirror memory region. If the remaining memory in the mirror memory region is insufficient to meet the memory required by the kernel process, the kernel process is controlled to prioritize accessing memory other than the original non-mirror memory region to apply for the target memory. Thus, while ensuring the characteristics of the original non-mirror memory region, it can also avoid OOM caused by insufficient mirror memory region in the system memory region.
[0072] Based on the above embodiments, when all memory regions other than the original non-mirrorized memory region do not meet the first target memory required by the kernel process, in order to further guarantee the characteristics of the original non-mirrorized memory region, the system memory allocation method provided by this invention can also add a memory region at the end of the linked list of system memory, and this added memory region is non-mirrorized memory region. When all memory regions other than the original non-mirrorized memory region do not meet the first target memory required by the kernel process, the memory of the newly added non-mirrorized region at the end of the linked list can be allocated to avoid OOM (Out of Memory) errors.
[0073] The present invention provides a method for allocating system memory by adding a non-mirror region memory at the end of the linked list of system memory. When the memory in other regions besides the original non-mirror region memory does not meet the first target memory required by the kernel process, the kernel process can access the newly added non-mirror memory at the end of the linked list to apply for the first target memory. This further ensures the characteristics of the original non-mirror region memory while avoiding OOM caused by insufficient mirror region memory in the system memory.
[0074] Currently, when a user process accesses non-mirrored memory in system memory to request memory, if the remaining memory in the non-mirrored memory is insufficient to meet the user process's memory request, it does not prevent the user process from accessing mirrored memory to request memory. When mirrored memory is excessively occupied, it can still lead to OutOfMemoryError (OOM) due to insufficient mirrored memory. Therefore, to further avoid OOM when mirrored memory is insufficient, the system memory allocation method provided by this invention further includes:
[0075] Obtain a request from a user process to access non-mirrorized memory in the system to request a second target memory.
[0076] Control user processes to access memory regions other than the mirror area to request a second target memory.
[0077] like Figure 3 As shown, according to the current top-down allocation logic, when a user process accesses a non-mirrored area in system memory to request memory, it starts by requesting memory from the non-mirrored area memory ZONE_MOVABLE. If the remaining memory in the non-mirrored area is insufficient to meet the memory requested by the user process, it then requests memory from the mirrored area memory ZONE_NORMA. This may result in excessive use of memory in the ZONE_NORMA area, leading to insufficient mirrored area memory and an OutOfMemoryError (OOM).
[0078] Therefore, to avoid OutOfMemoryError (OOM), the system memory allocation method provided in this application, when receiving a request from a user process to access non-mirror region memory of the system memory to allocate a second target memory, controls the user process to access memory regions other than the mirror region memory to allocate the second target memory, thereby avoiding OOM caused by excessive occupation of the mirror region memory. Figure 3 As shown, when the non-mirror memory ZONE_MOVABLE is insufficient, it skips the mirror memory ZONE_NORMA and requests a second target memory. Alternatively, it could be as follows: Figure 4 As shown, when the non-mirror memory ZONE_MOVABLE is insufficient, it skips the mirror memory ZONE_MIRROR and requests memory from the non-mirror memory ZONE_NORMA.
[0079] The present invention provides a system memory allocation method. When a user process accesses non-mirror area memory of system memory to allocate a second target memory, in order to avoid the user process occupying mirror area memory and causing an OutOfMemoryError (OOM) due to insufficient mirror area memory when the remaining memory in the non-mirror area memory is insufficient to meet the second target memory, after determining that the user process is accessing system memory, the method controls the user process to only access memory other than mirror area memory to allocate the second target memory. This avoids the system from OOM and improves the reliability of the system.
[0080] In practical implementation, depending on user needs, a small number of user processes need to request mirrored memory. Therefore, based on the above embodiments, after obtaining the request from the user process to access the mirrored memory of system memory to request the second target memory, the following is also included:
[0081] Determine if the requested memory page has a target flag indicating that it should prioritize the allocation of mirror region memory.
[0082] If it exists, control the user process to access the mirror area memory in the memory of each node to request the second target memory, determine whether the remaining memory in the mirror area memory meets the second target memory, if not, control the user process to access the non-mirror area memory to request the second target memory;
[0083] If it does not exist, proceed to the step of controlling the user process to access other memory regions besides the mirror area memory to request the second target memory.
[0084] After receiving a request from a user process to allocate a second target memory, the system first checks if a target flag exists for prioritizing mirrored memory allocation. If a target flag exists, the user process is controlled to access mirrored memory on each node to allocate the second target memory. When mirrored memory is insufficient, the user process is then controlled to access non-mirrored memory to allocate the second target memory. It should be noted that when a user process needs to allocate mirrored memory, the allocation logic is the same as that of the kernel process. That is, it prioritizes allocating mirrored memory on each node; when mirrored memory is insufficient, it returns to the starting node to allocate memory from other regions besides mirrored memory. If no target flag exists for the allocated memory page, it is determined that the user process needs to allocate non-mirrored memory. In this case, the user process is controlled to access non-mirrored memory to allocate the second target memory.
[0085] In practical implementation, based on actual user business needs, when some user processes need to request memory from kernel processes, a flag is added to the memory page request. This flag is checked during page fault exceptions and memory page requests. If the flag is found, it indicates that the process needs to request memory from the mirror memory area, so a target flag is added. When a user process accesses system memory to request a second target memory, this target flag is obtained, and the user process is then controlled to access the mirror memory area in each node's memory to request the second target memory. For ease of understanding, an example will be provided below.
[0086] For example, based on actual user business needs, when some user processes need to request memory from kernel processes, a MAD_MIRROR flag is added to the requested memory page. During a page fault and memory page request process, a check is performed. If the MAD_MIRROR flag is found, it indicates that the process needs to request memory from the mirror memory region. In this case, a target flag GFP_MIRROR is added. When a user process requests a second target memory region, if the target flag GFP_MIRROR is found, the user process is controlled to access the mirror memory region in each node's memory to request the second target memory. Otherwise, the user process is controlled to access other memory regions besides the mirror memory region to request the second target memory.
[0087] The present invention provides a system memory allocation method. When there is a target flag indicating that the memory page to be allocated should be allocated to a mirror area, the user process is controlled to access the mirror area memory in the memory of each node to allocate the second target memory, thereby satisfying the different allocation needs of the user process.
[0088] Finally, to facilitate a better understanding of the technical solution of this invention by those skilled in the art, the following will be combined with... Figure 4 This section provides a detailed explanation of how the kernel and users request system memory.
[0089] It should be noted that, in order to ensure the characteristics of the ZONE_MOVABLE region in system memory while avoiding OOM (Out of Memory) errors due to insufficient mirrored memory, this invention preferably adds a mirrored memory region ZONE_MIRROR between the original non-mirrored memory region ZONE_MOVABLE and the original mirrored memory region ZONE_NORMAL, and sets the original mirrored memory region ZONE_NORMAL as non-mirrored memory. In this case, the ZONE_MOVABLE region is non-mirrored memory, ZONE_MIRROR is mirrored memory, and ZONE_NORMAL is non-mirrored memory.
[0090] In practice, it is first necessary to determine whether the process requesting the memory is a kernel process or a user process. If it is determined to be a kernel process, the process will start by requesting memory from the mirror memory ZONE_MIRROR of each node in the system memory. After accessing the mirror memory ZONE_MIRROR of each node in turn, if the remaining memory in the mirror memory cannot meet the memory requested by the kernel process, the kernel process will be controlled to access the non-mirror memory ZONE_NORMAL to request memory.
[0091] If the requesting process is a user process, the system first checks if the user process has a target flag indicating that it should prioritize requesting mirrored memory. If the target flag exists, memory allocation is performed according to the kernel's allocation logic, prioritizing mirrored memory. If mirrored memory is insufficient, non-mirrored memory is then requested. If no target flag exists, the user process is controlled to start accessing non-mirrored memory (ZONE_MOVABLE). When the non-mirrored memory (ZONE_MOVABLE) on each node is insufficient, the user process is controlled to skip mirrored memory (ZONE_MIRROR) and access non-mirrored memory (ZONE_NORMAL) to request memory.
[0092] In the above embodiments, the method for allocating system memory has been described in detail. This application also provides embodiments corresponding to the system memory allocating apparatus. It should be noted that this application describes the embodiments of the apparatus from two perspectives: one is based on functional modules, and the other is based on hardware structure.
[0093] Figure 5 This is a structural diagram of the system memory application device provided in an embodiment of the present invention, as shown below. Figure 5 As shown, the device includes:
[0094] Module 10 is used to obtain the kernel process's request to access the mirror area memory of the system memory in order to request the first target memory.
[0095] The control module 11 is used to control the kernel process to access non-mirror area memory to request the first target memory when the remaining memory in the mirror area memory is insufficient to meet the first target memory requirement.
[0096] Among them, non-mirror memory is the original non-mirror memory of each node in the system memory, or non-mirror memory is the original mirror memory of each node memory, with a new mirror memory added between the original non-mirror memory and the original mirror memory of each node memory, and the original mirror memory is set as non-mirror memory.
[0097] Since the embodiments of the apparatus and the embodiments of the method correspond to each other, please refer to the description of the embodiments of the method for the embodiments of the apparatus, which will not be repeated here.
[0098] An embodiment of the present invention provides a system memory allocation apparatus, comprising: obtaining a request from a kernel process to access mirrored memory in system memory to allocate a first target memory; and, after obtaining the request, determining that the remaining memory in the mirrored memory does not meet the first target memory requirement, controlling the kernel process to access non-mirrored memory in system memory to allocate the first target memory. The non-mirrored memory is either the original non-mirrored memory of each node's memory in system memory, or a newly added mirrored memory between the original non-mirrored memory and the original mirrored memory of each node's memory, with the original mirrored memory set as non-mirrored memory, in which case the non-mirrored memory is the original mirrored memory of each node's memory. Therefore, the technical solution provided by this invention allows the kernel process to request memory in the original non-mirror region when the remaining memory in the mirror region is insufficient. Alternatively, a mirror region can be added between the original non-mirror region memory and the original mirror region memory in each node's memory, and the original mirror region memory can be set as non-mirror region memory. Thus, when the mirror region memory is insufficient, the memory with the original mirror region memory set as non-mirror region memory can be accessed to request the first target memory. This avoids the OOM phenomenon caused by the inability to request non-mirror region memory when the remaining memory in the traditional mirror region memory is insufficient, thereby improving the reliability of system memory.
[0099] Figure 6 A structural diagram of a system memory application device provided in another embodiment of the present invention is shown below. Figure 6 As shown, the system memory allocation device includes: memory 20, used to store computer programs;
[0100] The processor 21 is configured to implement the steps of the system memory allocation method as described in the above embodiments when executing a computer program.
[0101] The system memory request device provided in this embodiment may include, but is not limited to, smartphones, tablets, laptops, or desktop computers.
[0102] The processor 21 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 21 may be implemented using at least one of the following hardware forms: Digital Signal Processor (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 21 may also include a main processor and a coprocessor. The main processor, also known as the Central Processing Unit (CPU), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 21 may integrate a Graphics Processing Unit (GPU), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 21 may also include an Artificial Intelligence (AI) processor, which handles computational operations related to machine learning.
[0103] The memory 20 may include one or more computer-readable storage media, which may be non-transitory. The memory 20 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In this embodiment, the memory 20 is used to store at least the following computer program 201, which, after being loaded and executed by the processor 21, is capable of implementing the relevant steps of the system memory allocation method disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, and the storage method may be temporary or permanent storage. The operating system 202 may include Windows, Unix, Linux, etc. The data 203 may include, but is not limited to, the relevant data involved in the system memory allocation method.
[0104] In some embodiments, the system memory requesting device may further include a display screen 22, an input / output interface 23, a communication interface 24, a power supply 25, and a communication bus 26.
[0105] Those skilled in the art will understand that Figure 6 The structure shown does not constitute a limitation on the system memory request device and may include more or fewer components than shown.
[0106] The system memory allocation device provided in this application embodiment includes a memory and a processor. When the processor executes a program stored in the memory, it can implement the following method: system memory allocation method.
[0107] The system memory allocation device provided in this embodiment of the invention can allocate memory in the original non-mirror region when the kernel process requests the first target memory and the remaining memory in the mirror region is insufficient. Alternatively, a mirror region can be added between the original non-mirror region memory and the original mirror region memory in each node memory, and the original mirror region memory can be set as non-mirror region memory. Thus, when the mirror region memory is insufficient, the memory with the original mirror region memory set as non-mirror region memory can be accessed to allocate the first target memory. This avoids the OOM phenomenon caused by the inability to allocate non-mirror region memory when the remaining memory in the traditional mirror region memory is insufficient, thereby improving the reliability of system memory.
[0108] Finally, this application also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps described in the above method embodiments.
[0109] It is understood that if the methods in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and executes all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0110] The foregoing has provided a detailed description of a method, apparatus, device, and medium for applying for system memory. The various embodiments in the specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.
[0111] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A method for allocating system memory, characterized in that, include: Obtain the kernel process's mirror memory access to the system memory to request the first target memory; When the remaining memory in the mirror area is insufficient to meet the first target memory requirement, the kernel process is controlled to access non-mirror area memory to request the first target memory. Wherein, the non-mirror area memory is the original non-mirror area memory of each node memory in the system memory, or the non-mirror area memory is the original mirror area memory in each node memory; the system memory is deployed on the server, and the system memory includes the memory of each node; A new mirror memory is added between the original non-mirror memory and the original mirror memory of each node, and the original mirror memory is set as the non-mirror memory.
2. The method for requesting system memory according to claim 1, characterized in that, The newly added mirror area memory has the same memory size as the original mirror area memory.
3. The method for requesting system memory according to claim 2, characterized in that, Following the request to obtain the mirror area memory of the kernel process accessing system memory in order to request the first target memory, the following is also included: Access the mirror area memory in the memory of each node to request the first target memory.
4. The method for allocating system memory according to claim 2, characterized in that, The non-mirror region memory refers to the original mirror region memory within the memory of each node. Therefore, when the remaining memory in the mirror region memory does not meet the first target memory requirement, controlling the kernel process to access the non-mirror region memory to request the first target memory includes: Access memory regions other than the original non-mirrorized memory region to request the first target memory.
5. The method for requesting system memory according to claim 1, characterized in that, Following the request to obtain the mirror area memory of the kernel process accessing system memory in order to request the first target memory, the following is also included: A new memory region is added to the end of the linked list in the system memory, and the newly added memory region is set as the non-mirror region memory.
6. The method for requesting system memory according to claim 1, characterized in that, Also includes: Obtain a request from a user process to access non-mirrorized memory in the system to request a second target memory. The user process is controlled to access memory regions other than the mirror area memory in order to request the second target memory.
7. The method for allocating system memory according to claim 6, characterized in that, Following the request to obtain the mirrored memory of the user process accessing system memory in order to request the second target memory, the following is also included: Determine if the requested memory page contains a target flag indicating that it should prioritize the allocation of mirror region memory; If it exists, the user process is controlled to access the mirror area memory in the memory of each node to apply for the second target memory. It is then determined whether the remaining memory in the mirror area memory meets the second target memory requirement. If not, the user process is controlled to access the non-mirror area memory to apply for the second target memory. If it does not exist, proceed to the step of controlling the user process to access other memory regions besides the mirror area memory to request the second target memory.
8. A system memory allocation device, characterized in that, include: The acquisition module is used to acquire the kernel process's request to access the mirror area memory of the system memory in order to request the first target memory; The control module is configured to control the kernel process to access non-mirror area memory to request the first target memory when the remaining memory in the mirror area memory does not meet the first target memory requirement. Wherein, the non-mirror area memory is the original non-mirror area memory of each node memory in the system memory, or the non-mirror area memory is the original mirror area memory in each node memory; the system memory is deployed on the server, and the system memory includes the memory of each node; A new mirror memory is added between the original non-mirror memory and the original mirror memory of each node, and the original mirror memory is set as the non-mirror memory.
9. A system memory allocation device, characterized in that, Includes memory used to store computer programs; A processor, configured to implement the steps of the system memory allocation method as described in any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the system memory allocation method as described in any one of claims 1 to 7.