A memory management method, program product, device and medium

By obtaining system memory configuration information, segmenting reserved memory and allocating target metadata based on the hot-swappable framework, and establishing a mapping array, the problem that reserved memory cannot be recognized by the standard page operation interface is solved, thus achieving efficient access to reserved memory and improving system consistency.

CN120743564BActive Publication Date: 2026-01-27LANGCHAO ELECTRONIC INFORMATION IND CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202511241343.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-02
Publication Date
2026-01-27
Estimated Expiration
2045-09-02

AI Technical Summary

Technical Problem

In existing technologies, reserved memory lacks a struct page structure, making it unrecognizable by the general standard page operation interface. This limits its versatility, causing kernel mechanisms such as page migration and page swapping to malfunction, and reducing the overall consistency and observability of the system.

Method used

By obtaining system memory configuration information, the reserved memory is segmented based on the hot-plug framework, and target metadata is allocated to each memory segment. A target mapping array is established to achieve the integration of reserved memory and standard memory management, allowing access using the standard kernel page operation interface.

Benefits of technology

It improves the versatility of reserved memory, simplifies the development process, enhances the overall consistency and manageability of the system, and reduces system complexity and maintenance burden.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120743564B_ABST
    Figure CN120743564B_ABST
Patent Text Reader

Abstract

The application discloses a memory management method, a program product, an equipment and a medium, relates to the technical field of computers, and comprises the following steps: acquiring memory configuration information in a system kernel starting process, determining a reserved memory range based on the memory configuration information, segmenting the reserved memory based on a memory hot plug framework and the reserved memory range, allocating corresponding target metadata to each reserved memory segment to obtain configured physical memory, wherein the target metadata is metadata of a data structure representing a physical memory page, establishing a target mapping array based on the memory configuration information, wherein the target mapping array is used for recording a mapping relationship between a physical address in the configured physical memory and a logical page number, responding to a target memory access request by using the target mapping array, and completing a corresponding memory access operation, wherein the target memory access request is an access request initiated for the reserved memory, the generality of the reserved memory is improved, the overall manageability of the system is enhanced, and the system complexity and maintenance burden are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a memory management method, program product, device and medium. Background Technology

[0002] Currently, after identifying reserved regions during the initialization phase, the system kernel marks them as specific types, such as reserved or nomap, and excludes them from the management scope of the general memory allocator. For this type of reserved memory, the kernel typically does not construct a complete struct page (management metadata) that belongs to the kernel's standard memory management structure.

[0003] The lack of an effective `struct page` structure means that reserved memory cannot be recognized by the general standard page operation interface, severely limiting its versatility. Developers cannot use the standard page operation interface for logic development or use this memory for kernel mechanisms that rely on `struct page` as a core management unit, such as page migration and page swapping. Furthermore, other kernel subsystems (such as NUMA (Non-Uniform Memory Access) balancing and performance monitoring tools) typically depend on `struct page`, and the lack of this management metadata causes these mechanisms to partially or completely fail on reserved memory, reducing the consistency of overall memory management and system observability.

[0004] As can be seen from the above, how to improve the versatility of reserved memory, enable developers to 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 problems to be solved in this field. Summary of the Invention

[0005] In view of this, the purpose of this invention is to provide a memory management method, program product, device, and medium that can improve the versatility of reserved memory, enabling developers to operate reserved memory using standard kernel page operation interfaces, simplifying the development of related applications, enhancing the overall consistency, manageability, and observability of the system, and reducing system complexity and maintenance burden. The specific solution is as follows:

[0006] In a first aspect, this application discloses a memory management method, including:

[0007] 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;

[0008] Based on the hot-swappable memory framework and the reserved memory range, the reserved memory is segmented to obtain each reserved memory segment;

[0009] Allocate corresponding target metadata 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.

[0010] A target mapping array is established based on the memory configuration information; the target mapping array is used to record the mapping relationship between physical addresses and logical page numbers in physical memory after configuration;

[0011] The target memory access request is responded to using the target mapping array to complete the corresponding memory access operation; the target memory access request is an access request initiated for reserved memory.

