Memory recovery control method and related apparatus
By detecting the locked state of the target page and utilizing candidate worker threads to perform memory reclamation operations, the problem of low memory reclamation efficiency in electronic devices is solved, improving memory reclamation efficiency and optimizing user experience.
Patent Information
- Application Number
- CN202211023280.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-25
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2042-08-25
AI Technical Summary
In existing technologies, electronic devices suffer from inefficiency during memory reclamation, leading to a decline in user experience.
By detecting whether the target page is locked, if it is locked, a candidate worker thread is determined from the thread pool, and the target page is added to the shared linked list. The candidate worker thread is then used to perform the reclamation operation, thus avoiding the memory reclamation process being blocked due to page lock contention.
It improves memory reclamation efficiency, optimizes user experience, reduces lag and waiting time during page reclamation, and lowers application frame drop rate.
Smart Images

Figure CN115373845B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of communication technology, specifically relating to a memory reclamation control method and related apparatus. Background Technology
[0002] The smoothness of electronic devices has become a necessary factor for consumers, and memory performance is particularly important. However, the memory demands of applications are increasing daily; for example, a single large mobile game may occupy 2GB of memory. Therefore, memory reclamation technology is crucial. Currently, however, electronic devices still suffer from low memory reclamation efficiency, impacting the user experience. Summary of the Invention
[0003] This application provides a memory reclamation control method and related apparatus to improve memory reclamation efficiency.
[0004] In a first aspect, embodiments of this application provide a memory reclamation control method, the method comprising:
[0005] Configure the first worker thread as the original thread that needs to perform the reclamation operation on the target pages to be reclaimed in memory;
[0006] When the target page is detected to be a locked page, a candidate worker thread in the thread pool that can perform the recycling operation is determined.
[0007] If available space is detected in the shared linked list, the target page is added to the shared linked list, which is a linked list that can be called by the first worker thread and / or the candidate worker thread.
[0008] The recycling operation is performed by the second worker thread among the candidate worker threads.
[0009] Secondly, embodiments of this application provide an electronic device including a processor, a memory, and one or more programs, the one or more programs being stored in the memory and configured to be executed by the processor, the programs including instructions for performing the steps in the first aspect of embodiments of this application.
[0010] Thirdly, embodiments of this application provide a memory reclamation control device, the device comprising:
[0011] A configuration unit is used to configure the first worker thread as the original thread that needs to perform a reclamation operation on the target page to be reclaimed in memory; a determination unit is used to determine a candidate worker thread in the thread pool that can perform the reclamation operation when the page type of the target page is detected to be a locked page; an addition unit is used to add the target page to the shared linked list if available space is detected in the shared linked list, wherein the shared linked list refers to a linked list that can be called by the first worker thread and / or the candidate worker thread; and an execution unit is used to execute the reclamation operation through the second worker thread among the candidate worker threads.
[0012] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program / instructions stored thereon, which, when executed by a processor, implement the steps in the first aspect of embodiments of this application.
[0013] Fifthly, embodiments of this application provide a computer program product, wherein the computer program product includes a non-transitory computer-readable storage medium storing a computer program, the computer program being operable to cause a computer to perform some or all of the steps described in the first aspect of embodiments of this application.
[0014] As can be seen from this embodiment, before the electronic device enters the first worker thread to begin the recycling operation on the target page, it first checks whether the page is locked. If the page is locked, it determines a worker thread capable of performing the recycling operation from the thread pool as a candidate worker thread and checks whether the shared linked list is full. If the shared linked list is not full, it adds the target page to the shared linked list, and the recycling operation is performed by the second worker thread among the candidate worker threads. This avoids the memory recycling process being blocked due to page lock contention, effectively improving memory recycling efficiency and optimizing the user experience. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 This is a structural block diagram of an electronic device provided in an embodiment of this application;
[0017] Figure 2 This is a flowchart illustrating a memory reclamation control method provided in an embodiment of this application;
[0018] Figure 3This is a schematic diagram of a preset mapping relationship set provided in an embodiment of this application;
[0019] Figure 4 This is a flowchart illustrating another memory reclamation control method provided in an embodiment of this application;
[0020] Figure 5a This is a functional unit block diagram of a memory reclamation control device provided in an embodiment of this application;
[0021] Figure 5b This is a block diagram of the functional units of another memory reclamation control device provided in the embodiments of this application. Detailed Implementation
[0022] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0023] The terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.
[0024] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0025] The following is a brief introduction to the relevant terminology used in this application.
[0026] Flags: Defined by the flags member of the page descriptor (struct page) data structure, these flags indicate the page type of a memory page, such as a locked page or a page that needs to be migrated. For example, when the flag is set to PG_locked, it indicates that the memory page is a locked page.
[0027] The Least Recently Used (LRU) list is a doubly linked list in the Linux operating system, consisting of an active LRU list and an inactive LRU list. It's used to let the operating system know which pages are the least recently used memory pages for reclamation. The least recently used memory pages are moved one by one to the end of the inactive LRU list, and memory reclamation begins from the end of the inactive LRU list.
[0028] Currently, when electronic devices reclaim memory pages, they need to lock the page first and then perform a series of operations such as reclamation. However, if the page has been locked by another process while holding the page lock, the reclamation process must wait for the other process to release the lock before it can hold the lock again, which can lead to process blockage, resulting in untimely memory reclamation, reduced memory reclamation efficiency, and greatly affecting the smoothness of electronic devices and the user experience.
[0029] To address the aforementioned problems, embodiments of this application provide a memory reclamation control method and related apparatus. Please refer to... Figure 1 , Figure 1 This is a structural block diagram of an electronic device provided in an embodiment of this application. For example... Figure 1 As shown, the electronic device 10 may include one or more of the following components: a processor 11 and a memory 12 coupled to the processor 11, wherein the memory 12 may store one or more computer programs, which may be configured to implement the methods described in the embodiments below when executed by one or more processors 11. The electronic device may be a mobile terminal, a tablet computer, a laptop computer, or a wearable smart device.
[0030] Processor 11 may include one or more processing cores. Processor 11 connects to various parts within the electronic device 10 using various interfaces and lines, and performs various functions and processes data of the electronic device 10 by running or executing instructions, programs, code sets, or instruction sets stored in memory 12, and by calling data stored in memory 12. Optionally, processor 11 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). Processor 11 may integrate one or more of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the displayed content; and the modem handles wireless communication. It is understood that the modem may also not be integrated into processor 11 and may be implemented separately using a communication chip.
[0031] The memory 12 may include random access memory (RAM) or read-only memory (ROM). The memory 12 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 12 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described above. The data storage area may also store data created by the electronic device 10 during use.
[0032] It is understood that the electronic device 10 may include more or fewer structural elements than those shown in the above block diagram, such as a power module, physical buttons, a Wi-Fi module, a speaker, a Bluetooth module, sensors, etc., without limitation.
[0033] The following describes a memory reclamation control method provided by an embodiment of this application.
[0034] Please see Figure 2 , Figure 2 This is a flowchart illustrating a memory reclamation control method provided in an embodiment of this application. The memory reclamation control method is applied to, for example... Figure 1 In the electronic device 10, such as Figure 2As shown, the memory reclamation control method includes:
[0035] Step 201: Configure the first worker thread as the original thread that needs to perform the reclamation operation on the target pages to be reclaimed in memory.
[0036] The page to be reclaimed can be a memory page at the tail of the inactive LRU list, or a memory page that needs to be reclaimed immediately as specified by the upper-layer application. There is no single limitation here.
[0037] Step 202: When the target page is detected to be a locked page, determine the candidate worker threads in the thread pool that can perform the recycling operation.
[0038] The worker threads in the thread pool are all worker threads other than the first worker thread, including candidate worker threads that can perform recycling operations.
[0039] If the target page is detected as an unlocked page, the recycling operation is performed on the target page through the first worker thread. Since the target page is detected as an unlocked page, it indicates that there is no page lock contention issue during the recycling process. Therefore, choosing to perform the recycling operation through the original thread, i.e., the first worker thread, can save redundant steps and improve the efficiency of memory recycling.
[0040] Step 203: If available space is detected in the shared linked list, the target page is added to the shared linked list.
[0041] The shared linked list refers to a linked list that can be invoked by the first worker thread and / or the candidate worker thread.
[0042] If no available space is detected in the shared linked list, the recycling operation is performed on the target page through the first worker thread. Since the shared linked list is full and cannot receive the target page, the target page can only undergo the recycling process in the first worker thread, waiting for other operations to release the page lock before recycling it while holding the lock.
[0043] Step 204: The recycling operation is performed by the second worker thread among the candidate worker threads.
[0044] As can be seen in this example, before the electronic device enters the target page and the first worker thread begins the reclamation operation, it first checks whether the page is locked. If the page is locked, it determines a worker thread from the thread pool that can perform the reclamation operation as a candidate worker thread and checks whether the shared linked list is full. If the shared linked list is not full, the target page is added to the shared linked list, and the reclamation operation is performed by the second worker thread from the candidate worker threads. This avoids the memory reclamation process being blocked due to page lock contention, effectively improving memory reclamation efficiency and optimizing the user experience.
[0045] In one possible example, detecting that the target page is a locked page includes: detecting the content information carried by the flag of the target page, wherein the content information is used to characterize that the target page is a locked page.
[0046] The electronic device can determine the page type by reading the flag bit of the target page to detect the content information it carries. Specifically, when the electronic device detects that the content information carried by the flag bit of the target page is PG_locked, it indicates that the target page is a locked page. If the first worker thread continues to perform the reclamation operation in this case, a page lock contention will occur. It should be noted that if the content information carried by the flag bit of the target page is not PG_locked, it indicates that the target page is an unlocked page, and the first worker thread will perform the reclamation operation in this case.
[0047] As can be seen in this example, the electronic device determines that the target page has been locked by other operations by detecting that the content information carried by the flag bit of the target page is the content information used to indicate that the target page is a locked page, thereby improving the flexibility of the electronic device.
[0048] In one possible example, detecting that the target page is a locked page includes: calling an attempt to hold the lock function to perform page type detection on the target page, obtaining an execution result, the execution result including successful lock holding attempt and failed lock holding attempt; if the execution result is a failed lock holding attempt, then the target page is detected as a locked page.
[0049] The function that attempts to acquire the lock can be the `trylock_page()` function. Specifically, the `trylock_page()` function uses `test_and_set_bit_lock()` to attempt to set the `PG_locked` flag in the `flags` property of the page descriptor (struct page) corresponding to the target page, and returns the original value of the flag. If the current process calls `trylock_page()` and returns `false` (the lock acquisition attempt failed), it means that another process has already locked the target page, i.e., the target page is in a locked state. It should be noted that if the current process calls `trylock_page()` and returns `true` (the lock acquisition attempt succeeded), it indicates that the target page is an unlocked page, and in this case, the first worker thread performs the reclamation operation.
[0050] As can be seen in this example, the electronic device detects that the target page is a locked page by calling the attempt to hold the lock function, which improves the processing efficiency of the electronic device.
[0051] In one possible example, determining the candidate worker threads in the thread pool that can perform the recycling operation includes: querying a preset mapping set to determine the candidate worker threads in the thread pool that can perform the recycling operation.
[0052] The thread pool includes multiple worker threads, each corresponding to a different thread type. The thread type indicates the type of operation performed by the worker thread. A preset mapping set includes the correspondence between the worker threads and their respective thread types. Specifically, by using the thread type as the lookup identifier and querying the preset mapping set, candidate worker threads can be identified. For example, as shown... Figure 3 As shown, Figure 3 This is a schematic diagram of a preset mapping relationship set provided in an embodiment of this application. In addition to the first worker thread, there are five worker threads in the thread pool. The thread types corresponding to threads 1, 4, and 5 are other operations, and the thread types corresponding to threads 2 and 3 are recycling operations. That is, threads 2 and 3 are candidate worker threads that can perform recycling operations.
[0053] As can be seen, in this example, the electronic device determines the working thread that can perform the recycling operation by querying a preset set of mapping relationships, thereby improving the processing efficiency of the electronic device.
[0054] In one possible example, if available space is detected in the shared linked list, adding the target page to the shared linked list includes: calling a caching function to add the target page to the reclamation space of the cache space corresponding to the shared linked list, the cache space including the reclamation space, the reclamation space being used to indicate memory pages to be reclaimed; and calling a callback function to add the set of pages to be reclaimed in the reclamation space to the shared linked list.
[0055] The shared linked list can be an LRU linked list within the worker thread performing the reclamation operation. According to the Linux kernel principles, when a new page is added to the LRU linked list, it must first be added to the corresponding LRU cache. For a shared linked list, the target page is the new page; therefore, when adding the target page to the shared linked list, it must first be added to the corresponding LRU cache. Specifically, the cache function can be the `__lru_cache_add()` function, which adds the target page to the CPU's `lru_add_pvec` cache. The cache space is divided into multiple spaces, including a reclamation space for storing pages to be reclaimed. When a page to be reclaimed is added to the cache space, it is automatically allocated to the reclamation space to distinguish the page type later. When a memory page needs to be added to the linked list, this can be achieved by calling a callback function. Specifically, the callback function can be `move_fn`. In the specific application scenario of adding a new page from the LRU cache to the LRU linked list, the specific expression of `move_fn` is `__pagevec_lru_add_fn()`. In another embodiment, when the LRU cache is full, the system will automatically add the set of pages to be reclaimed to the linked list for memory reclamation to avoid cache space blockage.
[0056] As can be seen in this example, the electronic device divides the cache space into multiple spaces, including a reclamation space to store pages to be reclaimed. This makes it easy to distinguish the memory pages that need to be reclaimed, thus improving the efficiency of memory reclamation.
[0057] In one possible example, the step of performing the recycling operation through a second worker thread among the candidate worker threads includes: retrieving the set of pages to be recycled from the shared linked list; selecting the target page from the set of pages to be recycled according to the order number in which the target page was added to the recycling space; and calling a lock-holding function through the second worker thread, the lock-holding function performing the following steps: if the page type of the target page is a locked page, then performing a locking operation on the target page when the type of the target page changes from a locked page to an unlocked page; if the page type of the target page is an unlocked page, then performing a locking operation on the target page; if it is detected that the target page meets the recycling conditions, then recycling the target page, the recycling conditions meaning that the target page does not have user access requirements; if it is detected that the target page does not meet the recycling conditions, then performing an unlocking operation on the target page and returning it to the file system.
[0058] In this example, when worker threads perform reclamation operations, the reclamation process for memory pages in the LRU list starts from the tail of the inactive LRU list. Therefore, under normal circumstances, processing the set of pages to be reclaimed in the shared list only requires processing from the tail to the head. However, in some special application scenarios, such as targeted reclamation of target pages, when the upper-layer application issues an instruction to immediately reclaim a target page, it is necessary to select the target page from the set of pages to be reclaimed and place the target page with the highest reclamation priority. In this example, the target page has a sequential number when it is added to the reclamation space, indicating which number of the memory page added to the reclamation space it is. The target page can be selected from the set of pages to be reclaimed based on the sequential number, and then the second worker thread performs the reclamation operation on the target page.
[0059] For example, the lock-holding function can be the `lock_page()` function. The system uses `lock_page()` to request a page lock on a memory page. If the page lock is held by another process, the system will sleep and wait until the other process unlocks its page lock before locking it again. After locking the target page, the LRU (Least Recently Used) algorithm is used to determine whether the target page truly needs to be reclaimed, i.e., whether the page no longer has user access needs. If the algorithm indicates that the page does need to be reclaimed, it is reclaimed, including removing all mappings of the page frame corresponding to the page. If the algorithm indicates that the page still has user access needs and does not need to be reclaimed, the page is unlocked and returned to the file system. Specifically, using the LRU algorithm to determine whether a target page meets the reclamation criteria can be done by calling the page reclamation check function `page_check_references()`.
[0060] It should be noted that since the principle and process of the recycling operation performed by the worker thread are the same, the steps of performing the recycling operation by the first worker thread in this embodiment are substantially the same as the steps after filtering out the target page in performing the recycling operation by the second worker thread in this embodiment. These steps include: calling a lock-holding function through the first worker thread, whereby the lock-holding function performs the following steps: if the target page's page type is a locked page, then when the target page's type changes from locked to unlocked, a locking operation is performed on the target page; if the target page's page type is an unlocked page, then a locking operation is performed on the target page; if the target page is detected to meet the recycling conditions, then the target page is recycled, where the recycling conditions refer to the target page not having user access requirements; if the target page is detected to not meet the recycling conditions, then an unlocking operation is performed on the target page and it is returned to the file system.
[0061] As can be seen in this example, the electronic device selects the target page from the set of pages to be reclaimed by sequential numbering, then locks the target page by the second worker thread, and finally selects whether to reclaim the page based on the user's usage needs of the target page, thus avoiding the reclamation of pages that do not need to be reclaimed, improving memory reclamation efficiency and system reliability.
[0062] In one possible example, before performing the recycling operation via the second worker thread among the candidate worker threads, the method further includes: if the candidate worker thread is a single worker thread, determining the candidate worker thread as the second worker thread for performing the recycling operation; if the candidate worker thread includes multiple worker threads, determining any one of the candidate worker threads as the second worker thread.
[0063] For example, when the number of worker threads in the thread pool is... Figure 3 In the scenario shown, where there are multiple candidate worker threads, any one of them is selected as the second worker thread. That is, either thread 2 or thread 3 can be used as the second worker thread to perform the recycling operation. If there is only one candidate worker thread in the thread pool, that thread is selected as the second worker thread.
[0064] As can be seen in this example, the electronic device identifies the second worker thread among the candidate worker threads so that the recycling operation can be performed through the second worker thread, thereby improving the stability and processing efficiency of the system.
[0065] The processing flow of this application will be described below through a specific embodiment.
[0066] Please see Figure 4 , Figure 4 This is a flowchart illustrating another memory reclamation control method provided in this application embodiment, including the following process:
[0067] Step 401: Traverse the pages in memory that need to be reclaimed;
[0068] Step 402: Configure the first worker thread as the original thread;
[0069] Step 403: Determine whether the page type of the target page to be reclaimed is a locked page;
[0070] If so, proceed to step 404;
[0071] If not, proceed to step 409;
[0072] Step 404: Determine the candidate worker threads in the thread pool that can perform the recycling operation;
[0073] Step 405: Determine if there is available space in the shared linked list;
[0074] If so, proceed to step 406;
[0075] If not, proceed to step 409;
[0076] Step 406: Add the target page to the shared list;
[0077] Step 407: Retrieve the target page from the shared list;
[0078] Step 408: Perform the page locking operation through the second worker thread among the candidate worker threads, and then proceed to step 410;
[0079] Step 409: Perform a page locking operation through the first worker thread, and then proceed to step 410;
[0080] Step 410: Determine if the page meets the recycling criteria;
[0081] If so, proceed to step 413;
[0082] If not, proceed to step 411;
[0083] Step 411: Perform a page unlock operation on the target page;
[0084] Step 412: Put the target page back into the file system, and then execute step 401 to start the reclamation process of the next memory page;
[0085] Step 413, reclaim the target page;
[0086] Step 414: Perform a page unlock operation on the target page, and the process ends.
[0087] As can be seen, in this embodiment, the electronic device differentiates and selects different worker threads to perform the recycling operation on the target page by detecting the page type of the target page and determining the available space of the shared linked list. This optimizes the problem of page recycling process blocking caused by other application processes occupying page locks during the target page recycling process to a certain extent, thereby improving memory recycling efficiency. Experimental results show that when the optimization scheme of this embodiment is applied to Android mobile terminals, it can reduce the page lock waiting time during the page recycling process and reduce the application frame drop rate by 10%.
[0088] For embodiments consistent with those shown above, please refer to... Figure 5a , Figure 5a This is a functional unit block diagram of a memory reclamation control device provided in an embodiment of this application, such as... Figure 5a As shown, the memory reclamation control device 50 includes: a configuration unit 501, configured to configure a first worker thread as the original thread that needs to perform a reclamation operation on a target page to be reclaimed in memory; a determination unit 502, configured to determine a candidate worker thread in the thread pool that can perform the reclamation operation when the page type of the target page is detected to be a locked page; an addition unit 503, configured to add the target page to the shared linked list if available space is detected in the shared linked list, wherein the shared linked list refers to a linked list that can be called by the first worker thread and / or the candidate worker thread; and an execution unit 504, configured to execute the reclamation operation through a second worker thread among the candidate worker threads.
[0089] In one possible example, regarding the detection that the target page is a locked page, the determining unit 502 is specifically configured to: detect the content information carried by the flag bit of the target page, the content information being used to characterize that the target page is a locked page.
[0090] In one possible example, regarding the detection that the target page's page type is a locked page, the determining unit 502 is specifically configured to: call the attempt to hold the lock function to perform page type detection on the target page, and obtain an execution result, the execution result including successful attempt to hold the lock and failed attempt to hold the lock; if the execution result is a failed attempt to hold the lock, then the target page's page type is detected as a locked page.
[0091] In one possible example, the thread pool includes multiple worker threads, which correspond to multiple thread types. The thread type indicates the type of operation performed by the worker thread. In determining the candidate worker threads in the thread pool that can perform the recycling operation, the determining unit 502 is specifically used to: query a preset mapping relationship set to determine the candidate worker threads in the thread pool that can perform the recycling operation. The preset mapping relationship set includes the correspondence between the multiple worker threads and the multiple thread types.
[0092] In one possible example, regarding the step of adding the target page to the shared linked list if available space is detected, the adding unit 503 is specifically configured to: call a caching function to add the target page to the reclamation space of the cache space corresponding to the shared linked list, the cache space including the reclamation space, the reclamation space being used to indicate memory pages to be reclaimed; and call a callback function to add the set of pages to be reclaimed in the reclamation space to the shared linked list.
[0093] In one possible example, regarding the execution of the recycling operation via a second worker thread among the candidate worker threads, the execution unit 504 is specifically configured to: retrieve the set of pages to be recycled from the shared linked list; filter the target page from the set of pages to be recycled according to the order number in which the target page was added to the recycling space; and call a lock-holding function via the second worker thread, the lock-holding function being configured to perform the following steps: if the page type of the target page is a locked page, then when the type of the target page changes from a locked page to an unlocked page, perform a locking operation on the target page; if the page type of the target page is an unlocked page, then perform a locking operation on the target page; if it is detected that the target page meets the recycling conditions, then recycle the target page, the recycling conditions meaning that the target page does not have a user access requirement; if it is detected that the target page does not meet the recycling conditions, then perform an unlocking operation on the target page and return it to the file system.
[0094] In one possible example, before performing the reclamation operation through the second worker thread among the candidate worker threads, the memory reclamation control device 50 is further configured to: if the candidate worker thread is a single worker thread, determine the candidate worker thread as the second worker thread for performing the reclamation operation; if the candidate worker thread includes multiple worker threads, determine any one of the candidate worker threads as the second worker thread.
[0095] It is understood that since the method embodiments and the device embodiments are different presentations of the same technical concept, the content of the method embodiment section in this application should be adapted to the device embodiment section in a synchronous manner, and will not be repeated here.
[0096] When using integrated units, such as Figure 5b As shown, Figure 5b This is a functional unit block diagram of another memory reclamation control device provided in an embodiment of this application. Figure 5b In this memory reclamation control device 51, there are a processing module 512 and a communication module 511. The processing module 512 is used to control and manage the operations of the memory reclamation control device, for example, executing the steps of the configuration unit 501, the determination unit 502, the addition unit 503, and the execution unit 504, and / or other processes for performing the techniques described herein. The communication module 511 is used to support interaction between the memory reclamation control device and other devices. Figure 5b As shown, the memory reclamation control device may also include a storage module 513, which is used to store the program code and data of the memory reclamation control device.
[0097] The processing module 512 can be a processor or controller, such as a central processing unit (CPU), a general-purpose processor, a digital signal processor (DSP), an ASIC, an FPGA, or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc. The communication module 511 can be a transceiver, RF circuitry, or a communication interface, etc. The storage module 513 can be a memory.
[0098] All relevant content in each scenario involved in the above method embodiments can be referenced from the functional descriptions of the corresponding functional modules, and will not be repeated here. Figure 2 The memory reclamation control method shown.
[0099] The above embodiments can be implemented, in whole or in part, by software, hardware, firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired or wireless means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more sets of available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium. A semiconductor medium can be a solid-state drive.
[0100] This application also provides a computer storage medium storing a computer program / instructions thereon, which, when executed by a processor, implements some or all of the steps of any of the methods described in the above method embodiments.
[0101] This application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program operable to cause a computer to perform some or all of the steps of any of the methods described in the above method embodiments.
[0102] It should be understood that in the various embodiments of this application, the order of the above-mentioned processes does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0103] In the several embodiments provided in this application, it should be understood that the disclosed methods, apparatuses, and systems can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for example, the division of units is merely a logical functional division, and other division methods may exist in actual implementation; for example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0104] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0105] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can be physically comprised separately, or two or more units can be integrated into one unit. The integrated unit described above can be implemented in hardware or in the form of hardware plus software functional units.
[0106] The integrated units implemented as software functional units described above can be stored in a computer-readable storage medium. These software functional units, stored in a storage medium, include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute some steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, volatile memory, or non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous DRAM (DDR SDRAM), enhanced synchronous DRAM (ESDRAM), synchronous linked DRAM (SLDRAM), and direct rambus RAM (DR RAM), etc., which are various media capable of storing program code.
[0107] While the present invention has been disclosed above, it is not limited thereto. Any person skilled in the art can easily conceive of variations or substitutions without departing from the spirit and scope of the present invention, and various modifications and alterations can be made, including combinations of the different functions and implementation steps described above, as well as software and hardware implementation methods, all of which are within the protection scope of the present invention.
Claims
1. A memory recovery control method characterized by comprising: The method comprises: configuring a first worker thread as an original thread requiring a recycling operation to be performed on a target page in memory to be recycled; if it is detected that the page type of the target page is an unlocked page, performing the recycling operation on the target page by the first worker thread; when it is detected that the page type of the target page is a locked page, determining a candidate worker thread capable of performing the recycling operation in a thread pool, the candidate worker thread being a worker thread other than the first worker thread; if it is detected that a shared linked list has available space, calling a cache function to add the target page to a recycling space of a cache space corresponding to the shared linked list, the cache space comprising the recycling space, the recycling space being used to indicate a memory page to be recycled; calling a callback function to add a set of pages to be recycled in the recycling space to the shared linked list, the shared linked list being a linked list that can be called by the first worker thread and / or the candidate worker thread; taking the set of pages to be recycled from the shared linked list; screening the target page from the set of pages to be recycled according to a sequence number of the target page added to the recycling space; calling a lock holding function by a second worker thread in the candidate worker thread, the lock holding function being used to perform the following steps: if the page type of the target page is a locked page, performing a locking operation on the target page when the type of the target page changes from a locked page to an unlocked page; if the page type of the target page is an unlocked page, performing a locking operation on the target page; if it is detected that the target page meets a recycling condition, recycling the target page by the second worker thread, the recycling condition being that the target page has no demand for user access; if it is detected that the target page does not meet the recycling condition, performing an unlocking operation on the target page and returning the target page to a file system.
2. The method of claim 1, wherein, The detection that the page type of the target page is a locked page comprises: detecting content information carried by a flag bit of the target page, the content information being used to represent that the page type of the target page is a locked page.
3. The method of claim 1, wherein, The detection that the page type of the target page is a locked page comprises: calling a lock holding function to perform page type detection on the target page to obtain an execution result, the execution result comprising lock holding success and lock holding failure; if the execution result is lock holding failure, it is detected that the page type of the target page is a locked page.
4. The method of claim 2 or 3, wherein, The thread pool comprises a plurality of worker threads, the plurality of worker threads corresponding to a plurality of thread types, the thread type being used to indicate the type of an operation performed by the worker thread, and the determination of the candidate worker thread capable of performing the recycling operation in the thread pool comprises: inquiring a preset mapping relationship set to determine the candidate worker thread capable of performing the recycling operation in the thread pool, the preset mapping relationship set comprising a correspondence relationship between the plurality of worker threads and the plurality of thread types.
5. The method of claim 1, wherein, Before invoking the holding lock function by a second worker thread in the candidate worker threads, the method further comprises: If the candidate worker thread is a single worker thread, determining the candidate worker thread as the second worker thread for performing the reclaim operation; If the candidate worker thread includes a plurality of worker threads, determining any one of the candidate worker threads as the second worker thread.
6. An electronic device, comprising: A computer program product comprising a processor, a memory, and one or more programs stored in the memory and configured to be executed by the processor, the programs comprising instructions for performing the steps in the method of any one of claims 1-5.
7. A memory recovery control device characterized by comprising: The apparatus comprises: A configuration unit configured to configure a first worker thread as an original thread requiring to perform a reclaim operation on a target page to be reclaimed in a memory; A determination unit configured to, if detecting that a page type of the target page is an unlocked page, perform the reclaim operation on the target page by the first worker thread; and when detecting that the page type of the target page is a locked page, determine a candidate worker thread in a thread pool capable of performing the reclaim operation; An addition unit configured to, if detecting that a shared linked list has available space, invoke a cache function to add the target page into a reclaim space in a cache space corresponding to the shared linked list, the cache space including the reclaim space, the reclaim space being used to indicate a memory page to be reclaimed; and invoke a callback function to add a set of pages to be reclaimed in the reclaim space into the shared linked list, the shared linked list being a linked list that can be invoked by the first worker thread and / or the candidate worker thread; An execution unit configured to take out the set of pages to be reclaimed from the shared linked list; and, Filter out the target page from the set of pages to be reclaimed according to a sequence number of the target page added into the reclaim space; and, Invoke a holding lock function by a second worker thread in the candidate worker threads, the holding lock function being used to perform the following steps: If the page type of the target page is a locked page, perform a lock operation on the target page when the page type of the target page changes from a locked page to an unlocked page; If the page type of the target page is an unlocked page, perform a lock operation on the target page; If detecting that the target page meets a reclaim condition, reclaim the target page by the second worker thread, the reclaim condition being that the target page has no demand for user access; If detecting that the target page does not meet the reclaim condition, perform an unlock operation on the target page and return the target page to a file system.
8. A computer readable storage medium having stored thereon computer programs / instructions, characterized in that, The computer program / instructions, when executed by a processor, implement the steps of the method of any one of claims 1-5.
Citation Information
Patent Citations
Page cache recovery method, device and equipment and storage medium
CN112269768A
Memory recovery method and device
CN114443510A