Memory access method, program product, device and medium
By parsing and dynamically managing system memory information through firmware, the memory access performance bottleneck is resolved, the memory stability and continuity of critical tasks are ensured, and the memory access performance is improved.
Patent Information
- Application Number
- CN202510813637.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-18
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2045-06-18
AI Technical Summary
Existing memory management technologies lack flexibility, resulting in address conflicts and degraded memory access performance. In particular, there are problems of latency and physical address discontinuity in the traditional 4KB small page management mode and static large page technology.
The firmware determines the system memory information, parses and splits it continuously, creates a virtual character device, implements dynamic memory segment management, performs linear large page mapping, and generates page tables to support exclusive memory access for critical tasks.
It improves memory access performance, reduces page fault exceptions and translation lookaside buffer burden, ensures memory stability and continuity, and meets the high performance requirements of critical tasks.
Smart Images

Figure CN120353723B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a memory access method, program product, device and medium. Background Art
[0002] Memory management plays a crucial role in system performance and the efficient operation of applications. By reserving physical memory for specific programs, the stability of the memory used by the current program is ensured. Currently, common memory reservation techniques often rely on hard-coded mmap (Memory Mapping) parameters. This approach typically requires configuration after system startup and lacks flexibility. Furthermore, setting mmap parameters requires pre-requisite information such as hardware information and application memory requirements. Improper settings can lead to address conflicts.
[0003] To address the performance bottlenecks of the traditional 4KB small page memory management model, THP (Transparent Huge Pages) and static huge page technologies are currently the primary approaches. Transparent huge pages typically automatically aggregate 4KB pages into huge pages, a process that introduces a certain delay, resulting in the inability to request huge page memory when the system requires it. Static huge page memory, on the other hand, relies on the huge page file system and requires pre-reservation of huge page memory. Furthermore, because huge page memory allocation is still subject to the randomness of the system's physical memory allocation buddy algorithm, the physical addresses of memory blocks allocated to user-mode applications may be discontinuous after request. This makes memory block calls inconvenient and reduces memory access performance.
[0004] It can be seen that how to dynamically configure the range and capacity of memory segments, ensure that critical tasks are exclusively allocated physical memory resources, guarantee the stability of memory when critical loads are running, reduce the burden on the translation backup buffer, ensure the continuity of physical memory, and improve memory access performance are problems that technical personnel in this field need to solve. Summary of the Invention
[0005] The purpose of the embodiments of the present invention is to provide a memory access method, program product, device, and medium that can dynamically configure memory segment ranges and capacities, ensure exclusive allocation of physical memory resources to critical tasks, guarantee memory stability during critical workload execution, reduce the burden on the translation lookaside buffer, ensure physical memory continuity, and improve memory access performance. The specific implementation is as follows:
[0006] In a first aspect, the present application discloses a memory access method, comprising:
[0007] Using firmware to determine physical memory information to be reserved in the system memory, parsing the physical memory information to be reserved, and obtaining physical memory;
[0008] Continuously split the physical memory to obtain physical memory segments, divide and align the physical memory segments to obtain processed physical memory segments;
[0009] Determine a virtual address space, divide the virtual address space, and align the divided virtual address space based on the processed physical memory segments to obtain a processed virtual address space;
[0010] Calculate the physical address space corresponding to the processed virtual address space, and perform memory mapping between the processed physical memory segment and the physical address space corresponding to the processed virtual address space;
[0011] Generate a page table using the physical address space corresponding to the mapped processed virtual address space;
[0012] When the user's access instruction is obtained, the target physical address space corresponding to the access instruction is filtered from the page table, the mapped target physical memory segment corresponding to the target physical address space is determined, and the target physical memory segment is sent to the user state process so that the user can access the target physical memory segment based on the user state process.
[0013] In a second aspect, the present application discloses an electronic device, comprising:
[0014] memory for storing computer programs;
[0015] A processor is used to implement the steps of the aforementioned memory access method when executing a computer program.
[0016] In a third aspect, the present application discloses a computer-readable storage medium, in which a computer program is stored, wherein the computer program implements the steps of the aforementioned memory access method when executed by a processor.
[0017] In a fourth aspect, the present application discloses a computer program product, which implements the steps of the aforementioned memory access method when the computer program is executed by a processor.
[0018] It can be seen that the present application provides a memory access method, including using firmware to determine the physical memory information to be reserved in the system memory, parsing the reserved physical memory information to obtain physical memory; continuously splitting the physical memory to obtain physical memory segments, dividing and aligning the physical memory segments to obtain processed physical memory segments; determining the virtual address space, dividing the virtual address space, aligning the divided virtual address space based on the processed physical memory segments to obtain the processed virtual address space; calculating the physical address space corresponding to the processed virtual address space, memory mapping the processed physical memory segments and the physical address space corresponding to the processed virtual address space; generating a page table using the physical address space corresponding to the mapped processed virtual address space; when a user's access instruction is obtained, filtering the target physical address space corresponding to the access instruction from the page table, determining the mapped target physical memory segment corresponding to the target physical address space, and sending the target physical memory segment to the user-state process so that the user can access the target physical memory segment based on the user-state process.
[0019] This application uses the underlying hardware control capabilities of the firmware to determine the physical memory information to be reserved in the system memory. Compared with the traditional static reservation method, this application can support dynamic configuration of memory segment range and capacity, ensure that critical tasks are exclusively allocated physical memory resources, avoid interference factors such as operating system memory recovery and process preemption, and ensure the stability of memory when critical loads are running. The reserved physical memory information is parsed to obtain physical memory, the physical memory is continuously split to obtain various physical memory segments, the physical memory segments are divided and aligned, the virtual address space is divided, and the divided virtual address space is aligned based on the processed physical memory segments. The processed virtual address space is obtained, the physical address space corresponding to the processed virtual address space is calculated, and the processed physical memory segment and the physical address space corresponding to the processed virtual address space are memory mapped. Therefore, the large page memory can be fully utilized to reduce the number of page table entries, reduce the burden of the translation backup buffer, ensure the continuity of the physical memory, and generate a page table using the physical address space corresponding to the mapped processed virtual address space. When the user's access instruction is obtained, the target physical memory segment can be quickly located, thereby improving the memory access performance, meeting the requirements of key tasks for high-performance memory access, and reducing the generation of page fault exceptions during memory access. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0021] Figure 1 A flow chart of a memory access method disclosed in this application;
[0022] Figure 2 A specific flow chart for implementing memory access provided by this application;
[0023] Figure 3 A structural diagram of a memory access system provided for this application;
[0024] Figure 4 This is a schematic diagram of the structure of a memory access device disclosed in this application. DETAILED DESCRIPTION
[0025] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0026] Memory management plays a crucial role in system performance and the efficient operation of applications. Reserving physical memory for specific programs ensures the stability of memory used by the current program. Currently, common memory reservation techniques rely on hard-coded mmap parameters, which typically require configuration after system startup and lack flexibility. Furthermore, setting mmap parameters requires pre-requisite information, such as hardware information and application memory requirements. Improper configuration can lead to addressing address conflicts. THP and static huge page technologies are currently the primary approaches to addressing the performance bottlenecks of the traditional 4KB small page memory management model. Transparent huge pages typically automatically aggregate 4KB pages into huge pages, a process that introduces a certain latency, resulting in the inability to allocate huge page memory when needed. Static huge page memory, on the other hand, relies on a huge page file system and requires pre-reservation of huge page memory. Furthermore, because huge page memory allocation is still subject to the randomness of the system's physical memory allocation buddy algorithm, the physical addresses of memory blocks allocated to user-mode applications may be discontinuous after allocation, making memory block calls inconvenient and degrading memory access performance.
[0027] It can be seen that how to dynamically configure the range and capacity of memory segments, ensure that critical tasks are exclusively allocated physical memory resources, guarantee the stability of memory when critical loads are running, reduce the burden on the translation backup buffer, ensure the continuity of physical memory, and improve memory access performance are problems that technical personnel in this field need to solve.
[0028] See also Figure 1As shown, an embodiment of the present invention discloses a memory access method, which may specifically include:
[0029] Step S11: using the firmware to determine the physical memory information to be reserved in the system memory, and parsing the physical memory information to be reserved to obtain the physical memory.
[0030] In this embodiment, a configuration command is obtained and generated by using a configuration interface of the firmware; a memory controller is used to forward the configuration command sent by the firmware to a programming memory controller or register, so that the programming memory controller or register modifies its own properties based on the configuration command to determine the physical memory information to be reserved in the system memory; the physical memory information to be reserved is added to the advanced configuration and power management interface table by using the firmware; the type of the physical memory information to be reserved in the advanced configuration and power management interface table is marked; the marked physical memory information to be reserved in the advanced configuration and power management interface table is parsed to obtain the physical memory and the corresponding physical memory information; a global static linked list is constructed, and the physical memory information is saved to the global static linked list; the physical memory information includes a starting address, a size, and an identifier.
[0031] The firmware in the present invention includes but is not limited to BIOS (Basic Input Output System) and UEFI (Unified Extensible Firmware Interface).
[0032] In this embodiment, during the system startup phase, the physical memory information to be reserved is determined through the configuration interface of the BIOS / UEFI firmware. Specifically, the BIOS sends a configuration command to the memory controller, and the memory controller forwards the configuration command to a specific register in the programming memory controller or chipset, such as the MTRR (Memory Type Range Register) or a similar mechanism. The programming memory controller or register then modifies its own attribute bit to identify the area as reserved memory. In the BIOS settings, by specifying the starting physical address (such as 0x20000000) and size (such as 1GB) of the reserved memory, the BIOS will mark the memory area as reserved.
[0033] At the same time, the BIOS writes the physical memory information to be reserved into the ACPI (Advanced Configuration and Power Interface) table, such as the E820 or UEFI memory map table, and marks it as "Reserved" type. This ensures that the operating system can recognize this area during the memory initialization phase and exclude it from dynamic memory allocation.
[0034] The BIOS uses the ACPI table to communicate the address range of physical memory to be reserved to the system. During the mem_block (memory management) phase of system startup, the system parses the ACPI table and separates physical memory from the operating system's regular memory management system. Furthermore, by constructing a global static linked list, the system can effectively store detailed physical memory information, including but not limited to the starting address, size, and identifiers, laying the foundation for subsequent driver access and management of physical memory.
[0035] Step S12: continuously splitting the physical memory to obtain physical memory segments, dividing and aligning the physical memory segments to obtain processed physical memory segments.
[0036] In this embodiment, a kernel driver module is constructed; a custom memory management structure is obtained, and a driver is generated based on the custom memory management structure; physical memory is obtained by using the kernel driver module; the physical memory is continuously split by using the driver to obtain physical memory segments; the array structure in the custom memory management structure in the driver is used to manage the physical memory segments; a corresponding virtual character device is created for each physical memory segment; a character device structure is defined for the virtual character device; a custom function is obtained, and the custom function is bound to the virtual character device; the bound virtual character device is registered to the kernel device management system; the transparent large page function is enabled; based on the transparent large page function, the physical memory segments are divided according to preset division rules, and the starting addresses and sizes of the physical memory segments are aligned to obtain the processed physical memory segments; the custom functions include device control functions, memory mapping functions, and virtual address space processing functions; the character device structure includes the major device number, minor device number, and device name of the virtual character device.
[0037] In this embodiment, a kernel driver module is created whose core function is to access physical memory. Based on this, the driver program rationally divides physical memory segments based on their continuity to better meet the system's memory management requirements. Furthermore, taking into account the node properties of NUMA (Non-Uniform Memory Architecture), the driver program categorizes and manages physical memory segments to ensure efficient memory utilization across different nodes. To implement this management process, the driver program defines custom memory management structures. Using array structures, it manages each physical memory segment in an orderly manner, improving the efficiency and flexibility of memory management.
[0038] In this embodiment, a corresponding virtual character device is created for each physical memory segment. In kernel space, knowledge of kernel driver development is leveraged to define a new character device structure for each physical memory segment. Taking the Linux kernel as an example, this structure contains essential information such as the device's major device number, minor device number, and device name, providing the fundamental data structure for creating and managing virtual character devices. This abstraction of a reserved physical memory segment into a virtual character device facilitates its use.
[0039] The present invention registers a virtual character device using a kernel-provided registration function, such as register_chrdev(), to register the virtual character device in the kernel device management system. During the registration process, a set of standard custom functions are bound to the virtual character device, such as an open function for opening the device and a close function for closing the device. In particular, the mmap function is bound to implement mapping between user-mode memory and physical memory segments, and the get_unmapped_area function is bound to implement processing of the process virtual address space.
[0040] Next, enable the transparent huge page feature. Taking the Linux kernel, a typical kernel configuration, as an example, enable huge page support in the kernel configuration options to ensure the kernel has huge page management capabilities. Physical memory segments are then divided according to preset partitioning rules, with default huge page sizes such as 2MB or 1GB. The starting address and size of the physical memory segments are aligned to the specified huge page size to ensure linear mapping.
[0041] Step S13: determining a virtual address space, dividing the virtual address space, and aligning the divided virtual address space based on the processed physical memory segments to obtain a processed virtual address space.
[0042] Step S14: Calculate the physical address space corresponding to the processed virtual address space, and perform memory mapping on the processed physical memory segment and the physical address space corresponding to the processed virtual address space.
[0043] In this embodiment, a preset linear operation formula is used to calculate the physical address space corresponding to the processed virtual address space; and a virtual address space processing function is used to perform memory mapping on the processed physical memory segment and the physical address space corresponding to the processed virtual address space.
[0044] This application implements custom memory mapping logic within the standard character device operation function mmap. When mapping memory to user mode via a system call, the virtual address range is determined, the starting address of the virtual space is aligned to the specified huge page size, and the requested mapping size is also aligned. The physical address space corresponding to the virtual address space is calculated using a preset linear arithmetic formula. During memory mapping, a page fault is triggered by default, and the initial huge page table is established.
[0045] Step S15: Generate a page table using the physical address space corresponding to the mapped and processed virtual address space.
[0046] In this embodiment, a page table entry is created for the virtual address in the physical address space corresponding to the processed virtual address space; the physical address corresponding to the virtual address is calculated using a preset linear operation formula, and the physical address corresponding to the virtual address is filled into the page table entry to generate a page table; the attribute information of the page table is configured according to the memory access requirements and security policy to obtain a configured page table; the configuration includes access permission configuration and cache policy configuration; the configured page table is saved to the system memory, and the page table pointer of the user-mode process is updated.
[0047] Specifically, the kernel traverses the virtual address space and creates a page table entry for the virtual address corresponding to each large page according to the large page boundary. When creating a page table entry, the corresponding physical address is calculated through linear operations and filled into the page table entry to obtain the final page table. At the same time, according to the memory access requirements and security policies, the access rights, cache policies and other attributes of the page table entries are set. For example, for large pages of read-only data, the page table entries are set to read-only permissions, and their cache policies are optimized to improve read performance. After completing the creation and filling of the page table entries, the kernel stores the page table information in the system memory and updates the page table pointer of the user-mode process, so that the process can directly use the pre-established page table when accessing the memory area in the future, avoiding the overhead of page fault exceptions.
[0048] Step S16: When the user's access instruction is obtained, the target physical address space corresponding to the access instruction is filtered from the page table, the mapped target physical memory segment corresponding to the target physical address space is determined, and the target physical memory segment is sent to the user state process so that the user can access the target physical memory segment based on the user state process.
[0049] In this embodiment, a user-mode program accesses a target physical memory segment through a standard interface for a virtual character device. Using the mmap system call, the target physical memory segment is mapped to the user-mode process via the corresponding file descriptor for direct access. This application also incorporates a physical memory pre-fill mechanism to reduce page faults during memory access, minimize context switching, and improve performance.
[0050] Furthermore, in addition to incorporating traditional ECC (Error-Correcting Code) memory protection mechanisms into the BIOS reserved memory area, this application also introduces a multi-level memory error detection and recovery strategy. For example, a protection scheme based on a combination of parity and ECC is employed. Correctable single-bit errors are automatically corrected using ECC; uncorrectable multi-bit errors are rapidly recovered through memory mirroring or redundant backup technologies (e.g., allocating redundant backup space for critical data in the reserved memory area), ensuring the continuity and reliability of critical tasks. Furthermore, a real-time memory error monitoring and alarm system is established. When memory errors exceed a certain threshold, system administrators are promptly notified to perform hardware maintenance or replacement, preventing critical task failures due to memory failures.
[0051] The specific process of implementing memory access in the present invention is as follows Figure 2 As shown, by utilizing the underlying hardware control capabilities of the BIOS, a specific memory segment is designated as reserved memory during the system startup phase, the physical memory information to be reserved is determined, the physical memory is parsed, and then a virtual character device is created and registered with the kernel device management system; linear large page mapping is then implemented, that is, memory mapping is performed on the processed physical memory segment and the physical address space corresponding to the processed virtual address space, and finally a page table is generated using the physical address space corresponding to the mapped processed virtual address space. When a user access instruction is obtained, the mapped target physical memory segment corresponding to the target physical address space in the page table is determined, and the target physical memory segment is sent to the user-mode process. The key technical point of the present invention is to achieve physical memory reservation through the collaborative configuration of the BIOS and the operating system and to establish a large page-level memory mapping for the reserved memory, thereby reducing TLB pressure and improving cache hit rate. The page table is established in advance during the mmap phase to reduce memory access overhead, thereby comprehensively improving memory management performance and stability.
[0052] Memory access system structure such as Figure 3 As shown, the present invention implements hardware-level memory resource reservation through BIOS-level physical memory pre-isolation and ACPI table customization, avoiding memory preemption and swapping issues caused by dynamic system allocation, providing dedicated memory areas for critical tasks, and improving program operation stability. Linear large page mapping reduces TLB misses, improves cache hit rates, and reduces access latency. Furthermore, linear mapping ensures physical memory continuity and reduces memory fragmentation. Pre-building the page table during mapping eliminates page fault exception handling overhead, reduces context switching during memory access, and improves program performance.
[0053] In this embodiment, firmware is used to determine physical memory information to be reserved in the system memory, and the reserved physical memory information is parsed to obtain physical memory; the physical memory is continuously split to obtain physical memory segments, and the physical memory segments are divided and aligned to obtain processed physical memory segments; a virtual address space is determined, the virtual address space is divided, and the divided virtual address space is aligned based on the processed physical memory segments to obtain a processed virtual address space; the physical address space corresponding to the processed virtual address space is calculated, and memory mapping is performed on the processed physical memory segments and the physical address space corresponding to the processed virtual address space; a page table is generated using the physical address space corresponding to the mapped processed virtual address space; when a user's access instruction is obtained, the target physical address space corresponding to the access instruction is filtered from the page table, the mapped target physical memory segment corresponding to the target physical address space is determined, and the target physical memory segment is sent to the user state process so that the user can access the target physical memory segment based on the user state process.
[0054] This application uses the underlying hardware control capabilities of the firmware to determine the physical memory information to be reserved in the system memory. Compared with the traditional static reservation method, this application can support dynamic configuration of memory segment range and capacity, ensure that critical tasks are exclusively allocated physical memory resources, avoid interference factors such as operating system memory recovery and process preemption, and ensure the stability of memory when critical loads are running. The reserved physical memory information is parsed to obtain physical memory, the physical memory is continuously split to obtain various physical memory segments, the physical memory segments are divided and aligned, the virtual address space is divided, and the divided virtual address space is aligned based on the processed physical memory segments. The processed virtual address space is obtained, the physical address space corresponding to the processed virtual address space is calculated, and the processed physical memory segment and the physical address space corresponding to the processed virtual address space are memory mapped. Therefore, the large page memory can be fully utilized to reduce the number of page table entries, reduce the burden of the translation backup buffer, ensure the continuity of the physical memory, and generate a page table using the physical address space corresponding to the mapped processed virtual address space. When the user's access instruction is obtained, the target physical memory segment can be quickly located, thereby improving the memory access performance, meeting the requirements of key tasks for high-performance memory access, and reducing the generation of page fault exceptions during memory access.
[0055] See also Figure 4 As shown, an embodiment of the present invention discloses a memory access device, which may specifically include:
[0056] The parsing module 11 is used to determine the physical memory information to be reserved in the system memory by using the firmware, and parse the physical memory information to obtain the physical memory;
[0057] A physical memory segment processing module 12 is configured to continuously split the physical memory to obtain physical memory segments, and to divide and align the physical memory segments to obtain processed physical memory segments.
[0058] A virtual address space processing module 13 is configured to determine a virtual address space, divide the virtual address space, and align the divided virtual address space based on the processed physical memory segments to obtain a processed virtual address space;
[0059] A memory mapping module 14 is configured to calculate a physical address space corresponding to the processed virtual address space and perform memory mapping between the processed physical memory segment and the physical address space corresponding to the processed virtual address space;
[0060] A page table generation module 15 is used to generate a page table using the physical address space corresponding to the mapped processed virtual address space;
[0061] The target physical memory segment access module 16 is used to, when obtaining the user's access instruction, filter the target physical address space corresponding to the access instruction from the page table, determine the mapped target physical memory segment corresponding to the target physical address space, and send the target physical memory segment to the user state process so that the user can access the target physical memory segment based on the user state process.
[0062] In this embodiment, firmware is used to determine physical memory information to be reserved in the system memory, and the reserved physical memory information is parsed to obtain physical memory; the physical memory is continuously split to obtain physical memory segments, and the physical memory segments are divided and aligned to obtain processed physical memory segments; a virtual address space is determined, the virtual address space is divided, and the divided virtual address space is aligned based on the processed physical memory segments to obtain a processed virtual address space; the physical address space corresponding to the processed virtual address space is calculated, and memory mapping is performed on the processed physical memory segments and the physical address space corresponding to the processed virtual address space; a page table is generated using the physical address space corresponding to the mapped processed virtual address space; when a user's access instruction is obtained, the target physical address space corresponding to the access instruction is filtered from the page table, the mapped target physical memory segment corresponding to the target physical address space is determined, and the target physical memory segment is sent to the user state process so that the user can access the target physical memory segment based on the user state process.
[0063] This application uses the underlying hardware control capabilities of the firmware to determine the physical memory information to be reserved in the system memory. Compared with the traditional static reservation method, this application can support dynamic configuration of memory segment range and capacity, ensure that critical tasks are exclusively allocated physical memory resources, avoid interference factors such as operating system memory recovery and process preemption, and ensure the stability of memory when critical loads are running. The reserved physical memory information is parsed to obtain physical memory, the physical memory is continuously split to obtain various physical memory segments, the physical memory segments are divided and aligned, the virtual address space is divided, and the divided virtual address space is aligned based on the processed physical memory segments. The processed virtual address space is obtained, the physical address space corresponding to the processed virtual address space is calculated, and the processed physical memory segment and the physical address space corresponding to the processed virtual address space are memory mapped. Therefore, the large page memory can be fully utilized to reduce the number of page table entries, reduce the burden of the translation backup buffer, ensure the continuity of the physical memory, and generate a page table using the physical address space corresponding to the mapped processed virtual address space. When the user's access instruction is obtained, the target physical memory segment can be quickly located, thereby improving the memory access performance, meeting the requirements of key tasks for high-performance memory access, and reducing the generation of page fault exceptions during memory access.
[0064] In some specific embodiments, the parsing module 11 may specifically include:
[0065] Configuration command acquisition and generation module, used to obtain and generate configuration commands using the firmware configuration interface;
[0066] The attribute modification module is used to use the memory controller to forward the configuration command sent by the firmware to the programming memory controller or register, so that the programming memory controller or register modifies its own attributes based on the configuration command to determine the physical memory information to be reserved in the system memory.
[0067] In some specific embodiments, the parsing module 11 may specifically include:
[0068] A module for adding information of physical memory to be reserved, used for adding information of physical memory to be reserved to the advanced configuration and power management interface table by using firmware;
[0069] The type marking module is used to mark the type of the physical memory information to be reserved in the advanced configuration and power management interface table.
[0070] In some specific embodiments, the parsing module 11 may specifically include:
[0071] The module for parsing the physical memory information to be reserved is used to parse the physical memory information to be reserved in the marked advanced configuration and power management interface table to obtain the physical memory and the corresponding physical memory information; the physical memory information includes the starting address, size, and identifier;
[0072] The physical memory information storage module is used to build a global static linked list and save the physical memory information to the global static linked list.
[0073] In some specific embodiments, the physical memory segment processing module 12 may specifically include:
[0074] Kernel driver module building module, used to build kernel driver module;
[0075] The driver generation module is used to obtain a custom memory management structure and generate a driver based on the custom memory management structure.
[0076] In some specific embodiments, the physical memory segment processing module 12 may specifically include:
[0077] A physical memory acquisition module is used to obtain physical memory using a kernel driver module;
[0078] The continuity splitting module is used to use the driver to continuously split the physical memory to obtain various physical memory segments;
[0079] The physical memory segment management module is used to manage each physical memory segment using the array structure in the custom memory management structure in the driver.
[0080] In some specific embodiments, the physical memory segment processing module 12 may specifically include:
[0081] A virtual character device creation module is used to create a corresponding virtual character device for each physical memory segment;
[0082] The character device structure definition module is used to define a character device structure for a virtual character device; the character device structure includes the major device number, minor device number, and device name of the virtual character device.
[0083] In some specific embodiments, the memory device further includes:
[0084] The binding module is used to obtain the custom function and bind the custom function to the virtual character device; the custom function includes the device control function, the memory mapping function, and the virtual address space processing function;
[0085] The registration module is used to register the bound virtual character device to the kernel device management system.
[0086] In some specific embodiments, the memory mapping module 14 may specifically include:
[0087] A physical address space calculation module is used to calculate the physical address space corresponding to the processed virtual address space using a preset linear operation formula;
[0088] The physical memory segment and physical address space memory mapping module is used to use the virtual address space processing function to perform memory mapping on the processed physical memory segment and the physical address space corresponding to the processed virtual address space.
[0089] In some specific embodiments, the virtual address space processing module 13 may specifically include:
[0090] Function activation module, used to enable the transparent huge page function;
[0091] The physical memory segment division and alignment processing module is used to divide the physical memory segments according to preset division rules based on the transparent huge page function, and align the starting address and size of the physical memory segments.
[0092] In some specific embodiments, the page table generation module 15 may specifically include:
[0093] A page table entry creation module is used to create a page table entry for the virtual address in the physical address space corresponding to the processed virtual address space;
[0094] The filling module is used to calculate the physical address corresponding to the virtual address using a preset linear operation formula, and fill the physical address corresponding to the virtual address into the page table entry to generate a page table.
[0095] In some specific embodiments, the page table generation module 15 may specifically include:
[0096] The attribute information configuration module is used to configure the attribute information of the page table according to the memory access requirements and security policies to obtain the configured page table; the configuration includes access permission configuration and cache policy configuration;
[0097] The page table saving module is used to save the configured page table to the system memory and update the page table pointer of the user mode process.
[0098] Among them, the description of the features in the embodiment corresponding to the memory access device can refer to the relevant description of the embodiment corresponding to the memory access method, and will not be repeated here.
[0099] 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 access method embodiments.
[0100] 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 access method embodiments when run.
[0101] 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.
[0102] 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 access method embodiments are implemented.
[0103] 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 access method embodiments are implemented.
[0104] 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.
[0105] The above is a detailed introduction to a memory access 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 noted 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 these improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. A memory access method, characterized in that: include: Determine physical memory information to be reserved in the system memory by using firmware, and parse the physical memory information to be reserved to obtain physical memory; Continuously splitting the physical memory to obtain physical memory segments, dividing and aligning the physical memory segments to obtain processed physical memory segments; Determine a virtual address space, divide the virtual address space, and align the divided virtual address space based on the processed physical memory segments to obtain the processed virtual address space; Calculating a physical address space corresponding to the processed virtual address space, and performing memory mapping on the processed physical memory segment and the physical address space corresponding to the processed virtual address space; Generate a page table using the physical address space corresponding to the mapped virtual address space; When a user's access instruction is obtained, the target physical address space corresponding to the access instruction is filtered from the page table, the mapped target physical memory segment corresponding to the target physical address space is determined, and the target physical memory segment is sent to the user state process so that the user can access the target physical memory segment based on the user state process.
2. The memory access method according to claim 1, wherein: The method of determining the physical memory information to be reserved in the system memory by using the firmware includes: Use the firmware's configuration interface to obtain and generate configuration commands; The memory controller is used to forward the configuration command sent by the firmware to a programming memory controller or a register, so that the programming memory controller or the register modifies its own properties based on the configuration command to determine the physical memory information to be reserved in the system memory.
3. The memory access method according to claim 1, wherein: After determining the physical memory information to be reserved in the system memory by using the firmware, the method further includes: Using firmware to add physical memory information to be reserved to the Advanced Configuration and Power Management Interface table; The physical memory information to be reserved in the advanced configuration and power management interface table is marked with a type.
4. The memory access method according to claim 3, wherein: The step of parsing the physical memory information to be reserved to obtain the physical memory includes: Parsing the physical memory information to be reserved in the marked advanced configuration and power management interface table to obtain physical memory and corresponding physical memory information; the physical memory information includes a starting address, size, and identifier; Construct a global static linked list, and save the physical memory information to the global static linked list.
5. The memory access method according to claim 1, wherein: Before the continuous splitting of the physical memory, the method further includes: Build kernel driver module; Obtain a custom memory management structure, and generate a driver based on the custom memory management structure.
6. The memory access method according to claim 5, wherein: The continuous splitting of the physical memory to obtain physical memory segments includes: Obtaining physical memory using the kernel driver module; Utilizing a driver to continuously split the physical memory to obtain physical memory segments; Each of the physical memory segments is managed using the array structure in the custom memory management structure in the driver.
7. The memory access method according to claim 1, wherein: Before dividing and aligning the physical memory segments, the method further includes: Creating a corresponding virtual character device for each of the physical memory segments; A character device structure is defined for the virtual character device; the character device structure includes a major device number, a minor device number, and a device name of the virtual character device.
8. The memory access method according to claim 7, wherein: Also includes: Obtaining a custom function, and binding the custom function to the virtual character device; The custom functions include device control functions, memory mapping functions, and virtual address space processing functions; Register the bound virtual character device to the kernel device management system.
9. The memory access method according to claim 8, wherein: The calculating a physical address space corresponding to the processed virtual address space, and performing memory mapping on the processed physical memory segment and the physical address space corresponding to the processed virtual address space, comprising: Calculating the physical address space corresponding to the processed virtual address space using a preset linear operation formula; The virtual address space processing function is used to perform memory mapping on the processed physical memory segment and the physical address space corresponding to the processed virtual address space.
10. The memory access method according to claim 1, wherein: The dividing and aligning of the physical memory segments includes: Enable the transparent huge pages feature; On the basis of the transparent huge page function, the physical memory segment is divided according to a preset division rule, and the starting address and size of the physical memory segment are aligned.
11. The memory access method according to claim 1, wherein: Generating a page table using the physical address space corresponding to the mapped virtual address space includes: Creating a page table entry for the processed virtual address in the physical address space corresponding to the virtual address space; A physical address corresponding to the virtual address is calculated using a preset linear operation formula, and the physical address corresponding to the virtual address is filled into the page table entry to generate a page table.
12. The memory access method according to any one of claims 1 to 11, characterized in that: After generating a page table using the physical address space corresponding to the mapped virtual address space, the method further includes: Configuring attribute information of a page table according to memory access requirements and security policies to obtain the configured page table; the configuration includes access permission configuration and cache policy configuration; The configured page table is saved to the system memory, and the page table pointer of the user mode process is updated.
13. An electronic device, characterized in that: include: memory for storing computer programs; A processor, configured to implement the steps of the memory access method according to any one of claims 1 to 12 when executing the computer program.
14. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the memory access 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 access method according to any one of claims 1 to 12 are implemented.
Citation Information
Patent Citations
Mirror image file generation and loading method and device
CN109683983A
Memory access method, chip, electronic equipment and computer readable storage medium
CN116136826A