[0012] Optionally, obtain memory configuration information during the system kernel startup process, and determine the reserved memory range based on the memory configuration information, including:

[0013] Perform system initialization operations to set global status flags that control the calls to the reserved memory management program when the system kernel starts, and to obtain memory configuration information during the system kernel startup process;

[0014] Determine the number of memory pages corresponding to the size of the reserved memory in the memory configuration information;

[0015] The range of reserved memory is determined based on the number of memory pages, the size of the memory pages, and the starting address of the reserved memory in the memory configuration information.

[0016] Optionally, based on the memory hot-swap framework and the reserved memory range, the reserved memory is segmented, including:

[0017] Determine the data structure and memory type corresponding to the reserved memory;

[0018] Based on the hot-swappable memory framework, reserved memory range, data structure, and memory type, the reserved memory is segmented.

[0019] Optionally, allocate corresponding target metadata to each reserved memory segment, including:

[0020] Using the remapping interface of the hot-swappable memory framework, corresponding target metadata is allocated to each reserved memory segment, and the reserved memory attributes of the reserved memory segments are initialized; the reserved memory attributes include page status identifier and the memory node to which they belong;

[0021] If initialization is successful, a linear mapping address is generated; otherwise, a resource rollback operation is performed, and corresponding error information is generated.

[0022] Optionally, a target mapping array is established based on memory configuration information, including:

[0023] Use the linear mapping address as the starting address of the array, and use the starting address of the array to create the initial mapping array;

[0024] The starting address of the reserved memory in the memory configuration information is used as the starting logical page number, and the starting logical page number is incremented based on the size of the reserved memory in the memory configuration information to obtain the logical page number.

[0025] Use the logical page number as the array index and build the target mapping array based on the initial mapping array.

[0026] Optionally, before responding to the target memory access request using the target mapping array, the following is also included:

[0027] Allocate memory space for the target device and set the corresponding target device handle; the target device handle points to the registered root device;

[0028] Define the memory alignment granularity of the target device and bind a set of operation functions for virtual memory; the set of operation functions includes fault handling functions;

[0029] Define the target interaction interface in user space to obtain the target memory access request sent by the user.

[0030] Optionally, the target memory access request can be responded to using a target mapping array to complete the corresponding memory access operation, including:

[0031] Obtain the target access request; based on the target access request and the target mapping array, determine the corresponding virtual address and physical address; the virtual address is the address of the virtual memory page, and the physical address is the address of the physical memory page;

[0032] Construct the kernel page table; the kernel page table is used to record the mapping relationship between virtual addresses and physical addresses;

[0033] The system obtains the target memory access request and, based on the request, selects the corresponding target physical address from the kernel page table so that the user can perform the corresponding memory access operation on the target physical memory corresponding to the target physical address.

[0034] Optionally, based on the target access request and the target mapping array, the corresponding physical address is determined, including:

[0035] Based on the address offset of the faulty page corresponding to the target access request, determine the corresponding target logical page number;

[0036] The corresponding physical address is determined using the target logical page number and the target mapping array.

[0037] Optionally, the corresponding physical address can be determined using the target logical page number and the target mapping array, including:

[0038] Filter the target physical page number corresponding to the target logical page number from the target mapping array;

[0039] The corresponding physical address is determined using the target physical page number.

[0040] Optionally, construct the kernel page table, including:

[0041] Determine the address range of the virtual address corresponding to the target access request;

[0042] If the address range and the corresponding physical address satisfy the preset big page alignment condition, then the kernel page table is constructed.

[0043] Optionally, after determining the address range of the virtual address corresponding to the target access request, the method further includes:

[0044] The size of the virtual memory address space and the starting virtual address are determined from the address range;

[0045] Determine whether the address space size of the virtual memory meets the preset big page alignment condition, and determine whether the starting virtual address meets the preset big page alignment condition;

[0046] Determine the physical address corresponding to the starting virtual address from the target mapping array;

