A heterogeneous memory allocation method, device and electronic equipment

By considering the read/write latency and economic cost of non-volatile memory during memory allocation and employing a cost calculation strategy, the system latency problem caused by read/write imbalance in heterogeneous memory management is solved, thereby optimizing memory allocation and reducing latency.

CN113867947BActive Publication Date: 2026-03-03CAS OF CHENGDU INFORMATION TECH CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111119129.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-24
Publication Date
2026-03-03
Estimated Expiration
2041-09-24

AI Technical Summary

Technical Problem

Existing heterogeneous memory management mechanisms fail to effectively balance the read/write imbalance of non-volatile memory, leading to increased system latency.

Method used

By considering the read/write latency, economic cost, and write lifetime of non-volatile memory during memory allocation, a cost calculation strategy is adopted to allocate memory in ascending order of allocation cost.

Benefits of technology

It achieves optimal memory allocation in heterogeneous memory scenarios, balances the write lifespan loss of non-volatile memory with read/write latency, and reduces system latency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113867947B_ABST
    Figure CN113867947B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a heterogeneous memory allocation method, device and electronic equipment, the heterogeneous memory comprising a plurality of non-volatile memories, the method comprising: receiving a memory allocation request initiated by an application program, reading memory resource information of a system, the memory resource information comprising memory size, first address, current write times, maximum writable times, read delay, write delay and economic cost of the plurality of non-volatile memories; calculating an allocation cost of each non-volatile memory in the plurality of non-volatile memories based on the memory allocation request, the memory resource information and a pre-set calculation rule; and allocating memory to the application program in order of allocation cost of the plurality of non-volatile memories from small to large. The above scheme provides a more reasonable memory allocation optimization mechanism to balance the write life consumption and read-write delay of the non-volatile memory, so that the cost of each memory allocation is the lowest.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of memory management technology, and more specifically, to a heterogeneous memory allocation method, apparatus, and electronic device. Background Technology

[0002] Non-volatile memory (NVMemory) is memory that does not lose data when the computer is turned off or shut down suddenly or unexpectedly. Therefore, NVOMemory is generally used to store data. In the industry, computer storage is usually divided into a three-level storage structure based on storage capacity and access speed: CPU cache, main memory (RAM), and secondary storage (SDS). NVOMemory generally corresponds to SSD, and specific product types include magnetic tape, flash memory, hard disk drives (HDDs), and solid-state drives (SSDs).

[0003] In recent years, with the rapid development of storage technology, non-volatile storage technology has also begun to gain momentum at the memory level. Intel officially released its first commercially available non-volatile memory product, Optane non-volatile memory, in 2018. Compared to external storage, non-volatile memory boasts read / write speeds approaching those of RAM, byte-addressing characteristics similar to RAM, significantly larger capacities, and the characteristic of data not being lost when power is off, representing a major breakthrough in storage technology. However, non-volatile memory also has some drawbacks, such as read / write imbalances, generally higher latency than regular RAM, and wear and tear during write cycles. Therefore, a suitable memory management mechanism is needed for non-volatile memory to fully utilize its performance. In particular, for heterogeneous memory scenarios combining regular RAM and non-volatile memory, proper memory allocation and management are crucial. Therefore, it is necessary to research a new memory allocation mechanism adapted to non-volatile memory or heterogeneous memory scenarios.

[0004] Most programs currently use virtual memory mapping. Before a program is loaded and executed, an address mapping is created in the virtual memory address space. The program then occupies a portion of the virtual memory space, and obtains the actual physical memory pages by triggering a page fault in the operating system when actually using memory. Modern Linux operating systems provide the mmap and unmap functions to create and delete virtual memory mappings, but these are costly to write and have poor portability. A common approach is to encapsulate the low-level operations of memory mapping into a dynamic memory allocator, hiding the low-level allocation details, thereby improving ease of use and portability.

[0005] The dynamic memory allocators mentioned above are divided into two types: explicit allocators and implicit allocators. Explicit allocators require the application to explicitly release any allocated blocks; for example, the malloc package in the C standard library is an explicit allocator. Implicit allocators, on the other hand, detect and reclaim memory that is no longer in use. This detection and reclamation process is generally called garbage collection, so implicit allocators are also commonly referred to as garbage collectors. High-level languages ​​such as Java and Python rely on garbage collectors to manage memory.

[0006] Currently, non-volatile memory is not widely used in industry, and existing mature explicit or implicit allocators are not adapted to this new type of hardware. Some existing research and patents have proposed optimizations for memory allocation in heterogeneous memory scenarios combining non-volatile and ordinary memory, but shortcomings remain. Specifically, before commercially available non-volatile memory products are available, the academic community's expectations for this new hardware are: 1. Read and write speeds close to ordinary memory; 2. Retention of byte addressing characteristics; 3. Read-write imbalance, with low read latency and high write latency; 4. Power-loss protection to ensure data integrity; 5. Write-endurance degradation, meaning write operations will wear down the hardware, eventually leading to unusability.

