Memory recycling method, device, storage medium, and system
By introducing recycling threads into application threads and using version numbers to manage memory recycling opportunities, the performance consumption problem caused by frequent smart pointer operations during multi-thread access is solved, and efficient memory recycling and application thread task processing speed are achieved.
Patent Information
- Application Number
- PCT/CN2024/087511
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-04-18
- Filing Date
- 2024-04-12
- Publication Date
- 2024-10-24
AI Technical Summary
When multiple application threads access the same memory space, memory recycling through smart pointers in the existing technology requires frequent atomic operations, resulting in large performance consumption and affecting system efficiency.
The recycling thread is introduced to coordinate the recycling requests and release operations of the application thread and the memory space by maintaining a monotonically increasing version number, ensuring that memory recycling is performed when no application thread accesses it, and avoiding the memory recycling process in the application thread.
It reduces the performance overhead during memory recycling, improves the task processing speed of application threads, reduces the burden on application threads, and realizes recycling timing judgment with low performance overhead through version number comparison operations.
Smart Images

Figure CN2024087511_24102024_PF_FP_ABST
Abstract
Description
Memory recycling method, device, storage medium and system
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on April 18, 2023, with application number 202310427928.7 and invention name “Memory Recovery Method, Device, Storage Medium and System”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present invention relates to the field of computer technology, and in particular to a memory recovery method, device, storage medium and system. Background Art
[0003] On electronic devices such as mobile phones, laptops, and servers, when an application is launched, a corresponding process is started. This process allocates its own independent memory block or blocks. Furthermore, a process can launch multiple threads (called application threads) to execute the various tasks required by the application. During task execution, multiple threads may access the same memory block. When this memory block is no longer being accessed, it can be reclaimed to improve memory utilization.
[0004] In view of the above-mentioned situation where multiple application threads access the same memory space, smart pointers are generally used to maintain the life cycle of the memory space. In specific implementation, each time each application thread accesses the memory space, it is necessary to construct and destroy the smart pointer. For example, when an application thread accesses the memory space, it first constructs a smart pointer pointing to the memory space, and performs an increment operation on the value of the atomic counter in the smart pointer. After accessing the memory space, the smart pointer is deconstructed to perform a decrement operation on the value of the atomic counter. Among them, multiple application threads share the atomic counter, and when the atomic counter is reduced to zero, the memory space can be recycled. In this process, atomic operations need to be used to ensure the atomicity between multiple application threads. Atomic operations and the continuous construction and destruction of smart pointers consume a lot of performance.
[0005] Summary of the Invention
[0006] Embodiments of the present invention provide a memory reclamation method, device, storage medium, and system for reducing performance overhead when reclaiming memory.
[0007] In a first aspect, an embodiment of the present invention provides a memory recovery method, which is applied to a recovery thread that reclaims a target memory space commonly accessed by at least one application thread, the method comprising: in response to a recovery request triggered for the target memory space at a first moment, incrementally updating a first version number corresponding to the recovery thread at this time to obtain a second version number; determining the second version number as the version number corresponding to the target memory space; in response to a version number acquisition request triggered after a target application thread in the at least one application thread completes a task at a second moment, sending a third version number corresponding to the recovery thread at this time to the target application thread as the version number corresponding to the target application thread at this time, the target application thread being any one of the at least one application thread; if it is determined that the target memory space meets the recovery conditions based on the version number corresponding to each of the at least one application thread and the second version number corresponding to the target memory space, then recycling the target memory space.
[0008] In a second aspect, an embodiment of the present invention provides a memory recovery device, which is applied to a recovery thread that reclaims a target memory space commonly accessed by at least one application thread, the device comprising: a determination module for, in response to a recovery request triggered for the target memory space at a first moment, incrementally updating a first version number corresponding to the recovery thread at this time to obtain a second version number; and determining the second version number as the version number corresponding to the target memory space; a sending module for, in response to a version number acquisition request triggered after the target application thread in the at least one application thread completes a task at a second moment, sending a third version number corresponding to the recovery thread at this time to the target application thread as the version number corresponding to the target application thread at this time, the target application thread being any one of the at least one application thread; and a recovery module for, if it is determined that the target memory space meets the recovery conditions based on the version number corresponding to each of the at least one application thread and the second version number corresponding to the target memory space, then reclaiming the target memory space.
[0009] In a third aspect, an embodiment of the present invention provides an electronic device comprising: a memory, a processor, and a communication interface; wherein, executable code is stored on the memory, and when the executable code is executed by the processor, the processor executes the memory recovery method as described in the first aspect.
[0010] In a fourth aspect, an embodiment of the present invention provides a non-temporary machine-readable storage medium, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor executes the memory recovery method described in the first aspect.
[0011] In a fifth aspect, an embodiment of the present invention provides a memory recovery method, which is applied to a target application thread in at least one application thread that accesses a target memory space together, the method comprising: triggering a recovery request for the target memory space to the recovery thread at a first moment, so that the recovery thread incrementally updates the first version number corresponding to the recovery thread at this time to obtain a second version number, and determines the second version number as the version number corresponding to the target memory space, and the recovery thread corresponds to the at least one application thread; after executing the task at a second moment, sending a version number acquisition request to the recovery thread, so that the recovery thread sends the third version number corresponding at this time to the target application thread as the version number corresponding to the target application thread at this time, and the target application thread is any one of the at least one application thread; wherein, the version number corresponding to each of the at least one application threads and the second version number corresponding to the target memory space are used to enable the recovery thread to recycle the target memory space when it is determined that the target memory space meets the recovery conditions.
[0012] In a sixth aspect, an embodiment of the present invention provides a memory recovery device, which is applied to a target application thread in at least one application thread that accesses a target memory space together, the device comprising: a sending module, configured to trigger a recovery request for the target memory space to the recovery thread at a first moment, so that the recovery thread incrementally updates the first version number corresponding to the recovery thread at this moment to obtain a second version number, and determines the second version number as the version number corresponding to the target memory space, where the recovery thread corresponds to the at least one application thread; the sending module is further configured to send a version number acquisition request to the recovery thread after completing the task at the second moment, so that the recovery thread sends the third version number corresponding to this moment to the target application thread as the version number corresponding to the target application thread at this moment, where the target application thread is any one of the at least one application threads; a determination module, configured to determine the third version number as the version number corresponding to the target application thread at this moment; wherein the version number corresponding to each of the at least one application threads and the second version number corresponding to the target memory space are configured to enable the recovery thread to recycle the target memory space when it is determined that the target memory space meets the recovery conditions.
[0013] In the seventh aspect, an embodiment of the present invention provides an electronic device, comprising: a memory, a processor, and a communication interface; wherein, executable code is stored on the memory, and when the executable code is executed by the processor, the processor executes the memory recovery method as described in the fifth aspect.
[0014] In an eighth aspect, an embodiment of the present invention provides a non-temporary machine-readable storage medium having executable code stored thereon. When the executable code is executed by a processor of an electronic device, the processor executes the memory recovery method as described in the fifth aspect.
[0015] In a ninth aspect, an embodiment of the present invention provides a memory recovery system, comprising: at least one application thread that accesses a target memory space together, and a recovery thread corresponding to the at least one application; a first application thread in the at least one application thread, configured to trigger a recovery request for the target memory space to the recovery thread at a first moment; a second application thread in the at least one application thread, configured to send a version number acquisition request to the recovery thread after completing a task at a second moment, the second application thread being any one of the at least one application thread; the recovery thread, configured to, in response to the recovery request, incrementally update the first version number corresponding to the recovery thread at this moment to obtain a second version number, and determine the second version number as the version number corresponding to the target memory space; in response to the version number acquisition request, send the third version number corresponding at this moment to the second application thread as the version number corresponding to the second application thread at this moment; and, if it is determined that the target memory space meets the recovery conditions based on the version number corresponding to each of the at least one application thread and the second version number corresponding to the target memory space, the target memory space is recycled. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following is a brief introduction to the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0017] FIG1 is a schematic structural diagram of a memory recycling system provided by an embodiment of the present invention;
[0018] FIG2 is a flow chart of a memory recovery method provided by an embodiment of the present invention;
[0019] FIG3 is a schematic diagram of an application of a memory recycling method provided by an embodiment of the present invention;
[0020] FIG4 is a flow chart of a memory recovery method provided by an embodiment of the present invention;
[0021] FIG5 is a schematic diagram of an application of a memory recycling method provided by an embodiment of the present invention;
[0022] FIG6 is a flow chart of a memory recycling method provided by an embodiment of the present invention;
[0023] FIG7 is a flowchart of another memory recovery method provided by an embodiment of the present invention;
[0024] FIG8 is a schematic diagram of a memory recycling device provided by an embodiment of the present invention;
[0025] FIG9 is a schematic diagram of another memory recycling device provided by an embodiment of the present invention;
[0026] FIG10 is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0027] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention. In addition, the step timing in the following method embodiments is only an example and not a strict limitation.
[0028] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the embodiments of the present invention are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0029] The following describes the terms used in the embodiments of the present invention:
[0030] Process: It is the basic unit for allocating and managing resources during the execution of concurrently executed programs. Simply put, a process refers to an application running in the system.
[0031] A thread is an execution unit within a process. It is contained within a process, and multiple threads can be started concurrently within a process. In the embodiments of the present invention, to distinguish between two different types of threads, they are named application threads and recycling threads. Application threads are threads started by a process to execute the application, and recycling threads are threads used for memory recycling.
[0032] Version number: In the embodiment of the present invention, three types of version numbers are involved: the version number corresponding to the recycling thread, the version number corresponding to the application thread, and the version number corresponding to the memory space. Among them, the recycling thread maintains a monotonically increasing version number, and the version numbers corresponding to the application thread and the memory space are derived from the assignment of the version number of the recycling thread. Therefore, the version number maintained by the recycling thread is called the main version number.
[0033] In actual applications, each application thread in the same process corresponds to the same application program and can be used to perform different tasks. For example, an application thread creates a communication connection, and other application threads can use this communication connection to transmit data.
[0034] When a process corresponding to an application is started, the process will apply for one or more independent memory spaces of its own, and each application thread in the process will access these memory spaces during the execution of tasks. For any of the memory spaces, in an embodiment of the present invention, in order to reduce the performance overhead during memory recycling, an additional recycling thread is introduced into the process to be responsible for the recycling of the memory space applied for by the process, avoiding the execution of the memory recycling process in the application thread, which can reduce the burden on the application thread and improve the application task processing speed of the application thread. In summary, the recycling thread is responsible for ensuring that when the recycling of a certain memory space begins, no application thread is accessing (i.e. reading and writing) this memory space, so as to ensure that this memory space can be released safely. Because if the recycling process is performed when a certain application thread is accessing this memory space, the access will fail and an error will occur.
[0035] To reduce the performance overhead of memory reclamation, in an embodiment of the present invention, the reclaiming thread maintains a monotonically increasing major version number locally. This major version number is used to assign the version number of the application thread and the version number of the target memory space to be reclaimed. This allows the timing of reclaiming the target memory space by comparing the version numbers of the application thread and the target memory space. This version number assignment and comparison operation has relatively low performance overhead. The version number assignment and comparison process will be described in conjunction with the following embodiments.
[0036] In the solution provided by an embodiment of the present invention, a recycling thread is provided corresponding to at least one application thread that commonly accesses a target memory space. When one of the application threads first determines that the target memory space needs to be reclaimed, it triggers a recycling request for the target memory space to the recycling thread. The recycling thread maintains a monotonically increasing major version number. Upon receiving the recycling request, assuming the major version number at that time is the first version number, it incrementally updates the first version number to obtain a second version number. The second version number can then be determined as the version number corresponding to the target memory space. The second version number corresponding to the target memory space can actually serve as a basis for time sequence sorting, reflecting when the recycling request was triggered for the target memory space.
[0037] In addition, every time any of the at least one application thread mentioned above completes a task, it sends a version number acquisition request to the recycling thread to request the main version number of the recycling thread at this time, and assigns its own version number with the main version number obtained. For example, at the second moment, the target application thread completes the task to trigger a version number acquisition request to the recycling thread. Assuming that the main version number corresponding to the recycling thread at this time is the third version number, the third version number is sent to the target application thread as the version number corresponding to the target application thread at this time. If the recycling thread determines at a certain moment that the target memory space meets the recycling condition based on the version number corresponding to each of the at least one application thread mentioned above and the second version number corresponding to the target memory space, the target memory space will start to be recycled, wherein the satisfaction of the recycling condition indicates that the above application threads are not accessing the target memory space when the target memory space starts to be recycled.
[0038] As can be seen from the above scheme, while the target memory space is awaiting reclamation, normal access to it by the application thread is not affected. Whether to initiate reclamation of the target memory space depends solely on the assignment and comparison of version numbers corresponding to the application thread and the target memory space. These operations do not require locking, resulting in minimal performance overhead. Furthermore, the memory reclamation process is relatively slow. By having an additional reclamation thread perform the memory reclamation process, rather than executing it within the application thread, this reduces the burden on the application thread and improves its processing speed.
[0039] Figure 1 is a schematic diagram of the structure of a memory reclamation system provided by an embodiment of the present invention. As shown in Figure 1 , the memory reclamation system includes: at least one application thread that collectively accesses a target memory space, and a reclamation thread corresponding to at least one application. For example, Figure 1 illustrates a scenario in which application threads 1, 2, and 3 collectively access the target memory space.
[0040] As described above, the at least one application thread and the recycling thread may be located in the same process, and the target memory space may be any one of multiple memory spaces applied for by the process.
[0041] The fact that multiple application threads access the target memory space together does not mean that the target memory space is accessed at the same time, but rather that there is a possibility that the target memory space is accessed while each of the application threads is executing a task.
[0042] It is understandable that the access operation of each application thread to the target memory space is actually reading and writing data stored in the target memory space.
[0043] The recycling thread is responsible for recycling the target memory space. Before recycling begins, each application thread can access the target memory space normally. After recycling begins, each application thread can no longer access the target memory space.
[0044] Based on the above system composition, the target memory space recovery process is described in detail below.
[0045] FIG2 is a flow chart of a memory reclamation method provided by an embodiment of the present invention. The memory reclamation method may be executed by the reclamation thread in FIG1 . As shown in FIG2 , the method includes the following steps:
[0046] 201. In response to a recycling request triggered on a target memory space at a first moment, incrementally update a first version number corresponding to the recycling thread at this moment to obtain a second version number.
[0047] 202. Determine the second version number as the version number corresponding to the target memory space.
[0048] 203. In response to a version number acquisition request triggered by the target application thread in at least one application thread at the second moment after completing the task, the third version number corresponding to the recovery thread at this time is sent to the target application thread as the version number corresponding to the target application thread at this time. The target application thread is any one of the at least one application thread.
[0049] 204. If it is determined that the target memory space meets the recycling condition based on the version number corresponding to the at least one application thread and the second version number corresponding to the target memory space, the target memory space is recycled.
[0050] In actual applications, when an application thread among at least one application thread determines at the first moment that the target memory space needs to be reclaimed, a reclaim request for the target memory space will be triggered to the reclaiming thread, and the reclaiming request carries the virtual memory address corresponding to the target memory space.
[0051] It is understandable that when a process applies for memory space, the memory address used is generally a virtual memory address rather than a physical memory address. For example, assuming that a process applies for two memory spaces with virtual memory addresses of 0-100 and 300-400, when it is determined that the target memory space 0-100 needs to be reclaimed, a reclaim request containing the virtual memory address is triggered.
[0052] Optionally, the application thread that triggers the recycling request may be any one of the at least one application thread. It should be noted that, for the target memory space, no matter which application thread triggers the recycling request, it is only triggered once.
[0053] Alternatively, the application thread that triggers the reclaim request may be an application thread among the at least one application thread that has permission to trigger the reclaim request. The application thread with this permission may be determined in advance by a negotiation mechanism between the application threads, or the application thread with this permission may be designated by a process.
[0054] For ease of description, regardless of the above situation, it is assumed that the first application thread in at least one application thread triggers the above recovery request to the recovery thread when determining that the target memory space needs to be recovered, wherein it is assumed that the moment when the recovery request is triggered is the first moment.
[0055] Among them, how the first application thread determines that the target memory space needs to be reclaimed is not specifically limited in the embodiments of the present invention. For example, it is determined to reclaim the target memory space after executing a specific task that will access the target memory space. For example, assuming that application thread 1 creates a communication connection and writes relevant information of the communication connection in the target memory space, application thread 2 and application thread 3 can use the communication connection to transmit data. When transmitting data, the relevant information of the communication connection is read from the target memory space. For example, if the first application thread is application thread 1, application thread 1 can determine that the target memory space needs to be reclaimed when disconnecting the communication connection, thereby triggering the above-mentioned recovery request to the recovery thread at this time (the first moment).
[0056] After receiving the recycling request, the recycling thread determines the main version number updated at this time (assuming it is the first version number), and incrementally updates the first version number to obtain the second version number, and uses the second version number as the version number corresponding to the target memory space, that is, the version number corresponding to the target memory space is set to the second version number.
[0057] For ease of understanding, an example is given in conjunction with Figure 3. As mentioned above, the recycling thread is responsible for updating the main version number maintained locally, which is essentially an incremental serial number, such as starting from 0 or 1, and adding one each time it is updated. For example, assuming that at the first moment (T1 shown in Figure 3) when the recycling thread receives the above-mentioned recycling request, the corresponding first version number is 10, then the second version number obtained after the incremental update is 11 (this is equivalent to adding one to the first version number), and the second version number 11 is used as the version number corresponding to the target memory space, that is, the version number corresponding to the target memory space is set to 11. As shown in Figure 3, optionally, the recycling thread can record the correspondence between the target memory space and the second version number 11 in the set storage space in the memory. In fact, the second version number corresponding to the target memory space is used to reflect when the recycling request for the target memory space is triggered.
[0058] For the above-mentioned at least one application thread, as long as the recycling process of the above-mentioned target memory space has not yet started, then the at least one application thread can normally access the target memory space. That is to say, before the first application thread triggers the recycling request for the target memory space, each application thread can normally access the target memory space. After the first application thread triggers the recycling request for the target memory space, as long as the recycling of the target memory space has not yet started, each application thread can still normally access the target memory space.
[0059] Based on this, in an embodiment of the present invention, any application thread among the above-mentioned at least one application thread (for the convenience of description, it is assumed to be the target application thread), whether before or after the above-mentioned recycling request is triggered, can trigger a version number acquisition request to the recycling thread every time a task is executed to request the main version number of the recycling thread at this time.
[0060] Combined with the example in Figure 3, assuming that the target application thread is application thread 1, it completes the execution of a task at the second moment (T2 shown in the figure) and sends a version number acquisition request to the recycling thread. Assuming that the main version number of the recycling thread at this time is the third version number, and assuming that the value is 11 as shown in the figure, the third version number 11 is sent to application thread 1, and application thread 1 will use the third version number 11 as its own version number assignment: V1=11, where V1 represents the version number corresponding to application thread 1.
[0061] It should be noted that Figure 3 illustrates the situation where the second moment T2 is no earlier than the first moment T1, because the recovery thread updates the major version number to the second version number 11 at moment T1, which means that before that, the major version number of the recovery thread was the first version number 10, which is less than 11. If moment T2 is earlier than moment T1, then the major version number obtained by application thread 1 will be the first version number 10. Moreover, Figure 3 illustrates the situation where the major version number (third version number) corresponding to the recovery thread at moment T2 is the same as the updated major version number (second version number) corresponding to moment T1, that is, before receiving the version number acquisition request triggered by application thread 1 at moment T2, the major version number of the recovery thread was the second version number and was not updated again.
[0062] In addition, in conjunction with the example in FIG3 , it can be understood that, assuming that at some other time after time T1, each application thread in the at least one application thread receives at least one task to be executed, then each application thread triggers a version number acquisition request to the recycling thread after completing a task. If the main version number of the recycling thread at that time still remains the second version number, that is, the third version number corresponding to the recycling thread when the version number acquisition request is received is equal to the second version number updated after receiving the recycling request, then the version number assignment result of each application thread is 11. However, if it is assumed that before the at least one application thread triggers the version number acquisition request, the main version number of the recycling thread has been updated from the second version number to a third version number different from the second version number (for example, from the second version number 11 to the third version number 12), then at this time, each application thread obtains the third version number 12 after issuing the version number acquisition request. Based on this, as shown in Figure 3, assuming that at time T3, application thread 2 receives the third version number 12 after sending a version number acquisition request, then the version number V2 of application thread 2 is assigned to 12 at this time. assuming that at time T4, application thread 3 receives the third version number 12 after sending a version number acquisition request, then the version number V3 of application thread 3 is assigned to 12 at this time, where neither T3 nor T4 is earlier than T2.
[0063] In addition, it should be noted that, as described above, the at least one application thread belongs to the same process, and the process may apply for multiple memory spaces, such as virtual memory addresses in the 0-100 and 300-400 memory spaces. Assuming that the target memory space is the 0-100 memory space, in actual applications, the at least one application thread may not only access the 0-100 memory space when executing a task, but may also access the 300-400 memory space. In this embodiment, the at least one application thread is not limited to sending the version number acquisition request to the recycling thread only after completing a task in the 0-100 memory space. Instead, the at least one application thread sends the version number acquisition request to the recycling thread after completing the task, regardless of which of the two memory spaces the task accesses.
[0064] For any application thread among the at least one application thread mentioned above, after completing a task each time, from its own perspective, it does not know whether there are other tasks to be executed subsequently. Therefore, after completing a task each time, it can be assumed that the target memory space will not be accessed subsequently. Therefore, a version number acquisition request is triggered, and its own version number is assigned with the main version number of the recycling thread obtained in the request to indicate when the application thread ends access to the target memory space.
[0065] For the above-mentioned target memory space, optionally, the recycling thread can periodically determine whether the target memory space should be reclaimed after receiving the recycling request. If it is determined at a certain moment that the target memory space can be reclaimed, the recycling process of the target memory space will be started. After the target memory space is reclaimed, at least one of the above-mentioned application threads will no longer be able to access the target memory space.
[0066] Among them, it is assumed that the recycling thread performs a judgment process at time T5. The judgment process at this time is: according to the version number corresponding to each of the at least one application thread and the second version number corresponding to the target memory space, determine whether the target memory space meets the recycling conditions. If it meets the conditions, the target memory space is recycled. In simple terms, it is to compare the version number corresponding to the target memory space at this time (based on the above description, its version number is the second version number) and the version number corresponding to each of the above application threads at this time to determine whether to start recycling the target memory space at the current time T5. Combined with the example in Figure 3, the second version number corresponding to the target memory space is 11, the version number corresponding to application thread 1 is 11, and the version numbers corresponding to application thread 2 and application thread 3 are 12. Based on the results of these version number assignments, it is determined whether to start recycling the target memory space at time T5.
[0067] In this embodiment, assuming that the target memory space is determined to be reclaimed at time T5, the process of reclaiming the target memory space can be understood as follows: for application threads, virtual memory addresses are used to access memory space. The operating system kernel stores the mapping relationship between virtual memory addresses and physical memory addresses. Reclaiming the target memory space means deleting the virtual memory address corresponding to the target memory space and the mapping relationship between the virtual memory address and the corresponding physical memory address, thereby making the virtual memory address unavailable to these application threads. Specifically, assuming that a process applies for multiple memory spaces when it starts, and the corresponding virtual memory addresses are 0-100, 200-300, 500-600, 800-900, etc., if the memory space corresponding to the virtual memory addresses 0-100 is reclaimed, it means that the above-mentioned application threads in this process can no longer access this memory space.
[0068] Regarding the determination of whether the above recycling conditions are met, in an optional embodiment, if it is determined that the version number corresponding to at least one application thread is greater than the second version number corresponding to the target memory space, it is determined to start recycling the target memory space.
[0069] In this embodiment, to put it simply, the second version number corresponding to the target memory space and the version number corresponding to the at least one application thread at the judgment moment are sorted from small to large. If the second version number corresponding to the target memory space is ranked first, it means that after the recycling request is triggered for the target memory space, the access to the target memory space by each application thread has ended, that is, before the target memory space is recycled, no application thread is accessing the target memory space, and the target memory space can be recycled at this time.
[0070] Continuing with the example in Figure 3, since the second version number of the target memory space is 11, the version number corresponding to application thread 1 at the judgment moment (T5) is 11, and the version numbers corresponding to application thread 2 and application thread 3 are 12. Since the version number 11 of application thread 1 is not greater than the second version number 11 of the target memory space, it is determined that the target memory space cannot be reclaimed at T5. Since the target memory space cannot be reclaimed at this time, if these application threads receive tasks that need to access the target memory space again, they can still access the target memory space normally to complete task processing. The target memory space will not be reclaimed until the version numbers corresponding to each application thread are greater than the second version number corresponding to the target memory space at a certain moment.
[0071] For example, at some point later, application thread 1 completes a task and triggers a version number acquisition request to the recycling thread. Assuming that the main version number of the recycling thread has been updated from the second version number 11 to 13 at this time, the version number corresponding to the application thread will be assigned 13. When judging again (assuming it is time T6), since the second version number 11 corresponding to the target memory space is already smaller than the version number corresponding to each application thread (the version number corresponding to application thread 1 is 13, and the version numbers corresponding to application thread 2 and application thread 3 are 12), the recycling thread determines to start reclaiming the target memory space at time T6.
[0072] In actual applications, there is often such a situation: an application thread in at least one application thread does not receive a task to be executed within a set time (such as 5s, 10s, etc.), that is, the application thread has no task to be executed for a long time and will enter a dormant state. As a result, the version number corresponding to the application thread will not be updated for a long time. In this case, it actually means that the application thread no longer accesses the target memory space. Based on this, if an application thread does not receive a task to be processed within a set time, it can set itself to an inactive state and sleep. Based on this, in another optional embodiment, the recycling thread can obtain the active state information corresponding to at least one application thread at the judgment moment; if it is determined based on the active state information that there is an application thread in an inactive state in at least one application thread, then when it is determined that the target memory space meets the recycling conditions based on the version numbers corresponding to the other application threads except the inactive application thread and the second version number corresponding to the target memory space, the target memory space is recycled.
[0073] In specific implementations, each application thread can record flag information reflecting its activity status in a set storage space in the memory. For example, a flag bit = 1 indicates activity, and a flag bit = 0 indicates inactivity. It is understood that if an application thread wakes up from a dormant state due to receiving a task after setting its corresponding flag bit to 0, the flag bit can be updated to 1.
[0074] At the time of determination, the recycling thread reads the active status of each of the application threads from the aforementioned set storage space in the memory, and then selects the application threads in the active state. Based on the version numbers corresponding to each of these active application threads and the second version number corresponding to the target memory space, it determines whether the recycling condition is met. If so, the target memory space is recycled. The recycling condition determination method at this time can be found in the aforementioned embodiment, i.e., it determines whether the version numbers corresponding to each of these active application threads are all greater than the second version number corresponding to the target memory space. If so, the recycling condition is met; otherwise, the recycling condition is not met.
[0075] In summary, while the target memory space is awaiting reclamation, normal access to it by the application thread is not affected. Whether the target memory space is reclaimed depends solely on the assignment and comparison of version numbers corresponding to the application thread and the target memory space. These operations do not require locking, resulting in minimal performance overhead. Furthermore, the memory reclamation process is relatively slow. By having an additional reclamation thread perform the memory reclamation process, rather than executing it within the application thread, this reduces the burden on the application thread and improves its processing speed.
[0076] FIG4 is a flow chart of a memory recovery method provided by an embodiment of the present invention. As shown in FIG4 , the method includes:
[0077] 401. In response to a recycling request triggered on a target memory space at a first moment, incrementally update a first version number corresponding to the recycling thread at this moment to obtain a second version number.
[0078] 402. Determine the second version number as the version number corresponding to the target memory space.
[0079] 403. In response to a version number acquisition request triggered by the target application thread in at least one application thread at the second moment after completing the task, the third version number corresponding to the recovery thread at this time is sent to the target application thread as the version number corresponding to the target application thread at this time, and the target application thread is any one of the at least one application thread.
[0080] 404. If it is determined that the target memory space does not meet the recycling condition based on the version number corresponding to at least one application thread and the second version number corresponding to the target memory space, the third version number corresponding to the recycling thread is incrementally updated to obtain a fourth version number.
[0081] 405. In response to the version number acquisition request triggered after the target application thread completes the task at the third moment, the fourth version number corresponding to the recycling thread at this moment is sent to the target application thread as the version number corresponding to the target application thread at this moment.
[0082] 406. If it is determined that the target memory space meets the recycling condition based on the version number corresponding to the at least one application thread and the second version number corresponding to the target memory space, the target memory space is recycled.
[0083] This embodiment mainly introduces the processing logic when the recycling thread determines that the target memory space does not meet the recycling condition based on the version number corresponding to at least one application thread and the second version number corresponding to the target memory space.
[0084] For ease of understanding, let's use Figure 5 as an example to illustrate. Suppose there are three application threads that can access the target memory space: application thread 1, application thread 2, and application thread 3. Suppose application thread 1 triggers a target memory space recovery request to the recovery thread at time T1 (the first moment). Suppose the main version number of the recovery thread at this time is the first version number, specifically 10. The first version number is added by one to obtain the second version number: 11. The correspondence between the target memory space and the second version number is recorded.
[0085] Afterwards, assuming that at T2, T3 and T4 (the second moment), the three application threads send version number acquisition requests to the recycling thread after completing their respective tasks. Since the main version number of the recycling thread (the third version number, assumed to be the same as the second version number) has been updated to 11 at this time, the version numbers of these three application threads will all be assigned to 11.
[0086] The recycling thread then determines that the recycling condition is not met based on the version numbers 11 of the three application threads and the second version number 11 corresponding to the target memory space. The recycling thread then increments the third version number by one, resulting in a fourth version number of 12. This means that the recycling thread now updates the major version number. Note that the second version number corresponding to the target memory space is not updated.
[0087] The update of the main version number of the recycling thread at this time will affect the version number requested by subsequent application threads. For example, at the third moment after the second moment, for example, application thread 1 completes a task at time T5 and requests the version number from the recycling thread. At this time, the recycling thread feedback is the fourth version number: 12, and the version number assignment result of application thread 1 is updated from the previous 11 to 12. Similarly, application thread 2 completes a task at time T6 and requests the version number from the recycling thread. At this time, the recycling thread feedback is the fourth version number: 12, and the version number assignment result of application thread 2 is updated from the previous 11 to 12; application thread 3 completes a task at time T7 and requests the version number from the recycling thread. At this time, the recycling thread feedback is the fourth version number: 12, and the version number assignment result of application thread 3 is updated from the previous 11 to 12.
[0088] Afterwards, when the recycling thread determines again, since the version numbers 12 of the three application threads are all greater than the version number 11 corresponding to the target memory space, the recycling condition is met, and it is determined that the target memory space can be recycled at this time.
[0089] As can be seen from the above example, after an application thread triggers a reclaim request for a target memory space, the reclaiming thread may need to make multiple judgments before finding that the target memory space can be reclaimed at a certain time in the future.
[0090] FIG6 is a flow chart of a memory recycling method provided by an embodiment of the present invention. The method is executed by a recycling thread. As shown in FIG6 , the method includes:
[0091] 601. In response to a recycling request triggered by writing the address information of the target memory space into the first queue at a first moment, obtain the address information of the target memory space from the first queue, incrementally update the first version number corresponding to the recycling thread at this time to obtain a second version number, and determine the second version number as the version number corresponding to the target memory space.
[0092] 602. In response to a version number acquisition request triggered by the target application thread in at least one application thread at the second moment after completing the task, the third version number corresponding to the recovery thread at this time is sent to the target application thread as the version number corresponding to the target application thread at this time, and the target application thread is any one of the at least one application thread.
[0093] 603. If it is determined that the target memory space does not meet the recycling conditions based on the version number corresponding to at least one application thread and the second version number corresponding to the target memory space, the address information of the target memory space is written into the second queue, the address information of the target memory space is deleted from the first queue, and the third version number corresponding to the recycling thread is incrementally updated to obtain a fourth version number.
[0094] 604. In response to the version number acquisition request triggered after the target application thread completes the task at the third moment, the fourth version number corresponding to the recycling thread at this moment is sent to the target application thread as the version number corresponding to the target application thread at this moment.
[0095] 605. If it is determined that the target memory space meets the recycling condition based on the version number corresponding to the at least one application thread and the second version number corresponding to the target memory space, the target memory space is recycled.
[0096] In this embodiment, two queues maintained by the recycling thread are introduced: a first queue and a second queue, which are used to mark different states of the target memory space.
[0097] Specifically, as described above, assuming that the first application thread among at least one application thread triggers a target memory space recovery request to the recovery thread at the first moment, specifically, the first application thread can write the address information of the target memory space (i.e., the virtual memory address) into the first queue, and the first queue triggers a corresponding notification to the recovery thread in response to the write event of the address information of the new target memory space. In this way, the recovery thread determines from the first queue based on the notification that the target memory space is written into the first queue, and then performs an update operation on the main version number.
[0098] It can be seen that the first application thread triggers a recycling request to the recycling thread by writing the address information of the target memory space into the first queue.
[0099] The scenario exemplified in the aforementioned embodiment is that when the recycling thread receives a version number acquisition request from any application thread in the at least one application thread at the second moment, the main version number at this moment is the same as the main version number updated at the first moment, that is, the third version number is the same as the second version number. However, in reality, assuming that before receiving the version number acquisition request, the first application thread also initiates a recycling request for another memory space, then the main version number of the recycling thread will be updated from the second version number to the third version number with a different value. For example, if the at least one application thread is a thread within the same process, and the process has applied for multiple memory spaces, a recycling request is triggered for one of the memory spaces at the first moment, and a recycling request is triggered for another memory space at another moment (before the second moment), each recycling request will prompt the update of the main version number of the recycling thread.
[0100] After receiving a version number acquisition request sent by a target application thread at the second moment, assuming that the main version number of the recycled thread is the third version number at this time, the third version number is sent to the target application thread to assign a value to its version number.
[0101] In actual applications, the recycling thread can be configured to perform a judgment process on whether the target memory space meets the recycling conditions after assigning the version number corresponding to the target memory space whenever it receives a recycling request, that is, receives the notification of the address information of the target memory space stored in the above-mentioned first queue.
[0102] If the judgment result is that the target memory space does not meet the recycling conditions, the main version number of the recycling thread is updated once to obtain the fourth version number, and the target memory space is removed from the first queue and written to the second queue. The memory space stored in the second queue is the memory space waiting to be recycled. That is to say, if the target memory space is added to the first queue, a judgment process is performed to determine that the target memory space cannot be recycled, then it is moved into the second queue to wait for recycling. Specifically, based on the setting strategy of querying the second queue, after the target memory space stored in the second queue is judged once or multiple times, it is recycled when it meets the recycling conditions. After recycling, the target memory space is deleted from the second queue.
[0103] Assume that before the next judgment, all or part of the above at least one application thread sends a version number acquisition request to the recycling thread at the third moment, then the recycling thread will send the fourth version number to the corresponding application thread to reassign the version number.
[0104] During the next judgment, assuming that the recycling thread determines that the target memory space meets the recycling condition, it is determined to start recycling the target memory space. After the recycling is completed, the target memory space can be deleted from the second queue.
[0105] As mentioned above, the recycling thread can perform a judgment on whether the memory space written in the first queue and the second queue meets the recycling conditions each time it receives a recycling request. In addition, when it determines that the second queue is not empty and no recycling request is received within the set time, the recycling thread can also determine whether any memory space contained in the second queue meets the recycling conditions based on the address information of the corresponding application threads at this time and the version number corresponding to the any memory space.
[0106] It should be understood that after the virtual memory address of the target memory space is stored in the first queue, on the one hand, the version number corresponding to the target memory space will be updated, and on the other hand, a judgment will be performed to determine whether the recycling conditions are met. If the judgment result is that the recycling conditions are not met, the virtual memory address of the target memory space will be stored in the second queue and wait for subsequent recycling. Then, when the next recycling request is received, or when it is determined that the second queue is not empty and no recycling request is received within the set time, it is equivalent to waking up the recycling thread. The recycling thread will make another judgment on whether the recycling conditions are met. If the judgment result is still that the recycling conditions are not met, it will continue to wait in the second queue for the next recycling. On the contrary, if the recycling conditions are met, it can be directly recycled. This cycle will continue until the second queue is empty. When the second queue is empty, the recycling thread will block and wait for the application thread to push new memory space that needs to be recycled.
[0107] In summary, in this embodiment of the present invention, while the target memory space is awaiting reclamation, normal access to it by the application thread is not affected. Whether to initiate reclamation of the target memory space depends solely on the assignment and comparison of version numbers corresponding to the application thread and the target memory space. These operations do not require locking, resulting in minimal performance overhead. Furthermore, the memory reclamation process is relatively slow. By having an additional reclamation thread complete the memory reclamation process, the application thread can avoid executing the memory reclamation process, reducing the burden on the application thread and improving the application thread's processing speed.
[0108] FIG7 is a flowchart of another memory reclamation method provided by an embodiment of the present invention. The method is applied to at least one application thread that accesses a target memory space together. As shown in FIG7 , the method includes the following steps:
[0109] 701. At the first moment, trigger a recycling request for the target memory space to the recycling thread, so that the recycling thread incrementally updates the first version number corresponding to the recycling thread at this time to obtain a second version number, and determines the second version number as the version number corresponding to the target memory space. The recycling thread corresponds to at least one application thread.
[0110] 702. After completing the task at the second moment, a version number acquisition request is sent to the recycling thread, so that the recycling thread sends the third version number corresponding to this moment to the target application thread as the version number corresponding to the target application thread at this moment. The target application thread is any one of at least one application thread, wherein the version number corresponding to at least one application thread and the second version number corresponding to the target memory space are used to enable the recycling thread to recycle the target memory space when it determines that the target memory space meets the recycling conditions.
[0111] As described above, the application thread that triggers the recycling request may be a specific application thread among the at least one application thread, or may be any application thread among the at least one application thread.
[0112] As described above, the method further includes: if the target application thread does not receive a task to be executed within a set time period, setting itself to an inactive state and then sleeping. The inactive state enables the recycling thread to determine whether the target memory space meets the recycling condition based on the version numbers corresponding to the application threads other than the inactive application thread and the second version number corresponding to the target memory space.
[0113] The execution process of the application thread in this embodiment will not be further described, and reference may be made to the description in other aforementioned embodiments.
[0114] The memory recycling device of one or more embodiments of the present invention will be described in detail below. Those skilled in the art will appreciate that these devices can be constructed using commercially available hardware components and configured according to the steps taught in this solution.
[0115] Figure 8 is a schematic diagram of a memory recovery device provided by an embodiment of the present invention. The device is applied to a recovery thread that reclaims a target memory space commonly accessed by at least one application thread. As shown in Figure 8, the device includes: a determination module 81, a sending module 82 and a recovery module 83.
[0116] The determination module 81 is used to respond to the recycling request triggered on the target memory space at the first moment, incrementally update the first version number corresponding to the recycling thread at this time to obtain a second version number; and determine the second version number as the version number corresponding to the target memory space.
[0117] The sending module 82 is used to respond to the version number acquisition request triggered after the target application thread in at least one application thread completes the task at the second moment, and send the third version number corresponding to the recovery thread at this time to the target application thread as the version number corresponding to the target application thread at this time. The target application thread is any one of the at least one application thread.
[0118] The recycling module 83 is configured to recycle the target memory space if it is determined that the target memory space meets the recycling condition based on the version number corresponding to at least one application thread and the second version number corresponding to the target memory space.
[0119] Optionally, the recycling module 83 is specifically configured to: if it is determined that the version number corresponding to at least one application thread is greater than the second version number corresponding to the target memory space, reclaim the target memory space.
[0120] Optionally, the recycling module 83 is specifically used to: obtain the activity status information corresponding to at least one application thread; if it is determined based on the activity status information that there is an application thread in an inactive state in at least one application thread, then when it is determined that the target memory space meets the recycling conditions based on the version numbers corresponding to the other application threads except the application thread in the inactive state and the second version number corresponding to the target memory space, the target memory space is recycled.
[0121] Optionally, the device also includes: an update module, which is used to incrementally update the third version number corresponding to the recovery thread to obtain a fourth version number if it is determined that the target memory space does not meet the recovery conditions based on the version number corresponding to at least one application thread and the second version number corresponding to the target memory space.
[0122] Optionally, the sending module 82 is also used to respond to the version number acquisition request triggered after the target application thread completes the task at the third moment, and send the fourth version number corresponding to the recycling thread at this time to the target application thread as the version number corresponding to the target application thread at this time.
[0123] Optionally, the determination module 81 is specifically used to: in response to a recycling request triggered by writing the address information of the target memory space into the first queue at a first moment, obtain the address information of the target memory space from the first queue, incrementally update the first version number corresponding to the recycling thread at this time to obtain a second version number, write the address information of the target memory space into the second queue for storing memory space waiting to be recycled, and delete the address information of the target memory space from the first queue.
[0124] Optionally, the recycling module 83 is specifically used to: when a recycling request is received, or when it is determined that the second queue is not empty and no recycling request is received within a set time period, for the address information of any memory space contained in the second queue, determine whether any memory space meets the recycling conditions based on the version numbers corresponding to the corresponding application threads at this time and the version numbers corresponding to any memory space.
[0125] The device shown in FIG8 can execute the steps of recycling thread execution in the aforementioned embodiment. The detailed execution process and technical effects are described in the aforementioned embodiment and will not be repeated here.
[0126] Figure 9 is a schematic diagram of another memory recovery device provided by an embodiment of the present invention. The device is applied to a target application thread in at least one application thread that accesses a target memory space together. As shown in Figure 9, the device includes: a sending module 91 and a module 92.
[0127] The sending module 91 is used to trigger a recycling request for the target memory space to the recycling thread at the first moment, so that the recycling thread incrementally updates the first version number corresponding to the recycling thread at this time to obtain a second version number, and determines the second version number as the version number corresponding to the target memory space. The recycling thread corresponds to at least one application thread.
[0128] The sending module 91 is also used to send a version number acquisition request to the recovery thread after completing the task at the second moment, so that the recovery thread sends the third version number corresponding to this time to the target application thread as the version number corresponding to the target application thread at this time, and the target application thread is any one of at least one application thread.
[0129] Determination module 92 is used to determine the third version number as the version number corresponding to the target application thread at this time; wherein, the version number corresponding to at least one application thread and the second version number corresponding to the target memory space are used to enable the recovery thread to recycle the target memory space when it is determined that the target memory space meets the recovery conditions.
[0130] Optionally, the device also includes: a setting module, which is used to set itself to an inactive state and then sleep if no task to be executed is received within a set time period; the inactive state enables the recovery thread to determine whether the target memory space meets the recovery conditions based on the version numbers corresponding to other application threads except the application thread in the inactive state and the second version number corresponding to the target memory space.
[0131] The device shown in FIG9 can execute the steps of application thread execution in the aforementioned embodiment. The detailed execution process and technical effects are described in the aforementioned embodiment and will not be repeated here.
[0132] FIG10 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. As shown in FIG10 , the electronic device may include: a processor 21, a memory 22, and a communication interface 23. The memory 22 stores executable code, which, when executed by the processor 21, causes the processor 21 to execute the memory reclamation method in the aforementioned embodiment.
[0133] In addition, an embodiment of the present invention provides a non-transitory machine-readable storage medium, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor executes the memory recovery method in the aforementioned embodiment.
[0134] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separate. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Those skilled in the art can understand and implement the present invention without inventive effort.
[0135] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by adding a necessary general hardware platform, and of course can also be implemented by a combination of hardware and software. Based on this understanding, the above technical solution, or the part that contributes to the prior art, can be embodied in the form of a computer product. The present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0136] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A memory recovery method, It is characterized in that A reclaiming thread is applied to reclaim a target memory space commonly accessed by at least one application thread, the method comprising: In response to a recycling request triggered on the target memory space at a first moment, incrementally updating a first version number corresponding to the recycling thread at this moment to obtain a second version number; Determine the second version number as the version number corresponding to the target memory space; In response to a version number acquisition request triggered by a target application thread in the at least one application thread at the second moment after executing a task, sending a third version number corresponding to the recycling thread at this time to the target application thread as the version number corresponding to the target application thread at this time, the target application thread being any one of the at least one application thread; If it is determined that the target memory space meets the recycling condition according to the version number corresponding to each of the at least one application thread and the second version number corresponding to the target memory space, the target memory space is recycled.
2. The method according to claim 1, It is characterized in that If it is determined that the target memory space meets the recycling condition according to the version number corresponding to each of the at least one application thread and the second version number corresponding to the target memory space, recycling the target memory space includes: If it is determined that the version number corresponding to each of the at least one application thread is greater than the second version number corresponding to the target memory space, the target memory space is reclaimed.
3. The method according to claim 1, It is characterized in that If it is determined that the target memory space meets the recycling condition according to the version number corresponding to each of the at least one application thread and the second version number corresponding to the target memory space, recycling the target memory space includes: Obtaining activity status information corresponding to each of the at least one application threads; If it is determined based on the active status information that there is an inactive application thread among the at least one application thread, then when it is determined that the target memory space meets the recycling conditions based on the version numbers corresponding to the other application threads except the inactive application thread and the second version number corresponding to the target memory space, the target memory space is recycled.
4. The method according to claim 1, It is characterized in that The method further comprises: If it is determined that the target memory space does not meet the recycling condition based on the version number corresponding to each of the at least one application thread and the second version number corresponding to the target memory space, the third version number corresponding to the recycling thread is incrementally updated to obtain a fourth version number.
5. The method according to claim 4, It is characterized in that The method further comprises: In response to the version number acquisition request triggered after the target application thread completes the task at the third moment, the fourth version number corresponding to the recycling thread at this time is sent to the target application thread as the version number corresponding to the target application thread at this time.
6. The method according to claim 4, It is characterized in that In response to the recycling request triggered on the target memory space at the first moment, incrementally updating the first version number corresponding to the recycling thread at this time to obtain the second version number, comprises: In response to a recycling request triggered by writing the address information of the target memory space into the first queue at a first moment, obtaining the address information of the target memory space from the first queue, and incrementally updating the first version number corresponding to the recycling thread at this time to obtain a second version number; If it is determined that the target memory space does not meet the recycling condition according to the version number corresponding to each of the at least one application thread and the second version number corresponding to the target memory space, the method further includes: The address information of the target memory space is written into a second queue for storing memory spaces waiting to be reclaimed, and the address information of the target memory space is deleted from the first queue.
7. The method according to claim 6, It is characterized in that The method further comprises: When a recycling request is received, or it is determined that the second queue is not empty and no recycling request is received within the set time, for the address information of any memory space contained in the second queue, determine whether any memory space meets the recycling conditions based on the version numbers corresponding to the corresponding application threads at this time and the version number corresponding to any memory space.
8. A memory recycling method, It is characterized in that The method is applied to a target application thread in at least one application thread that accesses a target memory space together, and comprises: triggering a reclaim request for the target memory space to a reclaim thread at a first moment, so that the reclaim thread incrementally updates a first version number corresponding to the reclaim thread at this time to obtain a second version number, and determines the second version number as the version number corresponding to the target memory space, the reclaim thread corresponding to the at least one application thread; After completing the task at the second moment, sending a version number acquisition request to the recycling thread, so that the recycling thread sends the third version number corresponding to this moment to the target application thread as the version number corresponding to this moment of the target application thread, wherein the target application thread is any one of the at least one application thread; The version number corresponding to each of the at least one application thread and the second version number corresponding to the target memory space are used to enable the recycling thread to recycle the target memory space when determining that the target memory space meets the recycling condition.
9. The method according to claim 8, It is characterized in that The method further comprises: If no tasks to be executed are received within the set time, the system will be set to sleep after being inactive. The inactive state enables the recovery thread to determine whether the target memory space meets the recovery condition according to the version numbers corresponding to the other application threads except the application thread in the inactive state and the second version number corresponding to the target memory space.
10. An electronic device, It is characterized in that include: A memory, a processor, and a communication interface; wherein the memory stores executable code, and when the executable code is executed by the processor, the processor executes the memory recovery method as described in any one of claims 1 to 7, or executes the memory recovery method as described in claim 8 or 9.
11. A non-transitory machine-readable storage medium, It is characterized in that The non-temporary machine-readable storage medium stores executable code, and when the executable code is executed by a processor of an electronic device, the processor executes the memory recovery method as described in any one of claims 1 to 7, or executes the memory recovery method as described in claim 8 or 9.
12. A memory recycling system, It is characterized in that include: at least one application thread that accesses the target memory space together, and a recycling thread corresponding to the at least one application program; A first application thread among the at least one application thread is used to trigger a recycling request for the target memory space to the recycling thread at a first moment; A second application thread in the at least one application thread is used to send a version number acquisition request to the recycling thread after completing the task at the second moment, and the second application thread is any one of the at least one application thread; The recycling thread is used to respond to the recycling request, incrementally update the first version number corresponding to the recycling thread at this time to obtain a second version number, and determine the second version number as the version number corresponding to the target memory space; In response to the version number acquisition request, sending the third version number corresponding to the current time to the second application thread as the version number corresponding to the second application thread at the current time; And, if it is determined that the target memory space meets the recycling condition according to the version number corresponding to each of the at least one application thread and the second version number corresponding to the target memory space, the target memory space is recycled.
13. The system according to claim 12, It is characterized in that The first application thread is an application thread having permission to trigger a recycling request among the at least one application thread.
Citation Information
Patent Citations
Memory management method and device, storage medium and electronic equipment
CN111078406A
Memory allocation method and device, storage medium and electronic equipment
CN111475299A
Memory recovery method and device
CN115421912A
Memory recovery method, device, storage medium and system
CN116303117A
Method and apparatus for reading data, electronic device and storage medium
US20230012881A1
