Memory allocation method and device, electronic equipment and readable storage medium

By pre-establishing memory map tables and filtering continuous available memory areas, the problem of discontinuous memory allocation within 4GB is solved, efficient memory management is achieved, and system performance is improved.

CN119669105AActive Publication Date: 2025-03-21INSPUR SUZHOU INTELLIGENT TECH CO LTD

Patent Information

Application Number
CN202411748870.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-30
Publication Date
2025-03-21
Estimated Expiration
2044-11-30

AI Technical Summary

Technical Problem

When managing memory within 4GB, the prior art is difficult to ensure the continuity of memory allocation, resulting in delay loss and system performance degradation.

Method used

By pre-establishing a memory mapping table, determining the memory application size and filtering out multiple target memory areas that are continuous and available, returning the mapping information of these areas to achieve continuous memory allocation.

Benefits of technology

Reduces latency loss, improves system performance, and ensures continuity of large-block memory allocation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119669105A_ABST
    Figure CN119669105A_ABST
Patent Text Reader

Abstract

The invention discloses a memory allocation method and device, electronic equipment and a readable storage medium, which are applied to the technical field of computer services, and are used for solving the problems that system delay damage is relatively large and system performance is influenced in a memory allocation process, and the method comprises the following steps: acquiring a memory application request of a user, and determining a memory application size according to the memory application request; according to a pre-established memory mapping table, determining whether an available single memory area with the memory size meeting the memory application size exists or not; if a single memory area with the memory size meeting the memory application size and available does not exist, screening out a plurality of target memory areas which have the total size meeting the memory application size and are mutually continuous and available from the memory areas according to a memory mapping table; returning mapping information of the plurality of target memory regions; wherein the mapping information is used for determining address information and size of the corresponding memory area; the delay loss can be reduced, and the system performance can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer service technology, and in particular to a memory allocation method, device, electronic equipment and computer-readable storage medium. Background Art

[0002] With the continuous development of computer service technology, memory performance management and fragmentation management are becoming more and more important. At the basic level, when managing memory within 4GB, we still consider the various attributes of memory resources in the past CPU (Central Processing Unit) and operating system. Different resources need to be divided into corresponding areas in the memory, such as Figure 1 As shown in the figure, the physical address space occupied by memories of different attributes is dispersed, resulting in that the allocated memory may be discontinuous for large-block memory allocation requirements. Allocating memory across physical areas will cause latency loss, affecting system performance.

[0003] In view of this, how to improve the continuity of memory partitioning and enhance system performance has become a problem that technical personnel in this field need to solve. Summary of the invention

[0004] The purpose of the embodiments of the present invention is to provide a memory allocation method, device, electronic device and computer-readable storage medium, which can reduce delay loss and help improve system performance.

[0005] In order to solve the above technical problems, an embodiment of the present invention provides a memory allocation method, comprising:

[0006] Obtaining a memory application request from a user, and determining a memory application size according to the memory application request;

[0007] Determine whether there is a single available memory area whose memory size meets the memory application size according to a pre-established memory mapping table; wherein the memory mapping table includes memory address information and attribute information corresponding to each memory area from the minimum physical address to the maximum physical address, and an adjustable number of memory areas starting from the minimum physical address are unavailable reserved areas, the reserved areas are used for configuration of device resources, and the initial states of other memory areas are all available, and the attribute information includes the current state of the memory;

[0008] If there is no single available memory area whose memory size meets the memory application size, then select multiple target memory areas whose total size meets the memory application size, are continuous with each other and are available from various memory areas according to the memory mapping table;

[0009] Return mapping information of the plurality of target memory regions; wherein the mapping information is used to determine address information and size of corresponding memory regions.

[0010] In some embodiments, it also includes:

[0011] If there is a single memory area whose memory size meets the memory application size and is available, determining whether there is a single memory area that is allocated and then released in the single memory area whose memory size meets the memory application size;

[0012] If there is a single memory area that is released after being allocated, a single memory area whose memory size is closest to the memory application size is determined from the single memory areas that are released after being allocated as the target memory area;

[0013] Obtaining a historical mapping identifier of the target memory area, and returning the historical mapping identifier as mapping information;

[0014] If there is no single memory area that is released after being allocated, a single memory area whose memory size meets the memory application size and is available is determined as the target memory area;

[0015] A new mapping identifier is generated for the target memory area, 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 or unavailable or used or released;

[0017] Then, multiple target memory areas whose total size meets the memory application size, are continuous with each other and are available are screened out from each memory area according to the memory mapping table, including:

[0018] Determine each available memory area according to the attribute information corresponding to each memory area stored in the memory mapping table;

[0019] According to the memory address information corresponding to each of the available memory areas, determining each group of available memory areas with continuous addresses from each of the available memory areas;

[0020] Determining, from the available memory area groups with consecutive addresses, the total memory size corresponding to each available memory area group;

[0021] Determine, according to the total memory size of each of the available memory area groups, a target available memory area group whose total memory size satisfies the memory application size;

[0022] The memory areas in the target available memory area group are determined to be a plurality of target memory areas whose total size satisfies the memory application size, are continuous with each other and are available.

[0023] In some embodiments, determining a target available memory area group whose total memory size meets the memory application size according to the total memory size of each of the available memory area groups includes:

[0024] Determine, from each of the available memory area groups, respective first available memory area groups whose total memory size is greater than or equal to the memory application size;

[0025] Determine whether there is a second available memory area group that is allocated and then released in each of the first available memory area groups;

[0026] If there are second available memory area groups that are released after being allocated, a second available memory area group whose memory size is closest to the memory application size is determined from each of the second available memory area groups as the target available memory area group; wherein the returned mapping information of the multiple target memory areas includes a historical mapping identifier of the target available memory area group; if there is no second available memory area group that is released after being allocated, a first available memory area group whose memory size is closest to the memory application size is determined from each of the first available memory area groups as the target available memory area group; wherein the returned mapping information of the multiple target memory areas includes a new mapping identifier generated for the target available memory area group.

[0027] In some embodiments, it also includes:

[0028] Get the user's memory release request;

[0029] Determine the memory area to be released according to the memory address and size in the memory release request;

