A memory management method, device, electronic device, and storage medium

By classifying and hierarchical management of memory and adapting to the classification of block management object Part, the problems of low memory utilization and memory allocation conflict in Ceph storage cluster are solved, and efficient memory management and utilization are achieved.

CN113515376BActive Publication Date: 2025-06-03NEW H3C BIG DATA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110562803.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-24
Publication Date
2025-06-03
Estimated Expiration
2041-05-24

AI Technical Summary

Technical Problem

The prior art has problems of low memory utilization and memory allocation conflicts in the memory allocation and release process. Especially in Ceph storage clusters, the memory space size frequently applied for by instances is not within the preset memory level division, resulting in memory fragmentation and waste.

Method used

By classifying and hierarchically managing the memory, the classification of the block management object Part is preferred, and memory is allocated from the local cache LocalCache and Slab. If it is insufficient, the original memory block will be obtained from the memory pool MemPool, initialize it into the Slab of the adapted Part classification, and add it to the Part.

Benefits of technology

It improves memory usage, reduces memory fragmentation, avoids possible conflicts in memory allocation by different instances, and realizes the adaptation of memory management and business applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113515376B_ABST
    Figure CN113515376B_ABST
Patent Text Reader

Abstract

The present disclosure provides a memory management method, apparatus, electronic device, and storage medium, which are used to solve the technical problems of low memory utilization rate and memory allocation conflicts. The present disclosure classifies and grades the memory, so that the memory space applied for by the service instance can be as compatible as possible with the provided memory blocks of different size types. By classifying different blocks and classifying memory blocks of different sizes into groups, and binding the groups to the service instance, isolation in memory management is achieved for different instances, thereby improving the memory utilization rate and avoiding possible conflicts in memory allocation among different instances.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computing and storage technologies, and particularly to a memory management method, apparatus, electronic device, and storage medium. Background Art

[0002] The rise of emerging services such as cloud computing, the Internet of Things, and social networks has prompted the types and scale of human society's data to grow at an unprecedented rate, and the big data era has officially arrived. The scale effect of big data has brought great challenges to data storage. Distributed storage systems represented by Ceph are widely used in various storage products. In a storage cluster, the efficient processing capabilities of each instance (such as OSD, MDS) for services determine the performance of the storage cluster, and the efficiency of memory application and release by each instance during the service processing is one of the key factors affecting the instance performance.

[0003] Instances in a Ceph-based storage cluster implement memory allocation and release through interfaces in dynamic link libraries such as tcmalloc or jemalloc. The key design concepts of tcmaloc and jemalloc are to divide memory allocation into several categories, such as small objects, medium objects, and large objects. For each classification, several levels are further divided to reduce memory fragmentation. For a thread, its cache is saved, and when an application performs memory application and release, it preferentially interacts with the cache to improve efficiency.

[0004] As general memory managers, tcmalloc and jemalloc consider more general scenarios in design and adopt the method of presetting fixed memory size levels, without being optimized for specific actual business scenarios. If the size of the memory space frequently applied by the actual business is not within the preset memory level division, a large amount of memory fragmentation will occur as the business progresses, resulting in memory waste. Summary of the Invention

[0005] In view of this, the present disclosure provides a memory management method, apparatus, electronic device, and storage medium for solving the technical problems of low memory utilization rate and memory allocation conflicts.

[0006] Figure 1 The following is a flowchart of the steps of the memory management method provided by the present disclosure. This method is used to implement the memory allocation of an instance, and the method includes:

[0007] Step 101. Adaptively classify the block management object Part based on the size of the memory space applied by the instance; wherein, Part is a memory management object composed of multiple memory blocks Slab with the same size managed by slices; the Slab includes multiple memory slices Slice of the same size sliced from the original memory block Blk; the Part is classified according to the size of the Slice;

[0008] Step 102. Allocate memory for the instance from the free memory slices Slice in the local cache LocalCache that are consistent with the adapted Part classification.

[0009] Step 103. When the space in the LocalCache is insufficient, allocate memory for the instance from the Slab with free Slice managed by the Part corresponding to the adapted Part classification.

[0010] Step 104. When there is no free Slice in the adapted Part, obtain the original memory block Blk from the memory pool MemPool, initialize Blk as the Slab corresponding to the adapted Part classification, add the Slab to the adapted Part, and then allocate memory for the instance from the adapted Part.

[0011] Based on the embodiments of the present disclosure, further, the Part includes:

[0012] An empty list Emptylist, where all Slabs are Slabs that have allocated all internal memory slices Slice.

[0013] A partially free list Partiallist, where all Slabs are Slabs that have allocated some internal memory slices Slice and some Slice have not been allocated.

[0014] A full free list Fulllist, where all Slabs are Slabs that have not allocated any memory slices Slice.

[0015] The method of allocating memory for the instance from the Slab with free Slice managed by the Part corresponding to the adapted Part classification is:

[0016] First, determine whether there are sufficient free Slice in the Partiallist for allocation. If so, allocate from the corresponding Slab. If not, obtain the unallocated Slab from the Fulllist and fill it into the Partiallist, and then allocate from the filled Slab.

[0017] Based on the embodiments of the present disclosure, further, the method is also used to implement the memory release of the instance. The steps of memory release include:

[0018] When releasing the released memory back to the LocalCache will not cause the LocalCache to overflow, release the released memory back to the LocalCache.

[0019] In the case where releasing back to the LocalCache causes the LocalCache to overflow, release the released memory back to the Part;

