Memory access method, program product, equipment and medium
Through firmware parsing and splitting memory, generating virtual address space page tables, the flexibility and stability of memory management are solved, dynamic memory mapping is realized, and memory access performance and system efficiency are improved.
Patent Information
- Application Number
- CN202510813637.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-18
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2045-06-18
AI Technical Summary
The lack of flexibility in existing memory management technologies leads to address conflicts and memory access performance degradation. Especially in the traditional 4KB small pages and static large page memory management mode, it is difficult to dynamically configure the memory segment range and capacity, affecting the memory stability and performance of critical tasks.
The system memory information is determined through firmware, the physical memory is parsed and split, and the page table of the virtual address space is generated, dynamic memory mapping and fast access are realized, ensuring that critical tasks exclusively allocate physical memory resources and reducing the burden of conversion backup buffers.
Improve memory access performance, ensure memory stability of critical tasks, reduce page-missing exceptions and memory fragmentation, and improve system operation efficiency.
Smart Images

Figure CN120353723A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technologies, and in particular, to a memory access method, a program product, a device, and a medium. Background Art
[0002] Memory management plays a crucial role in system performance and the efficient operation of application programs. By reserving physical memory for specific programs, the stability of the memory used by the current program can be ensured. Currently, common memory reservation technologies usually rely on the hard coding of mmap (Memory Mapping) parameters. This method usually requires configuration after the system starts, lacks flexibility, and setting mmap parameters requires obtaining information such as hardware information and the memory requirement characteristics of application programs in advance. Once set improperly, it may lead to address conflicts.
[0003] In response to the performance bottleneck of the traditional 4KB small page memory management mode, currently, mainly THP (Transparent Huge Pages) and static large page technologies are adopted. Transparent large pages usually automatically aggregate 4K pages into large pages, and there will be a certain delay in this process, resulting in the inability to apply for large page memory when the system needs large page memory. Static large page memory depends on the large page file system and requires reservation of large page memory in advance. At the same time, due to the randomness of the system physical memory allocation Buddy algorithm for large page memory allocation, the physical addresses of the memory blocks allocated to user-mode application programs may be discontinuous after application, which is inconvenient for memory block calls and leads to a decrease in memory access performance.
[0004] It can be seen that how to dynamically configure the memory segment range and capacity, ensure the exclusive allocation of physical memory resources for critical tasks, guarantee the stability of memory during the operation of critical loads, reduce the burden on the translation lookaside buffer, ensure the continuity of physical memory, and improve memory access performance are problems that need to be solved by those skilled in the art. Summary of the Invention
[0005] The purpose of the embodiments of the present invention is to provide a memory access method, a program product, a device, and a medium, which can dynamically configure the memory segment range and capacity, ensure the exclusive allocation of physical memory resources for critical tasks, guarantee the stability of memory during the operation of critical loads, reduce the burden on the translation lookaside buffer, ensure the continuity of physical memory, and improve memory access performance. The specific solutions are as follows: In a first aspect, the present application discloses a memory access method, including: Using 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 physical memory; Perform continuous splitting on the physical memory to obtain each physical memory segment, perform partitioning and alignment processing on the physical memory segment to obtain the processed physical memory segment; Determine the virtual address space, partition the virtual address space, and perform alignment processing on the partitioned virtual address space based on the processed physical memory segment to obtain the processed virtual address space; 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; Generate a page table using the physical address space corresponding to the mapped processed virtual address space; When an access instruction from the user is obtained, 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-mode process so that the user can access the target physical memory segment based on the user-mode process.
[0006] In a second aspect, the present application discloses an electronic device, including: A memory for storing a computer program; A processor for implementing the steps of the foregoing memory access method when executing the computer program.
[0007] In a third aspect, the present application discloses a computer-readable storage medium having a computer program stored therein, wherein the computer program, when executed by a processor, implements the steps of the foregoing memory access method.
[0008] In a fourth aspect, the present application discloses a computer program product, wherein the computer program, when executed by a processor, implements the steps of the foregoing memory access method.
[0009] As can be seen, the present application provides a memory access method, which includes using firmware to determine the physical memory information to be reserved in the system memory, parsing the physical memory information to be reserved to obtain physical memory; splitting the physical memory continuously to obtain each physical memory segment, partitioning and aligning the physical memory segments to obtain the processed physical memory segments; determining the virtual address space, partitioning the virtual address space, and aligning the partitioned 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, and performing memory mapping on 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 an access instruction from a user is obtained, screening 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-mode process so that the user can access the target physical memory segment based on the user-mode process.
[0010] The present 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, the present application can support dynamic configuration of the memory segment range and capacity, ensure that the physical memory resources are exclusively allocated for critical tasks, avoid interference factors such as operating system memory recycling and process preemption, and guarantee the stability of the memory during the operation of critical loads. By parsing the physical memory information to be reserved to obtain physical memory, continuously splitting the physical memory to obtain each physical memory segment, partitioning and aligning the physical memory segments, partitioning the virtual address space, and aligning the partitioned 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, and performing memory mapping on the processed physical memory segments and the physical address space corresponding to the processed virtual address space, it can give full play to the large-page memory to reduce the number of page table entries, reduce the burden on the translation lookaside buffer, and ensure the continuity of physical memory. By generating a page table using the physical address space corresponding to the mapped processed virtual address space, when an access instruction from a user is obtained, it can quickly locate the target physical memory segment, thereby improving the memory access performance, meeting the requirements of critical tasks for high-performance memory access, and reducing the occurrence of page faults during memory access. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the embodiments of the present application, the drawings required for the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0012] Figure 1 Flowchart of a memory access method disclosed in this application; Figure 2 Specific flowchart for implementing memory access provided by this application; Figure 3 Structure diagram of a memory access system provided by this application; Figure 4 Schematic diagram of the structure of a memory access device disclosed in this application. Detailed implementation manners
[0013] Next, the technical solutions in the embodiments of this application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of this application.
[0014] 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 usually rely on the hard coding of mmap parameters. This method usually requires configuration after the system starts, lacking flexibility. At the same time, setting mmap parameters requires obtaining information such as hardware information and the memory requirement characteristics of application programs in advance. Once set improperly, it may lead to address conflicts. In response to the performance bottleneck of the traditional 4KB small-page memory management mode, currently, mainly THP and static large-page technologies are adopted. Transparent large pages usually automatically aggregate 4K pages into large pages, and this process will have a certain delay, resulting in the inability to apply for large-page memory when the system needs large-page memory. Static large-page memory depends on the large-page file system and requires pre-reservation of large-page memory. At the same time, due to the randomness of the system physical memory allocation Buddy algorithm affecting the allocation of large-page memory, the physical addresses of the memory blocks allocated to user-mode applications may be discontinuous after application, which is inconvenient for memory block calls and leads to a decrease in memory access performance.
[0015] It can be seen that how to implement dynamic configuration of the memory segment range and capacity, ensure exclusive allocation of physical memory resources for critical tasks, guarantee the stability of memory during the operation of critical loads, reduce the burden on the translation lookaside buffer, ensure the continuity of physical memory, and improve memory access performance are problems that need to be solved by those skilled in the art.
[0016] See Figure 1 As shown, an embodiment of the present invention discloses a memory access method, which may specifically include: Step S11: Use the firmware to determine the physical memory information to be reserved in the system memory, and parse the physical memory information to be reserved to obtain the physical memory.
[0017] In this embodiment, use the configuration interface of the firmware to obtain and generate a configuration command; 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; use the firmware to add the physical memory information to be reserved to the Advanced Configuration and Power Management Interface Table; perform type annotation on the physical memory information to be reserved in the Advanced Configuration and Power Management Interface Table; parse the physical memory information to be reserved in the annotated Advanced Configuration and Power Management Interface Table to obtain the physical memory and the corresponding physical memory information; construct a global static linked list and save the physical memory information to the global static linked list; the physical memory information includes the starting address, size, and identifier.
[0018] The firmware in the present invention includes but is not limited to BIOS (Basic Input Output System), UEFI (Unified Extensible Firmware Interface).
[0019] In this embodiment, in the system startup phase, determine the physical memory information to be reserved through the configuration interface of the BIOS / UEFI firmware. Specifically, the BIOS sends a configuration command to the memory controller, and then the memory controller forwards the configuration command to the programming memory controller or a specific register in the chipset, such as MTRR (Memory Type Range Register) or a similar mechanism. Then, the programming memory controller or register modifies its own attribute bits to identify this 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 marks this memory area as reserved.
[0020] 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 mapping table, and annotates it as the "Reserved" type, so as to ensure that the operating system can identify this area and exclude it from dynamic memory allocation during the memory initialization phase.
[0021] The BIOS passes the address range of the physical memory to be reserved to the system by means of the ACPI table. During the mem_block (memory management) stage of system startup, the system parses the ACPI table to separate the physical memory from the normal memory management system of the operating system. At the same time, by constructing a global static linked list, the system can effectively save the detailed physical memory information of the physical memory, including but not limited to the start address, size, identifier, etc., laying a foundation for the subsequent driver program to obtain and manage the physical memory.
[0022] Step S12: Continuously split the physical memory to obtain each physical memory segment, and perform partitioning and alignment processing on the physical memory segment to obtain the processed physical memory segment.
[0023] In this embodiment, a kernel driver module is constructed; a custom memory management structure is obtained, and a driver program is generated based on the custom memory management structure; the kernel driver module is used to obtain the physical memory; the driver program is used to continuously split the physical memory to obtain each physical memory segment; the array structure in the custom memory management structure in the driver program is used to manage each physical memory segment; 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 huge page function is enabled; on the basis of the transparent huge page function, the physical memory segment is partitioned according to a preset partitioning rule, and the start address and size of the physical memory segment are aligned to obtain the processed physical memory segment; the custom function includes a device control function, a memory mapping function, and a virtual address space processing function; the character device structure includes the major device number, minor device number, and device name of the virtual character device.
[0024] In this embodiment, a kernel driver module is created, and the core function of this module is to obtain the physical memory. On this basis, the driver program reasonably splits the physical memory segment according to its continuity to better adapt to the memory management requirements of the system. At the same time, considering the NUMA (Non-uniform Memory Architecture) node attributes, the driver program classifies and manages the physical memory segments to ensure the efficient utilization of the memory of different nodes. To implement this management process, the driver program customizes the memory management related structure, and through the array structure, manages each physical memory segment in an orderly manner, improving the efficiency and flexibility of memory management.
[0025] In this embodiment, corresponding virtual character devices are created for each physical memory segment. In the kernel space, using the relevant knowledge of kernel driver development, a new character device structure is defined for the physical memory segment. Taking the Linux kernel as an example, this structure contains necessary information such as the major device number, minor device number, and device name of the device, providing a basic data structure for the creation and management of virtual character devices. The reserved physical memory segments are abstracted as virtual character devices for convenient use.
[0026] In the present invention, the register function provided by the kernel, such as register_chrdev(), is used to register the virtual character device into the kernel device management system. During the registration process, a set of standard custom functions are bound to the virtual character device. For example, the open function is used to open the device, the close function is used to close the device. In particular, the mmap function is bound to implement the mapping between the user-mode memory and the physical memory segment, and the get_unmapped_area function is used to handle the process virtual address space.
[0027] Then, the transparent huge page function is enabled. Taking the Linux kernel, which is typical in kernel configuration, as an example, the relevant functions for huge page support are enabled in the kernel configuration options to ensure that the kernel has the ability to manage huge pages. Then, the physical memory segments are divided according to the preset division rules. The default huge page size is, for example, 2M or 1G, and the start address and size of the physical memory segments are aligned according to the specified huge page size to provide guarantee for linear mapping.
[0028] Step S13: Determine the virtual address space, divide the virtual address space, and perform alignment processing on the divided virtual address space based on the processed physical memory segment to obtain the processed virtual address space.
[0029] 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.
[0030] In this embodiment, the physical address space corresponding to the processed virtual address space is calculated using a preset linear operation formula; and 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.
[0031] In this application, a custom memory mapping processing logic is implemented in the mmap function of the standard character device operation. When mapping memory to user space through a system call, the virtual address range is determined, and the starting address of the virtual space is aligned according to the specified large page size, and the size of the requested mapping is also aligned. The physical address space corresponding to the virtual address space is calculated through a preset linear operation formula. When performing memory mapping, a page fault is triggered by default to establish an initial large page page table.
[0032] Step S15: Generate a page table using the physical address space corresponding to the processed virtual address space after mapping.
[0033] 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 policies 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 space process is updated.
[0034] 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 a linear operation 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, attributes such as the access permission and cache policy of the page table entry are set. For example, for a large page of read-only data, the page table entry is set to read-only permission, and its cache policy is optimized to improve the reading performance. After completing the creation and filling of the page table entry, the kernel stores the page table information in the system memory and updates the page table pointer of the user space process, so that the process can directly use the pre-established page table when accessing this memory area later, avoiding the overhead of page faults.
[0035] Step S16: When an access instruction from the user is obtained, 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 space process so that the user can access the target physical memory segment based on the user space process.
[0036] In this embodiment, the user space program uses the target physical memory segment through the standard interface of the virtual character device. The mmap system call is used to map the target physical memory segment into the user space process for direct access through the corresponding file descriptor. This application also adds a physical memory pre-filling mechanism to reduce the generation of page faults during memory access, reduce context switching, and improve performance.
[0037] In addition, in the BIOS reserved memory area of the present application, in addition to adding the traditional ECC (Error - Correcting Code) memory protection mechanism, a multi - level memory error detection and recovery strategy can also be introduced. For example, a protection scheme combining parity check and ECC is adopted. For correctable single - bit errors, ECC is used for automatic correction; for uncorrectable multi - bit errors, data is quickly recovered through memory mirroring or redundant backup technology (such as allocating redundant backup space for critical data in the reserved memory area) to ensure the continuity and reliability of critical tasks. At the same time, a real - time monitoring and alarm system for memory errors is established. When the memory errors exceed a certain threshold, the system administrator is notified in a timely manner for hardware maintenance or replacement to avoid the failure of critical tasks caused by memory faults.
[0038] The specific process of implementing memory access in the present invention is as Figure 2 shown. By utilizing the underlying hardware control capabilities of the BIOS, a specific memory segment is designated as the reserved memory during the system startup phase to determine the physical memory information to be reserved, the physical memory is parsed, and then a virtual character device is created and registered to the kernel device management system; then linear large - page mapping is 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. Finally, a page table is generated using the physical address space corresponding to the processed virtual address space after mapping. When a user access instruction is obtained, the 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 technical key point of the present invention is to achieve physical memory reservation through the collaborative configuration of the BIOS and the operating system and establish a large - page - level memory mapping for the reserved memory, thereby reducing the TLB pressure and improving the cache hit rate. The page table is established in advance during the mmap stage to reduce the memory access overhead, thereby comprehensively improving the memory management performance and stability.
[0039] The memory access system structure is as Figure 3 shown. Through physical memory pre - isolation at the BIOS layer and ACPI table customization, the present invention realizes hardware - level memory resource reservation, avoids memory preemption and swapping problems caused by dynamic system allocation, provides an exclusive memory area for critical tasks, and improves the program running stability; the implementation of linear large - page mapping not only reduces TLB misses, improves the cache hit rate, and reduces access latency, but also ensures the continuity of physical memory through linear mapping, reducing memory fragmentation; by pre - constructing the page table during mapping, the overhead of handling page - fault exceptions is eliminated, the context switching during memory access is reduced, and the program performance is improved.
[0040] In this embodiment, the firmware is used to determine the physical memory information to be reserved in the system memory, the physical memory information to be reserved is parsed to obtain the physical memory; the physical memory is continuously split to obtain each physical memory segment, and the physical memory segment is divided and aligned to obtain the processed physical memory segment; the 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 segment to obtain the processed virtual address space; the physical address space corresponding to the processed virtual address space is calculated, and the memory mapping is performed on the processed physical memory segment and the physical address space corresponding to the processed virtual address space; the page table is generated by using the physical address space corresponding to the mapped processed virtual address space; when the access instruction of the user is obtained, the target physical address space corresponding to the access instruction is screened from the page table, the target physical memory segment corresponding to the target physical address space is determined, and the target physical memory segment is sent to the user-mode process so that the user can access the target physical memory segment based on the user-mode process.
[0041] This application utilizes 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 the dynamic configuration of the memory segment range and capacity, ensure that the physical memory resources are exclusively allocated for critical tasks, avoid interference factors such as operating system memory recycling and process preemption, and ensure the stability of the memory during the operation of critical loads. The physical memory information to be reserved is parsed to obtain the physical memory, the physical memory is continuously split to obtain each physical memory segment, the physical memory segment is divided and aligned, the virtual address space is divided, and the divided virtual address space is aligned based on the processed physical memory segment to obtain the processed virtual address space. The physical address space corresponding to the processed virtual address space is calculated, and the memory mapping is performed on the processed physical memory segment and the physical address space corresponding to the processed virtual address space. Therefore, it can give full play to the large-page memory to reduce the number of page table entries, reduce the burden on the translation lookaside buffer, and ensure the continuity of the physical memory. The page table is generated by using the physical address space corresponding to the mapped processed virtual address space. When the access instruction of the user is obtained, the target physical memory segment can be quickly located, thereby improving the memory access performance, meeting the requirements of critical tasks for high-performance memory access, and reducing the occurrence of page faults during memory access.
[0042] See Figure 4 As shown, an embodiment of the present invention discloses a memory access device, which may specifically include: The parsing module 11 is used to use the firmware to determine the physical memory information to be reserved in the system memory, and parse the physical memory information to be reserved to obtain the physical memory; The physical memory segment processing module 12 is used to perform continuous splitting on the physical memory to obtain each physical memory segment, and perform partitioning and alignment processing on the physical memory segments to obtain the processed physical memory segments; The virtual address space processing module 13 is used to determine the virtual address space, partition the virtual address space, and perform alignment processing on the partitioned virtual address space based on the processed physical memory segments to obtain the processed virtual address space; The memory mapping module 14 is used to calculate the physical address space corresponding to the processed virtual address space, and perform memory mapping on the processed physical memory segments and the physical address space corresponding to the processed virtual address space; The page table generation module 15 is used to generate a page table by using the physical address space corresponding to the mapped processed virtual address space; The target physical memory segment access module 16 is used to, when obtaining a user 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-mode process so that the user can access the target physical memory segment based on the user-mode process.
[0043] In this embodiment, the firmware is used to determine the physical memory information to be reserved in the system memory, parse the physical memory information to be reserved to obtain the physical memory; perform continuous splitting on the physical memory to obtain each physical memory segment, and perform partitioning and alignment processing on the physical memory segments to obtain the processed physical memory segments; determine the virtual address space, partition the virtual address space, and perform alignment processing on the partitioned virtual address space based on the processed physical memory segments to obtain the processed virtual address space; calculate the physical address space corresponding to the processed virtual address space, and perform memory mapping on the processed physical memory segments and the physical address space corresponding to the processed virtual address space; generate a page table by using the physical address space corresponding to the mapped processed virtual address space; when obtaining a user 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-mode process so that the user can access the target physical memory segment based on the user-mode process.
[0044] This application utilizes 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 the memory segment range and capacity, ensure that the physical memory resources are exclusively allocated for critical tasks, avoid interference factors such as operating system memory recycling and process preemption, guarantee the stability of memory during the operation of critical loads, parse the physical memory information to be reserved to obtain the physical memory, split the physical memory continuously to obtain each physical memory segment, perform partitioning and alignment processing on the physical memory segments, partition the virtual address space, and perform alignment processing on the partitioned virtual address space based on the processed physical memory segments to obtain the processed virtual address space. Calculate the physical address space corresponding to the processed virtual address space, perform memory mapping on the processed physical memory segments and the physical address space corresponding to the processed virtual address space. Therefore, it can give full play to the advantages of large-page memory, reduce the number of page table entries, reduce the burden on the translation lookaside buffer, ensure the continuity of physical memory, generate a page table using the physical address space corresponding to the mapped processed virtual address space. When obtaining the user's access instruction, it can quickly locate the target physical memory segment, thereby improving the memory access performance, meeting the requirements of critical tasks for high-performance memory access, and reducing the occurrence of page faults during memory access.
[0045] In some specific embodiments, the parsing module 11 may specifically include: A configuration command acquisition and generation module, which is used to acquire and generate configuration commands using the configuration interface of the firmware; An attribute modification module, which is used to forward the configuration commands sent by the firmware to the programming memory controller or register using the memory controller, so that the programming memory controller or register modifies its own attributes based on the configuration commands to determine the physical memory information to be reserved in the system memory.
[0046] In some specific embodiments, the parsing module 11 may specifically include: A physical memory information to be reserved addition module, which is used to add the physical memory information to be reserved to the Advanced Configuration and Power Management Interface Table using the firmware; A type annotation module, which is used to perform type annotation on the physical memory information to be reserved in the Advanced Configuration and Power Management Interface Table.
[0047] In some specific embodiments, the parsing module 11 may specifically include: A physical memory information to be reserved parsing module, which is used to parse the physical memory information to be reserved in the annotated 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; A physical memory information storage module, which is used to construct a global static linked list and store the physical memory information in the global static linked list.
[0048] In some specific embodiments, the physical memory segment processing module 12 may specifically include: A kernel driver module construction module for constructing a kernel driver module; A driver program generation module for obtaining a custom memory management structure and generating a driver program based on the custom memory management structure.
[0049] In some specific embodiments, the physical memory segment processing module 12 may specifically include: A physical memory acquisition module for acquiring physical memory by using the kernel driver module; A continuity splitting module for continuously splitting the physical memory by using the driver program to obtain each physical memory segment; A physical memory segment management module for managing each physical memory segment by using an array structure in the custom memory management structure in the driver program.
[0050] In some specific embodiments, the physical memory segment processing module 12 may specifically include: A virtual character device creation module for creating a corresponding virtual character device for each physical memory segment; A character device structure definition module for defining a character device structure for the virtual character device; the character device structure includes the major device number, minor device number, and device name of the virtual character device.
[0051] In some specific embodiments, the memory device further includes: A binding module for obtaining a custom function and binding the custom function to the virtual character device; the custom function includes a device control function, a memory mapping function, and a virtual address space processing function; A registration module for registering the bound virtual character device to the kernel device management system.
[0052] In some specific embodiments, the memory mapping module 14 may specifically include: A physical address space calculation module for calculating the physical address space corresponding to the processed virtual address space by using a preset linear operation formula; A physical memory segment and physical address space memory mapping module for performing memory mapping on the processed physical memory segment and the physical address space corresponding to the processed virtual address space by using the virtual address space processing function.
[0053] In some specific embodiments, the virtual address space processing module 13 may specifically include: A function enabling module for enabling the transparent huge page function; The physical memory segment division and alignment processing module is used to divide the physical memory segment according to the preset division rules on the basis of the transparent huge page function, and perform alignment processing on the start address and size of the physical memory segment.
[0054] In some specific embodiments, the page table generation module 15 may specifically include: The page table entry creation module is used to create page table entries for virtual addresses in the physical address space corresponding to the processed virtual address space; The filling module is used to calculate the physical address corresponding to the virtual address by using the preset linear operation formula, and fill the physical address corresponding to the virtual address into the page table entry to generate a page table.
[0055] In some specific embodiments, the page table generation module 15 may specifically include: 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; 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.
[0056] Among them, for the description of the features in the embodiments corresponding to the memory access device, reference can be made to the relevant descriptions in the embodiments corresponding to the memory access method, which will not be elaborated here one by one.
[0057] An embodiment of the present application also provides an electronic device, including a memory and a processor. A computer program is stored in the memory, 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.
[0058] An embodiment of the present application also provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps in any one of the above-mentioned memory access method embodiments when running.
[0059] In an exemplary embodiment, the above-mentioned computer-readable storage medium may include, but is not limited to: USB flash drives, read-only memories (ROM for short), random access memories (RAM for short), mobile hard disks, magnetic disks or optical disks and other various media that can store computer programs.
[0060] An embodiment of the present application also provides a computer program product. The above-mentioned computer program product includes a computer program, and when the computer program is executed by a processor, it implements the steps in any one of the above-mentioned memory access method embodiments.
[0061] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium storing a computer program, where the computer program, when executed by a processor, implements the steps in any of the above-mentioned embodiments of the memory access method.
[0062] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner 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 to exceed the scope of the present application.
[0063] The above has introduced in detail a memory access method, program product, device, and medium provided by the present application. Specific examples are used herein to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.
Claims
1. A memory access method, characterized in that, Including: Using firmware to determine the physical memory information to be reserved in the system memory, parsing the physical memory information to be reserved to obtain physical memory; Continuously splitting the physical memory to obtain each physical memory segment, and performing partitioning and alignment processing on the physical memory segment to obtain the processed physical memory segment; Determining the virtual address space, partitioning the virtual address space, and performing alignment processing on the partitioned virtual address space based on the processed physical memory segment to obtain the processed virtual address space; Calculating the 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; Generating a page table using the physical address space corresponding to the mapped processed virtual address space; When an access instruction from a user is obtained, screening 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-mode process so that the user can access the target physical memory segment based on the user-mode process.
2. The memory access method according to claim 1, wherein The using firmware to determine the physical memory information to be reserved in the system memory includes: Using the configuration interface of the firmware to obtain and generate a configuration command; Using 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 the register modifies its own attributes 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 using the firmware to determine the physical memory information to be reserved in the system memory, it further includes: Using the firmware to add the physical memory information to be reserved to the Advanced Configuration and Power Management Interface Table; Performing type annotation on the physical memory information to be reserved in the Advanced Configuration and Power Management Interface Table.
4. The memory access method according to claim 3, wherein The parsing the physical memory information to be reserved to obtain physical memory includes: Parsing the physical memory information to be reserved in the annotated Advanced Configuration and Power Management Interface Table to obtain physical memory and corresponding physical memory information; the physical memory information includes a starting address, a size, and an identifier; Constructing a global static linked list and saving the physical memory information to the global static linked list.
5. The memory access method according to claim 1, characterized in that, Before continuously splitting the physical memory, it further includes: Constructing a kernel driver module; Obtaining a custom memory management structure and generating a driver program based on the custom memory management structure.
6. The memory access method according to claim 5, wherein The continuously splitting the physical memory to obtain each physical memory segment includes: Using the kernel driver module to obtain physical memory; Using the driver program to continuously split the physical memory to obtain each physical memory segment; Using the array structure in the custom memory management structure in the driver program to manage each physical memory segment.
7. The memory access method according to claim 1, wherein Before performing partitioning and alignment processing on the physical memory segment, it further includes: Creating a corresponding virtual character device for each physical memory segment; Define a character device structure for the virtual character device; the character device structure includes the major device number, minor device number, and device name of the virtual character device.
8. The memory access method according to claim 7, wherein It further includes: Obtain a custom function and bind the custom function to the virtual character device; The custom function includes a device control function, a memory mapping function, and a virtual address space processing function; Register the bound virtual character device to the kernel device management system.
9. The memory access method according to claim 8, wherein Calculating the 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, includes: Calculating the physical address space corresponding to the processed virtual address space using a preset linear operation formula; Performing memory mapping on the processed physical memory segment and the physical address space corresponding to the processed virtual address space using the virtual address space processing function.
10. The memory access method according to claim 1, characterized in that, The partitioning and alignment processing of the physical memory segment includes: Enable the transparent huge page function; Based on the transparent huge page function, partition the physical memory segment according to a preset partitioning rule, and perform alignment processing on the starting address and size of the physical memory segment.
11. The memory access method according to claim 1, wherein The generating a page table using the physical address space corresponding to the mapped processed virtual address space includes: Create a page table entry for the virtual address in the physical address space corresponding to the processed virtual address space; 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.
12. The memory access method according to any one of claims 1 to 11, characterized in that, After generating the page table using the physical address space corresponding to the mapped processed virtual address space, it further includes: Configure the attribute information of the page table according to the memory access requirement and security policy to obtain the configured page table; the configuration includes access permission configuration and cache policy configuration; Save the configured page table to the system memory and update the page table pointer of the user-mode process.
13. An electronic device, characterized in that, It includes: A memory for storing a computer program; A processor for implementing 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, A computer program is stored in the computer-readable storage medium, wherein the computer program implements the steps of the memory access method according to any one of claims 1 to 12 when executed by a processor.
15. A computer program product, comprising a computer program, characterized in that, The computer program implements the steps of the memory access method according to any one of claims 1 to 12 when executed by a processor.
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
Memory management method and device, computer equipment and storage medium
CN116302491A
Memory management method and device based on RDMA (Remote Direct Memory Access)
CN116644002A
Memory management method, device and equipment and machine readable storage medium
CN117743202A
Cited By
Memory management method, program product, equipment and medium
CN120743564A
A memory management method, program product, device and medium
CN120743564B
Memory data loading method and device, medium and product
CN120780541A
A memory data loading method, device, medium and product
CN120780541B
Memory access method and device, storage medium and program product
CN120803976A