[go: up one dir, main page]

CN107665146B - Memory management device and method - Google Patents

Memory management device and method Download PDF

Info

Publication number
CN107665146B
CN107665146B CN201610618811.7A CN201610618811A CN107665146B CN 107665146 B CN107665146 B CN 107665146B CN 201610618811 A CN201610618811 A CN 201610618811A CN 107665146 B CN107665146 B CN 107665146B
Authority
CN
China
Prior art keywords
memory
length
blocks
block
free
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.)
Active
Application number
CN201610618811.7A
Other languages
Chinese (zh)
Other versions
CN107665146A (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.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies 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 Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN201610618811.7A priority Critical patent/CN107665146B/en
Priority to PCT/CN2017/076666 priority patent/WO2018018896A1/en
Publication of CN107665146A publication Critical patent/CN107665146A/en
Application granted granted Critical
Publication of CN107665146B publication Critical patent/CN107665146B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5016Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals the resource being the memory
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/0292User address space allocation, e.g. contiguous or non contiguous base addressing using tables or multilevel address translation means

Landscapes

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

Abstract

The invention discloses a memory management device and a memory management method, and belongs to the field of computers. The memory management device manages the memory blocks and the memory fragments in a hierarchical mode, flexibly applies or releases the memory blocks according to the actual occupation condition of the memory fragments, achieves dynamic management of the memory blocks, can meet the burst of services, enhances the sharing performance of memory resources, avoids resource waste and improves the use efficiency of the memory.

Description

内存管理装置和方法Memory management device and method

技术领域technical field

本发明涉及计算机领域,特别涉及一种内存管理装置和方法。The present invention relates to the field of computers, and in particular, to a memory management device and method.

背景技术Background technique

随着计算机技术和通信技术的发展,数据通信业务在人们的生活中已经越来越常见,数据通信业务中通常包括数据接收、数据存储以及数据转发的业务,而以上这些业务均需要对内存进行频繁地操作,具体地,接收数据时要申请内存,而后将数据存储在申请到的内存中,数据经过特定处理后再转发出去,需要释放内存,数据通信业务的频繁访问内存特性对内存管理提出了更高的要求,也即是碎片少、效率高、抗突发能力强等。With the development of computer technology and communication technology, data communication services have become more and more common in people's lives. Data communication services usually include data reception, data storage and data forwarding services. Frequent operations, specifically, when receiving data, it is necessary to apply for memory, and then store the data in the applied memory, and then forward the data after specific processing, and the memory needs to be released. It meets higher requirements, that is, less fragmentation, high efficiency, and strong anti-burst ability.

相关技术中,通常采用静态的方式进行内存管理,即,将内存配置为多个大小相同的内存块,再将每个内存块配置为多个长度相同的内存分片,将同一长度的内存分片的内存地址存储至同一个内存队列,以采取内存队列的形式来维护内存分片的分配,例如,在有业务申请内存时,从上述内存队列头部取出一个空闲内存的地址进行分配,在释放内存时,将待释放内存的地址存储于上述内存队列尾部。In related technologies, memory management is usually performed in a static manner, that is, the memory is configured into multiple memory blocks of the same size, and then each memory block is configured into multiple memory slices of the same length, and the memory of the same length is divided into multiple memory blocks with the same length. The memory addresses of the slices are stored in the same memory queue to maintain the allocation of memory slices in the form of memory queues. For example, when there is a business requesting memory, a free memory address is taken from the head of the above-mentioned memory queue for allocation. When the memory is released, the address of the memory to be released is stored at the tail of the above-mentioned memory queue.

在实现本发明的过程中,发明人发现现有技术至少存在以下问题:In the process of realizing the present invention, the inventor found that the prior art has at least the following problems:

上述静态方式的内存管理,对于每种业务,均设置了固定数量的内存块,然而,业务往往具有突发性,一个业务很可能无法全部占用一个内存队列所占用的所有内存块,从而导致内存资源的浪费,内存使用效率较低。In the above-mentioned static memory management, a fixed number of memory blocks are set for each service. However, services are often bursty, and a service may not be able to occupy all the memory blocks occupied by a memory queue, resulting in memory loss. Waste of resources and low memory usage efficiency.

发明内容SUMMARY OF THE INVENTION

为了解决现有技术的问题,本发明实施例提供了一种内存管理装置和方法。In order to solve the problems in the prior art, embodiments of the present invention provide a memory management apparatus and method.

首先,本发明提供了一种内存管理装置,所述内存管理装置包括多个功能模块,该多个功能模块用于监控至少两个内存块的状态;当一个内存块已进行内存分片时,则所述内存块的状态为占用状态,当一个内存块未进行内存分片时,则所述内存块的状态为空闲状态;监控至少两个内存分片的状态,所述至少两个内存分片包括至少两种分片长度,每个内存分片由内存块划分而成;如果同一长度的空闲内存分片数量少于内存块申请阈值,则根据所述至少两个内存块的状态,申请处于空闲状态的内存块进行划分;如果同一长度的空闲内存分片数量大于内存块释放阈值,则释放所述同一长度的空闲内存分片;接收到业务请求时,为所述业务请求分配相应长度的空闲内存分片;根据所述内存分片管理模块分配到的空闲内存分片的内存地址,存储所述业务请求对应的数据。First, the present invention provides a memory management device, the memory management device includes a plurality of functional modules, and the plurality of functional modules are used to monitor the status of at least two memory blocks; when a memory block has been fragmented, Then the state of the memory block is the occupied state, and when a memory block is not fragmented, the state of the memory block is the idle state; monitor the states of at least two memory fragments, the at least two memory fragments are in the idle state. The slice includes at least two slice lengths, and each memory slice is divided into memory blocks; if the number of free memory slices of the same length is less than the memory block application threshold, the application will be applied according to the status of the at least two memory blocks. The memory blocks in the idle state are divided; if the number of free memory fragments of the same length is greater than the memory block release threshold, the free memory fragments of the same length are released; when a service request is received, a corresponding length is allocated for the service request The free memory fragmentation; according to the memory address of the free memory fragmentation allocated by the memory fragmentation management module, the data corresponding to the service request is stored.

本发明提供的内存管理装置,通过对内存块和内存分片进行分层次管理,并根据内存分片的实际占用情况,灵活的申请或释放内存块,实现了内存块的动态管理,能够满足业务的突发性,增强了内存资源的共享性,避免了资源浪费,提高了内存使用效率。The memory management device provided by the present invention realizes the dynamic management of memory blocks by performing hierarchical management on memory blocks and memory slices, and flexibly applies for or releases memory blocks according to the actual occupancy of memory slices, thereby realizing the dynamic management of memory blocks and meeting business needs. The burstiness of memory resources enhances the sharing of memory resources, avoids resource waste, and improves memory usage efficiency.

其次,本发明还提供了一种内存管理方法,该方法具体包括:监控至少两个内存块的状态;当一个内存块已进行内存分片时,则所述内存块的状态为占用状态,当一个内存块未进行内存分片时,则所述内存块的状态为空闲状态;监控至少两个内存分片的状态,所述至少两个内存分片包括至少两种分片长度,每个内存分片由内存块划分而成;如果同一长度的空闲内存分片数量少于内存块申请阈值,则根据所述至少两个内存块的状态,申请处于空闲状态的内存块进行划分;如果同一长度的空闲内存分片数量大于内存块释放阈值,则释放所述同一长度的空闲内存分片;在接收到业务请求时,为所述业务请求分配相应长度的空闲内存分片;根据分配到的空闲内存分片的内存地址,存储所述业务请求对应的数据。Secondly, the present invention also provides a memory management method, the method specifically includes: monitoring the states of at least two memory blocks; when a memory block has been fragmented, the state of the memory block is an occupied state, when When a memory block is not fragmented, the state of the memory block is an idle state; the state of at least two memory fragments is monitored, and the at least two memory fragments include at least two fragment lengths. The shards are divided into memory blocks; if the number of free memory shards of the same length is less than the memory block application threshold, then according to the state of the at least two memory blocks, apply for the memory blocks in the free state for division; if the same length If the number of free memory fragments is greater than the memory block release threshold, the free memory fragments of the same length are released; when a service request is received, a corresponding length of free memory fragments is allocated for the service request; according to the allocated free memory fragments The memory address of the memory slice, which stores the data corresponding to the service request.

本发明提供的内存管理方法,通过对内存块和内存分片进行分层次管理,并根据内存分片的实际占用情况,灵活的申请或释放内存块,实现了内存块的动态管理,能够满足业务的突发性,增强了内存资源的共享性,避免了资源浪费,提高了内存使用效率。The memory management method provided by the present invention realizes the dynamic management of memory blocks by performing hierarchical management on memory blocks and memory slices, and flexibly applies for or releases memory blocks according to the actual occupancy of memory slices, and can satisfy business needs. The burstiness of memory resources enhances the sharing of memory resources, avoids resource waste, and improves memory usage efficiency.

在一种可能的设计中,所述方法还包括:In a possible design, the method further includes:

对于任一种长度的内存分片,若在预设时间内没有接收到对所述长度的内存分片的申请,则释放所述长度的内存分片所占用的内存块。For a memory fragment of any length, if no application for the memory fragment of the length is received within a preset time, the memory block occupied by the memory fragment of the length is released.

通过上述内存管理方法,可以根据业务实际的发生情况,判断是否需要回收内存块,供其他业务对应的内存分片来进行申请,以提高内存使用效率。Through the above memory management method, it is possible to judge whether the memory block needs to be reclaimed according to the actual occurrence of the business, so as to apply for the memory shard corresponding to other business, so as to improve the memory usage efficiency.

在一种可能的设计中,对于任一种长度的内存分片,以未使用内存块队列、已耗尽内存块队列以及正使用内存块队列的形式管理所述长度的内存分片所占用的内存块的内存地址;In one possible design, for a memory slice of any length, the amount of memory occupied by a memory slice of that length is managed in the form of a queue of unused memory blocks, a queue of exhausted memory blocks, and a queue of memory blocks in use. the memory address of the memory block;

所述未使用内存块队列包括所述长度的内存分片中所有内存分片均空闲的内存块的内存地址;The unused memory block queue includes the memory addresses of the memory blocks in which all memory fragments of the length are free;

所述已耗尽内存块队列包括所述长度的内存分片中所有内存分片均被占用的内存块的内存地址;The exhausted memory block queue includes the memory addresses of the memory blocks in which all memory fragments of the length are occupied;

所述正使用内存块队列包括所述长度的内存分片中部分内存分片被占用的内存块的内存地址。The memory block queue in use includes memory addresses of memory blocks occupied by some of the memory segments in the memory segments of the length.

通过上述内存管理方法,采用多种职能的队列对某种长度的内存分片所占用的内存块进行管理,能够大大减少业务申请内存时的延时。另外,可以减少页表切换,降低查找页表以及切换页表等所需的计算量。Through the above-mentioned memory management method, multiple function queues are used to manage the memory blocks occupied by memory fragments of a certain length, which can greatly reduce the delay when a business applies for memory. In addition, page table switching can be reduced, and the amount of computation required for looking up and switching page tables and the like can be reduced.

在一种可能的设计中,在接收到业务请求时,为所述业务请求分配相应长度的空闲内存分片包括:In a possible design, when a service request is received, allocating an idle memory segment of a corresponding length to the service request includes:

在接收到所述业务请求时,从所述业务请求对应长度的空闲内存分片中,优先分配所占用内存块中空闲内存分片数量最少的内存块中的空闲内存分片。When the service request is received, from the free memory fragments of the length corresponding to the service request, the free memory fragment in the memory block with the smallest number of free memory fragments among the occupied memory blocks is preferentially allocated.

通过上述内存管理方法,可以保证内存中数据写入的连续性,避免产生过多的内存碎片。Through the above memory management method, the continuity of data writing in the memory can be ensured, and excessive memory fragmentation can be avoided.

在一种可能的设计中,对于任一种长度的内存分片,采用多级位图Bitmap查找表的方式维护所述长度的内存分片的占用情况。In a possible design, for a memory slice of any length, a multi-level Bitmap lookup table is used to maintain the occupancy of the memory slice of the length.

通过多级位图Bitmap查找表的方式,可以有序的维护内存分片的实际占用情况。Through the multi-level bitmap Bitmap lookup table, the actual occupancy of memory slices can be maintained in an orderly manner.

在一种可能的设计中,所述方法还包括:In a possible design, the method further includes:

对于任一种大小的内存块,检测所述大小的内存块中处于占用状态的内存块的比例是否小于第一预设阈值;For memory blocks of any size, detecting whether the proportion of memory blocks in an occupied state in the memory blocks of the size is less than a first preset threshold;

若所述比例小于所述第一预设阈值,则卸载所述大小的内存块中至少一个处于空闲状态的内存块。If the ratio is less than the first preset threshold, unload at least one memory block in an idle state among the memory blocks of the size.

在一种可能的设计中,所述方法还包括:In a possible design, the method further includes:

对于任一种大小的内存块,检测所述大小的内存块中处于占用状态的内存块的比例是否大于第二预设阈值;For memory blocks of any size, detecting whether the proportion of memory blocks in the occupied state in the memory blocks of the size is greater than a second preset threshold;

若所述比例大于所述第二预设阈值,则从系统内存中加载至少一个处于空闲状态的内存块。If the ratio is greater than the second preset threshold, load at least one memory block in an idle state from the system memory.

通过根据内存块的实际占用情况,来确定从系统内存进行加载或卸载,可以实现灵活的内存管理,也能够满足不同场景下业务的数据量需求。By determining whether to load or unload from the system memory according to the actual occupancy of memory blocks, flexible memory management can be achieved, and it can also meet the data volume requirements of services in different scenarios.

在一种可能的设计中,所述方法还包括:In a possible design, the method further includes:

对于任一种长度的内存分片,以双指针后进先出LIFO缓存的形式,缓存预设数量的所述长度的空闲内存分片的内存地址;For memory slices of any length, cache the memory addresses of a preset number of free memory slices of the length in the form of a double-pointer LIFO cache;

相应地,在接收到业务请求时,从与所述业务请求响应的所述双指针后进先出LIFO缓存中分配空闲内存分片的内存地址。Correspondingly, when a service request is received, the memory address of the free memory slice is allocated from the double-pointer LIFO cache corresponding to the service request.

通过上述内存管理方法,采用预先获取一些内存分片的内存地址,以备为业务请求分配使用,可以降低对空闲内存分片的定位所需的时间,大大降低了业务申请内存的时延。Through the above memory management method, the memory addresses of some memory segments are obtained in advance for allocation and use for business requests, which can reduce the time required for locating free memory segments and greatly reduce the delay of business requesting memory.

在一种可能的设计中,所述方法还包括:In a possible design, the method further includes:

对于任一种长度的内存分片,检测所述双指针后进先出LIFO缓存中的内存地址数量低于预设阈值;For memory slices of any length, detect that the number of memory addresses in the double-pointer LIFO cache is lower than a preset threshold;

若所述内存地址数量低于所述预设阈值,则获取预设数量的内存分片的内存地址存储至所述双指针后进先出LIFO缓存中。If the number of memory addresses is lower than the preset threshold, the memory addresses of a preset number of memory slices are acquired and stored in the double-pointer LIFO cache.

通过上述内存管理方法,可以保证缓存中内存地址数量,大大降低了业务申请内存的时延。Through the above memory management method, the number of memory addresses in the cache can be guaranteed, which greatly reduces the delay of business application for memory.

再次,本发明实施例还提供了一种数据通信设备,该数据通信设备包括接收设备、发送设备、系统主机、内存管理设备和内存,其中,内存管理设备被配置为监控至少两个内存块的状态;当一个内存块已进行内存分片时,则所述内存块的状态为占用状态,当一个内存块未进行内存分片时,则所述内存块的状态为空闲状态;监控至少两个内存分片的状态,所述至少两个内存分片包括至少两种分片长度,每个内存分片由内存块划分而成;如果同一长度的空闲内存分片数量少于内存块申请阈值,则根据所述至少两个内存块的状态,申请处于空闲状态的内存块进行划分;如果同一长度的空闲内存分片数量大于内存块释放阈值,则释放所述同一长度的空闲内存分片;在接收到业务请求时,为所述业务请求分配相应长度的空闲内存分片;根据分配到的空闲内存分片的内存地址,存储所述业务请求对应的数据。Thirdly, an embodiment of the present invention also provides a data communication device, the data communication device includes a receiving device, a sending device, a system host, a memory management device, and a memory, wherein the memory management device is configured to monitor at least two memory blocks. state; when a memory block has been fragmented, the state of the memory block is an occupied state, and when a memory block has not been fragmented, the state of the memory block is an idle state; monitoring at least two The state of memory shards, the at least two memory shards include at least two shard lengths, and each memory shard is divided into memory blocks; if the number of free memory shards of the same length is less than the memory block application threshold, Then, according to the state of the at least two memory blocks, apply for a memory block in an idle state for division; if the number of free memory fragments of the same length is greater than the memory block release threshold, then release the free memory fragments of the same length; When a service request is received, an idle memory segment of a corresponding length is allocated to the service request; and data corresponding to the service request is stored according to the memory address of the allocated idle memory segment.

本发明提供的数据通信设备,通过对内存块和内存分片进行分层次管理,并根据内存分片的实际占用情况,灵活的申请或释放内存块,实现了内存块的动态管理,能够满足业务的突发性,增强了内存资源的共享性,避免了资源浪费,提高了内存使用效率。The data communication device provided by the present invention realizes the dynamic management of memory blocks by performing hierarchical management on memory blocks and memory slices, and flexibly applies for or releases memory blocks according to the actual occupancy of memory slices, thereby realizing the dynamic management of memory blocks and meeting business needs. The burstiness of memory resources enhances the sharing of memory resources, avoids resource waste, and improves memory usage efficiency.

在一种可能的设计中,所述方法还内存管理设备被配置为对于任一种长度的内存分片,若在预设时间内没有接收到对所述长度的内存分片的申请,则释放所述长度的内存分片所占用的内存块。In a possible design, the method further configures the memory management device to release the memory fragment of any length if no application for the memory fragment of the length is received within a preset time. The memory block occupied by the memory fragment of the specified length.

通过上述数据通信设备,可以根据业务实际的发生情况,判断是否需要回收内存块,供其他业务对应的内存分片来进行申请,以提高内存使用效率。Through the above-mentioned data communication device, it is possible to judge whether the memory block needs to be reclaimed according to the actual occurrence of the business, so as to apply for the memory shard corresponding to other business, so as to improve the efficiency of memory usage.

在一种可能的设计中,对于任一种长度的内存分片,以未使用内存块队列、已耗尽内存块队列以及正使用内存块队列的形式管理所述长度的内存分片所占用的内存块的内存地址;In one possible design, for a memory slice of any length, the amount of memory occupied by a memory slice of that length is managed in the form of a queue of unused memory blocks, a queue of exhausted memory blocks, and a queue of memory blocks in use. the memory address of the memory block;

所述未使用内存块队列包括所述长度的内存分片中所有内存分片均空闲的内存块的内存地址;The unused memory block queue includes the memory addresses of the memory blocks in which all memory fragments of the length are free;

所述已耗尽内存块队列包括所述长度的内存分片中所有内存分片均被占用的内存块的内存地址;The exhausted memory block queue includes the memory addresses of the memory blocks in which all memory fragments of the length are occupied;

所述正使用内存块队列包括所述长度的内存分片中部分内存分片被占用的内存块的内存地址。The memory block queue in use includes memory addresses of memory blocks occupied by some of the memory segments in the memory segments of the length.

通过上述数据通信设备,采用多种职能的队列对某种长度的内存分片所占用的内存块进行管理,能够大大减少业务申请内存时的延时。另外,可以减少页表切换,降低查找页表以及切换页表等所需的计算量。Through the above data communication equipment, multiple function queues are used to manage the memory blocks occupied by a certain length of memory shards, which can greatly reduce the delay when a business applies for memory. In addition, page table switching can be reduced, and the amount of computation required for looking up and switching page tables and the like can be reduced.

在一种可能的设计中,内存管理设备被配置为在接收到所述业务请求时,从所述业务请求对应长度的空闲内存分片中,优先分配所占用内存块中空闲内存分片数量最少的内存块中的空闲内存分片。In a possible design, the memory management device is configured to, when receiving the service request, preferentially allocate the least number of free memory fragments in the occupied memory block from the free memory fragments of the length corresponding to the service request. free memory slices in the memory block of .

通过上述数据通信设备,可以保证内存中数据写入的连续性,避免产生过多的内存碎片。Through the above data communication device, the continuity of data writing in the memory can be ensured, and excessive memory fragmentation can be avoided.

在一种可能的设计中,对于任一种长度的内存分片,采用多级位图Bitmap查找表的方式维护所述长度的内存分片的占用情况。In a possible design, for a memory slice of any length, a multi-level Bitmap lookup table is used to maintain the occupancy of the memory slice of the length.

通过多级位图Bitmap查找表的方式,可以有序的维护内存分片的实际占用情况。Through the multi-level bitmap Bitmap lookup table, the actual occupancy of memory slices can be maintained in an orderly manner.

在一种可能的设计中,内存管理设备被配置为对于任一种大小的内存块,检测所述大小的内存块中处于占用状态的内存块的比例是否小于第一预设阈值;若所述比例小于所述第一预设阈值,则卸载所述大小的内存块中至少一个处于空闲状态的内存块。In a possible design, the memory management device is configured to, for a memory block of any size, detect whether the proportion of the memory blocks in the occupied state in the memory blocks of the size is less than a first preset threshold; if the If the ratio is smaller than the first preset threshold, at least one memory block in an idle state among the memory blocks of the size is unloaded.

在一种可能的设计中,内存管理设备被配置为对于任一种大小的内存块,检测所述大小的内存块中处于占用状态的内存块的比例是否大于第二预设阈值;若所述比例大于所述第二预设阈值,则从系统内存中加载至少一个处于空闲状态的内存块。In a possible design, the memory management device is configured to, for a memory block of any size, detect whether the proportion of the memory blocks in the occupied state in the memory blocks of the size is greater than a second preset threshold; if the If the ratio is greater than the second preset threshold, at least one memory block in an idle state is loaded from the system memory.

通过根据内存块的实际占用情况,来确定从系统内存进行加载或卸载,可以实现灵活的内存管理,也能够满足不同场景下业务的数据量需求。By determining whether to load or unload from the system memory according to the actual occupancy of memory blocks, flexible memory management can be achieved, and it can also meet the data volume requirements of services in different scenarios.

在一种可能的设计中,内存管理设备被配置为对于任一种长度的内存分片,以双指针后进先出LIFO缓存的形式,缓存预设数量的所述长度的空闲内存分片的内存地址;相应地,在接收到业务请求时,从与所述业务请求响应的所述双指针后进先出LIFO缓存中分配空闲内存分片的内存地址。In a possible design, the memory management device is configured to, for a memory slice of any length, cache the memory of a preset number of free memory slices of the length in the form of a double-pointer LIFO cache. Correspondingly, when a service request is received, the memory address of the free memory slice is allocated from the double-pointer LIFO cache corresponding to the service request.

通过上述数据通信设备,采用预先获取一些内存分片的内存地址,以备为业务请求分配使用,可以降低对空闲内存分片的定位所需的时间,大大降低了业务申请内存的时延。Through the above data communication device, the memory addresses of some memory segments are obtained in advance for allocation and use for business requests, which can reduce the time required for locating free memory segments and greatly reduce the delay of business requesting memory.

在一种可能的设计中,内存管理设备被配置为对于任一种长度的内存分片,检测所述双指针后进先出LIFO缓存中的内存地址数量低于预设阈值;In a possible design, the memory management device is configured to detect that the number of memory addresses in the double-pointer LIFO cache is lower than a preset threshold for memory slices of any length;

若所述内存地址数量低于所述预设阈值,则获取预设数量的内存分片的内存地址存储至所述双指针后进先出LIFO缓存中。If the number of memory addresses is lower than the preset threshold, the memory addresses of a preset number of memory slices are acquired and stored in the double-pointer LIFO cache.

通过上述数据通信设备,可以保证缓存中内存地址数量,大大降低了业务申请内存的时延。Through the above-mentioned data communication device, the number of memory addresses in the cache can be guaranteed, which greatly reduces the delay of business application for memory.

附图说明Description of drawings

为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to illustrate the technical solutions in the embodiments of the present invention more clearly, the following briefly introduces the accompanying drawings used in the description of the embodiments. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained from these drawings without creative effort.

图1是本发明实施例提供的数据通信设备的硬件结构示意图。FIG. 1 is a schematic diagram of a hardware structure of a data communication device provided by an embodiment of the present invention.

图2是本发明实施例提供的内存管理装置的结构示意图。FIG. 2 is a schematic structural diagram of a memory management apparatus provided by an embodiment of the present invention.

图3是本发明实施例提供的内存块管理模块维护的队列的示意图。FIG. 3 is a schematic diagram of a queue maintained by a memory block management module according to an embodiment of the present invention.

图4是本发明实施例提供的三级Bitmap查找表的示意图。FIG. 4 is a schematic diagram of a three-level Bitmap lookup table provided by an embodiment of the present invention.

图5是本发明实施例提供的内存块队列和内存分片队列的配置方式示意图。FIG. 5 is a schematic diagram of a configuration manner of a memory block queue and a memory fragmentation queue provided by an embodiment of the present invention.

图6是本发明实施例提供的一种内存管理方法的流程图。FIG. 6 is a flowchart of a memory management method provided by an embodiment of the present invention.

具体实施方式Detailed ways

为使本发明的目的、技术方案和优点更加清楚,下面将结合附图对本发明实施方式作进一步地详细描述。In order to make the objectives, technical solutions and advantages of the present invention clearer, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.

本发明实施例提供了一种内存管理装置,该内存管理装置尤其适用于数据通信设备中,为了使读者方便理解本发明实施例的技术方案,下面本发明将对上述数据通信设备的硬件结构进行简要地说明。An embodiment of the present invention provides a memory management device, which is especially suitable for data communication equipment. In order to make it easier for readers to understand the technical solutions of the embodiments of the present invention, the present invention will hereinafter describe the hardware structure of the above-mentioned data communication device. Briefly explain.

如图1所示为上述数据通信设备的硬件结构示意图,该数据通信设备至少可以包括接收设备110,发送设备120,系统主机130,内存管理设备140和内存150。其中,该接收设备110用于接收数据包,该发送设备120用于发送数据包,该系统主机130用于对接收到的数据包进行特定处理,该内存管理设备140用于根据在数据包的处理过程中,根据处理过程中所产生的业务请求为业务请求对应的数据分配内存。FIG. 1 is a schematic diagram of the hardware structure of the above data communication device. The data communication device may at least include a receiving device 110 , a sending device 120 , a system host 130 , a memory management device 140 and a memory 150 . The receiving device 110 is used to receive data packets, the sending device 120 is used to send data packets, the system host 130 is used to perform specific processing on the received data packets, and the memory management device 140 is used to During the processing, memory is allocated for the data corresponding to the service request according to the service request generated during the processing.

请参考图2,其示出了本发明一个实施例提供的内存管理装置的结构示意图。如图2所示,该装置可以包括但不限于:内存块状态监控模块210、内存分片监控模块220、内存分片管理模块230和数据存储模块240。下面,针对各个模块的功能分别进行介绍:Please refer to FIG. 2 , which shows a schematic structural diagram of a memory management apparatus provided by an embodiment of the present invention. As shown in FIG. 2 , the apparatus may include, but is not limited to, a memory block status monitoring module 210 , a memory fragmentation monitoring module 220 , a memory fragmentation management module 230 and a data storage module 240 . The following describes the functions of each module:

内存块状态监控模块210。The memory block status monitoring module 210 .

内存块状态监控模块210用于监控至少两个内存块的状态;当一个内存块已进行内存分片时,则所述内存块的状态为占用状态,当一个内存块未进行内存分片时,则所述内存块的状态为空闲状态。The memory block state monitoring module 210 is used to monitor the states of at least two memory blocks; when a memory block has been fragmented, the state of the memory block is an occupied state, and when a memory block has not been fragmented, Then the state of the memory block is an idle state.

内存150可以被划分为多个内存块,该多个内存块的大小可以由技术人员根据数据通信业务的需求进行设置,此外,该多个内存块大小可以相同,也可以不相同;当然,在实际应用中,该内存管理配置模块210也可以将内存划分为一整个内存块。对于内存块的个数、内存块的大小等内存块划分方法本发明不做具体限定。The memory 150 can be divided into multiple memory blocks, and the sizes of the multiple memory blocks can be set by technicians according to the requirements of the data communication service. In addition, the sizes of the multiple memory blocks can be the same or different; In practical applications, the memory management configuration module 210 can also divide the memory into a whole memory block. The present invention does not specifically limit the memory block division methods such as the number of memory blocks and the size of the memory blocks.

而对于数据通信设备来说,其具有处理多种不同的业务的能力,因此,为了满足多种业务需求,每种业务可以预先占用一定数目的内存块,且每种业务可以占用至少一个相同大小的内存块,也可以占用至少两个不同大小的内存块,在此不做具体限定。而为了避免对内存资源的浪费,可以将其占用的内存块进一步划分为至少一个内存分片,使得能够为业务请求以内存分片为单位进行内存申请和分配。在这里需要说明的是,每个内存块中各内存分片的大小也可以由技术人员根据数据通信业务的需求进行设置,各个内存块中内存分片的个数可以相同也可以不相同,且,每个内存块中各内存分片的大小可以相同也可以不相同,本发明对此也不做具体限定。For data communication equipment, it has the ability to process a variety of different services. Therefore, in order to meet the needs of various services, each service can occupy a certain number of memory blocks in advance, and each service can occupy at least one of the same size. It can also occupy at least two memory blocks of different sizes, which are not specifically limited here. In order to avoid waste of memory resources, the occupied memory block can be further divided into at least one memory shard, so that memory application and allocation can be performed in units of memory shards for business requests. It should be noted here that the size of each memory slice in each memory block can also be set by technicians according to the requirements of data communication services, and the number of memory slices in each memory block can be the same or different, and , the size of each memory slice in each memory block may be the same or different, which is not specifically limited in the present invention.

需要说明的是,内存150在进行内存块划分时,可以仅对内存150的一部分内存进行划分,剩余一部分内存暂且不做划分,以供后续灵活使用。进一步地,为了应对业务请求突发,可以根据内存块的占用情况,灵活调整启用的内存块数量。具体地,该内存块状态监控模块可以用于以下任一种实施过程:It should be noted that, when the memory 150 is divided into memory blocks, only a part of the memory of the memory 150 may be divided, and the remaining part of the memory may not be divided temporarily for subsequent flexible use. Further, in order to cope with the burst of service requests, the number of enabled memory blocks can be flexibly adjusted according to the occupancy of the memory blocks. Specifically, the memory block status monitoring module can be used in any of the following implementation processes:

第一种实施过程、该内存块状态监控模块用于对于任一种大小的内存块,检测所述大小的内存块中处于占用状态的内存块的比例是否小于第一预设阈值;若所述比例小于所述第一预设阈值,则卸载所述大小的内存块中至少一个处于空闲状态的内存块。In the first implementation process, the memory block status monitoring module is used for memory blocks of any size to detect whether the proportion of the memory blocks in the occupied state in the memory blocks of the size is smaller than the first preset threshold; if the If the ratio is smaller than the first preset threshold, at least one memory block in an idle state among the memory blocks of the size is unloaded.

对于这种实施过程,如果检测所述大小的内存块中处于占用状态的内存块的比例小于第一预设阈值,则说明当前该业务所需数据量较小,当前所占用的内存块过多,为了避免内存资源浪费,可以将该业务所占用的内存块卸载,也即是,将内存块释放回内存,以供其他业务进行内存块加载。For this implementation process, if the proportion of the memory blocks in the occupied state among the memory blocks of the size detected is smaller than the first preset threshold, it means that the current amount of data required by the service is small, and the currently occupied memory blocks are too many , in order to avoid wasting memory resources, the memory block occupied by the service can be unloaded, that is, the memory block is released back to the memory for other services to load the memory block.

第二种实施过程、该内存块状态监控模块用于对于任一种大小的内存块,检测所述大小的内存块中处于占用状态的内存块的比例是否大于第二预设阈值;若所述比例大于所述第二预设阈值,则从系统内存中加载至少一个处于空闲状态的内存块。The second implementation process, the memory block status monitoring module is used for memory blocks of any size to detect whether the proportion of the memory blocks in the occupied state in the memory blocks of the size is greater than the second preset threshold; if the If the ratio is greater than the second preset threshold, at least one memory block in an idle state is loaded from the system memory.

对于这种实施过程,如果检测所述大小的内存块中处于占用状态的内存块的比例大于第二预设阈值,则说明当前该大小的内存块的剩余量不足,可能不足以应对该业务的数据量,因此,可以从系统内存中加载至少一个处于空闲状态的内存块,以保证业务处理不受影响。For this implementation process, if it is detected that the proportion of memory blocks in the occupied state in the memory blocks of the size is greater than the second preset threshold, it means that the current remaining amount of memory blocks of the size is insufficient, which may not be enough to deal with the problem of the service. Therefore, at least one free memory block can be loaded from the system memory to ensure that business processing is not affected.

需要说明的是,除通过上述比例来判断是否卸载或加载内存块以外,还可以通过处于占用状态的内存块的个数等进行判断,本发明实施例对此不做限定。It should be noted that, in addition to judging whether to unload or load a memory block according to the above ratio, judgment may also be made according to the number of memory blocks in an occupied state, etc., which is not limited in this embodiment of the present invention.

对于内存块的管理,可以采用队列形式进行,每个队列用于存储内存块的地址,每个队列可以用于管理相同大小的内存块,且每个队列中所存储的地址数量可以相同或不同,本发明实施例对此不做具体限定。需要说明的是,该队列以链表或其他数据结构的形式存在,其至少可以包括如下信息:队列头尾指针、内存块个数及内存块大小等。For the management of memory blocks, it can be carried out in the form of queues. Each queue is used to store the addresses of memory blocks. Each queue can be used to manage memory blocks of the same size, and the number of addresses stored in each queue can be the same or different. , which is not specifically limited in this embodiment of the present invention. It should be noted that the queue exists in the form of a linked list or other data structures, which may at least include the following information: pointers to the head and tail of the queue, the number of memory blocks, and the size of the memory blocks.

综上,通过上述对根据对内存块的实际占用情况进行内存块加载和卸载,使得内存块可以根据业务实际需求进行动态调整,从而增强了内存资源的共享性,提高了内存使用效率。In summary, the above-mentioned loading and unloading of memory blocks according to the actual occupancy of the memory blocks enables the memory blocks to be dynamically adjusted according to the actual needs of the business, thereby enhancing the sharing of memory resources and improving the efficiency of memory use.

内存分片监控模块220Memory fragmentation monitoring module 220

内存分片监控模块220用于监控至少两个内存分片的状态,所述至少两个内存分片包括至少两种分片长度,每个内存分片由内存块划分而成;如果同一长度的空闲内存分片数量少于内存块申请阈值,则根据所述至少两个内存块的状态,申请处于空闲状态的内存块进行分割;如果同一长度的空闲内存分片数量大于内存块释放阈值,则释放所述同一长度的空闲内存分片。The memory fragmentation monitoring module 220 is used to monitor the status of at least two memory fragments, the at least two memory fragments include at least two fragment lengths, and each memory fragment is divided into memory blocks; If the number of free memory fragments is less than the memory block application threshold, then according to the status of the at least two memory blocks, apply for the memory block in the free state to be divided; if the number of free memory fragments of the same length is greater than the memory block release threshold, then Free memory segments of the same length are released.

其中,内存分片的状态包括占用状态和空闲状态,当该内存分片已经被分配,则该内存分片处于占用状态,当该内存分片已经被释放或还未被分配,则该内存分片处于空闲状态。而如果同一长度的空闲内存分片数量少于内存块申请阈值,则说明该长度的内存分片可能不足以满足业务需求,则可以从处于空闲状态的内存块中申请至少一个内存块,并将申请到的内存块划分为至少一个内存分片,以供业务申请需要,如果某一个处于空闲状态的内存块被分配并划分,则该内存块的状态转换至占用状态。而如果同一长度的空闲内存分片数量大于内存块释放阈值,则说明该长度的内存分片对应的业务数据量有限,则为了避免对内存资源造成浪费,可以释放所述同一长度的空闲内存分片。在释放时,可以先将内存分片的内存地址聚合,以得到整个内存块的地址,再对内存块的地址进行释放。Among them, the state of the memory segment includes the occupied state and the idle state. When the memory segment has been allocated, the memory segment is in the occupied state. When the memory segment has been released or has not been allocated, the memory segment is in the occupied state. The slice is idle. However, if the number of free memory shards of the same length is less than the memory block application threshold, it means that the memory shards of this length may not be enough to meet the business requirements, you can apply for at least one memory block from the memory blocks in the idle state, and assign The applied memory block is divided into at least one memory shard for business application needs. If a memory block in an idle state is allocated and divided, the state of the memory block is converted to the occupied state. However, if the number of free memory fragments of the same length is greater than the memory block release threshold, it means that the amount of business data corresponding to the memory fragments of this length is limited. In order to avoid wasting memory resources, the free memory fragments of the same length can be released. piece. When releasing, the memory addresses of the memory slices can be aggregated to obtain the address of the entire memory block, and then the address of the memory block is released.

进一步地,所述内存分片监控模块用于对于任一种长度的内存分片,若在预设时间内没有接收到对所述长度的内存分片的分配,则释放所述长度的内存分片所占用的内存块。如果预设时间内没有接收到对该长度的内存分片的申请,说明该业务没有需求量,则为了避免对内存资源造成浪费,可以将该长度的内存分片所占用的内存块释放。Further, the memory fragmentation monitoring module is used for the memory fragmentation of any length, if the allocation of the memory fragmentation of the length is not received within the preset time, then the memory fragmentation of the length is released. The block of memory occupied by the slice. If no application is received for a memory slice of this length within the preset time, it means that there is no demand for the service, and in order to avoid wasting memory resources, the memory blocks occupied by the memory slice of this length can be released.

为了减少内存碎片,增加内存的使用效率,对于任一长度的内存分片,可以采用多个不同职能的队列来管理该长度的内存分片所占用的内存块,参见图3,具体说明如下:所述内存分片监控模块用于对于任一种长度的内存分片,以未使用内存块队列、已耗尽内存块队列以及正使用内存块队列的形式管理所述长度的内存分片所占用的内存块的内存地址。其中,所述未使用内存块队列包括所述长度的内存分片中所有内存分片均空闲的内存块的内存地址。所述已耗尽内存块队列包括所述长度的内存分片中所有内存分片均被占用的内存块的内存地址。所述正使用内存块队列包括所述长度的内存分片中部分内存分片被占用的内存块的内存地址。In order to reduce memory fragmentation and increase the efficiency of memory use, for a memory fragment of any length, multiple queues with different functions can be used to manage the memory blocks occupied by the memory fragment of this length, see Figure 3, and the details are as follows: The memory fragmentation monitoring module is used for memory fragmentation of any length, in the form of unused memory block queues, exhausted memory block queues, and in-use memory block queues to manage the occupied memory fragments of the lengths. The memory address of the memory block. Wherein, the unused memory block queue includes memory addresses of memory blocks in which all memory fragments of the length are free. The exhausted memory block queue includes memory addresses of memory blocks in which all memory fragments of the length are occupied. The memory block queue in use includes memory addresses of memory blocks occupied by some of the memory segments in the memory segments of the length.

需要说明的是,对于内存分片所占用的内存块来说,可以具有三种状态:未使用状态,即该内存块所划分的内存分片均处于空闲状态;已使用状态,即该内存块所划分的内存分片有一部分处于空闲状态,有一部分已被分配;已耗尽状态,即该内存块所划分的内存分片均已被分配。而随着设备的运行,内存分片的状态会发生变化,这就导致内存块的状态也会随时发生变化,如当某一个未使用内存块中的一个内存分片被分配时,该未使用内存块随即成为一个正使用内存块,为了真实反映内存的变化,需要动态维护上述队列,该动态维护过程可以包括以下(a)至(d)几种情况:It should be noted that a memory block occupied by a memory fragment can have three states: unused state, that is, the memory fragments divided by the memory block are all in an idle state; used state, that is, the memory block Some of the divided memory shards are in the idle state, and some have been allocated; in the exhausted state, that is, all the memory shards divided by the memory block have been allocated. With the operation of the device, the state of the memory fragment will change, which will cause the state of the memory block to change at any time. For example, when a memory fragment in an unused memory block is allocated, the unused memory The memory block immediately becomes a memory block in use. In order to truly reflect the changes in memory, the above queue needs to be dynamically maintained. The dynamic maintenance process can include the following situations (a) to (d):

a)当正使用内存块队列的第一指定内存块中的内存分片全部空闲时,该内存分片监控模块将该第一指定内存块从正使用内存块队列中删除,添加到未使用内存块队列尾部。a) When all the memory fragments in the first specified memory block in the memory block queue are free, the memory fragment monitoring module deletes the first specified memory block from the memory block queue in use and adds it to the unused memory Tail of the block queue.