[0020] In the case where releasing back to the Part causes the Part to overflow, release the released memory back to the MemPool;

[0021] In the case where releasing back to the MemPool causes the MemPool to overflow, release the released memory back to the operating system.

[0022] Based on the embodiments of the present disclosure, further, the method further includes:

[0023] The instance is bound to a block management object group Group, and the Group is composed of multiple Parts of different classifications;

[0024] The specific adaptation of the block management object Part classification based on the size of the applied memory space is: perform adaptation among the Part classifications included in the Group;

[0025] The adapted Part is the Part in the Group.

[0026] Based on the embodiments of the present disclosure, further, in the method:

[0027] When the instance starts, initialize the Group using the Part classification table;

[0028] The Part classification table adopts the default configuration and / or adopts the following dynamic configuration method:

[0029] Statistically analyze the frequencies of different sizes of memory spaces applied by the instance;

[0030] Based on a preset threshold, add a Part classification corresponding to the size of the memory space with a frequency higher than the preset threshold to the default Part classification table.

[0031] Figure 2 It is a schematic structural diagram of a memory management device provided by an embodiment of the present disclosure. Each functional module in the device 200 can be implemented in a software, hardware, or a combination of software and hardware manner. The device 200 is used to implement the memory allocation of the instance, and the device includes:

[0032] An adaptation module 210, configured to adapt the block management object Part classification based on the size of the applied memory space; wherein, the Part is a memory management object composed of multiple memory block Slabs of the same size managed by slices; the Slab includes multiple memory slices Slice of the same size sliced from the original memory block Blk; the Part is classified according to the size of the Slice;

[0033] The local cache allocation module 211 is used to allocate memory for an instance from free memory slices Slice that are consistent with the adapted Part classification included in the local cache LocalCache;

[0034] The block management object allocation module 212 is used to allocate memory for an instance from a Slab with free Slice managed by the Part corresponding to the adapted Part classification when the space in the LocalCache is insufficient;

[0035] The memory pool allocation module 213 is used to obtain the original memory block Blk from the memory pool MemPool when there is no free Slice in the adapted Part, initialize Blk as a Slab corresponding to the adapted Part classification, add the Slab to the adapted Part, and then allocate memory for the instance from the adapted Part.

[0036] Based on the embodiments of the present disclosure, further, the block management object allocation module 212 includes:

[0037] The empty list Emptylist, where all Slabs are Slabs that have allocated all internal memory slices Slice;

[0038] The partial free list Partiallist, where all Slabs are Slabs that have allocated some internal memory slices Slice and there are still some Slice not allocated;

[0039] The full free list Fulllist, where all Slabs are Slabs that have not allocated any memory slices Slice;

[0040] The method for the block management object allocation module to allocate memory for an instance from a Slab with free Slice managed by the Part corresponding to the adapted Part classification is:

[0041] First, determine whether there are sufficient free Slice in the Partiallist for allocation. If so, allocate from the corresponding Slab. If not, obtain an unallocated Slab from the Fulllist and fill it into the Partiallist, and then allocate from the filled Slab.

[0042] Based on the embodiments of the present disclosure, further, the device 200 is also used to implement the memory release of the instance, and the device 200 further includes:

[0043] The first release module is used to release the released memory back to the LocalCache when releasing the released memory back to the LocalCache will not cause the LocalCache to overflow;

[0044] The second release module is used to release the released memory back to the Part when releasing it back to the LocalCache will cause the LocalCache to overflow;

[0045] The third release module is used to release the released memory back to the MemPool when releasing it back to the Part will cause the Part to overflow;

[0046] The fourth release module is used to release the released memory back to the operating system when releasing it back to the MemPool will cause the MemPool to overflow.

[0047] Based on the embodiments of the present disclosure, further, the instance is bound to the block management object group Group, and the Group is composed of multiple Parts of different classifications;

[0048] The adaptation module 210 performs adaptation of the Part classification among the Part classifications included in the Group, and the adapted Part is the Part in the Group.

[0049] Based on the embodiments of the present disclosure, further, the apparatus 200 further includes:

[0050] The initialization module is used to initialize the Group using the Part classification table when the instance is started; the Part classification table adopts default configuration and / or dynamic configuration;

[0051] The dynamic configuration module is used to statistically analyze the frequencies of memory space of different sizes applied for by the instance when the Part classification table adopts dynamic configuration; and based on a preset threshold, add a Part classification corresponding to the memory space size with a frequency higher than the preset threshold to the default Part classification table.

[0052] The memory management method provided by the present disclosure classifies and grades the memory, so that the memory space applied for by the service instance can be as well adapted as possible to the provided memory blocks of different size types. By classifying different blocks and forming groups with memory blocks of different sizes, binding the groups to the service instances, and achieving isolation in memory management for different instances, the memory utilization rate is improved, and conflicts that may occur in memory allocation between different instances are avoided. Description of the Drawings

[0053] To more clearly illustrate the technical solutions in the embodiments of the present disclosure or the prior art, the following will briefly introduce the drawings required for the description of the embodiments of the present disclosure or the prior art. Obviously, the drawings described below are only some embodiments recorded in the present disclosure. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings of the embodiments of the present disclosure.

[0054] Figure 1 It is a flowchart of the steps of the memory management method provided by the present disclosure;

[0055] Figure 2 It is a schematic structural diagram of a memory management device provided by the present disclosure;

