CN112650577A - Memory management method and device - Google Patents

Memory management method and device Download PDF

Info

Publication number
CN112650577A
CN112650577A CN201910966469.3A CN201910966469A CN112650577A CN 112650577 A CN112650577 A CN 112650577A CN 201910966469 A CN201910966469 A CN 201910966469A CN 112650577 A CN112650577 A CN 112650577A
Authority
CN
China
Prior art keywords
memory
memory block
block
size
blocks
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
CN201910966469.3A
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.)
Loongson Technology Corp Ltd
Original Assignee
Loongson Technology Corp 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 Loongson Technology Corp Ltd filed Critical Loongson Technology Corp Ltd
Priority to CN201910966469.3A priority Critical patent/CN112650577A/en
Publication of CN112650577A publication Critical patent/CN112650577A/en
Pending legal-status Critical Current

Links

Images

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

Abstract

The invention provides a memory management method and a memory management device, wherein the memory management method comprises the following steps: acquiring a memory allocation request, wherein the memory allocation request is used for applying for a memory; allocating memory blocks to be used in the memory area according to the memory allocation request, and generating memory management information of the memory blocks to be used; the memory block to be used is aligned in address and size; storing memory management information of a memory block to be used into a preset memory block; the preset memory block is not overlapped with the memory area and is used for storing the memory management information of the memory block in the memory area. By storing the memory management information of the memory block in a centralized manner, the integrity and the continuity of the managed memory area are ensured, and the utilization rate of the memory area is improved.

Description