b)当正使用内存块队列不包括任何内存块时,该内存分片监控模块从未使用内存块队列头部获取至少一个处于空闲状态的内存块,将该至少一个处于空闲状态的内存块添加到正使用内存块队列尾部。b) When the memory block queue in use does not include any memory blocks, the memory fragmentation monitoring module obtains at least one free memory block from the head of the unused memory block queue, and adds the at least one free memory block to the to the end of the queue of memory blocks in use.

c)当已耗尽内存块队列中的第二指定内存块的至少一个内存分片变为空闲时,该内存分片监控模块将该第二指定内存块从已耗尽内存块队列中删除,添加到正使用内存块队列头部,从而使该内存块中的内存分片可以被优先分配,以起到减少内存碎片,增加内存的使用效率的效果。c) When at least one memory segment of the second specified memory block in the exhausted memory block queue becomes free, the memory segment monitoring module deletes the second specified memory block from the exhausted memory block queue, It is added to the head of the memory block queue in use, so that the memory fragments in the memory block can be allocated preferentially, so as to reduce the memory fragmentation and increase the efficiency of memory usage.

d)当正使用内存块队列中的第三指定内存块的内存分片全被分配时,该内存分片监控模块将该第三指定内存块从正使用内存块队列中删除,添加到已耗尽内存块队列尾部。d) When the memory segments of the third specified memory block in the memory block queue are all allocated, the memory segment monitoring module deletes the third specified memory block from the memory block queue in use and adds it to the consumed memory block. The tail of the memory block queue is exhausted.

