[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN118210632A - Memory allocation method and device, electronic equipment and storage medium - Google Patents

Memory allocation method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN118210632A
CN118210632A CN202410518880.5A CN202410518880A CN118210632A CN 118210632 A CN118210632 A CN 118210632A CN 202410518880 A CN202410518880 A CN 202410518880A CN 118210632 A CN118210632 A CN 118210632A
Authority
CN
China
Prior art keywords
memory
target
allocation
task
memory block
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410518880.5A
Other languages
Chinese (zh)
Inventor
请求不公布姓名
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Bi Ren Technology Co ltd
Original Assignee
Shanghai Bi Ren Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Bi Ren Technology Co ltd filed Critical Shanghai Bi Ren Technology Co ltd
Priority to CN202410518880.5A priority Critical patent/CN118210632A/en
Publication of CN118210632A publication Critical patent/CN118210632A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/06Addressing a physical block of locations, e.g. base addressing, module addressing, memory dedication
    • G06F12/0646Configuration or reconfiguration
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5011Pool

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System (AREA)

Abstract

The invention relates to the technical field of computers and provides a memory allocation method, a memory allocation device, electronic equipment and a storage medium, wherein the memory allocation method firstly receives a memory allocation request sent by a process of target equipment; and then selecting a first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queue of the target equipment to allocate. The method can ensure that the allocation and the use of the memory blocks have time sequence by means of the first-in first-out semantics of the task queue for submitting the calculation task, and avoid the conflict between the allocation and the use of the same memory block. In addition, the method selects the first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queue for allocation, so that the idle memory blocks can be safely reused in the queue scope, the memory allocation efficiency can be greatly improved, and the memory waste can be avoided.

Description

Memory allocation method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a memory allocation method, a device, an electronic apparatus, and a storage medium.
Background
In conventional memory allocation policies, the allocation of memory is globally scoped, meaning that the memory blocks allocated for whichever portion of the program can be used directly elsewhere. And the memory allocation is realized by sending a memory application request to the system.
Because each application of memory requires interaction with the system, complex underlying operations, such as searching for free memory blocks, updating memory management tables, etc., are typically associated with relatively high computational resources and time. Particularly in the scenario of applying for a large amount or frequently, the time consumption of the allocation in this way becomes more remarkable, so that the execution efficiency of the program is affected.
In addition, conventional memory allocation policies may also cause memory fragmentation problems. With the continuous allocation and release of memory, the free memory space may be divided into many small fragments, which may not meet the requirements of the subsequent larger memory application, resulting in waste of memory resources.
Disclosure of Invention
The invention provides a memory allocation method, a memory allocation device, electronic equipment and a storage medium, which are used for solving the defects of long memory allocation time and memory resource waste when a system is directly applied for memory.
The invention provides a memory allocation method, which comprises the following steps:
Receiving a memory allocation request sent by a process of target equipment;
Selecting a first target memory block meeting the memory allocation request from idle memory blocks owned by a task queue of the target equipment to allocate;
The idle memory blocks comprise memory blocks released after use on the task queue.
According to the memory allocation method provided by the invention, the method further comprises the following steps:
determining that the first target memory block does not exist in the idle memory blocks or the task queue does not own the idle memory blocks, and sending the memory allocation request to a management system of the memory pool; the memory pool stores a plurality of memory blocks;
receiving a second target memory block provided by the management system based on the memory allocation request;
and distributing the second target memory block.
According to the memory allocation method provided by the invention, the second target memory block is a memory block which satisfies the memory allocation request in the memory pool;
Or the second target memory block is a memory block allocated to the memory pool by the installation system after the management system sends the memory allocation request to the installation system of the target device under the condition that the second target memory block does not exist in the memory pool.
According to the memory allocation method provided by the invention, the task queue comprises allocation tasks, calculation tasks and release tasks which are arranged in sequence; selecting a first target memory block meeting the memory allocation request from idle memory blocks owned by the task queue for allocation, wherein the method specifically comprises the following steps:
Executing the allocation task, and selecting the first target memory block from the idle memory blocks owned by the task queue for allocation;
selecting a first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queue for allocation, and then comprising the following steps:
And after the calculation task is executed based on the first target memory block, executing the release task, and releasing the first target memory block as the idle memory block to the task queue.
According to the memory allocation method provided by the invention, the number of the task queues is a plurality of task queues; selecting a first target memory block meeting the memory allocation request from idle memory blocks owned by the task queue for allocation, and specifically including:
And selecting a first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queues corresponding to the memory allocation request to allocate.
According to the memory allocation method provided by the invention, the number of the task queues is multiple, and task dependency relations are arranged among the task queues;
Selecting a first target memory block meeting the memory allocation request from idle memory blocks owned by the task queue for allocation, and specifically including:
And selecting a memory block meeting the memory allocation request from the idle memory blocks owned by the task queues as the first target memory block for allocation.
According to the memory allocation method provided by the invention, the memory allocation request comprises the memory size required by the process of the target equipment;
The first target memory block is a memory block with the same size as the memory in the idle memory block.
The invention also provides an electronic device comprising a memory, a processor and a computer program stored on the memory and capable of running on the processor, wherein the memory allocation method is realized by the processor when the processor executes the computer program.
The present invention also provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements a memory allocation method as described in any of the above.
The invention also provides a computer program product comprising a computer program which when executed by a processor implements a memory allocation method as described in any one of the above.
The invention provides a memory allocation method, a device, electronic equipment and a storage medium, wherein the method firstly receives a memory allocation request sent by a process of target equipment; the target device submits a computing task based on the task queue; and then selecting a first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queue for allocation. The method can ensure that the allocation and the use of the memory blocks have time sequence by means of the first-in first-out semantics of the task queue for submitting the calculation task, and avoid the conflict between the allocation and the use of the same memory block. In addition, the method selects the first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queue for allocation, so that the idle memory blocks can be safely reused in the queue scope, the memory allocation efficiency can be greatly improved, and the memory waste can be avoided.
Drawings
In order to more clearly illustrate the technical solutions of the present invention or related art, the drawings used in the description of the embodiments or related art will be briefly described below, and it is apparent that other drawings can be obtained according to the drawings in the description below without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a memory allocation method according to the present invention;
FIG. 2 is a schematic diagram of task dependencies between task queues provided by the present invention;
FIG. 3 is a diagram of an implementation architecture of the memory allocation method provided by the present invention;
fig. 4 is a schematic structural diagram of a memory allocation device according to the present invention;
fig. 5 is a schematic structural diagram of an electronic device provided by the present invention.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the present invention more apparent, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The features of the invention "first", "second" and the like in the description and in the claims may be used for the explicit or implicit inclusion of one or more such features. In the description of the invention, unless otherwise indicated, the meaning of "a plurality" is two or more. Furthermore, in the description and claims, "and/or" means at least one of the connected objects, and the character "/", generally means that the associated object is an "or" relationship.
Because in the related art, when memory allocation is performed on a host process, interaction is required to be performed with the system, and a memory allocation application is issued to the system, the system involves complex bottom operations, such as searching idle memory blocks, updating a memory management table, and the like, and allocating a suitable memory to the host process. However, the above complex bottom layer operation generally needs to consume more computing resources and time, which affects the execution efficiency of the host process, and also easily causes the problem of memory fragmentation, thereby resulting in waste of memory resources.
Therefore, the embodiment of the invention provides a memory allocation method.
Fig. 1 is a flow chart of a memory allocation method provided in an embodiment of the present invention, as shown in fig. 1, the method includes:
S1, receiving a memory allocation request sent by a process of target equipment;
s2, selecting a first target memory block meeting the memory allocation request from idle memory blocks owned by the task queue of the target equipment to allocate;
The idle memory blocks comprise memory blocks released after use on the task queue.
Specifically, the execution body of the memory allocation method provided in the embodiment of the present invention is a memory allocator, and the memory allocator may be configured in a Runtime System (running System) of the target device, so as to allocate a required memory for each process on the target device. Wherein the runtime system is primarily responsible for handling and managing the underlying computer resources during process execution.
The target device may be a device that submits computing tasks based on task queues, such as a graphics processor (Graphics Processing Unit, GPU), a General-purpose graphics processor (General-purpose Computing on Graphics Processing Unit, GPGPU), a central processing unit (Central Processing Unit, CPU), a microprocessor (Microprocessor Unit, MPU), or the like. Different classes of target devices may constitute heterogeneous systems.
The task queue employed to submit the computing task may be an application programming interface (Application Programming Interface, API) of the runtime system of the target device, which may send task requests to the runtime system of the target device, which may receive the task requests of the user, allocate and manage the task queue, ensuring that the computing task can be properly scheduled to execute on the target device.
First, step S1 is executed, where the target device needs to Process a computing task using its memory for installing a system, a Process (Process) of the target device may send a memory allocation request to a memory allocator, where the memory allocation request may include a memory requirement of the Process, for example, may be a memory size required by the Process. The process of the target device refers to a user program in the target device, which is used for applying for memory allocation and using the memory. The installation system of the target device may include an operating system such as a Linux system, a windows system, and the like, which is not particularly limited herein.
Because the target device submits the calculation task through the task queue, the task queue may also submit the allocation task, so that the memory allocator allocates a suitable memory for the process of the target device, i.e. the task queue includes the allocation task and the calculation task arranged in sequence. Here, the process of the target device may cause the memory allocator to perform the allocation task by sending a memory allocation request to the memory allocator.
After the process of the target device sends the memory allocation request to the memory allocator, the memory allocator receives the memory allocation request sent by the process.
Then, step S2 is executed, where the memory allocator determines the free memory blocks owned by the task queue of the target device. The free memory blocks may include memory blocks used when computing tasks on the task queue are executed and released back to the task queue after use. The task queue may also include a release task after the computing task, and when the release task is performed, the used memory blocks are released back to the task queue, but not directly to the target device's installation system.
And then, the memory allocator selects a first target memory block from the idle memory blocks owned by the task queue for allocation. The first target memory block refers to a memory block that satisfies a memory allocation request, that is, a memory block that satisfies a memory requirement of a process of the target device, and may be the same memory size as a memory required by the process of the target device.
And allocating the first target memory block, namely allocating the first target memory block to a process of the target device sending the memory allocation request, so that the process can process the calculation task in the task queue by using the first target memory block.
It will be appreciated that the memory allocator may be considered a memory allocator having queue semantics because the task queue has first-in, first-out queue semantics.
The memory allocation method provided by the embodiment of the invention firstly receives a memory allocation request sent by a process of target equipment; the target device submits a computing task based on the task queue; and then selecting a first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queue for allocation. The method can ensure that the allocation and the use of the memory blocks have time sequence by means of the first-in first-out semantics of the task queue for submitting the calculation task, and avoid the conflict between the allocation and the use of the same memory block. In addition, the method selects the first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queue for allocation, so that the idle memory blocks can be safely reused in the queue scope, the memory allocation efficiency can be greatly improved, and the memory waste can be avoided.
On the basis of the above embodiment, the memory allocation method further includes:
determining that the first target memory block does not exist in the idle memory blocks or the task queue does not own the idle memory blocks, and sending the memory allocation request to a management system of the memory pool; the memory pool stores a plurality of memory blocks;
receiving a second target memory block provided by the management system based on the memory allocation request;
and distributing the second target memory block.
Specifically, to increase the efficiency of memory block allocation and release on a task queue, a memory pool may be introduced in which multiple memory blocks may be stored. The memory pool can apply for the memory from the installation system of the target equipment through the management system of the memory pool, and the applied memory is divided into a plurality of memory blocks to be constructed. The sizes of the different memory blocks in the memory pool may be the same or different, and are not particularly limited herein.
After receiving a memory allocation request sent by a process of the target device, if the task queue has no free memory block or a first target memory block meeting the memory allocation request in the free memory blocks owned by the task queue, the memory allocator sends the memory allocation request to a management system of the memory pool, wherein the memory allocation request is the same as the memory allocation request sent by the process of the target device to the memory allocator, and all the memory allocation requests comprise the memory requirements of the process of the target device.
And then, the management system of the memory pool can select the memory block meeting the memory allocation request from the memory pool, and if the memory block meeting the memory allocation request exists in the memory pool, the memory block is used as a second target memory block. If the memory block meeting the memory allocation request does not exist in the memory pool, the management system of the memory pool can further request the memory meeting the memory allocation request to the installation system of the target device as a second target memory block, so that the second target memory block is not empty all the time, and a spam scheme is provided for memory allocation.
Thereafter, the management system of the memory pool may provide the second target memory block to the memory allocator, and the process of allocating the second target memory block to the target device sending the memory allocation request through the memory allocator may also directly allocate the second target memory block to the process of sending the target device sending the memory allocation request, which is not specifically limited herein.
In the embodiment of the invention, the memory allocation request is sent to the management system of the memory pool only when the first target memory block is determined to be empty, that is, the task queue does not have the idle memory block meeting the memory allocation request, so that the second target memory block is provided by the management system of the memory pool. The process can give priority to whether the idle memory blocks meeting the memory allocation request exist in the task queue, so that the memory allocation efficiency is improved, the memory blocks can be rapidly allocated and released through the memory pool, and memory fragments can be avoided.
On the basis of the above embodiment, the second target memory block is a memory block in the memory pool that satisfies the memory allocation request;
Or the second target memory block is a memory block allocated to the memory pool by the installation system after the management system sends the memory allocation request to the installation system of the target device under the condition that the second target memory block does not exist in the memory pool.
Specifically, after the management system of the memory pool receives the memory allocation request sent by the memory allocator, the management system of the memory pool preferentially selects a memory block meeting the memory allocation request from the memory pool as a second target memory block for allocation by the memory allocator.
If the management system of the memory pool judges that the memory blocks meeting the memory allocation request do not exist in the memory pool, the memory allocation request is sent to the installation system of the target device, and after the installation system of the target device receives the memory allocation request, the memory blocks meeting the memory allocation request are provided for the memory pool, so that the management system of the memory pool takes the memory blocks provided by the installation system as second target memory blocks for the memory allocator to allocate.
It will be appreciated that in the embodiments of the present invention, the memory involved includes the system memory of the installation system, memory blocks on the memory pool, and memory blocks on the task queue.
The system memory is uniformly managed by the installation system, and all processes in the installation system are shared.
The memory blocks on the memory pool are managed by the management system of the memory pool, and the memory allocation requested by the process of the target device to the memory pool is allocated from the memory allocation.
The memory blocks on the task queue are managed by the memory allocator, so that the repeated application of the idle memory blocks on the task queue can be ensured.
When the memory allocation is performed, the priority of each memory is sequentially from high to low as the free memory block on the task queue, the memory block on the memory pool and the system memory. That is, only if there is no first target memory block satisfying the memory allocation request on the task queue and there is no memory block satisfying the memory allocation request on the memory pool, the memory satisfying the memory allocation request is requested to the installation system through the management system of the memory pool.
In the embodiment of the invention, the proper memory blocks are allocated for the process of the target equipment by considering the priorities of the memories in different positions, the idle memory pool on the task queue is preferably reused, and the memory blocks in the memory pool are used, so that the memory allocation efficiency can be improved, and the problem of low allocation efficiency caused by directly allocating the system memory is avoided.
On the basis of the embodiment, the task queue comprises distributed tasks, calculation tasks and release tasks which are arranged in sequence; selecting a first target memory block meeting the memory allocation request from idle memory blocks owned by the task queue for allocation, wherein the method specifically comprises the following steps:
Executing the allocation task, and selecting the first target memory block from the idle memory blocks owned by the task queue for allocation;
selecting a first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queue for allocation, and then comprising the following steps:
And after the calculation task is executed based on the first target memory block, executing the release task, and releasing the first target memory block as the idle memory block to the task queue.
In particular, the task queue may include assigned tasks, computing tasks, and release tasks in a sequential order.
And the memory allocator selects a first target memory block from the idle memory blocks owned by the task queue to allocate by executing the allocation task.
If the first target memory block is determined not to be empty, the memory allocator allocates the first target memory block to a process of the target device sending the memory allocation request, so that the process of the target device performs a computing task by using the first target memory block.
After the calculation task is finished based on the first target memory block, the memory allocator executes a release task, and releases the first target memory block as an idle memory block to the task queue.
Therefore, the allocation and the release of the memory blocks are respectively provided with the tasks in the task queue, and the conflict between the allocation and the release of the memory blocks can be avoided.
On the basis of the embodiment, the number of the task queues is a plurality of task queues;
Selecting a first target memory block meeting the memory allocation request from idle memory blocks owned by the task queue for allocation, and specifically including:
And selecting a first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queues corresponding to the memory allocation request to allocate.
In particular, the number of task queues may include a plurality, i.e., the target device may submit different computing tasks synchronously based on the plurality of task queues.
At this time, the memory allocation requests are in one-to-one correspondence with the task queues. Step S2 may specifically select, from the idle memory blocks owned by the task queues corresponding to the memory allocation request, a first target memory block that satisfies the memory allocation request to allocate, so that conflicts in use of the idle memory blocks in different task queues may be avoided.
On the basis of the embodiment, the number of the task queues is multiple, and task dependency relations are arranged among the task queues;
Selecting a first target memory block meeting the memory allocation request from idle memory blocks owned by the task queue for allocation, and specifically including:
And selecting a memory block meeting the memory allocation request from the idle memory blocks owned by the task queues as the first target memory block for allocation.
Specifically, when the number of task queues includes a plurality of task dependency relationships among the task queues, step S2 may further select, from the idle memory blocks owned by the task queues, a memory block that meets the memory requirement of the process of the target device as the first target memory block for allocation.
It will be appreciated that the Task dependency relationship between the Task queues may be implemented by adding a record instruction of an event (event) and a wait instruction in each Task queue, that is, as shown in fig. 2, there is a first Task queue (queue 0) and a second Task queue (queue 1), where the first Task queue includes a plurality of tasks, that is, task0 (Task 0), task1 (Task 1), task2 (Task 2), and Task3 (Task 3), and the record instruction of the event is added in the first Task queue. A wait instruction for an event is added to the second Task queue, after which Task4 is added to the second Task queue (Task 4).
And introducing events into the first task queue and the second task queue, and determining task dependency relationship between the first task queue and the second task queue through a recording instruction and a waiting instruction of the events, namely, when the recording instruction of the events in the first task queue is executed, the previous task 0, task 1, task 2 and task 3 are all executed.
When the waiting instruction of the event in the second task queue is executed, the instruction is waited until the execution of the task 3 is completed, and then the task 4 can be executed, so that the task 4 can be ensured to be executed after the task 3, and the task dependency relationship between the first task queue and the second task queue is obtained, namely, the tasks 1 to 4 are executed sequentially.
Therefore, due to the fact that task dependency relations exist among the task queues, after the memory allocation request sent by the process of the target device is received, idle memory blocks owned by the task queues can be used for being allocated to the process of the target device. Therefore, it can be determined whether there is a memory block capable of satisfying the memory allocation request in the idle memory blocks owned by each task queue, and if so, it can be allocated as the first target memory block. If no memory block capable of meeting the memory allocation request exists in the idle memory blocks owned by all the task queues, namely the first target memory block is empty, the memory allocation request can be sent to a management system of the memory pool.
In the embodiment of the invention, because the task dependency relationship exists among the task queues, the idle memory blocks owned by the task queues can be used for being distributed to the process of the target equipment, the range and the number of the idle memory blocks can be further enlarged, the proper memory blocks can be conveniently and rapidly found and distributed, and the memory distribution efficiency is improved.
On the basis of the above embodiment, the memory allocation request includes a memory size required by a process of the target device;
The first target memory block is a memory block with the same size as the memory in the idle memory block.
Specifically, in the embodiment of the present invention, since the memory allocation request may be a memory size required by a process of the target device, the first target memory block satisfying the memory allocation request may be a memory block having the same memory size as that required by the process of the target device in the memory allocation request, that is, a memory block having the same memory size as that required by the process of the target device needs to be selected as the first target memory block in the idle memory blocks owned by the task queue of the target device.
According to the method, through the memory size required by the process of the target equipment, the first target memory block matched with the memory size is selected from the idle memory blocks in the task queue of the target equipment to be allocated, so that the idle memory blocks can be safely reused in the queue acting domain, the memory allocation efficiency can be greatly improved, and the memory waste can be avoided.
On the basis of the above embodiment, as shown in fig. 3, in the memory allocation method provided in the embodiment of the present invention, the memory involved includes a system memory of an installation system of the target device, a memory block on the memory pool, and a memory block on the task queue. At the time of memory pool creation, the management system of the memory pool may request allocation of a certain amount of system memory from the installation system of the target device, as indicated by arrow 1 in fig. 3.
The implementation flow of the memory allocation method provided by the embodiment of the invention comprises the following steps:
in a first step, a process of a target device sends a memory allocation request to a memory allocator, where the memory allocation request may include a memory requirement of the process of the target device.
And secondly, searching an idle memory block which is not released to the memory pool in a task queue corresponding to the memory allocation request by the memory allocator, judging whether the idle memory block exists or not, and under the condition that the idle memory block exists, releasing the idle memory block to meet the memory allocation request, and if the idle memory block meets the memory allocation request, directly allocating the memory block from the task queue. For example, the three processes of the target device respectively send the memory allocation requests to the memory allocator, and the memory allocator may directly allocate the memory allocation requests from the task queues corresponding to the respective memory allocation requests. As shown in fig. 3, arrows 2, 3, 4 represent direct allocation from the corresponding task queues, respectively.
And thirdly, if no free memory block exists in the task queue corresponding to the memory allocation request or the existing free memory block does not meet the memory allocation request, the memory allocator continues to send the memory allocation request to the management system of the memory pool so as to request the memory block from the memory pool.
If the management system of the memory pool determines that there is a memory block in the memory pool that meets the memory allocation requirement, it is provided to the memory allocator to cause the memory allocator to allocate it to the process of the target device. Here, the memory blocks allocated for the processes of the target device come from a memory pool, as indicated by arrow 5 in fig. 3.
Fourth, if the management system of the memory pool determines that there is no memory block satisfying the memory allocation requirement in the memory pool, the management system of the memory pool may continue to send a memory allocation request to the installation system of the target device, search the memory block satisfying the memory allocation request in the system memory through the installation system, and then allocate the memory block to the process of the target device through the memory pool by the memory allocator. As indicated by arrow 1 in fig. 3.
And fifthly, releasing the allocated memory blocks, namely moving the memory blocks used up by the process of the target device to the corresponding task queues, as shown by arrows 7,8 and 9 in fig. 3.
The memory allocation and release actions in the first to fifth steps can be repeated, and the memory allocator allocates the memory in the idle memory blocks owned by the task queues first, so that the purpose of reusing the memory can be achieved.
And since memory blocks can be allocated from the memory pool, allocation efficiency can be improved, and since a typical application scenario is to allocate and release memory blocks in a series of asynchronous interface calls, allocation and release tasks must be guaranteed to be completed within a suitable time period.
Sixth, when all the memory blocks owned by the task queue are idle memory blocks, then all the memory blocks owned by the task queue can be released to the memory pool to become unoccupied memory pool memory, as indicated by arrow 11 in fig. 3.
And seventh, if all the memory blocks in the memory pool are used, i.e. all the memory blocks are unoccupied, releasing all the memory blocks in the memory pool to the installation system to become unoccupied system memory, i.e. as shown by arrow 10 in fig. 3.
In summary, in the embodiment of the present invention, by considering the priorities of the memories in different locations, a suitable memory block is allocated to the process of the target device, and the idle memory pool on the task queue is preferably reused, and then the use of the memory block in the memory pool is considered, and finally the system memory of the installation system is used as a pocket, so that not only can the reuse of the memory be realized, but also the memory resource can be saved, the memory allocation efficiency can be improved, and the problems of low allocation efficiency and high cost caused by directly allocating the system memory can be avoided.
As shown in fig. 4, based on the above embodiment, an embodiment of the present invention provides a memory allocation apparatus, including:
a request receiving module 41, configured to receive a memory allocation request sent by a process of a target device;
The memory allocation module 42 is configured to select, from the idle memory blocks owned by the task queue of the target device, a first target memory block that satisfies the memory allocation request for allocation;
The idle memory blocks comprise memory blocks released after use on the task queue.
Based on the foregoing embodiments, the memory allocation device provided in the embodiments of the present invention, the memory allocation module is further configured to:
determining that the first target memory block does not exist in the idle memory blocks or the task queue does not own the idle memory blocks, and sending the memory allocation request to a management system of the memory pool; the memory pool stores a plurality of memory blocks;
receiving a second target memory block provided by the management system based on the memory allocation request;
and distributing the second target memory block.
Based on the foregoing embodiment, in the memory allocation device provided in the embodiment of the present invention, the second target memory block is a memory block in the memory pool that satisfies the memory allocation request; or alternatively
And under the condition that the second target memory block does not exist in the memory pool, the management system sends the memory allocation request to the installation system of the target equipment, and then the installation system allocates the memory block for the memory pool.
On the basis of the above embodiment, the memory allocation device provided in the embodiment of the present invention, the task queue includes allocation tasks, calculation tasks and release tasks that are arranged in sequence;
the memory allocation module is further specifically configured to:
Executing the allocation task, and selecting the first target memory block from the idle memory blocks owned by the task queue for allocation;
And after the calculation task is executed based on the first target memory block, executing the release task, and releasing the first target memory block as the idle memory block to the task queue.
Based on the above embodiment, the memory allocation device provided in the embodiment of the present invention has a plurality of task queues;
the memory allocation module is further specifically configured to:
And selecting a first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queues corresponding to the memory allocation request to allocate.
Based on the above embodiment, in the memory allocation device provided in the embodiment of the present invention, the number of the task queues is plural, and task dependencies are provided between the plural task queues;
the memory allocation module is further specifically configured to:
And selecting a memory block meeting the memory allocation request from the idle memory blocks owned by the task queues as the first target memory block for allocation.
Based on the above embodiments, the memory allocation device provided in the embodiments of the present invention, where the memory allocation request includes a memory size required by a process of the target device;
The first target memory block is a memory block with the same size as the memory in the idle memory block.
Specifically, the functions of each module in the memory allocation device provided in the embodiment of the present invention are in one-to-one correspondence with the operation flows of each step in the method embodiment, and the achieved effects are consistent.
Fig. 5 illustrates a physical schematic diagram of an electronic device, as shown in fig. 5, which may include: processor (Processor) 510, communication interface (Communications Interface) 520, memory (Memory) 530, and communication bus 540, wherein Processor 510, communication interface 520, memory 530 complete communication with each other through communication bus 540. Processor 510 may invoke logic instructions in memory 530 to perform the memory allocation methods provided in the embodiments described above.
Further, the logic instructions in the memory 530 described above may be implemented in the form of software functional units and may be stored in a computer-readable storage medium when sold or used as a stand-alone product. Based on such understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the related art or in a part of the technical solution, in the form of a software product stored in a storage medium, including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
In another aspect, the present invention also provides a computer program product, where the computer program product includes a computer program, where the computer program can be stored on a non-transitory computer readable storage medium, and when the computer program is executed by a processor, the computer can perform the memory allocation method provided in the foregoing embodiments.
In yet another aspect, the present invention further provides a non-transitory computer readable storage medium having stored thereon a computer program which, when executed by a processor, is implemented to perform the memory allocation method provided in the above embodiments.
The apparatus embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
From the above description of the embodiments, it will be apparent to those skilled in the art that the embodiments may be implemented by means of software plus necessary general hardware platforms, or of course may be implemented by means of hardware. Based on such understanding, the foregoing technical solution may be embodied essentially or in a part contributing to the related art in the form of a software product, which may be stored in a computer readable storage medium, such as ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform the method described in the respective embodiments or some parts of the embodiments.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and are not limiting; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (10)

1. A memory allocation method, comprising:
Receiving a memory allocation request sent by a process of target equipment;
Selecting a first target memory block meeting the memory allocation request from idle memory blocks owned by a task queue of the target equipment to allocate;
The idle memory blocks comprise memory blocks released after use on the task queue.
2. The memory allocation method according to claim 1, further comprising:
Determining that the first target memory block does not exist in the idle memory blocks or the task queue does not own the idle memory blocks, and sending the memory allocation request to a management system of a memory pool; the memory pool stores a plurality of memory blocks;
receiving a second target memory block provided by the management system based on the memory allocation request;
and distributing the second target memory block.
3. The memory allocation method according to claim 2, wherein the second target memory block is a memory block in the memory pool that satisfies the memory allocation request;
Or the second target memory block is a memory block allocated to the memory pool by the installation system after the management system sends the memory allocation request to the installation system of the target device under the condition that the second target memory block does not exist in the memory pool.
4. A memory allocation method according to any one of claims 1 to 3, wherein the task queue comprises allocation tasks, calculation tasks and release tasks arranged in order; selecting a first target memory block meeting the memory allocation request from idle memory blocks owned by the task queue for allocation, wherein the method specifically comprises the following steps:
Executing the allocation task, and selecting the first target memory block from the idle memory blocks owned by the task queue for allocation;
selecting a first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queue for allocation, and then comprising the following steps:
And after the calculation task is executed based on the first target memory block, executing the release task, and releasing the first target memory block as the idle memory block to the task queue.
5. The memory allocation method according to any one of claims 1 to 3, wherein the number of the task queues is plural;
Selecting a first target memory block meeting the memory allocation request from idle memory blocks owned by the task queue for allocation, and specifically including:
And selecting a first target memory block meeting the memory allocation request from the idle memory blocks owned by the task queues corresponding to the memory allocation request to allocate.
6. The memory allocation method according to any one of claims 1 to 3, wherein the number of the task queues is plural, and task dependencies are provided among the plural task queues;
Selecting a first target memory block meeting the memory allocation request from idle memory blocks owned by the task queue for allocation, and specifically including:
And selecting a memory block meeting the memory allocation request from the idle memory blocks owned by the task queues as the first target memory block for allocation.
7. A memory allocation method according to any one of claims 1-3, wherein the memory allocation request comprises a memory size required by a process of the target device;
The first target memory block is a memory block with the same size as the memory in the idle memory block.
8. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the memory allocation method of any of claims 1-7 when the computer program is executed by the processor.
9. A non-transitory computer readable storage medium having stored thereon a computer program, which when executed by a processor implements the memory allocation method according to any of claims 1-7.
10. A computer program product comprising a computer program which, when executed by a processor, implements the memory allocation method according to any one of claims 1-7.
CN202410518880.5A 2024-04-26 2024-04-26 Memory allocation method and device, electronic equipment and storage medium Pending CN118210632A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410518880.5A CN118210632A (en) 2024-04-26 2024-04-26 Memory allocation method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410518880.5A CN118210632A (en) 2024-04-26 2024-04-26 Memory allocation method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN118210632A true CN118210632A (en) 2024-06-18

Family

ID=91456345

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410518880.5A Pending CN118210632A (en) 2024-04-26 2024-04-26 Memory allocation method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN118210632A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118363542A (en) * 2024-06-19 2024-07-19 上海燧原科技股份有限公司 Dynamic storage management method, device, equipment and medium during task running

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118363542A (en) * 2024-06-19 2024-07-19 上海燧原科技股份有限公司 Dynamic storage management method, device, equipment and medium during task running

Similar Documents

Publication Publication Date Title
EP3786793B1 (en) Task processing method and device, and computer system
US9875139B2 (en) Graphics processing unit controller, host system, and methods
WO2022247105A1 (en) Task scheduling method and apparatus, computer device and storage medium
CN109240825B (en) Elastic task scheduling method, device, equipment and computer readable storage medium
KR102338849B1 (en) Method and system for providing stack memory management in real-time operating systems
US8032884B2 (en) Thread hand off
US20090260008A1 (en) Virtual machine management system and method for managing processor resources thereof
US20170344398A1 (en) Accelerator control device, accelerator control method, and program storage medium
US20160371123A1 (en) Data Processing Method and Apparatus
CN110162397B (en) Resource allocation method, device and system
Amert et al. Timewall: Enabling time partitioning for real-time multicore+ accelerator platforms
CN118210632A (en) Memory allocation method and device, electronic equipment and storage medium
US9740530B2 (en) Decreasing the priority of a user based on an allocation ratio
CN112286688A (en) Memory management and use method, device, equipment and medium
CN115509704A (en) Task scheduling method, device, equipment and storage medium
US20150212859A1 (en) Graphics processing unit controller, host system, and methods
CN114721818A (en) Kubernetes cluster-based GPU time-sharing method and system
US9367326B2 (en) Multiprocessor system and task allocation method
CN110175078B (en) Service processing method and device
CN117311939A (en) Client request processing method, computing device and storage medium
WO2021253875A1 (en) Memory management method and related product
CN115878910A (en) Line query method, device and storage medium
CN114816741A (en) GPU resource management method, device and system and readable storage medium
CN113268356A (en) LINUX system-based multi-GPU board card bounding system, method and medium
CN112948069A (en) Method for operating a computing unit

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination