CN117033002A - Memory management method, device, equipment and storage medium - Google Patents

Memory management method, device, equipment and storage medium Download PDF

Info

Publication number
CN117033002A
CN117033002A CN202311300873.XA CN202311300873A CN117033002A CN 117033002 A CN117033002 A CN 117033002A CN 202311300873 A CN202311300873 A CN 202311300873A CN 117033002 A CN117033002 A CN 117033002A
Authority
CN
China
Prior art keywords
memory
idle
management group
capacity
memory management
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.)
Granted
Application number
CN202311300873.XA
Other languages
Chinese (zh)
Other versions
CN117033002B (en
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.)
Suzhou Metabrain Intelligent Technology Co Ltd
Original Assignee
Suzhou Metabrain Intelligent 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 Suzhou Metabrain Intelligent Technology Co Ltd filed Critical Suzhou Metabrain Intelligent Technology Co Ltd
Priority to CN202311300873.XA priority Critical patent/CN117033002B/en
Publication of CN117033002A publication Critical patent/CN117033002A/en
Application granted granted Critical
Publication of CN117033002B publication Critical patent/CN117033002B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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
    • 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/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system

Landscapes

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

Abstract

The embodiment of the application relates to the technical field of storage, in particular to a memory management method, a device, equipment and a storage medium, aiming at improving the use efficiency and the allocation rate of a memory. The method comprises the following steps: setting a plurality of first-type memory management groups, wherein each first-type memory management group comprises a plurality of memory blocks with the same capacity, and the memory capacities of the memory blocks contained in different memory management groups are different; in response to receiving a memory application, determining a target memory management group corresponding to the memory application; applying for a memory capacity of a preset capacity value from a memory byte pool in response to no free memory block being found in the target memory management group; performing memory supplementation on the target memory management group through the memory capacity to obtain a plurality of idle memory blocks; and distributing the idle memory blocks to the user side corresponding to the memory application.

Description