[0047] Determine whether the physical address corresponding to the starting virtual address meets the preset big page alignment condition;

[0048] If the address space size of the virtual memory meets the preset big page alignment condition, and the starting virtual address meets the preset big page alignment condition, and the physical address corresponding to the starting virtual address meets the preset big page alignment condition, then the address range and the physical address corresponding to the address range are determined to meet the preset big page alignment condition.

[0049] Optionally, based on the target memory access request, the corresponding target physical address is selected from the kernel page table, including:

[0050] Based on the target memory access request, the target virtual address is determined by calling the memory mapping function;

[0051] Select the target physical address corresponding to the target virtual address from the kernel page table.

[0052] Secondly, this application discloses an electronic device, comprising:

[0053] Memory, used to store computer programs;

[0054] A processor is used to execute computer programs to implement the aforementioned memory management methods.

[0055] Thirdly, this application discloses a computer storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the steps of the aforementioned disclosed memory management method.

[0056] Fourthly, this application discloses a computer program product, wherein the computer program, when executed by a processor, implements the steps of the aforementioned memory management method.

[0057] As can be seen, this application provides a memory management method, including obtaining memory configuration information during the system kernel startup process, determining a reserved memory range based on the memory configuration information; the memory configuration information includes the starting address and size of the reserved memory; segmenting the reserved memory based on the memory hot-plug framework and the reserved memory range to obtain each reserved memory segment; allocating corresponding target metadata to each reserved memory segment to obtain the configured physical memory; the target metadata is metadata representing the data structure of physical memory pages; establishing a target mapping array based on the memory configuration information; the target mapping array is used to record the mapping relationship between physical addresses and logical page numbers in the configured physical memory; responding to target memory access requests 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. This 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 the corresponding target metadata based on the memory hot-plug framework, enabling developers to operate the reserved memory using the standard kernel page operation interface while retaining the reserved attributes. A target mapping array is established based on the memory configuration information to ensure efficient memory access, enabling efficient virtual address and physical address translation in user space, maintaining the original isolation characteristics, and responding to target memory access requests using the target mapping array to complete the corresponding memory access operations. This improves the versatility of reserved memory, simplifies the development of related applications, enhances the overall consistency, manageability, and observability of the system, and reduces system complexity and maintenance burden. Attached Figure Description

[0058] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0059] Figure 1This is a flowchart of a memory management method disclosed in this application;

[0060] Figure 2 This application discloses a flowchart of a memory management implementation based on a memory-based hot-swappable framework.

[0061] Figure 3 This is a diagram of a memory management system architecture disclosed in this application;

[0062] Figure 4 This is a schematic diagram of a memory management device disclosed in this application. Detailed Implementation

[0063] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0064] Currently, after identifying reserved regions during the initialization phase, the system kernel marks them as specific types, such as `reserved` or `nomap`, and excludes them from the management scope of the general memory allocator. For this type of reserved memory, the kernel typically does not construct a complete `struct page`, which belongs to the kernel's standard memory management structure. Due to the lack of an effective `struct page` structure, reserved memory cannot be recognized by the general standard page operation interface, greatly limiting its versatility. Developers cannot use the standard page operation interface for logic development or use this memory for kernel mechanisms that rely on `struct pages` as the core management unit, 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 on reserved memory, reducing the overall consistency of memory management and the system's observability. Therefore, improving the versatility of reserved memory, enabling developers to use the standard kernel page operation interface to operate on reserved memory, simplifying the development of related applications, enhancing the overall consistency, manageability, and observability of the system, and reducing system complexity and maintenance burden are problems that need to be solved in this field.

[0065] See Figure 1 As shown in the figure, an embodiment of the present invention discloses a memory management method, which may specifically include:

[0066] Step S11: 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.

[0067] In this embodiment, system initialization operations are performed to set global status flags for controlling the call of the reserved memory management program when the system kernel starts, and to 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 range of reserved memory based on the number of memory pages, the size of the memory pages, and the starting address of the reserved memory in the memory configuration information.

[0068] In this embodiment, during operating system kernel startup or kernel module loading, the main tasks are setting global state identifiers and registering root devices to ensure that subsequent operations are performed in a secure and isolated environment. This prevents the reserved memory management program from being called multiple times.

[0069] Step S12: Based on the hot-swappable memory framework and the reserved memory range, the reserved memory is segmented to obtain each reserved memory segment.

[0070] In this embodiment, the data structure and memory type corresponding to the reserved memory are determined; based on the hot-swappable memory framework, the reserved memory range, the data structure, and the memory type, the reserved memory is segmented.

[0071] In this embodiment, the starting physical address and the 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 region. The calculation process of the reserved memory range is as follows: the complete interval is obtained by adding the total byte length (number of pages multiplied by page size) to the starting address.

[0072] Then, based on the hot-plug framework for memory, the data structure and memory type of the device-related page mapping are determined, such as the memory type being general device memory (MEMORY_DEVICE_GENERIC). The reserved memory is then segmented according to the reserved memory range. The memory type specification can be set based on specific needs and kernel-defined attributes. This example only proposes a specific implementation and is not a fixed implementation.

[0073] Step S13: Allocate corresponding target metadata 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.

[0074] In this embodiment, the remapping interface of the hot-swappable memory framework 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 corresponding error information is generated.

[0075] In this embodiment, the hot-plug framework's remapping interface allocates a `struct page` array (target metadata) for the reserved memory segment based on a data structure. This process integrates the physical memory region with the kernel page frame management system, ensuring that each physical page frame is associated with a valid `struct page` structure and initializing key attributes (such as page status identifiers and the memory node to which it belongs). Since the memory is reserved, the corresponding memory reservation attributes do not change in the corresponding `struct page`. If initialization fails, a resource rollback operation is performed and an error message is returned; if initialization succeeds, a linear mapping address is generated. This process ensures that each physical page frame is associated with valid `struct page` metadata while retaining the page's reservation attribute markers, such as `PG_reserved`, ensuring that the reserved memory is both incorporated into the standard memory management system and maintains its original isolation characteristics.

[0076] Step S14: Establish a target mapping array based on memory configuration information; the target mapping array is used to record the mapping relationship between physical addresses and logical page numbers in physical memory after configuration.

[0077] In this embodiment, the linear mapping address is used as the starting address of the array, and an initial mapping array is created using the starting address of the array; the starting address of the reserved memory in the memory configuration information is used as the starting logical page number, and the starting logical page number is incremented based on the size of the reserved memory in the memory configuration information to obtain the logical page number; the logical page number is used as the array index, and a target mapping array is established based on the initial mapping array.

[0078] In this embodiment, an initial mapping array is created to store the pfn (Page Frame Number) mapping for each physical address, starting from the beginning address of the reserved memory, with the logical page number initially set to 0. The logical page number is incremented for each page offset, and serves as the array index to implement the mapping relationship between logical page numbers and physical address pfn.

[0079] Step S15: 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 reserved memory.

[0080] In this embodiment, memory space for the target device is allocated, and a 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 a set of operation functions for virtual memory is bound; the set of operation functions includes fault handling functions; a target interaction interface in user space is defined to obtain the target memory access request sent by the user; the target access request is obtained, and based on the target access request and the target mapping array, the corresponding virtual address and physical address are determined; 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 virtual addresses and physical addresses; the target memory access request is obtained, and based on the target memory access request, the corresponding target physical address is selected 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.

[0081] In this embodiment, memory space for the target device is allocated, and a target device handle is set. Memory alignment granularity is defined, for example, set to the large page size PMD_SIZE to support large page mapping optimization. A custom set of operation functions for virtual memory is bound, including page fault handling functions and large page fault handling functions, to ensure that subsequent user accesses can be responded to correctly. The target interaction interface is defined, including the mmap (memory mapping) function, the unmapping handling function, and the unmapped region address calculation function. Then, the device is registered with a dynamically allocated minor device number, device name, and file operation interface, enabling the application to access the device through the device file path.

