Memory recycling processing method, device, computer equipment and storage medium
By traversing the anonymous linked list tags and updating the exchange linked list, directly recycling memory pages that do not meet the conditions, solving the problem of traditional low memory recycling efficiency and improving memory utilization and terminal stability.
Patent Information
- Application Number
- CN201911291858.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-16
- Publication Date
- 2024-12-27
- Estimated Expiration
- 2039-12-16
AI Technical Summary
Traditional memory recycling methods are inefficient and require multiple scans of anonymous linked lists to recycle memory pages, resulting in waste of resources and abnormal operation.
By obtaining the memory recycling task, traverse the anonymous linked list to mark the memory page that does not meet the conditions as the swap memory page, and update the swap linked list to directly recycle the memory page that meets the conditions to avoid repeated scanning of unmarked pages.
Improve memory recycling efficiency, reduce resource waste, and ensure stable operation of the terminal.
Smart Images

Figure CN112988610B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a memory recycling processing method, device, computer equipment and storage medium. Background Art
[0002] During the operation of the terminal, the operating system will cache a large amount of data in the terminal memory in order to speed up the operation of the terminal, so as to facilitate fast reading and writing of the cached data. However, the terminal's memory space is limited, and caching all the data in the memory will cause insufficient memory allocation, resulting in abnormal terminal operation. Therefore, a mechanism for reclaiming memory has emerged.
[0003] In the traditional way, the terminal can recycle the memory pages in the anonymous linked list or file linked list of the memory. When reclaiming the memory pages of the anonymous linked list, the anonymous linked list needs to be scanned at least twice to recycle the marked memory pages in the anonymous linked list. However, the anonymous linked list also includes many unmarked memory pages. Each scan of the anonymous linked list requires scanning each memory page in the anonymous linked list from the head of the linked list in sequence. When reclaiming memory, the unmarked memory pages are scanned repeatedly, resulting in low efficiency of memory recycling. Summary of the invention
[0004] Based on this, it is necessary to provide a memory recycling processing method, device, computer equipment and storage medium that can improve the memory recycling efficiency in order to address the above-mentioned technical problem of low memory recycling efficiency.
[0005] A memory recycling method, the method comprising:
[0006] Obtain a memory recycling task, wherein the memory recycling task carries a condition of memory to be recycled;
[0007] Acquire target memory page information corresponding to the swap linked list according to the memory recovery task;
[0008] When the target memory page information does not meet the to-be-reclaimed memory condition, traverse the anonymous linked list and mark a specific anonymous memory page in the anonymous linked list as a swap memory page;
[0009] Updating the swap linked list according to the swap memory page in the anonymous linked list;
[0010] The updated target memory page in the exchange linked list is recycled to obtain a free memory page.
[0011] In one of the embodiments, the target memory page information includes a target page number corresponding to the target memory page;
[0012] When the target memory page information does not meet the to-be-reclaimed memory condition, traversing the anonymous linked list and marking a specific anonymous memory page in the anonymous linked list as a swap memory page comprises:
[0013] When the target number of pages is greater than a threshold, determining a first number of pages to be marked according to the target number of pages and the condition of the memory to be reclaimed;
[0014] The anonymous linked list is traversed until the number of the marked specific anonymous memory pages reaches the first number of pages to be marked.
[0015] In one embodiment, after the step of reclaiming the updated target memory page in the swap linked list to obtain a free memory page, the method further includes:
[0016] Obtain the number of free pages corresponding to the free memory page;
[0017] When the number of free pages does not satisfy the memory condition to be reclaimed, determining a second number of pages to be marked according to the number of free pages and the memory condition to be reclaimed;
[0018] Repeat the step of traversing the anonymous linked list to mark the specific anonymous memory pages reaching the second number of pages to be marked as the swap memory pages.
[0019] In one embodiment, after the step of marking the specific anonymous memory page in the anonymous linked list as a swap memory page, the method further includes:
[0020] Get the page slot identifier corresponding to the free page slot in the swap partition;
[0021] Generate a swap page table entry according to the page slot identifier;
[0022] The process page table entry corresponding to the swap memory page is updated according to the swap page table entry, and the swap memory page is written back to the free page slot corresponding to the page slot identifier.
[0023] In one embodiment, the step of reclaiming the updated target memory page in the exchange linked list to obtain a free memory page comprises:
[0024] Sequentially traverse the target memory page in the updated exchange linked list to obtain a write-back status corresponding to the target memory page;
[0025] When the write-back status is write-back completion, the target data in the target memory page is cleared to obtain the free memory page.
[0026] In one embodiment, the method further comprises:
[0027] Reading a swap descriptor corresponding to the target memory page, wherein the swap descriptor is used to mark the specific anonymous memory page as the swap memory page;
[0028] The target memory page whose swap descriptor is cleared is extracted from the swap linked list, and the target memory page is added to the anonymous linked list.
[0029] In one embodiment, the method further comprises:
[0030] When a plurality of the memory recycling tasks are acquired within a preset time period, calling a preset lock mechanism to set the status of the memory recycling tasks;
[0031] When the state corresponding to the memory recycling task is executable, executing the step of obtaining target memory page information corresponding to the swap linked list according to the memory recycling task;
[0032] When the state corresponding to the memory reclaiming task is locked, the memory reclaiming task is intercepted until the execution of a previous memory reclaiming task corresponding to the memory reclaiming task is completed.
[0033] A memory recycling processing device, the device comprising:
[0034] A task acquisition module, used to acquire a memory recovery task, wherein the memory recovery task carries a condition of memory to be recovered;
[0035] An information acquisition module, used for acquiring target memory page information corresponding to a swap linked list according to the memory recovery task;
[0036] A linked list traversal module, used for traversing the anonymous linked list and marking a specific anonymous memory page in the anonymous linked list as a swap memory page when the target memory page information does not meet the memory condition to be reclaimed;
[0037] A linked list updating module, used for updating the exchange linked list according to the exchange memory page in the anonymous linked list;
[0038] The memory recycling module is used to recycle the target memory page in the updated exchange linked list to obtain a free memory page.
[0039] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above-mentioned memory recycling processing method when executing the computer program.
[0040] A computer-readable storage medium stores a computer program, which implements the steps of the above-mentioned memory recycling processing method when executed by a processor.
[0041] The above-mentioned memory recycling processing method, device, computer equipment and storage medium, when obtaining a memory recycling task, obtains the target memory page information corresponding to the exchange linked list according to the memory recycling task. When the target memory page information does not meet the condition of the memory to be recycled in the memory recycling task, the anonymous linked list is traversed, and the specific anonymous memory page in the anonymous linked list is marked as a swap memory page, and the swap memory page is updated to the exchange linked list. The target memory page in the updated exchange linked list is recycled, which avoids repeated scanning of the anonymous memory pages that are not marked in the anonymous linked list, and effectively improves the memory recycling efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 An application environment diagram of a memory recycling method in an embodiment;
[0043] Figure 2 A schematic diagram of a memory recycling process in one embodiment;
[0044] Figure 3 A schematic diagram of a flow chart of a memory recycling method in another embodiment;
[0045] Figure 4 is a structural block diagram of a memory recycling processing device in one embodiment;
[0046] Figure 5 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0047] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0048] The memory recycling method provided in this application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 obtains a memory recovery task, and the memory recovery task carries the memory condition to be recovered. The terminal 102 obtains the target memory page information corresponding to the exchange linked list according to the memory recovery task. When the target memory page information does not meet the memory condition to be recovered, the anonymous linked list is traversed, and the specific anonymous memory page in the anonymous linked list is marked as a swap memory page. The terminal 102 updates the exchange linked list according to the swap memory page in the anonymous linked list, recycles the target memory page in the updated exchange linked list, and obtains a free memory page. Among them, the terminal 102 may include but is not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices.
[0049] In one embodiment, Figure 2As shown, a memory recycling method is provided, which is applied to Figure 1 The terminal 102 in the example is used as an example to illustrate, and the following steps are included:
[0050] Step 202, obtaining a memory recycling task, wherein the memory recycling task carries a condition of the memory to be recycled.
[0051] The memory recycling task is used to instruct the terminal to recycle the memory pages that have been occupied for a long time but rarely used, so as to obtain free memory pages and ensure that the terminal's operating system continues to have memory available. A memory page refers to a physical page of memory and is the smallest management unit of memory.
[0052] The terminal can obtain the memory recovery task in a variety of ways. Specifically, the terminal can perform memory recovery according to a preset period. The period for memory recovery can be fixed or adjusted according to the actual operation requirements of the terminal. The terminal can also detect the usage of memory, and when it detects that the free memory page is less than the preset value, it generates a memory recovery task and performs memory recovery according to the memory recovery task. The terminal can also trigger the memory recovery task according to the memory recovery instruction of the operating system when the operating system needs the memory page, and recycle the memory page according to the needs of the operating system.
[0053] The memory recovery task carries the memory condition to be recovered, and the terminal recovers the memory pages that meet the memory condition to be recovered according to the memory recovery task. The memory condition to be recovered includes the number of memory pages that the terminal needs to recover at least. When the number of memory pages recovered by the terminal is greater than or equal to the number of memory pages that need to be recovered at least, it means that the memory condition to be recovered is met. Otherwise, the memory condition to be recovered is not met. The memory condition to be recovered can also be the size of memory that the terminal needs to recover. The condition to be recovered can be fixed. For example, when memory recovery is performed according to a preset cycle, a fixed number of memory pages are recovered. The condition to be recovered can also be variable. For example, the terminal can determine the memory condition to be recovered based on the memory requirements of the operating system when memory pages are needed.
[0054] Step 204, obtaining target memory page information corresponding to the swap linked list according to the memory recovery task.
[0055] Among them, the exchange linked list is a newly established linked list in this embodiment to improve the memory recovery efficiency. The exchange linked list is used to store the exchange memory pages in the memory, and all the memory pages stored in the exchange linked list are exchange memory pages. A linked list is a non-continuous and non-sequential storage structure on the memory, and the exchange linked list can be an LRU (Least Recently Used) linked list. The data element corresponding to each node in the exchange linked list is a exchange memory page. The exchange memory page refers to an anonymous memory page (Anonymous Page) marked as to be written back to the SWAP (swap) partition. The anonymous memory page includes the memory pages used by the process heap, stack, data segment, etc. In the process of reclaiming memory, the terminal can directly write the exchange memory page back to the exchange partition, thereby releasing the exchange memory page and obtaining a free memory page for use by other processes.
[0056] After the terminal obtains the memory recovery task, it obtains the target memory page information corresponding to the exchange linked list according to the memory recovery task. The target memory page refers to the exchange memory page to be recovered in the exchange linked list, and the target memory page information is the information corresponding to the exchange memory page. The target memory page information may include the target page number and target memory page size corresponding to the target memory page in the exchange linked list. The terminal can count the target memory page information corresponding to the exchange linked list when the exchange linked list is updated. The terminal can also count the target memory page information corresponding to the exchange linked list according to the memory recovery task after obtaining the memory recovery task.
[0057] Step 206, when the target memory page information does not meet the memory to be reclaimed condition, the anonymous linked list is traversed, and a specific anonymous memory page in the anonymous linked list is marked as a swap memory page.
[0058] The terminal compares the target memory page information corresponding to the exchange linked list with the memory condition to be reclaimed carried by the memory recovery task. Specifically, when the memory condition to be reclaimed includes at least the number of memory pages to be reclaimed, the terminal compares the target number of pages in the target memory page information with the number of memory pages to be reclaimed. If the target number of pages is greater than or equal to the number of memory pages to be reclaimed, it means that the target memory page information meets the memory condition to be reclaimed. If the target number of pages is less than the number of memory pages to be reclaimed, it means that the target memory page information does not meet the memory condition to be reclaimed. When the memory condition to be reclaimed includes the size of memory to be reclaimed, the terminal can compare the size of all target memory pages with the size of memory to be reclaimed, and can also determine the number of memory pages to be reclaimed based on the size of memory to be reclaimed and the size of each swap memory page, and judge whether the target memory page information meets the memory condition to be reclaimed based on the number of memory pages.
[0059] When the target memory page information does not meet the conditions for memory to be reclaimed, the terminal traverses the anonymous linked list. Among them, the anonymous linked list is a linked list used to store anonymous memory pages, and the anonymous linked list can be an LRU linked list. The terminal traverses the anonymous memory pages one by one in order from the list head of the anonymous linked list until all anonymous memory pages in the anonymous linked list are traversed, and the specific anonymous memory page in the anonymous linked list is marked as a swap memory page. Specifically, the terminal can use a descriptor to mark a specific anonymous memory page as a swap memory page. The specific anonymous memory page is an anonymous memory page in the anonymous linked list that has a low probability of being accessed and has a process mapping. The specific anonymous memory pages are scattered in the anonymous linked list. Anonymous memory pages that have not been accessed recently will occupy unnecessary memory space if stored in the anonymous linked list. The terminal can write back the specific anonymous memory page marked as a swap memory page to the swap partition.
[0060] Step 208, updating the swap linked list according to the swap memory pages in the anonymous linked list.
[0061] The terminal updates the swap linked list according to the swap memory pages marked in the anonymous linked list. Specifically, the terminal can extract the marked swap memory pages from the anonymous linked list, splice the extracted swap memory pages with the swap memory pages in the swap linked list, and add the extracted swap memory pages to the established swap linked list. Since the marked swap memory pages are scattered in the anonymous linked list, after the terminal extracts the swap memory pages from the anonymous linked list, it re-splices the anonymous memory pages in the anonymous linked list to ensure the integrity of the anonymous linked list.
[0062] Step 210, reclaiming the target memory page in the updated swap linked list to obtain a free memory page.
[0063] After the terminal stores the swap memory page in the anonymous linked list into the swap linked list, it recycles the target memory page in the updated swap linked list to obtain a free memory page. Specifically, the terminal writes the target memory page back to the swap partition so that the swap partition can be accessed and re-read when the data in the target memory page is needed. After the terminal writes the data in the target memory page back to the swap partition, it deletes the target memory page in the swap linked list to obtain a free memory page.
[0064] In this embodiment, when the terminal obtains a memory recovery task, the target memory page information corresponding to the exchange linked list is obtained according to the memory recovery task. When the target memory page information does not meet the memory condition to be recovered carried in the memory recovery task, the anonymous linked list is traversed, and the specific anonymous memory page in the anonymous linked list is marked as a swap memory page, and the swap memory page is updated to the exchange linked list. The terminal directly recycles the target memory page in the updated exchange linked list to obtain the free memory page that meets the memory condition to be recovered. In the traditional method, the exchange linked list does not exist in the memory of the terminal. Compared with the traditional recovery method that requires scanning the anonymous linked list at least twice, the present embodiment newly creates and maintains the exchange linked list in the memory, directly recycles the target memory page in the exchange linked list, avoids repeated scanning of the anonymous memory page that is not marked in the anonymous linked list, and effectively improves the recovery efficiency of the memory.
[0065] In one embodiment, when the target memory page information does not meet the condition of the memory to be reclaimed, the terminal can call multiple threads to traverse the anonymous linked list and the exchange linked list in parallel. Specifically, the terminal calls multiple threads to write the target memory pages in the exchange linked list back to the exchange partition in sequence. At the same time, the specific anonymous memory pages in the anonymous linked list are marked as exchange memory pages, and the exchange memory pages are written back to the exchange partition, thereby improving the efficiency of writing back the exchange memory pages. In one embodiment, when the terminal traverses the anonymous linked list and marks the specific anonymous memory pages in the anonymous linked list as exchange memory pages, the marked exchange memory pages are not stored in the exchange linked list until the anonymous linked list traversal is completed, thereby ensuring the consistency of the exchange memory pages between the anonymous linked list and the exchange linked list, and improving the accuracy of memory recovery.
[0066] In this embodiment, when the target memory page in the exchange linked list after the update is recycled, the target memory page in the exchange linked list has been written back to the exchange partition. The terminal can directly clear the target data in the target memory page to obtain a free memory page, which effectively improves the recycling efficiency of the memory.
[0067] In one embodiment, after the terminal compares the target memory page information corresponding to the exchange linked list with the memory condition to be reclaimed carried by the memory reclaiming task, when the target memory page information meets the memory condition to be reclaimed, the terminal directly reclaims the target memory page in the exchange linked list. Specifically, the terminal writes back the target memory pages in the exchange linked list to the exchange partition one by one according to the order of the exchange linked list. When the target memory page is written back, the target memory page in the exchange linked list is cleared to obtain a free memory page.
[0068] In this embodiment, when the target memory page information meets the memory to be reclaimed condition, the terminal directly reclaims the target memory page in the exchange linked list. Each target memory page in the exchange linked list is recyclable. The terminal does not need to spend time traversing the non-recyclable anonymous memory pages in the anonymous linked list, which effectively improves the memory recovery efficiency.
[0069] In one embodiment, the target memory page information includes a target page number corresponding to the target memory page. When the target memory page information does not meet the memory condition to be reclaimed, the anonymous linked list is traversed, and the step of marking a specific anonymous memory page in the anonymous linked list as a swap memory page includes: when the target page number is greater than a threshold, determining a first number of pages to be marked according to the target page number and the memory condition to be reclaimed; and traversing the anonymous linked list until the number corresponding to the marked specific anonymous memory pages reaches the first number of pages to be marked.
[0070] The target memory page information may include the target number of pages corresponding to the target memory page, and the target number of pages refers to the number of target memory pages included in the exchange linked list. When the target memory page information does not meet the memory condition to be reclaimed, the terminal may compare the target number of pages with the threshold, and the threshold is the minimum number of pages pre-set by the user according to actual needs. For example, the threshold may be 0. When the target number of pages is less than or equal to the threshold, the terminal traverses the anonymous memory pages in the anonymous linked list until all anonymous memory pages are traversed. When the target number of pages is greater than the threshold, the terminal determines the first number of pages to be marked based on the target number of pages and the memory condition to be reclaimed, and the terminal traverses the anonymous memory pages from the head of the anonymous linked list in sequence. When the number corresponding to the specific anonymous memory pages marked as exchange memory pages reaches the first number of pages to be marked, the anonymous linked list is stopped.
[0071] Specifically, the terminal can calculate the difference between the number of memory pages to be reclaimed and the target number of pages in the memory to be reclaimed condition, and determine the difference between the number of memory pages to be reclaimed and the target number of pages as the first number of pages to be marked. In one embodiment, the terminal may also compare the target number of pages with the threshold first. When the target number of pages is less than or equal to the threshold, the terminal traverses all anonymous memory pages in the anonymous linked list. When the target number of pages is greater than the threshold, the terminal compares the target memory page information with the memory to be reclaimed condition. When the target memory page information meets the memory to be reclaimed condition, the target memory page in the exchange linked list is directly reclaimed. When the target memory page information does not meet the memory to be reclaimed condition, the first number of pages to be marked is determined according to the target number of pages and the memory to be reclaimed condition, and the anonymous linked list is traversed until the number corresponding to the marked specific anonymous memory pages reaches the first number of pages to be marked.
[0072] In this embodiment, when the target number of pages in the target memory page information is greater than a threshold value, the terminal can determine the first number of pages to be marked based on the target number of pages and the memory condition to be reclaimed. When the number corresponding to the marked specific anonymous memory pages reaches the first number of pages to be marked, stop traversing the anonymous memory pages in the anonymous linked list. The terminal stores the swap memory pages of the first number of pages to be marked in the swap linked list, recycles the target number of pages and the target memory pages of the first number of pages to be marked, and obtains free memory pages that meet the memory condition to be reclaimed. In the process of reclaiming memory, the terminal avoids traversing redundant anonymous memory pages, reduces the number of anonymous memory pages traversed by the terminal, and effectively improves the memory recovery efficiency.
[0073] In one embodiment, after the step of marking a specific anonymous memory page in the anonymous linked list as a swap memory page, the method further includes: obtaining a page slot identifier corresponding to a free page slot in a swap partition; generating a swap page table entry based on the page slot identifier; updating a process page table entry corresponding to the swap memory page based on the swap page table entry, and writing the swap memory page back to the free page slot corresponding to the page slot identifier.
[0074] When the terminal traverses the anonymous linked list and marks a specific anonymous memory page in the anonymous linked list as a swap memory page, the swap memory page is written back. Specifically, the terminal can obtain the free page slots allocated by the swap partition. The swap partition can be a group of continuous physical sectors on the disk. The swap partition includes multiple page slots with the same size as the memory page, which are used to store the written-back memory pages. For example, when the size of the memory page is 4k, the swap partition can be divided into page slots of 4k each to save the data in the written-back swap memory page. Each free page slot in the swap partition has a corresponding page slot identifier, and the terminal can obtain the page slot identifier corresponding to the free page slot in the swap partition.
[0075] The terminal determines the node corresponding to the page slot identifier from the base tree of the swap partition according to the obtained page slot identifier, and stores the descriptor corresponding to the swap memory page in the node. The terminal uses the page slot identifier as an offset and generates a swap page table entry according to the offset. The swap page table entry refers to a field in the page table corresponding to the swap memory page in the swap partition. The page table is a correspondence table between the swap memory page and the free page slot. The page table can be used as an index to record the one-to-one mapping relationship between the swap memory page and the page slot. The terminal can determine in which page slot of the swap partition the swap memory page is stored through the page table. The terminal performs reverse mapping on the swap memory page, and replaces the process page table entry corresponding to the swap memory page with the generated swap page table entry. The terminal writes back the data corresponding to the swap memory page to the free page slot corresponding to the page slot identifier, and completes the write-back of the swap memory page.
[0076] In this embodiment, after the terminal marks a specific anonymous memory page as a swap memory page, the swap memory page is written back to the swap partition. When the terminal updates the swap linked list according to the swap memory page and recycles the target memory page in the updated swap linked list, the swap memory page has been written back to the swap partition, and the terminal can directly clear the target data in the target memory page to obtain a usable free memory page, which effectively improves the memory recovery efficiency.
[0077] In one embodiment, the step of reclaiming the target memory page in the updated swap linked list to obtain the free memory page includes: sequentially traversing the target memory page in the updated swap linked list to obtain the write-back status corresponding to the target memory page; when the write-back status is write-back completed, clearing the target data in the target memory page to obtain the free memory page.
[0078] The terminal traverses the target memory pages one by one from the list head of the updated exchange list in the order of the exchange list, and obtains the write-back status corresponding to the target memory pages one by one. When the terminal obtains the write-back status corresponding to the target memory page, it determines whether the write-back status is complete. When the write-back status corresponding to the target memory page is complete, it means that the target data in the target memory page has been written back to the exchange partition. The terminal can clear the target data in the target memory page and obtain a free memory page that can be used. When the write-back status corresponding to the target memory page is in the process of writing back, it means that the target data in the target memory page is still in the process of writing back to the exchange partition. The terminal skips the target memory page and continues to obtain the write-back status corresponding to the next target memory page to determine whether the corresponding write-back status is complete. The terminal traverses the target memory pages one by one, and only starts to determine the next target memory page after determining whether the write-back status is complete and performing the operation corresponding to the write-back status. The skipped target memory page continues to write back the corresponding target data and waits for the terminal to traverse the exchange list next time.
[0079] In this embodiment, the terminal sequentially traverses the target memory page in the updated exchange linked list, obtains the write-back status corresponding to the target memory page, and clears the target data in the target memory page when the write-back status is complete, and obtains a free memory page. The terminal avoids clearing the target data that has not been written back by judging whether the write-back status corresponding to the target memory page is complete, thereby preventing the loss of memory data.
[0080] In one embodiment, Figure 3 As shown, after the step of recycling the target memory page in the updated swap linked list to obtain a free memory page, the method further includes:
[0081] Step 302, obtaining the number of free pages corresponding to the free memory pages.
[0082] Step 304: When the number of free pages does not satisfy the memory condition to be reclaimed, determine a second number of pages to be marked according to the number of free pages and the memory condition to be reclaimed.
[0083] Step 306, repeating the step of traversing the anonymous linked list, marking specific anonymous memory pages reaching the second number of pages to be marked as swap memory pages.
[0084] The terminal obtains the number of free pages corresponding to the free memory page, and the number of free pages refers to the number of free memory pages obtained after the terminal recycles the target memory page in the updated exchange linked list. The terminal compares the number of free pages corresponding to the free memory page with the memory condition to be reclaimed carried in the memory recovery task to determine whether the number of free pages meets the memory condition to be reclaimed. When the number of free pages is greater than or equal to the number of memory pages to be reclaimed in the memory condition to be reclaimed, it means that the number of free pages meets the memory condition to be reclaimed. When the number of free pages is less than the number of memory pages to be reclaimed, it means that the number of free pages does not meet the memory condition to be reclaimed. In one embodiment, when the number of free pages recovered by the terminal meets the memory condition to be reclaimed, it is determined that the memory recovery task is completed.
[0085] When the number of free pages recovered by the terminal does not meet the condition of the memory to be recovered, the second number of pages to be marked is determined according to the number of free pages and the condition of the memory to be recovered. Specifically, the terminal calculates the difference between the number of memory pages to be recovered and the number of free pages, and determines the difference between the number of memory pages to be recovered and the number of free pages as the second number of pages to be marked. The terminal repeats the step of traversing the anonymous linked list, marks the specific anonymous memory pages that reach the second number of pages to be marked as swap memory pages, and then stops traversing the anonymous linked list. The terminal repeatedly updates the swap linked list according to the swap memory pages in the anonymous linked list, recycles the target memory pages in the updated swap linked list, and obtains free memory pages, until the number of free pages corresponding to the free memory pages recovered by the terminal meets the condition of the memory to be recovered.
[0086] In this embodiment, the write-back state corresponding to the target memory page in the exchange linked list may be in the write-back process, and the terminal needs to skip the target memory page in the write-back process, which causes the number of free pages corresponding to the free memory pages recovered by the terminal to fail to meet the memory condition to be recovered. The terminal determines the second number of marked pages based on the number of free pages and the memory condition to be recovered, and the terminal repeatedly executes the specific anonymous memory page that marks the second number of pages to be marked from the anonymous linked list, thereby ensuring that the number of free pages corresponding to the free memory pages recovered can meet the memory condition to be recovered, effectively improving the accuracy of memory recovery.
[0087] In one embodiment, the method further includes: reading a swap descriptor corresponding to the target memory page, the swap descriptor being used to mark a specific anonymous memory page as a swap memory page; extracting the target memory page whose swap descriptor is cleared from the swap linked list, and adding the target memory page to the anonymous linked list.
[0088] The terminal can scan the exchange linked list and read the exchange descriptors corresponding to the target memory page in the exchange linked list in sequence. The exchange descriptor is a marker used by the terminal when traversing and marking a specific anonymous memory page, and is used to mark the specific anonymous memory page in the anonymous linked list as a exchange memory page. When the exchange descriptor corresponding to the target memory page is cleared, the corresponding target memory page is extracted from the exchange linked list. The exchange descriptor corresponding to the target memory page can be cleared in various situations. For example, when the target data corresponding to the target memory page is overwritten, the exchange descriptor corresponding to the target memory page can be cleared. When the target memory page is accessed, the exchange descriptor corresponding to the target memory page can also be cleared.
[0089] The terminal extracts the target memory page whose swap descriptor is cleared from the swap linked list, and adds the extracted target memory page to the anonymous linked list. Specifically, the target memory page whose swap descriptor is cleared may be scattered in the swap linked list. After the terminal extracts the target memory page whose swap descriptor is cleared from the swap linked list, it reassembles the swap linked list and stores the extracted target memory page in the anonymous linked list.
[0090] In this embodiment, the terminal can scan the exchange linked list, read the exchange descriptor corresponding to the target memory page in the exchange linked list, and when the exchange descriptor corresponding to the target memory page is cleared, extract the target memory page from the exchange linked list, and add the extracted target memory page to the anonymous linked list. When the target memory page changes, the storage linked list of the target memory page is adjusted in time, ensuring the correctness of the memory pages stored in the exchange linked list and the anonymous linked list, as well as the effectiveness of memory recovery.
[0091] In one embodiment, the above method also includes: when multiple memory recovery tasks are obtained within a preset time period, calling a preset lock mechanism to set the status of the memory recovery task; when the status corresponding to the memory recovery task is executable, executing the step of obtaining the target memory page information corresponding to the exchange linked list according to the memory recovery task; when the status corresponding to the memory recovery task is locked, intercepting the memory recovery task until the previous memory recovery task corresponding to the memory recovery task is executed.
[0092] When a memory recycling task is triggered and generated according to the operating requirements of the operating system, the terminal can obtain multiple memory recycling tasks within a preset time period. When the terminal obtains multiple memory recycling tasks within the preset time period, in order to ensure the correctness of the memory pages stored in the exchange linked list and the anonymous linked list, the terminal can set the status of the obtained memory recycling task according to the acquisition time corresponding to the memory recycling task.
[0093] Specifically, the preset time period may be a time length pre-set by the user according to the memory recovery time, the preset time period may be less than or equal to the time required for the terminal to execute the memory recovery task for memory recovery, and the preset time period may be a preset time length starting when the terminal acquires the memory recovery task. The terminal may call a preset lock mechanism to control the execution of the acquired memory recovery task. Among them, the preset lock mechanism may include multiple lock mechanisms. For example, the preset lock mechanism called by the terminal may be a spin lock mechanism, a mutex lock mechanism, or a synchronization lock mechanism. This prevents multiple processors in the terminal from concurrently processing shared exchange linked lists and anonymous linked lists.
[0094] The terminal can call a preset lock mechanism to set the state of the memory recovery task. After obtaining the memory recovery task, the terminal obtains the lock according to the memory recovery task. When the exchange list and the anonymous list are not occupied, the state corresponding to the memory recovery task is set to the executable state. The terminal can execute the steps of obtaining the target memory page information corresponding to the exchange list according to the executable state of the memory recovery task. After obtaining the free list and completing the memory recovery task, the terminal releases the lock. When the exchange list and the anonymous list are occupied by other memory recovery tasks, the terminal sets the state corresponding to the memory recovery task to the locked state. The terminal intercepts the memory recovery task in the locked state until the previous memory recovery task corresponding to the memory recovery task is executed.
[0095] In this embodiment, when the terminal obtains multiple memory recovery tasks within a preset time period, the preset lock mechanism is called to set the state of the memory recovery task. The terminal performs corresponding different processing for memory recovery tasks in different states. When the state corresponding to the memory recovery task is executable, the step of obtaining the target memory page information corresponding to the exchange linked list according to the memory recovery task is executed. When the state corresponding to the memory recovery task is locked, the memory recovery task is intercepted until the previous memory recovery task corresponding to the memory recovery task is executed. It is ensured that when multiple memory recovery tasks are obtained, the terminal only executes one memory recovery task at the same time, preventing the terminal's multiple processors from concurrently processing the shared exchange linked list and anonymous linked list, and effectively ensuring the accuracy of the exchange linked list and anonymous linked list.
[0096] It should be understood that although Figure 2-3 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2-3At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0097] In one embodiment, Figure 4 As shown, a memory recovery processing device is provided, including: a task acquisition module 402, an information acquisition module 404, a linked list traversal module 406, a linked list update module 408 and a memory recovery module 410, wherein:
[0098] The task acquisition module 402 is used to acquire a memory recovery task, and the memory recovery task carries the conditions of the memory to be recovered.
[0099] The information acquisition module 404 is used to acquire the target memory page information corresponding to the swap linked list according to the memory recovery task.
[0100] The linked list traversal module 406 is used to traverse the anonymous linked list when the target memory page information does not meet the condition for memory to be reclaimed, and mark a specific anonymous memory page in the anonymous linked list as a swap memory page.
[0101] The linked list updating module 408 is used to update the swap linked list according to the swap memory pages in the anonymous linked list.
[0102] The memory recycling module 410 is used to recycle the target memory page in the updated swap linked list to obtain a free memory page.
[0103] In one embodiment, the target memory page information includes a target page number corresponding to the target memory page; the linked list traversal module 406 is also used to determine a first number of pages to be marked according to the target page number and the memory condition to be reclaimed when the target page number is greater than a threshold; and traverse the anonymous linked list until the number corresponding to the marked specific anonymous memory pages reaches the first number of pages to be marked.
[0104] In one embodiment, the memory recovery module 410 is also used to obtain the number of free pages corresponding to the free memory pages; when the number of free pages does not meet the memory condition to be reclaimed, determine the second number of pages to be marked according to the number of free pages and the memory condition to be reclaimed; repeat the step of traversing the anonymous linked list, and mark the specific anonymous memory pages that reach the second number of pages to be marked as swap memory pages.
[0105] In one embodiment, the linked list traversal module 406 is also used to obtain a page slot identifier corresponding to a free page slot in a swap partition; generate a swap page table entry based on the page slot identifier; update a process page table entry corresponding to a swap memory page based on the swap page table entry, and write the swap memory page back to the free page slot corresponding to the page slot identifier.
[0106] In one embodiment, the memory recovery module 410 is also used to sequentially traverse the target memory page in the updated swap list to obtain the write-back status corresponding to the target memory page; when the write-back status is write-back completed, clear the target data in the target memory page to obtain a free memory page.
[0107] In one embodiment, the linked list update module 408 is also used to read the swap descriptor corresponding to the target memory page, where the swap descriptor is used to mark a specific anonymous memory page as a swap memory page; extract the target memory page whose swap descriptor is cleared from the swap linked list, and add the target memory page to the anonymous linked list.
[0108] In one embodiment, the above-mentioned memory recovery processing device also includes a state setting module, which is used to call a preset lock mechanism to set the state of the memory recovery task when multiple memory recovery tasks are obtained within a preset time period; when the state corresponding to the memory recovery task is executable, execute the step of obtaining the target memory page information corresponding to the exchange linked list according to the memory recovery task; when the state corresponding to the memory recovery task is locked, intercept the memory recovery task until the previous memory recovery task corresponding to the memory recovery task is executed.
[0109] For the specific definition of the memory recovery processing device, please refer to the definition of the memory recovery processing method above, which will not be repeated here. Each module in the above-mentioned memory recovery processing device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0110] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 5As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a memory recycling method is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0111] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0112] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps of the above-mentioned memory recycling processing method embodiment when executing the computer program.
[0113] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned memory recycling processing method embodiment are implemented.
[0114] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0115] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0116] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A memory recycling method, characterized in that: The method comprises: Obtain a memory recycling task, wherein the memory recycling task carries a condition of memory to be recycled; According to the memory recycling task, the target memory page information corresponding to the swap linked list is obtained; the swap linked list is used to store swap memory pages in the memory; the swap memory page refers to an anonymous memory page marked as to be written back to the swap partition; the target memory page information is information corresponding to the swap memory page; the target memory page is a swap memory page to be recycled in the swap linked list; When the target memory page information does not meet the to-be-reclaimed memory condition, the anonymous linked list is traversed, and a specific anonymous memory page in the anonymous linked list is marked as a swap memory page; the specific anonymous memory page is an anonymous memory page in the anonymous linked list that has not been accessed recently and has a process mapping; Updating the swap linked list according to the swap memory page in the anonymous linked list; The updated target memory page in the exchange linked list is recycled to obtain a free memory page.
2. The method according to claim 1, characterized in that The target memory page information includes the target page number corresponding to the target memory page; When the target memory page information does not meet the to-be-reclaimed memory condition, traversing the anonymous linked list and marking a specific anonymous memory page in the anonymous linked list as a swap memory page comprises: When the target number of pages is greater than a threshold, determining a first number of pages to be marked according to the target number of pages and the condition of the memory to be reclaimed; The anonymous linked list is traversed until the number of the marked specific anonymous memory pages reaches the first number of pages to be marked.
3. The method according to claim 1, characterized in that After the step of reclaiming the updated target memory page in the exchange linked list to obtain a free memory page, the method further includes: Obtain the number of free pages corresponding to the free memory page; When the number of free pages does not satisfy the memory condition to be reclaimed, determining a second number of pages to be marked according to the number of free pages and the memory condition to be reclaimed; Repeat the step of traversing the anonymous linked list to mark the specific anonymous memory pages reaching the second number of pages to be marked as the swap memory pages.
4. The method according to claim 1, characterized in that: After the step of marking the specific anonymous memory page in the anonymous linked list as a swap memory page, the method further includes: Get the page slot identifier corresponding to the free page slot in the swap partition; Generate a swap page table entry according to the page slot identifier; The process page table entry corresponding to the swap memory page is updated according to the swap page table entry, and the swap memory page is written back to the free page slot corresponding to the page slot identifier.
5. The method according to claim 1, characterized in that: The reclaiming of the updated target memory page in the exchange linked list to obtain a free memory page comprises: Sequentially traverse the target memory page in the updated exchange linked list to obtain a write-back status corresponding to the target memory page; When the write-back status is write-back completion, the target data in the target memory page is cleared to obtain the free memory page.
6. The method according to claim 1, characterized in that The method further comprises: Reading a swap descriptor corresponding to the target memory page, wherein the swap descriptor is used to mark the specific anonymous memory page as the swap memory page; The target memory page whose swap descriptor is cleared is extracted from the swap linked list, and the target memory page is added to the anonymous linked list.
7. The method according to claim 1, characterized in that The method further comprises: When a plurality of the memory recycling tasks are acquired within a preset time period, calling a preset lock mechanism to set the status of the memory recycling tasks; When the state corresponding to the memory recycling task is executable, executing the step of obtaining target memory page information corresponding to the swap linked list according to the memory recycling task; When the state corresponding to the memory reclaiming task is locked, the memory reclaiming task is intercepted until the execution of a previous memory reclaiming task corresponding to the memory reclaiming task is completed.
8. A memory recycling processing device, characterized in that: The device comprises: A task acquisition module, used to acquire a memory recovery task, wherein the memory recovery task carries a condition of memory to be recovered; An information acquisition module is used to acquire target memory page information corresponding to a swap list according to the memory recycling task; the swap list is used to store swap memory pages in the memory; the swap memory page refers to an anonymous memory page marked as to be written back to the swap partition; the target memory page information is information corresponding to the swap memory page; the target memory page is a swap memory page to be recycled in the swap list; A linked list traversal module, used for traversing an anonymous linked list when the target memory page information does not meet the memory condition to be reclaimed, and marking a specific anonymous memory page in the anonymous linked list as a swap memory page; the specific anonymous memory page is an anonymous memory page in the anonymous linked list that has not been accessed recently and has a process mapping; A linked list updating module, used for updating the exchange linked list according to the exchange memory page in the anonymous linked list; The memory recycling module is used to recycle the target memory page in the updated exchange linked list to obtain a free memory page.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