[0056] Figure 3 It is a schematic diagram of the memory hierarchical structure adopted when tcmalloc and jemalloc perform memory allocation and release;

[0057] Figure 4 It is a schematic diagram of the memory organizational structure adopted by the memory management method provided by an embodiment of the present disclosure;

[0058] Figure 5 It is a schematic diagram of the method steps for dynamically adjusting the Part classification configuration provided by an embodiment of the present disclosure;

[0059] Figure 6 It is a flowchart of the steps of memory application in the memory management method provided by an embodiment of the present disclosure;

[0060] Figure 7 It is a flowchart of the steps of memory release in the memory management method provided by an embodiment of the present disclosure;

[0061] Figure 8 It is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure. Detailed implementation manners

[0062] The terms used in the embodiments of the present disclosure are only for the purpose of describing specific embodiments, rather than limiting the embodiments of the present disclosure. The singular forms "a", "the" and "said" used in the embodiments of the present disclosure are also intended to include the plural forms, unless the context clearly indicates otherwise. The term "and / or" used in the present disclosure refers to any or all possible combinations including one or more of the associated listed items.

[0063] It should be understood that although the terms first, second, third, etc. may be used in the embodiments of the present disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of the embodiments of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, in addition, the word "if" used may be interpreted as "when" or "while" or "in response to a determination".

[0064] Instances in the Ceph storage cluster implement memory allocation and release through interfaces provided by dynamic link libraries such as tcmalloc or jemalloc. Based on the analysis of the memory allocation and recycling methods of tcmaloc and jemalloc, the inventors found that tcmaloc and jemalloc divide the allocated memory into several categories, such as small objects, medium objects, and large objects, and for each classification, several levels are further subdivided. For the thread to save its cache, when the application makes a memory application and release, it preferentially interacts with the cache to improve efficiency.

[0065] Figure 3 It is a schematic diagram of the memory hierarchical structure adopted when tcmalloc and jemalloc perform memory allocation and release. As general memory managers, tcmalloc and jemalloc consider general scenarios in their designs. They take into account most business application scenarios in terms of memory classification and memory space hierarchical division methods, and adopt the method of presetting fixed allocable memory block sizes and levels, and cannot achieve optimization of memory allocation and management for a specific business application.

[0066] In a Ceph-based storage cluster, different instances, such as Metadata Server (MDS) instances, Object Storage Device (OSD) daemon instances, etc., in different business scenarios, the memory application and release will vary greatly with different services. If during the running of an instance, the size of the memory frequently applied by the instance is not within the range of the preset allocable memory block size, as the instance runs, a large amount of memory fragmentation may occur, resulting in memory waste. In addition, the Ceph storage cluster manages memory by directly loading dynamic or static link libraries similar to tcmalloc or jemalloc. When instances in different storage clusters apply for memory, memory allocation is not isolated. In actual business scenarios, it may happen that the memory applied by instance A is allocated to instance B, resulting in memory allocation conflicts and program disorders.

[0067] In view of the above technical problems, the present disclosure provides a memory management method, which can be applied to business instances in various applications and business systems, such as the OSD daemon and MDS instances of the Ceph distributed storage system, so as to improve memory usage efficiency, reduce memory fragmentation, and avoid conflicts in memory allocation.

[0068] In order to adapt to the memory allocation requirements of different sizes in different business scenarios, the present disclosure improves the hierarchical structure, allocation, and management method of the memory space, classifies and groups memory blocks of different sizes, and allows dynamic adjustment of the memory block classification based on the statistical results of the memory classification table, so as to achieve the adaptation of memory management to business applications and improve memory utilization. In addition, by specifying different memory block groups for different instances, memory allocation isolation is achieved, thus effectively solving the problem that conflicts may occur in memory applications of different instances.

[0069] Figure 4 FIG. is a schematic diagram of the memory organizational structure adopted by the memory management method provided in an embodiment of the present disclosure. The present disclosure divides the memory allocation hierarchy into 4 levels, namely:

[0070] Memory Pool (MemPool): Inside this level, there are several original memory blocks (abbreviated as Blk). Blk is an original memory block of a preset fixed size applied to the physical storage space through the operating system. The size of Blk can be configured. For example, the default size of Blk can be 8M, or it can be configured as 16M, 32M, etc. When initializing the MemPool, a certain number of Blks are applied and allocated into the MemPool by calling the memory allocation function of the operating system (such as the mmap() method). As the upper-layer services are used, when the Blks in the MemPool are used up, new Blks can be continuously applied from the system to expand the memory space of the MemPool. The initial value and maximum value of the number of Blks during MemPool initialization can be set through a configuration file.

[0071] Local Cache (LocalCache): In order to improve the efficiency of memory allocation and release by threads and avoid the overhead of mutex management for different threads to directly allocate or release memory from the Part, a memory space dedicated to the thread itself is provided for the thread, and the memory space at this level is called LocalCache, that is, the local cache. For the memory in the Localcache layer, when a thread allocates or releases, it can directly operate on its own LocalCache. Inside the LocalCache, it is composed of memory slices (Slice) divided by the slab for managing memory blocks. The size of the LocalCache, that is, the maximum number of Slices that can be managed in the LocalCache, can be configured through a configuration file.

[0072] The sliced management memory block Slab is a data structure with Slice management function obtained after initializing Blk, which includes data structure information (such as the starting position of the Slice, the number of Slices, etc.) and multiple memory slices Slice. All the Slices included in one Slab have the same size. During initialization allocation, Slab can be obtained by reading Blk from MemPool and splitting Blk into Slices.

