LRU-based handle management method, device, equipment and readable storage medium

By using LRU -based handle management methods in the process of storage I/O, combining two -level cache strategies of lock -free LRU cache and global hash table, it solves the problem of great performance impact in existing technology, realized the effective reduction of memory and reducing memory and realizing memory Increase the performance of the handle.

CN117591446BActive Publication Date: 2025-01-28CHINA ELECTRONICS CLOUD DIGITAL INTELLIGENCE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311529282.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-16
Publication Date
2025-01-28
Estimated Expiration
2043-11-16

Smart Images

  • Figure CN117591446B_ABST
    Figure CN117591446B_ABST
Patent Text Reader

Abstract

A handle management method, device, equipment and readable storage medium based on LRU, which relates to the field of memory optimization, including when a target object is detected and the least recently used LRU cache of the thread where the target object is located has been initialized, judging whether there is a target keyword corresponding to the target object in the LRU cache, and the processing mechanism of the LRU cache is a lock-free operation; if there is, obtaining the target handle corresponding to the target keyword from a preset hash table; if it does not exist and it is detected that there is no target handle corresponding to the target object in the hash table, applying for a target handle for the target object, and creating a first keyword in the LRU cache, so that the first keyword and the target object form a key-value pair; storing the target handle in the hash table, so that the target handle and the first keyword form a key-value pair. The present application not only reduces the memory usage of the handle, but also improves the performance of obtaining handles for objects such as obj during storage I / O.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of memory optimization technology, and in particular to a handle management method, device, equipment and readable storage medium based on LRU. Background Art

[0002] In the process of storage I / O (Input / Output, putting data in / taking data out), each obj (i.e. object, such as a file object, etc.) needs to apply for a corresponding handle, and the handle applied for each obj is fully cached. However, since the handle needs to carry layout information of about 2k in size, it will occupy a large amount of memory space when the number of storage I / O is large.

[0003] In order to reduce memory, the related art usually puts the handle applied for each obj into a global hash table Hash; when a new obj comes in, it is directly searched in the global Hash table. If it is found, the handle is not applied for again, otherwise it is reapplied. Although the above method can achieve the purpose of reducing memory, when a large number of obj access the global Hash table at the same time, frequent locking and releasing operations are required, which has a great impact on performance.

[0004] It can be seen that how to improve the performance of obtaining handles while reducing memory is an urgent problem that needs to be solved. Summary of the invention

[0005] The present application provides a handle management method, apparatus, device and readable storage medium based on LRU to improve the performance of obtaining handles while reducing memory.

[0006] In a first aspect, an embodiment of the present application provides a handle management method based on LRU, and the handle management method based on LRU includes:

[0007] When a target object is detected and the least recently used LRU cache of the thread where the target object is located has been initialized, it is determined whether there is a target keyword corresponding to the target object in the LRU cache, and the processing mechanism of the LRU cache is a lock-free operation;

[0008] If it exists, then obtain the target handle corresponding to the target keyword from the preset Hash table;

[0009] If it does not exist and it is detected that there is no target handle corresponding to the target object in the Hash table, apply for a target handle for the target object, and create a first keyword in the LRU cache so that the first keyword and the target object form a key-value pair;

[0010] The target handle is stored in the Hash table so that the target handle and the first keyword form a key-value pair.

[0011] In combination with the first aspect, in one implementation, the method further includes:

[0012] When a target object is detected and the LRU cache of the thread where the target object is located is not initialized, the LRU cache is initialized, and a first keyword is newly created in the LRU cache so that the first keyword and the target object form a key-value pair;

[0013] Detect whether there is a target handle corresponding to the target object in the Hash table;

[0014] If it exists, then obtaining the target handle from the Hash table, and forming a key-value pair between the target handle and the first keyword in the Hash table;

[0015] If it does not exist, apply for a target handle for the target object and store the target handle in a hash table so that the target handle and the first keyword form a key-value pair.

[0016] In combination with the first aspect, in one implementation, after the step of determining whether there is a target keyword corresponding to the target object in the LRU cache, the step further includes:

[0017] If the target keyword corresponding to the target object does not exist in the LRU cache and it is detected that the target handle corresponding to the target object exists in the Hash table, then the target handle is obtained from the Hash table;

[0018] A new first keyword is created in the LRU cache so that the first keyword and the target object form a key-value pair, and at the same time, the target handle and the first keyword form a key-value pair in the Hash table.

[0019] In combination with the first aspect, in one implementation, each keyword in the LRU cache has a counter corresponding thereto, and after the step of determining whether there is a target keyword corresponding to the target object in the LRU cache, the method further includes:

[0020] If a target keyword corresponding to the target object exists in the LRU cache, the counter corresponding to the target keyword is updated to obtain a new counter value.

[0021] In combination with the first aspect, in one implementation, after the step of acquiring the target handle corresponding to the target keyword from the preset Hash table, the method further includes:

[0022] Add the target keyword to the release list;

[0023] After the target keyword is released, the counter corresponding to the target keyword is updated to obtain a new counter value.

[0024] In combination with the first aspect, in one implementation, each key-value pair in the Hash table has a corresponding counter, and the method further includes:

[0025] When it is detected that the number of objects in the LRU cache is greater than a preset threshold, the second keyword with the smallest counter value is eliminated;

[0026] The counter of the target key-value pair corresponding to the second keyword in the Hash table is updated to obtain a new reference count value.

[0027] In combination with the first aspect, in one implementation, the method further includes:

[0028] When the reference count value corresponding to the target key-value pair is equal to 0, the target key-value pair and the handle corresponding to the target key-value pair are deleted from the Hash table.

[0029] In a second aspect, an embodiment of the present application provides a handle management device based on LRU, and the handle management device based on LRU includes:

[0030] A first management module, which is used to determine whether there is a target keyword corresponding to the target object in the LRU cache when a target object is detected and the least recently used LRU cache of the thread where the target object is located has been initialized, and the processing mechanism of the LRU cache is a lock-free operation;

[0031] A second management module, which is used to obtain a target handle corresponding to the target keyword from a preset hash table if it exists;

[0032] The third management module is used to apply for a target handle for the target object if it does not exist and detects that the target handle corresponding to the target object does not exist in the Hash table, and to create a first keyword in the LRU cache so that the first keyword and the target object form a key-value pair; the target handle is stored in the Hash table so that the target handle and the first keyword form a key-value pair.

[0033] In the third aspect, an embodiment of the present application provides an LRU-based handle management device, which includes a processor, a memory, and an LRU-based handle management program stored in the memory and executable by the processor, wherein when the LRU-based handle management program is executed by the processor, the steps of the aforementioned LRU-based handle management method are implemented.

[0034] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which an LRU-based handle management program is stored, wherein when the LRU-based handle management program is executed by a processor, the steps of the aforementioned LRU-based handle management method are implemented.

[0035] The beneficial effects brought by the technical solution provided in the embodiments of the present application include:

[0036] A single-threaded, lock-free LRU cache is used to perform preliminary management of handle queries and caches for target objects such as obj. When the LRU cache of the thread where the target object is located has been initialized and the target keyword corresponding to the target object exists in the LRU cache, the target handle corresponding to the target keyword is directly obtained from the Hash table without repeatedly applying for the handle or storing the handle repeatedly in the Hash table, thereby effectively reducing memory usage. When the target handle corresponding to the target object does not exist in the LRU cache and does not exist in the Hash table, a target handle is applied for the target object, and a first keyword is newly created in the LRU cache so that the first keyword and the target object form a key-value pair, and the target handle is stored in the Hash table so that the target handle and the first keyword form a key-value pair, so that when the next object that needs to apply for the target handle enters, the target handle can be quickly found based on the above two key-value pairs, thereby effectively improving the performance of obtaining handles for objects such as obj. It can be seen that the present application adopts a single-threaded lock-free LRU cache mechanism and combines it with a two-level cache strategy of a global hash table to implement handle acquisition and caching of objects such as obj. It does not need to directly search in the hash table, nor does it need to repeatedly store the handles in the hash table. This not only improves the performance of obtaining handles for objects such as obj during storage I / O, but also reduces the memory usage of the handles, so as to effectively avoid excessive memory usage in large-scale I / O scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] Figure 1 This is a flowchart of an embodiment of the LRU-based handle management method of the present application;