[0007] Based on the above five characteristics, existing technical solutions and research have proposed some program optimization strategies for non-volatile memory, which are basically centered around point 5 (write lifetime loss) and point 3 (low read latency, high write latency). Some technical solutions propose to perform read operations on non-volatile memory as much as possible, and move operations that require a large number of frequent writes to ordinary memory.

[0008] For Optane non-volatile memory, currently the only commercially available non-volatile memory product, experiments have shown that its read / write imbalance manifests as high read latency and low write latency. Previous designs have revealed significant drawbacks to this characteristic. Specifically, by shifting read operations to non-volatile memory, which typically suffers from higher read latency, this approach, while reducing hardware wear to some extent, increases program latency. Since memory allocation is a low-level operation, the impact of low-level memory latency in large systems is amplified across the entire system. Therefore, a re-evaluation of memory allocation optimization mechanisms for heterogeneous memory environments is necessary. Summary of the Invention

[0009] The purpose of this disclosure is to provide a heterogeneous memory allocation method, apparatus, and electronic device to alleviate the technical problem of system latency caused by the imbalance between non-volatile memory read and write operations and the unreasonable memory allocation optimization mechanism under existing heterogeneous memory.

[0010] To achieve the above objectives, the first aspect of this disclosure provides a heterogeneous memory allocation method, wherein the heterogeneous memory includes multiple non-volatile memory blocks, the method comprising:

[0011] Receive a memory allocation request initiated by an application, the memory allocation request including the length in bytes of the memory to be allocated and the process number;

[0012] Read the system's memory resource information, which includes the memory size, starting address, current write count, maximum write count, read latency, write latency, and economic cost of the multiple non-volatile memory blocks;

[0013] The allocation cost of each non-volatile memory block in the multiple non-volatile memory blocks is calculated based on the memory allocation request, the memory resource information, and the pre-set calculation rules.

[0014] Memory is allocated to the application in ascending order of the allocation cost of the multiple non-volatile memory blocks.

[0015] Optionally, before calculating the allocation cost of each non-volatile memory block among the multiple non-volatile memory blocks based on the memory allocation request, the memory resource information, and pre-set calculation rules, the method further includes:

[0016] When the application initiates the memory allocation request, the type attribute of the operation to be performed on the currently allocated memory is obtained; wherein, the type attribute is a read operation or a write operation;

[0017] If the application does not specify the type attribute of the operation, the default type attribute of the operation is the write operation.

[0018] Optionally, the pre-set calculation rules include:

[0019] The calculation rule for the allocation cost of the read operation is as follows: The calculation rule for the allocation cost of the write operation is as follows:

[0020] Wherein, Rcontency is the read latency, Scontency is the standard memory latency, Length is the byte length of the memory to be allocated, MemSize is the size of the non-volatile memory, Price is the economic cost, Wcontency is the write latency, Ctimes is the remaining number of write operations, and Wtimes is the number of write operations performed by the current process on the requested memory. Wtimes is estimated based on the historical allocation information of the current process.

[0021] Optionally, memory is allocated to the application in ascending order of the allocation cost of the multiple non-volatile memory blocks, including:

[0022] Select the memory with the lowest allocation cost from the multiple non-volatile memory blocks, and obtain the starting address of the memory with the lowest allocation cost;

[0023] Based on the starting address of the memory with the lowest allocation cost, find the allocation queue corresponding to the memory with the lowest allocation cost, and determine whether the remaining space of the memory heap managed by the allocation queue is sufficient for allocation.

[0024] If the conditions are met, memory is allocated to the application; if not, a new memory heap is requested from the system from the memory with the lowest allocation cost for allocation.

[0025] If the system has no new memory, it selects the memory with the lowest allocation cost from the remaining non-volatile memory and continues to allocate until the memory allocation is successful or all non-volatile memory allocations fail.

[0026] Optionally, the method further includes:

[0027] Receive a memory release request initiated by the application; wherein, the memory release request includes the starting address of the memory space to be released, a pointer to a memory block in the memory allocation queue, and the process ID of the memory to be released when it was requested; the memory allocation queue contains multiple allocation queues, and the multiple allocation queues respectively map to multiple non-volatile memory blocks;

[0028] Based on the pointer to a memory block in the memory allocation queue, determine the non-volatile memory corresponding to the memory release request;

[0029] Based on the starting address of the memory space to be released, find the specific address of the non-volatile memory corresponding to the memory release request and release it.

[0030] Optionally, the method further includes:

[0031] A memory allocation record is generated, which includes the starting address of the memory space to be allocated, the allocation length, the process ID, and the current timestamp. If the memory allocation fails, the starting address of the memory space is marked as insufficient memory, and the allocation length is marked as 0.

[0032] Optionally, the method further includes:

[0033] If the memory allocation is successful, update the current write count of the allocated memory.

[0034] Optionally, the method further includes:

[0035] Generate a memory release record, which includes the release result, a pointer to a memory block in the memory allocation queue, and the process number of the memory to be released when it was requested.

[0036] Optionally, the method further includes:

[0037] If memory release fails, an error exception will be thrown;