[0082] In this embodiment, constructing a kernel page table includes: determining the address range of the virtual address corresponding to the target access request; if the address range and the physical address corresponding to the address range satisfy a preset big page alignment condition, then constructing a kernel page table.

[0083] In this embodiment, the corresponding physical address is determined based on the target access request and the target mapping array, including: determining the corresponding target logical page number based on the address offset of the faulty page corresponding to the target access request; and determining the corresponding physical address using the target logical page number and the target mapping array.

[0084] The process of determining the corresponding physical address using the target logical page number and the target mapping array includes: filtering 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.

[0085] Specifically, in standard page fault handling, the target logical page number is calculated based on the address offset of the faulty page corresponding to the target access request. 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 virtual address and physical address is established.

[0086] In this embodiment, after determining the address range of the virtual address corresponding to the target access request, the method further includes: determining the address space size of the virtual memory and the starting virtual address from the address range; determining whether the address space size of the virtual memory meets the preset big page alignment condition, and determining whether the starting virtual address meets the preset big page alignment condition; determining the 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 the preset big page alignment condition; if the address space size of the virtual memory meets the preset big page alignment condition, the starting virtual address meets the preset big page alignment condition, and the physical address corresponding to the starting virtual address meets the preset big page alignment condition, then the address range and the physical address corresponding to the address range meet the preset big page alignment condition.

[0087] Specifically, it determines whether the virtual memory address space is big-page aligned, and whether both the starting virtual address and the corresponding physical address are big-page aligned. If so, it prioritizes establishing a kernel page table via big-page mapping. The corresponding level of big-page mapping is established through the page table processing interface in the transparent big-page framework. If mapping fails, it falls back to standard page mapping processing.

[0088] This application dynamically creates valid struct page metadata for reserved memory regions and seamlessly integrates it into the operating system's standard memory management framework while preserving its reserved attributes. Furthermore, it supports user-space applications in efficiently accessing reserved memory through a massive page mapping mechanism.

[0089] In this embodiment, the corresponding target physical address is selected from the kernel page table based on the target memory access request, including: determining the target virtual address based on the target memory access request and calling the memory mapping function; and selecting the target physical address corresponding to the target virtual address from the kernel page table.

[0090] Finally, user space uses reserved memory to directly access the reserved physical memory based on the target virtual address returned by the system call mmap.

[0091] The memory management process implemented in this application using a memory-based hot-swap framework is as follows: Figure 2As shown, the process includes the following main stages: system initialization, reserved memory segmentation, target metadata allocation, establishment of a target mapping array, and dynamic handling of user access to reserved memory. During system initialization, the kernel module obtains the physical address range of reserved memory, including the starting address and size (in pages), through predefined parameters or configuration information. Subsequently, the system utilizes the hot-plug framework for memory and allocates corresponding target metadata to each reserved memory segment through the remapping interface, enabling the reserved memory to be managed by the standard page operation interface. A target mapping array is established to record the mapping relationship between physical addresses and logical page numbers in the configured physical memory. Then, the target mapping array is used to respond to target memory access requests.

[0092] The memory management system framework in this application is as follows: Figure 3 As shown, this invention brings several significant advantages to reserved memory management. The most crucial effect is the integration of reserved memory with the operating system's standard memory management subsystem: reserved memory possesses a standard struct page metadata representation, thus meeting the basic requirements for being recognized and processed by the general memory allocator. This allows developers to use the standard kernel page operation interface to manipulate reserved memory, greatly simplifying the development of related applications. The application of struct page information to the reserved memory region enhances the overall consistency, manageability, and observability of the system, while reducing system complexity and maintenance burden.

[0093] Furthermore, this application defaults to reserving memory as a contiguous region. Considering fragmentation scenarios, this application can maintain a Buddy System submodule for reserved memory, independent of the kernel global Buddy, and supports defragmentation. Logical address remapping is achieved through a hot-plug framework: scattered physical pages are merged into contiguous virtual large pages, similar to the vmalloc function, but bypassing TLB (Translation Lookaside Buffer) jitter. User space detects repartitioning events through mremap() without restarting the application, thus solving the DMA failure problem caused by reserved memory fragmentation after long-term operation, such as when a video capture card requires a contiguous 64MB buffer. "Elastic reservation" is supported: dynamically reclaiming free fragments to the kernel general allocator (reverse hot-plugging).