[0038] Figure 2 A schematic diagram of the process of eliminating cached data in an embodiment of the present application;

[0039] Figure 3 This is a functional module diagram of an embodiment of a handle management device based on LRU of the present application;

[0040] Figure 4 This is a schematic diagram of the hardware structure of the LRU-based handle management device involved in the embodiment of the present application. DETAILED DESCRIPTION

[0041] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0042] First, some technical terms in the present application are explained to facilitate those skilled in the art to understand the present application.

[0043] LRU (Least Recently Used): A commonly used page replacement algorithm that selects the pages that have not been used for the longest time for elimination.

[0044] Hash table: A data structure that is accessed directly based on a key value, that is, records are accessed by mapping the key value to a position in the table to speed up the search.

[0045] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0046] In a first aspect, an embodiment of the present application provides a handle management method based on LRU.

[0047] In one embodiment, referring to Figure 1 , Figure 1 FIG. 1 is a flow chart of an embodiment of the LRU-based handle management method of the present application. Figure 1 As shown, the LRU-based handle management method includes:

[0048] Step S10: When a target object is detected and the least recently used LRU cache of the thread where the target object is located has been initialized, it is determined whether there is a target keyword corresponding to the target object in the LRU cache, and the processing mechanism of the LRU cache is a lock-free operation.

[0049] For example, in order to solve the memory usage caused by full caching of handles and the performance loss caused by searching the global hash table, this embodiment proposes a method combining a two-level cache mechanism of lock-free LRU and global hash to cache handles in the I / O process. Among them, the two-level cache mechanism in this embodiment mainly includes the following two levels: the first level is to create an LRU cache in the dimension of threads in libdaos, that is, to create an LRU cache for each thread separately, and the LRU in the thread uses a lock-free method to ensure performance, that is, there is no need to frequently lock and release the lock; the second level is to establish a global hash table to store handles.

[0050] It should be understood that the LRU cache is used to store key-value pairs, which represent the correspondence between the visited obj objects and their corresponding keyword keys; the Hash table is also used to store key-value pairs, which represent the correspondence between the keyword key and the handle. The Hash table is initialized and the memory limit is set when the process starts; the keyword key in the Hash table is the same as the keyword key in the LRU cache, and the corresponding value is the handle with layout information required to store I / O.

[0051] When the target object is detected, that is, when the obj object arrives, it can be determined whether the LRU cache of the thread where the target object is located has been initialized based on whether the thread variable occupies memory. If the LRU cache has been initialized, the LRU cache is queried to determine whether there is a target keyword corresponding to the target object in the LRU cache. If so, it means that the target object has applied for a handle through the thread, and a target keyword with a small memory footprint has been constructed based on the target object, and the target keyword is added to the LRU cache queue as a node, and the correspondence between the target object and the target keyword is stored in the LRU cache in the form of a key-value pair. If not, it means that the target object may not have applied for a handle through the thread. Of course, it is also possible that the previously stored target keyword has been eliminated in order to reduce the memory footprint of the LRU cache, so that it cannot be found.

[0052] Step S20: If it exists, obtain the target handle corresponding to the target keyword from the preset Hash table.

[0053] Exemplarily, in this embodiment, if there is a target keyword corresponding to the target object in the LRU cache, it means that the target object has applied for a handle through the thread and the handle has also been stored in the hash table, then directly enter the second-level hash table; and traverse the key-value pairs in the hash table until the target handle corresponding to the target keyword is found, and return the target handle to the target object.

[0054] Step S30: If it does not exist and it is detected that there is no target handle corresponding to the target object in the Hash table, apply for a target handle for the target object and create a first keyword in the LRU cache so that the first keyword and the target object form a key-value pair.

[0055] Exemplarily, in this embodiment, if the target keyword corresponding to the target object does not exist in the LRU cache, it is further determined whether there is a target handle corresponding to the target object in the Hash table; if it is detected that there is no target handle corresponding to the target object in the Hash table, it means that the target handle is not stored in the Hash table, that is, the handle cannot be directly obtained from the Hash table for the target object, then it is necessary to apply for a handle for the target object, and the handle is the target handle that has a corresponding relationship with the target object. At the same time, it is necessary to construct a keyword (i.e., the first keyword) for the target object in the LRU cache, and store the corresponding relationship between the target object and the first keyword in the form of a key-value pair, so that when the target object arrives next time, it can enter the Hash table according to the key-value pair information to obtain the handle, which effectively improves the performance of obtaining the handle.

[0056] Step S40: Store the target handle into the Hash table so that the target handle and the first keyword form a key-value pair.

[0057] Exemplarily, in this embodiment, for the target handle newly applied for the target object, it will be stored in the Hash table, and the corresponding relationship between the target handle and the first keyword will be constructed in the form of a key-value pair, and the target handle will be returned at the same time. It can be seen that for each handle, the handle will only be stored in the Hash table if it does not exist in the Hash table, instead of storing each handle applied for the obj object in the Hash table, which effectively limits the memory occupied by the handle to prevent the problem of excessive memory usage in the scenario of a large number of I / Os. For example, the handle requested by obj1 is oh1, the handle requested by obj2 is oh1, and the handle requested by obj3 is also oh1, then only one oh1 will be stored in the Hash table instead of three. At this time, the Hash table will store the correspondence between obj1 and oh1, the correspondence between obj2 and oh1, and the correspondence between obj3 and oh1 in the form of key-value pairs. When any of obj1, obj2, and obj3 needs to obtain the handle, it only needs to traverse the key-value pairs in the Hash table to quickly find oh1.

[0058] It can be seen that this embodiment implements the acquisition and caching of handles of objects such as obj by adopting a single-threaded lock-free LRU cache mechanism and combining it with a two-level cache strategy of a global hash table. It does not need to directly search in the hash table, nor does it need to repeatedly store the handles in the hash table. This not only improves the performance of obtaining handles of objects such as obj during the storage I / O process, but also reduces the memory usage of the handles, so as to effectively avoid excessive memory usage in large-scale I / O scenarios.

[0059] Furthermore, in one embodiment, the method further includes:

[0060] When a target object is detected and the LRU cache of the thread where the target object is located is not initialized, the LRU cache is initialized, and a first keyword is newly created in the LRU cache so that the first keyword and the target object form a key-value pair;

[0061] Detect whether there is a target handle corresponding to the target object in the Hash table;

[0062] If it exists, then obtaining the target handle from the Hash table, and forming a key-value pair between the target handle and the first keyword in the Hash table;

[0063] If it does not exist, apply for a target handle for the target object and store the target handle in a hash table so that the target handle and the first keyword form a key-value pair.

[0064] Exemplarily, in this embodiment, when the target object is detected and the LRU cache of the thread where the target object is located is not initialized, it is necessary to initialize the queue length and other information of the LRU cache of the current thread, and set the memory upper limit of the LRU cache queue; at the same time, a first keyword with a smaller memory footprint is constructed according to the target object, and the first keyword is added as a node to the LRU cache queue, and the correspondence between the target object and the first keyword is stored in the form of a key-value pair.

[0065] After the LRU cache operation is completed, check whether there is a target handle corresponding to the target object in the second-level Hash table; if there is a target handle corresponding to the target object in the Hash table, obtain the target handle directly from the Hash table, and create a correspondence between the target handle and the first keyword in the form of a key-value pair in the Hash table; if there is no target handle corresponding to the target object in the Hash table, it is necessary to apply for a target handle for the target object, store the target handle in the Hash table, and build a correspondence between the target handle and the first keyword in the form of a key-value pair.

[0066] Furthermore, in one embodiment, after the step of determining whether there is a target keyword corresponding to the target object in the LRU cache, the step further includes:

[0067] If the target keyword corresponding to the target object does not exist in the LRU cache and it is detected that the target handle corresponding to the target object exists in the Hash table, then the target handle is obtained from the Hash table;

[0068] A new first keyword is created in the LRU cache so that the first keyword and the target object form a key-value pair, and at the same time, the target handle and the first keyword form a key-value pair in the Hash table.

[0069] Exemplarily, in this embodiment, if it is detected that there is no target keyword corresponding to the target object in the LRU cache, but there is a target handle corresponding to the target object in the Hash table, the target handle is directly obtained from the Hash table; and a new first keyword is created for the target object in the LRU cache, and a correspondence between the first keyword and the target object is constructed in the form of a key-value pair. At the same time, a correspondence between the target handle and the first keyword is constructed in the Hash table in the form of a key-value pair, so that when the subsequent target object needs to obtain the target handle, it can quickly query and obtain the target handle through the LRU cache and the key-value pairs stored in the Hash.

[0070] Further, in one embodiment, each keyword in the LRU cache has a counter corresponding thereto, and after the step of determining whether there is a target keyword corresponding to the target object in the LRU cache, the method further includes:

[0071] If a target keyword corresponding to the target object exists in the LRU cache, the counter corresponding to the target keyword is updated to obtain a new counter value.

[0072] Exemplarily, in this embodiment, each keyword node in the LRU cache maintains a corresponding counter, that is, when a keyword node is accessed (such as newly created or queried), the counter value is incremented by 1, so as to represent the number of times the keyword is referenced, accessed or queried through the counter value, and the counter value is used as the criterion for elimination. Specifically, if it is detected that there is a target keyword corresponding to the target object in the LRU cache, it means that the number of times the target keyword is accessed increases by 1, then the counter of the target keyword is incremented by 1 to obtain a new counter value.

[0073] Furthermore, in one embodiment, after the step of obtaining the target handle corresponding to the target keyword from the preset hash table, the method further includes:

[0074] Add the target keyword to the release list;

[0075] After the target keyword is released, the counter corresponding to the target keyword is updated to obtain a new counter value.

[0076] Exemplarily, in this embodiment, after returning the target handle corresponding to the target object, the target keyword corresponding to the target object will be added to the release list freelist to wait for the corresponding pointer relationship to be released, thereby releasing a larger memory space. Since the LRU cache is a single-threaded variable, when the target keyword needs to be released, the current thread may not be the thread that applies for the LRU cache (i.e., the LRU cache where the target keyword is located), so the target keyword is only added to the release list and waits for release; when the target keyword is released, the counter corresponding to the target keyword is decremented by 1 to obtain a new counter value.

[0077] See also Figure 2 As shown, the specific release process is: before a certain obj object arrives to query the LRU cache, first traverse the release list of the thread variable to see if it is empty. If it is empty, end directly; if it is not empty, find the keyword to be released and release it, and reduce the counter value corresponding to the keyword in the LRU cache where the keyword is located by 1.

[0078] Furthermore, in one embodiment, each key-value pair in the Hash table has a corresponding counter, and the method further includes:

[0079] When it is detected that the number of objects in the LRU cache is greater than a preset threshold, the second keyword with the smallest counter value is eliminated;

[0080] The counter of the target key-value pair corresponding to the second keyword in the Hash table is updated to obtain a new reference count value.

[0081] Exemplarily, in this embodiment, the preset threshold is used to characterize the maximum number of objects that can be stored in the LRU cache, and the specific value setting can be determined according to actual needs and is not limited here. Each handle in the hash table maintains a corresponding counter, that is, when a handle is accessed (such as newly created or queried), the counter value is increased by 1, and when the keyword corresponding to the handle is eliminated, the counter value is reduced by 1, so that the counter value represents the number of times the handle is referenced, accessed or queried, and the counter value is used as the elimination standard.

[0082] When it is detected that the number of objects in the LRU cache is greater than the preset threshold, it means that the memory allocated in the LRU cache has been fully occupied. At this time, memory release is required. Specifically, the keyword with the smallest counter value (that is, the coldest keyword) can be eliminated, and the counter of the target key-value pair corresponding to the keyword in the Hash table can be updated to obtain a new reference count value.

[0083] Furthermore, in one embodiment, the method further includes:

[0084] When the reference count value corresponding to the target key-value pair is equal to 0, the target key-value pair and the handle corresponding to the target key-value pair are deleted from the Hash table.

[0085] Exemplarily, in this embodiment, not only will the elimination of cached data be triggered when the number of objects in the LRU cache is greater than a preset threshold, but also when the counter value of a certain keyword is equal to 0. It should be understood that the data elimination methods corresponding to the above two situations will trigger the elimination of cached data in the Hash table.

[0086] See also Figure 2 As shown, the cache data elimination process triggered when the counter value of a certain keyword is equal to 0 is used as an example for explanation: first, the release list is traversed to see if it is empty. If it is empty, it ends; if it is not empty, the keyword to be released in the release list is obtained for release, and the counter value corresponding to the keyword in the LRU cache where the keyword is located is reduced by 1 to obtain a new counter value; then it is determined whether the new counter value is equal to 0, if not, the release list is traversed again; if so, the keyword is eliminated from the LRU cache, and the reference counter value of the handle corresponding to the keyword in the Hash table is reduced by 1 to obtain a new reference counter value; then it is continued to determine whether the new reference counter value is equal to 0, if not, the release list is traversed again, and if so, the handle and its corresponding key-value pair are released and eliminated from the Hash table, thereby achieving the purpose of data elimination in the Hash table and effectively realizing memory control.

[0087] In summary, this embodiment adopts a single-thread lock-free LRU cache to ensure performance, and adopts a two-level cache strategy of thread variable LRU plus a global hash table to achieve memory control; in addition, the elimination logic of cached data in the release list corresponding to the thread variable LRU triggers the elimination logic in the global hash table, thereby achieving effective memory control.

[0088] In a second aspect, an embodiment of the present application also provides a handle management device based on LRU.

[0089] In one embodiment, referring to Figure 3 , Figure 3This is a functional module diagram of an embodiment of a handle management device based on LRU in this application. Figure 3 As shown, the LRU-based handle management device includes:

[0090] A first management module, which is used to determine whether there is a target keyword corresponding to the target object in the LRU cache when a target object is detected and the least recently used LRU cache of the thread where the target object is located has been initialized, and the processing mechanism of the LRU cache is a lock-free operation;

[0091] A second management module, which is used to obtain a target handle corresponding to the target keyword from a preset hash table if it exists;

[0092] The third management module is used to apply for a target handle for the target object if it does not exist and detects that the target handle corresponding to the target object does not exist in the Hash table, and to create a first keyword in the LRU cache so that the first keyword and the target object form a key-value pair; the target handle is stored in the Hash table so that the target handle and the first keyword form a key-value pair.

[0093] Furthermore, in one embodiment, the first management module is also used to initialize the LRU cache when a target object is detected and the LRU cache of the thread where the target object is located is not initialized; and to create a new first keyword in the LRU cache through the third management module, so that the first keyword and the target object form a key-value pair; the first management module is also used to detect whether there is a target handle corresponding to the target object in the Hash table; the second management module is also used to obtain the target handle from the Hash table if it exists, and form a key-value pair with the target handle and the first keyword in the Hash table through the third management module; the third management module is also used to apply for a target handle for the target object if it does not exist, and store the target handle in the Hash table, so that the target handle and the first keyword form a key-value pair.

[0094] Furthermore, in one embodiment, the second management module is also used to obtain the target handle from the Hash table if there is no target keyword corresponding to the target object in the LRU cache and it is detected that there is a target handle corresponding to the target object in the Hash table; the third management module is also used to create a new first keyword in the LRU cache so that the first keyword and the target object form a key-value pair, and at the same time, the target handle and the first keyword form a key-value pair in the Hash table.

[0095] Further, in one embodiment, each keyword in the LRU cache has a corresponding counter, and the third management module is further used to:

[0096] If a target keyword corresponding to the target object exists in the LRU cache, the counter corresponding to the target keyword is updated to obtain a new counter value.

[0097] Furthermore, in one embodiment, the third management module is further configured to:

[0098] Add the target keyword to the release list;

[0099] After the target keyword is released, the counter corresponding to the target keyword is updated to obtain a new counter value.

[0100] Furthermore, in one embodiment, each key-value pair in the Hash table has a corresponding counter, and the third management module is further used to:

[0101] When it is detected that the number of objects in the LRU cache is greater than a preset threshold, the second keyword with the smallest counter value is eliminated;

[0102] The counter of the target key-value pair corresponding to the second keyword in the Hash table is updated to obtain a new reference count value.

[0103] Furthermore, in one embodiment, the third management module is further configured to:

[0104] When the reference count value corresponding to the target key-value pair is equal to 0, the target key-value pair and the handle corresponding to the target key-value pair are deleted from the Hash table.

[0105] Among them, the functional implementation of each module in the above-mentioned LRU-based handle management device corresponds to each step in the above-mentioned LRU-based handle management method embodiment, and its functions and implementation processes are no longer repeated here.

[0106] In a third aspect, an embodiment of the present application provides an LRU-based handle management device. The LRU-based handle management device may be a personal computer (PC), a laptop computer, a server, or other device having a data processing function.

[0107] Reference Figure 4 , Figure 4 The hardware structure diagram of the LRU-based handle management device involved in the embodiment of the present application is shown in FIG. In the embodiment of the present application, the LRU-based handle management device may include a processor, a memory, a communication interface, and a communication bus.

[0108] The communication bus may be of any type and is used to interconnect the processor, the memory, and the communication interface.

[0109] The communication interface includes an input / output (I / O) interface, a physical interface, and a logical interface, etc., which are used to realize the interconnection of devices inside the LRU-based handle management device, and an interface for realizing the interconnection between the LRU-based handle management device and other devices (such as other computing devices or user devices). The physical interface can be an Ethernet interface, an optical fiber interface, an ATM interface, etc.; the user device can be a display, a keyboard, etc.

[0110] The memory can be various types of storage media, such as random access memory (RAM), read-only memory (ROM), non-volatile RAM (NVRAM), flash memory, optical storage, hard disk, programmable ROM (PROM), erasable PROM (EPROM), electrically erasable PROM (EEPROM), etc.

[0111] The processor may be a general-purpose processor, and the general-purpose processor may call the LRU-based handle management program stored in the memory and execute the LRU-based handle management method provided in the embodiment of the present application. For example, the general-purpose processor may be a central processing unit (CPU). The method executed when the LRU-based handle management program is called may refer to the various embodiments of the LRU-based handle management method of the present application, which will not be repeated here.

[0112] Those skilled in the art will understand that Figure 4 The hardware structure shown in the figure does not constitute a limitation on the present application, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.

[0113] In a fourth aspect, an embodiment of the present application also provides a computer-readable storage medium.

[0114] The readable storage medium of the present application stores an LRU-based handle management program, wherein when the LRU-based handle management program is executed by a processor, the steps of the LRU-based handle management method described above are implemented.

[0115] Among them, the method implemented when the LRU-based handle management program is executed can refer to the various embodiments of the LRU-based handle management method of the present application, and will not be repeated here.

[0116] It should be noted that the serial numbers of the above-mentioned embodiments of the present application are only for description and do not represent the advantages or disadvantages of the embodiments.

[0117] The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices. The terms "first", "second" and "third" are used to distinguish different objects, etc., and do not represent a sequence, nor do they limit "first", "second" and "third" to different types.

[0118] In the description of the embodiments of the present application, "exemplary", "for example" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary", "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary", "for example" or "for example" is intended to present related concepts in a specific way.

[0119] In the description of the embodiments of the present application, unless otherwise specified, “ / ” means or, for example, A / B can mean A or B; the “and / or” in the text is merely a description of the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, “multiple” refers to two or more than two.

[0120] In some processes described in the embodiments of the present application, multiple operations or steps that appear in a specific order are included, but it should be understood that these operations or steps may not be executed in the order in which they appear in the embodiments of the present application or in parallel, and the sequence number of the operation is only used to distinguish the different operations, and the sequence number itself does not represent any execution order. In addition, these processes may include more or fewer operations, and these operations or steps may be executed in sequence or in parallel, and these operations or steps may be combined.

[0121] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD) as described above, and includes a number of instructions for a terminal device to execute the methods described in each embodiment of the present application.