Memory management method and device
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a memory management method and apparatus.
Background
A Real Time Operating System (RTOS) is an Operating System that can accept and process external events or data at a fast enough speed, and the processing result can control the production process or make a fast response to the processing System within a specified Time, schedule all available resources to complete Real-Time tasks, and control all Real-Time tasks to run in a coordinated and consistent manner. Providing timely response and high reliability are the main features of real-time operating systems.
In memory management of a real-time operating system, allocation of memory blocks generally needs to satisfy address alignment and size alignment, and management overhead of the memory blocks needs to be recorded.
At present, the management overhead of a memory block and a memory block is stored in the same continuous memory area, which causes a large amount of memory fragments to be generated when memory blocks with aligned addresses and aligned sizes are allocated, and reduces the utilization rate of the memory.
Disclosure of Invention
The invention provides a memory management method and device, which avoid memory fragments and improve the utilization rate of a memory area.
In a first aspect, the present invention provides a memory management method, including:
acquiring a memory allocation request, wherein the memory allocation request is used for applying for a memory;
allocating the memory blocks to be used in the memory area according to the memory allocation request, and generating memory management information of the memory blocks to be used; the memory area addresses are continuous, and the addresses and the sizes of the memory blocks to be used are aligned;
storing the memory management information of the memory block to be used into a preset memory block; the preset memory block is not overlapped with the memory area and is used for storing the memory management information of the memory block in the memory area.
Optionally, the allocating, according to the memory allocation request, the memory blocks to be used in the memory area includes:
performing memory segmentation on the memory area according to the size of a unit memory block of the memory area to obtain N first memory blocks; the N first memory blocks are aligned in block address and size, and N is a positive integer; wherein a size/location of the first memory blockThe size of the unit memory block is a power of 2,
Figure BDA0002230653090000021
Figure BDA0002230653090000022
if at least one idle first memory block exists in the N first memory blocks, allocating one idle first memory block as the memory block to be used.
Optionally, the address and size of the memory region are aligned, and the memory partitioning is performed on the memory region according to the size of the unit memory block of the memory region to obtain N first memory blocks, including:
averagely dividing the memory area to obtain two first-stage memory blocks with the same size;
judging whether the quotient of the size of the first-level memory block divided by the size of the memory applied by the memory allocation request is greater than 1;
if the number of the first-level memory blocks is greater than 1, the steps of averagely dividing and judging are performed on at least one first-level memory block until the quotient of the size of the memory block obtained by dividing by the size of the memory applied for the memory allocation request is equal to 1, and the memory block obtained by dividing is determined as the N first memory blocks.
Optionally, the method further includes:
acquiring a memory release request, wherein the memory release request is used for requesting to release the memory blocks occupied in the memory area;
and releasing the occupied memory block according to the memory release request.
Optionally, the method further includes:
judging whether a partner memory block of the occupied memory block is idle or not; the partner memory block of the occupied memory block and the occupied memory block are obtained by performing memory segmentation on the same memory block, or the partner memory block of the occupied memory block and the occupied memory block are memory blocks with adjacent addresses;
if the merged memory block is idle, performing memory merging on the occupied memory block and a partner memory block of the occupied memory block to obtain the merged memory block, and repeatedly executing the step of memory merging on the merged memory block until the memory merging cannot be performed, obtaining the merged memory block, and generating memory management information of the merged memory block;
and storing the memory management information of the merged memory block into the preset memory block.
Optionally, the memory management information of the memory block includes: the index value of the memory block, the idle indication information and the size of the memory block; wherein the idle indication information is used to indicate whether the memory block is idle.
Optionally, the memory management information of the memory block further includes an index value of a partner memory block of the memory block; the partner memory block of the memory block and the memory block are obtained by performing memory segmentation on the same memory block, or the partner memory block of the memory block and the memory block are memory blocks with adjacent addresses.
Optionally, the method further includes:
acquiring an index value of a memory block to be queried;
and obtaining the memory address of the memory block to be queried according to the index value of the memory block to be queried and the corresponding relation between the index value and the memory address.
Optionally, the method further includes:
acquiring a memory address to be inquired;
and obtaining the index value of the memory block corresponding to the memory address to be inquired according to the memory address to be inquired and the corresponding relation between the index value and the memory address.
In a second aspect, the present invention provides a memory management device, including:
the device comprises an acquisition module, a storage allocation module and a processing module, wherein the acquisition module is used for acquiring a storage allocation request which is used for applying for a storage;
the management module is used for allocating the memory blocks to be used in the memory area according to the memory allocation request and generating memory management information of the memory blocks to be used; the memory area addresses are continuous, and the addresses and the sizes of the memory blocks to be used are aligned;
the memory module is used for storing the memory management information of the memory block to be used into a preset memory block; the preset memory block is not overlapped with the memory area and is used for storing the memory management information of the memory block in the memory area.
Optionally, the management module is specifically configured to:
performing memory segmentation on the memory area according to the size of a unit memory block of the memory area to obtain N first memory blocks; the N first memory blocks are aligned in block address and size, and N is a positive integer; wherein the size of the first memory block/the size of the unit memory block is a power of 2,
Figure BDA0002230653090000031
Figure BDA0002230653090000032
if at least one idle first memory block exists in the N first memory blocks, allocating one idle first memory block as the memory block to be used.
Optionally, the memory area addresses are aligned and the sizes are aligned, and the management module is specifically configured to:
averagely dividing the memory area to obtain two first-stage memory blocks with the same size;
judging whether the quotient of the size of the first-level memory block divided by the size of the memory applied by the memory allocation request is greater than 1;
if the number of the first-level memory blocks is greater than 1, the steps of averagely dividing and judging are performed on at least one first-level memory block until the quotient of the size of the memory block obtained by dividing by the size of the memory applied for the memory allocation request is equal to 1, and the memory block obtained by dividing is determined as the N first memory blocks.
Optionally, the obtaining module is further configured to obtain a memory release request, where the memory release request is used to request to release an occupied memory block in the memory area;
the management module is further configured to release the occupied memory block according to the memory release request.
Optionally, the management module is further configured to:
judging whether a partner memory block of the occupied memory block is idle or not; the partner memory block of the occupied memory block and the occupied memory block are obtained by performing memory segmentation on the same memory block, or the partner memory block of the occupied memory block and the occupied memory block are memory blocks with adjacent addresses;
if the merged memory block is idle, performing memory merging on the occupied memory block and a partner memory block of the occupied memory block to obtain the merged memory block, and repeatedly executing the step of memory merging on the merged memory block until the memory merging cannot be performed, obtaining the merged memory block, and generating memory management information of the merged memory block;
and storing the memory management information of the merged memory block into the preset memory block.
Optionally, the memory management information of the memory block includes: the index value of the memory block, the idle indication information and the size of the memory block; wherein the idle indication information is used to indicate whether the memory block is idle.
Optionally, the memory management information of the memory block further includes an index value of a partner memory block of the memory block; the partner memory block of the memory block and the memory block are obtained by performing memory segmentation on the same memory block, or the partner memory block of the memory block and the memory block are memory blocks with adjacent addresses.
Optionally, the obtaining module is further configured to obtain an index value of the memory block to be queried;
the management module is further configured to obtain the memory address of the memory block to be queried according to the index value of the memory block to be queried and the corresponding relationship between the index value and the memory address.
Optionally, the obtaining module is further configured to obtain a memory address to be queried;
the management module is further configured to obtain an index value of the memory block corresponding to the memory address to be queried according to the memory address to be queried and a corresponding relationship between the index value and the memory address.
In a third aspect, the present invention provides a memory management device, including: a processor and a memory;
the memory to store instructions;
the processor is configured to execute the instructions stored in the memory to execute the memory management method provided in any embodiment of the present invention.
In a fourth aspect, the present invention provides a storage medium comprising: the memory management method comprises a readable storage medium and a computer program, wherein the computer program is used for realizing the memory management method provided by any embodiment of the invention.
The invention provides a memory management method and a memory management device, which are used for allocating memory blocks to be used in a memory area according to a memory allocation request, generating memory management information of the memory blocks to be used and storing the memory management information of the memory blocks to be used in a preset memory block. The preset memory block is not overlapped with the memory area and is used for storing the memory management information of the memory block in the memory area. By storing the memory management information of the memory blocks in the memory area in a centralized manner, the integrity and the continuity of the managed memory area are ensured, memory fragments are avoided in the memory allocation process, and the utilization rate of the memory area is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
FIG. 1 is a schematic diagram illustrating a location of a conventional memory block;
fig. 2 is a flowchart of a memory management method according to an embodiment of the present invention;
FIG. 3 is a schematic diagram illustrating a location of a memory block according to an embodiment of the present invention;
FIG. 4 is a schematic diagram illustrating another location of a memory block according to an embodiment of the present invention;
fig. 5 is a schematic diagram illustrating a memory partition performed on a memory area according to an embodiment of the present invention;
fig. 6 is a schematic diagram illustrating merging of memory regions according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of a memory management device according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of a memory management device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In memory management of a real-time operating system, allocation of memory blocks generally needs to satisfy address alignment and size alignment, and management overhead of the memory blocks needs to be recorded. The memory block and the management overhead of the memory block are stored in the same continuous memory area. For example, fig. 1 is a schematic location diagram of a conventional memory block. In fig. 1, the memory block 11 and the memory block 12 have consecutive addresses. The memory chunks 12 are allocated memory chunks, the memory chunks 12 being address aligned and size aligned. The memory block 11 stores management overhead of the memory block 12. Similarly, the memory block 14 is an allocated memory block, addresses of the memory blocks are aligned, and sizes of the memory blocks are aligned, and the memory block 13 stores management overhead of the memory block 14. The memory chunks between the memory chunks 12 and 13 are unallocated memory chunks. It can be seen that, since the management overheads of the memory blocks and the memory blocks are stored in the memory areas with continuous addresses, the memory blocks storing the management overheads, the allocated memory blocks, and the unallocated memory blocks are arranged at intervals, and the unallocated memory blocks may not be address aligned or size aligned, so that a large amount of memory fragments exist, and the memory utilization rate is reduced.
In view of the above technical problems, the memory management method provided by the present invention ensures that the managed memory areas are complete and continuous by performing centralized storage on the management overhead of the memory blocks, avoids the generation of memory fragments, and improves the utilization rate of the memory.
The concept of the present invention will be explained below.
(1) Address alignment
Memory address alignment is a way to arrange data in a computer memory and to access the data. When a computer reads and writes data in a memory, the operation is carried out according to a basic unit. For example, in a 32-bit system, 4 bytes (one byte in size) can be read at a time. By address alignment, it is meant that the starting address of the memory block is equal to a multiple of the base unit.
(2) Size alignment
By size aligned, it is meant that the size of the memory block is equal to a multiple of the base unit, and the multiple is a power of 2.
The technical solution of the present invention will be described in detail below with specific examples. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments.
Fig. 2 is a flowchart of a memory management method according to an embodiment of the present invention, and fig. 3 is a schematic diagram of a location of a memory block in a memory allocation process according to an embodiment of the present invention. In the memory management method provided in this embodiment, the execution main body may be a memory management device. As shown in fig. 2 and fig. 3, the memory management method provided in this embodiment may include:
s201, a memory allocation request is obtained, and the memory allocation request is used for applying for a memory.
In this embodiment, the specific content included in the memory allocation request is not limited. Optionally, the memory allocation request may include the size of the memory requested. The memory of the application can be a memory with aligned size, and can also be a memory with non-aligned size. For example, the size of the memory requested may be 4 kbytes, 8 kbytes, 16 kbytes, 32 kbytes, 64 kbytes, 128 kbytes, etc., and at this time, the size of the memory requested is aligned. For another example, the size of the memory requested may be 6 kbytes, 12 kbytes, 48 kbytes, etc., and at this time, the size of the memory requested is not aligned.
In this embodiment, whether the applied memories are aligned in size or not, the memory blocks actually allocated according to the memory allocation request are all the memory blocks aligned in size.
S202, allocating the memory blocks to be used in the memory area according to the memory allocation request, and generating memory management information of the memory blocks to be used.
The memory area addresses are continuous, and the addresses and the sizes of the memory blocks to be used are aligned.
Illustratively, in FIG. 3, the memory region addresses are contiguous. The memory blocks to be used can be the memory blocks 32-34. The memory blocks 32-34 are address aligned and size aligned.
Optionally, the memory regions are address aligned and size aligned.
By setting the memory area to be aligned in address and size, the memory blocks to be used are convenient to allocate, and the memory allocation efficiency is improved.
Optionally, the memory management information of the memory block may include: the index value of the memory block, the idle indication information and the size of the memory block.
The index value of the memory block can uniquely distinguish different memory blocks.
The idle indication information is used for indicating whether the memory block is idle or not. Alternatively, the idle indication information may be 1-bit information. When the idle indication information is 0, the idle indication information is used for indicating that the memory block is idle, and when the idle indication information is 1, the idle indication information is used for indicating that the memory block is occupied.
Optionally, the memory management information of the memory block may further include an index value of a partner memory block of the memory block. The partner memory block and the memory block of the memory block are obtained by performing memory segmentation on the same memory block, or the partner memory block and the memory block of the memory block are memory blocks with adjacent addresses.
The memory management information of the memory block and the partner memory block of the memory block will be described later by way of example in fig. 5 and 6.
S203, storing the memory management information of the memory block to be used into a preset memory block. The preset memory block is not overlapped with the memory area and is used for storing the memory management information of the memory block in the memory area.
For example, in fig. 3, the preset memory block is marked as a memory block 31, and is used to store memory management information of the memory blocks in the memory area, for example, the memory management information of the allocated memory blocks 32 to 34 may be stored. The preset memory block is not overlapped with the memory area, so that the completeness and continuity of the memory area are ensured.
Optionally, the preset memory block and the memory area may have consecutive addresses, for example, as shown in fig. 3. Optionally, the preset memory block and the memory area may also have discontinuous addresses.
Optionally, the preset memory blocks are address-aligned and size-aligned.
In memory management for real-time operating systems, memory allocation is typically both address-aligned and size-aligned. By setting the preset memory blocks to be address aligned and size aligned, address fragments caused by the preset memory blocks are avoided, and the utilization rate of the memory is improved.
It can be seen that the memory management method provided in this embodiment is suitable for a scenario where the addresses of the allocated memory blocks are aligned and the sizes of the allocated memory blocks are aligned, and the memory management information of the memory blocks in the managed memory area is stored in a centralized manner, so that the memory blocks storing the memory management information and the managed memory area are both areas with continuous addresses, thereby ensuring the integrity and continuity of the managed memory area, facilitating the allocation of the memory blocks with aligned addresses and aligned sizes, avoiding the generation of memory fragments, and improving the utilization rate of the memory area.
Optionally, in S202, allocating the memory block to be used in the memory area according to the memory allocation request may include:
and performing memory segmentation on the memory area according to the size of the unit memory block of the memory area to obtain N first memory blocks. The N first memory blocks are aligned in block address and size, and N is a positive integer. Wherein the size of the first memory block/the size of the unit memory block is a power of 2,
Figure BDA0002230653090000081
Figure BDA0002230653090000082
if at least one idle first memory block exists in the N first memory blocks, one of the idle first memory blocks is allocated as a memory block to be used.
This is illustrated in connection with fig. 4. Fig. 4 is a schematic diagram of another position of a memory block according to an embodiment of the present invention. In this example, the size of the memory area is 128 kbytes, and the size of the unit memory block is 4 kbytes.
In the first example, the size of the memory requested by the memory allocation request is 32 kbytes, and the requested memory is size-aligned. The size of the first memory block can be determined to be 32 kbytes according to the size of the memory to which the memory allocation request applies, and the size of the first memory block/the size of the unit memory block is 8. The memory area is divided into 4 first memory blocks, which are separated by a dotted line in fig. 4. Each first memory block is block address aligned and size aligned. Optionally, the first free memory block 42 may be allocated as a memory block to be used according to the order of the addresses of the memory areas. Optionally, any free memory block in the memory area may be allocated as a memory block to be used, for example, the memory block 43.
In a second example, the memory size requested by the memory allocation request is 24 kbytes, and the requested memory is not size-aligned. The size of the first memory block can be determined to be 32 kbytes according to the size of the memory to which the memory allocation request applies, and the size of the first memory block/the size of the unit memory block is 8. For the allocation of the memory blocks, reference may be made to the above-mentioned first example, which has similar principles and is not described herein again.
It can be seen that the first memory block is determined according to the size of the memory applied by the memory allocation request, the memory area is divided into a plurality of first memory blocks, and any idle first memory block is allocated as the memory block to be used, so that the memory blocks to be used are ensured to be address-aligned and size-aligned.
Optionally, the address and size of the memory area are aligned, and performing memory partition on the memory area according to the size of the unit memory block of the memory area to obtain the N first memory blocks may include:
and averagely dividing the memory area to obtain two first-stage memory blocks with the same size.
And judging whether the quotient of the size of the first-level memory block divided by the size of the memory applied by the memory allocation request is greater than 1.
If the memory size is larger than 1, the steps of averagely dividing and judging are carried out on at least one first-level memory block until the quotient of the size of the memory block obtained by dividing the memory size applied by the memory allocation request is equal to 1, and the memory block obtained by dividing the memory block is determined as N first memory blocks.
This is illustrated below in connection with fig. 5. Fig. 5 is a schematic diagram of memory partitioning of a memory area according to an embodiment of the present invention. Assuming that the size of the memory area is 128 kbytes, the size of the unit memory block of the memory area is 4 kbytes, and the size of the memory to which the memory allocation request applies is 4 kbytes, the size of the first memory block is 4 kbytes. The memory area may be divided into 32 first memory blocks. As shown in fig. 5, the memory region is divided equally to obtain 2 first-level memory blocks with the same size. The size of the first level memory block is 64 kbytes. And continuing to perform memory partitioning. And respectively carrying out average segmentation on the first-stage memory blocks to obtain 4 second-stage memory blocks with the same size. The size of the second level memory block is 32 kbytes. And continuing to perform memory partitioning until 32 equal-size fifth-level memory blocks are obtained, wherein the size of the fifth-level memory blocks is 4 Kbytes. Thus, 32 first memory blocks are obtained. Similarly, the memory blocks 52 and 53, 54 and 55, 56 and 57, and 58 and 59 are all partner memory blocks. Optionally, the index value of the unit memory block may be set based on the unit memory block of the memory area. In fig. 5, the index values of the 32 unit memory blocks included in the memory area may be respectively identified as 0 to 31. Optionally, in the process of allocating the memory, the index value of the first unit memory block included in the memory block may be used as the index value of the memory block. It should be noted that the index values of the memory blocks in fig. 5 are merely examples, and the index values of the memory blocks may be set in other manners, which is not limited in this embodiment.
Therefore, the addresses and the sizes of the memory areas are aligned, and the first memory blocks are obtained through continuous average division, so that the addresses and the sizes of the first memory blocks are ensured to be aligned, and the memory allocation is facilitated.
Optionally, the memory management method provided in this embodiment may further include:
and acquiring a memory release request, wherein the memory release request is used for requesting to release the occupied memory blocks in the memory area.
And releasing the occupied memory blocks according to the memory release request.
In this embodiment, the specific content included in the memory release request is not limited. Optionally, the memory release request may include an index value of the occupied memory block.
Optionally, the memory management method provided in this embodiment may further include:
and judging whether the partner memory block of the occupied memory block is idle or not. The partner memory block of the occupied memory block and the occupied memory block are obtained by performing memory partition on the same memory block, or the partner memory block of the occupied memory block and the occupied memory block are memory blocks with adjacent addresses.
And if the merged memory block is idle, performing memory merging on the occupied memory block and a partner memory block of the occupied memory block to obtain the merged memory block, repeating the step of memory merging on the merged memory block until the memory merging cannot be performed, obtaining the merged memory block, and generating memory management information of the merged memory block.
And storing the memory management information of the merged memory block into a preset memory block.
The merging of memory blocks is exemplarily described below with reference to fig. 6. Fig. 6 is a schematic diagram of merging memory regions according to an embodiment of the present invention. It is assumed that the memory block occupied in the memory region for which the memory release request is used to request release is the memory block 64, and the partner memory block of the memory block 64 is the memory block 65. The index value of the memory block 64 is 0 and the index value of the memory block 65 is 4. Assuming that the memory block 65 is idle, the memory block 64 and the memory block 65 may be merged to generate the memory block 62, and the index value of the memory block 62 is 0. The partner memory block of the memory block 62 is the memory block 63. If the memory block 63 is idle, the memory block 62 and the memory block 63 may be merged to generate the memory block 60, and the index value of the memory block 60 is 0. The partner memory block of the memory block 60 is the memory block 61. Assuming that the memory block 61 is not free and is occupied, the memory consolidation is stopped. At this time, the memory management information of the memory block 60 is generated. For example, the memory management information of the memory block 60 may include the following items: index value 0 of the memory block 60, idle indication information indicating that the memory block 60 is idle, size 64 kbytes of the memory block 60, and index value 16 of the partner memory block of the memory block 60.
Optionally, the memory management method provided in this embodiment may further include:
and acquiring the index value of the memory block to be inquired.
And obtaining the memory address of the memory block to be inquired according to the index value of the memory block to be inquired and the corresponding relation between the index value and the memory address.
Optionally, the memory management method provided in this embodiment may further include:
and acquiring the memory address to be inquired.
And obtaining the index value of the memory block corresponding to the memory address to be inquired according to the memory address to be inquired and the corresponding relation between the index value and the memory address.
Specifically, a mapping relationship exists between the index value of the memory block and the memory address, the setting modes of the index value of the memory block are different, and the mapping relationship between the index value of the memory block and the memory address may be different. For example, as shown in fig. 5 and fig. 6, if the index value of the memory block is set based on the unit memory block of the memory area, the mapping relationship between the index value of the memory block and the memory address may be:
formula for converting index number into memory address: memory address ═ initial address of memory region + (size of unit memory index)
Formula of memory address translation index number: index number (memory address-starting address of memory area)/size of unit memory
Through the corresponding relationship between the index value of the memory block and the memory address, the memory address of the memory block can be obtained according to the index value query of the memory block, and the index value of the memory block can also be obtained according to the memory address query of the memory block, so that the memory block can be conveniently searched and managed.
Fig. 7 is a schematic structural diagram of a memory management device according to an embodiment of the present invention. The memory management device provided in this embodiment is configured to execute the memory management method provided in the embodiments shown in fig. 2 to 6. As shown in fig. 7, the memory management device provided in this embodiment may include:
an obtaining module 71, configured to obtain a memory allocation request, where the memory allocation request is used to apply for a memory;
the management module 72 is configured to allocate, according to the memory allocation request, a memory block to be used in a memory area, and generate memory management information of the memory block to be used; the memory area addresses are continuous, and the addresses and the sizes of the memory blocks to be used are aligned;
a storage module 73, configured to store the memory management information of the memory block to be used in a preset memory block; the preset memory block is not overlapped with the memory area and is used for storing the memory management information of the memory block in the memory area.
Optionally, the management module 72 is specifically configured to:
performing memory segmentation on the memory area according to the size of a unit memory block of the memory area to obtain N first memory blocks; the N first memory blocks are aligned in block address and size, and N is a positive integer; wherein the size of the first memory block/the size of the unit memory block is a power of 2,
Figure BDA0002230653090000121
Figure BDA0002230653090000122
if at least one idle first memory block exists in the N first memory blocks, allocating one idle first memory block as the memory block to be used.
Optionally, the memory area addresses are aligned and the sizes are aligned, and the management module 72 is specifically configured to:
averagely dividing the memory area to obtain two first-stage memory blocks with the same size;
judging whether the quotient of the size of the first-level memory block divided by the size of the memory applied by the memory allocation request is greater than 1;
if the number of the first-level memory blocks is greater than 1, the steps of averagely dividing and judging are performed on at least one first-level memory block until the quotient of the size of the memory block obtained by dividing by the size of the memory applied for the memory allocation request is equal to 1, and the memory block obtained by dividing is determined as the N first memory blocks.
Optionally, the obtaining module 71 is further configured to obtain a memory release request, where the memory release request is used to request to release an occupied memory block in the memory area;
the management module 72 is further configured to release the occupied memory block according to the memory release request.
Optionally, the management module 72 is further configured to:
judging whether a partner memory block of the occupied memory block is idle or not; the partner memory block of the occupied memory block and the occupied memory block are obtained by performing memory segmentation on the same memory block, or the partner memory block of the occupied memory block and the occupied memory block are memory blocks with adjacent addresses;
if the merged memory block is idle, performing memory merging on the occupied memory block and a partner memory block of the occupied memory block to obtain the merged memory block, and repeatedly executing the step of memory merging on the merged memory block until the memory merging cannot be performed, obtaining the merged memory block, and generating memory management information of the merged memory block;
and storing the memory management information of the merged memory block into the preset memory block.
Optionally, the memory management information of the memory block includes: the index value of the memory block, the idle indication information and the size of the memory block; wherein the idle indication information is used to indicate whether the memory block is idle.
Optionally, the memory management information of the memory block further includes an index value of a partner memory block of the memory block; the partner memory block of the memory block and the memory block are obtained by performing memory segmentation on the same memory block, or the partner memory block of the memory block and the memory block are memory blocks with adjacent addresses.
Optionally, the obtaining module 71 is further configured to obtain an index value of a memory block to be queried;
the management module 72 is further configured to obtain the memory address of the memory block to be queried according to the index value of the memory block to be queried and the corresponding relationship between the index value and the memory address.
Optionally, the obtaining module 71 is further configured to obtain a memory address to be queried;
the management module 72 is further configured to obtain an index value of the memory block corresponding to the memory address to be queried according to the memory address to be queried and a corresponding relationship between the index value and the memory address.
The memory management device provided in this embodiment is configured to execute the memory management method provided in the embodiments shown in fig. 2 to 6. The technical principle and the technical effect are similar, and the detailed description is omitted here.
Fig. 8 is a schematic structural diagram of a memory management device according to an embodiment of the present invention. As shown in fig. 8, the memory management device provided in this embodiment includes: a processor 81 and a memory 82. The memory 82 for storing instructions; the processor 81 is configured to execute the instructions stored in the storage 82 to execute the memory management method provided in the embodiments shown in fig. 2 to fig. 6. The technical principle and the technical effect are similar, and the detailed description is omitted here.
Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only used for illustrating the technical solutions of the embodiments of the present invention, and are not limited thereto; although embodiments of the present invention have been described in detail with reference to the foregoing embodiments, those skilled in the art will understand that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.

Claims (20)

1. A memory management method, comprising:
acquiring a memory allocation request, wherein the memory allocation request is used for applying for a memory;
allocating the memory blocks to be used in the memory area according to the memory allocation request, and generating memory management information of the memory blocks to be used; the memory area addresses are continuous, and the addresses and the sizes of the memory blocks to be used are aligned;
storing the memory management information of the memory block to be used into a preset memory block; the preset memory block is not overlapped with the memory area and is used for storing the memory management information of the memory block in the memory area.
2. The method according to claim 1, wherein the allocating the memory blocks to be used in the memory area according to the memory allocation request includes:
performing memory segmentation on the memory area according to the size of a unit memory block of the memory area to obtain N first memory blocks; the N first memory blocks are aligned in block address and size, and N is a positive integer; wherein the size of the first memory block/the size of the unit memory block is a power of 2,
Figure FDA0002230653080000011
Figure FDA0002230653080000012
if at least one idle first memory block exists in the N first memory blocks, allocating one idle first memory block as the memory block to be used.
3. The method according to claim 2, wherein the memory region addresses are aligned and sizes are aligned, and the obtaining N first memory blocks by performing memory partition on the memory region according to the size of a unit memory block of the memory region comprises:
averagely dividing the memory area to obtain two first-stage memory blocks with the same size;
judging whether the quotient of the size of the first-level memory block divided by the size of the memory applied by the memory allocation request is greater than 1;
if the number of the first-level memory blocks is greater than 1, the steps of averagely dividing and judging are performed on at least one first-level memory block until the quotient of the size of the memory block obtained by dividing by the size of the memory applied for the memory allocation request is equal to 1, and the memory block obtained by dividing is determined as the N first memory blocks.
4. The method of claim 1, further comprising:
acquiring a memory release request, wherein the memory release request is used for requesting to release the memory blocks occupied in the memory area;
and releasing the occupied memory block according to the memory release request.
5. The method of claim 4, further comprising:
judging whether a partner memory block of the occupied memory block is idle or not; the partner memory block of the occupied memory block and the occupied memory block are obtained by performing memory segmentation on the same memory block, or the partner memory block of the occupied memory block and the occupied memory block are memory blocks with adjacent addresses;
if the merged memory block is idle, performing memory merging on the occupied memory block and a partner memory block of the occupied memory block to obtain the merged memory block, and repeatedly executing the step of memory merging on the merged memory block until the memory merging cannot be performed, obtaining the merged memory block, and generating memory management information of the merged memory block;
and storing the memory management information of the merged memory block into the preset memory block.
6. The method according to any of claims 1 to 5, wherein the memory management information of the memory block comprises: the index value of the memory block, the idle indication information and the size of the memory block; wherein the idle indication information is used to indicate whether the memory block is idle.
7. The method according to claim 6, wherein the memory management information of the memory chunk further includes an index value of a partner memory chunk of the memory chunk; the partner memory block of the memory block and the memory block are obtained by performing memory segmentation on the same memory block, or the partner memory block of the memory block and the memory block are memory blocks with adjacent addresses.
8. The method of claim 6, further comprising:
acquiring an index value of a memory block to be queried;
and obtaining the memory address of the memory block to be queried according to the index value of the memory block to be queried and the corresponding relation between the index value and the memory address.
9. The method of claim 6, further comprising:
acquiring a memory address to be inquired;
and obtaining the index value of the memory block corresponding to the memory address to be inquired according to the memory address to be inquired and the corresponding relation between the index value and the memory address.
10. A memory management device, comprising:
the device comprises an acquisition module, a storage allocation module and a processing module, wherein the acquisition module is used for acquiring a storage allocation request which is used for applying for a storage;
the management module is used for allocating the memory blocks to be used in the memory area according to the memory allocation request and generating memory management information of the memory blocks to be used; the memory area addresses are continuous, and the addresses and the sizes of the memory blocks to be used are aligned;
the memory module is used for storing the memory management information of the memory block to be used into a preset memory block; the preset memory block is not overlapped with the memory area and is used for storing the memory management information of the memory block in the memory area.
11. The apparatus of claim 10, wherein the management module is specifically configured to:
performing memory segmentation on the memory area according to the size of a unit memory block of the memory area to obtain N first memory blocks; the N first memory blocks are aligned in block address and size, and N is a positive integer; wherein the size of the first memory block/the size of the unit memory block is a power of 2,
Figure FDA0002230653080000031
Figure FDA0002230653080000032
if at least one idle first memory block exists in the N first memory blocks, allocating one idle first memory block as the memory block to be used.
12. The apparatus of claim 11, wherein the memory regions are address aligned and size aligned, and wherein the management module is specifically configured to:
averagely dividing the memory area to obtain two first-stage memory blocks with the same size;
judging whether the quotient of the size of the first-level memory block divided by the size of the memory applied by the memory allocation request is greater than 1;
if the number of the first-level memory blocks is greater than 1, the steps of averagely dividing and judging are performed on at least one first-level memory block until the quotient of the size of the memory block obtained by dividing by the size of the memory applied for the memory allocation request is equal to 1, and the memory block obtained by dividing is determined as the N first memory blocks.
13. The apparatus of claim 10,
the obtaining module is further configured to obtain a memory release request, where the memory release request is used to request to release an occupied memory block in the memory area;
the management module is further configured to release the occupied memory block according to the memory release request.
14. The apparatus of claim 13, wherein the management module is further configured to:
judging whether a partner memory block of the occupied memory block is idle or not; the partner memory block of the occupied memory block and the occupied memory block are obtained by performing memory segmentation on the same memory block, or the partner memory block of the occupied memory block and the occupied memory block are memory blocks with adjacent addresses;
if the merged memory block is idle, performing memory merging on the occupied memory block and a partner memory block of the occupied memory block to obtain the merged memory block, and repeatedly executing the step of memory merging on the merged memory block until the memory merging cannot be performed, obtaining the merged memory block, and generating memory management information of the merged memory block;
and storing the memory management information of the merged memory block into the preset memory block.
15. The apparatus according to any of claims 10 to 14, wherein the memory management information of the memory block comprises: the index value of the memory block, the idle indication information and the size of the memory block; wherein the idle indication information is used to indicate whether the memory block is idle.
16. The apparatus according to claim 15, wherein the memory management information of the memory chunk further includes an index value of a partner memory chunk of the memory chunk; the partner memory block of the memory block and the memory block are obtained by performing memory segmentation on the same memory block, or the partner memory block of the memory block and the memory block are memory blocks with adjacent addresses.
17. The apparatus of claim 15,
the obtaining module is further configured to obtain an index value of the memory block to be queried;
the management module is further configured to obtain the memory address of the memory block to be queried according to the index value of the memory block to be queried and the corresponding relationship between the index value and the memory address.
18. The apparatus of claim 15,
the acquisition module is also used for acquiring a memory address to be inquired;
the management module is further configured to obtain an index value of the memory block corresponding to the memory address to be queried according to the memory address to be queried and a corresponding relationship between the index value and the memory address.
19. A memory management device, comprising: a processor and a memory;
the memory to store instructions;
the processor, configured to execute instructions stored in the memory to perform the memory management method according to any one of claims 1 to 9.
20. A storage medium, comprising: readable storage medium and computer program for implementing a memory management method according to any of claims 1 to 9.
CN201910966469.3A 2019-10-12 2019-10-12 Memory management method and device Pending CN112650577A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910966469.3A CN112650577A (en) 2019-10-12 2019-10-12 Memory management method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910966469.3A CN112650577A (en) 2019-10-12 2019-10-12 Memory management method and device