[0094] In this embodiment, memory configuration information during the system kernel startup process is obtained, 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-plug framework of 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 characterizes the data structure of physical memory pages. A target mapping array is established based on the memory configuration information. The target mapping array is used to record the mapping relationship between physical addresses and logical page numbers in the configured physical memory. The target mapping array is used to respond to target memory access requests to complete the corresponding memory access operations. The target memory access request is an access request initiated for the reserved memory. This 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 the corresponding target metadata based on the memory hot-plug framework, enabling developers to operate the reserved memory using the standard kernel page operation interface while retaining the reserved attributes. A target mapping array is established based on the memory configuration information to ensure efficient memory access, enabling efficient virtual address and physical address translation in user space, maintaining the original isolation characteristics, and responding to target memory access requests using the target mapping array to complete the corresponding memory access operations. This improves the versatility of reserved memory, simplifies the development of related applications, enhances the overall consistency, manageability, and observability of the system, and reduces system complexity and maintenance burden.

[0095] See Figure 4 As shown, an embodiment of the present invention discloses a memory management device, which may specifically include:

[0096] 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;

[0097] Segmentation module 12 is used to segment the reserved memory based on the memory hot-swap framework and the reserved memory range to obtain each reserved memory segment;

[0098] 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 that represents the data structure of the physical memory page.

[0099] The target mapping array creation module 14 is used to create a target mapping array based on memory configuration information; the target mapping array is used to record the mapping relationship between physical addresses and logical page numbers in physical memory after configuration.

[0100] The response module 15 is used 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 reserved memory.

[0101] In some specific embodiments, the reserved memory range determination module 11 may specifically include:

[0102] The memory configuration information acquisition module is used to perform system initialization operations, in order to set global status flags that control the call of the reserved memory management program when the system kernel starts, and to acquire memory configuration information during the system kernel startup process;

[0103] The memory page count determination module is used to determine the number of memory pages corresponding to the size of the reserved memory in the memory configuration information.

[0104] The reserved memory range determination module is used to determine the reserved memory range based on the number of memory pages, the size of the memory pages, and the starting address of the reserved memory in the memory configuration information.

[0105] In some specific embodiments, the segmentation module 12 may specifically include:

[0106] The data structure and memory type determination module is used to determine the data structure and memory type corresponding to the reserved memory.

[0107] The reserved memory segmentation module is used to segment reserved memory based on the hot-swappable memory framework, reserved memory range, data structure, and memory type.

[0108] In some specific embodiments, the target metadata allocation module 13 may specifically include:

[0109] The initialization module is used to allocate corresponding target metadata to each reserved memory segment using the remapping interface of the hot-swappable memory framework, and to initialize the reserved memory attributes of the reserved memory segments; the reserved memory attributes include the page status identifier and the memory node to which it belongs;

[0110] The linear mapping address generation module is used to generate a linear mapping address if initialization is successful, otherwise to perform a resource rollback operation and generate corresponding error information.

[0111] In some specific embodiments, the target mapping array establishment module 14 may specifically include:

[0112] The initial mapping array creation module is used to take the linear mapping address as the starting address of the array and create the initial mapping array using the starting address of the array;

[0113] The logical page number determination module is used to take the starting address of the reserved memory in the memory configuration information as the starting logical page number, and increment the starting logical page number based on the size of the reserved memory in the memory configuration information to obtain the logical page number;

[0114] The target mapping array creation module is used to create a target mapping array based on the initial mapping array, using the logical page number as the array index.

[0115] In some specific embodiments, the response module 15 may specifically include:

[0116] The memory allocation and target device handle setting module is used to allocate memory space for the target device and set the corresponding target device handle; the target device handle points to the registered root device;

