A memory allocation method and device, electronic equipment and readable storage medium
By pre-establishing a memory mapping table, contiguous available memory regions are selected for allocation, solving the problem of non-contiguous memory in memory management within 4GB and improving system performance and memory utilization.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INSPUR SUZHOU INTELLIGENT TECH CO LTD
- Filing Date
- 2024-11-30
- Publication Date
- 2026-07-31
AI Technical Summary
When managing memory up to 4GB, existing technologies struggle to guarantee the continuity of memory allocation, leading to latency issues and impacting system performance.
By pre-establishing a memory mapping table, available memory regions are determined, and multiple target memory regions that are contiguous and whose total size meets the application requirements are selected during memory request. Their mapping information is then returned for allocation.
It reduces memory allocation latency, improves system performance, and enhances memory utilization and operating system startup stability.
Smart Images

Figure CN119669105B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer service technology, and in particular to a memory allocation method, apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] With the continuous development of computer service technologies, memory performance management and fragmentation management have become increasingly important. At the basic level, when managing memory up to 4GB, it's still necessary to consider compatibility with the various attributes of memory resources in past CPUs (Central Processing Units) and operating systems. Different resource requirements necessitate the partitioning of memory into corresponding regions, such as... Figure 1 As shown, this results in the physical address space being scattered among memory with different attributes, which means that the allocated memory may be discontinuous for large memory allocation needs. Since allocating memory across physical regions will cause latency loss, it will affect system performance.
[0003] Therefore, improving the continuity of memory partitioning and enhancing system performance has become a problem that needs to be solved by those skilled in the art. Summary of the Invention
[0004] The purpose of this invention is to provide a memory allocation method, apparatus, electronic device, and computer-readable storage medium that can reduce latency and improve system performance.
[0005] To address the aforementioned technical problems, embodiments of the present invention provide a memory allocation method, comprising:
[0006] Obtain the user's memory request and determine the memory request size based on the memory request;
[0007] The existence of a single memory region whose size meets the memory request size and is available is determined based on a pre-established memory mapping table. The memory mapping table includes memory address information and attribute information corresponding to each memory region from the minimum physical address to the maximum physical address. An adjustable number of memory regions starting from the minimum physical address are unavailable reserved areas, which are used for device resource configuration. The initial state of other memory regions is available. The attribute information includes the current state of the memory.
[0008] If there is no single memory region whose size meets the memory request size and is available, then multiple target memory regions whose total size meets the memory request size, are contiguous, and are available are selected from each memory region according to the memory mapping table.
[0009] Returns mapping information for multiple target memory regions; wherein the mapping information is used to determine the address information and size of the corresponding memory regions.
[0010] In some embodiments, it also includes:
[0011] If there exists a single memory region whose memory size meets the memory request size and is available, then determine whether there exists a single memory region that has been allocated and then released within the single memory region whose memory size meets the memory request size;
[0012] If there exists a single memory region that has been allocated and then freed, then the single memory region whose size is closest to the memory request size is determined from the single memory region that has been allocated and then freed as the target memory region.
[0013] Obtain the historical mapping identifier of the target memory region and return the historical mapping identifier as mapping information;
[0014] If there is no single memory region that has been allocated and then freed, then the single memory region whose memory size is closest to the memory request size is determined from all single memory regions whose memory size meets the memory request size and is available, and is used as the target memory region.
[0015] A new mapping identifier is generated for the target memory region, and the mapping identifier is returned as mapping information.
[0016] In some embodiments, the memory address information includes a start address and an end address; the memory status is available, unavailable, used, or released.
[0017] Then, multiple target memory regions that are selected from various memory regions according to the memory mapping table, whose total size meets the memory request size, are contiguous, and are available, include:
[0018] Based on the attribute information corresponding to each memory region stored in the memory mapping table, the available memory regions are determined.
[0019] Based on the memory address information corresponding to each available memory region, groups of available memory regions with consecutive addresses are determined from each available memory region;
[0020] From each of the available memory region groups that are address-contiguous, determine the total memory size corresponding to each available memory region group;
[0021] Based on the total memory size of each of the available memory region groups, a target available memory region group whose total memory size satisfies the memory request size is determined;
[0022] Each memory region in the target available memory region group is determined as a plurality of target memory regions whose total size meets the memory request size, are contiguous, and are available.
[0023] In some embodiments, determining the target available memory region group whose total memory size satisfies the memory request size based on the total memory size of each of the available memory region groups includes:
[0024] From each of the available memory region groups, identify the first available memory region groups whose total memory size is greater than or equal to the memory request size;
[0025] Determine whether there is a second available memory region group that has been allocated and then released in each of the first available memory region groups;
[0026] If there are groups of second available memory regions that have been allocated and then released, then the group of second available memory regions whose memory size is closest to the memory request size is determined as the target available memory region group; wherein, the returned mapping information of the multiple target memory regions includes the historical mapping identifier of the target available memory region group; if there are no groups of second available memory regions that have been allocated and then released, then the group of first available memory regions whose memory size is closest to the memory request size is determined as the target available memory region group; wherein, the returned mapping information of the multiple target memory regions includes the new mapping identifier generated for the target available memory region group.
[0027] In some embodiments, it also includes:
[0028] Get the user's memory release request;
[0029] The memory region to be released is determined based on the memory address and size in the memory release request;
[0030] Clear the data in the memory region to be released and update the attribute information corresponding to the memory region to be released in the memory mapping table.
[0031] In some embodiments, it also includes:
[0032] During the memory initialization phase, obtain the number of CPUs n on a single CPU, the number of CPUs cnt, the number of system root CPUs D, the memory capacity Sc of a single root CPU, and the reserved fixed memory capacity R.
[0033] The available memory capacity of the operating system is calculated based on the number of CPUs n on a single CPU, the number of CPUs cnt, the number of system root CPUs D, the memory capacity Sc of a single root CPU, and the reserved fixed memory capacity R.
[0034] Send the available memory capacity of the operating system to the operating system.
[0035] In some embodiments, the available memory capacity of the operating system is calculated based on the number of bandwidths n on a single central processing unit, the number of central processing units cnt, the number of system bandwidths D, the memory capacity Sc of a single bandwidth, and the reserved fixed memory capacity R, including:
[0036] The total number of bands N is calculated based on the number of bands n on the single central processing unit and the number of central processing units cnt;
[0037] The number of interleaving I is calculated based on the number of root bands D in the system and the number of bands n on a single central processing unit;
[0038] The total physical memory T of the system is calculated based on the number of system roots D and the memory capacity Sc of a single system root.
[0039] The first ratio is obtained by dividing the difference between the total physical memory T of the system and the reserved fixed memory capacity R by the total number of modules N.
[0040] Divide the first ratio by the number of interleavings I to obtain the second ratio, and round the second ratio to obtain the physical memory capacity St on each band;
[0041] The memory capacity of the minimum block available area cm is obtained by taking the third ratio of the physical memory capacity St of each band to the number of interleavings.
[0042] The available memory capacity of the operating system is calculated based on the memory capacity cm of the minimum block available region, the number of interleaving I, the number of CPUs n on a single CPU, and the number of CPUs cnt.
[0043] Another embodiment of the present invention provides a memory allocation device, comprising:
[0044] The first determining module is used to obtain the user's memory request and determine the memory request size based on the memory request.
[0045] The judgment module is used to determine whether there exists a single memory region whose memory size meets the memory request size and is available, based on a pre-established memory mapping table; wherein, the memory mapping table includes memory address information and attribute information corresponding to each memory region from the minimum physical address to the maximum physical address;
[0046] The filtering module is used to filter out multiple target memory regions that are available, whose total size meets the memory request size, are contiguous, and are available from each memory region according to the memory mapping table if there is no single memory region whose memory size meets the memory request size.
[0047] The return module is used to return mapping information for multiple target memory regions; wherein the mapping information is used to determine the address information and size of the corresponding memory region.
[0048] Another aspect of the present invention provides an electronic device, comprising:
[0049] Memory, used to store computer programs;
[0050] A processor for executing the computer program to implement the steps of the memory allocation method as described above.
[0051] Another aspect of this invention provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the memory allocation method described above.
[0052] As can be seen from the above technical solution, the beneficial effects of the present invention are as follows:
[0053] This invention provides a memory allocation method, comprising: acquiring a user's memory request; determining the memory request size based on the memory request; determining whether there exists a single memory region whose size satisfies the memory request size and is available based on a pre-established memory mapping table; wherein the memory mapping table includes memory address information and attribute information corresponding to each memory region from the minimum physical address to the maximum physical address, and an adjustable number of memory regions starting from the minimum physical address are unavailable reserved areas, which are used for device resource configuration, and the initial state of other memory regions is available, and the attribute information includes the current state of the memory; if there is no single memory region whose size satisfies the memory request size and is available, then selecting multiple target memory regions whose total size satisfies the memory request size, are contiguous, and are available from each memory region according to the memory mapping table; and returning the mapping information of the multiple target memory regions; wherein the mapping information is used to determine the address information and size of the corresponding memory region.
[0054] Therefore, in this embodiment of the invention, a memory mapping table is pre-established. The adjustable number of memory regions in the memory mapping table, starting from the smallest physical address, are reserved areas for device resource configuration. This ensures that the addresses of the reserved areas are contiguous, and that all other memory regions are initially available. This ensures that the initially available memory addresses are contiguous. When a user requests memory, the requested memory size can be determined based on the memory request. If, according to the memory mapping table, there is no single memory region whose size meets the memory request size and is available, a set of contiguous target memory regions with a total size that meets the memory request size can be determined from the memory mapping table. Then, the mapping information corresponding to this set of target memory regions is returned to the user, thereby allocating a set of contiguous memory regions, reducing latency and improving system performance.
[0055] Furthermore, the present invention also provides corresponding implementation devices, electronic devices, and computer-readable storage media for the memory allocation method, further making the method more practical, and the devices, electronic devices, and computer-readable storage media have corresponding advantages. Attached Figure Description
[0056] To more clearly illustrate the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0057] Figure 1 This is a representation of a 4G memory mapping in related technologies;
[0058] Figure 2 This is a schematic diagram of a memory allocation process in related technologies;
[0059] Figure 3 This is a memory classification relationship format diagram in related technologies;
[0060] Figure 4 A flowchart illustrating a memory allocation method provided in an embodiment of the present invention;
[0061] Figure 5 A flowchart illustrating another memory allocation method provided in an embodiment of the present invention;
[0062] Figure 6 This invention provides a memory mapping representation schematic for an embodiment of the invention.
[0063] Figure 7 This is a schematic diagram of a memory allocation device provided in an embodiment of the present invention;
[0064] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention;
[0065] Figure 9 This is a schematic diagram of the structure of a computer-readable storage medium provided in an embodiment of the present invention. Detailed Implementation
[0066] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of the present invention.
[0067] The terms "comprising" and "having," and any variations thereof, in the specification and accompanying drawings of this invention are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the steps or units listed, but may include steps or units not listed.
[0068] To enable those skilled in the art to better understand the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0069] It should be noted that when managing memory, at the basic level, when managing memory up to 4GB, the occupancy of memory resources, interrupts, display devices, and FLASH ROM (i.e., fast erase / write read-only programmer) within the 4GB address space is still considered in relation to past CPU and operating system memory resources. During the BIOS (Basic Input Output System) PEI (Pre-EFI Initialization) stage, when forming a memory resource description, the resource usage of the traditional CPU and devices is planned in advance. In the DXE (Driver Execution Environment) stage, the GCD (Global Coherency Domain, a group of processors and memory controllers) memory service management further classifies and manages these resources as basic memory services for BIOS use. This memory allocation process, compatible with traditional devices with PCH (Platform Controller Hub) and traditional OS (Operating System), is as follows: Figure 2 As shown, the constructed 4G memory mapping table is as follows: Figure 1 As shown.
[0070] When constructing the 4GB memory mapping table, the 1MB space will reserve the memory address range 0x00 to 0x500 and the area 0xA0000 to 0xFFFF for display, onboard device option ROM loading and operation, and FLASH ROM access. The top 4GB space will still reserve space for MMIO (Memory-mapped I / O), IOAPC (Advanced Programmable Interrupt Controller), CPU (Central Processing Unit) Root Port PCIE (peripheral component interconnect express) device space, and FLASH ROM space.
[0071] During the PEI phase, the occupancy status of different physical memory address spaces is obtained and compiled into a HOB (Hand-Off Block, a type of data transfer table) memory resource description table. In the early stages of DXE, basic GCD memory management services can be created, and resources transferred via HOBs are categorized and managed according to the attributes of physical memory segments and the space they occupy, with the format as follows: Figure 3 As shown.
[0072] In traditional memory management, GCD can provide basic management services for memory allocation and release initiated by the BIOS through the following function interfaces:
[0073] ·AddMemorySpace();
[0074] •AllocateMemorySpace();
[0075] ·FreeMemorySpace();
[0076] RemoveMemorySpace();
[0077] ·SetMemorySpaceAttributes();
[0078] ·SetMemorySpaceCapabilities().
[0079] The BIOS typically uses the following functions in bootservice (system service) to request and release memory:
[0080] / / Memory Services / /
[0081] EFI_ALLOCATE_PAGES AllocatePages;
[0082] EFI_FREE_PAGES FreePages;
[0083] EFI_GET_MEMORY_MAP GetMemoryMap;
[0084] EFI_ALLOCATE_P00L AllocatePool;
[0085] EFI_FREE_PO0L FreePool.
[0086] When the OS loads, the exitbootservice function in the BIOS will be called. The BIOS will pass the entire memory mapping relationship to the OS so that the OS can generate management tables for different types of memory attributes, which can be called by the kernel and system application layers.
[0087] The traditional memory management methods described above are no longer suitable for the development of current mainstream server systems. The traditional memory management within 4GB will cause the physical address space occupied by memory with different attributes to be scattered. As a result, the memory allocated for large memory allocation needs may be discontinuous. Since memory allocation across physical regions will cause latency loss, it will affect system performance.
[0088] In addition, considering that the devices in the current mainstream market have fully supported the UEFI architecture, the resources reserved in the low memory segment are not consumed. Instead, the MMIO method is directly used to provide memory space for device initialization and service calls. Therefore, most of the memory reserved within 4GB is idle and unused, resulting in resource waste.
[0089] In view of this, this embodiment of the invention provides a memory allocation method that can adapt to the development of current mainstream servers. This method abandons the traditional methods of CPU and OS low address memory management services and interrupt management services, and improves the problem of discontinuous memory management of 4GB top MMIO and Flash ROM, making memory allocation and management more optimized.
[0090] Next, a memory allocation method provided by an embodiment of the present invention will be described in detail. Figure 4This is a flowchart illustrating a memory allocation method provided in an embodiment of the present invention. The method includes:
[0091] S110: Obtain the user's memory request and determine the memory request size based on the memory request;
[0092] It should be noted that the method in this embodiment of the invention can be applied to the GCD memory management service, and the memory allocation function `allocate memory()` and the free memory service function can be pre-established. During the operating system startup phase, the user can send a memory request to the GCD memory management service through the BIOS. This memory request includes the memory request size (or memory request capacity), and can include `allocate pages` (allocate physical pages) or `allocate pool` (allocate a memory pool). After receiving the memory request sent by the BIOS, the GCD memory management service can determine the required memory size based on the memory request, that is, determine the memory request size.
[0093] S120: Determine whether there exists a single memory region whose size meets the memory request size and is available based on a pre-established memory mapping table; wherein, the memory mapping table includes the memory address information and attribute information corresponding to each memory region from the minimum physical address to the maximum physical address, and the adjustable number of memory regions starting from the minimum physical address are unavailable reserved areas, which are used for the configuration of device resources, and the initial state of other memory regions is available, and the attribute information includes the current state of the memory;
[0094] In this embodiment of the invention, a memory mapping table is pre-established. After determining the memory request and the memory request size, the memory size corresponding to each memory region can be further determined based on the memory address information and attribute information corresponding to each memory region stored in the memory mapping table. This allows it to determine whether there exists a single memory region that meets the memory request size (i.e., the memory is greater than or equal to the memory request size) and is available. In this embodiment of the invention, "available" means that the memory region is not used or has not been allocated.
[0095] It should be noted that, please refer to Figure 5 and Figure 6In this embodiment of the invention, a memory mapping table is pre-established. During the establishment process, the memory mapping table can be initialized first. This process can start from the smallest physical address of the memory (i.e., the lowest physical address) to build an initial memory mapping table. This initial memory mapping table records the memory address information and attribute information of each memory region (i.e., physical address segment). The memory address information can include the start address and end address, and the attribute information can include whether it is available, unavailable, used, released, or unused, etc. The attribute information is used to represent the state of a memory region. Then, the entire physical memory (e.g., physical memory within a 4GB range) is traversed, and the start address, end address, and attribute information corresponding to each memory region are identified and recorded and filled back into the initial memory mapping table. After traversing all memory regions, a completed physical memory mapping table is obtained. Each memory region in this memory mapping table is arranged in ascending order, and an adjustable number of memory regions starting from the smallest physical address are determined as unavailable reserved areas. These reserved areas can be used for device resource configuration. The initial state of other memory regions, except for the reserved areas, is available. The state of the corresponding memory regions will change after subsequent memory allocation based on the memory mapping table. Figure 5 The memory mapping table shown allows for the pre-reservation of some low-address memory regions for the configuration of different device resources.
[0096] S130: If there is no single memory region whose size meets the memory request size and is available, then select multiple target memory regions from each memory region according to the memory mapping table, whose total size meets the memory request size, are contiguous, and are available.
[0097] Understandably, if there is no single memory region in each memory region whose memory size meets the memory request size and is available, then the available and contiguous memory regions can be further determined from the memory mapping table. In other words, several unused contiguous memory regions can be identified, thereby identifying multiple sets of contiguous memory regions. Based on the total memory size of each set of contiguous memory regions, a set of contiguous and available memory regions whose total memory size is greater than or equal to the memory request size can be selected, and these memory regions can be used as target memory regions.
[0098] S140: Returns mapping information for multiple target memory regions; the mapping information is used to determine the address information and size of the corresponding memory regions.
[0099] It should be noted that after determining multiple target memory regions that are of sufficient total size to meet the memory request size, are contiguous, and are available, corresponding mapping information can be generated based on the memory address information corresponding to each target memory region in the memory mapping table. This mapping information is then returned to the BIOS. The BIOS determines the location of the allocated memory based on this mapping information and stores the user's data in the corresponding memory. Since the physical addresses of the memory regions allocated in this invention are contiguous and there is no allocation across physical regions, latency loss can be effectively avoided, which is beneficial to the performance of memory.
[0100] In addition, after returning the mapping information of multiple target memory regions, the attribute information corresponding to each of the multiple target memory regions in the memory mapping table can be updated in a timely manner. That is, the attribute information corresponding to the target memory region can be changed from available to unavailable, or from unused to allocated, so as to better manage memory.
[0101] Therefore, in this embodiment of the invention, a memory mapping table is pre-established. This memory mapping table includes memory address information and attribute information corresponding to each memory region from the minimum physical address to the maximum physical address. When a user requests memory, the size of the requested memory can be determined according to the memory request. If, according to the memory mapping table, there is no single memory region whose size meets the memory request size, a set of contiguous target memory regions with a total size that meets the memory request size can be determined from the memory mapping table. Then, the mapping information corresponding to this set of target memory regions is returned to the user, thereby allocating a set of contiguous memory regions, reducing latency and improving system performance.
[0102] It should be noted that for peripheral devices that require dynamic memory allocation and deallocation, this increases memory mapping. If there are still changes in memory mapping relationships before and after the operating system loads, the exit boot service is loaded, and the EFI get memory map is called, it can lead to operating system loading failure and instability. Therefore, in this embodiment of the invention, when selecting a target memory region, it can first determine whether there is a memory region that has been allocated and released. If such a memory region exists, it can be selected as the target memory region for the current user. Since the allocated memory region already has corresponding mapping information, it can be reassigned to the current user after release without generating new mapping information (map key). This reduces changes in mapping information, which is beneficial for successful operating system loading and increases the robustness of the operating system startup.
[0103] Therefore, the method in the embodiments of the present invention may further include:
[0104] If there exists a single memory region whose memory size meets the memory request size and is available, then determine whether there exists a single memory region that has been allocated and then released within the single memory region whose memory size meets the memory request size;
[0105] If there exists a single memory region that has been allocated and then freed, then the single memory region whose size is closest to the memory request size is determined from the single memory region that has been allocated and then freed as the target memory region.
[0106] Obtain the historical mapping identifier of the target memory region and return the historical mapping identifier as mapping information;
[0107] If there is no single memory region that has been allocated and then freed, then the single memory region whose size is closest to the memory request size is determined from all single memory regions whose memory size meets the memory request size and is used as the target memory region.
[0108] Generate a new mapping identifier for the target memory region and return the mapping identifier as mapping information.
[0109] It should be noted that after identifying individual memory regions whose size is greater than or equal to the memory request size, it is possible to further determine whether any of these individual memory regions were previously allocated and have now been released. That is, if a single memory region was previously allocated, a corresponding historical mapping identifier (map key) has been generated, and it is currently released and in an available (idle) state. When individual memory regions that have been allocated and then released exist, the target memory region can be determined based on the memory size corresponding to each of these allocated and released regions. The historical mapping identifier (map key) of this target memory region is then returned to the BIOS side, thereby allocating the target memory region to the user. In this case, there is no need to change the map key, which facilitates smooth operating system loading and increases the robustness of the operating system startup.
[0110] If there is no allocated and then freed memory region within a single memory region whose memory size meets the memory request size, and these single memory regions have all been allocated individually, then from all available single memory regions whose memory size meets the memory request size, the single memory region whose memory size is closest to the memory request size can be identified as the target memory region. A new mapping identifier (map key) is generated for the target memory region, and the mapping identifier (map key) is returned to the BIOS side as mapping information. The BIOS side can then determine the physical address of the allocated target memory region based on the map key and perform user-based operations to store data in the target memory region.
[0111] In addition, after returning the mapping information of the target memory region, the attribute information corresponding to the target memory region in the memory mapping table can be updated in a timely manner. That is, the attribute information corresponding to the target memory region can be changed from available to unavailable, or from unused to allocated, so as to better manage memory.
[0112] In some embodiments of the present invention, the memory address information may include a start address and an end address; the memory status may be available, unavailable, used, released, or allocated, etc.
[0113] Therefore, the process in S130 above, which involves selecting multiple target memory regions from various memory regions based on the memory mapping table, whose total size meets the memory request size, are contiguous, and are available, may include:
[0114] Based on the attribute information corresponding to each memory region stored in the memory mapping table, the available memory regions are determined.
[0115] Based on the memory address information corresponding to each available memory region, groups of available memory regions with consecutive addresses are determined from each available memory region;
[0116] From each group of available memory regions with contiguous addresses, determine the total memory size corresponding to each group of available memory regions;
[0117] Based on the total memory size of each available memory region group, determine the target available memory region group whose total memory size satisfies the memory request size;
[0118] Each memory region in the target available memory region group is determined as a set of multiple target memory regions whose total size meets the memory request size, are contiguous, and are available.
[0119] It should be noted that, in this embodiment of the invention, when there is no single memory region whose memory size meets the memory request size and is available, the available memory regions with available memory status can be determined according to the memory status in the attribute information corresponding to each memory region in the memory mapping table. Then, the memory address information of each available memory region is obtained from the memory mapping table. According to the start position and end position corresponding to each available memory region, it can be determined which available memory regions are consecutive. Thus, the available memory regions with consecutive addresses can be determined. A group of available memory regions with consecutive addresses is called a group of available memory regions, thus obtaining multiple groups of available memory regions. The addresses of each available memory region in each group are consecutive.
[0120] After identifying the available memory region groups, for each group, the total memory size can be determined based on the memory size of each available memory region within that group. Then, a target available memory region group can be selected from those groups whose total memory size is greater than or equal to (i.e., satisfies) the memory request size. If there is only one target available memory region group, each available memory region in that group is directly used as the target memory region. If there are multiple target available memory region groups, the group whose total memory size is closest to the memory request size can be selected, and all available memory regions in that group are used as the target memory regions. This embodiment of the invention better ensures that the allocated memory is contiguous, which is beneficial for operating system performance.
[0121] It is understood that this embodiment of the invention also considers that dynamic memory allocation and release for peripheral devices would increase memory mapping. If there are still changes in memory mapping relationships before and after the operating system loads, the exit boot service is loaded, and EFIget memory map is called, it could lead to operating system loading failure and instability. Therefore, the process of determining the target available memory region group whose total memory size satisfies the memory allocation size based on the total memory size of each available memory region group can include:
[0122] First, we can identify the first available memory regions from each available memory region group whose total memory size is greater than or equal to the memory request size. Then, we can further determine whether there are second available memory regions in each first available memory region group that have been allocated and then released. That is, the second available memory region group was allocated as a whole and then released. Now the second available memory region group is in an idle and available state, and there is a corresponding historical mapping identifier map key.
[0123] If there exist multiple groups of second available memory regions that have been allocated and then released, then for each group, the total memory size of the group can be determined based on the memory size of each available memory region within it. Then, the group whose total memory size is closest to the requested memory size is selected as the target available memory region group. The historical mapping identifier corresponding to this target available memory region group is returned to the BIOS as mapping information for multiple target memory regions. This allows the BIOS to directly locate the corresponding memory regions for user data storage. Alternatively, if there is only one group of second available memory regions that has been allocated and then released, then that group can be directly selected as the target available memory region group.
[0124] In other words, in this case, the previous mapping information can be reused in the embodiments of the present invention without generating new mapping information map key, thereby reducing the changes in mapping information, which is conducive to the successful loading of the operating system and increasing the robustness of the operating system startup.
[0125] Additionally, if there is no second available memory region group that has been allocated and then released, then for each first available memory region group, the total memory size can be determined based on the memory size of each memory region in the first available memory region group. The first available memory region group whose total memory size is closest to the memory request size can be selected as the target available memory region group. In this case, a new mapping identifier can be generated for the target available memory region group, and this new mapping identifier can be returned to the BIOS side as mapping information for multiple target memory regions. This allows the BIOS side to directly locate the corresponding memory regions based on the historical mapping identifier for storing user data.
[0126] In some embodiments, the method may further include:
[0127] Get the user's memory release request;
[0128] The memory region to be released is determined based on the memory address and size in the memory release request;
[0129] Clear the data in the memory region to be released and update the attribute information corresponding to the memory region to be released in the memory mapping table.
[0130] It's important to note that when a user initiates a memory release request (i.e., free memory), GCD uses its built-in free memory service function to parse the request, obtaining the memory address and size to determine the memory region to be released. Essentially, the memory map corresponding to the memory being released is in an existing memory mapping table. Therefore, based on the memory address, the corresponding physical memory space can be found through the memory mapping table, the relevant data in that memory space can be cleared, and the memory status in the memory mapping region's attribute information can be changed to either available or released. This completes the release of the memory region, making it available for use by the GCD memory service when other users request memory again.
[0131] In some embodiments, the method may further include:
[0132] If the total memory size of each available memory region group is less than the memory request size, then the third available memory region group whose total memory size is closest to the memory request size is determined from each available memory region group.
[0133] Based on the difference between the memory request size and the total memory size of the third available memory region group, a single memory region whose memory size is greater than the difference and which is available is determined from each memory region;
[0134] Generate and return mapping information corresponding to the third group of available memory regions and a single memory region whose size is greater than the difference and is available.
[0135] It should be noted that in practical applications, there may be situations where the total memory size of each available memory region group is less than the memory request size. In this case, a third available memory region group can be identified from each available memory region group whose total memory size is closest to the memory request size. Obviously, the total memory size of this third available memory region group does not meet the memory request size. At this time, based on the difference between the memory request size and the total memory size of the third available memory region group, a single memory region with a memory size greater than the difference can be identified from other available single memory regions. This single memory region and the identified third available memory region group are merged as a whole and allocated to the user. At the same time, mapping information corresponding to this single memory region and the identified third available memory region group as a whole is generated and returned to the BIOS side. This embodiment of the invention can merge free memory regions, reduce memory fragmentation, and improve memory utilization.
[0136] In addition, the method may also include:
[0137] During the memory initialization phase, obtain the number of CPUs n on a single CPU, the number of CPUs cnt, the number of system root CPUs D, the memory capacity Sc of a single root CPU, and the reserved fixed memory capacity R.
[0138] The available memory capacity of the operating system is calculated based on the number of CPUs n on a single CPU, the number of CPUs cnt, the number of system root CPUs D, the memory capacity of a single root CPU Sc, and the reserved fixed memory capacity R.
[0139] Send the available memory capacity of the operating system to the operating system.
[0140] It should be noted that during memory initialization in the PEI stage, the maximum available memory function of the operating system can be used to read the SNC (Sub-NUMA Clustering, a technology used in computer systems to communicate with hardware devices) settings of the current operating system memory. When the SNC function is enabled, the specific value of the SNC is determined, as well as the number of CPUs (cnt) of the current operating system, the number of digits (n) on a single CPU (i.e., the number of SNCs is n), the number of system digits (D), the memory capacity of a single digit (Sc), and the reserved fixed memory capacity (R) (i.e., the fixed memory space reserved for the system). Then, the available memory capacity of the operating system is obtained based on these parameters.
[0141] In practical applications, the available memory capacity of the operating system can be calculated through the following process:
[0142] The total number of bands N is calculated based on the number of bands n on a single central processing unit and the number of central processing units cnt;
[0143] The number of interleavings I is calculated based on the number of root bands D in the system and the number of bands n on a single central processing unit;
[0144] The total physical memory T of the system is calculated based on the number of root bands D and the memory capacity Sc of a single root band.
[0145] The first ratio is obtained by dividing the difference between the total physical memory T of the system and the reserved fixed memory capacity R by the total number of modules N.
[0146] Divide the first ratio by the number of interleavings I to get the second ratio, and round the second ratio to get the physical memory capacity St on each die;
[0147] The third ratio of the physical memory capacity St of each band to the number of interleavings is rounded to obtain the memory capacity cm of the minimum block available area.
[0148] The available memory capacity of the operating system is calculated based on the memory capacity cm of the smallest block available region, the number of interleaving I, the number of interleavings on a single CPU n, and the number of CPUs cnt.
[0149] It is understandable that the total number of bands N can be obtained by multiplying the number of bands n on a single CPU by the number of CPUs cnt, i.e., n*cnt=N; the ratio of the number of system band roots D to the number of bands n on a single CPU is used as the interleaving quantity I, i.e., I=D / n; the total number of system band roots D is multiplied by the memory capacity Sc of a single band root to obtain the total physical memory T of the system, i.e., T=D*Sc; the memory capacity of the minimum block available area cm=[St / I], where St=[(TR) / N / I], where [] represents the rounding symbol.
[0150] Then, based on the relationship C = cm * I * n * cnt, the available memory capacity C of the operating system can be further calculated.
[0151] It should be noted that the available memory capacity C obtained after rounding by the above system is the maximum available memory that can be reported to the operating system in SNC mode. Using the above formula, the rounding value can be adjusted according to dynamically input variable parameters to ensure that the available memory reported to the operating system is the maximum value, thereby improving memory utilization.
[0152] It is understandable that this invention changes the traditional practice of non-contiguous memory addresses within 4GB in memory management. By planning the use of contiguous addresses from low address segments to high address segments, the memory service system obtains memory services from this invention when calling related memory allocation and release, and there is no problem of performance degradation in large memory space allocation caused by non-contiguous intermediate physical addresses.
[0153] Considering the current mainstream market's CPU architectures featuring Sub-NUMA Clustering (a technology used in computer systems for communicating with hardware devices), memory management loopholes exist when equally partitioning memory, leading to resource waste. NUMA (Non-Uniform Memory Access) is a technology used in multiprocessor systems where each processor has its own local memory, and accessing this local memory is faster than accessing the memory of other processors. This design helps improve the performance of multiprocessor systems, especially when handling large-scale parallel tasks.
[0154] In view of this, in this embodiment of the invention, the memory is re-segmented in the SNC scenario. By dividing the memory into blocks using SNC, the size of the smallest partition memory block is dynamically recalculated to find the greatest common divisor between the smallest memory block and the maximum memory capacity of the operating system. This allows for the adjustment of the operating system memory blocks, thereby enabling the operating system to obtain a larger available memory capacity.
[0155] It should also be noted that, in this embodiment of the invention, the FlashROM capacity, MMIO capacity, CPU PCIE root port capacity, and physical memory space to be occupied by the IO APIC can be determined in advance based on the physical configuration of the operating system. Based on the requirements of these resources, the physical memory address of the corresponding device is determined, forming a pre-compiled global physical address constant to be used. When SEC and PEI use and construct the memory attribute description table, the predefined constant physical address and related physical memory attribute information are passed to the HOB.
[0156] Additionally, for the operating system (OS), during loading, it can invoke the GCD memory management mapping service. That is, when the operating system begins loading, it can call the interface provided by the GCD memory management service to obtain the current memory mapping table. The operating system checks the memory mapping table to ensure that there are sufficient memory resources to support the normal operation of the system. If the memory mapping does not meet the requirements, the operating system will stop loading and display an error message, thus ensuring that the operating system can correctly acquire and use memory resources during loading.
[0157] It should also be noted that during the handover process between the BIOS and the operating system, the BIOS converts the physical address corresponding to each memory region in the memory mapping table into a virtual address, and then sends the converted memory mapping table to the operating system.
[0158] In other words, when the operating system calls the memory management mapping service again to obtain the latest memory mapping information, the BIOS converts each physical address in the memory mapping table into a virtual address, generates E820 memory information, and passes the generated E820 memory information to the operating system for its use. E820 is a memory description format under the x86 architecture, containing detailed information about memory regions.
[0159] The operating system parses the E820 memory information to determine the details of each memory region. Based on the information in the memory description table, the operating system can schedule memory resources, such as allocating the kernel memory, buffers, and caches required by the system. In other words, the operating system can allocate memory to different processes and tasks, ensuring that each process can obtain the memory resources it needs.
[0160] As can be seen, the present invention provides an efficient memory management mechanism that can dynamically adjust the memory mapping table during system startup and operation, reduce memory fragmentation, improve memory utilization, and thus ensure system stability and performance.
[0161] In addition, in the preliminary part of the peripheral device in this invention, the MMIO method will be used to initialize the device. The device option ROM will also be executed according to the memory base address space allocated to the device, thereby solving the problem of remapping the dependence on low memory to other available high memory address segments when loading traditional devices.
[0162] This invention also provides a corresponding apparatus for the memory allocation method, further enhancing the method's practicality. The apparatus can be described from both a functional module perspective and a hardware perspective. The memory allocation apparatus provided by this invention is described below. This apparatus is used to implement the memory allocation method provided by this invention. In this embodiment, the memory allocation apparatus may include or be divided into one or more program modules. These program modules are stored in a storage medium and executed by one or more processors to complete the memory allocation method disclosed in the above embodiments. The program module referred to in this invention is a series of computer program instruction segments capable of performing a specific function, and is more suitable than the program itself for describing the execution process of the memory allocation apparatus in the storage medium. The following description will specifically introduce the functions of each program module in this embodiment. The memory allocation apparatus described below corresponds to the memory allocation method described above.
[0163] From the perspective of functional modules, see Figure 7 , Figure 7 This invention provides a structural diagram of a memory allocation device, which may include:
[0164] The first determining module 11 is used to obtain the user's memory request and determine the memory request size based on the memory request.
[0165] The judgment module 12 is used to determine whether there is a single memory region whose memory size meets the memory request size based on a pre-established memory mapping table; wherein, the memory mapping table includes memory address information and attribute information corresponding to each memory region from the minimum physical address to the maximum physical address;
[0166] The filtering module 13 is used to filter out multiple target memory regions that are contiguous and available, whose total size meets the memory request size, from each memory region according to the memory mapping table if there is no single memory region whose memory size meets the memory request size.
[0167] Return module 14 is used to return mapping information for multiple target memory regions; wherein, the mapping information is used to determine the address information and size of the corresponding memory region.
[0168] In some embodiments, the device further includes:
[0169] The second determining module is used to determine the target memory region from the single memory region whose memory size meets the memory request size and is available if there exists a single memory region whose memory size meets the memory request size and is available, and return the mapping information of the target memory region.
[0170] In some embodiments, it also includes:
[0171] The first update module is used to update the attribute information corresponding to the target memory region in the memory mapping table;
[0172] Or, it also includes:
[0173] The second update module is used to update the attribute information corresponding to each of the multiple target memory regions in the memory mapping table.
[0174] In some embodiments, the second determining module includes:
[0175] The first determining unit is used to determine whether there is a single memory region that has been allocated and then freed within a single memory region whose memory size satisfies the memory request size.
[0176] The second determining unit is used to determine, if there is a single memory region that has been allocated and then released, the single memory region whose memory size is closest to the memory request size as the target memory region.
[0177] The first acquisition unit is used to acquire the historical mapping identifier of the target memory region and return the historical mapping identifier as mapping information;
[0178] The third determining unit is used to determine, if there is no single memory region that has been allocated and then freed, the single memory region whose memory size is closest to the memory request size from all available single memory regions whose memory size satisfies the memory request size, as the target memory region.
[0179] The first generation unit is used to generate a new mapping identifier for the target memory region and return the mapping identifier as mapping information.
[0180] In some embodiments, the memory address information includes a start address and an end address; the attribute information includes the memory status, which is available, unavailable, used, or released.
[0181] Therefore, the filtering module 13 includes:
[0182] The fourth determining unit is used to determine each available memory region based on the attribute information corresponding to each memory region stored in the memory mapping table.
[0183] The fifth determining unit is used to determine, based on the memory address information corresponding to each available memory region, groups of available memory regions with consecutive addresses from each available memory region.
[0184] The sixth determining unit is used to determine the total memory size corresponding to each available memory region group from the various available memory region groups with consecutive addresses;
[0185] The seventh determining unit is used to determine the target available memory region group whose total memory size satisfies the memory request size based on the total memory size of each available memory region group.
[0186] The eighth determining unit is used to determine each memory region in the target available memory region group as multiple target memory regions whose total size meets the memory request size, are contiguous, and are available.
[0187] In some embodiments, the seventh determining unit includes:
[0188] The first determining subunit is used to determine, from each available memory region group, each first available memory region group whose total memory size is greater than or equal to the memory request size;
[0189] The second determining subunit is used to determine whether there is a second available memory region group that has been allocated and then released in each first available memory region group;
[0190] The third determining subunit is used to, if there are groups of second available memory regions that have been allocated and then released, determine the group of second available memory regions whose memory size is closest to the memory request size as the target available memory region group; wherein, the returned mapping information of multiple target memory regions includes the historical mapping identifier of the target available memory region group; if there are no groups of second available memory regions that have been allocated and then released, determine the group of first available memory regions whose memory size is closest to the memory request size as the target available memory region group; wherein, the returned mapping information of multiple target memory regions includes the new mapping identifier generated for the target available memory region group.
[0191] In some embodiments, it also includes:
[0192] The acquisition module is used to acquire users' memory release requests;
[0193] The third determination module is used to determine the memory region to be released based on the memory address and size in the memory release request;
[0194] The cleanup module is used to clear the data in the memory region to be freed and update the attribute information corresponding to the memory region to be freed in the memory mapping table.
[0195] It should be noted that the memory allocation device provided in the embodiments of the present invention has the same beneficial effects as the memory allocation method provided in the above embodiments, and for a detailed description of the memory allocation method involved in the embodiments of the present invention, please refer to the above embodiments, which will not be repeated here.
[0196] The memory allocation device mentioned above is described from the perspective of a functional module. Furthermore, the present invention also provides an electronic device, which is described from the perspective of hardware. Figure 8 A structural diagram of an electronic device provided in an embodiment of the present invention, such as... Figure 8 As shown, the electronic device includes:
[0197] Memory 20 is used to store computer programs;
[0198] The processor 21 is used to implement the steps of the memory allocation method as described in the above embodiments when executing a computer program.
[0199] The electronic devices provided in this embodiment may include, but are not limited to, smartphones, tablets, laptops, or desktop computers.
[0200] The processor 21 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 21 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 21 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.
[0201] The memory 20 may include one or more computer-readable storage media, which may be non-transitory. The memory 20 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the memory 20 may be an internal storage unit of an electronic device, such as a server hard drive. In other embodiments, the memory 20 may be an external storage device of an electronic device, such as a plug-in hard drive on a server, a smart media card (SMC), a secure digital card (SD), a flash card, etc. Furthermore, the memory 20 may include both internal and external storage units of the electronic device. The memory 20 can be used not only to store application software and various types of data installed on the electronic device, such as code of a program executing a memory allocation method, but also to temporarily store data that has been output or will be output. In this embodiment, the memory 20 is used to store at least the following computer program 201, which, after being loaded and executed by the processor 21, is capable of implementing the relevant steps of the memory allocation method disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, and the storage method may be temporary storage or permanent storage. The operating system 202 may include Windows, Unix, Linux, etc. The data 203 may include, but is not limited to, data corresponding to the set memory allocation results.
[0202] In some embodiments, the electronic device may further include a display screen 22, an input / output interface 23, a communication interface 24, a power supply 25, and a communication bus 26. The display screen 22 and input / output interface 23, such as a keyboard, are user interfaces; optional user interfaces may also include standard wired interfaces, wireless interfaces, etc. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an OLED (Organic Light-Emitting Diode) touchscreen, etc. The display may also be appropriately referred to as a screen or display unit, used to display information processed in the electronic device and to display a visual user interface. The communication interface 24 may optionally include a wired interface and / or a wireless interface, such as a Wi-Fi interface, a Bluetooth interface, etc., typically used to establish communication connections between the electronic device and other electronic devices. The communication bus 26 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. This bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0203] Those skilled in the art will understand that Figure 8 The structures shown do not constitute a limitation on electronic devices and may include more or fewer components than those shown.
[0204] It is understood that if the memory allocation method in the above embodiments is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and executes all or part of the steps of the methods in the various embodiments of the present invention. The aforementioned storage medium includes: USB flash drive, mobile hard disk, read-only memory (ROM), random access memory (RAM), electrically erasable programmable ROM, register, hard disk, removable disk, CD-ROM, magnetic disk, or optical disk, and other media capable of storing program code.
[0205] Based on this, such as Figure 9As shown, this embodiment of the invention also provides a computer-readable storage medium 30, on which a computer program 31 is stored. When the computer program 31 is executed by a processor, it implements the steps of the memory allocation method described above.
[0206] Based on the above embodiments, this invention also provides a computer program product, including a computer program / instructions, which, when executed by a processor, implement the steps of the memory allocation method described above.
[0207] The foregoing has provided a detailed description of a memory allocation method, apparatus, electronic device, and computer-readable storage medium provided by embodiments of the present invention. The various embodiments are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.
[0208] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0209] The present invention has provided a detailed description of a memory allocation method, apparatus, electronic device, and computer-readable storage medium. Specific examples have been used to illustrate the principles and implementation methods of the invention. The descriptions of these embodiments are merely illustrative of the method and its core ideas. It should be noted that those skilled in the art can make various improvements and modifications to the invention without departing from its principles, and these improvements and modifications also fall within the scope of protection of the claims.
Claims
1. A memory allocation method, characterized by, include: Obtain the user's memory request and determine the memory request size based on the memory request; The existence of a single memory region whose size meets the memory request size and is available is determined based on a pre-established memory mapping table. The memory mapping table includes memory address information and attribute information corresponding to each memory region from the minimum physical address to the maximum physical address. An adjustable number of memory regions starting from the minimum physical address are unavailable reserved areas, which are used for device resource configuration. The initial state of other memory regions is available. The attribute information includes the current state of the memory. If there is no single memory region whose size meets the memory request size and is available, then multiple target memory regions whose total size meets the memory request size, are contiguous, and are available are selected from each memory region according to the memory mapping table. Returns mapping information for multiple target memory regions; wherein, the mapping information is used to determine the address information and size of the corresponding memory regions; wherein: It also includes: during the memory initialization phase, obtaining the number of CPUs n on a single CPU, the number of CPUs cnt, the number of system root CPUs D, the memory capacity Sc of a single root CPU, and the reserved fixed memory capacity R; The available memory capacity of the operating system is calculated based on the number of CPUs n on a single CPU, the number of CPUs cnt, the number of system root CPUs D, the memory capacity Sc of a single root CPU, and the reserved fixed memory capacity R. Send the available memory capacity of the operating system to the operating system; The available memory capacity of the operating system is calculated based on the number of CPUs n on a single CPU, the number of CPUs cnt, the number of system root CPUs D, the memory capacity Sc of a single root CPU, and the reserved fixed memory capacity R, including: The total number of bands N is calculated based on the number of bands n on the single central processing unit and the number of central processing units cnt; The number of interleaving I is calculated based on the number of root bands D in the system and the number of bands n on a single central processing unit; The total physical memory T of the system is calculated based on the number of system roots D and the memory capacity Sc of a single system root. The first ratio is obtained by dividing the difference between the total physical memory T of the system and the reserved fixed memory capacity R by the total number of modules N. Divide the first ratio by the number of interleavings I to obtain the second ratio, and round the second ratio to obtain the physical memory capacity St on each band; The memory capacity of the minimum block available area cm is obtained by taking the third ratio of the physical memory capacity St of each band to the number of interleavings. The available memory capacity of the operating system is calculated based on the memory capacity cm of the minimum block available region, the number of interleaving I, the number of CPUs n on a single CPU, and the number of CPUs cnt.
2. The memory allocation method according to claim 1, characterized in that, Also includes: If there exists a single memory region whose memory size meets the memory request size and is available, then determine whether there exists a single memory region that has been allocated and then released within the single memory region whose memory size meets the memory request size; If there exists a single memory region that has been allocated and then freed, then the single memory region whose size is closest to the memory request size is determined from the single memory region that has been allocated and then freed as the target memory region. Obtain the historical mapping identifier of the target memory region and return the historical mapping identifier as mapping information; If there is no single memory region that has been allocated and then freed, then the single memory region whose size is closest to the memory request size is determined from all single memory regions whose memory size meets the memory request size and is available, and is used as the target memory region. A new mapping identifier is generated for the target memory region, and the mapping identifier is returned as mapping information.
3. The memory allocation method according to claim 1, characterized in that, The memory address information includes a start address and an end address; the current state of the memory is either available, unavailable, used, or released. Then, multiple target memory regions that are selected from various memory regions according to the memory mapping table, whose total size meets the memory request size, are contiguous, and are available, include: Based on the attribute information corresponding to each memory region stored in the memory mapping table, the available memory regions are determined. Based on the memory address information corresponding to each available memory region, groups of available memory regions with consecutive addresses are determined from each available memory region; From each of the available memory region groups that are address-contiguous, determine the total memory size corresponding to each available memory region group; Based on the total memory size of each of the available memory region groups, a target available memory region group whose total memory size satisfies the memory request size is determined; Each memory region in the target available memory region group is determined as a plurality of target memory regions whose total size meets the memory request size, are contiguous, and are available.
4. The memory allocation method according to claim 3, characterized in that, The step of determining the target available memory region group whose total memory size satisfies the memory request size based on the total memory size of each of the available memory region groups includes: From each of the available memory region groups, identify the first available memory region groups whose total memory size is greater than or equal to the memory request size; Determine whether there is a second available memory region group that has been allocated and then released in each of the first available memory region groups; If there are groups of second available memory regions that have been allocated and then released, then the group of second available memory regions whose memory size is closest to the memory request size is determined as the target available memory region group; wherein, the returned mapping information of the multiple target memory regions includes the historical mapping identifier of the target available memory region group; if there are no groups of second available memory regions that have been allocated and then released, then the group of first available memory regions whose memory size is closest to the memory request size is determined as the target available memory region group; wherein, the returned mapping information of the multiple target memory regions includes the new mapping identifier generated for the target available memory region group.
5. The memory allocation method according to claim 1, characterized in that, Also includes: Get the user's memory release request; The memory region to be released is determined based on the memory address and size in the memory release request; Clear the data in the memory region to be released and update the attribute information corresponding to the memory region to be released in the memory mapping table.
6. A memory allocation device, characterized in that, include: The first determining module is used to obtain the user's memory request and determine the memory request size based on the memory request. The judgment module is used to determine, based on a pre-established memory mapping table, whether there exists a single memory region whose size meets the memory request size and is available; wherein, the memory mapping table includes memory address information and attribute information corresponding to each memory region from the minimum physical address to the maximum physical address, and an adjustable number of memory regions starting from the minimum physical address are unavailable reserved areas, which are used for device resource configuration, and the initial state of other memory regions is available, and the attribute information includes the current state of the memory; The filtering module is used to filter out multiple target memory regions that are available, whose total size meets the memory request size, are contiguous, and are available from each memory region according to the memory mapping table if there is no single memory region whose memory size meets the memory request size. The return module is used to return mapping information for multiple target memory regions; wherein, the mapping information is used to determine the address information and size of the corresponding memory regions; wherein: It also includes: during the memory initialization phase, obtaining the number of CPUs n on a single CPU, the number of CPUs cnt, the number of system root CPUs D, the memory capacity Sc of a single root CPU, and the reserved fixed memory capacity R; The available memory capacity of the operating system is calculated based on the number of CPUs n on a single CPU, the number of CPUs cnt, the number of system root CPUs D, the memory capacity Sc of a single root CPU, and the reserved fixed memory capacity R. Send the available memory capacity of the operating system to the operating system; The available memory capacity of the operating system is calculated based on the number of CPUs n on a single CPU, the number of CPUs cnt, the number of system root CPUs D, the memory capacity Sc of a single root CPU, and the reserved fixed memory capacity R, including: The total number of bands N is calculated based on the number of bands n on the single central processing unit and the number of central processing units cnt; The number of interleaving I is calculated based on the number of root bands D in the system and the number of bands n on a single central processing unit; The total physical memory T of the system is calculated based on the number of system roots D and the memory capacity Sc of a single system root. The first ratio is obtained by dividing the difference between the total physical memory T of the system and the reserved fixed memory capacity R by the total number of modules N. Divide the first ratio by the number of interleavings I to obtain the second ratio, and round the second ratio to obtain the physical memory capacity St on each band; The memory capacity of the minimum block available area cm is obtained by taking the third ratio of the physical memory capacity St of each band to the number of interleavings. The available memory capacity of the operating system is calculated based on the memory capacity cm of the minimum block available region, the number of interleaving I, the number of CPUs n on a single CPU, and the number of CPUs cnt.
7. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the memory allocation method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the memory allocation method as described in any one of claims 1 to 5.