Publications (1)

Publication Number Publication Date
CN112650577A true CN112650577A (en) 2021-04-13

Family

ID=75343555

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910966469.3A Pending CN112650577A (en) 2019-10-12 2019-10-12 Memory management method and device

Country Status (1)

Country Link
CN (1) CN112650577A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113076266A (en) * 2021-06-04 2021-07-06 深圳华云信息系统有限公司 Memory management method and device, electronic equipment and storage medium
CN113312522A (en) * 2021-06-30 2021-08-27 科东(广州)软件科技有限公司 Management method and device of kernel object, storage medium and electronic equipment
CN117194055A (en) * 2023-11-06 2023-12-08 西安芯云半导体技术有限公司 GPU video memory application and release method, device and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1567249A (en) * 2003-06-16 2005-01-19 华为技术有限公司 Internal memory managerial approach for computer system
CN104317734A (en) * 2014-11-28 2015-01-28 迈普通信技术股份有限公司 Memory allocation method and device applicable to SLAB
CN107977265A (en) * 2016-10-25 2018-05-01 中兴通讯股份有限公司 Internal memory initialization method, apparatus and memory allocation method, device
US20180267892A1 (en) * 2018-05-21 2018-09-20 Williams Ludwell Harrison, III Process for buddy allocation
CN109308269A (en) * 2017-07-26 2019-02-05 华为技术有限公司 A kind of EMS memory management process and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1567249A (en) * 2003-06-16 2005-01-19 华为技术有限公司 Internal memory managerial approach for computer system
CN104317734A (en) * 2014-11-28 2015-01-28 迈普通信技术股份有限公司 Memory allocation method and device applicable to SLAB
CN107977265A (en) * 2016-10-25 2018-05-01 中兴通讯股份有限公司 Internal memory initialization method, apparatus and memory allocation method, device
CN109308269A (en) * 2017-07-26 2019-02-05 华为技术有限公司 A kind of EMS memory management process and device
US20180267892A1 (en) * 2018-05-21 2018-09-20 Williams Ludwell Harrison, III Process for buddy allocation

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
万国春 等编著: "系统芯片(SOC)设计方法与实践", vol. 1, 北京航空航天大学出版社, pages: 287 - 124 *

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113076266A (en) * 2021-06-04 2021-07-06 深圳华云信息系统有限公司 Memory management method and device, electronic equipment and storage medium
CN113076266B (en) * 2021-06-04 2021-10-29 深圳华云信息系统有限公司 Memory management method and device, electronic equipment and storage medium
CN113312522A (en) * 2021-06-30 2021-08-27 科东(广州)软件科技有限公司 Management method and device of kernel object, storage medium and electronic equipment
CN113312522B (en) * 2021-06-30 2022-01-11 科东(广州)软件科技有限公司 Management method and device of kernel object, storage medium and electronic equipment
CN117194055A (en) * 2023-11-06 2023-12-08 西安芯云半导体技术有限公司 GPU video memory application and release method, device and storage medium
CN117194055B (en) * 2023-11-06 2024-03-08 西安芯云半导体技术有限公司 GPU video memory application and release method, device and storage medium