[0073] The space of Localcache is loaded from Slab (that is, the Slices in Slab are loaded into Localcache). The Slices in Localcache have the same size, and the size of the Slice depends on the corresponding Part of the current Localcache. One Part corresponds to one size of Slice. The size and corresponding Part classification of LocalCache can be configured through the configuration file. The Part classification is determined by the size of the Slice in the Part. For example, when the size of the Slice in the Part is 8B, the classification of this Part refers to the Part with Slice of 8B.

[0074] Block management object (referred to as Part): Part is a memory management object composed of multiple sliced management memory blocks Slab with the same size. It internally includes three linked lists (which can also be in the form of lists, arrays, etc.), namely: the empty list emptylist, the partially free list partiallist, and the fully free list fulllist. The elements in the three linked lists are all sliced management memory blocks Slab of the same size.

[0075] All the Slabs in the empty list Emptylist are the Slabs that have allocated all the internal memory slices Slice.

[0076] All the Slabs in the partially free list Partiallist are the Slabs that have allocated some of the internal memory slices Slice and there are still some Slices not allocated.

[0077] All the Slabs in the fully free list Fulllist are the Slabs that have not allocated any of the internal memory slices Slice.

[0078] In the embodiments of the present disclosure, each Part corresponds to a memory slice (Slice) of a certain size, that is, all the Slices managed by all the Slabs within one Part have the same size, and the sizes of the Slices within different categories of Parts are different. When the upper-layer application needs a memory space of a certain size, it can determine which Part's Slice size is adapted to the size of the applied memory space according to the size of the applied memory space, and apply from the adapted Part. By classifying and managing memory slices of different sizes in the form of Slabs, the present disclosure can improve the efficiency of memory application and release, and reduce memory fragmentation.

[0079] Block management object group (referred to as Group for short): A Group consists of multiple Parts corresponding to Slices of different sizes. For example, it can be default that a Group contains 20 Parts, and the size of the Slice corresponding to each Part increases in powers of 2. For example, Part1 corresponds to a Slice size of 8 bytes, Part2 corresponds to a Slice size of 16 bytes,..., and Part20 corresponds to a Slice size of 4 megabytes. To improve flexibility, the size grading of Parts can be configured through a configuration file for different services. For example, the increment method of the Slice size corresponding to a Part can be configured by specifying an increment function, so as to configure multiple Parts of different classification sizes based on a certain starting size to adapt to memory allocation requests of different sizes, or the Parts of a certain size can also be configured in a fixed configuration manner to adapt to the large amount of memory allocation requirements of a certain application for Slices of this size.

[0080] In the embodiments of the present disclosure, it is allowed to specify Groups with different configurations for different upper-layer application instances through automatic or manual configuration, so that different instances have their own exclusive Groups and there will be no interaction in memory allocation with other instances, thus effectively solving the problem of possible conflicts in memory allocation between different instances.

[0081] Before starting an application instance, for the purpose of optimization and management, the memory parameters of each level can be configured through a configuration file. If no configuration is made, the default configuration can be adopted after the instance is started. During the process of the instance being loaded and started in memory, the memory of each level needs to be initialized. When initializing, first read the configuration file. If there are non-default configuration parameters set in the configuration file, use the non-default configuration parameters. If there is no configuration file or there are no non-default configuration parameters in the configuration file, use the default configuration.

[0082] Taking the initialization of a Part as an example, the embodiments of the present disclosure allow users to manually configure the initialization parameters of the Part in the configuration file, and at the same time, the embodiments of the present disclosure can also provide a preset Part classification table as the default configuration parameters of the Part. Example configuration parameters of the Part are as follows:

[0083] {sliceSize, localcacheSize, minSliceCnt, maxSliceCnt, attr}

[0084] Among them, sliceSize is the size of the Slice in the current Part;

[0085] localcacheSize is the size of the LocalCache (the number of included Slices);

[0086] minSliceCnt is the minimum number of Slices when creating a Part, which determines how many Blks to obtain from the MemPool initially;

[0087] maxSliceCnt is the maximum number of Slices that a Part can accommodate, which can be used to judge whether the internal expansion logic is reasonable.

[0088] attr is the attribute configuration of the Part, which is used for internal logic.

[0089] The following is an example of the Part classification table provided by an embodiment of the present disclosure, where the parameters prefixed with "DEFAULT" are predefined constants:

[0090] {8, 512 * DEFAULT_PART_CACHE_SIZE, DEFAULT_PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0091] {16, 256 * DEEAULT_PART-CACHE_SIZE, DEFAULT_PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0092] {32, 128 * DEFAULT_PART_CACHE_SIZE, DEFAULT_PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0093] {64, 64 * DEFAULT_PART_CACHE_SIZE, DEFAULT_PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0094] {128, 32 * DEFAULT_PART_CACHE_SIZE, DEFAULT_PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0095] {256, 16 * DEFAULT_PART_CACHE_SIZE, DEFAULT - PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0096] {512, 16 * DEFAULT_PART_CACHE_SIZE, DEFAULT_PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0097] {1024, DEFAULT_PART_CACHE_SIZE, DEFAULT_PART_MIN_SLICE, DEFAULT - PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0098] {2048, DEFAULT_PART_CACHE_SIZE, DEFAULT_PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0099] {4096, DEFAULT - PART_CACHE_SIZE, DEFAULT_PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0100] {8192, DEFAULT_PART_CACHE_SIZE, DEFAULT_PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0101] {16384, 2 * DEFAULT - PART_CACHE_SIZE, DEFAULT_PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0102] {32768, DEFAULT_PART_CACHE_SIZE, DEFAULT_PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0103] {65536, DEFAULT_PART_CACHE_SIZE / 2, DEFAULT_PART-MIN_SLICE, DEFAULT_PART-MA×_SLICE, DEFAULT-PART_ATTR},