[0030] The data in the memory area to be released is cleared, and the attribute information corresponding to the memory area to be released in the memory mapping table is updated.

[0031] In some embodiments, it also includes:

[0032] In the memory initialization phase, the number of CPUs n, the number of CPUs cnt, the number of system root D, the memory capacity of a single root Sc, and the reserved fixed memory capacity R are obtained;

[0033] Calculate the available memory capacity of the operating system according to the number n of the single CPU, the number cnt of the CPU, the number D of the system root, the memory capacity Sc of the single root, and the reserved fixed memory capacity R;

[0034] The amount of memory available to the operating system is sent to the operating system.

[0035] In some embodiments, the available memory capacity of the operating system is calculated according to the number n of the single CPU, the number cnt of the CPU, the number D of the system root, the memory capacity Sc of the single root, and the reserved fixed memory capacity R, including:

[0036] Calculate the total number of bands N according to the number of bands n on the single CPU and the number of CPUs cnt;

[0037] Calculate the number of interleaving I according to the number of system band roots D and the number of bands on the single central processor n;

[0038] The total physical memory T of the system is calculated according to the number D of system root and the memory capacity Sc of a single root;

[0039] Dividing the difference between the total physical memory T of the system and the reserved fixed memory capacity R by the total number of bands N to obtain a first ratio;

[0040] Dividing the first ratio by the interleaving number I obtains a second ratio, and rounding the second ratio to obtain a physical memory capacity St on each band;

[0041] Round the third ratio of the physical memory capacity St on each band to the interleaving quantity to obtain the memory capacity cm of the minimum block available area;

[0042] The available memory capacity of the operating system is calculated based on the memory capacity cm of the minimum block available area, the interleaving number I, the number n of bands on the single central processing unit, and the number cnt of the central processing units.

[0043] Another aspect of the present invention further provides a memory allocation device, including:

[0044] A first determination module, configured to obtain a memory application request from a user and determine a memory application size according to the memory application request;

[0045] A judgment module, used to determine whether there is a single memory area whose memory size meets the memory application size and is available according to a pre-established memory mapping table; wherein the memory mapping table includes memory address information and attribute information corresponding to each memory area from the minimum physical address to the maximum physical address;

[0046] A screening module is used for screening multiple target memory areas whose total size meets the memory application size, are continuous with each other and are available from various memory areas according to a memory mapping table if there is no single memory area whose memory size meets the memory application size and is available;

[0047] The return module is used to return mapping information of multiple target memory areas; wherein the mapping information is used to determine the address information and size of the corresponding memory area.

[0048] Another aspect of the present invention provides an electronic device, including:

[0049] Memory for storing computer programs;

[0050] A processor is used to execute the computer program to implement the steps of the memory allocation method as described above.

[0051] Another aspect of the embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the memory allocation method described above are implemented.

[0052] It can be seen from the above technical solution that the beneficial effects of the present invention are:

[0053] The embodiment of the present invention provides a memory allocation method, comprising: obtaining a user's memory application request, determining a memory application size according to the memory application request; determining whether there is a single memory area whose memory size meets the memory application size and is available according to a pre-established memory mapping table; wherein the memory mapping table includes memory address information and attribute information corresponding to each memory area from the minimum physical address to the maximum physical address, and an adjustable number of memory areas starting from the minimum physical address are unavailable reserved areas, the reserved areas are used for the configuration of device resources, and the initial states of other memory areas are all available, and the attribute information includes the current state of the memory; if there is no single memory area whose memory size meets the memory application size and is available, then screening out multiple target memory areas whose total size meets the memory application size, are mutually continuous and available from each memory area according to the memory mapping table; returning mapping information of multiple target memory areas; wherein the mapping information is used to determine the address information and size of the corresponding memory area.

[0054] It can be seen that in the embodiment of the present invention, a memory mapping table is pre-established, and an adjustable number of memory areas starting from the minimum physical address in the memory mapping table are reserved areas for device resource configuration, so that the reserved area addresses can be continuous, and the initial states of other memory areas are all available, so that the initially available memory addresses can be continuous. When a user applies for memory, the memory application size applied for can be determined according to the memory application request, and when it is determined according to the memory mapping table that there is no single memory area in each memory area whose memory size meets the memory application size and is available, a group of target memory areas with continuous addresses and a total size that meets the memory size application and are available can be determined from the memory mapping table, and then the mapping information corresponding to this group of target memory areas is returned to the user, so that a group of memories with continuous addresses can be allocated, thereby reducing delay losses and helping to improve system performance.

[0055] In addition, the present invention also provides a corresponding implementation device, electronic device and computer-readable storage medium for the memory allocation method, which further makes the method more practical, and the device, electronic device and computer-readable storage medium have corresponding advantages. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0057] Figure 1 A 4G memory mapping schematic diagram in the related art;

[0058] Figure 2 A schematic diagram of a memory allocation process in the related art;

[0059] Figure 3 A memory classification relationship format diagram in the related art;

[0060] Figure 4 A flowchart of a memory allocation method provided by an embodiment of the present invention;

[0061] Figure 5 A schematic diagram of a flow chart of another memory allocation method provided by an embodiment of the present invention;

[0062] Figure 6 A memory mapping representation diagram provided for an embodiment of the present invention;

[0063] Figure 7 A schematic diagram of the structure of a memory allocation device provided by an embodiment of the present invention;

[0064] Figure 8 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention;

[0065] Fig. 9 A schematic diagram of the structure of a computer-readable storage medium provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0066] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0067] The terms "including" and "having" in the specification of the present invention and the above-mentioned drawings, as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device including a series of steps or units is not limited to the listed steps or units, but may include steps or units that are not listed.

[0068] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0069] It should be noted that when managing memory, for the basic level, when managing memory within 4GB, it is still considered to be compatible with the memory resources and interrupts, display devices, FLASH ROM (also known as the fast erase read-only programmer) and other attributes of the past CPU and operating system within the 4GB address space. When forming a memory resource description in the BIOS (Basic Input Output System) PEI (Pre-EFI Initialization, pre-EFI (Extensible Firmware Interface) initialization) stage, the resources occupied by the traditional CPU and equipment are planned in advance; in the DXE (Driver Execution Environment) stage, through the GCD (Global Coherency Domain, a group of processors and memory controllers) memory service management, it is uniformly classified and managed as a basic memory service for BIOS to call. This memory allocation process that is compatible with traditional PCH (Platform Controller Hub) devices and traditional OS (Operating System) is as follows Figure 2 As shown, the constructed 4G memory mapping table is as follows Figure 1 shown.