Memory management method, device, equipment and storage medium
Technical Field
The embodiment of the application relates to the technical field of storage, in particular to a memory management method, a memory management device, a memory management equipment and a memory medium.
Background
In an embedded system, a memory belongs to a scarce resource, and in the running process of the system, limited memory needs to be reasonably and efficiently utilized, and the memory management method is that the memory resource is managed through a linked list with unidirectional circulation, and when a memory application is received, the memory is distributed through traversing the linked list, and the memory is divided according to a fixed size.
In the related art, the linked list needs to be traversed, the memory allocation rate is low, only memory blocks with specified sizes can be allocated, and the use efficiency of the memory is low.
Disclosure of Invention
The embodiment of the application provides a memory management method, a device, equipment and a storage medium, aiming at improving the use efficiency and the allocation rate of a memory.
An embodiment of the present application provides a memory management method, including:
setting a plurality of first-type memory management groups, wherein each first-type memory management group comprises a plurality of memory blocks with the same capacity, and the memory capacities of the memory blocks contained in different first-type memory management groups are different;
in response to receiving the memory application, determining a target memory management group corresponding to the memory application from a plurality of first-type memory management groups;
applying for a memory capacity of a preset capacity value from the memory byte pool in response to the absence of the free memory block in the target memory management group;
Performing memory supplementation on the target memory management group through the memory capacity to obtain a plurality of idle memory blocks;
and distributing the idle memory blocks to the user end corresponding to the memory application.
Optionally, before setting the preset number of the plurality of memory management groups, the method further includes:
determining a starting address and a terminating address of a free space in the memory space;
and creating a memory byte pool according to the starting address and the ending address.
Optionally, setting a plurality of first-type memory management groups includes:
determining the memory capacity corresponding to each first type of memory management group;
and creating a corresponding first type of memory management group according to the memory capacity.
Optionally, the method further comprises:
setting a second type of memory management group, wherein the second type of memory management group is used for managing memories with memory capacity larger than a preset memory capacity threshold value.
Optionally, in response to receiving the memory application, determining a target memory management group corresponding to the memory application from the plurality of first-type memory management groups includes:
determining a memory capacity value corresponding to the memory application;
searching a memory management group corresponding to the memory capacity value in the memory management groups;
and taking the memory management group as a target memory management group.
Optionally, searching the memory management group corresponding to the memory capacity value in the multiple memory management groups includes:
and comparing the memory capacity value with the memory capacity value corresponding to each first type of memory management group, and determining the first type of memory management group corresponding to the memory capacity value.
Searching grouping index information corresponding to a plurality of memory management groups;
determining a memory capacity value corresponding to each first type of memory management group according to the grouping index information;
and comparing the memory capacity value with the memory capacity value corresponding to each first type of memory management group to determine the first type of memory management group corresponding to the memory capacity value.
Optionally, applying for the memory capacity of the preset capacity value from the memory byte pool includes:
transmitting the memory capacity application to a memory byte pool;
and receiving the memory capacity returned by the memory byte pool.
Optionally, performing memory replenishment on the target memory management group through the memory capacity to obtain a plurality of idle memory blocks, including:
dividing the memory capacity according to the memory block capacity corresponding to the target memory management group to obtain a plurality of memory blocks;
and adding the multiple memory blocks into an idle linked list corresponding to the target memory management group to obtain multiple idle memory blocks.
Optionally, the allocating the idle memory block to the user terminal corresponding to the memory application includes:
taking out the idle memory blocks from the idle linked list of the target memory management group;
and sending the idle memory block to the user terminal.
Optionally, before sending the idle memory block to the user terminal, the method further includes:
the free memory block is marked as used.
Optionally, the method further comprises:
and updating the address of the idle linked list so that the idle linked list stores the address of the next idle memory block.
Optionally, the method further comprises:
in response to finding the idle memory block in the target memory management group, taking out the idle memory block from the idle linked list of the target memory management group;
marking the idle memory block as a used state;
and sending the idle memory block to the user terminal.
Optionally, the method further comprises:
and updating the address of the idle linked list so that the idle linked list stores the address of the next idle memory block.
Optionally, the method further comprises:
and responding to the idle memory blocks distributed to the user side to release the memory, and marking the idle memory blocks as idle states.
Optionally, the method further comprises:
and updating the address of the idle linked list of the target memory management group so that the idle linked list stores the address of the idle memory block.
Optionally, the method further comprises:
and responding to the memory blocks corresponding to the memory capacity applied last time in the target memory management group as idle memory blocks, and releasing the memory of the memory blocks so as to restore the memory capacity to the memory byte pool.
Optionally, the method further comprises:
determining that the memory management group corresponding to the memory application is a second type of memory management group in response to the memory capacity value corresponding to the memory application being greater than a preset memory capacity threshold;
determining an application memory capacity value corresponding to the memory capacity value according to the memory capacity value;
applying for the memory capacity corresponding to the memory capacity value from the memory byte pool through the second type of memory management group;
and distributing the applied memory capacity to the user side from the idle linked list corresponding to the second type memory management group.
Optionally, the allocating the applied memory capacity to the user side from the idle linked list corresponding to the second type memory management group includes:
taking the memory capacity out of the idle linked list;
marking the memory capacity as a used state;
and sending the memory capacity to the user side.
Optionally, the method further comprises:
and returning the memory capacity to the memory byte pool in response to the release of the memory capacity by the user terminal.
A second aspect of an embodiment of the present application provides a memory management device, where the device includes:
the memory management group setting module is used for setting a plurality of first-type memory management groups, each first-type memory management group comprises a plurality of memory blocks with the same capacity, and the memory capacities of the memory blocks contained in different first-type memory management groups are different;
the memory management group determining module is used for determining a target memory management group corresponding to the memory application from a plurality of first-type memory management groups in response to the received memory application;
the memory capacity application module is used for applying for the memory capacity with preset capacity value from the memory byte pool in response to the fact that the idle memory block is not found in the target memory management group;
the free memory block obtaining module is used for carrying out memory supplementation on the target memory management group through the memory capacity to obtain a plurality of free memory blocks;
and the memory allocation module is used for allocating the idle memory blocks to the user side corresponding to the memory application.
Optionally, the apparatus further includes a memory byte pool creation module, the module including:
an address determination submodule, configured to determine a start address and a termination address of a free space in the memory space;
the memory byte pool creation sub-module is used for creating a memory byte pool according to the starting address and the ending address.
Optionally, the memory management group setting module includes:
the memory capacity determining submodule is used for determining the memory capacity corresponding to each first-class memory management group;
and the memory management group creation sub-module is used for creating a corresponding first type of memory management group according to the memory capacity.
Optionally, the apparatus further comprises:
the second-type memory management group setting submodule is used for setting a second-type memory management group, and the second-type memory management group is used for managing memories with memory capacity larger than a preset memory capacity threshold value.
Optionally, the memory management group determining module includes:
the memory capacity value determining submodule is used for determining a memory value corresponding to a memory application;
the memory management group searching sub-module is used for searching the memory management group corresponding to the memory capacity value in the memory management groups;
the target memory management group determining sub-module is used for taking the memory management group as a target memory management group.
Optionally, the memory management group lookup submodule includes:
the grouping index information searching sub-module is used for searching grouping index information corresponding to a plurality of memory management groups;
the grouping index information determining submodule is used for determining the memory capacity value corresponding to each first-class memory management group according to the grouping index information;
The memory management group determination submodule is used for comparing the memory capacity value with the memory capacity value corresponding to each first-class memory management group and determining the first-class memory management group corresponding to the memory capacity value.
Optionally, the memory capacity application module includes:
the memory capacity application transmitting sub-module is used for transmitting the memory capacity application to the memory byte pool;
and the memory capacity receiving sub-module is used for receiving the memory capacity returned by the memory byte pool.
Optionally, the obtaining the idle memory block includes:
the memory capacity dividing sub-module is used for dividing the memory capacity according to the memory block capacity corresponding to the target memory management group to obtain a plurality of memory blocks;
and the idle memory block obtaining sub-module is used for adding the plurality of memory blocks into an idle linked list corresponding to the target memory management group to obtain a plurality of idle memory blocks.
Optionally, the memory allocation module includes:
the idle memory block extraction sub-module is used for extracting idle memory blocks from an idle linked list of the target memory management group;
and the idle memory block sending sub-module is used for sending the idle memory block to the user side.
Optionally, the memory allocation module further includes:
and the marking submodule is used for marking the idle memory block as a used state.
Optionally, the memory allocation module further includes:
and the address updating sub-module is used for updating the address of the idle linked list so that the idle linked list stores the address of the next idle memory block.
Optionally, the apparatus further comprises:
the free memory quick extraction module is used for responding to the finding of the free memory blocks in the target memory management group and extracting the free memory blocks from the free linked list of the target memory management group;
the marking module is used for marking the idle memory block as a used state;
and the second memory allocation module is used for sending the idle memory blocks to the user side.
Optionally, the second memory allocation module further includes:
and the address updating module is used for updating the address of the idle linked list so that the idle linked list can store the address of the next idle memory block.
Optionally, the apparatus further comprises:
and the idle state marking module is used for responding to the idle memory blocks distributed to the user terminal to carry out memory release and marking the idle memory blocks as idle states.
Optionally, the idle state flag module further includes:
and the second address updating sub-module is used for updating the address of the idle linked list of the target memory management group so that the idle linked list stores the address of the idle memory block.
Optionally, the apparatus further comprises:
and the first memory capacity returning module is used for responding to the memory blocks corresponding to the memory capacity which is applied for last time in the target memory management group as idle memory blocks and performing memory release on the memory blocks so as to return the memory capacity to the memory byte pool.
Optionally, the apparatus further comprises:
the second-class memory management group determining module is used for determining that the memory management group corresponding to the memory application is the second-class memory management group in response to the memory capacity value corresponding to the memory application being greater than the preset memory capacity threshold;
the applied memory capacity value determining module is used for determining an applied memory capacity value corresponding to the memory capacity value according to the memory capacity value;
the special management group memory capacity application module is used for applying for the memory capacity corresponding to the memory capacity value from the memory byte pool through the second type of memory management group;
and the third memory allocation module is used for allocating the applied memory capacity to the user terminal from the idle linked list corresponding to the second memory management group.
Optionally, the third memory allocation module includes:
the memory capacity extraction sub-module is used for extracting the memory capacity from the idle linked list;
the memory capacity marking submodule is used for marking the memory capacity as a used state;
And the memory capacity transmitting sub-module is used for transmitting the memory capacity to the user terminal.
Optionally, the apparatus further comprises:
and the second memory capacity returning module is used for returning the memory capacity to the memory byte pool in response to the release of the memory capacity of the user terminal.
A third aspect of the embodiments of the present application provides a non-transitory readable storage medium having stored thereon a computer program which, when executed by a processor, implements steps in a method as in the first aspect of the application.
A fourth aspect of the embodiments of the present application provides an electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the method of the first aspect of the application when the computer program is executed by the processor.
By adopting the memory management method provided by the application, a plurality of first-type memory management groups are arranged, each first-type memory management group comprises a plurality of memory blocks with the same capacity, and the memory capacities of the memory blocks contained in different first-type memory management groups are different; in response to receiving the memory application, determining a target memory management group corresponding to the memory application from a plurality of first-type memory management groups; applying for a memory capacity of a preset capacity value from the memory byte pool in response to the absence of the free memory block in the target memory management group; performing memory supplementation on the target memory management group through the memory capacity to obtain a plurality of idle memory blocks; and distributing the idle memory blocks to the user end corresponding to the memory application.
In the method, the memories are managed in groups, each memory management group manages the memory capacities with different sizes, when the user side applies for the memories, the corresponding memory management group is determined according to the sizes of the memories applied by the user side, when the memory management group does not have the free memory blocks, the memories with certain sizes are applied from the memory byte pool, then the memories managed by the memory management group are divided into a plurality of memory blocks according to the memory capacities managed by the memory management group, a plurality of free memory blocks are obtained, and then the free memory blocks are distributed to the user side.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments of the present application will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a memory management method according to an embodiment of the application;
FIG. 2 is a diagram illustrating creation of a memory byte pool according to an embodiment of the present application;
FIG. 3 is a schematic diagram illustrating a memory allocation process according to an embodiment of the present application;
FIG. 4 is a schematic diagram of a memory management device according to an embodiment of the application;
fig. 5 is a schematic diagram of a memory management device according to an embodiment of the application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without any inventive effort, are intended to be within the scope of the application.
Referring to fig. 1, fig. 1 is a flowchart of a memory management method according to an embodiment of the application. As shown in fig. 1, the method comprises the steps of:
s11: setting a plurality of first-type memory management groups, wherein each first-type memory management group comprises a plurality of memory blocks with the same capacity, and the memory capacities of the memory blocks contained in different first-type memory management groups are different.
In this embodiment, in the computer system, variables and intermediate data are generally placed in the system memory space, and the data are transferred from the memory space to the central processing unit for calculation only when actually used. The types of storage space fall into two categories: the access speed of the internal storage space and the external storage space is relatively high, and the internal storage space can be accessed randomly according to variable addresses, namely a Random Access Memory (RAM), which is also called a computer memory. In the design of the embedded system, the memory belongs to scarce resources, if the memory utilization rate is low, a great amount of memory resources are wasted, when the system operates normally, the memory with larger capacity is required to be configured, so that the operating cost of the system is increased, and if the memory allocation rate is low, more time is consumed when the memory is dynamically applied, so that the embedded system operates slower. The use efficiency and the memory allocation rate of the memory are key factors influencing the performance of the embedded system, so that the use efficiency and the memory allocation rate of the memory are improved, and the performance of the embedded system can be remarkably improved.
In this embodiment, the memory management group is a management unit for managing the memory of the computer. The memory block is a small segment of continuous memory space divided in the memory space, and the memory space between the starting address and the ending address of the memory block is continuous. The first type memory management group is used for managing memories less than a preset memory capacity threshold, and the memory capacity in the first type memory management group is divided into a plurality of memory blocks.
In this embodiment, in order to manage the memory, a plurality of memory management groups are set, according to the size of the memory to be managed in the embedded system, the size of the memory to be managed in each memory management group is set, each memory management group includes a plurality of memory blocks with the same capacity, the plurality of memory blocks with the same capacity are connected in series by a linked list, and when the memory blocks are required to be allocated, the memory blocks are taken out from the linked list to be allocated, and the memory capacities of the memory blocks included in different memory management groups are different. When the memory management group is set, memory capacities of different sizes to be managed are preset, and then a corresponding management group is set to manage the memory capacities of corresponding sizes, for example, the management group 1 manages the memory capacity of a first preset size, and the management group 2 manages the memory capacity of a second preset size.
In this embodiment, the specific steps of setting a plurality of memory management groups include:
s11-1: and determining the memory capacity corresponding to each first-type memory management group.
In this embodiment, when the memory management groups are set, the memory capacity corresponding to each management group is predetermined, and generally, when the memory capacity is set, the memory capacities are ordered according to the order from small to large, and each memory management capacity is linearly increased in multiple when the memory management group is set.
For example, the embedded system to be managed is a thread system, and the memory capacity to be managed is determined to be 8 bytes, 16 bytes, 32 bytes, 64 bytes, 128 bytes, 256 bytes, 512 bytes, 1024 bytes in sequence. A special packet may also be provided for managing memory capacities greater than 1024 bytes.
S11-2: and creating a corresponding first type of memory management group according to the memory capacity.
In this embodiment, after determining the size of the memory capacity to be managed, a corresponding memory management group is created according to the determined memory capacity, and when creating the memory management group, a corresponding management group is designated for each memory capacity according to the preset memory capacity for management, where the number of the memory management groups is the same as the number of the preset memory capacities.
For example, 8-byte size memory is managed using memory management group 0, 16-byte size memory is managed using memory management group 1, 32-byte size memory is managed using memory management group 2, 64-byte size memory is managed using memory management group 3, 128-byte size memory is managed using memory management group 4, 256-byte size memory is managed using memory management group 5, 512-byte size memory is managed using memory management group 6, 1024-byte size memory is managed using memory management group 7, and more than 1024-byte size memory is managed using memory management group 8.
S12: and in response to receiving the memory application, determining a target memory management group corresponding to the memory application from the plurality of first-type memory management groups.
In this embodiment, the memory application is an application sent by the user side to the background of the system, and is used for applying for a memory with a certain size, where the memory application includes information of the user and a size of the memory to be applied. The target memory management group corresponds to the memory management group corresponding to the memory application.
In this embodiment, when the system receives the memory application, the size of the memory capacity of the memory to be applied in the memory application is determined, then the grouping index information is searched for, the memory management group corresponding to the memory capacity is searched for, the searched memory management group is used as the target memory management group, and when the memory management group is searched for, the memory capacity managed by the memory management group is greater than the memory capacity of the user application.
In this embodiment, in response to receiving the memory application, the specific steps for determining the target memory management group corresponding to the memory application from the plurality of first-class memory management groups are as follows:
s12-1: and determining a memory capacity value corresponding to the memory application.
In this embodiment, when the memory application is received, the memory capacity value corresponding to the memory application is determined, and when the memory capacity value is determined, the memory application sent by the user is parsed, and the memory capacity value included in the memory application sent by the user is determined.
For example, the content of the memory application sent by the user is "apply for memory capacity of 8 bytes", and the background analyzes the memory application to obtain the memory capacity value corresponding to the memory application as 8 bytes.
S12-2: and searching the memory management group corresponding to the memory capacity value in the memory management groups.
In this embodiment, after determining the memory capacity value required by the user, searching the memory management group corresponding to the memory capacity in the multiple memory management groups, specifically includes the steps of:
searching grouping index information corresponding to the plurality of first-type memory management groups;
determining a memory capacity value corresponding to each first type of memory management group according to the grouping index information;
and comparing the memory capacity value with the memory capacity value corresponding to each first type of memory management group, and determining the first type of memory management group corresponding to the memory capacity value.
S12-2-1, searching grouping index information corresponding to a plurality of first-type memory management groups.
In this embodiment, the packet index information includes information such as a management group name of the memory management group, a byte size managed by the management group, and the like.
In this embodiment, after determining the memory capacity value to be applied, searching the grouping index information of multiple memory management groups in the grouping index information stored in the background, where the grouping index information is stored in a grouping index list, the name of each memory management group and the size of the byte managed by each memory management group are recorded in the list, and querying the grouping index information in the grouping index list to determine the memory management group corresponding to the memory capacity value.
For example, the names of the memory management groups are "cache_node0 (8 bytes), cache_node1 (16 bytes), … …, and cache_node8 (> 1024 bytes)", respectively, according to the memory management group 0 to the memory management group 8.
S12-2-2: and determining the memory capacity value corresponding to each first-type memory management group according to the grouping index information.
S12-2-3: and comparing the memory capacity value with the memory capacity value corresponding to each first type of memory management group to determine the first type of memory management group corresponding to the memory capacity value.
In this embodiment, according to the group index information, a memory management group corresponding to the memory capacity value is determined, that is, a memory management group for allocating memory to a user is determined, and when a memory management group corresponding to the memory capacity applied by the user is determined, the memory capacity value applied by the user is compared with the memory capacity value corresponding to each first type of memory management group, and a first memory management group greater than the memory capacity value applied by the user is selected as the memory management group corresponding to the memory capacity application of the user.
For example, when the capacity applied by the user is determined to be 6 bytes, the memory management group corresponding to the memory capacity is determined to be cache_node0 (responsible for managing 8 bytes of memory), when the capacity applied by the user is determined to be 100 bytes, the memory management group corresponding to the memory capacity is determined to be cache_node4 (responsible for managing 128 bytes of memory), and when the capacity applied by the user is determined to be 3000 bytes, the memory management group corresponding to the memory capacity is determined to be cache_node8 (responsible for managing more than 1024 bytes of memory).
S12-3: and taking the memory management group as a target memory management group.
S13: and applying for the memory capacity with the preset capacity value from the memory byte pool in response to the fact that the idle memory block is not found in the target memory management group.
In this embodiment, the idle memory block is an unused memory block, in which data is not stored, and can be used at any time. The memory byte pool is a memory space created in the memory space according to the starting address and the ending address of the free memory space, and is a space with large space capacity and continuous memory addresses. The preset capacity value is a value of the memory capacity applied to the memory byte pool by the preset memory management group when no free memory block exists.
In this embodiment, after determining the target memory management group, searching for an idle memory block in an idle linked list of the target memory management group, and when no idle memory block is found, indicating that no memory block capable of being called is in the memory management group, where the memory blocks are occupied, applying for a memory capacity of a preset capacity value from a memory byte pool by the memory management group to supplement the memory blocks in the memory management group.
The preset capacity value is 2048 bytes, for example.
In this embodiment, the specific steps of applying for the memory capacity of the preset capacity value from the memory byte pool include:
s13-1: and sending the memory capacity application to a memory byte pool.
In this embodiment, the memory capacity application is an application for sending a memory management group to a direct memory pool, and is used for applying a memory with a certain size to a memory byte pool, where the memory capacity application includes information of the memory management group and a value of a memory capacity to be applied.
In this embodiment, the memory management group sends the memory capacity application to the memory byte pool, and after the memory byte pool receives the memory capacity application, the memory byte pool sends the corresponding memory capacity to the memory management group according to the memory management group information included in the memory capacity application and the information of the applied memory capacity value.
For example, the memory capacity application is "cache_node3 applies for 2048 bytes of memory".
S13-2: and receiving the memory capacity returned by the memory byte pool.
In this embodiment, when the memory byte pool sends the memory capacity to the memory management group, the memory management group receives the memory capacity returned by the memory byte pool.
S14: and performing memory supplementation on the target memory management group through the memory capacity to obtain a plurality of idle memory blocks.
In this embodiment, after the memory management group obtains the memory capacity sent by the memory byte pool, the obtained memory capacity is divided according to the memory capacity managed by the memory management group to obtain a plurality of memory blocks, and then the memories are quickly added into an idle linked list of the memory management group to obtain a plurality of idle memory blocks.
In this embodiment, the step of performing memory replenishment on the target memory management group by using the memory capacity to obtain a plurality of idle memory blocks includes:
s14-1: and dividing the memory capacity according to the memory block capacity corresponding to the target memory management group to obtain a plurality of memory blocks.
In this embodiment, after the target memory management group obtains the applied memory capacity, the obtained memory capacity is divided into a plurality of memory blocks with the same size according to the memory block capacity corresponding to the memory management group, so as to obtain a plurality of memory blocks, in order to ensure that no redundant memory is left during the memory block division, the memory block capacity corresponding to the memory management group and the preset capacity value corresponding to the memory capacity application are in a multiple relationship, and the memory capacity of the memory block can be divided by the applied memory capacity, so that the division of the memory capacity is facilitated.
For example, when the memory management group 6 (responsible for managing 512 bytes of memory) applies 2048 bytes of memory to the memory byte pool, the memory management group 6 divides the memory according to the size of the memory responsible for management, and 2048/512=4 memory blocks are obtained.
S14-2: and adding the multiple memory blocks into an idle linked list corresponding to the target memory management group to obtain multiple idle memory blocks.
In this embodiment, the linked list is a non-continuous, non-sequential storage structure on the physical storage unit, and the logical order of the data elements is implemented by the order of pointer links in the linked list. The linked list is made up of a series of nodes (each element in the linked list is called a node) that can be dynamically generated at runtime. Each node comprises two parts: one is a data field storing a data element and the other is a pointer field storing the address of the next node. The idle linked list is a linked list composed of idle memory blocks.
In this embodiment, a plurality of divided memory blocks are added to an idle linked list corresponding to a target memory management group, that is, start and stop addresses of the plurality of memory blocks are connected, and are stored through a linked list structure, so as to obtain a plurality of idle memory blocks.
S15: and distributing the idle memory blocks to the user end corresponding to the memory application.
In this embodiment, after obtaining the idle memory blocks, one idle memory block of the obtained multiple idle memory blocks is allocated to the user side that sends the memory application, where the user side may use the memory block to store any specified data, and when the idle memory block is allocated to the user side, the allocated memory block is marked as used, and meanwhile, the idle linked list is updated, so that the address of the next idle memory block is saved in the idle linked list.
For example, the idle linked list sequentially includes an idle memory block 1, an idle memory block 2, an idle memory block 3, and an idle memory block 4, and the idle memory block 1 is taken out and sent to a user side that proposes a memory application.
In this embodiment, the specific steps of allocating the idle memory block to the user terminal corresponding to the memory application include:
s15-1: and taking out the idle memory blocks from the idle linked list of the target memory management group.
In this embodiment, after the target memory management group supplements the new idle memory block, the idle block is taken out from the idle linked list of the target memory management group.
S15-2: and sending the idle memory block to the user terminal.
In this embodiment, after the target memory management group takes out the idle memory block, the obtained idle memory block is sent to the user side. The user can use the memory block to store arbitrary data.
In another embodiment of the present application, before the idle memory block is sent to the client, the method further includes:
s15-3: the free memory block is marked as used.
In this embodiment, in order to facilitate management of the memory blocks, before the idle memory blocks are sent to the user side, the idle memory blocks to be sent are marked as used, so that the used memory blocks are conveniently distinguished from the existing idle memory blocks.
In another embodiment of the present application, the method further comprises:
s15-4: and updating the address of the idle linked list so that the idle linked list stores the address of the next idle memory block.
In this embodiment, after the target memory management group allocates the idle memory blocks to the user end, the address of the idle linked list is updated, and after the address of the idle linked list is updated, the address of the next idle memory block is saved, and the start address and the end address of each idle memory block are different, which represents that the positions of the memory blocks in the memory space are different, and the idle memory blocks are connected in series through the idle linked list.
For example, the idle linked list sequentially includes an idle memory block 1, an idle memory block 2, an idle memory block 3, and an idle memory block 4, and the idle memory block 1 is taken out and sent to a user side that proposes a memory application. And updating the idle linked list to enable the idle linked list to store the address of the idle memory block 2, and directly taking the idle memory block 2 when the memory management group is accessed next time.
In this embodiment, in order to facilitate management of a memory, a plurality of memory management groups are provided, the painless memory management groups are used for managing memories of different sizes, each memory management group includes a plurality of memory blocks of the same size, when a user applies for a memory, according to the size of the memory applied by the user, the memory blocks of the corresponding size are allocated to the user terminal through the corresponding memory management groups, when no free memory block is found in the memory management groups, a memory with a preset capacity value is applied to a memory byte pool, the applied memory is divided according to the memory capacity value managed by the memory management groups, and then one of the free memory blocks is allocated to the user terminal, so that the memory is managed in this way, the memory application of different sizes can be flexibly processed, the memory allocation rate is improved, and the running rate of the whole embedded system is further improved.
In another embodiment of the present application, the method further comprises:
s21: and in response to finding the idle memory block in the target memory management group, taking the idle memory block out of the idle linked list of the target memory management group.
In this embodiment, when an idle memory block exists in the memory management group, when a memory application of a user is received, the idle memory block is directly found in the target memory management group, that is, a start address of the idle memory block is directly obtained in the idle linked list.
For example, there is an idle memory block 1 in the target memory management group, and when a memory application of a user is received, the idle memory block 1 is directly taken out from an idle linked list in the memory management group.
S22: the free memory block is marked as used.
In this embodiment, in order to facilitate management of the memory blocks, before the idle memory blocks are sent to the user side, the idle memory blocks to be sent are marked as used, so that the used memory blocks are conveniently distinguished from the existing idle memory blocks.
S23: and sending the idle memory block to the user terminal.
In this embodiment, after the idle memory block is taken out from the idle linked list, the address of the user terminal is determined according to the user information included in the internal memory application sent by the user, and the idle memory block is sent to the user terminal.
In another embodiment of the present application, the method further comprises:
s24: and updating the address of the idle linked list so that the idle linked list stores the address of the next idle memory block.
In this embodiment, after the idle memory block in the idle linked list is sent to the user terminal, the address of the idle linked list is updated, so that the idle linked list stores the address of the next idle memory block.
In this embodiment, when there is an idle memory block in the memory management group, the idle memory block is directly sent to the user side, so that the memory capacity does not need to be applied to the byte pool, and the memory allocation efficiency is improved.
In another embodiment of the present application, the method further comprises:
s31: and responding to the idle memory blocks distributed to the user side to release the memory, and marking the idle memory blocks as idle states.
In this embodiment, the memory release refers to removing the data stored in the memory block, so that the memory block does not store data.
In this embodiment, after the use of the memory block by the user terminal is completed, the memory block is released, and after the memory management group corresponding to the memory block detects that the memory block is released by the user terminal, the memory block is marked as an idle state, restored as an idle memory block, and then added into an idle linked list in the memory management group.
In this embodiment, after the user side performs memory release on the memory block, the memory management group returns the memory block to the idle linked list, marks the memory block as an idle state, and ensures efficient utilization of the memory block.
In another embodiment of the present application, the method further comprises:
s32: and updating the address of the idle linked list of the target memory management group so that the idle linked list stores the address of the idle memory block.
In this embodiment, after the free memory block after the memory release is performed by the user is put into the free linked list of the target memory management group again, the address of the free linked list is updated, and the address pointed by the free linked list pointer is updated from the original address to the address of the free memory block, so that the free linked list stores the address of the free memory block.
In this embodiment, after returning the idle memory block to the idle linked list, the address of the idle linked list is updated, so that the memory management group is guaranteed to be able to manage the idle memory block in time, and the memory allocation efficiency is improved.
In another embodiment of the present application, the method further comprises:
and S41, responding to the memory blocks corresponding to the memory capacity applied last time in the target memory management group as idle memory blocks, and releasing the memory of the memory blocks so as to restore the memory capacity to the memory byte pool.
In this embodiment, when memory blocks corresponding to the memory capacity applied from the memory byte pool in the memory management group last time are idle memory blocks, memory release is performed on the memory blocks, and the memory capacity is returned to the memory byte pool.
For example, there are 4 idle memory blocks in the memory management group 6, the size of the 4 idle memory blocks is 512 bytes, which is a memory block divided by the memory capacity applied last time, and if the memory management group detects that there are 4 idle memory blocks, and the 4 idle memory blocks are all memory blocks divided by the memory capacity applied last time from the memory byte pool, the 4 memory blocks are taken out from the idle linked list and returned to the memory byte pool.
In this embodiment, when the memory blocks corresponding to the memory capacity applied from the memory byte pool in the memory management group in the last time are idle memory blocks, the memory applied in the last time is directly released, the memory capacity is returned to the byte pool, and the memory capacity is applied from the memory byte pool again when needed, so that reasonable utilization of idle memory resources is ensured.
In another embodiment of the present application, the method further comprises:
S51: and determining that the memory management group corresponding to the memory application is the second type of memory management group in response to the memory capacity value corresponding to the memory application being greater than a preset memory capacity threshold.
In this embodiment, the preset memory capacity threshold is the maximum value of the memory capacity corresponding to the preset memory application, and the memory application higher than the memory capacity threshold is managed by the second type memory management group. The second type of memory management group is used for managing memory applications, corresponding to which the memory capacity is larger than a preset memory capacity threshold, in all the memory applications.
In this embodiment, based on the characteristics of the embedded system, when the memory capacity value is greater than the preset memory capacity threshold, the memory capacity to be allocated is greater than one page, that is, 2048 bytes, and at this time, the second type memory management group processes the memory application, and determines the memory management group corresponding to the memory application as the second type memory management group.
For example, if the memory capacity value corresponding to the memory application sent by the user is 3000 bytes, the preset memory capacity threshold is 1024 bytes, and the memory capacity value applied by the user is greater than the preset memory capacity threshold, the second type of memory management group, namely "cache_node8", is used to process the memory application.
S52: and determining an application memory capacity value corresponding to the memory capacity value according to the memory capacity value.
In this embodiment, the applied memory capacity value is a memory capacity value applied by the second type of memory management group to the memory byte pool.
In this embodiment, based on the characteristics of the embedded system, the application memory capacity value corresponding to the memory capacity value is calculated according to the memory capacity value, in each memory management group, there are memory pages above the memory block, and one memory page can store 2048 bytes, when the application memory is greater than 1024 bytes, the memory space required to be used is greater than one memory page, because some basic data is required to be stored in addition to 1024 bytes actually used, when the application memory capacity is applied, the application memory capacity value is directly applied for 2048 integer multiples, that is, the application memory capacity value is applied according to the memory page as a unit.
For example, the second memory management group applies for a memory size nn of 2048 bytes to the memory byte pool, where n= (x-1)/2048+1, x is the size of the memory to be applied.
S53: and applying for the memory capacity corresponding to the memory capacity value from the memory byte pool through the second type of memory management group.
In this embodiment, after the second type memory management group determines the memory capacity corresponding to the memory application, the memory capacity corresponding to the memory capacity value of the application is applied to the memory byte pool, and after the memory byte pool receives the application, the corresponding memory capacity is sent to the second type memory management group.
S54: and distributing the applied memory capacity to the user side from the idle linked list corresponding to the second type memory management group.
In this embodiment, the second type memory management group places the applied memory in the idle linked list, and then takes out the memory in the idle linked list and distributes the memory to the user terminal.
In this embodiment, the specific step of allocating the applied memory capacity to the user side from the idle linked list corresponding to the second type memory management group includes:
s54-1: and taking the memory capacity out of the idle linked list.
In this embodiment, the second type memory management group takes the applied memory capacity out of the corresponding idle linked list.
S54-2: the memory capacity is marked as used.
In this embodiment, when the memory capacity is fetched, the memory capacity is marked as used.
S54-3: and sending the memory capacity to the user side.
In this embodiment, the second type of memory management group sends the fetched memory capacity to the client.
In this embodiment, when the memory capacity applied by the user is greater than the preset memory capacity threshold, the second type memory management group processes the memory application, directly takes out the corresponding memory capacity from the byte pool, sends the memory capacity to the user, allocates the memory for the application with larger memory capacity by taking the memory page as a unit, meets the requirement of the user on the large memory capacity, ensures the stable operation of the embedded system, and improves the efficiency of memory allocation.
In another embodiment of the present application, the method further comprises:
s61: and returning the memory capacity to the memory byte pool in response to the release of the memory capacity by the user terminal.
In this embodiment, after the user end uses the memory capacity allocated by the second type of memory management group, the memory capacity is released, and after the second type of memory management group detects that the memory capacity is released, the memory capacity is planned to the memory byte pool.
In this embodiment, after the memory capacity is released by the client, the memory capacity is directly returned to the memory byte pool, so that full utilization of the memory is ensured, and the operation efficiency of the system is improved.
In another embodiment of the present application, before setting the preset number of the plurality of memory management groups, the method further includes:
s71: a starting address and a terminating address of a free space in the memory space are determined.
In this embodiment, the memory space is a space for storing data in a memory in the system. Free space is a contiguous memory space in which no data is stored in memory space. The start address is the address of the start position of the free space in the memory, and the end address is the end address of the free space in the memory space.
In this embodiment, before the memory management group is created, the start address and the end address of the free space in the memory space are determined. Free space is also referred to as unallocated memory.
S72: and creating a memory byte pool according to the starting address and the ending address.
In this embodiment, after the start address and the end address of the free space are determined, the continuous storage space between the start address and the end address is designated as the memory byte pool, and the creation of the memory byte pool is completed.
Referring to fig. 2, fig. 2 is a schematic diagram of creating a memory byte pool according to an embodiment of the present application, as shown in fig. 2, a start address and a stop address of "unallocated memory 2" in the map are obtained as an available space for memory management, so as to create a memory byte pool, wherein stacks and stacks that are used for the memory byte pool have the feature of growing downwards and upwards respectively, but grow only within a preset range, and do not encroach on the space of the memory byte pool, and do not cause the change of the start and stop addresses of "unallocated memory 2".
Referring to fig. 3, fig. 3 is a schematic memory allocation flow proposed in an embodiment of the present application, as shown in fig. 3, in which there are 9 cache_node (cache nodes), each cache node is regarded as a memory management group, that is, there are 9 memory management groups, which are respectively cache_no0 (memory management group 0) for managing memory with a size of 8Byte (8 bytes), cache_no1 (memory management group 1) for managing memory with a size of 16Byte (16 bytes), cache_no2 (memory management group 2) for managing memory with a size of 32Byte (32 bytes), cache_no3 (memory management group 3) for managing memory with a size of 64Byte (64 bytes), cache_no5 (memory management group 4) for managing memory with a size of 128Byte (128 bytes), cache_no5 (memory management group 5) for managing memory with a size of 8Byte (bytes), cache_no6 (memory management group 6) for managing memory with a size of 16Byte (16 bytes), cache_node2 (memory with a size of 16Byte (32 bytes) for managing memory with a size of 64Byte (64 bytes), a memory with a size of 1024 (memory management group) for managing memory with a size of 16Byte (8 bytes) for each memory with a size of 24Byte (24 bytes), a memory_nob (memory management group 3) for managing memory with a size of 64Byte (64 bytes), a memory size of 16Byte (8 bytes) for each memory buffer (memory is a memory buffer (memory) of 8), and a size of a buffer (memory buffer) is allocated to a buffer (memory size) of a buffer (16) for a buffer (memory size) which is a buffer (memory is allocated, respectively, and a buffer (memory size) is a buffer memory is allocated, and each buffer is allocated. free is free memory.
In the embodiment of the application, the memory byte pool is allocated according to the size of the appointed memory block, so that the memory fragments generated when the memory is repeatedly allocated and released in the process of byte allocation and management in the traditional memory pool management method can be effectively reduced, and the utilization rate of the memory is improved. The packet management mechanism is introduced, the flexibility of memory allocation is high, and the allocation efficiency is increased. The second type of memory management group is added in the grouping management mechanism, so that the utilization rate of the memory is effectively improved, a large amount of memory waste caused when a user applies for the excessive memory is avoided, idle memory blocks are preferably allocated for the user when the user applies for the memory, the memory allocation rate is increased, and the improvement of the memory utilization efficiency and the memory allocation rate is realized.
Based on the same inventive concept, an embodiment of the present application provides a memory management device. Referring to fig. 4, fig. 4 is a schematic diagram of a memory management device 400 according to an embodiment of the application. As shown in fig. 4, the apparatus includes:
the memory management group setting module 401 is configured to set a plurality of first type memory management groups, where each first type memory management group includes a plurality of memory blocks with the same capacity, and memory capacities of the memory blocks included in different first type memory management groups are different;
A memory management group determining module 402, configured to determine, in response to receiving the memory application, a target memory management group corresponding to the memory application from a plurality of first-class memory management groups;
a memory capacity application module 403, configured to apply for a memory capacity of a preset capacity value from the memory byte pool in response to the idle memory block not being found in the target memory management group;
an idle memory block obtaining module 404, configured to perform memory replenishment on the target memory management group through the memory capacity, to obtain a plurality of idle memory blocks;
the memory allocation module 405 is configured to allocate the idle memory block to a user terminal corresponding to the memory application.
Optionally, the apparatus further includes a memory byte pool creation module, the module including:
an address determination submodule, configured to determine a start address and a termination address of a free space in the memory space;
the memory byte pool creation sub-module is used for creating a memory byte pool according to the starting address and the ending address.
As one embodiment of the present application, the memory management group setting module includes:
the memory capacity determining submodule is used for determining the memory capacity corresponding to each first-class memory management group;
and the memory management group creation sub-module is used for creating a corresponding first type of memory management group according to the memory capacity.
As an embodiment of the present application, the apparatus further comprises:
the second-type memory management group setting submodule is used for setting a second-type memory management group, and the second-type memory management group is used for managing memories with memory capacity larger than a preset memory capacity threshold value.
As one embodiment of the present application, the memory management group determining module includes:
the memory capacity value determining submodule is used for determining a memory value corresponding to a memory application;
the memory management group searching sub-module is used for searching the memory management group corresponding to the memory capacity value in the memory management groups;
the target memory management group determining sub-module is used for taking the memory management group as a target memory management group.
As one embodiment of the present application, the memory management group lookup submodule includes:
the grouping index information searching sub-module is used for searching grouping index information corresponding to a plurality of memory management groups;
the grouping index information determining submodule is used for determining the memory capacity value corresponding to each first-class memory management group according to the grouping index information;
the memory management group determination submodule is used for comparing the memory capacity value with the memory capacity value corresponding to each first-class memory management group and determining the first-class memory management group corresponding to the memory capacity value.
As one embodiment of the present application, the memory capacity application module includes:
the memory capacity application transmitting sub-module is used for transmitting the memory capacity application to the memory byte pool;
and the memory capacity receiving sub-module is used for receiving the memory capacity returned by the memory byte pool.
As one embodiment of the present application, the obtaining the idle memory block includes:
the memory capacity dividing sub-module is used for dividing the memory capacity according to the memory block capacity corresponding to the target memory management group to obtain a plurality of memory blocks;
and the idle memory block obtaining sub-module is used for adding the plurality of memory blocks into an idle linked list corresponding to the target memory management group to obtain a plurality of idle memory blocks.
As one embodiment of the present application, the memory allocation module includes:
the idle memory block extraction sub-module is used for extracting idle memory blocks from an idle linked list of the target memory management group;
and the idle memory block sending sub-module is used for sending the idle memory block to the user side.
As an embodiment of the present application, the memory allocation module further includes:
and the marking submodule is used for marking the idle memory block as a used state.
As an embodiment of the present application, the memory allocation module further includes:
And the address updating sub-module is used for updating the address of the idle linked list so that the idle linked list stores the address of the next idle memory block.
As an embodiment of the present application, the apparatus further comprises:
the free memory quick extraction module is used for responding to the finding of the free memory blocks in the target memory management group and extracting the free memory blocks from the free linked list of the target memory management group;
the marking module is used for marking the idle memory block as a used state;
and the second memory allocation module is used for sending the idle memory blocks to the user side.
As an embodiment of the present application, the second memory allocation module further includes:
and the address updating module is used for updating the address of the idle linked list so that the idle linked list can store the address of the next idle memory block.
As an embodiment of the present application, the apparatus further comprises:
and the idle state marking module is used for responding to the idle memory blocks distributed to the user terminal to carry out memory release and marking the idle memory blocks as idle states.
As an embodiment of the present application, the idle state flag module further includes:
and the second address updating sub-module is used for updating the address of the idle linked list of the target memory management group so that the idle linked list stores the address of the idle memory block.
As an embodiment of the present application, the apparatus further comprises:
and the first memory capacity returning module is used for responding to the memory blocks corresponding to the memory capacity which is applied for last time in the target memory management group as idle memory blocks and performing memory release on the memory blocks so as to return the memory capacity to the memory byte pool.
As an embodiment of the present application, the apparatus further comprises:
the second-class memory management group determining module is used for determining that the memory management group corresponding to the memory application is the second-class memory management group in response to the memory capacity value corresponding to the memory application being greater than the preset memory capacity threshold;
the applied memory capacity value determining module is used for determining an applied memory capacity value corresponding to the memory capacity value according to the memory capacity value;
the special management group memory capacity application module is used for applying for the memory capacity corresponding to the memory capacity value from the memory byte pool through the second type of memory management group;
and the third memory allocation module is used for allocating the applied memory capacity to the user terminal from the idle linked list corresponding to the second memory management group.
As one embodiment of the present application, the third memory allocation module includes:
the memory capacity extraction sub-module is used for extracting the memory capacity from the idle linked list;
The memory capacity marking submodule is used for marking the memory capacity as a used state;
and the memory capacity transmitting sub-module is used for transmitting the memory capacity to the user terminal.
As an embodiment of the present application, the apparatus further comprises:
and the second memory capacity returning module is used for returning the memory capacity to the memory byte pool in response to the release of the memory capacity of the user terminal.
Based on the same inventive concept, another embodiment of the present application provides a non-volatile readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the memory management method according to any of the above embodiments of the present application.
Based on the same inventive concept, another embodiment of the present application provides an electronic device, and referring to fig. 5, fig. 5 is a schematic diagram of a memory management device 500 according to an embodiment of the present application, including a memory 501, a processor 502, and a computer program stored in the memory and capable of running on the processor, where the processor implements the steps in the memory management method according to any of the foregoing embodiments of the present application when executing.
For the device embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference is made to the description of the method embodiments for relevant points.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described by differences from other embodiments, and identical and similar parts between the embodiments are all enough to be referred to each other.
It will be apparent to those skilled in the art that embodiments of the present application may be provided as a method, apparatus, or computer program product. Accordingly, embodiments of the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the application may take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
Embodiments of the present application are described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. It is therefore intended that the following claims be interpreted as including the preferred embodiment and all such alterations and modifications as fall within the scope of the embodiments of the application.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or terminal device comprising the element.
The memory management method, device, equipment and storage medium provided by the application are described in detail, and specific examples are applied to illustrate the principles and embodiments of the application, and the description of the above examples is only used for helping to understand the method and core ideas of the application; meanwhile, as those skilled in the art will vary in the specific embodiments and application scope according to the idea of the present application, the present disclosure should not be construed as limiting the present application in summary.

Claims (22)

1. A memory management method, the method comprising:
setting a plurality of first-type memory management groups, wherein each first-type memory management group comprises a plurality of memory blocks with the same capacity, and the memory capacities of the memory blocks contained in different memory management groups are different;
in response to receiving a memory application, determining a target memory management group corresponding to the memory application;
applying for a memory capacity of a preset capacity value from a memory byte pool in response to no free memory block being found in the target memory management group;
performing memory supplementation on the target memory management group through the memory capacity to obtain a plurality of idle memory blocks;
and distributing the idle memory blocks to the user side corresponding to the memory application.
2. The method of claim 1, wherein prior to setting up the plurality of first-type memory management groups, the method further comprises:
determining a starting address and a terminating address of a free space in the memory space;
and creating the memory byte pool according to the starting address and the ending address.
3. The method of claim 1, wherein the setting a plurality of first-class memory management groups comprises:
Determining the memory capacity corresponding to each first type of memory management group;
and creating the corresponding first type memory management group according to the memory capacity.
4. A method according to claim 3, characterized in that the method further comprises:
setting a second type of memory management group, wherein the second type of memory management group is used for managing memories with memory capacity larger than a preset memory capacity threshold.
5. The method of claim 1, wherein the determining, in response to receiving a memory application, a target memory management group corresponding to the memory application comprises:
determining a memory capacity value corresponding to the memory application;
searching a first type memory management group corresponding to the memory capacity value in the plurality of first type memory management groups;
and taking the first type of memory management group as the target memory management group.
6. The method of claim 5, wherein searching for a first type of memory management group corresponding to the memory capacity value from the plurality of first type of memory management groups comprises:
searching grouping index information corresponding to the plurality of first-type memory management groups;
determining a memory capacity value corresponding to each first type of memory management group according to the grouping index information;
And comparing the memory capacity value with the memory capacity value corresponding to each first type of memory management group, and determining the first type of memory management group corresponding to the memory capacity value.
7. The method of claim 1, wherein applying for a memory capacity of a predetermined capacity value from a memory byte pool comprises:
transmitting a memory capacity application corresponding to the memory capacity to the memory byte pool;
and receiving the memory capacity returned by the memory byte pool.
8. The method of claim 1, wherein the performing memory replenishment on the target memory management group by the memory capacity to obtain a plurality of free memory blocks comprises:
dividing the memory capacity according to the memory block capacity corresponding to the target memory management group to obtain a plurality of memory blocks;
and adding the plurality of memory blocks into an idle linked list corresponding to the target memory management group to obtain a plurality of idle memory blocks.
9. The method of claim 1, wherein the allocating the idle memory block to the user side corresponding to the memory application comprises:
the idle memory block is taken out from the idle linked list of the target memory management group;
And sending the idle memory block to the user terminal.
10. The method of claim 9, wherein prior to sending the free memory block to the user side, the method further comprises:
and marking the idle memory block as a used state.
11. The method according to claim 9, wherein the method further comprises:
and updating the address of the idle linked list so that the idle linked list stores the address of the next idle memory block.
12. The method according to claim 1, wherein the method further comprises:
responding to the searching of the idle memory blocks in the target memory management group, and taking out the idle memory blocks from an idle linked list of the target memory management group;
marking the idle memory block as a used state;
and sending the idle memory block to the user terminal.
13. The method according to claim 12, wherein the method further comprises:
and updating the address of the idle linked list so that the idle linked list stores the address of the next idle memory block.
14. The method according to claim 1, wherein the method further comprises:
And responding to the idle memory blocks distributed to the user terminal to perform memory release, and marking the idle memory blocks as idle states.
15. The method of claim 14, wherein the method further comprises:
and updating the address of the idle linked list of the target memory management group so that the idle linked list stores the address of the idle memory block.
16. The method of claim 15, wherein the method further comprises:
and responding to the memory blocks corresponding to the memory capacity which is applied for last time in the target memory management group as idle memory blocks, and performing memory release on the memory blocks so as to restore the memory capacity to the memory byte pool.
17. The method according to claim 1, wherein the method further comprises:
determining that the memory management group corresponding to the memory application is a second type of memory management group in response to the memory capacity value corresponding to the memory application being greater than a preset memory capacity threshold;
determining an application memory capacity value corresponding to the memory capacity value according to the memory capacity value;
applying for the memory capacity corresponding to the applied memory capacity value from the memory byte pool through the second type of memory management group;
And distributing the applied memory capacity to the user side from the idle linked list corresponding to the second type memory management group.
18. The method of claim 17, wherein the allocating the applied memory capacity from the idle linked list corresponding to the second type of memory management group to the client includes:
taking the memory capacity out of the idle linked list;
marking the memory capacity as a used state;
and sending the memory capacity to the user side.
19. The method of claim 18, wherein the method further comprises:
and responding to the release of the memory capacity by the user terminal, and returning the memory capacity to the memory byte pool.
20. A memory management device, the device comprising:
the memory management group setting module is used for setting a plurality of first-type memory management groups, each first-type memory management group comprises a plurality of memory blocks with the same capacity, and the memory capacities of the memory blocks contained in different memory management groups are different;
the memory management group determining module is used for determining a target memory management group corresponding to the memory application from the plurality of first-type memory management groups in response to the received memory application;
The memory capacity application module is used for applying for the memory capacity with preset capacity value from the memory byte pool in response to the fact that the idle memory block is not found in the target memory management group;
the idle memory block obtaining module is used for carrying out memory supplementation on the target memory management group through the memory capacity to obtain a plurality of idle memory blocks;
and the memory allocation module is used for allocating the idle memory blocks to the user ends corresponding to the memory applications.
21. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method according to any of claims 1 to 19.
22. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the steps of the method according to any one of claims 1 to 19 when executing the computer program.
CN202311300873.XA 2023-10-09 2023-10-09 Memory management method, device, equipment and storage medium Active CN117033002B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311300873.XA CN117033002B (en) 2023-10-09 2023-10-09 Memory management method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311300873.XA CN117033002B (en) 2023-10-09 2023-10-09 Memory management method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN117033002A true CN117033002A (en) 2023-11-10
CN117033002B CN117033002B (en) 2024-02-09

Family

ID=88637639

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311300873.XA Active CN117033002B (en) 2023-10-09 2023-10-09 Memory management method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117033002B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118069373A (en) * 2024-04-12 2024-05-24 北京象帝先计算技术有限公司 Electronic component, electronic device and memory management method

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110016285A1 (en) * 2009-07-16 2011-01-20 Samsung Electronics Co., Ltd. Apparatus and method for scratch pad memory management
CN102915276A (en) * 2012-09-25 2013-02-06 武汉邮电科学研究院 Memory control method for embedded systems
WO2018063020A1 (en) * 2016-09-28 2018-04-05 Huawei Technologies Co., Ltd Memory management method and device
CN109388580A (en) * 2018-09-28 2019-02-26 深圳市景阳科技股份有限公司 A kind of EMS memory management process, memory management device and terminal device
CN116089321A (en) * 2022-12-29 2023-05-09 浙江大华技术股份有限公司 Memory management method, device, electronic device and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110016285A1 (en) * 2009-07-16 2011-01-20 Samsung Electronics Co., Ltd. Apparatus and method for scratch pad memory management
CN102915276A (en) * 2012-09-25 2013-02-06 武汉邮电科学研究院 Memory control method for embedded systems
WO2018063020A1 (en) * 2016-09-28 2018-04-05 Huawei Technologies Co., Ltd Memory management method and device
CN109388580A (en) * 2018-09-28 2019-02-26 深圳市景阳科技股份有限公司 A kind of EMS memory management process, memory management device and terminal device
CN116089321A (en) * 2022-12-29 2023-05-09 浙江大华技术股份有限公司 Memory management method, device, electronic device and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118069373A (en) * 2024-04-12 2024-05-24 北京象帝先计算技术有限公司 Electronic component, electronic device and memory management method

Also Published As

Publication number Publication date
CN117033002B (en) 2024-02-09

Similar Documents

Publication Publication Date Title
US6757802B2 (en) Method for memory heap and buddy system management for service aware networks
CN109690498B (en) Memory management method and equipment
CN117033002B (en) Memory management method, device, equipment and storage medium
CN110209490B (en) Memory management method and related equipment
CN107066498B (en) Key value KV storage method and device
US11074179B2 (en) Managing objects stored in memory
CN106326309B (en) Data query method and device
CN109388590B (en) Dynamic cache block management method and device for improving multichannel DMA (direct memory access) access performance
WO2020199760A1 (en) Data storage method, memory and server
US10049035B1 (en) Stream memory management unit (SMMU)
CN110555001A (en) data processing method, device, terminal and medium
CN104503703A (en) Cache processing method and device
US20190026325A1 (en) Memory object pool use in a distributed index and query system
US20130061009A1 (en) High Performance Free Buffer Allocation and Deallocation
CN114153785B (en) Memory management method and device based on remote direct memory access
WO2017086987A1 (en) In-memory data shuffling
CN111666150B (en) Storage space allocation method and device, terminal and computer readable storage medium
CN110825953A (en) Data query method, device and equipment
CN111104435B (en) Metadata organization method, device and equipment and computer readable storage medium
CN111597392B (en) Index processing method, device, equipment and storage medium
US11003578B2 (en) Method and system for parallel mark processing
US20180329756A1 (en) Distributed processing system, distributed processing method, and storage medium
CN106021121B (en) Packet processing system, method and apparatus to optimize packet buffer space
CN110825652B (en) Method, device and equipment for eliminating cache data on disk block
US11630776B2 (en) Methods and systems for fast allocation of fragmented caches

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
GR01 Patent grant
GR01 Patent grant