[0104] {131072, DEFAULT_PART_CACHE-SIZE / 2, DEFAULT_PART_MIN_SLICE, DEFAULT_PART_MAX_SLICE, DEFAULT_PART_ATTR},

[0105] {262144, DEFAULT_PART-CACHE-SIZE / 8, DEFAULT_PART-MIN_SLICE, DEFAULT_PART_MA×-SLICE, DEFAULT-PART_ATTR},|

[0106] {524288, DEFAULT_PART_CACHE_SIZE / 4, DEFAULT_PART_MIN_SLICE / 2, DEFAULT_PART_MAX_SLICE, PART_ATTR_NO_CACHE},

[0107] {1048576, DEFAULT_PART_CACHE_SIZE / 4, DEFAULT_PART_MIN_SLICE / 4, DEFAULT_PART_MAX_SLICE, DEFAULT-PART_ATTR},

[0108] {2097152, DEFAULT_PART_CACHE_sIZE / 4, DEFAULT_PART_MIN_SLICE / 8, DEFAULT_PART_MAX_SLICE, PART_ATTR_NO_CACHE},

[0109] {4194304, DEFAULT_PART_CACHE_SIZE / 4, DEFAULT_PART_MIN_SLICE / 16, DEFAULT_PART_MAX_SLICE, PART_ATTR_NO_CACHE},

[0110] Embodiments of the present disclosure can also adjust memory configuration parameters by combining default configuration parameters, non-default configuration parameters (requiring special specification), and dynamic configuration to provide greater flexibility.

[0111] For example, for the initialization of a Group, if the types of Parts included in the Group are not manually specified in the configuration file, the Group is initialized with the configuration parameters of the Parts classified in the preset Part classification table (i.e., default configuration parameters), and all Part classifications in the Part classification table are created for the Group; if there are both default configuration parameters and non-default configuration parameters, non-default Part classifications (such as Part classifications manually added by users) are created for the Group, and Part classifications in the preset Part classification table are also created for the Group.

[0112] To achieve memory optimization for different services, an embodiment of the present disclosure allows dynamic configuration of memory parameters. Figure 5 FIG. is a schematic diagram of the method steps for dynamically adjusting the Part classification configuration provided by an embodiment of the present disclosure. The method of dynamic adjustment is as follows:

[0113] Step 501. In the initial state, each Group in the service instances is initialized using a preset Part classification table.

[0114] When a service instance initializes a Group, it reads the Part classification table to create Parts in the Group. In the case of the initial deployment of the service, a general preset Part classification table is first provided for the service.

[0115] Step 502. For each service, statistically analyze the memory application situation of the service instance to generate a Part classification table corresponding to the service.

[0116] In an actual service scenario, the actual memory application situation of each service instance is statistically analyzed, and the statistical data is analyzed. Then, the memory space sizes with high application frequencies are classified and refined into different Part classifications or a Part classification of a certain specification is set separately to improve the memory utilization rate. For example, in an actual environment, when the cluster is for a certain service scenario, a set of Part classifications more beneficial to the service scenario can be configured. When the cluster is in another service scenario, a set of Part classifications more beneficial to another service can be configured, so as to optimize the Part classification table for different service instances.

[0117] Taking the business instance of an object storage device (OSD) as an example, when the OSD daemon process in the cluster uses the memory management method provided by the present disclosure, the specific situation of the memory allocated by the OSD can be obtained through the memory statistics information in the log file. For example, after analyzing the memory allocation data, it is found that the OSD applies for 80K of memory more frequently. Assuming that under the default configuration, after the 64K Part classification, there is a 128K Part classification. If the business instance applies for 80K of memory space, it can only apply for and allocate slices from the 128K Part, resulting in memory waste. Therefore, if the allocation of 80K of memory space is indeed a large quantity, a new 80K Part classification can be added, or combined with other memory allocation situations, add a Part classification between the 64K and 128K Part classifications to reduce memory waste.

[0118] The dynamic configuration function of the Part classification table can be completed by a dynamic configuration component. For example, by periodically running the dynamic configuration component to statistically analyze the memory application situation of the business instance, the dynamic configuration component automatically generates a Part classification table corresponding to each business. For example, generate Part classification table 1 for business 1, generate Part classification table 2 for business 2, generate Part classification table 3 for business 3, and so on.

[0119] Step 503. Based on the statistical analysis results, adjust the configuration of the Part classification table corresponding to the business;

[0120] For example, in the configuration file of the business, there is a Part classification table configuration item for specifying the Part classification table used by the business. Initially, all configuration items point to the default Part classification table. After the business runs for a period of time, the dynamic configuration component generates a new Part classification table for each business. The dynamic configuration component automatically updates the Part classification table configuration item in the configuration file of a certain business or certain businesses according to the statistical analysis results, so that it points to the new Part classification table generated for this business, thereby realizing the dynamic configuration of the Part classification table.

[0121] Step 504. After the business instance restarts, initialize using their respective Part classification tables.