[0070] When building a 4G memory mapping table, the memory address segment from 0x00 to 0x500 and the area from 0xA0000 to 0xFFFF will be reserved in the 1M space for display, onboard device option rom loading and running, and reserved access to FLASH ROM; the top 4GB space still reserves MMIO (Memory-mapped I / O) space, IOAPIC (Advanced Programmable Interrupt Controller), CPU (Central Processing Unit) Root Port PCIE (peripheral component interconnect express) device space, and FLASH ROM space.

[0071] In the PEI stage, the occupied space of different physical memory addresses is obtained, and the HOB (Hand-OffBlock, a data used for handover) memory resource description table is collected; in the early stage of DXE, the basic GCD memory management service can be created, and the resources delivered by HOB are classified and managed according to the properties of the physical memory segment and the space occupied. The format is as follows Figure 3 shown.

[0072] In the traditional memory management process, GCD can provide basic management services for the memory request release initiated by BIOS through the following function interfaces:

[0073] AddMemorySpace();

[0074] AllocateMemorySpace();

[0075] FreeMemorySpace();

[0076] RemoveMemorySpace();

[0077] ·SetMemorySpaceAttributes();

[0078] ·SetMemorySpaceCapabilities().

[0079] BIOS usually uses the following functions in bootservice (system service) to request the release of 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 is loaded, 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 a management table of different types of memory attributes for the kernel and system application layer to call.

[0087] The traditional memory management method mentioned above is difficult to adapt to the development of current mainstream server systems. The compatible management of traditional memory within 4GB will cause the physical address space occupied by memories of different attributes to be dispersed, resulting in the allocated memory may be discontinuous for large-block memory allocation requirements. The allocation of memory across physical areas will cause delay losses, affecting system performance.

[0088] In addition, considering that the devices in the current mainstream market already fully support the UEFI architecture, the resources reserved in the low memory segment are not consumed. Instead, the MMIO method is directly adopted to provide the device with memory space for initialization and service calls. Therefore, most of the memory reserved in 4GB is idle and unused, resulting in a waste of resources.

[0089] In view of this, an embodiment of the present invention provides a memory allocation method that can adapt to the development of current mainstream servers. The method abandons the methods of low-address memory management services and interrupt management services of traditional CPU and OS, improves the problem of discontinuous memory management of 4GB top MMIO and Flash ROM, and makes memory allocation management more optimized.

[0090] Next, a memory allocation provided by an embodiment of the present invention is described in detail. Figure 4A flowchart of a memory allocation method provided by an embodiment of the present invention, the method comprising:

[0091] S110: Obtain a memory application request from a user, and determine a memory application size according to the memory application request;

[0092] It should be noted that the method in the embodiment of the present invention can be applied to the GCD memory management service, and the memory allocation function allocate memory() service and the free memory service function can be pre-established. During the operating system startup phase, the user can send a memory application request to the GCD memory management service through the BIOS, and the memory application request includes the memory application size (or memory application capacity), and the memory application request can include allocate pages (allocate physical pages) or allocate pool (allocate memory pool). After the GCD memory management service receives the memory application request sent by the BIOS, it can determine the required memory size according to the memory application request, that is, determine the memory application size.

[0093] S120: Determine whether there is a single memory area whose memory size meets the memory application size and is available according to a pre-established memory mapping table; wherein the memory mapping table includes memory address information and attribute information corresponding to each memory area from the minimum physical address to the maximum physical address, and an adjustable number of memory areas starting from the minimum physical address are unavailable reserved areas, the reserved areas are used for configuration of device resources, and the initial states of other memory areas are all available, and the attribute information includes the current state of the memory;

[0094] In the embodiment of the present invention, a memory mapping table is pre-established. After determining the memory application request and the memory application size, the memory size corresponding to each memory area can be further determined based on the memory address information and attribute information corresponding to each memory area stored in the memory mapping table, so as to determine whether there is a single memory area that meets the memory application size (that is, the memory is greater than or equal to the memory application size) and is available, wherein available in the embodiment of the present invention means that the memory area is not used or allocated.

[0095] Please note that, please refer to Figure 5 and Figure 6In the embodiment of the present invention, a memory mapping table is pre-established. During the establishment process, the memory mapping table can be initialized first. The process can start with the minimum physical address (i.e., the low physical address) of the memory to construct an initial memory mapping table. The memory address information and attribute information of each memory area (i.e., the physical address segment) are recorded through the initial memory mapping table, wherein the memory address information may include the starting address and the ending address, and the attribute information may include available or unavailable or used or released, unused, etc. The attribute information is used to indicate the state of a memory area. Then, the entire physical memory (e.g., the physical memory within the range of 4GB) is traversed, and the starting address, the ending address, and the attribute information corresponding to each memory area are identified and recorded and filled back into the initial memory mapping table. After traversing all the memory areas, a constructed physical memory mapping table is obtained. Each memory area in the memory mapping table is arranged in order from the first to the highest, and an adjustable number of memory areas starting from the minimum physical address are determined as unavailable reserved areas. The reserved areas can be used for the configuration of device resources. The initial states of other memory areas except the reserved areas are all available. After the memory allocation is performed based on the memory mapping table, the states of the corresponding memory areas will change. Figure 5 In the memory mapping table shown, some memory areas at low addresses can be reserved in advance for configuration of different device resources.

[0096] S130: If there is no single available memory area whose memory size meets the memory application size, multiple target memory areas whose total size meets the memory application size, are continuous with each other and are available are screened from various memory areas according to the memory mapping table;

[0097] It is understandable that if there is no single memory area in the memory areas whose memory size meets the memory application size and is available, then the available and mutually continuous memory areas can be further determined from the memory mapping table, that is, several unused continuous memory areas can be determined, so that multiple groups of continuous memory areas can be determined. According to the total memory size of each group of continuous memory areas, a group of continuous and available memory areas with a total memory size greater than or equal to the memory application size are screened out, and these memory areas are used as target memory areas.