[0038] If memory is successfully released, based on the process ID of the memory to be released when it was requested and the pointer to a memory block in the memory allocation queue, the memory request record corresponding to the release record is found, and the time taken for the memory request record is calculated and recorded based on the timestamp difference.

[0039] Optionally, the memory resource information is stored in a fixed location in the system and only one copy is stored.

[0040] A second aspect of this disclosure provides a heterogeneous memory allocation apparatus, wherein the heterogeneous memory includes multiple non-volatile memory blocks, and the apparatus includes:

[0041] The metadata module is used to store the system's memory resource information, which includes the memory size, starting address, current write count, maximum write count, read latency, write latency, and economic cost of the multiple non-volatile memory blocks.

[0042] The cost calculation module is used to receive a memory allocation request initiated by the application, the memory allocation request including the byte length of the memory to be allocated and the process number; and to read the memory resource information of the system from the metadata module, and calculate the allocation cost of each non-volatile memory block among the multiple non-volatile memory blocks based on the memory allocation request, the memory resource information and the pre-set calculation rules.

[0043] The allocation management module is used to receive the calculation results from the cost calculation module and allocate memory to the application in ascending order of the allocation costs of the multiple non-volatile memory blocks.

[0044] A third aspect of this disclosure provides a non-transitory computer-readable storage medium having a computer program stored thereon that, when executed by a processor, implements the steps of the method described in the first aspect.

[0045] A fourth aspect of this disclosure provides an electronic device, comprising:

[0046] A memory on which computer programs are stored;

[0047] A processor for executing the computer program in the memory to implement the steps of the method described in the first aspect.

[0048] Through the above technical solution, when an application initiates a memory allocation request, memory is allocated to the application in ascending order of allocation cost among multiple non-volatile memory blocks in the system. When calculating the allocation cost of non-volatile memory, the byte length of the memory requested by the application, the size of the non-volatile memory, the current number of writes, the maximum number of writes, read latency, write latency, and economic cost are considered, minimizing the cost of each memory allocation. This provides a more reasonable memory allocation optimization mechanism to alleviate the technical problem of system latency caused by the imbalance between non-volatile memory reads and writes and the unreasonable memory allocation optimization mechanism under existing heterogeneous memory. The memory allocation optimization mechanism in this solution can balance the write lifespan loss and read / write latency of non-volatile memory as much as possible.

[0049] Other features and advantages of this disclosure will be described in detail in the following detailed description section. Attached Figure Description

[0050] The accompanying drawings are provided to further illustrate the present disclosure and form part of the specification. They are used together with the following detailed description to explain the present disclosure, but do not constitute a limitation thereof. In the drawings:

[0051] Figure 1 This is a schematic diagram of the structure of a memory allocator according to an exemplary embodiment;

[0052] Figure 2 This is a flowchart illustrating a heterogeneous memory allocation method according to an exemplary embodiment;

[0053] Figure 3 To illustrate the use according to an exemplary embodiment Figure 1 A flowchart illustrating the process of a memory allocation using the memory allocator in the code.

[0054] Figure 4 This is a block diagram illustrating an electronic device according to an exemplary embodiment. Detailed Implementation

[0055] The specific embodiments of this disclosure will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit this disclosure.

[0056] This specification first describes the heterogeneous memory and non-volatile memory in the embodiments of this disclosure.

[0057] Because non-volatile memory (NV) is still in the early stages of industrialization, many different technologies are currently used to implement this hardware. When large-scale commercial products emerge in the future, it's reasonable to predict that NVs produced by different manufacturers using different technologies will inevitably exhibit diverse read / write latency. This is because, firstly, currently only Intel has commercially deployed NVs based on its own 3Dxpoint NV technology. Other technologies include phase-change memory, memristors, and spin torque conversion random access memory, but these technologies have not yet seen commercial products. Secondly, even for Intel's own commercial Optane NV, its actual read / write latency deviates from academic estimates. Many existing research and technical solutions treat NV as a unified whole, heterogeneous with ordinary memory, without considering that different NV technologies or products themselves create a heterogeneous environment.

[0058] In other words, existing technologies do not take into account that non-volatile memory itself is heterogeneous in heterogeneous memory scenarios. Since different non-volatile memory types vary in read / write latency, price, and write endurance, it is inappropriate to simply consider them as a whole. Treating multiple hardware characteristics that are inconsistent as a unified whole cannot guarantee optimal allocation efficiency, thereby indirectly increasing usage costs.

[0059] The inventors of this solution considered both of the above reasons when designing it, taking into account the heterogeneity of different types of non-volatile memory during memory allocation. In this embodiment, one type of non-volatile memory can comprise multiple blocks; each type of memory refers to a specific model of non-volatile memory implemented using a particular technology or brand, possessing its own hardware performance. Each block refers to a specific non-volatile memory block of a particular model. For example, suppose a motherboard has four memory slots, which can accommodate four memory modules of the same brand and model, four memory modules of different models from the same brand, or four memory modules of different brands and models. This disclosure does not limit the specific implementation method of heterogeneous memory.

