Memory management method, program product, equipment and medium
By obtaining memory configuration information when the system kernel starts, segmenting the reserved memory and allocating metadata based on the hot-plug framework, and establishing a mapping array, the problem of reserved memory being unrecognizable is solved, and efficient management of reserved memory and improved system consistency are achieved.
Patent Information
- Application Number
- CN202511241343.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-02
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2045-09-02
AI Technical Summary
In the existing technology, reserved memory cannot be recognized by the general standard page operation interface due to the lack of a valid struct page structure, which limits its versatility, affects kernel mechanisms such as page migration and NUMA balancing, and reduces system consistency and observability.
By obtaining the memory configuration information when the system kernel is started, the reserved memory is segmented based on the hot-swap framework, and target metadata is assigned to each memory segment. A target mapping array is established to achieve the integration of reserved memory and standard memory management and support efficient memory access.
Improves the versatility of reserved memory, enabling developers to use standard kernel page operation interfaces, simplifying application development, enhancing system consistency and observability, and reducing system complexity and maintenance burden.
Smart Images

Figure CN120743564A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a memory management method, program product, device and medium. Background Art
[0002] Currently, after the system kernel identifies reserved areas during initialization, it marks them as specific types, such as reserved or nomap (no map selected), and excludes them from the management of the general memory allocator. For this type of reserved memory, the kernel usually does not build a complete struct page (management metadata) for it, which belongs to the kernel's standard memory management structure.
[0003] Due to the lack of a valid struct page structure, reserved memory cannot be recognized by universal standard page operation interfaces, significantly limiting the versatility of reserved memory. Developers cannot use standard page operation interfaces for logic development or use this memory for kernel mechanisms that rely on struct pages as core management units, such as page migration and page swapping. Furthermore, other kernel subsystems (such as NUMA (Non-Uniform Memory Access) balancing and performance monitoring tools) often rely on struct pages. The lack of this management metadata causes these mechanisms to partially or completely fail with reserved memory, reducing the consistency of overall memory management and the observability of the system.
[0004] As can be seen from the above, how to improve the versatility of reserved memory so that developers can use standard kernel page operation interfaces to operate reserved memory, simplify the development of related applications, enhance the overall consistency, manageability and observability of the system, and reduce system complexity and maintenance burden are issues to be solved in this field. Summary of the Invention
[0005] In view of this, the present invention aims to provide a memory management method, program product, device, and medium that improve the versatility of reserved memory, enable developers to operate reserved memory using a standard kernel page operation interface, simplify the development of related applications, enhance the overall consistency, manageability, and observability of the system, and reduce system complexity and maintenance burden. The specific solution is as follows: In a first aspect, the present application discloses a memory management method, comprising: Obtain memory configuration information during system kernel startup and determine the reserved memory range based on the memory configuration information; the memory configuration information includes the starting address and size of the reserved memory; Based on the hot-swap framework of the memory and the reserved memory range, the reserved memory is segmented to obtain each reserved memory segment; Allocate corresponding target metadata to each reserved memory segment to obtain the configured physical memory; the target metadata is metadata representing the data structure of the physical memory page; Establish a target mapping array based on the memory configuration information; the target mapping array is used to record the mapping relationship between the physical address and the logical page number in the physical memory after configuration; The target mapping array is used to respond to the target memory access request to complete the corresponding memory access operation; the target memory access request is an access request initiated for the reserved memory.
[0006] Optionally, memory configuration information is obtained during system kernel startup, and a reserved memory range is determined based on the memory configuration information, including: Performing system initialization operations to set a global status flag for controlling the call of a reserved memory manager when the system kernel is started, and obtaining memory configuration information during the system kernel startup process; Determine the number of memory pages corresponding to the size of the reserved memory in the memory configuration information; The reserved memory range is determined based on the number of memory pages, the memory page size, and the starting address of the reserved memory in the memory configuration information.
[0007] Optionally, based on the memory hot-swap framework and reserved memory ranges, the reserved memory is segmented, including: Determine the data structure and memory type corresponding to the reserved memory; The reserved memory is segmented based on the memory hot-swap framework, reserved memory range, data structure, and memory type.
[0008] Optionally, assign corresponding target metadata to each reserved memory segment, including: Using the remapping interface of the hot-swap framework of the memory, the corresponding target metadata is allocated to each reserved memory segment, and the reserved memory attributes of the reserved memory segment are initialized; the reserved memory attributes include the page status identifier and the memory node to which it belongs; If the initialization is successful, a linear mapping address is generated; otherwise, a resource rollback operation is performed and a corresponding error message is generated.
[0009] Optionally, create a target mapping array based on the memory configuration information, including: Use the linear mapping address as the array start address and use the array start address to create the initial mapping array; Taking the starting address of the reserved memory in the memory configuration information as the starting logical page number, and incrementing the starting logical page number based on the size of the reserved memory in the memory configuration information to obtain a logical page number; Use the logical page number as the array index and create a target mapping array based on the initial mapping array.
[0010] Optionally, before responding to the target memory access request using the target mapping array, the following steps are further included: Allocate memory space for the target device and set the corresponding target device handle; the target device handle points to the registered root device; Define the memory alignment granularity of the target device and bind a set of operation functions for virtual memory; the operation function set includes a fault handling function; A target interaction interface of the user space is defined to obtain a target memory access request sent by the user through the target interaction interface.
[0011] Optionally, the target mapping array is used to respond to the target memory access request to complete the corresponding memory access operation, including: Obtain a target application access request, and determine a corresponding virtual address and a physical address based on the target application access request and the target mapping array; the virtual address is the address of a virtual memory page, and the physical address is the address of a physical memory page; Build kernel page table; kernel page table is used to record the mapping relationship between virtual address and physical address; Obtain a target memory access request, and based on the target memory access request, filter out a corresponding target physical address from the kernel page table so that the user can perform a corresponding memory access operation on the target physical memory corresponding to the target physical address.
[0012] Optionally, based on the target application access request and the target mapping array, determine the corresponding physical address, including: Determine the corresponding target logical page number based on the address offset of the fault page corresponding to the target application access request; The corresponding physical address is determined using the target logical page number and the target mapping array.
[0013] Optionally, the target logical page number and the target mapping array are used to determine the corresponding physical address, including: Filter the target physical page number corresponding to the target logical page number from the target mapping array; The target physical page number is used to determine the corresponding physical address.
[0014] Optionally, build the kernel page table, including: Determine the address range of the virtual address corresponding to the target application access request; If the address range and the physical address corresponding to the address range meet the preset large page alignment condition, a kernel page table is constructed.
[0015] Optionally, after determining the address range of the virtual address corresponding to the target application access request, the following further comprises: Determine the address space size and starting virtual address of the virtual memory from the address range; Determine whether the address space size of the virtual memory meets the preset large page alignment condition, and determine whether the starting virtual address meets the preset large page alignment condition; Determine the physical address corresponding to the starting virtual address from the target mapping array; Determine whether the physical address corresponding to the starting virtual address meets the preset large page alignment condition; If the address space size of the virtual memory meets the preset large page alignment condition, the starting virtual address meets the preset large page alignment condition, and the physical address corresponding to the starting virtual address meets the preset large page alignment condition, then it is determined that the address range and the physical address corresponding to the address range meet the preset large page alignment condition.
[0016] Optionally, based on the target memory access request, the corresponding target physical address is filtered out from the kernel page table, including: Based on the target memory access request, the memory mapping function is called to determine the target virtual address; Filter the target physical address corresponding to the target virtual address from the kernel page table.
[0017] In a second aspect, the present application discloses an electronic device, comprising: Memory, used to store computer programs; The processor is used to execute a computer program to implement the aforementioned memory management method.
[0018] In a third aspect, the present application discloses a computer storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the steps of the aforementioned disclosed memory management method are implemented.
[0019] In a fourth aspect, the present application discloses a computer program product, which implements the steps of the aforementioned memory management method when the computer program is executed by a processor.
[0020] It can be seen that the present application provides a memory management method, including obtaining memory configuration information during the system kernel startup process, and determining the reserved memory range based on the memory configuration information; the memory configuration information includes the starting address and size of the reserved memory; based on the memory hot-swap framework and the reserved memory range, the reserved memory is segmented to obtain each reserved memory segment; corresponding target metadata is allocated to each reserved memory segment to obtain the configured physical memory; the target metadata is metadata that represents the data structure of the physical memory page; a target mapping array is established based on the memory configuration information; the target mapping array is used to record the mapping relationship between the physical address and the logical page number in the physical memory after configuration; the target mapping array is used to respond to the target memory access request to complete the corresponding memory access operation; the target memory access request is an access request initiated for the reserved memory. The present application obtains memory configuration information during the system kernel startup process, determines the reserved memory range based on the memory configuration information, segments the reserved memory based on the memory hot-plug framework and the reserved memory range, obtains each reserved memory segment, allocates corresponding target metadata to each reserved memory segment, and dynamically allocates corresponding target metadata based on the memory hot-plug framework, so that developers can use the standard kernel page operation interface to operate the reserved memory while retaining the reserved attributes, establishes a target mapping array based on the memory configuration information, ensures efficient memory access, and can obtain efficient virtual address and physical address conversion in user mode, maintains the original isolation characteristics, and uses the target mapping array to respond to the target memory access request to complete the corresponding memory access operation, thereby improving the versatility of the reserved memory, simplifying the development of related applications, enhancing the overall consistency, manageability and observability of the system, and reducing the system complexity and maintenance burden. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0022] Figure 1 A flow chart of a memory management method disclosed in this application; Figure 2 A flowchart of implementing memory management based on a memory hot-swap framework disclosed in this application; Figure 3 This is a memory management system architecture diagram disclosed in this application; Figure 4 This is a schematic diagram of the structure of a memory management device disclosed in this application. DETAILED DESCRIPTION
[0023] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0024] Currently, after the system kernel identifies reserved areas during initialization, it marks them as specific types, such as reserved or nomap, and excludes them from management by the general-purpose memory allocator. For this type of reserved memory, the kernel typically does not construct a complete, standard kernel memory management structure called a struct page. Due to the lack of a valid struct page structure, reserved memory cannot be recognized by standard page operation interfaces, significantly limiting its versatility. Developers cannot use standard page operation interfaces for logic development or utilize this memory for kernel mechanisms that rely on struct pages as core management units, such as page migration and page swapping. Furthermore, other kernel subsystems (such as NUMA balancing and performance monitoring tools) often rely on struct pages. The lack of this management metadata causes these mechanisms to partially or completely fail with reserved memory, reducing overall memory management consistency and system observability. As can be seen from the above, improving the versatility of reserved memory, enabling developers to operate it using standard kernel page operation interfaces, simplifying application development, enhancing overall system consistency, manageability, and observability, and reducing system complexity and maintenance burden, remains an unresolved issue in this field.
[0025] See also Figure 1 As shown, an embodiment of the present invention discloses a memory management method, which may specifically include: Step S11: Obtain memory configuration information during the system kernel startup process, and determine a reserved memory range based on the memory configuration information; the memory configuration information includes a starting address and size of the reserved memory.
[0026] In this embodiment, a system initialization operation is performed to set a global status flag for controlling the call of the reserved memory management program when the system kernel is started, and obtain memory configuration information during the system kernel startup process; determine the number of memory pages corresponding to the size of the reserved memory in the memory configuration information; and determine the reserved memory range based on the number of memory pages, the memory page size, and the starting address of the reserved memory in the memory configuration information.
[0027] In this embodiment, when the operating system kernel is started or the kernel module is loaded, the global status flag is set and the root device is registered to ensure that subsequent operations are performed in a secure and isolated environment, thereby preventing the reserved memory management program from being called multiple times.
[0028] Step S12: Based on the hot-swap framework of the memory and the reserved memory range, the reserved memory is segmented to obtain reserved memory segments.
[0029] In this embodiment, the data structure and memory type corresponding to the reserved memory are determined; and the reserved memory is segmented based on the hot-swap framework of the memory, the reserved memory range, the data structure, and the memory type.
[0030] In this embodiment, the starting physical address and reserved memory size are obtained through predefined module parameters or system startup configuration. The reserved memory size is defined according to the 4K page size, that is, the number of 4K pages is obtained. If multiple segments of reserved memory need to be managed, multiple starting physical addresses and corresponding page numbers are obtained to accurately define the boundaries of the reserved memory area. The reserved memory range is calculated by adding the starting address to the total byte length (number of pages multiplied by the page size) to obtain the complete range.
[0031] Then, based on the memory hotplug framework, the data structure and memory type of the device-related page mapping are determined. For example, if the memory type is generic device memory (MEMORY_DEVICE_GENERIC), the reserved memory is segmented according to the reserved memory range. The memory type can be set based on specific needs and kernel-defined properties. This example only proposes a specific implementation and is not a fixed implementation.
[0032] Step S13: allocating corresponding target metadata to each reserved memory segment to obtain configured physical memory; the target metadata is metadata representing the data structure of the physical memory page.
[0033] In this embodiment, the remapping interface of the hot-swap framework of the memory is used to allocate corresponding target metadata to each reserved memory segment, and initialize the reserved memory attributes of the reserved memory segment; the reserved memory attributes include the page status identifier and the memory node to which it belongs; if the initialization is successful, a linear mapping address is generated, otherwise a resource rollback operation is performed and a corresponding error message is generated.
[0034] In this embodiment, a struct page array (target metadata) is allocated to the reserved memory segment based on the data structure through the remapping interface of the hot-swap framework of the memory. This process integrates the physical memory area with the kernel page frame management system, ensures that each physical page frame is associated with a valid struct page structure, and initializes key attributes (such as the page status identifier and the memory node to which it belongs). Because the memory is reserved memory, the corresponding memory reservation attributes will not change in the corresponding struct page. If the initialization fails, the resource rollback operation is performed and an error message is returned; if the initialization is successful, a linear mapping address is generated. This process enables each physical page frame to be associated with valid struct page metadata, while retaining the page's reserved attribute mark, such as PG_reserved, to ensure that the reserved memory is incorporated into the standard memory management system while maintaining its original isolation characteristics.
[0035] Step S14: establishing a target mapping array based on the memory configuration information; the target mapping array is used to record the mapping relationship between the physical address and the logical page number in the physical memory after configuration.
[0036] In this embodiment, the linear mapping address is used as the array starting address, and the array starting address is used to create an initial mapping array; the starting address of the reserved memory in the memory configuration information is used as the starting logical page number, and based on the size of the reserved memory in the memory configuration information, the starting logical page number is incremented to obtain the logical page number; the logical page number is used as the array index, and based on the initial mapping array, a target mapping array is established.
[0037] In this embodiment, an initial mapping array is created to store the PFN (Page Frame Number) mapping for each physical address, starting from the start address of the reserved memory, with the logical page number initially set to 0. The logical page number increments with each page offset, and the logical page number serves as an array index to implement the PFN mapping relationship between the logical page number and the physical address.
[0038] Step S15: using the target mapping array to respond to the target memory access request to complete the corresponding memory access operation; the target memory access request is an access request initiated for the reserved memory.
[0039] In this embodiment, the memory space of the target device is allocated and the corresponding target device handle is set; the target device handle points to the registered root device; the memory alignment granularity of the target device is defined, and an operation function set for the virtual memory is bound; the operation function set includes a fault handling function; a target interaction interface of the user space is defined, so as to utilize the target interaction interface to obtain the target memory access request sent by the user; the target application access request is obtained, and the corresponding virtual address and physical address are determined based on the target application access request and the target mapping array; the virtual address is the address of the virtual memory page, and the physical address is the address of the physical memory page; a kernel page table is constructed; the kernel page table is used to record the mapping relationship between the virtual address and the physical address; the target memory access request is obtained, and based on the target memory access request, the corresponding target physical address is filtered out from the kernel page table so that the user can perform corresponding memory access operations on the target physical memory corresponding to the target physical address.
[0040] In this embodiment, the memory space of the target device is allocated, and the target device handle is set. The memory alignment granularity is defined, for example, it is set to the large page size PMD_SIZE to support large page mapping optimization. A customized set of operation functions for virtual memory is bound, including a page fault handling function and a large page fault handling function, to ensure that subsequent user access can respond correctly. The target interaction interface is defined, including an mmap (memory mapping) function, an unmapping processing function, and an unmapped area address calculation function. Then, the device is registered to specify a dynamically allocated minor device number, device name, and file operation interface, so that the application can access the device file path.
[0041] In this embodiment, building a kernel page table includes: determining an address range of a virtual address corresponding to a target application access request; and building a kernel page table if the address range and a physical address corresponding to the address range meet a preset large page alignment condition.
[0042] In this embodiment, the corresponding physical address is determined based on the target application access request and the target mapping array, including: determining the corresponding target logical page number based on the address offset of the fault page corresponding to the target application access request; and determining the corresponding physical address using the target logical page number and the target mapping array.
[0043] Determining the corresponding physical address using the target logical page number and the target mapping array includes: selecting the target physical page number corresponding to the target logical page number from the target mapping array; and determining the corresponding physical address using the target physical page number.
[0044] Specifically, in standard page fault processing, the target logical page number is calculated based on the address offset of the fault page corresponding to the target application access request, and then the specific target physical page number is found based on the mapping relationship between the target logical page number and pfn, the corresponding physical address is calculated, and a mapping between the virtual address and the physical address is established.
[0045] In this embodiment, after determining the address range of the virtual address corresponding to the target application access request, it also includes: determining the address space size and the starting virtual address of the virtual memory from the address range; judging whether the address space size of the virtual memory meets the preset large page alignment condition, and judging whether the starting virtual address meets the preset large page alignment condition; determining the physical address corresponding to the starting virtual address from the target mapping array; judging whether the physical address corresponding to the starting virtual address meets the preset large page alignment condition; if the address space size of the virtual memory meets the preset large page alignment condition, and the starting virtual address meets the preset large page alignment condition, and the physical address corresponding to the starting virtual address meets the preset large page alignment condition, then it is determined that the address range and the physical address corresponding to the address range meet the preset large page alignment condition.
[0046] Specifically, determine whether the address space size of the virtual memory is large page aligned, and whether the starting virtual address and the corresponding physical address are both large page aligned. If so, prioritize establishing the kernel page table through large page mapping. Establish the corresponding level of large page mapping through the page table processing interface in the transparent large page framework. If the mapping fails, fall back to the standard page mapping process.
[0047] This application dynamically creates valid struct page metadata for the reserved memory area and seamlessly integrates it into the standard memory management framework of the operating system while preserving its reserved properties. On this basis, it further supports user space applications to efficiently access the reserved memory through the large page mapping mechanism.
[0048] In this embodiment, based on the target memory access request, the corresponding target physical address is filtered out from the kernel page table, including: based on the target memory access request, calling the memory mapping function to determine the target virtual address; filtering out the target physical address corresponding to the target virtual address from the kernel page table.
[0049] Finally, the user state uses the reserved memory and directly accesses the reserved physical memory according to the target virtual address returned by the system call mmap.
[0050] In this application, the memory management process is implemented based on the hot-swap framework of the memory. Figure 2As shown, the system includes the following main stages: system initialization, reserved memory segmentation, target metadata allocation, establishment of a target mapping array, and dynamic processing of user access to reserved memory. During the system initialization stage, the kernel module obtains the physical address range of the reserved memory, including the starting address and size (in pages), through predefined parameters or configuration information. Subsequently, the system utilizes the hot-plug framework of the memory and allocates corresponding target metadata to each reserved memory segment through the remapping interface, so that the reserved memory can be managed by the standard page operation interface. It establishes a target mapping array to record the mapping relationship between physical addresses and logical page numbers in the configured physical memory, and then uses the target mapping array to respond to target memory access requests.
[0051] The memory management system framework in this application is as follows Figure 3 As shown, this invention brings many significant advantages to reserved memory management. The most important benefit is the integration of reserved memory with the standard operating system memory management subsystem: reserved memory has a standard struct page metadata representation, which provides the basic conditions for recognition and processing by general-purpose memory allocators. This enables developers to use standard kernel page operation interfaces to operate reserved memory, greatly simplifying the development of related applications. The struct page information is used to take effect on the reserved memory area, enhancing the overall consistency, manageability, and observability of the system, reducing system complexity and maintenance burden.
[0052] In addition, this application reserves memory as a continuous area by default. Taking into account the fragmentation scenario, this application can maintain a Buddy System sub-module for reserved memory, which is independent of the kernel global Buddy and supports defragmentation; logical address remapping is achieved through the hot-plug framework: scattered physical pages are merged into continuous virtual large pages, similar to the vmalloc function, but bypassing the TLB (Translation Lookaside Buffer) jitter. The user state perceives the repartitioning event through mremap() without restarting the application, so it can solve the DMA failure problem caused by reserved memory fragmentation after long-term operation, such as video capture cards requiring a continuous 64MB buffer; support "elastic reservation": dynamically reclaim idle fragments to the kernel general allocator (reverse hot plug).
[0053] In this embodiment, memory configuration information is obtained during the system kernel startup process, and a reserved memory range is determined based on the memory configuration information; the memory configuration information includes the starting address and size of the reserved memory; based on the hot-swap framework of the memory and the reserved memory range, the reserved memory is segmented to obtain each reserved memory segment; corresponding target metadata is allocated to each reserved memory segment to obtain the configured physical memory; the target metadata is metadata that represents the data structure of the physical memory page; a target mapping array is established based on the memory configuration information; the target mapping array is used to record the mapping relationship between the physical address and the logical page number in the physical memory after configuration; the target mapping array is used to respond to the target memory access request to complete the corresponding memory access operation; the target memory access request is an access request initiated for the reserved memory. The present application obtains memory configuration information during the system kernel startup process, determines the reserved memory range based on the memory configuration information, segments the reserved memory based on the memory hot-plug framework and the reserved memory range, obtains each reserved memory segment, allocates corresponding target metadata to each reserved memory segment, and dynamically allocates corresponding target metadata based on the memory hot-plug framework, so that developers can use the standard kernel page operation interface to operate the reserved memory while retaining the reserved attributes, establishes a target mapping array based on the memory configuration information, ensures efficient memory access, and can obtain efficient virtual address and physical address conversion in user mode, maintains the original isolation characteristics, and uses the target mapping array to respond to the target memory access request to complete the corresponding memory access operation, thereby improving the versatility of the reserved memory, simplifying the development of related applications, enhancing the overall consistency, manageability and observability of the system, and reducing the system complexity and maintenance burden.
[0054] See also Figure 4 As shown, an embodiment of the present invention discloses a memory management device, which may specifically include: The reserved memory range determination module 11 is used to obtain memory configuration information during the system kernel startup process and determine the reserved memory range based on the memory configuration information; the memory configuration information includes the starting address and size of the reserved memory; A segmentation module 12 is used to segment the reserved memory based on the hot-swap framework of the memory and the reserved memory range to obtain each reserved memory segment; The target metadata allocation module 13 is used to allocate corresponding target metadata to each reserved memory segment to obtain the configured physical memory; the target metadata is metadata representing the data structure of the physical memory page; The target mapping array establishment module 14 is used to establish a target mapping array based on the memory configuration information; the target mapping array is used to record the mapping relationship between the physical address and the logical page number in the physical memory after configuration; The response module 15 is configured to respond to the target memory access request using the target mapping array to complete the corresponding memory access operation; the target memory access request is an access request initiated for the reserved memory.
[0055] In some specific embodiments, the reserved memory range determination module 11 may specifically include: A memory configuration information acquisition module is used to perform system initialization operations to set a global status flag for controlling the call of the reserved memory management program when the system kernel is started, and to obtain memory configuration information during the system kernel startup process; A memory page quantity determination module, configured to determine the number of memory pages corresponding to the size of the reserved memory in the memory configuration information; The reserved memory range determination module is used to determine the reserved memory range based on the number of memory pages, the memory page size and the starting address of the reserved memory in the memory configuration information.
[0056] In some specific embodiments, the segmentation module 12 may specifically include: A data structure and memory type determination module, configured to determine a data structure and a memory type corresponding to the reserved memory; The reserved memory segmentation module is used to segment the reserved memory based on the hot-swap framework of the memory, the reserved memory range, the data structure and the memory type.
[0057] In some specific embodiments, the target metadata allocation module 13 may specifically include: An initialization module is used to allocate corresponding target metadata to each reserved memory segment using the remapping interface of the memory hot-swap framework, and initialize the reserved memory attributes of the reserved memory segment; the reserved memory attributes include a page status identifier and a memory node to which it belongs; The linear mapping address generation module is used to generate a linear mapping address if the initialization is successful, otherwise perform a resource rollback operation and generate a corresponding error message.
[0058] In some specific embodiments, the target mapping array establishing module 14 may specifically include: An initial mapping array creation module is used to use the linear mapping address as the array start address and create an initial mapping array using the array start address; a logical page number determination module, configured to use the starting address of the reserved memory in the memory configuration information as the starting logical page number, and to increment the starting logical page number based on the size of the reserved memory in the memory configuration information to obtain a logical page number; The target mapping array establishment module is used to use the logical page number as an array index and establish a target mapping array based on the initial mapping array.
[0059] In some specific embodiments, the response module 15 may specifically include: The space allocation and target device handle setting module is used to allocate the memory space of the target device and set the corresponding target device handle; the target device handle points to the registered root device; A binding module is used to define the memory alignment granularity of the target device and bind a set of operation functions for the virtual memory; the operation function set includes a fault handling function; The target memory access request acquisition module is used to define a target interaction interface of the user space so as to utilize the target interaction interface to acquire a target memory access request sent by the user.
[0060] In some specific embodiments, the response module 15 may specifically include: A virtual address and physical address determination module is used to obtain a target application access request and determine the corresponding virtual address and physical address based on the target application access request and the target mapping array; the virtual address is the address of the virtual memory page, and the physical address is the address of the physical memory page; Kernel page table construction module, used to build kernel page table; kernel page table is used to record the mapping relationship between virtual address and physical address; The filtering module is used to obtain a target memory access request and, based on the target memory access request, filter out a corresponding target physical address from the kernel page table so that the user can perform a corresponding memory access operation on the target physical memory corresponding to the target physical address.
[0061] In some specific embodiments, the virtual address and physical address determination module may specifically include: A target logical page number determination module, configured to determine a corresponding target logical page number based on an address offset of a fault page corresponding to a target application access request; The first physical address determination module is used to determine the corresponding physical address using the target logical page number and the target mapping array.
[0062] In some specific embodiments, the physical address determination module may specifically include: A target physical page number determination module is used to select a target physical page number corresponding to a target logical page number from a target mapping array; The second physical address determining module is configured to determine a corresponding physical address using the target physical page number.
[0063] In some specific embodiments, the kernel page table construction module may specifically include: An address range determination module, used to determine the address range of the virtual address corresponding to the target application access request; The kernel page table specific construction module is used to construct the kernel page table if the address range and the physical address corresponding to the address range meet the preset large page alignment condition.
[0064] In some specific embodiments, the kernel page table specific construction module may include: An address space size and starting virtual address determination module, configured to determine the address space size and starting virtual address of the virtual memory from the address range; A first judgment module is used to judge whether the address space size of the virtual memory meets the preset large page alignment condition, and to judge whether the starting virtual address meets the preset large page alignment condition; A physical address determination module corresponding to the starting virtual address, used to determine the physical address corresponding to the starting virtual address from the target mapping array; The second judgment module is used to judge whether the physical address corresponding to the starting virtual address meets the preset large page alignment condition; The third judgment module is used to determine whether the address range and the physical address corresponding to the address range meet the preset large page alignment condition if the address space size of the virtual memory meets the preset large page alignment condition, the starting virtual address meets the preset large page alignment condition, and the physical address corresponding to the starting virtual address meets the preset large page alignment condition.
[0065] In some specific embodiments, the screening module may specifically include: A target virtual address determination module is used to determine the target virtual address based on the target memory access request and calling the memory mapping function; The target physical address filtering module is used to filter out the target physical address corresponding to the target virtual address from the kernel page table.
[0066] Among them, the description of the features in the embodiment corresponding to the memory management device can refer to the relevant description of the embodiment corresponding to the memory management method, and will not be repeated here.
[0067] An embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above-mentioned memory management method embodiments.
[0068] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above-mentioned memory management method embodiments when running.
[0069] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0070] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps in any one of the above-mentioned memory management method embodiments are implemented.
[0071] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any of the above-mentioned memory management method embodiments are implemented.
[0072] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0073] The above is a detailed introduction to a memory management method, program product, device, and medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only intended to help understand the method and core ideas of the present application. It should be pointed out that, for those skilled in the art, without departing from the principles of the present application, several improvements and modifications may be made to the present application, and such improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. A memory management method, characterized in that: include: Obtain memory configuration information during system kernel startup and determine the reserved memory range based on the memory configuration information; The memory configuration information includes the starting address and size of the reserved memory; Based on the hot-swap framework of the memory and the reserved memory range, the reserved memory is segmented to obtain reserved memory segments; Allocating corresponding target metadata to each of the reserved memory segments to obtain configured physical memory; The target metadata is metadata representing a data structure of a physical memory page; Establishing a target mapping array based on the memory configuration information; The target mapping array is used to record the mapping relationship between the physical address and the logical page number in the physical memory after the configuration; The target mapping array is used to respond to the target memory access request to complete the corresponding memory access operation; the target memory access request is an access request initiated for the reserved memory.
2. The memory management method according to claim 1, wherein: The acquiring memory configuration information during the system kernel startup process and determining the reserved memory range based on the memory configuration information includes: Performing system initialization operations to set a global status flag for controlling the call of a reserved memory manager when the system kernel is started, and obtaining memory configuration information during the system kernel startup process; Determine the number of memory pages corresponding to the size of the reserved memory in the memory configuration information; A reserved memory range is determined based on the number of memory pages, the memory page size, and the starting address of the reserved memory in the memory configuration information.
3. The memory management method according to claim 1, wherein: The memory-based hot-swap framework and the reserved memory range segment the reserved memory, including: Determine the data structure and memory type corresponding to the reserved memory; The reserved memory is segmented based on a memory hot-plug framework, the reserved memory range, the data structure, and the memory type.
4. The memory management method according to claim 1, wherein: Allocating corresponding target metadata to each of the reserved memory segments includes: Utilizing a remapping interface of a hot-swap framework of a memory, corresponding target metadata is allocated to each of the reserved memory segments, and reserved memory attributes of the reserved memory segments are initialized; the reserved memory attributes include a page status identifier and a memory node to which the page belongs; If the initialization is successful, a linear mapping address is generated; otherwise, a resource rollback operation is performed and a corresponding error message is generated.
5. The memory management method according to claim 4, characterized in that: The establishing of a target mapping array based on the memory configuration information includes: Using the linear mapping address as an array start address, and creating an initial mapping array using the array start address; Taking the starting address of the reserved memory in the memory configuration information as the starting logical page number, and incrementing the starting logical page number based on the size of the reserved memory in the memory configuration information to obtain a logical page number; The logical page number is used as an array index, and a target mapping array is established based on the initial mapping array.
6. The memory management method according to claim 1, wherein: Before responding to the target memory access request using the target mapping array, the method further includes: Allocate memory space for the target device and set a corresponding target device handle; the target device handle points to the registered root device; Defining the memory alignment granularity of the target device and binding an operation function set for virtual memory; the operation function set includes a fault handling function; A target interaction interface of the user space is defined, so as to utilize the target interaction interface to obtain a target memory access request sent by the user.
7. The memory management method according to any one of claims 1 to 6, characterized in that: The using the target mapping array to respond to the target memory access request to complete the corresponding memory access operation includes: Obtaining a target application access request, and determining a corresponding virtual address and a physical address based on the target application access request and the target mapping array; the virtual address is an address of a virtual memory page, and the physical address is an address of a physical memory page; Constructing a kernel page table; the kernel page table is used to record the mapping relationship between the virtual address and the physical address; A target memory access request is obtained, and based on the target memory access request, a corresponding target physical address is screened out from the kernel page table so that a user can perform a corresponding memory access operation on a target physical memory corresponding to the target physical address.
8. The memory management method according to claim 7, wherein: Determining a corresponding physical address based on the target application access request and the target mapping array includes: Determining a corresponding target logical page number based on an address offset of a faulty page corresponding to the target application access request; The corresponding physical address is determined using the target logical page number and the target mapping array.
9. The memory management method according to claim 8, wherein: The determining of the corresponding physical address by using the target logical page number and the target mapping array includes: Filtering a target physical page number corresponding to the target logical page number from the target mapping array; The target physical page number is used to determine a corresponding physical address.
10. The memory management method according to claim 7, wherein: The step of constructing a kernel page table includes: Determining an address range of the virtual address corresponding to the target application access request; If the address range and the physical address corresponding to the address range meet a preset large page alignment condition, the kernel page table is constructed.
11. The memory management method according to claim 10, characterized in that: After determining the address range of the virtual address corresponding to the target application access request, the method further includes: Determine the address space size and the starting virtual address of the virtual memory from the address range; Determining whether the address space size of the virtual memory satisfies a preset large page alignment condition, and determining whether the starting virtual address satisfies a preset large page alignment condition; Determining a physical address corresponding to the starting virtual address from the target mapping array; Determining whether the physical address corresponding to the starting virtual address meets a preset large page alignment condition; If the address space size of the virtual memory satisfies the preset large page alignment condition, the starting virtual address satisfies the preset large page alignment condition, and the physical address corresponding to the starting virtual address satisfies the preset large page alignment condition, then it is determined that the address range and the physical address corresponding to the address range satisfy the preset large page alignment condition.
12. The memory management method according to claim 7, wherein: The step of filtering out a corresponding target physical address from the kernel page table based on the target memory access request includes: Based on the target memory access request, a memory mapping function is called to determine a target virtual address; A target physical address corresponding to the target virtual address is filtered out from the kernel page table.
13. An electronic device, characterized in that: include: memory for storing computer programs; A processor, configured to execute the computer program to implement the steps of the memory management method according to any one of claims 1 to 12.
14. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the memory management method according to any one of claims 1 to 12.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the memory management method according to any one of claims 1 to 12 are implemented.
Citation Information
Patent Citations
Dynamic memory management system based on memory hot plug for virtual machine
CN102222014A
Processing method and device for memory management metadata
CN109508304A
Method and device for determining global page directory, electronic equipment and storage medium
CN114327777A
Memory access method, chip, electronic equipment and computer readable storage medium
CN116136826A
Memory management method and device, computer equipment and storage medium
CN116302491A
Cited By
Memory resource processing method and electronic equipment
CN121050891A
Memory resource processing method and electronic device
CN121050891B
Input and output management method and system for reserved memory, equipment and medium
CN121233499A
Large-page memory processing method and device, storage medium and program product
CN122044893A