[0122] After updating the Part classification table, the dynamic configuration component restarts the business instance. After the business instance restarts, it will reload the configuration file and create corresponding Groups and Parts according to the Parts in the configuration file.

[0123] In the embodiments of the present disclosure, the memory configuration parameters involved when the business instance starts include but are not limited to the size of Blk, the size of LocalCache, the size of MemPool, the configuration parameters of the Group, the Part classification table, etc.

[0124] Figure 6 The flowchart of the memory application steps in the memory management method provided by an embodiment of the present disclosure. This flowchart exemplifies the processing logic for the memory allocation request of an instance after the application instance is started. The method includes:

[0125] Step 601. After the memory allocation function is called, adapt the Part based on the size of the requested memory space.

[0126] When the instance is started, the instance needs to first load the memory management dynamic library provided by the present disclosure, and the memory allocation function in the memory management dynamic library provided by the present disclosure takes over the original memory allocation function of the operating system (such as the malloc function).

[0127] When the instance needs to apply for memory, it will call the memory allocation function to apply for memory. If the program function module responsible for memory allocation is regarded as a device, then the business instance calling the memory allocation function is equivalent to the instance sending a memory allocation request to the device. If the memory allocation function executes successfully, the memory space required by the instance is obtained. If the memory allocation function executes fails, an information indicating the failure is returned.

[0128] Step 602. Obtain the current memory allocation situation of LocalCache and attempt to allocate the requested memory space from LocalCache.

[0129] Normally, a certain amount of memory space is reserved in LocalCache for business instances to apply for allocation. For example, after each execution of the memory allocation function, it can be judged whether there is a certain amount of reserved space. If there is not enough reserved space, it is replenished from the upper-level storage space in advance.

[0130] Step 603. Judge whether there is sufficient memory space in LocalCache for allocation; if there is sufficient memory space in LocalCache for allocation, the memory allocation function returns the requested memory space and the function ends; if not, execute Step 604.

[0131] Since the Slice in LocalCache is taken from the Part, it is necessary to first adapt the requested memory space to the Part classification, and then check whether there is a Slice of the specified Part classification in LocalCache. When there is an adaptable Slice in LocalCache for allocation, the idle Slice is allocated and the allocation information is recorded.

[0132] Step 604. Obtain the information of the adaptable Part and attempt to allocate from the Part.

[0133] Step 605. Determine whether there is sufficient allocatable space in the partiallist of Part for allocation. If there is, execute Step 606; otherwise, execute 607;

[0134] The Slab in the partiallist of Part is a Slab that has already allocated the internal memory slices Slice, and there are still some Slices not allocated. Therefore, allocation is first performed from the partiallist. If all the Slices of the Slab in the partiallist have been allocated, the Slab will be moved to the emptylist. When there is no Slab in the partiallist, a Slab is taken from the fullist to fill the partiallist. When there is no Slab in the fullist, a Blk is applied from the MemPool to fill the fullist. When there are insufficient Blks in the MemPool, memory is allocated from the system through the system call mmap to fill the MemPool.

[0135] Step 606. Obtain storage space from the partiallist and fill it into the LocalCache. After the memory allocation function returns the requested memory space, the function ends;

[0136] Step 607. Determine whether there is sufficient allocatable space in the fullist of Part for allocation. If there is, execute Step 608; otherwise, execute 609;

[0137] Step 608. Obtain storage space from the fullist and fill it into the partiallist, and then obtain the requested memory space from the partialist and fill it into the LocalCache. After the memory allocation function returns the requested memory space, the function ends.

[0138] Step 609. Obtain the storage information of the MemPool and attempt to obtain storage space from the MemPool;

[0139] Step 610. Determine whether the storage space of the MemPool is sufficient. If it is sufficient, execute Step 611; otherwise, execute 612;

[0140] Step 611. Obtain storage space from the MemPool and fill it into the fullist, then obtain the requested storage space from the fullist and fill it into the partiallist, and then obtain the requested memory space from the partialist and fill it into the LocalCache. After the memory allocation function returns the requested memory space, the function ends.

[0141] Step 612. Obtain a certain number of original memory blocks Blk from the operating system;

[0142] Step 613. Fill the obtained Blk into the MemPool, obtain storage space from the MemPool and fill it into the fullist, then obtain storage space from the fullist and fill it into the partiallist, and then obtain the applied memory space from the partialist and fill it into the LocalCache. After the memory allocation function returns the applied memory space, the function ends.

[0143] Figure 7 The following is a flowchart of the steps for memory release in the memory management method provided by an embodiment of the present disclosure. This flowchart exemplifies the processing logic for releasing memory for an instance after the application instance is started. The method includes:

[0144] Step 710. The service instance requests to release the memory space that is no longer in use through the memory release function;

[0145] Similarly, when the instance is started, the instance needs to first load the memory management dynamic library provided by the present disclosure, and the memory release function in the memory management dynamic library provided by the present disclosure takes over the original memory release function of the operating system (such as the free function).

[0146] Step 711. First, attempt to release the memory back to the LocalCache;

[0147] In the embodiment of the present disclosure, since memory is allocated from the Localcache when applying for memory, it is also preferentially released to the Localcache during release.

[0148] Step 712. Determine if the LocalCache will overflow, that is, if it will exceed the preset size of the LocalCache, when the memory is released to the LocalCache. If so, execute Step 713; otherwise, the memory release function is executed successfully and the release process ends.

[0149] Step 713. Attempt to release the memory back to the Part;