[0060] The memory allocator designed in this invention takes into account the differences in read and write latency of different types of non-volatile memory in heterogeneous memory scenarios and the characteristics of program read and write types. It adopts an allocation strategy based on cost to minimize the cost of each allocation, which is also the core idea of ​​this technical solution.

[0061] The solution in this disclosure is designed for heterogeneous memory scenarios and proposes a cost-based memory allocation method, the main component of which is a dynamic memory allocator. The structure of this memory allocator is as follows: Figure 1 As shown.

[0062] The memory allocator consists of the following five parts.

[0063] 1. Metadata module Mi

[0064] 2. Cost Calculation Module Mc

[0065] 3. Allocation Management Module Mq

[0066] 4. Statistical Data Module Ms

[0067] 5. Local configuration file

[0068] The use of this memory allocator is divided into the following two stages.

[0069] Construction phase

[0070] The build phase occurs when the memory allocator is first invoked. It requires obtaining system memory resource information, including the size of each memory block, the read / write latency of each block, the current write count and maximum write count for each block, and the economic cost of each block. This data is maintained in a globally unique configuration file, ensuring that each process's memory allocator can obtain accurate configuration information for non-volatile memory within the system. It should be noted that, unless otherwise specified, memory in the following specification generally refers to non-volatile memory.

[0071] According to the configuration file, initialize a memory allocator for the program process. For example... Figure 1 As shown, the memory allocator includes a cost calculation module Mc, a memory allocation queue Mq, a metadata module Mi, and a statistics module Ms. During memory pool initialization, for each type of memory in the system, the memory allocation queue Mq maintains an allocation queue within the allocator. Each allocation queue maps to a block of memory in the system. A type of memory may include multiple blocks of memory, resulting in multiple allocation queues within the memory allocation queue Mq, each mapping to a different block of memory. The pointer array records the corresponding memory allocation status. The memory allocation queue Mq maintains an allocation queue for each block of memory in the system. The pointer array (or pointer linked list) in the allocation queue indicates the current allocation status of each block of memory in the system by the memory allocator. Subsequent allocations involve adding a new pointer to that memory block to the allocation queue.

[0072] Simultaneously, the metadata module Mi reads data from the configuration file and updates the data in the configuration file in real time or periodically as the memory allocator is used. Table 1 shows one possible form of data in the metadata module Mi. Real-time updates provide the most accurate data. However, since memory allocation is a relatively frequent operation, lock contention can occur in a multi-process environment to ensure accurate data updates. Therefore, a periodic update method can also be used to avoid lock contention. In this embodiment, real-time or periodic updates can be selected according to the actual situation. For example, if a server is a dedicated server for a specific service and only runs a specific program, real-time updates can be used. Those skilled in the art can choose according to actual needs, and this disclosure does not impose any restrictions.

[0073]

[0074] Table 1

[0075] Use phase

[0076] Please refer to Figure 2 , Figure 2 This is a flowchart illustrating a heterogeneous memory allocation method according to an exemplary embodiment, the method comprising the following steps.

[0077] Step 201: Receive a memory allocation request initiated by the application, wherein the memory allocation request includes the byte length of the memory to be allocated and the process number.

[0078] Step 202: Read the system's memory resource information, which includes the memory size, starting address, current write count, maximum write count, read latency, write latency, and economic cost of the multiple non-volatile memory blocks.

[0079] Step 203: Calculate the allocation cost of each non-volatile memory block among the multiple non-volatile memory blocks based on the memory allocation request, the memory resource information, and the pre-set calculation rules.

[0080] Step 204: Allocate memory to the application in ascending order of the allocation cost of the multiple non-volatile memory blocks.

[0081] When the memory allocator receives a memory allocation request from an application, it passes the request to the cost calculation module Mc. Mc calculates the allocation cost Pcost for each memory in the allocation queue Mq based on the memory resource information and memory allocation request information from the metadata module Mi. Then, it selects the memory with the lowest Pcost value for allocation. Because the above scheme maintains memory resource information in the system, including read latency, write latency, number of writes, and economic cost for each non-volatile memory block, this information serves as an important reference for cost calculation during memory allocation. By combining the characteristics of program execution, it strives to balance the write lifespan loss of non-volatile memory with read / write latency, achieving the most economical allocation result at the current time. This provides a new reference approach for non-volatile memory allocation in heterogeneous memory scenarios.

[0082] Next, please refer to Figure 3 , Figure 3 To illustrate the use according to an exemplary embodiment Figure 1 The diagram below illustrates the process of a memory allocation operation performed by the memory allocator. Figure 1 and Figure 3 The heterogeneous memory allocation method in the embodiments of this disclosure is described, and the method includes the following steps.

[0083] Step 301: Obtain configuration information.

[0084] The memory allocator reads the configuration file and initializes a memory allocator instance for the current process. In this embodiment, the configuration file is maintained in a fixed location on the system and there is only one copy. When the system does not have a configuration file, it needs to be created manually. The configuration file contains at least the following information: the size of each memory block, read latency, write latency, number of writes, economic cost, unique memory identifier, and starting address. In practical applications, other relevant information can also be written to the configuration file, which is not limited in this disclosure.