[0117] The binding module is used to define the memory alignment granularity of the target device and bind a set of operation functions for virtual memory; the set of operation functions includes fault handling functions.

[0118] The target memory access request acquisition module is used to define the target interaction interface in user space, so as to acquire the target memory access request sent by the user using the target interaction interface.

[0119] In some specific embodiments, the response module 15 may specifically include:

[0120] The virtual address and physical address determination module is used to obtain the target access request and determine the corresponding virtual address and physical address based on the target 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;

[0121] The kernel page table construction module is used to build kernel page tables; kernel page tables are used to record the mapping relationship between virtual addresses and physical addresses.

[0122] The filtering module is used to obtain target memory access requests and, based on these requests, to filter out the corresponding target physical addresses from the kernel page table so that users can perform corresponding memory access operations on the target physical memory corresponding to the target physical address.

[0123] In some specific embodiments, the virtual address and physical address determination module may specifically include:

[0124] The target logical page number determination module is used to determine the corresponding target logical page number based on the address offset of the faulty page corresponding to the target access request;

[0125] 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.

[0126] In some specific embodiments, the physical address determination module may specifically include:

[0127] The target physical page number determination module is used to filter the target physical page number corresponding to the target logical page number from the target mapping array;

[0128] The second physical address determination module is used to determine the corresponding physical address using the target physical page number.

[0129] In some specific embodiments, the kernel page table construction module may specifically include:

[0130] The address range determination module is used to determine the address range of the virtual address corresponding to the target access request;

[0131] The kernel page table construction module is used to construct the kernel page table if the address range and the corresponding physical address meet the preset big page alignment conditions.

[0132] In some specific embodiments, the kernel page table construction module may specifically include:

[0133] The address space size and starting virtual address determination module is used to determine the address space size and starting virtual address of virtual memory from the address range;

[0134] The first judgment module is used to determine whether the address space size of the virtual memory meets the preset big page alignment condition, and to determine whether the starting virtual address meets the preset big page alignment condition.

[0135] The physical address determination module corresponding to the starting virtual address is used to determine the physical address corresponding to the starting virtual address from the target mapping array;

[0136] The second judgment module is used to determine whether the physical address corresponding to the starting virtual address meets the preset big page alignment condition;

[0137] The third judgment module is used to determine that the address range and the physical address corresponding to the address range satisfy the preset big page alignment condition if the address space size of the virtual memory satisfies the preset big page alignment condition, the starting virtual address satisfies the preset big page alignment condition, and the physical address corresponding to the starting virtual address satisfies the preset big page alignment condition.

[0138] In some specific embodiments, the filtering module may specifically include:

[0139] The target virtual address determination module is used to determine the target virtual address based on the target memory access request and by calling the memory mapping function;

[0140] 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.

[0141] For a description of the features in the embodiment corresponding to the memory management device, please refer to the relevant description of the embodiment corresponding to the memory management method, which will not be repeated here.

[0142] Embodiments of this application also provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any of the memory management method embodiments described above.

[0143] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above-described memory management method embodiments at runtime.

[0144] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.

[0145] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above-described memory management method embodiments.

[0146] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in any of the above-described memory management method embodiments.

[0147] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can 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.

[0148] The foregoing has provided a detailed description of a memory management method, program product, device, and medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and its core ideas. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from its principles, and these improvements and modifications also fall within the protection scope of the claims of this application.

Claims

1. A memory management method, characterized in that, include: 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; Based on the hot-swappable memory framework and the reserved memory range, the reserved memory is segmented to obtain each reserved memory segment; Allocate corresponding target metadata to each of the reserved memory segments to obtain the configured physical memory; The target metadata is metadata that characterizes the data structure of a physical memory page; A target mapping array is established based on the aforementioned memory configuration information; The target mapping array is used to record the mapping relationship between physical addresses and logical page numbers in the physical memory after the configuration; The target memory access request is responded to 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; Based on the hot-swappable memory framework and the reserved memory range, the reserved memory is segmented, including: determining the data structure and memory type corresponding to the reserved memory; and segmenting the reserved memory based on the hot-swappable memory framework, the reserved memory range, the data structure, and the memory type. Allocating corresponding target metadata to each of the reserved memory segments includes: using the remapping interface of the hot-swappable memory framework to allocate corresponding target metadata to each of the reserved memory segments, and initializing the reserved memory attributes of the reserved memory segments; the reserved memory attributes include page status identifier and the memory node to which they belong; if the initialization is successful, a linear mapping address is generated; otherwise, a resource rollback operation is performed and corresponding error information is generated.