[0150] In the embodiment of the present disclosure, each Blk in the MemPool is of the same size and aligned. When the Localcache is full, based on the address of the released Slice, it can be calculated which Slab in which Part the Slice belongs to. After the calculation, the released Slice can be put back into the Slab. When all the Slices in the Slab are released back, this Slab can be moved to the fullist.

[0151] Step 714. Determine whether the Slab in the partiallist is full, i.e., whether all Slices in the Slab are unused, after the released memory reaches the specified Slab. If so, execute Step 715; otherwise, the memory release function is executed successfully and the release process ends.

[0152] Step 715. Move the full Slab to the fullist.

[0153] Step 716. Determine whether the fullist is full, i.e., whether the number of Slabs in the fullist has reached the preset maximum number of Slabs, causing Slab overflow. If so, execute Step 717; otherwise, the memory release function is executed successfully and the release process ends.

[0154] Step 717. Release the overflowed Slab to the MemPool.

[0155] Step 718. Determine whether the release to the MemPool will cause the Blk managed by the MemPool to overflow. If so, execute Step 719; otherwise, the memory release function is executed successfully and the release process ends.

[0156] Step 719. Release the overflowed Blk back to the operating system, the memory release function is executed successfully, and the release process ends.

[0157] The memory management method provided by the present disclosure classifies and hierarchically manages the memory, enabling the memory space applied for by service instances to be as compatible as possible with the provided memory blocks of different size types. By classifying different blocks and classifying memory blocks of different sizes into groups, binding the groups to service instances, and achieving isolation in memory management for different instances, the memory utilization rate is improved, and conflicts that may occur in memory allocation between different instances are avoided.

[0158] Figure 8 FIG. 800 is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure. The device 800 includes a processor 810 such as a central processing unit (CPU), a communication bus 820, and a storage medium 830. Among them, the processor 810 and the storage medium 830 can communicate with each other through the communication bus 820. The storage medium 830 stores a computer program, and when the computer program is executed by the processor 810, the functions of the steps of the memory management method provided by the present disclosure can be implemented.

[0159] Among them, the storage medium may include a Random Access Memory (RAM), or may also include a Non-Volatile Memory (NVM), such as at least one disk memory. Additionally, the storage medium may also be at least one storage device located far from the aforementioned processor. The processor may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processing (DSP), an Application-Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0160] It should be recognized that the embodiments of the present disclosure can be implemented or carried out by computer hardware, a combination of hardware and software, or by computer instructions stored in a non-transitory memory. The method can be implemented in a computer program using standard programming techniques, including a non-transitory storage medium configured with the computer program, wherein the storage medium so configured causes the computer to operate in a specific and predefined manner. Each program can be implemented in a high-level procedural or object-oriented programming language to communicate with the computer system. However, if necessary, the program can be implemented in assembly or machine language. In any case, the language can be a compiled or interpreted language. Additionally, for this purpose, the program can run on a programmed application-specific integrated circuit. Moreover, the operations of the processes described in the present disclosure can be performed in any suitable order, unless the present disclosure otherwise indicates or is otherwise clearly inconsistent with the context. The processes described in the present disclosure (or variations and / or combinations thereof) can be executed under the control of one or more computer systems configured with executable instructions, and can be implemented as code (e.g., executable instructions, one or more computer programs, or one or more applications) executed commonly on one or more processors, by hardware, or a combination thereof. The computer program includes multiple instructions executable by one or more processors.

[0161] Further, the method can be implemented in any type of computing platform operatively connected to a suitable one, including but not limited to personal computers, minicomputers, mainframes, workstations, network or distributed computing environments, separate or integrated computer platforms, or communicating with charged particle tools or other imaging devices, etc. Aspects of the present disclosure can be implemented in machine-readable code stored on a non-transitory storage medium or device, whether removable or integrated into the computing platform, such as a hard disk, optical read and / or write storage medium, RAM, ROM, etc., such that it can be read by a programmable computer and can be used to configure and operate the computer to perform the processes described herein when the storage medium or device is read by the computer. Additionally, the machine-readable code, or portions thereof, can be transmitted via wired or wireless networks. When such media includes instructions or programs that implement the above-described steps in conjunction with a microprocessor or other data processor, the inventions described in the present disclosure include these and other different types of non-transitory computer-readable storage media. When programmed according to the methods and techniques described in the present disclosure, the present disclosure also includes the computer itself.

[0162] The above are only embodiments of the present disclosure and are not intended to limit the present disclosure. For those skilled in the art, various changes and modifications can be made to the present disclosure. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present disclosure shall be included within the protection scope of the present disclosure.

Claims

1. A memory management method, characterized in that, the method is used to implement memory allocation for an instance, and the method includes: adapting the classification of the block management object Part based on the size of the memory space applied for by the instance; wherein, Part is a memory management object composed of multiple memory blocks Slab managed by slices of the same size; the Slab includes multiple memory slices Slice of the same size sliced from the original memory block Blk; the Part is classified according to the size of the Slice; allocating memory for the instance from the free memory slices Slice included in the local cache LocalCache that is consistent with the adapted Part classification; when the space in the LocalCache is insufficient, allocating memory for the instance from the Slab with free Slice managed by the Part corresponding to the adapted Part classification; when there is no free Slice in the adapted Part, obtaining the original memory block Blk from the memory pool MemPool, initializing the Blk as the Slab corresponding to the adapted Part classification, adding the Slab to the adapted Part, and then allocating memory for the instance from the adapted Part.