[0098] S140: Return mapping information of multiple target memory areas; wherein the mapping information is used to determine address information and size of corresponding memory areas.

[0099] It should be noted that after determining multiple target memory areas whose total size meets the memory application size, are continuous and available, corresponding mapping information can be generated according to the memory address information corresponding to each target memory area in the memory mapping table, and the mapping information can be returned to the BIOS. The BIOS determines the location of the allocated memory based on the mapping information and stores the user's data in the corresponding memory. Since the physical addresses of the allocated memory areas in the present invention are continuous and not allocated across physical areas, delay losses can be effectively avoided, which is beneficial to the performance of memory performance.

[0100] In addition, after returning the mapping information of multiple target memory areas as mentioned above, the attribute information corresponding to each of the multiple target memory areas in the memory mapping table can be updated in a timely manner, that is, the attribute information corresponding to the target memory area is changed from available to unavailable, or from unused to allocated, so as to better manage the memory.

[0101] It can be seen that in the embodiment of the present invention, a memory mapping table is pre-established, and the memory mapping table includes memory address information and attribute information corresponding to each memory area from the minimum physical address to the maximum physical address. When a user applies for memory, the memory application size applied for can be determined according to the memory application request, and when it is determined according to the memory mapping table that there is no single memory area in each memory area whose memory size meets the memory application size, a group of target memory areas with continuous addresses and a total size that meets the memory size application and are available can be determined from the memory mapping table, and then the mapping information corresponding to this group of target memory areas is returned to the user, so that a group of memory with continuous addresses can be allocated, thereby reducing delay loss and helping to improve system performance.

[0102] It should be noted that for peripheral devices that require dynamic memory application and release, the memory mapping will increase. When the operating system is loaded, the exit boot service is loaded, and the EFI get memory map is called, if there are still changes in the memory mapping relationship, the operating system loading will fail, causing the problem of unstable operating system. In view of this, in the embodiment of the present invention, when selecting the target memory area, it can first determine whether there is an allocated and released memory area. If such a memory area exists, the allocated and released memory area that meets the requirements can be selected as the target memory area and allocated to the current user. Since the corresponding mapping information has been generated for the allocated memory area, it can be reallocated to the current user after it is released without generating a new mapping information map key again, thereby reducing the change of mapping information, facilitating the successful loading of the operating system, and increasing the robustness of the operating system startup.

[0103] In view of this, the method in the embodiment of the present invention may further include:

[0104] If there is a single memory area whose memory size meets the memory application size and is available, determining whether there is a single memory area that is allocated and then released in the single memory area whose memory size meets the memory application size;

[0105] If there is a single memory area that is allocated and then released, a single memory area whose memory size is closest to the memory application size is determined from the single memory areas that are allocated and then released as the target memory area;

[0106] Get the historical mapping identifier of the target memory area, and return the historical mapping identifier as mapping information;

[0107] If there is no single memory area that is released after being allocated, a single memory area whose memory size meets the memory application size is determined as the target memory area from among all single memory areas whose memory sizes meet the memory application size;

[0108] Generates a new mapping identifier for the target memory area and returns the mapping identifier as mapping information.

[0109] It should be noted that after determining the memory size of each single memory area that is greater than or equal to the memory application size, it can be further determined whether there is a single memory area that has been previously allocated and is now released among these single memory areas, that is, the single memory area has been allocated before, and a historical mapping identifier map key corresponding to it has been generated, and the current single memory area has been released and is in an available (free) state. When there are individual memory areas that are allocated and then released, it is possible to further determine a single memory area whose memory size is closest to the memory application size as the target memory area based on the memory sizes corresponding to each of these individual memory areas that are allocated and then released, and return the historical mapping identifier map key of the target memory area to the BIOS side, so that the target memory area is allocated to the user. At this time, there is no need to change the map key, which is conducive to the smooth loading of the operating system and to increasing the robustness of the operating system startup.

[0110] In the case that there is no single memory area that is allocated and then released in the single memory area whose memory size meets the memory application size, it is indicated that these single memory areas have been allocated separately. At this time, a single memory area with a memory size closest to the memory application size can be determined as the target memory area from all the single memory areas whose memory sizes meet the memory application size and are available, and a new mapping identifier map key is generated for the target memory area, and the mapping identifier map key is returned to the BIOS side as mapping information, so that the BIOS side determines the physical address of the allocated target memory area according to the map key and stores the data in the target memory area based on the user operation.

[0111] In addition, after returning the mapping information of the target memory area, the attribute information corresponding to the target memory area in the memory mapping table can be updated in time, that is, the attribute information corresponding to the target memory area can be changed from available to unavailable, or from unused to allocated, so as to better manage the memory.

[0112] In some embodiments, the memory address information in the embodiments of the present invention may include a start address and an end address; the memory status may be available or unavailable or used or released or allocated, etc.;

[0113] Then, the process of selecting multiple target memory areas whose total size meets the memory application size, are continuous with each other and are available from each memory area according to the memory mapping table in S130 may include:

[0114] Determine available memory areas according to the attribute information corresponding to each memory area stored in the memory mapping table;

[0115] According to the memory address information corresponding to each available memory area, each available memory area group with continuous addresses is determined from each available memory area;

[0116] Determine the total memory size corresponding to each available memory area group from each available memory area group with consecutive addresses;

[0117] According to the total memory size of each available memory area group, determine the target available memory area group whose total memory size meets the memory application size;

[0118] The memory areas in the target available memory area group are determined to be a plurality of target memory areas whose total size satisfies the memory application size, are continuous with each other and are available.

[0119] It should be noted that, in the embodiment of the present invention, when there is no single memory area whose memory size meets the memory application size and is available, the available memory areas whose memory status is available can be determined according to the memory status in the attribute information corresponding to each memory area in the memory mapping table, and then the memory address information of each available memory area is obtained from the memory mapping table. According to the starting position and end position corresponding to each available memory area, it can be determined which available memory areas are continuous, thereby determining the available memory areas with continuous addresses, wherein a group of available memory areas with continuous addresses is taken as an available memory area group, thereby obtaining multiple available memory area groups, and the addresses of each available memory area in each group are continuous.