综上,通过以多种不同职能队列的形式管理某一长度的内存分片所占用内存块,使得正使用内存块中的内存分片可以被优先分配,从而可以减少内存碎片,增加内存使用效率,提高对内存分配的灵活性以及避免页表频繁切换带来的负面影响,In summary, by managing the memory blocks occupied by memory fragments of a certain length in the form of a variety of different functional queues, the memory fragments in the memory blocks in use can be allocated preferentially, thereby reducing memory fragmentation and increasing memory usage efficiency. , improve the flexibility of memory allocation and avoid the negative impact of frequent page table switching,

进一步地,为了提高后续内存申请时对内存分片的定位速度,减少业务申请内存的时延,本发明提供了一种内存分片占用情况的维护方法,也即是,所述内存分片监控模块用于对于任一种长度的内存分片,采用多级位图Bitmap查找表的方式维护所述长度的内存分片的占用情况。Further, in order to improve the positioning speed of memory shards during subsequent memory application and reduce the delay of business application for memory, the present invention provides a maintenance method for the occupancy of memory shards, that is, the memory shard monitoring. The module is used to maintain the occupancy status of the memory segment of any length by adopting a multi-level Bitmap lookup table for memory segments of any length.

例如,对于一种长度的内存分片来说,可以配置一个多级位图Bitmap查找表,该多级位图Bitmap查找表包括:一级Bitmap调度表和三级Bitmap查找表,该三级Bitmap查找表包括:第一级Bitmap查找表,第二级Bitmap查找表和第三级Bitmap查找表。For example, for a memory slice of one length, a multi-level bitmap Bitmap lookup table can be configured, and the multi-level bitmap Bitmap lookup table includes: a first-level Bitmap scheduling table and a third-level Bitmap look-up table. The third-level Bitmap lookup table The look-up table includes: a first-level Bitmap look-up table, a second-level Bitmap look-up table and a third-level Bitmap look-up table.