[0085] Step 302: Create a memory allocator.

[0086] The memory allocator program reads information from the configuration file, stores the information in the metadata module Mi, and creates an array of pointers to track the allocation for each memory block in the memory allocation management module Mq based on the starting address and the unique memory identifier. Steps 301 and 302 above occur during the creation phase of the memory allocator.

[0087] Step 303: After initialization is complete, wait for the application's memory allocation request.

[0088] When an application initiates a memory request, the memory allocation request is identified by the following five-tuple structure: [Length, Type, Pid, ​​Tid, Pname].

[0089] Wherein, Length: the length of the memory to be allocated in bytes.

[0090] Type: The type of operation to be performed on the memory to be allocated (optional). Operations are divided into read (Write) and write (Write) operations. The default parameter is write operation.

[0091] Pid: Process ID.

[0092] Tid: Thread number (optional).

[0093] Pname: A string that uniquely identifies a program (optional).

[0094] In this embodiment, the Type attribute is optional for compatibility with existing programs. A memory allocator is essentially a callable function that manipulates memory. In this embodiment, when the program calls a memory allocation function (such as malloc), it needs to tell the allocator whether the currently allocated memory is primarily for read or write operations (i.e., the Type attribute). Therefore, for existing programs, the Type attribute may not be included. To ensure non-intrusive compatibility with existing programs, the Type attribute is optional. Thus, the Type attribute is specified by the program. If not specified, the default is write operation. This is because read operations do not affect the lifespan of non-volatile memory, while write operations do. Therefore, when the program does not provide an operation type, a pessimistic strategy is adopted, using write operation as the default value, thereby achieving optimal allocation.

[0095] Step 304: Obtain the request type.

[0096] As described in step 303, when the application initiates the memory allocation request, the type attribute of the operation to be performed on the currently allocated memory, as specified by the application, is obtained; wherein the type attribute is either a read operation or a write operation. If the application does not specify the type attribute of the operation, the default type attribute of the operation is a write operation.

[0097] Step 305: Calculate the allocation cost.

[0098] In step 305, after receiving the memory allocation request initiated by the application, the cost calculation module Mc reads information from the metadata module Mi and begins to calculate the cost Pcost of this memory allocation.

[0099] First, the cost calculation module Mc obtains information such as read latency, write latency, and economic cost for each non-volatile memory block from the metadata module Mi.

[0100] Then, the cost calculation module Mc obtains the historical allocation information of the current process from the statistics module Ms, estimates Wtimes, and calculates the Pcost allocated on each non-volatile memory block. The Wtimes estimation is done by reading the write count records from the past allocation records of the current process in the statistics module Ms and taking the median. In this embodiment of the disclosure, the calculation rules for allocation cost are as follows.

[0101] For the allocation cost marked as a read operation,

[0102] The allocation cost for operations marked as write operations,

[0103] Rcontency: memory read latency, obtained from the metadata module Mi.

[0104] Wcontency: Memory write latency, obtained from Mi in the metadata module.

[0105] Scontency: Standard memory latency, obtained from the metadata module Mi. Since ordinary memory is read-write balanced (i.e., read latency and write latency are equal), the read-write latency of ordinary memory is the benchmark for measurement.

[0106] Memsize: The total size of each memory block.

[0107] Wtimes: The number of write operations on the allocated memory, estimated from the statistics module Ms.

[0108] Ctimes: The current number of writes to memory (i.e., the remaining number of writes), obtained from the metadata module Mi. The remaining number of writes can be calculated from the current number of writes and the maximum number of writes. For ordinary memory, Ctimes defaults to an unlimited number of writes. Since ordinary memory is read-write balanced and does not experience write wear, there is no need to measure it using allocation cost.

[0109] Price: The economic cost of the allocated memory hardware, obtained from the metadata module Mi.

[0110] The Pcost for a read operation is determined based on the read latency Rcontency and the economic price Price of different memory locations.

[0111] For the Pcost of a write operation, its allocation cost is divided into two parts. One part is the same as that of a read operation, based on the write latency Wcontency. The other part, due to the write lifetime of non-volatile memory, also includes the economic cost of the write operation, which is determined by the number of write operations Wtimes caused by a cache page fault, the remaining number of write operations Ctimes, and the economic price Price.

[0112] In this embodiment of the disclosure, the calculation results can be temporarily stored in the form of a list of {[memory1, Pcost1][memory2, Pcost2]...}, where each item is arranged in ascending order of the value of Pcost.

[0113] Step 306: Allocate memory based on allocation cost.

[0114] In step 306, the Pcost calculation result from step 305 is passed to the allocation management module Mq, which attempts to allocate memory in ascending order of Pcost.