[0120] After determining each available memory area group, for each available memory area group, the total memory size of the available memory area group can be determined according to the memory size corresponding to each available memory area in the available memory area group, so that a target available memory area group whose total memory size is greater than or equal to (that is, satisfies) the memory application size can be obtained from each available memory area group. When there is one target available memory area group, each available memory area in the target available memory area group is directly used as each target memory area. In the case where there are multiple target available memory area groups, a target available memory area group whose total memory size is closest to the memory application size can be selected from each target available memory area group, and each available memory area in the target available memory area group is used as each target memory area. The embodiment of the present invention can better ensure that the allocated memory is a continuous address, which is beneficial to the performance of the operating system.

[0121] It is understandable that the embodiments of the present invention also take into account that the need for dynamic memory application and release for peripheral devices will increase the memory mapping. When the operating system is loaded, the exit boot service is loaded, and the EFIget memory map is called, if there are still changes in the memory mapping relationship, the operating system loading will fail, causing the problem of unstable operating system. In view of this, the above process of determining the target available memory area group whose total memory size meets the memory application size based on the total memory size of each available memory area group can include:

[0122] First, each first available memory area group whose total memory size is greater than or equal to the memory application size can be determined from each available memory area group; then, it is further determined whether there is a second available memory area group that is allocated and then released in each first available memory area group, that is, the second available memory area group is allocated as a whole and then released, and now the second available memory area group is in an idle and available state, and there is a historical mapping identifier map key corresponding to it.

[0123] If there are second available memory area groups that are released after being allocated, then for each second available memory area group, the total memory size of the second available memory area group can be determined according to the memory sizes corresponding to the respective available memory areas in the second available memory area group, and then a second available memory area group whose total memory size is closest to the memory application size is determined from the second available memory area groups as the target available memory area group, and the historical mapping identifier corresponding to the target available memory area group is returned to the BIOS side as the mapping information of the multiple target memory areas, so that the BIOS side can directly locate the corresponding memory areas according to the historical mapping identifier for storing user data. Of course, if there is only one second available memory area group that is released after being allocated, then the second available memory area group can be directly determined as the target available memory area group.

[0124] That is, in this case, the embodiment of the present invention can reuse the previous mapping information without generating new mapping information map key, thereby reducing the change of mapping information, facilitating the successful loading of the operating system, and increasing the robustness of the operating system startup.

[0125] In addition, if there is no second available memory area group that is released after allocation, then for each first available memory area group, the total memory size can be determined according to the memory size of each memory area in the first available memory area group, and a first available memory area group whose total memory size is closest to the memory application size is determined from each first available memory area group as the target available memory area group. In this case, a new mapping identifier can be generated for the target available memory area group, and the new mapping identifier can be returned to the BIOS side as mapping information of multiple target memory areas, so that the BIOS side can directly locate the corresponding memory areas according to 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] Determine the memory area to be released according to the memory address and size in the memory release request;

[0129] The data in the memory area to be released is cleared, and the attribute information corresponding to the memory area to be released in the memory mapping table is updated.

[0130] It should be noted that when a user initiates a memory release request (free memory), GCD parses the free memory that the user wants to initiate through the constructed free memory service function, obtains the memory address and size in the memory release request, and determines the memory area to be released. It can be understood that the memorymap corresponding to the memory released by the user is in the existing memory mapping table, so the corresponding physical address memory space can be found through the memory mapping table according to the memory address, and the relevant data of the corresponding memory space can be cleared, and then the memory state in the attribute information of the memory mapping area corresponding to the memory area is changed to an available state or a released state, thereby completing the release of the memory area, so that when other users apply for memory again, this memory area can be recognized and used by the GCD memory service.

[0131] In some embodiments, the method may further include:

[0132] When it is determined that the total memory size of each available memory area group is smaller than the memory application size according to the total memory size of each available memory area group, a third available memory area group having a total memory size closest to the memory application size is determined from each available memory area group;

[0133] According to the difference between the memory application size and the total memory size of the third available memory area group, determining from each memory area a single memory area whose memory size is greater than the difference and is available;

[0134] Mapping information corresponding to the third available memory area group and a single memory area whose memory size is greater than the difference value and is available is generated and returned.

[0135] It should be noted that in actual applications, there may be a situation where the total memory size of each available memory area group is smaller than the memory application size. In this case, a third available memory area group whose total memory size is closest to the memory application size can be determined from each available memory area group. Obviously, the total memory size of the third available memory area group does not meet the memory application size. At this time, according to the difference between the memory application size and the total memory size of the third available memory area group, a single memory area whose memory size is larger than the difference can be determined from other available single memory areas, and the single memory area and the determined third available memory area group are merged and allocated to the user as a whole. At the same time, mapping information corresponding to the single memory area and the determined third available memory area group as a whole is generated, and the mapping information is returned to the BIOS side. The embodiment of the present invention can merge free memory areas, reduce memory fragmentation, and improve memory utilization.

[0136] Additionally, the method may further include:

[0137] In the memory initialization phase, the number of CPUs n, the number of CPUs cnt, the number of system root D, the memory capacity of a single root Sc, and the reserved fixed memory capacity R are obtained;

[0138] The available memory capacity of the operating system is calculated based on the number of CPUs n, the number of CPUs cnt, the number of system roots D, the memory capacity of a single root Sc, and the reserved fixed memory capacity R;

[0139] Sends the amount of available memory to the operating system.

[0140] It should be noted that when the memory is initialized in the PEI stage, the SNC (Sub-NUMA Clustering, a technology used to communicate with hardware devices in computer systems) setting of the current operating system memory can be read through the constructed operating system maximum available memory function. When the SNC function is turned on, the specific value of the SNC setting, as well as the number of central processing units CPU cnt of the current operating system, the number of bands on a single central processing unit n (that is, the number of SNCs is n), the number of system band (Dimm) roots D, the memory capacity of a single band root Sc and the reserved fixed memory capacity R (that is, the fixed memory space reserved for the system) are determined, and 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] According to the number of bands n on a single CPU and the number of CPUs cnt, the total number of bands N is calculated;

[0143] According to the number of system band roots D and the number of bands on a single CPU n, the number of interleavings I is calculated;