其中,该一级Bitmap调度表,用于存储该未使用内存块队列,该已耗尽内存块队列以及该正使用内存块队列中内存块与该三级Bitmap查找表的映射关系,该第一级Bitmap查找表为一维存储结构,包括多个一级存储单元,每个一级存储单元对应该第二级Bitmap查找表的一行,该第二级Bitmap查找表为二维存储结构,包括多个行和多个二级存储单元,每个二级存储单元对应该第三级Bitmap查找表的一行,该第三级Bitmap查找表为二维存储结构,包括多个三级存储单元,每个三级存储单元对应其中的一个内存分片,如图4所示为上述三级Bitmap查找表的示意图,该一级存储单元、该二级存储单元以及该三级存储单元均对应一个预设值,该预设值用于反映该一级存储单元、该二级存储单元以及该三级存储单元对应的内存的占用状态,例如,该预设值可以为0或1,其中0用于表示内存未被占用或未被全部占用,1用于表示被占用,需要说明的是,上述预设值仅仅是示例性的,在实际应用中该预设值可以为任意值,且,该预设值可以不止两个,对此本发明不做具体限定,此外,在实际应用中,多级位图Bitmap查找表可以仅包括Bitmap查找表,而不包括Bitmap调度表,或者,可以包括四级、二级等任一级数的Bitmap查找表,对此,本发明也不做具体限定,且,由于不同级数的Bitmap查找表的查找方式十分类似,因此,本发明将以三级Bitmap查找表为例进行说明,对于其他级数的Bitmap查找表查找方式就不再赘述。Among them, the first-level Bitmap scheduling table is used to store the unused memory block queue, the exhausted memory block queue and the mapping relationship between the memory blocks in the memory block queue in use and the third-level Bitmap lookup table, the first The first-level Bitmap look-up table is a one-dimensional storage structure, including multiple first-level storage units, each first-level storage unit corresponds to a row of the second-level Bitmap look-up table, and the second-level Bitmap look-up table is a two-dimensional storage structure, including multiple rows and multiple secondary storage units, each secondary storage unit corresponds to a row of the third-level Bitmap look-up table, the third-level Bitmap look-up table is a two-dimensional storage structure, including multiple third-level storage units, each The third-level storage unit corresponds to one of the memory slices. FIG. 4 is a schematic diagram of the above-mentioned three-level Bitmap lookup table. The first-level storage unit, the second-level storage unit and the third-level storage unit all correspond to a preset value , the preset value is used to reflect the occupancy status of the memory corresponding to the first-level storage unit, the second-level storage unit, and the third-level storage unit. For example, the preset value can be 0 or 1, where 0 is used to represent the memory Not occupied or not fully occupied, 1 is used to indicate occupied, it should be noted that the above preset value is only an example, in practical application, the preset value can be any value, and the preset value There may be more than two, which is not specifically limited in the present invention. In addition, in practical applications, the multi-level bitmap Bitmap lookup table may only include the Bitmap lookup table, but not the Bitmap scheduling table, or may include four levels, two The Bitmap lookup table of any series of levels is not specifically limited in the present invention, and since the lookup methods of the Bitmap lookup tables of different levels are very similar, the present invention will use the three-level Bitmap lookup table as An example is used to illustrate, and the search methods of the Bitmap lookup table of other series will not be described again.

