A memory management method, device, apparatus and storage medium
By monitoring usage in the central cache and requesting new memory from the page cache, and splitting it into free objects to form a linked list, the problem of Span not being able to be released quickly is solved, thus improving memory utilization.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SANGFOR TECH INC
- Filing Date
- 2021-04-30
- Publication Date
- 2026-05-29
Smart Images

Figure CN115269172B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, and in particular to a memory management method, apparatus, device, and storage medium. Background Technology
[0002] To effectively improve memory allocation management in distributed storage systems, the thread-caching dynamic memory allocation technology (TCMalloc) has matured significantly. It effectively reduces performance overhead caused by frequent memory allocation and deallocation, and effectively controls memory fragmentation. Based on the size of the allocated memory, TCMalloc categorizes memory allocation into three types: small object allocation (0-256 kilobytes (KB)); medium object allocation (256 KB-1 megabyte (MB)); and large object allocation (1 MB-+∞). Currently, when managing small object allocations, TCMalloc implements a three-level cache: thread-level cache (ThreadCache), central cache (CentralCache), and page cache (PageHeap). ThreadCache can be divided into multiple sizes, denoted as sizeclass, depending on requirements.
[0003] Currently, when a process has a high demand for a certain size class at time A, CentralCache allocates multiple logically contiguous memory spaces (Spans) consisting of several memory pages for the process to use. However, when the process's demand for that size class decreases at time B, the Spans cannot be released quickly, resulting in low Span utilization. Currently, there is no method to quickly release Spans.
[0004] Application content
[0005] In view of this, the embodiments of this application aim to provide a memory management method, apparatus, device and storage medium, which solves the problem that there is currently no technical solution for quickly releasing Span, and proposes a technical solution for quickly releasing Span, thereby improving the utilization rate of memory cache.
[0006] To achieve the above objectives, the technical solution of this application is implemented as follows:
[0007] In a first aspect, a memory management method is provided, the method being applied to a memory management device implementing dynamic memory allocation TCMalloc for thread caching, the method comprising:
[0008] Determine the current usage of the first contiguous page of memory in the central cache;
[0009] If the current utilization rate is less than or equal to a preset threshold, request memory for a second contiguous page from the page cache;
[0010] The second contiguous page memory is split into at least one first free object, and a first memory linked list is obtained based on the at least one first free object; wherein, the first memory linked list is used to provide a matching object for the process when the process requests an object;
[0011] The memory of the first contiguous page is released.
[0012] Optionally, the method further includes:
[0013] If the current usage rate is less than or equal to the preset threshold, determine the first object that is not used by the process and included in the first free list of the thread cache;
[0014] The first object is stored in a first free list of the central cache; wherein the first free list is used to store objects that are currently in an idle state.
[0015] Optionally, after splitting the second contiguous page memory into at least one first free object and obtaining a first memory linked list based on the at least one first free object, the method further includes:
[0016] Determine at least one second free object matching the process from the first memory list;
[0017] Based on the at least one second free object, a second free list is created in the thread cache;
[0018] If a request object operation of the process is detected, a second object matching the request object operation is determined from the second free list;
[0019] Assign the second object to the process.
[0020] Optionally, the method further includes:
[0021] A selection instruction is determined; wherein the selection instruction is used to indicate whether the process should return the currently used third object if the current usage rate of the first contiguous memory page is detected to be less than or equal to the preset threshold.
[0022] If the selection instruction is a target instruction, a fourth object is determined from the second free list; wherein the second object includes the fourth object;
[0023] Copy the cached content from the third object to the fourth object;
[0024] Return the third object to the central cache.
[0025] Optionally, returning the third object to the central cache includes:
[0026] Determine the target identifier information of the memory linked list to which the third object belongs;
[0027] If the target identification information is the first identification information of the first contiguous page memory, the third object is saved to the first free list corresponding to the first contiguous page memory; wherein, the first free list is used to store objects that are currently in a free state.
[0028] Optionally, the method further includes:
[0029] If the target identification information is the second identification information of the second contiguous page memory, the third object is saved to the second free list corresponding to the second contiguous page memory; wherein, the second free list is used to store objects that are currently in a free state.
[0030] Optionally, determining the current utilization rate of the first contiguous page memory in the central cache includes:
[0031] Get the current memory cache size;
[0032] If the current memory cache size is greater than the cache threshold, determine the current utilization rate of the first contiguous pages of memory.
[0033] In a second aspect, a memory management apparatus for implementing TCMalloc, the apparatus comprising: a determination unit, an allocation unit, a splitting unit, and a release unit; wherein:
[0034] The determining unit is used to determine the current usage rate of the first contiguous page memory in the central cache;
[0035] The application unit is used to apply for a second contiguous page memory from the page cache if the current utilization rate is less than or equal to a preset threshold.
[0036] The splitting unit is used to split the second consecutive page into at least one first free object, and to obtain a first memory linked list based on the at least one first free object; wherein, the first memory linked list is used to provide a matching object for the process when the process requests an object;
[0037] The release unit is used to release the first contiguous page memory.
[0038] Thirdly, a memory management device, the device comprising: a memory, a processor, a RAM, and a communication bus; wherein:
[0039] The memory is used to store executable instructions;
[0040] The communication bus is used to realize the communication connection between the processor and the memory;
[0041] The memory is used to provide data caching objects for process execution;
[0042] The processor is configured to execute a memory management program stored in the memory to implement the steps of the memory management method as described in any of the preceding claims.
[0043] Fourthly, a storage medium storing a memory management program, which, when executed by a processor, implements the steps of the memory management method as described in any of the preceding claims.
[0044] The memory management method, apparatus, device, and storage medium provided in the embodiments of this application, after determining the current utilization rate of a first contiguous page of memory in the central cache, if the current utilization rate is less than or equal to a preset threshold, requests a second contiguous page of memory from the page cache, and splits the second contiguous page of memory into at least one first free object, thereby obtaining a first memory linked list based on the at least one first free object, and finally releasing the first contiguous page of memory. In this way, when the current utilization rate of the first contiguous page of memory is low, new second contiguous page of memory is requested from the page cache so that when a process needs an object, the object corresponding to the second contiguous page of memory is allocated to the process, and the first contiguous page of memory is released. This solves the problem that there is currently no technical solution for quickly releasing spans, and proposes a technical solution for quickly releasing spans, thereby improving the utilization rate of the memory cache. Attached Figure Description
[0045] Figure 1 A flowchart illustrating a memory management method provided in an embodiment of this application;
[0046] Figure 2 A flowchart illustrating another memory management method provided in an embodiment of this application;
[0047] Figure 3 A flowchart illustrating yet another memory management method provided in an embodiment of this application;
[0048] Figure 4 A schematic diagram illustrating a small object allocation process provided in an embodiment of this application;
[0049] Figure 5 A schematic diagram of the structure of a CentralFreeList provided in an embodiment of this application;
[0050] Figure 6 A schematic diagram illustrating the relationship between objects provided in an embodiment of this application;
[0051] Figure 7 A schematic diagram of a central cache structure provided in an embodiment of this application;
[0052] Figure 8 A schematic diagram illustrating a process for clearing contiguous pages of memory from a thread cache, provided as an embodiment of this application;
[0053] Figure 9 A flowchart illustrating a memory management method according to another embodiment of this application;
[0054] Figure 10 This is a schematic diagram of the structure of a memory management device provided in an embodiment of this application;
[0055] Figure 11 This is a schematic diagram of the structure of a memory management device provided in an embodiment of this application. Detailed Implementation
[0056] It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit this application.
[0057] Embodiments of this application provide a memory management method applied to a memory management device that implements dynamic memory allocation TCMalloc for thread caching, referencing... Figure 1 As shown, the method includes the following steps:
[0058] Step 101: Determine the current usage of the first contiguous page of memory in the central cache.
[0059] In this embodiment, the first contiguous page memory is referred to as Span. Determining the current utilization rate of the first contiguous page memory in the central cache can be achieved by statistically analyzing the ratio of used objects in the first contiguous page memory to all objects in the first contiguous page memory. The memory management device can be any electronic device capable of implementing TCMalloc, including but not limited to computer devices, smartphones, etc.
[0060] Step 102: If the current usage rate is less than or equal to the preset threshold, request memory for the second contiguous page from the page cache.
[0061] The application operation is used to instruct the applicant.
[0062] In this embodiment, the preset threshold can be an empirical value obtained from a large number of experiments, or it can be a value set by the user according to their actual needs. When the current utilization rate of the first contiguous page memory is less than or equal to the preset threshold, it indicates that the current utilization efficiency of the first contiguous page memory is low. In order to improve the utilization rate of the first contiguous page memory and release it as soon as possible, new contiguous page memory is requested from the page cache to obtain the second contiguous page memory.
[0063] Step 103: Split the second contiguous page memory into at least one first free object, and obtain a first memory linked list based on at least one first free object.
[0064] The first memory linked list is used to provide a matching object for the process when the process requests an object.
[0065] In this embodiment of the application, the second contiguous page memory is split into free objects corresponding to different size classes, and at least one first free object obtained from the split is given to obtain a first memory linked list, which can be denoted as empty_rotating_Span.
[0066] Step 104: Release the memory of the first contiguous page.
[0067] In this embodiment, when all objects corresponding to the first contiguous page memory are in a free state, the first contiguous page memory is released so that the memory space corresponding to the first contiguous page memory can be reallocated subsequently, thereby improving the memory utilization rate of the first contiguous page memory. In some application scenarios, the first contiguous page memory includes at least one contiguous page memory.
[0068] The memory management method provided in this application, after determining the current utilization rate of the first contiguous page memory in the central cache, if the current utilization rate is less than or equal to a preset threshold, requests a second contiguous page memory from the page cache, and splits the second contiguous page memory into at least one first free object. A first memory linked list is then obtained based on at least one first free object, and finally, the first contiguous page memory is released. In this way, when the current utilization rate of the first contiguous page memory is low, new second contiguous page memory is requested from the page cache so that when a process needs an object, the object corresponding to the second contiguous page memory can be allocated to the process, and the first contiguous page memory can be released. This solves the problem of the lack of a technical solution for quickly releasing spans and proposes a technical solution for quickly releasing spans, thereby improving the utilization rate of the memory cache.
[0069] Based on the foregoing embodiments, embodiments of this application provide a memory management method, which is applied to a memory management device that implements dynamic memory allocation TCMalloc for thread caching, and refers to... Figure 2 As shown, the method includes the following steps:
[0070] Step 201: Determine the current usage rate of the first contiguous page of memory in the central cache.
[0071] In this embodiment, the current utilization rate of the first contiguous page memory is determined based on the ratio of the number of objects currently in use in the first contiguous page memory to the total number of objects included in the first contiguous page memory.
[0072] Step 202: If the current usage rate is less than or equal to the preset threshold, request memory for the second contiguous page from the page cache.
[0073] The application operation is used to instruct the applicant.
[0074] In this embodiment of the application, when it is determined that the current usage rate of the first contiguous page memory is low, a new contiguous page memory, namely the second contiguous page memory, is requested from the page cache.
[0075] Step 203: Split the second contiguous page memory into at least one first free object, and obtain a first memory linked list based on at least one first free object.
[0076] The first memory linked list is used to provide a matching object for the process when the process requests an object.
[0077] In this embodiment, the newly allocated second contiguous page memory is split into at least one first free object corresponding to different size classes, and a first memory linked list is generated based on at least one first free object. That is, the first memory linked list is used to record at least one first free object, including the pointing relationships between each object.
[0078] Step 204: If the current usage rate is less than or equal to a preset threshold, determine the first object that is not used by the process and included in the first free list of the thread cache.
[0079] In this embodiment of the application, the first free list is a list of unused objects in the thread cache for a process, i.e., FreeList.
[0080] Step 205: Store the first object in the first free list of the central cache.
[0081] The first free list is used to store objects that are currently in a free state, including the identifier of the first contiguous page of memory.
[0082] In this embodiment of the application, the first object is stored in the first free list of the central cache to realize the operation of returning the first object.
[0083] Step 206: Release the memory of the first contiguous page.
[0084] In this embodiment, the first contiguous page memory is released when all objects in the first contiguous page memory pair are in a free state. That is, when the first free list stores all objects in the first contiguous page memory pair, it is determined that the first contiguous page memory can be released.
[0085] It should be noted that steps 204 to 205 can be implemented before steps 202 to 203, or steps 204 to 205 can be implemented simultaneously with steps 202 to 203. Steps 202 to 203 and steps 204 to 205 can also be implemented separately, that is, each can be implemented as a separate embodiment. The specific execution order can be determined according to the actual situation, and no restrictions are made here.
[0086] Based on the foregoing embodiments, in other embodiments of this application, refer to... Figure 3 As shown, after executing step 203, the memory management device is also used to execute steps 207 to 210:
[0087] Step 207: Determine at least one second free object that matches the process from the first memory linked list.
[0088] Step 208: Create a second free list in the thread cache based on at least one second free object.
[0089] Step 209: If a process's request for an object is detected, determine a second object that matches the request for an object from the second free list.
[0090] Step 210: Assign the second object to the process.
[0091] In this embodiment, at least one first free object corresponding to the newly allocated first memory list in the central cache is allocated to the thread cache. When the process needs the object during runtime, the second object in the second free list in the thread cache is allocated to the process, so that the object in the first contiguous page memory is no longer allocated, thereby ensuring that the first contiguous page memory can be released quickly.
[0092] Based on the foregoing embodiments, in other embodiments of this application, step 201 can be implemented by steps 201a to 201b:
[0093] Step 201a: Get the current memory cache size.
[0094] Step 201b: If the current memory cache size is greater than the cache threshold, determine the current usage rate of the first contiguous page memory.
[0095] In the embodiments of this application, steps 201a to 201b implement the process of automatically monitoring and releasing the memory of the first contiguous page.
[0096] Based on the foregoing embodiments, this application provides a flowchart illustrating the allocation of small objects (0, 256KB), referring to... Figure 4As shown, the cache includes three areas: process A, thread cache B, central cache C, and page heap D. When process A is running, thread cache B provides corresponding memory for process A. When the memory cache in thread cache B is insufficient, thread cache B requests small objects from central cache C to provide more memory for the process. When the free objects in central cache C are insufficient, central cache C will request another block of memory from page heap D for the process to use. Specifically:
[0097] Thread Cache is a memory cache corresponding to each process, including thread caches for multiple processes. Each Thread Cache is divided into different sizes, denoted as size classes, and each size class has a separate FreeList for caching corresponding free objects. Central Cache is a cache shared by all processes. Central Cache divides Span into several objects for thread use. Page Heap is TCMalloc's abstraction of dynamically allocable memory. When the free objects in Central Cache are insufficient, Central Cache requests a block of memory from Page Heap, which may come from Page Heap caches or request new memory from the system, and splits it into a series of free objects, adding them to the CentralFreeList of the corresponding size class.
[0098] In this process, small objects are allocated by directly returning a free object from the Thread Cache's FreeList. Similarly, small objects are reclaimed by simply putting them back into the FreeList of objects in the Thread Cache. No locking is required when retrieving or reclaiming memory from the Thread Cache. A Span can only be released after all its objects are in an unused state. Correspondingly, the CentralFreeList caches a series of small objects for each thread's Thread Cache to retrieve. Each thread also returns any excess free small objects to the CentralFreeList. Furthermore, the CentralFreeList is responsible for requesting spans from the PageHeap to divide them into small objects, and for returning unused spans to the PageHeap.
[0099] The structure diagram of CentralFreeList can be found by referring to... Figure 5 As shown, this includes a list of empty spans, which can be denoted as `empty_Span`, and a list of non-empty spans, which can be denoted as `nonempty_Span`. Among these, Figure 5 In each Span, `prev` represents a pointer relationship, pointing to the Span preceding it, and `next` also represents a pointer relationship, pointing to the Span following it. `object` indicates the objects included in the Span. An `object` can specifically include multiple objects, and the relationships between each of these objects can be found in [reference needed]. Figure 6 As shown, in Figure 6 It includes four objects: E1, E2, E3, and E4 (not shown in the diagram). Figure 6 In this context, E11 is the address of object E1, which points to the address of the next object E2; E12 is the content of object E1; E21 is the address of object E2, which points to the address of the next object E3; E22 is the content of object E2; E31 is the address of object E3, which points to the address of the next object E4; E32 is the content of object E3; E41 is the address of object E4; and E42 is the content of object E4.
[0100] Based on the foregoing embodiments, this application provides an application scenario where, at a first moment, a process has a high demand for a certain size class and therefore requests a large number of Spans from the Central Cache via the Thread Cache. However, at a second moment, the process's demand for that size class decreases. In this case, the Central Cache isolates the existing `empty_Span` and `nonempty_Span` non-rotating lists, setting them to only return historical Spans in `empty_Span` and `nonempty_Span` without requesting them again. Simultaneously, the Central Cache requests new Spans from the PageHeap and creates rotating lists based on these new Spans, namely `empty_rotating_Span` and `nonempty_rotating_Span`, placing the new free Spans into `empty_rotating_Span`. Spans in the rotating lists can be requested and released normally. `empty_rotating_Span` and `nonempty_rotating_Span` are the aforementioned first memory linked list, `empty_Span` is the aforementioned first free list, and `empty_rotating_Span` is the aforementioned second free list. Correspondingly, the structural diagram of the Central Cache at this time can be referred to... Figure 7 As shown, when an object En is returned, its identifier information can be used to determine whether the object belongs to an existing empty_Span or nonempty_Span, or a newly created empty_rotating_Span or nonempty_rotating_Span. In other words, when the Thread Cache returns a small object to the Central Cache, it determines the linked list to which the Span belongs based on the identifier of the Span containing the small object.
[0101] For Thread Cache, Thread Cache returns all small objects from its original FreeList to Central Cache, and simultaneously requests new small objects from Central Cache, adding them to a new FreeList. When Central Cache receives a small object returned from Thread Cache, it determines the identifier of the Span containing the returned object. If the Span identifier matches a previous Span identifier, the returned object is placed in the empty_Span; otherwise, it is placed in the empty_rotating_Span.
[0102] Let's take size class = 2, which is 32 bits (Byte, B), as an example for explanation. Figure 8 As shown, when the Thread Cache determines to return an object of size class = 2 in Span1, step F1: The Thread Cache calculates the identifier information of the Span included by the address of the object of size class = 2, determines the non-rotating linked list of Span1 based on the calculated identifier information of the Span, and returns the object of size class = 2 to empty_Span; step F2: When the Thread Cache requests an object of size class = 2 from the Central Cache, it determines the object of size class = 2 from empty_rotating_Span and obtains a new Span, denoted as Span2.
[0103] It should be noted that the explanation of the same steps or concepts in this embodiment as in other embodiments can be found in the descriptions in other embodiments, and will not be repeated here.
[0104] The memory management method provided in this application, after determining the current utilization rate of the first contiguous page memory in the central cache, if the current utilization rate is less than or equal to a preset threshold, requests a second contiguous page memory from the page cache and splits the second contiguous page memory into at least one first free object. The first contiguous page memory is then released based on the at least one first free object linked to the end of the first memory list. In this way, when the current utilization rate of the first contiguous page memory is low, a new second contiguous page memory is requested from the page cache so that when a process needs an object, the object corresponding to the second contiguous page memory is allocated to the process, and the first contiguous page memory is released. This solves the problem of the lack of a technical solution for quickly releasing spans and proposes a technical solution for quickly releasing spans, thereby improving the utilization rate of the memory cache.
[0105] Based on the foregoing embodiments, embodiments of this application provide a memory management method, which is applied to a memory management device that implements dynamic memory allocation TCMalloc for thread caching, and refers to... Figure 9 As shown, the method includes the following steps:
[0106] Step 301: Determine the current usage rate of the first contiguous page of memory in the central cache.
[0107] Step 302: If the current usage rate is less than or equal to the preset threshold, request memory for the second contiguous page from the page cache.
[0108] The application operation is used to instruct the applicant.
[0109] Step 303: Split the second contiguous page memory into at least one first free object, and obtain a first memory linked list based on at least one first free object.
[0110] The first memory linked list is used to provide a matching object for the process when the process requests an object.
[0111] Step 304: Determine at least one second free object that matches the process from the first memory linked list.
[0112] Step 305: Create a second free list in the thread cache based on at least one second free object.
[0113] Step 306: If a process's request for an object is detected, determine a second object that matches the request for an object from the second free list.
[0114] Step 307: Assign the second object to the process.
[0115] Step 308: Confirm the selection instruction.
[0116] The selection instruction is used to indicate whether the process should return the currently used third object if the current usage rate of the first contiguous memory page is less than or equal to a preset threshold.
[0117] In this embodiment, the selection instruction is set by the user according to their own needs, indicating whether the process should actively release the currently used object when the usage rate of Span is low.
[0118] Step 309: If the selected instruction is the target instruction, determine the fourth object from the second free list.
[0119] The second object includes the fourth object.
[0120] In this embodiment, the target instruction selected by the user is an instruction that instructs the process to return the currently used object when the current usage rate of the first contiguous page memory is less than or equal to a preset threshold.
[0121] Step 310: Copy the cached content from the third object to the fourth object.
[0122] Step 311: Return the third object to the central cache.
[0123] In this embodiment, a fourth object is allocated to the process before the process returns the third object. This does not affect the running efficiency of the process, but the process actively returns the Span object with low usage, which effectively improves the efficiency of releasing the Span with low usage.
[0124] Step 312: If the current usage rate is less than or equal to a preset threshold, determine the first object that is not used by the process and included in the first free list of the thread cache.
[0125] Step 313: Store the first object in the first free list of the central cache.
[0126] The first free list is used to store objects that are currently in a free state.
[0127] Step 314: Release the memory of the first contiguous page.
[0128] In other embodiments of this application, steps 302-311 may be executed after steps 312-313, or steps 302-311 and steps 312-313 may be executed simultaneously. The specific order of execution can be determined according to the actual application scenario, and no specific limitation is made here.
[0129] Based on the foregoing embodiments, in other embodiments of this application, step 311 can be implemented by steps 311a to 311b, or steps 311a and 311c:
[0130] Step 311a: Determine the target identifier information of the memory linked list to which the third object belongs.
[0131] Step 311b: If the target identification information is the first identification information of the first contiguous page memory, save the third object to the first free list corresponding to the first contiguous page memory.
[0132] The first free list is used to store objects that are currently in a free state.
[0133] Step 311c: If the target identification information is the second identification information of the second contiguous page memory, save the third object to the second free list corresponding to the second contiguous page memory.
[0134] The second free list is used to store objects that are currently in a free state.
[0135] Based on the aforementioned embodiments, when determining the user's selection instruction, when a process actively returns small objects, a corresponding object return processing method can be customized for a specific size class, such as a rotating processing function. For example, the customized processing function for a small object with size class = 2 is as follows: The process performs a memory copy operation, releasing the original object with size class = 2 and allocating new memory. At this time, the memory used by the process is not reduced, but because the original object is on a non-rotating linked list, TCMalloc can release a large number of spans after the small object is returned. After the process registers the processing function with TCMalloc, TCMalloc will automatically call the corresponding processing function when adjusting the size class, improving the release efficiency of spans.
[0136] It should be noted that the explanation of the same steps or concepts in this embodiment as in other embodiments can be found in the descriptions in other embodiments, and will not be repeated here.
[0137] The memory management method provided in this application, after determining the current utilization rate of the first contiguous page memory in the central cache, if the current utilization rate is less than or equal to a preset threshold, requests a second contiguous page memory from the page cache, and splits the second contiguous page memory into at least one first free object. A first memory linked list is then obtained based on at least one first free object, and finally, the first contiguous page memory is released. In this way, when the current utilization rate of the first contiguous page memory is low, new second contiguous page memory is requested from the page cache so that when a process needs an object, the object corresponding to the second contiguous page memory can be allocated to the process, and the first contiguous page memory can be released. This solves the problem of the lack of a technical solution for quickly releasing spans and proposes a technical solution for quickly releasing spans, thereby improving the utilization rate of the memory cache.
[0138] Based on the foregoing embodiments, this application provides a memory management device 4 for implementing TCMalloc. This memory management device 4 can be applied to... Figures 1-3 and Figure 9 In embodiments corresponding to other methods, refer to Figure 10 As shown, the memory management device 4 includes: a determination unit 41, an allocation unit 42, a splitting unit 43, and a release unit 44; wherein:
[0139] Determining unit 41 is used to determine the current usage rate of the first contiguous page memory in the central cache;
[0140] Application unit 42 is used to request a second contiguous page of memory from the page cache if the current utilization rate is less than or equal to a preset threshold.
[0141] The splitting unit 43 is used to split the second consecutive page into at least one first free object and obtain a first memory linked list based on the at least one first free object; wherein, the first memory linked list is used to provide matching objects for the process when the process requests objects;
[0142] Release unit 44 is used to release the first contiguous page memory.
[0143] In other embodiments of this application, the memory management device further includes: a processing unit; wherein:
[0144] The processing unit is used to determine, if the current usage rate is less than or equal to a preset threshold, a first object that is not used by the process and is included in the first free list of the thread cache.
[0145] The processing unit is also used to store the first object into a first free list in the central cache; wherein the first free list is used to store objects that are currently in a free state.
[0146] In other embodiments of this application, after the splitting unit performs the steps of splitting the second contiguous page memory into at least one first free object and obtaining a first memory linked list based on at least one first free object, it is further configured to perform the following steps:
[0147] Identify at least one second free object matching the process from the first memory linked list;
[0148] Create a second free list in the thread cache based on at least one second free object;
[0149] If a process requests an object, determine a second object that matches the request from the second free list;
[0150] Assign a second object to the process.
[0151] In other embodiments of this application, the processing unit is further configured to perform the following steps:
[0152] Determine the selection instruction; wherein, the selection instruction is used to indicate whether the process should return the currently used third object if the current usage rate of the first contiguous memory page is detected to be less than or equal to a preset threshold;
[0153] If the selected instruction is the target instruction, the fourth object is determined from the second free list; wherein the second object includes the fourth object;
[0154] Copy the cached content from the third object to the fourth object;
[0155] Return the third object to the central cache.
[0156] In other embodiments of this application, when the processing unit implements the step of returning the third object to the central cache, it can be achieved through the following steps:
[0157] Determine the target identifier information of the memory linked list to which the third object belongs;
[0158] If the target identifier information is the first identifier information of the first contiguous page memory, the third object is saved to the first free list corresponding to the first contiguous page memory; wherein, the first free list is used to store objects that are currently in a free state.
[0159] In other embodiments of this application, the processing unit is further configured to implement the following steps:
[0160] If the target identifier is the second identifier of the second contiguous page memory, the third object is saved to the second free list corresponding to the second contiguous page memory; wherein, the second free list is used to store objects that are currently in a free state.
[0161] In other embodiments of this application, the determining unit includes: an acquisition module and a determining module; wherein:
[0162] The get module is used to obtain the current memory cache size;
[0163] The determination module is used to determine the current utilization rate of the first contiguous page of memory if the current memory cache size is greater than the cache threshold.
[0164] It should be noted that the explanation of the same steps or concepts in this embodiment as in other embodiments can be found in the descriptions in other embodiments, and will not be repeated here.
[0165] The memory management device provided in the embodiments of this application, after determining the current utilization rate of the first contiguous page memory in the central cache, if the current utilization rate is less than or equal to a preset threshold, requests a second contiguous page memory from the page cache, and splits the second contiguous page memory into at least one first free object, so as to obtain a first memory linked list based on at least one first free object, and finally releases the first contiguous page memory. In this way, when the current utilization rate of the first contiguous page memory is low, a new second contiguous page memory is requested from the page cache, so that when the process needs an object, the object corresponding to the second contiguous page memory is allocated to the process, and the first contiguous page memory is released. This solves the problem that there is currently no technical solution for fast release of spans, and proposes a technical solution for fast release of spans, thereby improving the utilization rate of memory cache.
[0166] Based on the foregoing embodiments, this application provides a memory management device 5, which can be applied to... Figures 1-3 and Figure 9 In embodiments corresponding to other methods, refer to Figure 11 As shown, the memory management device 5 includes: a memory 51, a processor 52, a memory 53, and a communication bus 54; wherein:
[0167] Memory 51 is used to store executable instructions;
[0168] Communication bus 54 is used to realize the communication connection between memory 51, processor 52 and memory 53;
[0169] Memory 53, used to provide data caching for process execution;
[0170] Processor 52 is used to execute the memory management program stored in memory 51 to implement the following Figures 1-3 and Figure 9 The corresponding embodiments and the interaction process in the memory management method provided in the above embodiments will not be described again here. It should be noted that in some specific application scenarios, the memory 51 includes the memory 53.
[0171] Based on the foregoing embodiments, embodiments of this application provide a computer-readable storage medium, simply referred to as a storage medium, which stores one or more memory management programs. These memory management programs can be executed by one or more processors to achieve the following: Figures 1-3 and Figure 9 The memory management methods provided in the corresponding embodiments will not be described in detail here.
[0172] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0173] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0174] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, air conditioner, or network communication link device, etc.) to execute the methods described in the various embodiments of this application.
[0175] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0176] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0177] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0178] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A memory management method, characterized in that, The method is applied to a memory management device that implements dynamic memory allocation TCMalloc for thread caching, and the method includes: Determine the current usage of the first contiguous page of memory in the central cache; If the current utilization rate is less than or equal to a preset threshold, request memory for a second contiguous page from the page cache; The second contiguous page memory is split into at least one first free object, and a first memory linked list is obtained based on the at least one first free object; wherein, the first memory linked list is used to provide a matching object for the process when the process requests an object; After obtaining the first memory linked list, the first contiguous page memory is released.
2. The method according to claim 1, characterized in that, The method further includes: If the current usage rate is less than or equal to the preset threshold, determine the first object that is not used by the process and included in the first free list of the thread cache; The first object is stored in a first free list of the central cache; wherein the first free list is used to store objects that are currently in an idle state.
3. The method according to any one of claims 1 to 2, characterized in that, After splitting the second contiguous page memory into at least one first free object and obtaining a first memory linked list based on the at least one first free object, the method further includes: Determine at least one second free object matching the process from the first memory list; Based on the at least one second free object, a second free list is created in the thread cache; If a request object operation of the process is detected, a second object matching the request object operation is determined from the second free list; Assign the second object to the process.
4. The method according to claim 3, characterized in that, The method further includes: A selection instruction is determined; wherein the selection instruction is used to indicate whether the process should return the currently used third object if the current usage rate of the first contiguous memory page is detected to be less than or equal to the preset threshold. If the selection instruction is a target instruction, a fourth object is determined from the second free list; wherein the second object includes the fourth object; Copy the cached content from the third object to the fourth object; Return the third object to the central cache.
5. The method according to claim 4, characterized in that, Returning the third object to the central cache includes: Determine the target identifier information of the memory linked list to which the third object belongs; If the target identification information is the first identification information of the first contiguous page memory, the third object is saved to the first free list corresponding to the first contiguous page memory; wherein, the first free list is used to store objects that are currently in a free state.
6. The method according to claim 5, characterized in that, The method further includes: If the target identification information is the second identification information of the second contiguous page memory, the third object is saved to the second free list corresponding to the second contiguous page memory; wherein, the second free list is used to store objects that are currently in a free state.
7. The method according to claim 1, characterized in that, Determining the current usage rate of the first contiguous page memory in the central cache includes: Get the current memory cache size; If the current memory cache size is greater than the cache threshold, determine the current utilization rate of the first contiguous pages of memory.
8. A memory management device, characterized in that, The apparatus is used to implement TCMalloc, and the apparatus includes: a determination unit, an allocation unit, a splitting unit, and a release unit; wherein: The determining unit is used to determine the current usage rate of the first contiguous page memory in the central cache; The application unit is used to apply for a second contiguous page memory from the page cache if the current utilization rate is less than or equal to a preset threshold. The splitting unit is used to split the second consecutive page into at least one first free object, and to obtain a first memory linked list based on the at least one first free object; wherein, the first memory linked list is used to provide a matching object for the process when the process requests an object; The release unit is used to release the first contiguous page memory after obtaining the first memory linked list.
9. A memory management device, characterized in that, The device includes: a memory, a processor, RAM, and a communication bus; wherein: The memory is used to store executable instructions; The communication bus is used to realize the communication connection between the processor, the memory and the memory; The memory is used to provide data caching objects for process execution; The processor is configured to execute a memory management program stored in the memory to implement the steps of the memory management method as described in any one of claims 1 to 7.
10. A storage medium, characterized in that, The storage medium stores a memory management program, which, when executed by a processor, implements the steps of the memory management method as described in any one of claims 1 to 7.