[0144] The total physical memory T of the system is calculated based on the number of system root disks D and the memory capacity of a single root disk Sc.

[0145] Divide the difference between the total physical memory T of the system and the reserved fixed memory capacity R by the total number of bands N to obtain a first ratio;

[0146] The first ratio is divided by the interleaving number I to obtain a second ratio, and the second ratio is rounded to an integer to obtain the physical memory capacity St on each Die;

[0147] Round the third ratio of the physical memory capacity St on each band to the number of interleavings 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 area, the number of interleaving I, the number n of bands on a single CPU, and the number cnt of CPUs.

[0149] It can be understood that the total number of bands N can be obtained by multiplying the number of bands n on a single central processing unit and the number of central processing units cnt, that is, n*cnt=N; the ratio of the number of system band roots D and the number of bands n on a single central processing unit is used as the interleaving number I, that is, I=D / n; the number of system band roots D and the memory capacity Sc of a single band root are multiplied to obtain the total physical memory T of the system, that is, 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] According to 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 finally obtained through the above system rounding is the maximum available memory that can be reported to the operating system in SNC mode. Through the above formula, according to the dynamically input variable parameters, the rounding value can be adjusted to make the available memory reported to the operating system the maximum value, thereby improving the memory utilization rate.

[0152] It can be understood that the present invention changes the traditional practice of discontinuous memory addresses within 4GB in memory management. By planning the use of continuous addresses from low address segments to high address segments, the memory service system, when calling related memory allocation and release, obtains memory services from the present invention, which are all memories of continuous address segments. There is no problem of decreased performance in allocating large memory spaces due to discontinuous intermediate physical addresses.

[0153] Considering the CPU architecture with SNC (Sub-NUMA Clustering, a technology used to communicate with hardware devices in computer systems) in the current mainstream market, there are also memory management loopholes when dividing the memory into equal areas, resulting in resource waste. Among them, NUMA (Non-Uniform Memory Access) is a technology used in multi-processor systems. In the NUMA architecture, each processor has its own local memory, and accessing these local memories is faster than accessing the memory of other processors. This design helps to improve the performance of multi-processor systems, especially when dealing with large-scale parallel tasks.

[0154] In view of this, in an embodiment of the present invention, by re-dividing the memory in the SNC scenario, the memory block size of the smallest partition is dynamically recalculated through SNC cutting, and the greatest common divisor between the smallest memory block and the maximum memory capacity of the operating system is found to adjust the memory block of the operating system, so that a larger available memory capacity can be obtained under the operating system.

[0155] It should also be noted that, in the embodiment of the present invention, the FlashROM capacity, MMIO capacity, CPU PCIEroot port capacity and physical memory space to be occupied by the IO APIC can be determined in advance according to the physical configuration of the operating system, and the physical memory address of the corresponding device can be determined according to the demand for these resources to form a global physical address constant to be used in pre-compilation. When the SEC and PEI use and construct the memory attribute description table, the pre-defined constant physical address and information such as the attributes of the relevant physical memory are passed to the HOB.

[0156] In addition, for the OS, the GCD memory management mapping service can be called when the OS is loaded. That is, when the OS starts loading, the interface provided by the GCD memory management service can be called to obtain the current memory mapping table. The OS checks the memory mapping table to ensure that there are enough memory resources to support the normal operation of the system. If the memory mapping does not meet the requirements, the OS will stop loading and prompt an error message, thereby ensuring that the OS can correctly obtain and use memory resources when loading.

[0157] It should also be noted that, during the interface between the BIOS and the operating system, the BIOS converts the physical address corresponding to each memory area in the memory mapping table into a virtual address, and sends the memory mapping table with the converted address to the operating system.

[0158] That is, 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. Among them, E820 is a memory description format under the x86 architecture, which contains detailed information about the memory area.

[0159] The operating system parses the E820 memory information and determines the details of each memory area. The operating system can schedule memory resources based on the information in the memory description table, such as allocating the core memory, buffer, cache, etc. required by the system. In other words, the operating system can allocate memory to different processes and tasks to ensure that each process can obtain the required memory resources.

[0160] It can be seen that the present invention provides an efficient memory management mechanism, which can dynamically adjust the memory mapping table during system startup and operation, reduce memory fragmentation, and improve memory utilization, thereby ensuring system stability and performance.

[0161] In addition, the present invention involves the initialization of peripheral devices, which will use MMIO to initialize the device, and the device option rom will be executed, and will also be loaded and run according to the memory base address space allocated to the device, thereby solving the problem of traditional devices relying on low-end memory when loading and remapping it to other available high-end memory address segments.

[0162] The present invention also provides a corresponding device for the memory allocation method, which further makes the method more practical. Among them, the device can be described from the perspective of functional modules and hardware. The memory allocation device provided by the present invention is introduced below. The device is used to implement the memory allocation method provided by the present invention. In this embodiment, the memory allocation device may include or be divided into one or more program modules, and the one or more 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 embodiment. The program module referred to in the present invention refers to a series of computer program instruction segments that can complete specific functions, which is more suitable for describing the execution process of the memory allocation device in the storage medium than the program itself. The following description will specifically introduce the functions of each program module in this embodiment. The memory allocation device described below and the memory allocation method described above can be referenced to each other.

[0163] From the perspective of functional modules, see Figure 7 , Figure 7 A structural diagram of a memory allocation device provided by the present invention, the device may include:

[0164] A first determining module 11 is used to obtain a memory application request from a user and determine a memory application size according to the memory application request;

[0165] The judgment module 12 is used to determine whether there is a single memory area whose memory size meets the memory application size according to a pre-established memory mapping table; wherein the memory mapping table includes memory address information and attribute information corresponding to each memory area from the minimum physical address to the maximum physical address;

[0166] A screening module 13 is used for screening multiple target memory areas whose total size meets the memory application size, are continuous with each other and are available from various memory areas according to a memory mapping table if there is no single memory area whose memory size meets the memory application size;

[0167] The return module 14 is used to return mapping information of multiple target memory areas; wherein the mapping information is used to determine the address information and size of the corresponding memory area.

[0168] In some embodiments, the apparatus further comprises:

[0169] The second determination module is used to determine the target memory area from the single memory area whose memory size meets the memory application size and is available, and return mapping information of the target memory area if there is a single memory area whose memory size meets the memory application size and is available.

[0170] In some embodiments, it also includes:

[0171] A first updating module, used for updating the attribute information corresponding to the target memory area in the memory mapping table;

[0172] or, also include:

[0173] The second updating module is used to update the attribute information corresponding to each of the multiple target memory areas in the memory mapping table.

[0174] In some embodiments, the second determining module includes:

[0175] A first determining unit is used to determine whether there is a single memory area that is released after being allocated in a single memory area whose memory size meets the memory application size;

[0176] A second determining unit is used for determining, if there is a single memory area released after being allocated, a single memory area whose memory size is closest to the memory application size from the single memory areas released after being allocated as the target memory area;

[0177] A first acquisition unit is used to acquire a historical mapping identifier of a target memory area and return the historical mapping identifier as mapping information;

[0178] A third determining unit is used for determining, if there is no single memory area that is released after being allocated, a single memory area whose memory size meets the memory application size and is available, as a target memory area.

[0179] The first generating unit is used to generate a new mapping identifier for the target memory area 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 a memory state, the memory state being available or unavailable or used or released;

[0181] Then, the screening module 13 includes:

[0182] A fourth determining unit, configured to determine each available memory area according to the attribute information corresponding to each memory area stored in the memory mapping table;

[0183] a fifth determining unit, configured to determine, from each available memory area, groups of available memory areas having consecutive addresses according to memory address information corresponding to each available memory area;

[0184] a sixth determining unit, configured to determine, from each available memory area group having consecutive addresses, a total memory size corresponding to each available memory area group;

[0185] A seventh determining unit, configured to determine a target available memory area group whose total memory size satisfies the memory application size according to the total memory size of each available memory area group;

[0186] The eighth determining unit is used to determine each memory area in the target available memory area group as a plurality of target memory areas whose total size satisfies the memory application size, are continuous with each other and are available.

[0187] In some embodiments, the seventh determining unit includes:

[0188] A first determining subunit, configured to determine, from each available memory area group, first available memory area groups whose total memory size is greater than or equal to the memory application size;

[0189] A second determining subunit is used to determine whether there is a second available memory area group that is released after allocation in each first available memory area group;

[0190] The third determination subunit is used for, if there are second available memory area groups that are released after being allocated, then determining a second available memory area group whose memory size is closest to the memory application size from each second available memory area group as the target available memory area group; wherein the returned mapping information of the multiple target memory areas includes a historical mapping identifier of the target available memory area group; if there is no second available memory area group that is released after being allocated, then determining a first available memory area group whose memory size is closest to the memory application size from each first available memory area group as the target available memory area group; wherein the returned mapping information of the multiple target memory areas includes a new mapping identifier generated for the target available memory area group.

[0191] In some embodiments, it also includes:

[0192] An acquisition module is used to obtain a user's memory release request;

[0193] A third determining module, used to determine the memory area to be released according to the memory address and size in the memory release request;

[0194] The clearing module is used to clear the data in the memory area to be released and update the attribute information corresponding to the memory area to be released in the memory mapping table.

[0195] It should be noted that the memory allocation device provided in the embodiment of the present invention has the same beneficial effects as the memory allocation method provided in the above embodiment, and for the specific introduction of the memory allocation method involved in the embodiment of the present invention, please refer to the above embodiment, and the present invention will not be repeated here.

[0196] The memory allocation device mentioned above is described from the perspective of functional modules. 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 by an embodiment of the present invention, such as Figure 8 As shown, the electronic equipment includes:

[0197] A memory 20, used for storing computer programs;

[0198] The processor 21 is used to implement the steps of the memory allocation method in the above embodiment when executing a computer program.

[0199] The electronic device provided in this embodiment may include but is not limited to a smart phone, a tablet computer, a laptop computer or a desktop computer.

[0200] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of 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 is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to process computing 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 a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. The memory 20 may be an internal storage unit of an electronic device in some embodiments, such as a hard disk of a server. The memory 20 may also be an external storage device of an electronic device in other embodiments, such as a plug-in hard disk equipped on a server, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc. Further, the memory 20 may also include both an internal storage unit of an electronic device and an external storage device. The memory 20 may not only be used to store application software and various types of data installed in the electronic device, such as: the code of the program in the process of executing the memory allocation method, etc., but may also be used to temporarily store data that has been output or is to be output. In this embodiment, the memory 20 is at least used to store the following computer program 201, wherein, after the computer program is loaded and executed by the processor 21, the relevant steps of the memory allocation method disclosed in any of the aforementioned embodiments can be implemented. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, etc., and the storage method may be temporary storage or permanent storage. Among them, 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 result).

[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. Among them, the display screen 22 and the input / output interface 23, such as a keyboard, belong to the user interface, and the optional user interface may also include a standard wired interface, a wireless interface, and the like. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode) touch device, and the like. The display may also be appropriately referred to as a display screen or a display unit, which is 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, and the like, which are generally used to establish a communication connection 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, and the like. The bus may be divided into an address bus, a data bus, a control bus, and the like. For ease of representation, Figure 8 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0203] Those skilled in the art will understand that Figure 8 The structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure.

[0204] It is understandable that if the memory allocation method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention is essentially 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, and the computer software product is stored in a storage medium to execute all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, 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 that can store program codes.

[0205] Based on this, Fig. 9As shown, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program 31 is stored. When the computer program 31 is executed by a processor, the steps of the above-mentioned memory allocation method are implemented.

[0206] On the basis of the above-mentioned embodiment, an embodiment of the present invention further provides a computer program product, including a computer program / instruction, which implements the steps of the memory allocation method as described above when executed by a processor.

[0207] The above is a detailed introduction to a memory allocation method, device, electronic device and computer-readable storage medium provided by an embodiment of the present invention. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.

[0208] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0209] The above is a detailed introduction to a memory allocation method, device, electronic device and computer-readable storage medium provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.

Claims