为了便于解利用上述利用多级位图Bitmap查找表定位正使用内存块队列中空闲内存分片的方法,本发明将对其进行简单的举例说明。In order to facilitate the understanding of the above-mentioned method for locating free memory slices in the memory block queue in use by using the multi-level Bitmap lookup table, the present invention will briefly illustrate the method.

例如,若需要查找正使用内存块队列中第一个空闲的内存分片时,可以首先查找一级Bitmap调度表,以获取正使用内存块队列头部内存块对应的三级Bitmap查找表,而后可以在第一级Bitmap查找表中按照顺序查找预设值为0的一级存储单元(预设值为0表示内存未被占用或未被全部占用),假设查询到的第一个预设值为0的一级存储单元的编号为a,则可以在第二级Bitmap查找表的第a行中按照顺序查找预设值为0的二级存储单元,假设查询到的第一个预设值为0的二级存储单元的编号为b,则内存管理装置200可以在第三级Bitmap查找表的第ab行中按照顺序查找预设值为0的三级存储单元,假设查询到的第一个预设值为0的三级存储单元的编号为ijkl0124,则编号为ijkl0124的内存分片即为正使用内存块队列中第一个空闲的内存分片,需要说明的是,上述举例中的编号仅仅是示例性的,并不能限制本发明。For example, if you need to find the first free memory slice in the memory block queue in use, you can first look up the first-level Bitmap scheduling table to obtain the third-level Bitmap lookup table corresponding to the memory block at the head of the memory block queue in use, and then The first-level storage unit with a default value of 0 can be searched in order in the first-level Bitmap lookup table (the default value of 0 means that the memory is not occupied or not fully occupied), assuming the first preset value queried. The number of the first-level storage unit that is 0 is a, then the second-level storage unit with a preset value of 0 can be searched in order in the a-th row of the second-level Bitmap lookup table, assuming that the first preset value queried. The number of the second-level storage unit that is 0 is b, then the memory management apparatus 200 can search for the third-level storage unit with a preset value of 0 in order in the abth row of the third-level Bitmap lookup table, assuming that the queried first The number of the three-level storage unit with the default value of 0 is ijkl0124, then the memory slice numbered ijkl0124 is the first free memory slice in the memory block queue in use. It should be noted that in the above example, the The numbers are only exemplary and do not limit the invention.

在采取队列方式对内存块和内存分片进行管理时,内存块队列以及内存分片队列之间的逻辑关系可以参见图5,如图5所示,多个内存分片队列可以对应于一个内存块队列,每个内存分片队列所管理的内存分片均是由该内存块队列所管理的内存块划分而成,而在实际场景中,该内存150可以通过多个内存块队列来管理。When using queues to manage memory blocks and memory fragments, the logical relationship between memory block queues and memory fragmentation queues can be seen in Figure 5. As shown in Figure 5, multiple memory fragmentation queues can correspond to one memory In the block queue, the memory segments managed by each memory segment queue are divided by the memory blocks managed by the memory block queue. In an actual scenario, the memory 150 can be managed by multiple memory block queues.

内存分片管理模块230Memory slice management module 230

内存分片管理模块230用于接收到业务请求时,为所述业务请求分配相应长度的空闲内存分片。The memory fragmentation management module 230 is configured to allocate free memory fragments of a corresponding length to the service request when receiving a service request.

为了减少内存碎片,在分配内存分片时,可以优先分配使用内存块队列头部内存块中的内存分片。而由于页表中存储有逻辑地址与物理地址的对应关系,因此,在分配内存分片时,需要使用页表获取中内存分片的内存地址与内存块之间的映射关系,而在分配内存分片时总是分配正使用内存块队列头部内存块中的内存分片,这就使得无需对页表进行切换就可以获取上述映射关系,因此,这种方法可以有效地抑制页表频繁切换带来的负面影响。In order to reduce memory fragmentation, when allocating memory fragments, the memory fragment in the memory block at the head of the memory block queue can be allocated first. Since the corresponding relationship between logical addresses and physical addresses is stored in the page table, when allocating memory slices, it is necessary to use the page table to obtain the mapping relationship between the memory addresses of the memory slices and the memory blocks, and when allocating memory When fragmenting, the memory fragment in the memory block in the head of the memory block queue is always allocated, which makes it possible to obtain the above mapping relationship without switching the page table. Therefore, this method can effectively suppress the frequent switching of the page table. negative impact.

在一种可能设计中,所述内存分片管理模块230,用于接收到业务请求时,从所述业务请求对应长度的空闲内存分片中,优先分配所占用内存块中空闲内存分片数量最少的内存块中的空闲内存分片。In a possible design, the memory fragmentation management module 230 is configured to, when receiving a service request, preferentially allocate the number of free memory fragments in the occupied memory block from the free memory fragments of the length corresponding to the service request Free memory slices in the fewest memory blocks.

发明人认识到,除了优先分配正使用内存块中的内存分片外,还可以优先分配空闲内存分片个数较少的正使用内存块中的内存分片,这样做同样可以起到减少内存碎片,增加内存的使用效率的效果。因此,在本发明的一个实施例中,对于每种长度的内存分片,可以每隔预定时间,检测其正使用内存块队列包含的每个内存块中空闲内存分片的个数,可以按照空闲的内存分片的个数由少到多的顺序,对该正使用内存块队列进行排序,以使空闲内存分片的个数最少的内存块中的内存分片被优先分配,其中该预定时间可以由技术人员进行设定,本发明对此不作具体限定。The inventor realized that, in addition to prioritizing the allocation of memory segments in the memory block in use, it is also possible to prioritize the allocation of memory segments in the memory block in use with a smaller number of free memory segments, which can also reduce memory usage. Fragmentation has the effect of increasing the efficiency of memory usage. Therefore, in an embodiment of the present invention, for each length of memory slices, the number of free memory slices in each memory block included in the memory block queue can be detected every predetermined time, and the number of free memory slices can be determined according to The number of free memory shards is in ascending order, and the queue of memory blocks in use is sorted, so that the memory shards in the memory block with the least number of free memory shards are allocated first. The time can be set by a skilled person, which is not specifically limited in the present invention.

在一种可能设计中,所述内存分片管理模块,用于对于任一种长度的内存分片,以双指针后进先出LIFO缓存的形式,缓存预设数量的所述长度的空闲内存分片的内存地址,在接收到业务请求时,从与所述业务请求响应的所述双指针后进先出LIFO缓存中分配空闲内存分片的内存地址。In a possible design, the memory fragmentation management module is configured to, for memory fragments of any length, cache a preset number of free memory fragments of the length in the form of a double-pointer LIFO cache. The memory address of the slice, when a service request is received, the memory address of the free memory slice is allocated from the double-pointer LIFO cache corresponding to the service request.

为了进一步减少业务申请内存的时延,还可以对于每种长度的内存分片,均提供一双指针后进先出LIFO缓存,用以缓存一定数量的内存地址,使得由业务来申请内存分片时,可以优先从该缓存中直接分配。在采用多级位图Bitmap查找表的维护形式时,能够避免查询上述多级位图Bitmap查找表的步骤,直接从缓存中分配内存,从而进一步降低了业务申请内存的时延,减小了内存管理所需的计算量。In order to further reduce the delay of business applying for memory, a pair of pointer LIFO caches can be provided for each length of memory shard to cache a certain number of memory addresses, so that when a business applies for memory shards, Direct allocation from this cache may be preferred. When the maintenance form of the multi-level bitmap Bitmap lookup table is adopted, the above steps of querying the multi-level bitmap Bitmap lookup table can be avoided, and the memory can be directly allocated from the cache, thereby further reducing the delay of business application memory and reducing the memory Manage the amount of computation required.

对于上述以双指针后进先出LIFO缓存的形式,缓存预设数量的所述长度的空闲内存分片的内存地址的场景,当接收到内存分片使用请求后,可以将栈顶指针对应的存储单元中的待分配内存分片的内存地址优先分配出去。而当接收到内存释放请求后,其可以将待释放内存分片的内存地址也存储至该缓存中,即将该待释放内存分片的内存地址写入栈顶指针对应的存储单元中,以使其可以被优先分配出去,这样可以避免业务申请内存时对页表的频繁切换。For the above scenario in which the memory addresses of a preset number of free memory slices of the described length are cached in the form of a double-pointer LIFO cache, when a memory slice usage request is received, the stack top pointer can be stored in the corresponding memory The memory addresses of the to-be-allocated memory slices in the unit are allocated first. After receiving the memory release request, it can also store the memory address of the memory segment to be released into the cache, that is, write the memory address of the memory segment to be released into the storage unit corresponding to the stack top pointer, so that the It can be allocated preferentially, which can avoid frequent switching of the page table when the business applies for memory.

在一种可能设计中,所述内存分片管理模块230,用于对于任一种长度的内存分片,检测所述双指针后进先出LIFO缓存中的内存地址数量低于预设阈值;若所述内存地址数量低于所述预设阈值,则获取预设数量的内存分片的内存地址存储至所述双指针后进先出LIFO缓存中。In a possible design, the memory fragmentation management module 230 is configured to, for memory fragments of any length, detect that the number of memory addresses in the double-pointer LIFO cache is lower than a preset threshold; if If the number of memory addresses is lower than the preset threshold, the memory addresses of a preset number of memory slices are acquired and stored in the double-pointer LIFO cache.

其中,存储的内存地址个数低于预设阈值,说明待分配内存分片不足,则可以从该长度的内存分片中获取预设数量的内存分片的内存地址。需要说明的是,上述预取阈值以及预设数量可以由技术人员进行设定,本发明对此不做具体限定。例如,以上述正使用内存块队列为例,内存分片管理模块可以根据正使用内存块队列中的内存块排列顺序,在多级位图Bitmap查找表中分级查找正使用内存块中空闲的内存分片,该正使用内存块为一部分内存分片被占用的内存块,按照查找顺序获取预设数量的空闲内存分片,将该预设数量的空闲内存分片的内存地址获取至该缓存中。Wherein, if the number of stored memory addresses is lower than the preset threshold, indicating that the to-be-allocated memory slices are insufficient, the memory addresses of the preset number of memory slices can be obtained from the memory slices of this length. It should be noted that, the above-mentioned prefetch threshold and preset number can be set by a technician, which is not specifically limited in the present invention. For example, taking the above-mentioned memory block queue as an example, the memory slice management module can search for the free memory in the memory block in use in the multi-level Bitmap lookup table hierarchically according to the arrangement order of the memory blocks in the memory block queue in use. Fragment, the memory block in use is a memory block occupied by a part of the memory fragment, obtain a preset number of free memory fragments in the search order, and obtain the memory address of the preset number of free memory fragments into the cache .

为了帮助读者理解上述技术过程,下面基于多级位图Bitmap查找表的结构,对上述获取过程进行说明。例如,通过对缓存中存储的待分配内存分片的个数与预取阈值的比较发现,其需要将获取10个空闲内存分片,则可以查询该多级位图Bitmap查找表,具体地,首先查找一级Bitmap调度表,以获取正使用内存块队列头部第一个内存块对应的三级Bitmap查找表,而后可以在第一级Bitmap查找表中按照顺序查找预设值为0的一级存储单元(预设值为0表示内存未被占用或未被全部占用),假设查询到的第一个预设值为0的一级存储单元的编号为a,则可以在第二级Bitmap查找表的第a行中按照顺序查找预设值为0的二级存储单元,假设查询到的第一个预设值为0的二级存储单元的编号为b,则可以在第三级Bitmap查找表的第ab行中按照顺序查找预设值为0的三级存储单元,若在第三级Bitmap查找表的第ab行中查找到10个预设值为0的三级存储单元,则将上述10个预设值为0的三级存储单元对应的内存分片的内存地址预取至上述缓存中,若在第三级Bitmap查找表的第ab行中查找到的预设值为0的三级存储单元不足10个,则其返回继续在第二级Bitmap查找表的第a行中查找预设值为0的二级存储单元,假设数据存储模块230查询到的第二个预设值为0的二级存储单元的编号为c,则可以在第三级Bitmap查找表的第ac行中按照顺序查找预设值为0的三级存储单元,可以循环执行上述查询过程,直到其将获取到10个内存地址,当然,如果返回第二级Bitmap查找表后仍未查找到足够的内存分片,其可以继续返回第一级Bitmap查找表甚至一级Bitmap调度表中进行查询,需要说明的是,上述预设值以及各级存储单元的编号仅仅是示例性的,其不能限制本发明。In order to help readers understand the above technical process, the above acquisition process is described below based on the structure of the multi-level bitmap Bitmap lookup table. For example, by comparing the number of memory segments to be allocated stored in the cache with the prefetch threshold, it is found that 10 free memory segments need to be acquired, then the multi-level bitmap Bitmap lookup table can be queried. Specifically, First, look up the first-level Bitmap scheduling table to obtain the third-level Bitmap lookup table corresponding to the first memory block at the head of the memory block queue being used. Level storage unit (the default value of 0 means that the memory is not occupied or not fully occupied). Assuming that the number of the first level storage unit with a default value of 0 is queried, it can be stored in the second level Bitmap In the a-th row of the lookup table, the secondary storage unit with the preset value of 0 is searched in order. Assuming that the number of the first secondary storage unit with the preset value of 0 is b, you can use the third-level Bitmap In the abth row of the lookup table, the tertiary storage units with the preset value of 0 are searched in order. If 10 third-level storage units with the preset value of 0 are found in the abth row of the third-level Bitmap lookup table, then Prefetch the memory addresses of the memory slices corresponding to the above-mentioned 10 third-level storage units with a default value of 0 into the above cache, if the default value found in the abth row of the third-level Bitmap lookup table is 0 If there are less than 10 third-level storage units, then it returns to continue to search for the second-level storage unit with a preset value of 0 in the a-th row of the second-level Bitmap lookup table, assuming that the second preset value queried by the data storage module 230 The number of the second-level storage unit with a value of 0 is c, then the third-level storage unit with a preset value of 0 can be searched in order in the ac-th row of the third-level Bitmap lookup table, and the above query process can be executed cyclically until it is 10 memory addresses will be obtained. Of course, if enough memory fragments are not found after returning to the second-level Bitmap lookup table, it can continue to return to the first-level Bitmap lookup table or even the first-level Bitmap scheduling table for query. It should be noted that the above-mentioned preset values and the numbers of the storage units at all levels are only exemplary, and do not limit the present invention.

需要指出的是,上述将预设数量的空闲内存分片的内存地址获取至该缓存后,可以在多级位图Bitmap查找表中,将上述预设数量的空闲内存分片对应三级存储单元的预设值进行修改,以表明该预设数量的空闲内存分片的内存地址已经被获取至上述缓存中,从而避免在下次获取过程中出现错误。It should be pointed out that after the above-mentioned memory addresses of the preset number of free memory slices are obtained into the cache, the above-mentioned preset number of free memory slices can be corresponding to the three-level storage unit in the multi-level bitmap Bitmap lookup table. The preset value of , is modified to indicate that the memory addresses of the preset number of free memory slices have been acquired into the above cache, so as to avoid errors in the next acquisition process.

而进一步地,对于任一种长度的内存分片,检测所述双指针后进先出LIFO缓存中的内存地址数量是否高于回收阈值;若所述内存地址数量高于所述回收阈值,则从所述双指针后进先出LIFO缓存中释放预设数量的内存分片的内存地址。该释放可以是指将内存分片以此回收到三级Bitmap查找表中。And further, for a memory fragment of any length, it is detected whether the number of memory addresses in the double-pointer LIFO cache is higher than the recycling threshold; if the number of memory addresses is higher than the recycling threshold, then The two-pointer LIFO cache releases the memory addresses of the preset number of memory slices. The release may refer to reclaiming the memory fragment into the three-level Bitmap lookup table.

还需要指出的是,上述缓存的存储结构可以是多种多样的,如上述缓存可以为后进先出LIFO缓存,也可以为先进先出FIFO缓存等,本发明对此不做具体限定,当上述缓存为双指针后进先出LIFO缓存时,该缓存可以包括栈顶指针和栈底指针,可以将预设数量的空闲内存分片写入该双指针后进先出LIFO缓存的栈底指针对应的存储单元中。It should also be pointed out that the storage structure of the above cache can be various, for example, the above cache can be a LIFO cache, or a FIFO cache, etc., which is not specifically limited in the present invention. When the cache is a double-pointer LIFO cache, the cache can include a stack top pointer and a stack bottom pointer, and a preset number of free memory slices can be written into the storage corresponding to the stack bottom pointer of the double-pointer LIFO cache. in the unit.

数据存储模块240data storage module 240

数据存储模块240用于根据所述内存分片管理模块分配到的空闲内存分片的内存地址,存储所述业务请求对应的数据。该数据存储模块240作为处理业务请求的前端,其具体存储过程在此不做赘述。The data storage module 240 is configured to store the data corresponding to the service request according to the memory addresses of the free memory segments allocated by the memory segment management module. The data storage module 240 serves as a front end for processing service requests, and its specific storage process is not described here.

本发明实施例提供的装置,通过对内存块和内存分片进行分层次管理,并根据内存分片的实际占用情况,灵活的申请或释放内存块,实现了内存块的动态管理,能够满足业务的突发性,增强了内存资源的共享性,避免了资源浪费,提高了内存使用效率。此外,可以通过缓存的方式预先获取一些待分配的内存分片的内存地址,使得在业务申请内存时直接将该缓存中的内存分片的内存地址分配给所述业务,而不需要对进行空闲内存分片的查询,从而可以减小业务申请内存的时延。The device provided by the embodiment of the present invention implements dynamic management of memory blocks by performing hierarchical management on memory blocks and memory slices, and flexibly applies for or releases memory blocks according to the actual occupation of memory slices, thereby realizing dynamic management of memory blocks and meeting business needs. The burstiness of memory resources enhances the sharing of memory resources, avoids resource waste, and improves memory usage efficiency. In addition, the memory addresses of some to-be-allocated memory slices can be pre-obtained by means of caching, so that when a service applies for memory, the memory addresses of the memory slices in the cache are directly allocated to the service, without the need for idling The query of memory shards can reduce the delay of business application for memory.

图6是本发明实施例提供的一种内存管理方法的流程图。参见图6,该实施例具体包括:FIG. 6 is a flowchart of a memory management method provided by an embodiment of the present invention. Referring to Figure 6, this embodiment specifically includes:

601、监控至少两个内存块的状态;当一个内存块已进行内存分片时,则所述内存块的状态为占用状态,当一个内存块未进行内存分片时,则所述内存块的状态为空闲状态。601. Monitor the states of at least two memory blocks; when a memory block has been fragmented, the state of the memory block is an occupied state, and when a memory block has not been fragmented, the state of the memory block is occupied. The state is idle.

602、监控至少两个内存分片的状态,所述至少两个内存分片包括至少两种分片长度,每个内存分片由内存块划分而成。602. Monitor the status of at least two memory segments, where the at least two memory segments include at least two segment lengths, and each memory segment is divided into memory blocks.

603、如果同一长度的空闲内存分片数量少于内存块申请阈值,则根据所述至少两个内存块的状态,申请处于空闲状态的内存块进行划分;如果同一长度的空闲内存分片数量大于内存块释放阈值,则释放所述同一长度的空闲内存分片。603. If the number of free memory fragments of the same length is less than the memory block application threshold, then according to the states of the at least two memory blocks, apply for a memory block in an idle state for division; if the number of free memory fragments of the same length is greater than If the memory block release threshold is set, then free memory fragments of the same length are released.

需要说明的是,上述步骤601至603的执行顺序可以是并行,也可以是任一种执行顺序,且其监控周期可以相同也可以不同,本发明实施例对此不做具体限定。It should be noted that the execution sequence of the above steps 601 to 603 may be parallel or any execution sequence, and the monitoring periods may be the same or different, which is not specifically limited in this embodiment of the present invention.

604、在接收到业务请求时,为所述业务请求分配相应长度的空闲内存分片。604. When a service request is received, allocate an idle memory segment of a corresponding length to the service request.

605、根据分配到的空闲内存分片的内存地址,存储所述业务请求对应的数据。605. Store data corresponding to the service request according to the allocated memory addresses of the free memory slices.

在一种可能设计中,所述方法还包括:In one possible design, the method further includes:

对于任一种长度的内存分片,若在预设时间内没有接收到对所述长度的内存分片的申请,则释放所述长度的内存分片所占用的内存块。For a memory fragment of any length, if no application for the memory fragment of the length is received within a preset time, the memory block occupied by the memory fragment of the length is released.

在一种可能设计中,对于任一种长度的内存分片,以未使用内存块队列、已耗尽内存块队列以及正使用内存块队列的形式管理所述长度的内存分片所占用的内存块的内存地址;In one possible design, for a memory slice of any length, the memory occupied by a memory slice of that length is managed in the form of a queue of unused memory blocks, a queue of exhausted memory blocks, and a queue of memory blocks in use the memory address of the block;

所述未使用内存块队列包括所述长度的内存分片中所有内存分片均空闲的内存块的内存地址;The unused memory block queue includes the memory addresses of the memory blocks in which all memory fragments of the length are free;

所述已耗尽内存块队列包括所述长度的内存分片中所有内存分片均被占用的内存块的内存地址;The exhausted memory block queue includes the memory addresses of the memory blocks in which all memory fragments of the length are occupied;

所述正使用内存块队列包括所述长度的内存分片中部分内存分片被占用的内存块的内存地址。The memory block queue in use includes memory addresses of memory blocks occupied by some of the memory segments in the memory segments of the length.

在一种可能设计中,在接收到业务请求时,为所述业务请求分配相应长度的空闲内存分片包括:In a possible design, when a service request is received, allocating an idle memory segment of a corresponding length to the service request includes:

在接收到所述业务请求时,从所述业务请求对应长度的空闲内存分片中,优先分配所占用内存块中空闲内存分片数量最少的内存块中的空闲内存分片。When the service request is received, from the free memory fragments of the length corresponding to the service request, the free memory fragment in the memory block with the smallest number of free memory fragments among the occupied memory blocks is preferentially allocated.