Similar Documents

Publication Publication Date Title
CN112650577A (en) Memory management method and device
US20140068211A1 (en) Converting a first address mapping function for mapping addresses to storage locations to a second address mapping function
CN109690498B (en) Memory management method and equipment
CN107066498B (en) Key value KV storage method and device
CN103577345A (en) Methods and structure for improved flexibility in shared storage caching by multiple systems
US8943108B2 (en) Hardware off-load memory garbage collection acceleration
KR101460062B1 (en) System for storing distributed video file in HDFS(Hadoop Distributed File System), video map-reduce system and providing method thereof
CN109144406B (en) Metadata storage method, system and storage medium in distributed storage system
US20140310498A1 (en) Organization of a small object area and a large object area in a java heap
US10073648B2 (en) Repartitioning data in a distributed computing system
US9569381B2 (en) Scheduler for memory
CN104731569A (en) Data processing method and relevant equipment
CN107193494B (en) RDD (remote data description) persistence method based on SSD (solid State disk) and HDD (hard disk drive) hybrid storage system
US9389997B2 (en) Heap management using dynamic memory allocation
CN116521576B (en) EDA software data processing system
GB2596453A (en) Memory management system
US10515055B2 (en) Mapping logical identifiers using multiple identifier spaces
JP6974510B2 (en) Methods, devices, devices and media for processing data
CN106462491B (en) Management method of stored data, storage manager and storage system
CN106598724A (en) Computing system memory management method
KR101640231B1 (en) Cloud Driving Method for supporting auto-scaled Hadoop Distributed Parallel Processing System
CN111984425B (en) Memory management method, device and equipment for operating system
US8407444B2 (en) Hardware off-load garbage collection acceleration for languages with finalizers
US9619151B2 (en) Region management apparatus, region management method, and program
CN115712500A (en) Memory release method, memory recovery method, memory release device, memory recovery device, computer equipment and storage medium

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