[0115] First, Mq retrieves the address of memory 1 from the list {[memory1, Pcost1][memory2, Pcost2]...}. Based on this address, it finds the memory pointer array it manages and attempts to allocate memory. If the allocation is successful, the current step ends. If the allocation fails, it requests more space from the operating system and then attempts to reallocate it. If the reallocation is successful, the current step ends; if the reallocation fails, the allocation management module Mq reads the next memory address with the lowest allocation cost (i.e., memory 2) from the list {[memory1, Pcost1][memory2, Pcost2]...} and attempts to allocate it, until the allocation succeeds or all memory allocations in the list fail.

[0116] In this embodiment of the disclosure, for non-volatile memory, each process's memory allocator does not occupy the entirety of a certain block of non-volatile memory in the system; it only requests a portion first. This portion of memory is called the heap. Before the memory heap is exhausted, all processes prioritize allocating memory from the heap. When the remaining heap space is insufficient, a larger block of memory is requested from the operating system for management.

[0117] The pointer array is used to determine if there is still space available for allocation in the currently mapped memory segment. If not, the memory allocator requests more memory from the operating system before allocating it. For the entire memory block 1, the memory allocator doesn't know how much remaining space is available; the address of memory 1 refers to the starting address of the allocation queue for mapped memory 1 in the allocation management module Mq. This allocation queue checks if the remaining space in the currently managed mapped memory 1 is sufficient for allocation. If so, it's allocated, and a new pointer is added to record the allocated space. If not, it requests more memory from the operating system. If the operating system also cannot return new memory, the memory allocator finds the next memory segment with the smallest Pcost value for allocation.

[0118] Step 307: After the allocation is completed, the allocation information is transmitted to the statistics module Ms.

[0119] In step 306, if the memory allocation is successful, the starting address of the allocated memory space, the allocation length, the process / thread number, and the current timestamp are passed to the statistics module Ms, and the memory allocation record is saved.

[0120] In step 306, if memory allocation fails, the above four pieces of data are still passed. The starting address of the memory space is marked as insufficient memory, the allocation length is marked as 0, and the process / thread ID and timestamp are displayed normally.

[0121] Step 308, release memory.

[0122] In step 308, the application initiates a memory release request, requesting the release of the memory allocated in steps 303-306.

[0123] After an application finishes using an allocated memory space, it initiates a memory release request, which is marked with the following structure: [Addr, Mem, Pid, ​​Tid, Pname].

[0124] Where Addr is the starting address of the memory to be freed.

[0125] Mem: A pointer to a memory block in Mq.

[0126] Pid: The process ID of the memory to be freed when it was allocated.

[0127] Tid: The thread number of the memory to be released when it was allocated.

[0128] Pname: A string that uniquely identifies a program. (Optional)

[0129] First, after receiving a memory release request from the application, the memory allocation module Mq determines which memory block on the system needs to be released based on Mem. Then, it uses Addr to find the specific address of that memory block in the memory allocation queue and releases it. If the address cannot be found, an error exception is thrown.

[0130] Then, the memory release operation result, along with the Mem, Pid, ​​Tid, Pname data, and the current timestamp, are passed to the statistics module Ms.

[0131] Step 309: During operation, the metadata module Mi will periodically write updated data back to the configuration file on the disk.

[0132] The metadata module Mi executes a scheduled task to synchronize the latest data in the current memory allocator instance to the configuration file on disk. After synchronizing the data to the disk file, the metadata module Mi reads the latest record from the configuration file.

[0133] Step 310: The allocation management module Mq accepts the release request, releases the memory, and then passes the release information to the statistics module Ms.

[0134] If the data in step 308 indicates a successful release, the memory allocation record corresponding to that release record is located in the statistics module Ms based on Pid / Tid+Mem. The time taken for this allocation record is calculated based on the timestamp difference, and the actual number of writes to the allocated memory is obtained and stored in the statistics module Ms. The memory allocation time can be used for performance analysis; this information, stored in the statistics module Ms, can be used to perform performance analysis on the memory allocator.

[0135] If the data in step 308 indicates a memory release failure, the statistics module Ms will not perform any operation.

[0136] Step 311: Update information in the metadata module Mi.

[0137] In this embodiment, if the statistics module Ms receives a successful allocation message, it notifies the metadata module Mi to update the current write count. The write count is the sum of the number of CPU cache writes and memory page faults. Currently, there are many ways to obtain memory page faults or CPU cache writes during application runtime, such as the cachegrind tool. This value can be obtained using these existing tools, or it can be estimated based on the average of previous records after the program has been running for a period of time.

[0138] If the statistics module Ms receives a message indicating a failed allocation, it will not notify the metadata module Mi.

[0139] Based on the same inventive concept, embodiments of this disclosure also provide a heterogeneous memory allocation device, such as... Figure 1 As shown, the heterogeneous memory includes multiple non-volatile memory blocks, and the device includes:

[0140] The metadata module is used to store the system's memory resource information, which includes the memory size, starting address, current write count, maximum write count, read latency, write latency, and economic cost of the multiple non-volatile memory blocks.

[0141] The cost calculation module is used to receive a memory allocation request initiated by the application, the memory allocation request including the byte length of the memory to be allocated and the process number; and to read the memory resource information of the system from the metadata module, and calculate the allocation cost of each non-volatile memory block among the multiple non-volatile memory blocks based on the memory allocation request, the memory resource information and the pre-set calculation rules.

[0142] The allocation management module is used to receive the calculation results from the cost calculation module and allocate memory to the application in ascending order of the allocation costs of the multiple non-volatile memory blocks.

[0143] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.

[0144] Figure 4 This is a block diagram illustrating an electronic device 400 according to an exemplary embodiment. Figure 4 As shown, the electronic device 400 may include a processor 401 and a memory 402. The electronic device 400 may also include one or more of a multimedia component 403, an input / output (I / O) interface 404, and a communication component 405.

[0145] The processor 401 controls the overall operation of the electronic device 400 to complete all or part of the steps in the heterogeneous memory allocation method described above. The memory 402 stores various types of data to support the operation of the electronic device 400. This data may include, for example, instructions for any application or method operating on the electronic device 400, and application-related data such as contact data, sent and received messages, pictures, audio, video, etc. The memory 402 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. Multimedia component 403 may include a screen and an audio component. The screen may be, for example, a touchscreen, and the audio component is used to output and / or input audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signals may be further stored in memory 402 or transmitted via communication component 405. The audio component also includes at least one speaker for outputting audio signals. I / O interface 404 provides an interface between processor 401 and other interface modules, such as a keyboard, mouse, buttons, etc. These buttons may be virtual or physical buttons. Communication component 405 is used for wired or wireless communication between the electronic device 400 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G, 4G, NB-IoT, eMTC, or other 5G technologies, or combinations thereof, is not limited here. Therefore, the corresponding communication component 405 may include: a Wi-Fi module, a Bluetooth module, an NFC module, etc.

[0146] In an exemplary embodiment, the electronic device 400 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the heterogeneous memory allocation method described above.

[0147] In another exemplary embodiment, a computer-readable storage medium including program instructions is also provided, which, when executed by a processor, implement the steps of the heterogeneous memory allocation method described above. For example, the computer-readable storage medium may be the memory 402 including program instructions described above, which may be executed by the processor 401 of the electronic device 400 to complete the heterogeneous memory allocation method described above.

[0148] In another exemplary embodiment, a computer program product is also provided, the computer program product comprising a computer program executable by a programmable device, the computer program having a code portion for performing the heterogeneous memory allocation method described above when executed by the programmable device.

[0149] It should be noted that the heterogeneous memory allocation method in this embodiment of the invention can be used on a single computer or in a cluster. A cluster can have multiple computers, each with a separate type of non-volatile memory. Compared to a scenario where multiple different types of non-volatile memory are configured heterogeneously within a single computer, a cluster comprising multiple different computers, each configured with a type of non-volatile memory, also fits the heterogeneous memory allocation method in this embodiment of the invention. In other words, in a cluster scenario, the memory allocation method described above still applies. Essentially, one computer in the cluster is selected as the master node, possessing a unique memory management device (similar to the heterogeneous memory allocation device described above), and each machine in the cluster also possesses the aforementioned memory allocation device. After a program task is submitted to the cluster, the memory management device decides which machine A to allocate it for execution, and that machine A then uses its own memory allocator to allocate memory.

[0150] The preferred embodiments of this disclosure have been described in detail above with reference to the accompanying drawings. However, this disclosure is not limited to the specific details of the above embodiments. Within the scope of the technical concept of this disclosure, various simple modifications can be made to the technical solutions of this disclosure, and these simple modifications all fall within the protection scope of this disclosure.

[0151] It should also be noted that the various specific technical features described in the above specific embodiments can be combined in any suitable manner without contradiction. In order to avoid unnecessary repetition, this disclosure will not describe the various possible combinations separately.

[0152] Furthermore, various different embodiments of this disclosure can be combined in any way, as long as they do not violate the spirit of this disclosure, they should also be regarded as the content disclosed in this disclosure.

Claims

1. A heterogeneous memory allocation method, characterized in that, The heterogeneous memory includes multiple non-volatile memory blocks, and the method includes: Receive a memory allocation request initiated by an application, the memory allocation request including the length in bytes of the memory to be allocated and the process number; Read the system's memory resource information, which includes the memory size, starting address, current write count, maximum write count, read latency, write latency, and economic cost of the multiple non-volatile memory blocks; The allocation cost of each non-volatile memory block in the multiple non-volatile memory blocks is calculated based on the memory allocation request, the memory resource information, and the pre-set calculation rules. Memory is allocated to the application in ascending order of allocation cost of the multiple non-volatile memory blocks, including: Select the memory with the lowest allocation cost from the multiple non-volatile memory blocks, and obtain the starting address of the memory with the lowest allocation cost; Based on the starting address of the memory with the lowest allocation cost, find the allocation queue corresponding to the memory with the lowest allocation cost, and determine whether the remaining space of the memory heap managed by the allocation queue is sufficient for allocation. If the conditions are met, memory is allocated to the application; if not, a new memory heap is requested from the system from the memory with the lowest allocation cost for allocation. If the system has no new memory, it selects the memory with the lowest allocation cost from the remaining non-volatile memory and continues to allocate until the memory allocation is successful or all non-volatile memory allocations fail. The method further includes, before calculating the allocation cost of each non-volatile memory block among the multiple non-volatile memory blocks based on the memory allocation request, the memory resource information, and pre-set calculation rules: When the application initiates the memory allocation request, the type attribute of the operation to be performed on the currently allocated memory is obtained; wherein, the type attribute is a read operation or a write operation; If the application does not specify the type attribute of the operation, the default type attribute of the operation is the write operation; The pre-set calculation rules include: The calculation rule for the allocation cost of the read operation is as follows: The calculation rule for the allocation cost of the write operation is as follows: ; Where Rcontency is the read latency. For standard memory latency, The length of the memory to be allocated in bytes. The size of the non-volatile memory. For economic costs, To delay writing, The remaining number of write operations. This represents the number of write operations performed by the current process on the allocated memory. This is estimated based on the historical allocation information of the current process.