在一种可能设计中,对于任一种长度的内存分片,采用多级位图Bitmap查找表的方式维护所述长度的内存分片的占用情况。In a possible design, for a memory slice of any length, a multi-level Bitmap lookup table is used to maintain the occupancy of the memory slice of the length.

在一种可能设计中,所述方法还包括:In one possible design, the method further includes:

对于任一种大小的内存块,检测所述大小的内存块中处于占用状态的内存块的比例是否小于第一预设阈值;For memory blocks of any size, detecting whether the proportion of memory blocks in an occupied state in the memory blocks of the size is less than a first preset threshold;

若所述比例小于所述第一预设阈值,则卸载所述大小的内存块中至少一个处于空闲状态的内存块。If the ratio is less than the first preset threshold, unload at least one memory block in an idle state among the memory blocks of the size.

在一种可能设计中,所述方法还包括:In one possible design, the method further includes:

对于任一种大小的内存块,检测所述大小的内存块中处于占用状态的内存块的比例是否大于第二预设阈值;For memory blocks of any size, detecting whether the proportion of memory blocks in the occupied state in the memory blocks of the size is greater than a second preset threshold;

若所述比例大于所述第二预设阈值,则从系统内存中加载至少一个处于空闲状态的内存块。If the ratio is greater than the second preset threshold, load at least one memory block in an idle state from the system memory.

在一种可能设计中,所述方法还包括:In one possible design, the method further includes:

对于任一种长度的内存分片,以双指针后进先出LIFO缓存的形式,缓存预设数量的所述长度的空闲内存分片的内存地址;For memory slices of any length, cache the memory addresses of a preset number of free memory slices of the length in the form of a double-pointer LIFO cache;

相应地,在接收到业务请求时,从与所述业务请求响应的所述双指针后进先出LIFO缓存中分配空闲内存分片的内存地址。Correspondingly, when a service request is received, the memory address of the free memory slice is allocated from the double-pointer LIFO cache corresponding to the service request.

在一种可能设计中,所述方法还包括:In one possible design, the method further includes:

对于任一种长度的内存分片,检测所述双指针后进先出LIFO缓存中的内存地址数量低于预设阈值;For memory slices of any length, detect that the number of memory addresses in the double-pointer LIFO cache is lower than a preset threshold;

若所述内存地址数量低于所述预设阈值,则获取预设数量的内存分片的内存地址存储至所述双指针后进先出LIFO缓存中。If the number of memory addresses is lower than the preset threshold, the memory addresses of a preset number of memory slices are acquired and stored in the double-pointer LIFO cache.

需要说明的是,上述方法实施例的具体实施过程与装置实施例中所述同理,在此不做赘述。It should be noted that, the specific implementation process of the foregoing method embodiment is the same as that described in the apparatus embodiment, and is not repeated here.

所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的方法的具体过程,可以参考装置实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and brevity of description, for the specific process of the method described above, reference may be made to the corresponding process in the apparatus embodiment, which is not repeated here.

本领域普通技术人员可以理解实现上述实施例的全部或部分步骤可以通过硬件来完成,也可以通过程序来指令相关的硬件完成,所述的程序可以存储于一种计算机可读存储介质中,上述提到的存储介质可以是只读存储器,磁盘或光盘等。Those of ordinary skill in the art can understand that all or part of the steps of implementing the above embodiments can be completed by hardware, or can be completed by instructing relevant hardware through a program, and the program can be stored in a computer-readable storage medium. The storage medium mentioned may be a read-only memory, a magnetic disk or an optical disk, etc.

以上所述仅为本发明的较佳实施例,并不用以限制本发明,凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included in the protection of the present invention. within the range.

Claims (16)

1.一种内存管理装置,其特征在于,包括:1. A memory management device, comprising: 内存块状态监控模块,用于监控至少两个内存块的状态;当一个内存块已进行内存分片时,则所述内存块的状态为占用状态,当一个内存块未进行内存分片时,则所述内存块的状态为空闲状态;The memory block status monitoring module is used to monitor the status of at least two memory blocks; when a memory block has been fragmented, the status of the memory block is occupied, and when a memory block has not been fragmented, Then the state of the memory block is an idle state; 内存分片监控模块,用于监控至少两个内存分片的状态,所述至少两个内存分片包括至少两种分片长度,每个内存分片由内存块划分而成;a memory fragmentation monitoring module, configured to monitor the status of at least two memory fragments, the at least two memory fragments include at least two fragment lengths, and each memory fragment is divided into memory blocks; 所述内存分片监控模块,还用于如果同一长度的空闲内存分片数量少于内存块申请阈值,则根据所述至少两个内存块的状态,申请处于空闲状态的内存块进行划分;如果同一长度的空闲内存分片数量大于内存块释放阈值,则释放所述同一长度的空闲内存分片;The memory fragmentation monitoring module is further configured to, if the number of free memory fragments of the same length is less than the memory block application threshold, apply for a memory block in an idle state for division according to the states of the at least two memory blocks; if If the number of free memory fragments of the same length is greater than the memory block release threshold, the free memory fragments of the same length are released; 内存分片管理模块,用于接收到业务请求时,从所述业务请求对应长度的空闲内存分片中,优先分配所占用内存块中空闲内存分片数量最少的内存块中的空闲内存分片;The memory fragmentation management module is configured to preferentially allocate the free memory fragment in the memory block with the least number of free memory fragments among the occupied memory blocks from the free memory fragments of the corresponding length of the service request when receiving a service request ; 数据存储模块,用于根据所述内存分片管理模块分配到的空闲内存分片的内存地址,存储所述业务请求对应的数据。A data storage module, configured to store the data corresponding to the service request according to the memory addresses of the free memory segments allocated by the memory segment management module. 2.根据权利要求1所述的装置,其特征在于,所述内存分片监控模块用于:2. The device according to claim 1, wherein the memory fragmentation monitoring module is used for: 对于任一种长度的内存分片,若在预设时间内没有接收到对所述长度的内存分片的申请,则释放所述长度的内存分片所占用的内存块。For a memory fragment of any length, if no application for the memory fragment of the length is received within a preset time, the memory block occupied by the memory fragment of the length is released. 3.根据权利要求1所述的装置,其特征在于,所述内存分片监控模块用于对于任一种长度的内存分片,以未使用内存块队列、已耗尽内存块队列以及正使用内存块队列的形式管理所述长度的内存分片所占用的内存块的内存地址;3. device according to claim 1, is characterized in that, described memory fragmentation monitoring module is used for the memory fragmentation of any kind of length, with unused memory block queue, exhausted memory block queue and being used. The memory address of the memory block occupied by the memory segment of the described length is managed in the form of a memory block queue; 所述未使用内存块队列包括所述长度的内存分片中所有内存分片均空闲的内存块的内存地址;The unused memory block queue includes the memory addresses of the memory blocks in which all memory fragments of the length are free; 所述已耗尽内存块队列包括所述长度的内存分片中所有内存分片均被占用的内存块的内存地址;The exhausted memory block queue includes the memory addresses of the memory blocks in which all memory fragments of the length are occupied; 所述正使用内存块队列包括所述长度的内存分片中部分内存分片被占用的内存块的内存地址。The memory block queue in use includes memory addresses of memory blocks occupied by some of the memory segments in the memory segments of the length. 4.根据权利要求1所述的装置,其特征在于,所述内存分片监控模块用于对于任一种长度的内存分片,采用多级位图Bitmap查找表的方式维护所述长度的内存分片的占用情况。4. device according to claim 1, is characterized in that, described memory fragmentation monitoring module is used for the memory fragmentation of any kind of length, adopts the mode of multi-level bitmap Bitmap lookup table to maintain the memory of described length Shard occupancy. 5.根据权利要求1所述的装置,其特征在于,所述内存块状态监控模块还用于:5. The device according to claim 1, wherein the memory block status monitoring module is further used for: 对于任一种大小的内存块,检测所述大小的内存块中处于占用状态的内存块的比例是否小于第一预设阈值;For memory blocks of any size, detecting whether the proportion of memory blocks in an occupied state in the memory blocks of the size is less than a first preset threshold; 若所述比例小于所述第一预设阈值,则卸载所述大小的内存块中至少一个处于空闲状态的内存块。If the ratio is less than the first preset threshold, unload at least one memory block in an idle state among the memory blocks of the size. 6.根据权利要求1所述的装置,其特征在于,所述内存块状态监控模块还用于:6. The device according to claim 1, wherein the memory block status monitoring module is further used for: 对于任一种大小的内存块,检测所述大小的内存块中处于占用状态的内存块的比例是否大于第二预设阈值;For memory blocks of any size, detecting whether the proportion of memory blocks in the occupied state in the memory blocks of the size is greater than a second preset threshold; 若所述比例大于所述第二预设阈值,则从系统内存中加载至少一个处于空闲状态的内存块。If the ratio is greater than the second preset threshold, load at least one memory block in an idle state from the system memory. 7.根据权利要求1所述的装置,其特征在于,所述内存分片管理模块,用于对于任一种长度的内存分片,以双指针后进先出LIFO缓存的形式,缓存预设数量的所述长度的空闲内存分片的内存地址,在接收到业务请求时,从与所述业务请求响应的所述双指针后进先出LIFO缓存中分配空闲内存分片的内存地址。7. device according to claim 1, is characterized in that, described memory fragmentation management module, for the memory fragmentation of any kind of length, in the form of double pointer LIFO cache, cache preset quantity When a service request is received, the memory address of the free memory fragment is allocated from the double-pointer LIFO cache that responds to the service request. 8.根据权利要求7所述的装置,其特征在于,所述内存分片管理模块,用于对于任一种长度的内存分片,检测所述双指针后进先出LIFO缓存中的内存地址数量低于预设阈值;8. device according to claim 7, is characterized in that, described memory fragmentation management module, is used for the memory fragmentation of any kind of length, detects the memory address quantity in described double pointer LIFO cache memory below the preset threshold; 若所述内存地址数量低于所述预设阈值,则获取预设数量的内存分片的内存地址存储至所述双指针后进先出LIFO缓存中。If the number of memory addresses is lower than the preset threshold, the memory addresses of a preset number of memory slices are acquired and stored in the double-pointer LIFO cache. 9.一种内存管理方法,其特征在于,包括:9. A memory management method, comprising: 监控至少两个内存块的状态;当一个内存块已进行内存分片时,则所述内存块的状态为占用状态,当一个内存块未进行内存分片时,则所述内存块的状态为空闲状态;Monitor the status of at least two memory blocks; when a memory block has been fragmented, the status of the memory block is occupied, and when a memory block has not been fragmented, the status of the memory block is idle state; 监控至少两个内存分片的状态,所述至少两个内存分片包括至少两种分片长度,每个内存分片由内存块划分而成;Monitoring the status of at least two memory fragments, the at least two memory fragments include at least two fragment lengths, and each memory fragment is divided into memory blocks; 如果同一长度的空闲内存分片数量少于内存块申请阈值,则根据所述至少两个内存块的状态,申请处于空闲状态的内存块进行划分;如果同一长度的空闲内存分片数量大于内存块释放阈值,则释放所述同一长度的空闲内存分片;If the number of free memory fragments of the same length is less than the memory block application threshold, then according to the states of the at least two memory blocks, apply for the memory blocks in the free state for division; if the number of free memory fragments of the same length is greater than the memory block If the threshold is released, the free memory fragments of the same length are released; 在接收到业务请求时,从所述业务请求对应长度的空闲内存分片中,优先分配所占用内存块中空闲内存分片数量最少的内存块中的空闲内存分片;When receiving a service request, from the free memory fragments of the corresponding length of the service request, preferentially allocate the free memory fragment in the memory block with the least number of free memory fragments among the occupied memory blocks; 根据分配到的空闲内存分片的内存地址,存储所述业务请求对应的数据。The data corresponding to the service request is stored according to the allocated memory addresses of the free memory segments. 10.根据权利要求9所述的方法,其特征在于,所述方法还包括:10. The method according to claim 9, wherein the method further comprises: 对于任一种长度的内存分片,若在预设时间内没有接收到对所述长度的内存分片的申请,则释放所述长度的内存分片所占用的内存块。For a memory fragment of any length, if no application for the memory fragment of the length is received within a preset time, the memory block occupied by the memory fragment of the length is released. 11.根据权利要求9所述的方法,其特征在于,对于任一种长度的内存分片,以未使用内存块队列、已耗尽内存块队列以及正使用内存块队列的形式管理所述长度的内存分片所占用的内存块的内存地址;11. The method of claim 9, wherein, for a memory slice of any length, the length is managed in the form of a queue of unused memory blocks, a queue of exhausted memory blocks, and a queue of memory blocks in use The memory address of the memory block occupied by the memory slice; 所述未使用内存块队列包括所述长度的内存分片中所有内存分片均空闲的内存块的内存地址;The unused memory block queue includes the memory addresses of the memory blocks in which all memory fragments of the length are free; 所述已耗尽内存块队列包括所述长度的内存分片中所有内存分片均被占用的内存块的内存地址;The exhausted memory block queue includes the memory addresses of the memory blocks in which all memory fragments of the length are occupied; 所述正使用内存块队列包括所述长度的内存分片中部分内存分片被占用的内存块的内存地址。The memory block queue in use includes memory addresses of memory blocks occupied by some of the memory segments in the memory segments of the length. 12.根据权利要求9所述的方法,其特征在于,对于任一种长度的内存分片,采用多级位图Bitmap查找表的方式维护所述长度的内存分片的占用情况。12 . The method according to claim 9 , wherein, for a memory fragment of any length, a multi-level Bitmap lookup table is used to maintain the occupancy of the memory fragment of the length. 13 . 13.根据权利要求9所述的方法,其特征在于,所述方法还包括:13. The method of claim 9, wherein the method further comprises: 对于任一种大小的内存块,检测所述大小的内存块中处于占用状态的内存块的比例是否小于第一预设阈值;For memory blocks of any size, detecting whether the proportion of memory blocks in an occupied state in the memory blocks of the size is less than a first preset threshold; 若所述比例小于所述第一预设阈值,则卸载所述大小的内存块中至少一个处于空闲状态的内存块。If the ratio is less than the first preset threshold, unload at least one memory block in an idle state among the memory blocks of the size. 14.根据权利要求9所述的方法,其特征在于,所述方法还包括:14. The method of claim 9, wherein the method further comprises: 对于任一种大小的内存块,检测所述大小的内存块中处于占用状态的内存块的比例是否大于第二预设阈值;For memory blocks of any size, detecting whether the proportion of memory blocks in the occupied state in the memory blocks of the size is greater than a second preset threshold; 若所述比例大于所述第二预设阈值,则从系统内存中加载至少一个处于空闲状态的内存块。If the ratio is greater than the second preset threshold, load at least one memory block in an idle state from the system memory. 15.根据权利要求9所述的方法,其特征在于,所述方法还包括:15. The method of claim 9, wherein the method further comprises: 对于任一种长度的内存分片,以双指针后进先出LIFO缓存的形式,缓存预设数量的所述长度的空闲内存分片的内存地址;For memory slices of any length, cache the memory addresses of a preset number of free memory slices of the length in the form of a double-pointer LIFO cache; 相应地,在接收到业务请求时,从与所述业务请求响应的所述双指针后进先出LIFO缓存中分配空闲内存分片的内存地址。Correspondingly, when a service request is received, the memory address of the free memory slice is allocated from the double-pointer LIFO cache corresponding to the service request. 16.根据权利要求15所述的方法,其特征在于,所述方法还包括:16. The method of claim 15, wherein the method further comprises: 对于任一种长度的内存分片,检测所述双指针后进先出LIFO缓存中的内存地址数量低于预设阈值;For memory slices of any length, detect that the number of memory addresses in the double-pointer LIFO cache is lower than a preset threshold; 若所述内存地址数量低于所述预设阈值,则获取预设数量的内存分片的内存地址存储至所述双指针后进先出LIFO缓存中。If the number of memory addresses is lower than the preset threshold, the memory addresses of a preset number of memory slices are acquired and stored in the double-pointer LIFO cache.
CN201610618811.7A 2016-07-29 2016-07-29 Memory management device and method Active CN107665146B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201610618811.7A CN107665146B (en) 2016-07-29 2016-07-29 Memory management device and method
PCT/CN2017/076666 WO2018018896A1 (en) 2016-07-29 2017-03-14 Memory management apparatus and method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610618811.7A CN107665146B (en) 2016-07-29 2016-07-29 Memory management device and method

