CN106469121B - Method and device for allocating memory - Google Patents
Method and device for allocating memory Download PDFInfo
- Publication number
- CN106469121B CN106469121B CN201610813881.8A CN201610813881A CN106469121B CN 106469121 B CN106469121 B CN 106469121B CN 201610813881 A CN201610813881 A CN 201610813881A CN 106469121 B CN106469121 B CN 106469121B
- Authority
- CN
- China
- Prior art keywords
- slab
- class
- objects
- memory
- source
- 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.)
- Expired - Fee Related
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/02—Addressing or allocation; Relocation
- G06F12/0223—User address space allocation, e.g. contiguous or non contiguous base addressing
- G06F12/023—Free address space management
- G06F12/0253—Garbage collection, i.e. reclamation of unreferenced memory
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F12/00—Accessing, addressing or allocating within memory systems or architectures
- G06F12/02—Addressing or allocation; Relocation
- G06F12/08—Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
- G06F12/0802—Addressing of a memory level in which the access to the desired data or data block requires associative addressing means, e.g. caches
- G06F12/0893—Caches characterised by their organisation or structure
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Memory System (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明公开了一种内存分配的方法及装置,通过获取每个slab类的信息;根据预先设置的最小影响因子选择算法和所述信息计算每个slab类的影响因子;将影响因子最小的slab类选取为源slab类,将一段时间内换出数量最多的slab设置为目的slab;将所述源slab类中的一个slab内存清空回收后重分配给所述目的slab,提出最小影响因子选择算法,综合考虑压缩情况下的存储数据的特征,合理选择恰当的源slab类和目的slab进行回收和重分配;调整Memcached的内存分配机制,根据slab存储状态空、满等有效地划分了区域,当需要内存的时候从末尾空闲的slab开始回收。
The invention discloses a memory allocation method and device. By acquiring the information of each slab class; calculating the influence factor of each slab class according to the preset minimum influence factor selection algorithm and the information; and assigning the slab with the smallest influence factor The class is selected as the source slab class, and the slab with the largest number of swapped out within a period of time is set as the destination slab; the memory of a slab in the source slab class is cleared and redistributed to the destination slab, and the minimum impact factor selection algorithm is proposed , comprehensively consider the characteristics of stored data in the case of compression, reasonably select the appropriate source slab class and destination slab for recycling and reallocation; adjust the memory allocation mechanism of Memcached, and effectively divide the area according to the slab storage status empty, full, etc., when When memory is needed, it starts recycling from the free slab at the end.
Description
技术领域technical field
本发明实施例涉及内存分配的技术领域,尤其涉及一种内存分配的方法及装置。Embodiments of the present invention relate to the technical field of memory allocation, and in particular, to a memory allocation method and device.
背景技术Background technique
Memcached根据请求对象的大小,将内存分配给相应的slab类。一旦Memcached中所有可用内存全部分配出去,当由于请求分布发生变化而导致内存重分配时问题就产生了,简称为钙化问题(Calcification),即Memcached中所有slab类的个数比例已经固定,无法根据变化的外部请求动态调整。如果Memcached需要存储的对象的大小分布情况不随着时间发生变化,那么钙化问题不会影响Memcached的性能,因为Memcached中已经实现的基本换出策略可以很好地保证存储热对象。然而,如果存储对象的大小分布情况随时在变化,使得钙化问题对Memcached的命中率有较大影响。Memcached allocates memory to the corresponding slab class according to the size of the requested object. Once all the available memory in Memcached is allocated, the problem arises when the memory is redistributed due to changes in the distribution of requests, which is referred to as the Calcification problem (Calcification). Changing external requests are dynamically adjusted. If the size distribution of the objects that Memcached needs to store does not change over time, then the calcification problem will not affect the performance of Memcached, because the basic swapping strategy implemented in Memcached can well guarantee the storage of hot objects. However, if the size distribution of storage objects changes at any time, the calcification problem has a greater impact on the hit rate of Memcached.
解决Memcached钙化问题的直接方法是允许Memcached将已经分配出去的内存进行回收和重新分配给需要的slab类。数据压缩加剧了Memcached的钙化问题。在Memcached启动数据压缩功能的时候,不仅会在被压缩的slab类中留下的空间无法归还给Memcached,而且会对压缩后存入的slab类造成较大的压力。在添加了数据压缩功能的Memcached中,尽管数据压缩给Memcached带来了不同的性能提升效果,但是也加剧了Memcached的钙化问题。The direct way to solve the Memcached calcification problem is to allow Memcached to reclaim and reallocate the allocated memory to the required slab classes. Data compression exacerbates Memcached's calcification problem. When Memcached starts the data compression function, not only the space left in the compressed slab class cannot be returned to Memcached, but also it will cause greater pressure on the compressed slab class. In Memcached with the data compression function added, although data compression brings different performance improvement effects to Memcached, it also exacerbates the calcification problem of Memcached.
发明内容Contents of the invention
本发明实施例的目的在于提出一种内存分配的方法及装置,旨在解决添加了数据压缩功能的Memcached中的钙化问题。The purpose of the embodiments of the present invention is to provide a method and device for memory allocation, aiming at solving the problem of calcification in Memcached with added data compression function.
为达此目的,本发明实施例采用以下技术方案:To achieve this purpose, the embodiments of the present invention adopt the following technical solutions:
第一方面,一种内存分配的方法,所述方法包括:In a first aspect, a method for memory allocation, the method comprising:
获取每个slab类的信息,所述信息包括已使用对象数量、请求数量、对象总数和换出数量;Obtain the information of each slab class, the information including the number of used objects, the number of requests, the total number of objects and the number of swapped out;
根据预先设置的最小影响因子选择算法和所述信息计算每个slab类的影响因子;Calculate the impact factor of each slab class according to the preset minimum impact factor selection algorithm and the information;
将影响因子最小的slab类选取为源slab类,将一段时间内换出数量最多的slab设置为目的slab;Select the slab class with the smallest impact factor as the source slab class, and set the slab with the largest number of swaps out within a period of time as the destination slab;
将所述源slab类中的一个slab内存清空回收后重分配给所述目的slab。A slab memory in the source slab class is emptied and recovered and then redistributed to the target slab.
优选地,所述根据预先设置的最小影响因子选择算法和所述信息计算每个slab类的影响因子,包括:Preferably, the calculation of the impact factor of each slab class according to the preset minimum impact factor selection algorithm and the information includes:
其中,所述used_chunks表示所述特定slab类中已使用对象数量,所述request表示所述特定slab类中一段时间内的请求数量,所述total_chunks表示所述特定slab类中的对象总数。Wherein, the used_chunks represents the number of used objects in the specific slab class, the request represents the number of requests in the specific slab class within a period of time, and the total_chunks represents the total number of objects in the specific slab class.
优选地,所述将所述源slab类中的一个slab内存清空回收后重分配给所述目的slab,包括:Preferably, the redistribution to the destination slab after emptying and reclaiming a slab memory in the source slab class includes:
获取所述源slab类中空闲空间数量最大的slab;Obtain the slab with the largest amount of free space in the source slab class;
清空所述源slab类中空闲空间数量最大的slab内存,并将清空后的内存回收后重新分配到所述目的slab。Empty the slab memory with the largest amount of free space in the source slab class, reclaim the emptied memory and redistribute it to the destination slab.
优选地,所述方法还包括:Preferably, the method also includes:
将Memcached中已使用的空间和未使用的空间区别对待,将已使用的区域集中于slab前端,将未使用的区域集中于slab后端。The used space and unused space in Memcached are treated differently, the used area is concentrated on the front end of the slab, and the unused area is concentrated on the back end of the slab.
优选地,所述方法还包括:Preferably, the method also includes:
在每个slab类中的每个slab的前端设置有用于指定该slab的范围的三个指针,所述三个指针包括用于标识slab中第一个存储对象的指针slab_start、用于标识slab中最后一个存储对象的指针slab_end、用于标识slab中当前可用存储对象的指针cur_free。The front end of each slab in each slab class is provided with three pointers for specifying the scope of the slab, and the three pointers include the pointer slab_start for identifying the first storage object in the slab, and the pointer slab_start for identifying the first storage object in the slab. The pointer slab_end of the last storage object and the pointer cur_free used to identify the currently available storage object in the slab.
第二方面,一种内存分配的装置,其特征在于,所述装置包括:In a second aspect, a memory allocation device is characterized in that the device includes:
获取模块,用于获取每个slab类的信息,所述信息包括已使用对象数量、请求数量、对象总数和换出数量;An acquisition module, configured to acquire the information of each slab class, said information including the number of objects used, the number of requests, the total number of objects and the number of swapped out;
选择模块,用于根据预先设置的最小影响因子选择算法和所述信息计算每个slab类的影响因子;A selection module, configured to calculate the impact factor of each slab class according to a preset minimum impact factor selection algorithm and the information;
选取模块,用于将影响因子最小的slab类选取为源slab类,将一段时间内换出数量最多的slab设置为目的slab;The selection module is used to select the slab class with the smallest impact factor as the source slab class, and set the slab with the largest number of swaps out within a period of time as the destination slab;
分配模块,用于将所述源slab类中的一个slab内存清空回收后重分配给所述目的slab。An allocating module, configured to clear and recover a slab memory in the source slab class and redistribute it to the target slab.
优选地,所述选择模块,包括:Preferably, the selection module includes:
其中,所述used_chunks表示所述特定slab类中已使用对象数量,所述request表示所述特定slab类中一段时间内的请求数量,所述total_chunks表示所述特定slab类中的对象总数。Wherein, the used_chunks represents the number of used objects in the specific slab class, the request represents the number of requests in the specific slab class within a period of time, and the total_chunks represents the total number of objects in the specific slab class.
优选地,所述分配模块,用于:Preferably, the allocation module is used for:
获取所述源slab类中空闲空间数量最大的slab;Obtain the slab with the largest amount of free space in the source slab class;
清空所述源slab类中空闲空间数量最大的slab内存,并将清空后的内存回收后重新分配到所述目的slab。Empty the slab memory with the largest amount of free space in the source slab class, reclaim the emptied memory and redistribute it to the destination slab.
优选地,所述装置还包括:Preferably, the device also includes:
调整模块,用于将Memcached中已使用的空间和未使用的空间区别对待,将已使用的区域集中于slab前端,将未使用的区域集中于slab后端。The adjustment module is used to treat the used space and the unused space in Memcached differently, concentrate the used area on the front end of the slab, and concentrate the unused area on the back end of the slab.
优选地,所述装置还包括:Preferably, the device also includes:
设置模块,在每个slab类中的每个slab的前端设置用于指定该slab的范围的三个指针,所述三个指针包括用于标识slab中第一个存储对象的指针slab_start、用于标识slab中最后一个存储对象的指针slab_end、用于标识slab中当前可用存储对象的指针cur_free。The module is set, and the front end of each slab in each slab class is provided with three pointers for specifying the scope of the slab, and the three pointers include the pointer slab_start for identifying the first storage object in the slab, for A pointer slab_end for identifying the last storage object in the slab, and a pointer cur_free for identifying the currently available storage object in the slab.
本发明实施例提供一种内存分配的方法及装置,所述方法通过获取每个slab类的信息,所述信息包括已使用对象数量、请求数量、对象总数和换出数量;根据预先设置的最小影响因子选择算法和所述信息计算每个slab类的影响因子;将影响因子最小的slab类选取为源slab类,将所述一段时间内换出数量最多的slab设置为目的slab;将所述源slab类中的一个slab内存清空回收后重分配给所述目的slab,提出最小影响因子选择算法,综合考虑压缩情况下的存储数据的特征,合理选择恰当的源slab类和目的slab进行回收和重分配;调整Memcached的内存分配机制,根据slab存储状态空、满等有效地划分了区域,当需要内存的时候从末尾空闲的slab开始回收。Embodiments of the present invention provide a method and device for memory allocation. The method obtains information of each slab class, the information including the number of used objects, the number of requests, the total number of objects, and the number of swapped out; according to the preset minimum The impact factor selection algorithm and the information calculate the impact factor of each slab class; the slab class with the smallest impact factor is selected as the source slab class, and the slab with the largest number of swapped out in the period of time is set as the destination slab; the described A slab memory in the source slab class is emptied and redistributed to the target slab after being emptied and reclaimed. A minimum impact factor selection algorithm is proposed, and the characteristics of the stored data under compression are considered comprehensively, and the appropriate source slab class and target slab are reasonably selected for recycling and Reallocate; adjust the memory allocation mechanism of Memcached, effectively divide the area according to the slab storage status empty, full, etc., and start recycling from the idle slab at the end when memory is needed.
附图说明Description of drawings
图1是本发明实施例提供的一种内存分配的方法的流程示意图;FIG. 1 is a schematic flowchart of a memory allocation method provided by an embodiment of the present invention;
图2是本发明实施例提供的一种内存分配的方法的另一流程示意图;FIG. 2 is another schematic flowchart of a memory allocation method provided by an embodiment of the present invention;
图3是本发明实施例提供的一种空间分配的方法示意图;Fig. 3 is a schematic diagram of a space allocation method provided by an embodiment of the present invention;
图4是本发明实施例提供的另一种空间分配的方法示意图;Fig. 4 is a schematic diagram of another space allocation method provided by an embodiment of the present invention;
图5是本发明实施例提供的一种内存分配的指针结构示意图;FIG. 5 is a schematic diagram of a memory allocation pointer structure provided by an embodiment of the present invention;
图6是本发明实施例提供的一种内存分配前后的钙化问题对比示意图;FIG. 6 is a schematic diagram of a comparison of calcification before and after memory allocation provided by an embodiment of the present invention;
图7是本发明实施例提供的一种内存分配的装置的功能模块示意图。FIG. 7 is a schematic diagram of functional modules of a device for memory allocation provided by an embodiment of the present invention.
具体实施方式Detailed ways
下面结合附图和实施例对本发明实施例作进一步的详细说明。可以理解的是,此处所描述的具体实施例仅仅用于解释本发明实施例,而非对本发明实施例的限定。另外还需要说明的是,为了便于描述,附图中仅示出了与本发明实施例相关的部分而非全部结构。The embodiments of the present invention will be further described in detail below in conjunction with the drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain the embodiments of the present invention, rather than to limit the embodiments of the present invention. In addition, it should be noted that, for the convenience of description, the drawings only show some but not all structures related to the embodiments of the present invention.
参照图1,图1是本发明实施例提供的一种内存分配的方法的流程示意图。Referring to FIG. 1 , FIG. 1 is a schematic flowchart of a memory allocation method provided by an embodiment of the present invention.
在图1中,所述内存分配的方法包括:In Fig. 1, the method of memory allocation includes:
步骤101,获取每个slab类的信息,所述信息包括已使用对象数量、请求数量、对象总数和换出数量;Step 101, obtaining the information of each slab class, said information including the number of objects used, the number of requests, the total number of objects and the number of swapped out;
具体的,由于在Memcached中新增了数据压缩功能,Memcached中存储对象的数据特征发生变化。从压缩数量、请求数量以及对象总数的角度,提出了最小影响因子选择算法。影响因子(Impact factor,IF)是综合压缩数量、请求数量以及对象总数对slab回收过程的影响得到的一个指标。Specifically, due to the addition of a data compression function in Memcached, data characteristics of objects stored in Memcached have changed. From the perspective of compression quantity, request quantity and total number of objects, a minimum impact factor selection algorithm is proposed. Impact factor (IF) is an index obtained by combining the impact of the number of compressions, the number of requests, and the total number of objects on the slab recovery process.
步骤102,根据预先设置的最小影响因子选择算法和所述信息计算每个slab类的影响因子;Step 102, calculating the impact factor of each slab class according to the preset minimum impact factor selection algorithm and the information;
优选地,所述根据预先设置的最小影响因子选择算法和所述信息计算每个slab类的影响因子,包括:Preferably, the calculation of the impact factor of each slab class according to the preset minimum impact factor selection algorithm and the information includes:
其中,所述used_chunks表示所述特定slab类中已使用对象数量,所述request表示所述特定slab类中一段时间内的请求数量,所述total_chunks表示所述特定slab类中的对象总数。Wherein, the used_chunks represents the number of used objects in the specific slab class, the request represents the number of requests in the specific slab class within a period of time, and the total_chunks represents the total number of objects in the specific slab class.
具体的,影响因子越小,说明该slab越适合作为源slab类提供内存。Specifically, the smaller the impact factor, the more suitable the slab is to provide memory as the source slab class.
步骤103,将影响因子最小的slab类选取为源slab类,将一段时间内换出数量最多的slab设置为目的slab;Step 103, selecting the slab class with the smallest impact factor as the source slab class, and setting the slab with the largest number of swaps out within a period of time as the destination slab;
具体的,收集每个slab类的已经使用对象数量、请求数量、对象总数以及换出数量。对每个slab类计算影响因子,从中选出一个影响因子最小的slab类作为源slab类。从slab类中选取换出数量最多(频繁)的slab类作为目的slab。Specifically, the number of used objects, the number of requests, the total number of objects, and the number of swapped out objects of each slab class are collected. Calculate the impact factor for each slab class, and select a slab class with the smallest impact factor as the source slab class. Select the slab class with the largest number (frequently) swapped out from the slab classes as the destination slab.
步骤104,将所述源slab类中的一个slab内存清空回收后重分配给所述目的slab。Step 104, emptying and reclaiming a slab memory in the source slab class and reallocating it to the destination slab.
优选地,所述将所述源slab类中的一个slab内存清空回收后重分配给所述目的slab,包括:Preferably, the redistribution to the destination slab after emptying and reclaiming a slab memory in the source slab class includes:
获取所述源slab类中空闲空间数量最大的slab;Obtain the slab with the largest amount of free space in the source slab class;
清空所述源slab类中空闲空间数量最大的slab内存,并将清空后的内存回收后重新分配到所述目的slab。Empty the slab memory with the largest amount of free space in the source slab class, reclaim the emptied memory and redistribute it to the destination slab.
其中,内存空间为固定大小为1M大小的内存。Wherein, the memory space is a memory with a fixed size of 1M.
具体的,参考图2,图2是本发明实施例提供的一种内存分配的方法的另一流程示意图。Specifically, refer to FIG. 2 , which is another schematic flowchart of a method for memory allocation provided by an embodiment of the present invention.
步骤201,若判断slab需要回收和重分配,则选出源slab类;Step 201, if it is judged that the slab needs to be recovered and redistributed, then select the source slab class;
步骤202,选出目的slab;Step 202, select the target slab;
步骤203,判断是否进行slab回收和重分配;Step 203, judging whether to perform slab recovery and reallocation;
步骤204,若判断slab不需要回收和重分配,则判断选出的slab类是否有效;Step 204, if it is judged that the slab does not need to be reclaimed and redistributed, then it is judged whether the selected slab class is valid;
步骤205,若选出的slab类有效,则进行slab回收和重分配工作。Step 205, if the selected slab class is valid, perform slab recovery and reallocation.
优选地,所述方法还包括:Preferably, the method also includes:
将Memcached中已使用的空间和未使用的空间区别对待,将已使用的区域集中于slab前端,将未使用的区域集中于slab后端。The used space and unused space in Memcached are treated differently, the used area is concentrated on the front end of the slab, and the unused area is concentrated on the back end of the slab.
具体的,将图3中Memcached已经使用的空间和空闲的空间区分对待,即将占用区域集中于slab的前端而将空闲区域集中于slab的后端。当发生钙化问题的时候,优先对后端区域进行内存回收和重分配。Specifically, the space already used by Memcached in Figure 3 is treated differently from the free space, that is, the occupied area is concentrated at the front end of the slab and the free area is concentrated at the back end of the slab. When a calcification problem occurs, memory recovery and reallocation are given priority to the backend area.
图4是修改后Memcached的slab分配器示意图,不仅将已经占用区域集中于前端,而且各slab之间指针更加规整,有利于在回收内存的时候进行链表的断链操作。在Memcached回收内存的时候,会将选中的slab存储的对象清空,重新切分为其他尺寸的小块。清空对象的操作会在一定程度上影响Memcached的命中率,使用图4所示的slab分配器结构可以降低这种影响。Figure 4 is a schematic diagram of the modified Memcached slab allocator, which not only concentrates the occupied area on the front end, but also makes the pointers between the slabs more regular, which is conducive to the disconnection of the linked list when reclaiming memory. When Memcached reclaims memory, it will clear the objects stored in the selected slab and re-segment them into small blocks of other sizes. The operation of clearing objects will affect the hit rate of Memcached to a certain extent. Using the slab allocator structure shown in Figure 4 can reduce this effect.
优选地,所述方法还包括:Preferably, the method also includes:
在每个slab类中的每个slab的前端设置有用于指定该slab的范围的三个指针,所述三个指针包括用于标识slab中第一个存储对象的指针slab_start、用于标识slab中最后一个存储对象的指针slab_end、用于标识slab中当前可用存储对象的指针cur_free。The front end of each slab in each slab class is provided with three pointers for specifying the scope of the slab, and the three pointers include the pointer slab_start for identifying the first storage object in the slab, and the pointer slab_start for identifying the first storage object in the slab. The pointer slab_end of the last storage object and the pointer cur_free used to identify the currently available storage object in the slab.
具体的,参考图5所示,图5是本发明实施例提供的一种内存分配的指针结构示意图。图5是具体的修改方法,除了在slab结构体中添加如图所示的3个指针,还需要在内存分配函数中添加相应的处理代码。Specifically, refer to FIG. 5 , which is a schematic diagram of a memory allocation pointer structure provided by an embodiment of the present invention. Figure 5 shows the specific modification method. In addition to adding three pointers as shown in the figure in the slab structure, it is also necessary to add corresponding processing codes in the memory allocation function.
参考图6,图6是本发明实施例提供的一种内存分配前后的钙化问题对比示意图。图6中的灰色虚线是实验效果,从中可以看到从请求类型A过渡到请求类型B,钙化问题下的命中率的改善有明显改善,这种方案有效地改善了Memcached在压缩情况下由钙化导致的命中率下降的问题。灰色曲线是压缩情况下受钙化影响的Memcached的命中率曲线。Referring to FIG. 6 , FIG. 6 is a schematic diagram of a comparison of calcification before and after memory allocation provided by an embodiment of the present invention. The gray dotted line in Figure 6 is the experimental effect, from which it can be seen that the hit rate improvement under the calcification problem has been significantly improved from the transition from request type A to request type B. This scheme effectively improves Memcached's compression by calcification The problem that caused the hit rate to drop. The gray curve is the hit rate curve of Memcached affected by calcification under compression.
本发明实施例提供一种内存分配的方法,所述方法通过获取每个slab类的信息,所述信息包括已使用对象数量、请求数量、对象总数和换出数量;根据预先设置的最小影响因子选择算法和所述信息计算每个slab类的影响因子;将影响因子最小的slab类选取为源slab类,将所述一段时间内换出数量最多的slab设置为目的slab;将所述源slab类中的一个slab内存清空回收后重分配给所述目的slab,提出最小影响因子选择算法,综合考虑压缩情况下的存储数据的特征,合理选择恰当的源slab类和目的slab进行回收和重分配;调整Memcached的内存分配机制,根据slab存储状态空、满等有效地划分了区域,当需要内存的时候从末尾空闲的slab开始回收。The embodiment of the present invention provides a method for memory allocation, the method obtains the information of each slab class, the information includes the number of used objects, the number of requests, the total number of objects and the number of swapped out; according to the preset minimum impact factor Selection algorithm and the influence factor of each slab class are calculated by the information; the slab class with the smallest influence factor is selected as the source slab class, and the slab with the largest number of swapped out in the period of time is set as the destination slab; the source slab A slab memory in a class is emptied and re-allocated to the target slab, and a minimum impact factor selection algorithm is proposed, comprehensively considering the characteristics of the stored data under compression, and reasonably selecting the appropriate source slab class and target slab for recycling and re-allocation ;Adjust the memory allocation mechanism of Memcached, effectively divide the area according to the slab storage status empty, full, etc., and start recycling from the idle slab at the end when memory is needed.
参考图7,图7是本发明实施例提供的一种内存分配的装置的功能模块示意图。Referring to FIG. 7 , FIG. 7 is a schematic diagram of functional modules of a device for memory allocation provided by an embodiment of the present invention.
在图7,所述内存分配的装置包括:In Figure 7, the memory allocation means include:
获取模块701,用于获取每个slab类的信息,所述信息包括已使用对象数量、请求数量、对象总数和换出数量;Obtaining module 701, is used for obtaining the information of each slab class, and described information comprises used object quantity, request quantity, object total number and exchanged out quantity;
选择模块702,用于根据预先设置的最小影响因子选择算法和所述信息计算每个slab类的影响因子;Selection module 702, for calculating the impact factor of each slab class according to the preset minimum impact factor selection algorithm and the information;
优选地,所述选择模块702,包括:Preferably, the selection module 702 includes:
其中,所述used_chunks表示所述特定slab类中已使用对象数量,所述request表示所述特定slab类中一段时间内的请求数量,所述total_chunks表示所述特定slab类中的对象总数。Wherein, the used_chunks represents the number of used objects in the specific slab class, the request represents the number of requests in the specific slab class within a period of time, and the total_chunks represents the total number of objects in the specific slab class.
选取模块703,用于将影响因子最小的slab类选取为源slab类,将一段时间内换出数量最多的slab设置为目的slab;The selection module 703 is used to select the slab class with the smallest impact factor as the source slab class, and set the slab with the largest number of swaps in a period of time as the destination slab;
分配模块704,用于将所述源slab类中的一个slab内存清空回收后重分配给所述目的slab。The allocating module 704 is configured to clear and reclaim a slab memory in the source slab class and then reallocate it to the target slab.
优选地,所述分配模块704,用于:Preferably, the allocation module 704 is configured to:
获取所述源slab类中空闲空间数量最大的slab;Obtain the slab with the largest amount of free space in the source slab class;
清空所述源slab类中空闲空间数量最大的slab内存,并将清空后的内存回收后重新分配到所述目的slab。Empty the slab memory with the largest amount of free space in the source slab class, reclaim the emptied memory and redistribute it to the destination slab.
优选地,所述装置还包括:Preferably, the device also includes:
调整模块,用于将Memcached中已使用的空间和未使用的空间区别对待,将已使用的区域集中于slab前端,将未使用的区域集中于slab后端。The adjustment module is used to treat the used space and the unused space in Memcached differently, concentrate the used area on the front end of the slab, and concentrate the unused area on the back end of the slab.
优选地,所述装置还包括:Preferably, the device also includes:
设置模块,用于在每个slab类中的每个slab的前端设置用于指定该slab的范围的三个指针,所述三个指针包括用于标识slab中第一个存储对象的指针slab_start、用于标识slab中最后一个存储对象的指针slab_end、用于标识slab中当前可用存储对象的指针cur_free。Setting module is used to set three pointers for specifying the scope of the slab at the front end of each slab in each slab class, and the three pointers include pointers slab_start, the first storage object used to identify the slab The pointer slab_end used to identify the last storage object in the slab, and the pointer cur_free used to identify the currently available storage object in the slab.
本发明实施例提供一种内存分配的装置,通过获取每个slab类的信息,所述信息包括已使用对象数量、请求数量、对象总数和换出数量;根据预先设置的最小影响因子选择算法和所述信息计算每个slab类的影响因子;将影响因子最小的slab类选取为源slab类,将所述一段时间内换出数量最多的slab设置为目的slab;将所述源slab类中的一个slab内存清空回收后重分配给所述目的slab,提出最小影响因子选择算法,综合考虑压缩情况下的存储数据的特征,合理选择恰当的源slab类和目的slab进行回收和重分配;调整Memcached的内存分配机制,根据slab存储状态空、满等有效地划分了区域,当需要内存的时候从末尾空闲的slab开始回收。The embodiment of the present invention provides a device for memory allocation, by obtaining the information of each slab class, the information includes the number of used objects, the number of requests, the total number of objects and the number of swapped out; according to the preset minimum impact factor selection algorithm and The information calculates the impact factor of each slab class; the slab class with the smallest impact factor is selected as the source slab class, and the slab with the largest number of swapped out in the period of time is set as the destination slab; the source slab class in the A slab memory is emptied and redistributed to the target slab after being reclaimed, and a minimum impact factor selection algorithm is proposed to comprehensively consider the characteristics of the stored data under compression, and reasonably select the appropriate source slab class and destination slab for recycling and redistribution; adjust Memcached The memory allocation mechanism effectively divides the area according to the slab storage status empty, full, etc. When the memory is needed, it starts to recycle from the idle slab at the end.
以上结合具体实施例描述了本发明实施例的技术原理。这些描述只是为了解释本发明实施例的原理,而不能以任何方式解释为对本发明实施例保护范围的限制。基于此处的解释,本领域的技术人员不需要付出创造性的劳动即可联想到本发明实施例的其它具体实施方式,这些方式都将落入本发明实施例的保护范围之内。The above describes the technical principles of the embodiments of the present invention in conjunction with specific embodiments. These descriptions are only for explaining the principles of the embodiments of the present invention, and cannot be construed as limiting the protection scope of the embodiments of the present invention in any way. Based on the explanations herein, those skilled in the art can think of other specific implementation manners of the embodiments of the present invention without creative work, and these manners will fall within the protection scope of the embodiments of the present invention.
Claims (8)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201610813881.8A CN106469121B (en) | 2016-09-09 | 2016-09-09 | Method and device for allocating memory |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201610813881.8A CN106469121B (en) | 2016-09-09 | 2016-09-09 | Method and device for allocating memory |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN106469121A CN106469121A (en) | 2017-03-01 |
| CN106469121B true CN106469121B (en) | 2019-12-13 |
Family
ID=58230412
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201610813881.8A Expired - Fee Related CN106469121B (en) | 2016-09-09 | 2016-09-09 | Method and device for allocating memory |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN106469121B (en) |
Families Citing this family (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110209594B (en) * | 2018-02-28 | 2020-01-24 | 贵州白山云科技股份有限公司 | Memory management method and device suitable for slab structure |
| CN113434285B (en) * | 2020-03-23 | 2024-03-26 | 阿里巴巴集团控股有限公司 | Memory management method and device based on key value cache system |
| CN114995993B (en) * | 2022-04-22 | 2025-03-11 | 阿里巴巴(中国)有限公司 | Memory recovery method and device |
Citations (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101676883A (en) * | 2008-09-17 | 2010-03-24 | 英业达股份有限公司 | Memory allocation and management method |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US9798745B2 (en) * | 2014-09-13 | 2017-10-24 | Samsung Electronics Co., Ltd. | Methods, devices and systems for caching data items |
-
2016
- 2016-09-09 CN CN201610813881.8A patent/CN106469121B/en not_active Expired - Fee Related
Patent Citations (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101676883A (en) * | 2008-09-17 | 2010-03-24 | 英业达股份有限公司 | Memory allocation and management method |
Non-Patent Citations (1)
| Title |
|---|
| Memory Partitioning in Memcached: An Experimental Performance Ayalysis;Damiano Carra et al.;《IEEE ICC 2014-Communication Qos,Reliability and Modeling Sysmposium》;20141231;第1154-1159页 * |
Also Published As
| Publication number | Publication date |
|---|---|
| CN106469121A (en) | 2017-03-01 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN108572792B (en) | Data storage method and device, electronic equipment and computer readable storage medium | |
| CN105677242B (en) | The separation method and device of cold and hot data | |
| CN100524249C (en) | Storage apparatus using non-volatile memory as cache and method of managing the same | |
| Kim et al. | {SHRD}: Improving spatial locality in flash storage accesses by sequentializing in host and randomizing in device | |
| CN106469121B (en) | Method and device for allocating memory | |
| CN105389210B (en) | A kind of memory space management and device | |
| KR102077149B1 (en) | Method for managing memory and apparatus thereof | |
| CN105975398A (en) | Method for memory fragmentation management | |
| EP3304317B1 (en) | Method and apparatus for managing memory | |
| US10101934B1 (en) | Memory allocation balancing for storage systems | |
| US20160110107A1 (en) | Method for writing data into flash memory apparatus, flash memory apparatus, and storage system | |
| CN106844050A (en) | A kind of memory allocation method and device | |
| CN114064588A (en) | Storage space scheduling method and system | |
| US20140281132A1 (en) | Method and system for ram cache coalescing | |
| CN107912063A (en) | A kind of method for recovering internal storage and device | |
| CN109753361A (en) | A kind of EMS memory management process, electronic equipment and storage device | |
| KR101744685B1 (en) | Protection method and apparatus for metadata of file | |
| CN103488577A (en) | Method and device of memory allocation and batch recovery for user applications based on use numbering | |
| US10157148B2 (en) | Semiconductor device configured to control a wear leveling operation and operating method thereof | |
| US11226738B2 (en) | Electronic device and data compression method thereof | |
| US20130254512A1 (en) | Memory management method and information processing device | |
| KR101950759B1 (en) | Garbage collection method for performing memory controller of storage device and memory controler | |
| KR101626218B1 (en) | Block based page mapping method | |
| US7783683B2 (en) | Computer-readable storage medium storing generational garbage collection program | |
| WO2015135281A1 (en) | Resource allocation method and device based on thin provisioning |
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 | ||
| CF01 | Termination of patent right due to non-payment of annual fee | ||
| CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20191213 |