1. A memory allocation method, characterized in that: include: Obtaining a memory application request from a user, and determining a memory application size according to the memory application request; Determine whether there is a single available memory area whose memory size meets the memory application size according to a pre-established memory mapping table; wherein the memory mapping table includes memory address information and attribute information corresponding to each memory area from the minimum physical address to the maximum physical address, and an adjustable number of memory areas starting from the minimum physical address are unavailable reserved areas, the reserved areas are used for configuration of device resources, and the initial states of other memory areas are all available, and the attribute information includes the current state of the memory; If there is no single available memory area whose memory size meets the memory application size, then select multiple target memory areas whose total size meets the memory application size, are continuous with each other and are available from various memory areas according to the memory mapping table; Return mapping information of the plurality of target memory regions; wherein the mapping information is used to determine address information and size of corresponding memory regions.

2. The memory allocation method according to claim 1, characterized in that: Also includes: If there is a single memory area whose memory size meets the memory application size and is available, determining whether there is a single memory area that is allocated and then released in the single memory area whose memory size meets the memory application size; If there is a single memory area that is released after being allocated, a single memory area whose memory size is closest to the memory application size is determined from the single memory areas that are released after being allocated as the target memory area; Obtaining a historical mapping identifier of the target memory area, and returning the historical mapping identifier as mapping information; If there is no single memory area that is released after being allocated, a single memory area whose memory size meets the memory application size and is available is determined as the target memory area; A new mapping identifier is generated for the target memory area, 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 memory status is available or unavailable or used or released; Then, multiple target memory areas whose total size meets the memory application size, are continuous with each other and are available are screened out from each memory area according to the memory mapping table, including: Determine each available memory area according to the attribute information corresponding to each memory area stored in the memory mapping table; According to the memory address information corresponding to each of the available memory areas, determining each group of available memory areas with continuous addresses from each of the available memory areas; Determining, from the available memory area groups with consecutive addresses, the total memory size corresponding to each available memory area group; Determine, according to the total memory size of each of the available memory area groups, a target available memory area group whose total memory size satisfies the memory application size; The memory areas in the target available memory area group are determined to be a plurality of target memory areas whose total size satisfies the memory application size, are continuous with each other and are available.

4. The memory allocation method according to claim 3, characterized in that: Determining, according to the total memory size of each of the available memory area groups, a target available memory area group whose total memory size meets the memory application size comprises: Determine, from each of the available memory area groups, respective first available memory area groups whose total memory size is greater than or equal to the memory application size; Determine whether there is a second available memory area group that is allocated and then released in each of the first available memory area groups; If there are second available memory area groups that are released after being allocated, a second available memory area group whose memory size is closest to the memory application size is determined from each of the second available memory area groups as the target available memory area group; wherein the returned mapping information of the multiple target memory areas includes a historical mapping identifier of the target available memory area group; if there is no second available memory area group that is released after being allocated, a first available memory area group whose memory size is closest to the memory application size is determined from each of the first available memory area groups as the target available memory area group; wherein the returned mapping information of the multiple target memory areas includes a new mapping identifier generated for the target available memory area group.

5. The memory allocation method according to claim 5, characterized in that: Also includes: Get the user's memory release request; Determine the memory area to be released according to the memory address and size in the memory release request; The data in the memory area to be released is cleared, and the attribute information corresponding to the memory area to be released in the memory mapping table is updated.

6. The memory allocation method according to any one of claims 1 to 5, characterized in that: Also includes: In the memory initialization phase, the number of CPUs n, the number of CPUs cnt, the number of system root D, the memory capacity of a single root Sc, and the reserved fixed memory capacity R are obtained; Calculate the available memory capacity of the operating system according to the number n of the single CPU, the number cnt of the CPU, the number D of the system root, the memory capacity Sc of the single root, and the reserved fixed memory capacity R; The amount of memory available to the operating system is sent to the operating system.

7. The memory allocation method according to claim 6, characterized in that: The available memory capacity of the operating system is calculated according to the number n of the single CPU, the number cnt of the CPU, the number D of the system root, the memory capacity Sc of the single root, and the reserved fixed memory capacity R, including: Calculate the total number of bands N according to the number of bands n on the single CPU and the number of CPUs cnt; Calculate the number of interleaving I according to the number of system band roots D and the number of bands on the single central processor n; The total physical memory T of the system is calculated according to the number D of system root and the memory capacity Sc of a single root; Dividing the difference between the total physical memory T of the system and the reserved fixed memory capacity R by the total number of bands N to obtain a first ratio; Dividing the first ratio by the interleaving number I obtains a second ratio, and rounding the second ratio to obtain a physical memory capacity St on each band; Round the third ratio of the physical memory capacity St on each band to the interleaving quantity to obtain the memory capacity cm of the minimum block available area; The available memory capacity of the operating system is calculated based on the memory capacity cm of the minimum block available area, the interleaving number I, the number n of bands on the single central processing unit, and the number cnt of the central processing units.

8. A memory allocation device, characterized in that: include: A first determination module, configured to obtain a memory application request from a user and determine a memory application size according to the memory application request; A judgment module is used to determine whether there is a single memory area whose memory size meets the memory application size and is available according to a pre-established memory mapping table; wherein the memory mapping table includes memory address information and attribute information corresponding to each memory area from the minimum physical address to the maximum physical address, and an adjustable number of memory areas starting from the minimum physical address are unavailable reserved areas, the reserved areas are used for configuration of device resources, and the initial states of other memory areas are all available, and the attribute information includes the current state of the memory; A screening module is used for screening multiple target memory areas whose total size meets the memory application size, are continuous with each other and are available from various memory areas according to a memory mapping table if there is no single memory area whose memory size meets the memory application size and is available; The return module is used to return mapping information of multiple target memory areas; wherein the mapping information is used to determine the address information and size of the corresponding memory area.

9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the computer program to implement the steps of the memory allocation method as claimed in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the memory allocation method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Memory allocation method and device, electronic device and readable storage medium

    CN107203477A

  • Memory allocation method and device, equipment and storage medium

    CN113448720A

  • Memory management method and device

    CN115794417A

  • Memory management method, host machine, electronic equipment, storage medium and program product

    CN118819871A

  • Internal memory distributing method

    CN1673979A

Cited By

  • Dynamic memory allocation method and device, medium and product

    CN120821439A

  • Memory allocation method and electronic equipment

    CN120892214A