Publications (2)

Publication Number Publication Date
CN107665146A CN107665146A (en) 2018-02-06
CN107665146B true CN107665146B (en) 2020-07-07

Family

ID=61016909

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610618811.7A Active CN107665146B (en) 2016-07-29 2016-07-29 Memory management device and method

Country Status (2)

Country Link
CN (1) CN107665146B (en)
WO (1) WO2018018896A1 (en)

Families Citing this family (20)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108984323B (en) * 2018-07-13 2022-04-01 上海联影医疗科技股份有限公司 Scheduling method and system for shared storage space
CN109213596B (en) * 2018-08-01 2023-03-10 青岛海信移动通信技术股份有限公司 Method and equipment for allocating terminal memory
CN109656836A (en) * 2018-12-24 2019-04-19 新华三技术有限公司 A kind of data processing method and device
CN109800089A (en) * 2019-01-24 2019-05-24 湖南国科微电子股份有限公司 A kind of buffer resource distribution method, module and electronic equipment
CN110008021B (en) * 2019-03-05 2024-05-28 平安科技(深圳)有限公司 Memory management method, memory management device, electronic equipment and computer readable storage medium
CN110471759B (en) * 2019-07-04 2023-09-01 中科晶上(苏州)信息技术有限公司 Method for dynamically managing memory of multi-core embedded processor in real time
CN111309482B (en) * 2020-02-20 2023-08-15 浙江亿邦通信科技有限公司 Hash algorithm-based block chain task allocation system, device and storable medium
CN113326120B (en) * 2020-02-29 2023-12-26 杭州迪普科技股份有限公司 Apparatus and method for managing memory
CN113535597B (en) * 2020-04-14 2024-05-03 阿里巴巴集团控股有限公司 Memory management method, memory management unit and Internet of things equipment
CN113485822A (en) * 2020-06-19 2021-10-08 中兴通讯股份有限公司 Memory management method, system, client, server and storage medium
CN113961363A (en) * 2020-07-20 2022-01-21 中移(苏州)软件技术有限公司 A data caching method and electronic device
CN111984652B (en) 2020-08-28 2022-08-12 苏州浪潮智能科技有限公司 A method for finding free blocks in bitmap data and related components
CN114253457B (en) * 2020-09-21 2024-06-25 华为技术有限公司 Memory control method and device
CN112650449B (en) * 2020-12-23 2022-12-27 展讯半导体(南京)有限公司 Method and system for releasing cache space, electronic device and storage medium
CN112685333B (en) * 2020-12-28 2024-06-07 上海创功通讯技术有限公司 Heap memory management method and device
CN114020458B (en) * 2021-10-30 2024-10-15 江苏信而泰智能装备有限公司 Data resource allocation method, system, intelligent terminal and readable storage medium
CN114416380B (en) * 2022-02-24 2025-05-09 成都北中网芯科技有限公司 A management method for fast application and release of pointers
CN114327917A (en) * 2022-03-11 2022-04-12 武汉深之度科技有限公司 Memory management method, computing device and readable storage medium
CN117591293B (en) * 2023-12-01 2024-07-19 深圳计算科学研究院 Memory management method, memory management device, computer equipment and computer readable storage medium
CN117573377B (en) * 2024-01-15 2024-06-25 摩尔线程智能科技(北京)有限责任公司 Memory management method, device, equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1489334A (en) * 2002-10-11 2004-04-14 深圳市中兴通讯股份有限公司 Method for storage area management with static and dynamic joint
CN1532708A (en) * 2003-03-19 2004-09-29 华为技术有限公司 A static memory management method
CN101122883A (en) * 2006-08-09 2008-02-13 中兴通讯股份有限公司 Memory allocation method for avoiding RAM fragmentation
CN101847127A (en) * 2010-06-18 2010-09-29 福建星网锐捷网络有限公司 Memory management method and device
CN102455974A (en) * 2010-10-21 2012-05-16 上海宝信软件股份有限公司 High-speed internal memory application and release management system with controllable internal memory consumption and high-speed internal memory application release management method

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103136104B (en) * 2011-11-24 2016-04-06 深圳市快播科技有限公司 A kind of EMS memory management process and system
US9541984B2 (en) * 2013-06-05 2017-01-10 Apple Inc. L2 flush and memory fabric teardown
CN105469173A (en) * 2014-08-19 2016-04-06 西安慧泽知识产权运营管理有限公司 Method of optimal management on static memory

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1489334A (en) * 2002-10-11 2004-04-14 深圳市中兴通讯股份有限公司 Method for storage area management with static and dynamic joint
CN1532708A (en) * 2003-03-19 2004-09-29 华为技术有限公司 A static memory management method
CN101122883A (en) * 2006-08-09 2008-02-13 中兴通讯股份有限公司 Memory allocation method for avoiding RAM fragmentation
CN101847127A (en) * 2010-06-18 2010-09-29 福建星网锐捷网络有限公司 Memory management method and device
CN102455974A (en) * 2010-10-21 2012-05-16 上海宝信软件股份有限公司 High-speed internal memory application and release management system with controllable internal memory consumption and high-speed internal memory application release management method

Also Published As

Publication number Publication date
WO2018018896A1 (en) 2018-02-01
CN107665146A (en) 2018-02-06

Similar Documents

Publication Publication Date Title
CN107665146B (en) Memory management device and method
CN104090847B (en) Address distribution method of solid-state storage device
KR101357397B1 (en) Method for tracking memory usages of a data processing system
US10268410B2 (en) Efficient modification of storage system metadata
US20160132541A1 (en) Efficient implementations for mapreduce systems
CN110196770B (en) Cloud system memory data processing method, device, equipment and storage medium
US11366758B2 (en) Method and devices for managing cache
CN110333956A (en) Message storage method, device, medium and electronic equipment in message queue
US20130232124A1 (en) Deduplicating a file system
WO2022199560A1 (en) Memory management method and device
KR101915944B1 (en) A Method for processing client requests in a cluster system, a Method and an Apparatus for processing I/O according to the client requests
CN105468305A (en) Data caching method, apparatus and system
US10514848B2 (en) Data storage method for selectively storing data in a buffer preset in a memory of an electronic device or an inherent buffer in an SSD
US11231964B2 (en) Computing device shared resource lock allocation
CN105677575A (en) Memory resource management method and apparatus
WO2017070869A1 (en) Memory configuration method, apparatus and system
CN113204382B (en) Data processing method, device, electronic equipment and storage medium
CN115145493A (en) A resource allocation method based on ZNS SSD system
CN105512048B (en) data configuration method and device
CN117539796B (en) Electronic device and buffer memory management method
US9965211B2 (en) Dynamic packet buffers with consolidation of low utilized memory banks
CN113127183B (en) Memory allocation method and device in user mode protocol stack
CN108733593B (en) Method, apparatus and computer readable medium for storage management
CN109413122A (en) Data processing method, network processor and computer storage medium
US10430087B1 (en) Shared layered physical space

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