2. The method as described in claim 1, characterized in that, The method further includes: Receive a memory release request initiated by the application; wherein, the memory release request includes the starting address of the memory space to be released, a pointer to a memory block in the memory allocation queue, and the process ID of the memory to be released when it was requested; the memory allocation queue contains multiple allocation queues, and the multiple allocation queues respectively map to multiple non-volatile memory blocks; Based on the pointer to a memory block in the memory allocation queue, determine the non-volatile memory corresponding to the memory release request; Based on the starting address of the memory space to be released, find the specific address of the non-volatile memory corresponding to the memory release request and release it.

3. The method as described in claim 1, characterized in that, The method further includes: A memory allocation record is generated, which includes the starting address of the memory space to be allocated, the allocation length, the process ID, and the current timestamp. If the memory allocation fails, the starting address of the memory space is marked as insufficient memory, and the allocation length is marked as 0.

4. The method as described in claim 1, characterized in that, The method further includes: If the memory allocation is successful, update the current write count of the allocated memory.

5. The method as described in claim 2, characterized in that, The method further includes: Generate a memory release record, which includes the release result, a pointer to a memory block in the memory allocation queue, and the process number of the memory to be released when it was requested.

6. The method as described in claim 3, characterized in that, The method further includes: If memory release fails, an error exception will be thrown; If memory release is successful, based on the process ID of the memory to be released when it was requested and the pointer to a memory block in the memory allocation queue, find the memory request record corresponding to the release record, calculate and record the time taken for the memory request record based on the timestamp difference.

7. The method as described in claim 1, characterized in that, The memory resource information is stored in a fixed location in the system and only one copy is stored.

8. A heterogeneous memory allocation device, characterized in that, The heterogeneous memory includes multiple non-volatile memory blocks, and the device includes: The metadata module is used to store the system's memory resource information, which includes the memory size, starting address, current write count, maximum write count, read latency, write latency, and economic cost of the multiple non-volatile memory blocks. A cost calculation module is used to receive a memory allocation request initiated by an application, the memory allocation request including the byte length of the memory to be allocated and the process number; and to read the system's memory resource information from the metadata module, and calculate the allocation cost of each non-volatile memory block among the multiple non-volatile memory blocks based on the memory allocation request, the memory resource information, and pre-set calculation rules. Before calculating the allocation cost of each non-volatile memory block among the multiple non-volatile memory blocks based on the memory allocation request, the memory resource information, and the pre-set calculation rules, the module further includes: When the application initiates the memory allocation request, the type attribute of the operation to be performed on the currently allocated memory is obtained; wherein, the type attribute is a read operation or a write operation; If the application does not specify the type attribute of the operation, the default type attribute of the operation is the write operation; wherein, the pre-set calculation rules include: The calculation rule for the allocation cost of the read operation is as follows: The calculation rule for the allocation cost of the write operation is as follows: ; Where Rcontency is the read latency. For standard memory latency, The length of the memory to be allocated in bytes. The size of the non-volatile memory. For economic costs, To delay writing, The remaining number of write operations. This represents the number of write operations performed by the current process on the allocated memory. This is estimated based on the historical allocation information of the current process. The allocation management module is used to receive the calculation results from the cost calculation module and allocate memory to the application in ascending order of the allocation costs of the multiple non-volatile memory blocks, including: Select the memory with the lowest allocation cost from the multiple non-volatile memory blocks, and obtain the starting address of the memory with the lowest allocation cost; Based on the starting address of the memory with the lowest allocation cost, find the allocation queue corresponding to the memory with the lowest allocation cost, and determine whether the remaining space of the memory heap managed by the allocation queue is sufficient for allocation. If the conditions are met, memory is allocated to the application; otherwise, a new memory heap is requested from the system from the memory with the lowest allocation cost for allocation.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the program implements the steps of the method described in any one of claims 1-7.

10. An electronic device, characterized in that, include: A memory on which computer programs are stored; A processor for executing the computer program in the memory to implement the steps of the method according to any one of claims 1-7.

Citation Information

Patent Citations

  • Read request scheduling method and system for heterogeneous memory cluster

    CN109960588A