[0122] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A handle management method based on LRU, characterized in that: The LRU-based handle management method includes: When a target object is detected and the least recently used LRU cache of the thread where the target object is located has been initialized, it is determined whether there is a target keyword corresponding to the target object in the LRU cache, and the processing mechanism of the LRU cache is a lock-free operation; If it exists, then obtain the target handle corresponding to the target keyword from the preset Hash table; If it does not exist and it is detected that there is no target handle corresponding to the target object in the Hash table, apply for a target handle for the target object, and create a first keyword in the LRU cache so that the first keyword and the target object form a key-value pair; The target handle is stored in the Hash table so that the target handle and the first keyword form a key-value pair.

2. The LRU-based handle management method according to claim 1, characterized in that: The method further comprises: When a target object is detected and the LRU cache of the thread where the target object is located is not initialized, the LRU cache is initialized, and a first keyword is newly created in the LRU cache so that the first keyword and the target object form a key-value pair; Detect whether there is a target handle corresponding to the target object in the Hash table; If it exists, then obtain the target handle from the Hash table, and make the target handle and the first keyword form a key-value pair in the Hash table; If it does not exist, apply for a target handle for the target object and store the target handle in a hash table so that the target handle and the first keyword form a key-value pair.

3. The LRU-based handle management method according to claim 1, characterized in that: After the step of determining whether there is a target keyword corresponding to the target object in the LRU cache, the method further includes: If the target keyword corresponding to the target object does not exist in the LRU cache and it is detected that the target handle corresponding to the target object exists in the Hash table, then the target handle is obtained from the Hash table; A new first keyword is created in the LRU cache so that the first keyword and the target object form a key-value pair, and at the same time, the target handle and the first keyword form a key-value pair in the Hash table.

4. The LRU-based handle management method according to claim 1, characterized in that: Each keyword in the LRU cache has a counter corresponding to it. After the step of determining whether there is a target keyword corresponding to the target object in the LRU cache, the method further includes: If a target keyword corresponding to the target object exists in the LRU cache, the counter corresponding to the target keyword is updated to obtain a new counter value.

5. The LRU-based handle management method according to claim 4, characterized in that: After the step of obtaining the target handle corresponding to the target keyword from the preset Hash table, the method further includes: Add the target keyword to the release list; After the target keyword is released, the counter corresponding to the target keyword is updated to obtain a new counter value.

6. The LRU-based handle management method according to claim 4 or 5, characterized in that: Each key-value pair in the Hash table has a corresponding counter, and the method further includes: When it is detected that the number of objects in the LRU cache is greater than a preset threshold, the second keyword with the smallest counter value is eliminated; The counter of the target key-value pair corresponding to the second keyword in the Hash table is updated to obtain a new reference count value.

7. The LRU-based handle management method according to claim 6, characterized in that: The method further comprises: When the reference count value corresponding to the target key-value pair is equal to 0, the target key-value pair and the handle corresponding to the target key-value pair are deleted from the Hash table.

8. A handle management device based on LRU, characterized in that: The LRU-based handle management device comprises: A first management module, which is used to determine whether there is a target keyword corresponding to the target object in the LRU cache when a target object is detected and the least recently used LRU cache of the thread where the target object is located has been initialized, and the processing mechanism of the LRU cache is a lock-free operation; A second management module, which is used to obtain a target handle corresponding to the target keyword from a preset hash table if it exists; The third management module is used to apply for a target handle for the target object if it does not exist and detects that the target handle corresponding to the target object does not exist in the Hash table, and to create a first keyword in the LRU cache so that the first keyword and the target object form a key-value pair; the target handle is stored in the Hash table so that the target handle and the first keyword form a key-value pair.

9. A handle management device based on LRU, characterized in that: The LRU-based handle management device includes a processor, a memory, and an LRU-based handle management program stored in the memory and executable by the processor, wherein when the LRU-based handle management program is executed by the processor, the steps of the LRU-based handle management method as described in any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores an LRU-based handle management program, wherein when the LRU-based handle management program is executed by a processor, the steps of the LRU-based handle management method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Multi-version parallel operation method and device for COM component

    CN109614165A

  • Method and system for operating archived file by using virtual file handle and storage medium

    CN113886334A