2. The method according to claim 1, characterized in that, the Part includes: an empty list Emptylist, where all Slab are Slab that have allocated all internal memory slices Slice; a partially free list Partiallist, where all Slab are Slab that have allocated some internal memory slices Slice and some Slice are not allocated; a full free list Fulllist, where all Slab are Slab that have not allocated any memory slices Slice; the method of allocating memory for the instance from the Slab with free Slice managed by the Part corresponding to the adapted Part classification is: firstly, judging whether there are sufficient free Slice in the Partiallist for allocation. If so, allocate from the corresponding Slab. If not, obtain the unallocated Slab from the Fulllist and fill it into the Partiallist, and then allocate from the filled Slab.

3. The method according to claim 2, characterized in that, the method is also used to implement memory release for the instance, and the steps of memory release include: when releasing the released memory back to the LocalCache will not cause the LocalCache to overflow, releasing the released memory back to the LocalCache; when releasing back to the LocalCache will cause the LocalCache to overflow, releasing the released memory back to the Part; when releasing back to the Part will cause the Part to overflow, releasing the released memory back to the MemPool; when releasing back to the MemPool will cause the MemPool to overflow, releasing the released memory back to the operating system.

4. The method according to claim 1, characterized in that, The method further includes: The instance is bound to a block management object group Group, and the Group consists of multiple Parts of different classifications; The adaptation of the Part classification of the block management object based on the size of the applied memory space is specifically: to perform adaptation among the Part classifications included in the Group; The adapted Part is the Part in the Group.

5. The method according to claim 4, wherein, When the instance is started, the Group is initialized using the Part classification table; The Part classification table adopts a default configuration and / or adopts the following dynamic configuration method: Statistically analyze the frequencies of different sizes of memory spaces applied by the instance; Based on a preset threshold, add a Part classification corresponding to the size of the memory space with a frequency higher than the preset threshold to the default Part classification table.

6. A memory management device, wherein, The device is used to implement the memory allocation of the instance, and the device includes: An adaptation module, which is used to adapt the Part classification of the block management object based on the size of the applied memory space; wherein, the Part is a memory management object composed of multiple memory blocks Slab managed by slices of the same size; the Slab includes multiple memory slices Slice of the same size sliced from the original memory block Blk; the Part is classified according to the size of the Slice; A local cache allocation module, which is used to allocate memory for the instance from the free memory slices Slice included in the local cache LocalCache that are consistent with the adapted Part classification; A block management object allocation module, which is used to allocate memory for the instance from the Slab with free Slice managed by the Part corresponding to the adapted Part classification when the space in the LocalCache is insufficient; A memory pool allocation module, which is used to obtain the original memory block Blk from the memory pool MemPool when there are no free Slice in the adapted Part, initialize the Blk into a Slab corresponding to the adapted Part classification, add the Slab to the adapted Part, and then allocate memory for the instance from the adapted Part.

7. The device according to claim 6, wherein, The block management object allocation module includes: An empty list Emptylist, all the Slab in which are Slab that have allocated all the internal memory slices Slice; A partial free list Partiallist, all the Slab in which are Slab that have allocated some of the internal memory slices Slice and there are still some Slice not allocated; A full free list Fulllist, all the Slab in which are Slab that have not allocated any of the memory slices Slice; The method by which the block management object allocation module allocates memory for the instance from the Slab with free Slice managed by the Part corresponding to the adapted Part classification is: First, it is determined whether there are sufficient free Slices in the Partiallist for allocation. If there are, allocation is performed from the corresponding Slab. If not, an unallocated Slab is obtained from the Fulllist and filled into the Partiallist, and then allocation is performed from the filled Slab.

8. The device according to claim 7, wherein, the device is further configured to implement memory release of an instance, and the device further includes: a first release module, configured to release the released memory back to the LocalCache when releasing the released memory back to the LocalCache will not cause the LocalCache to overflow; a second release module, configured to release the released memory back to the Part when releasing it back to the LocalCache will cause the LocalCache to overflow; a third release module, configured to release the released memory back to the MemPool when releasing it back to the Part will cause the Part to overflow; a fourth release module, configured to release the released memory back to the operating system when releasing it back to the MemPool will cause the MemPool to overflow.

9. The device according to claim 6, wherein, the instance is bound to a block management object group Group, and the Group is composed of multiple Parts of different classifications; the adaptation module performs adaptation of the Part classification among the Part classifications included in the Group, and the adapted Part is a Part in the Group.

10. The device according to claim 9, wherein, the device further includes: an initialization module, configured to initialize the Group using the Part classification table when the instance is started; the Part classification table adopts a default configuration and / or a dynamic configuration; a dynamic configuration module, configured to perform statistical analysis on the frequencies of memory space of different sizes applied for by the instance when the Part classification table adopts a dynamic configuration; and add a Part classification corresponding to the memory space size with a frequency higher than a preset threshold to the default Part classification table based on the preset threshold.

11. An electronic device, wherein, it includes a processor, a communication interface, a storage medium, and a communication bus. Among them, the processor, the communication interface, and the storage medium complete communication with each other through the communication bus; the storage medium is used to store a computer program; the processor, when executing the computer program stored on the storage medium, implements the method steps described in any one of claims 1 to 5.

12. A storage medium, on which a computer program is stored, wherein, when the computer program is executed by a processor, it implements the method steps described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method and device for managing memory resources in cluster system, and network system

    CN101594309A

  • Memory control method for embedded systems

    CN102915276A