2. The memory management method according to claim 1, characterized in that, The step of obtaining memory configuration information during the system kernel startup process and determining the reserved memory range based on the memory configuration information includes: Perform system initialization operations to set global status flags that control the calls to the reserved memory management program when the system kernel starts, and to 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; The reserved memory range is determined based on the number of memory pages, the size of the memory pages, and the starting address of the reserved memory in the memory configuration information.

3. The memory management method according to claim 1, characterized in that, The step of establishing the target mapping array based on the memory configuration information includes: Use the linear mapping address as the starting address of the array, and use the starting address of the array 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 the starting logical page number is incremented based on the size of the reserved memory in the memory configuration information to obtain the logical page number. Use the logical page number as an array index, and establish the target mapping array based on the initial mapping array.

4. The memory management method according to claim 1, characterized in that, 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 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 set of operation functions includes fault handling functions; Define a target interaction interface in the user space to obtain the target memory access request sent by the user.

5. The memory management method according to any one of claims 1 to 4, characterized in that, The step of responding to the target memory access request using the target mapping array to complete the corresponding memory access operation includes: Obtain the target access request, and based on the target access request and the target mapping array, determine the corresponding virtual address and physical address; the virtual address is the address of a virtual memory page, and the physical address is the address of a physical memory page; Construct a kernel page table; the kernel page table is used to record the mapping relationship between the virtual address and the physical address; Obtain the target memory access request, and based on the target memory access request, filter the corresponding target physical address from the kernel page table so that the user can perform the corresponding memory access operation on the target physical memory corresponding to the target physical address.

6. The memory management method according to claim 5, characterized in that, Based on the target access request and the target mapping array, the corresponding physical address is determined, including: Based on the address offset of the faulty page corresponding to the target access request, the corresponding target logical page number is determined; The corresponding physical address is determined using the target logical page number and the target mapping array.

7. The memory management method according to claim 6, characterized in that, The step of determining the corresponding physical address using the target logical page number and the target mapping array includes: Filter the target physical page number corresponding to the target logical page number from the target mapping array; The corresponding physical address is determined using the target physical page number.

8. The memory management method according to claim 5, characterized in that, The construction of the kernel page table includes: Determine the address range of the virtual address corresponding to the target access request; If the address range and the corresponding physical address satisfy a preset big page alignment condition, then the kernel page table is constructed.

9. The memory management method according to claim 8, characterized in that, After determining the address range of the virtual address corresponding to the target access request, the method further includes: The address space size and starting virtual address of the virtual memory are determined from the address range. Determine whether the address space size of the virtual memory meets the preset big page alignment condition, and determine whether the starting virtual address meets the preset big 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 satisfies the preset big page alignment condition; If the address space size of the virtual memory satisfies the preset big page alignment condition, and the starting virtual address satisfies the preset big page alignment condition, and the physical address corresponding to the starting virtual address satisfies the preset big page alignment condition, then it is determined that the address range and the physical address corresponding to the address range satisfy the preset big page alignment condition.

10. The memory management method according to claim 5, characterized in that, The step of selecting the corresponding target physical address from the kernel page table based on the target memory access request includes: Based on the target memory access request, the target virtual address is determined by calling the memory mapping function; The target physical address corresponding to the target virtual address is selected from the kernel page table.

11. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the memory management method as described in any one of claims 1 to 10.

12. 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 memory management method as described in any one of claims 1 to 10.

13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the memory management method as described in any one of claims 1 to 10.

Citation Information

Patent Citations

  • Memory access method, program product, equipment and medium

    CN120353723A