Memory reclamation method and apparatus, device, medium, and product
By monitoring and migrating the storage occupancy of two-level SWAP devices in the computer system, the problem of high-priority devices being occupied by data that has not been used for a long time is solved, and storage space is released and performance is improved.
Patent Information
- Application Number
- PCT/CN2023/131408
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-01-18
- Filing Date
- 2023-11-14
- Publication Date
- 2024-09-19
AI Technical Summary
Memory recycling data that has not been used for a long time in the computer system is difficult to swap in after being swapped out to a high-priority SWAP device, causing the high-priority device to become unavailable. Memory recycling data that is used more frequently can only be swapped out to secondary devices. , affecting the data swapping speed.
By monitoring the storage occupancy of at least two levels of SWAP devices, when the storage occupancy of the upper-level SWAP device reaches the watermark threshold, the least recently used data to be migrated is determined and migrated to the lower-level SWAP device, thereby freeing up the storage space of the upper-level device. , so that data with higher frequency of use can be swapped out to the upper-level device.
It realizes the release of storage space of upper-level SWAP devices, avoids performance degradation caused by unbalanced use of multi-level SWAP devices, and improves the memory utilization and performance of the computer system.
Smart Images

Figure CN2023131408_19092024_PF_FP_ABST
Abstract
Description
Memory recycling method, device, equipment, medium and product
[0001] This application claims priority to Chinese patent application No. 202310089221.X filed on January 18, 2023, entitled “Memory Recovery Method, Device, Equipment, Medium and Product,” the entire contents of which are incorporated herein by reference. Technical Field
[0002] The embodiments of the present application relate to the field of memory recycling technology, and in particular to a memory recycling method, apparatus, device, storage medium, and product. Background Art
[0003] To improve performance, most applications in computer systems adopt a memory-intensive strategy, maximizing memory utilization and improving cache performance. Consequently, many applications occupy memory for extended periods of time. However, as the system's memory gradually becomes depleted, applications are unable to access more memory, necessitating memory reclamation.
[0004] In the related art, the memory pressure of a computer system is reduced by reclaiming data from some of the memory in the computer system and swapping it out to a SWAP (swap) device. The computer system supports at least two levels of SWAP devices, each with a different priority and thus a different order of use. The rule for using SWAP devices is to give priority to using the SWAP device with the first priority. When the SWAP device with the first priority is used up, the SWAP device with the second priority is used. The higher the priority of the SWAP device, the faster the access speed.
[0005] However, since memory recycling data that has not been used for a long time in the computer system will not be swapped in again for a long time once it is swapped out to the SWAP device with the first priority, the above method will cause a large amount of memory recycling data that has not been used for a long time to accumulate on the SWAP device with the first priority, thereby making the SWAP device with the first priority unusable, and the memory recycling data with a relatively high usage frequency can only be swapped out to the secondary SWAP device, thereby affecting the speed of swapping in the memory recycling data with a relatively high frequency.
[0006] Summary of the Invention
[0007] This application provides a memory recovery method, device, equipment, storage medium, and product. The technical solution is as follows:
[0008] According to one aspect of the present application, a memory reclamation method is provided, the method being executed by a computer system including at least two levels of SWAP devices, the method comprising:
[0009] Monitoring storage usage of the at least two levels of SWAP devices, wherein the at least two levels of SWAP devices include an upper-level SWAP device and a lower-level SWAP device;
[0010] When the storage usage of the upper-level SWAP device reaches a watermark threshold, determining the least recently used data to be migrated stored in the upper-level SWAP device;
[0011] Migrate the data to be migrated from the upper-level SWAP device to the lower-level SWAP device.
[0012] According to another aspect of the present application, a memory recovery device is provided, wherein the device includes at least two levels of SWAP devices, and the device includes:
[0013] A monitoring module, configured to monitor the storage usage of the at least two levels of SWAP devices, wherein the at least two levels of SWAP devices include an upper-level SWAP device and a lower-level SWAP device;
[0014] a determination module, configured to determine the least recently used data to be migrated stored in the upper-level SWAP device when the storage usage of the upper-level SWAP device reaches a watermark threshold;
[0015] The migration module is used to migrate the data to be migrated from the upper-level SWAP device to the lower-level SWAP device.
[0016] According to another aspect of the present application, a computer device is provided, comprising: a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set, or an instruction set, and the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the memory recovery method described above.
[0017] According to another aspect of the present application, a computer-readable storage medium is provided, which stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by a processor to implement the memory recovery method described above.
[0018] According to another aspect of the present application, a computer program product is provided, which includes at least one program segment, and the at least one program segment is stored in a computer-readable storage medium; a processor of a computer device reads the at least one program segment from the computer-readable storage medium, and the processor executes the at least one program segment, so that the computer device executes the memory recovery method described above.
[0019] The beneficial effects of the technical solution provided by this application include at least:
[0020] By monitoring the storage occupancy of at least two levels of SWAP devices, when the storage occupancy of the upper-level SWAP device reaches the watermark threshold, the least recently used data to be migrated stored in the upper-level SWAP device is migrated to the lower-level SWAP device, so that the least recently used data to be migrated stored in the upper-level SWAP device can be swapped out to the lower-level SWAP device, so that the storage space in the upper-level SWAP device can be released, thereby swapping out the memory recovery data with relatively high usage frequency to the upper-level SWAP device, avoiding the performance degradation of the computer system due to the unbalanced use of multi-level SWAP devices. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] FIG1 is a block diagram of a computer system provided by an exemplary embodiment of the present application;
[0022] FIG2 is a structural block diagram of a memory recycling method provided by an exemplary embodiment of the present application;
[0023] FIG3 is a flowchart of a memory recycling method provided by an exemplary embodiment of the present application;
[0024] FIG4 is a schematic diagram of a memory recycling method provided by an exemplary embodiment of the present application;
[0025] FIG5 is a flowchart of a memory recycling method provided by an exemplary embodiment of the present application;
[0026] FIG6 is a schematic diagram of a memory recycling method provided by an exemplary embodiment of the present application;
[0027] FIG7 is a flowchart of a memory recycling method provided by an exemplary embodiment of the present application;
[0028] FIG8 is a schematic diagram of a memory recycling method provided by an exemplary embodiment of the present application;
[0029] FIG9 is a flowchart of a memory recycling method provided by an exemplary embodiment of the present application;
[0030] FIG10 is a flowchart of a memory recycling method provided by an exemplary embodiment of the present application;
[0031] FIG11 is a flowchart of a memory recycling method provided by an exemplary embodiment of the present application;
[0032] FIG12 is a block diagram of a memory recycling device provided by an exemplary embodiment of the present application;
[0033] FIG13 is a block diagram of a computer device provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0034] First, a brief introduction to the terms involved in the embodiments of this application is given:
[0035] SWAP (Exchange): When the physical memory of the computer system is insufficient, part of the storage space in the physical memory is released and temporarily saved in a pre-set storage space.
[0036] SWAP device: refers to the temporary storage space for memory data in a computer system. It is used to store data from physical memory to make more free physical memory. When the physical memory of the computer system is insufficient, some memory data in the physical memory is swapped out to the SWAP device.
[0037] Multi-level swap devices: These are swap devices with different priorities in a computer system. Generally, when swapping out memory data, the computer system prioritizes the swap device with the highest priority. Lower-priority swap devices are used only after the higher-priority swap devices have been used up. The higher the priority of the swap device, the faster it is accessed.
[0038] Least Recently Used (LRU) refers to a common algorithm in computer systems. By maintaining an LRU linked list, the computer system can quickly identify the least recently used memory data. Specifically, the computer system places the most recently used memory data at the head of the LRU linked list. When accessing memory data in the cache, the memory data is moved to the head of the LRU linked list. In other words, the memory data at the end of the LRU linked list is the least recently used memory data. For a detailed introduction to the LRU algorithm, please refer to the website: https: / / blog.csdn.net / belongtocode / article / details / 102989685.
[0039] SWAP Entry: refers to an entry in the SWAP device that is used to store or record the physical address of the corresponding memory reclaim data. It includes information such as the identifier of the SWAP device where the memory reclaim data is located and the offset of the memory reclaim data in the SWAP device.
[0040] Fig. 1 shows a block diagram of a computer system 100 provided by an exemplary embodiment of the present application. The computer system 100 includes a server or a cluster of several servers.
[0041] The server includes a hardware layer 110 , an operating system layer 120 , and an application layer 130 .
[0042] The hardware layer 110 includes at least one of a power supply, a central processing unit (CPU), a memory, a hard disk, a network device, an input / output device (I / O device), a fan, and an optical drive. As shown in Figure 1, a CPU 111, a memory 112, and a hard disk 113 are taken as an example. The hardware layer 110 is also provided with a virtual memory space for temporarily storing memory recovery data of the computer system 100. The virtual memory is also referred to as a SWAP device 1131. The SWAP device 1131 is mainly used to release part of the memory space in the physical memory when the physical memory in the computer system 100 is insufficient, and to save the memory recovery data in the released part of the memory space to the SWAP device 1131. In the embodiment of the present application, the SWAP device is taken as an example of a hard disk. Those skilled in the art should be able to know that the SWAP device can also be a reserved memory area in the computer system.
[0043] A computer system includes multiple SWAP devices, each with a different usage priority. Generally, SWAP devices with higher priorities are used first. Lower-priority SWAP devices are used only after the higher-priority SWAP devices have been fully utilized. For example, the computer system 100 shown in FIG1 includes SWAP device 1132, SWAP device 1133, and SWAP device 1134. SWAP device 1132 has a higher priority than SWAP device 1133, and SWAP device 1133 has a higher priority than SWAP device 1134. Computer system 100 prioritizes using SWAP device 1132 to swap out memory reclaimed data in memory space. As shown in FIG1 , SWAP device 1132 includes memory reclaimed data 11321 that has not been used for a long time and memory reclaimed data 11322 that is relatively frequently used. The memory reclaimed data 11321 that has not been used for a long time and the memory reclaimed data 11322 that is relatively frequently used have completely utilized the free space in SWAP device 1132. Therefore, the computer system 100 continues to use the SWAP device 1133 to swap out the memory recovery data in the memory space. As shown in Figure 1, the SWAP device 1133 includes memory recovery data 11331 that has not been used for a long time, memory recovery data 11332 that is used relatively frequently, and remaining free space 11333. When the free space in the SWAP device 1133 has not been fully used, the computer system 100 does not continue to use the SWAP device 1134, so the SWAP device 1134 only includes free space 11341. In the embodiment of the present application, three-level SWAP devices, namely, a memory optimization (ZRAM) device, a non-volatile memory express (NVME) device, and a mechanical hard disk (HDD), are taken as examples. Among them, ZRAM has the highest priority and the fastest access speed; NVME has a lower priority than ZRAM, and its access speed is lower than ZRAM's; SDD / HDD / Hybrid has the lowest priority, lower than NVME's priority; and its access speed is the slowest, lower than NVME's. If the memory recycling method proposed in this application is not used, relying on the existing SWAP device balancing mechanism in the computer system will quickly lead to a large amount of memory recycling data that has not been used for a long time being deposited in the SWAP device with the highest priority.
[0044] The operating system layer 120 is mainly used to implement the allocation of various resources and the management of multiple processes in the computer system 100. In the embodiment of the present application, the Linux operating system is taken as an example.
[0045] The application layer 130 includes one or more applications running in the computer system 100. As shown in Figure 1, it includes application 1301. Each application includes one or more processes. Those skilled in the art will appreciate that the number of applications may be greater or lesser, for example, there may be only one application, or there may be dozens, hundreds, or even more applications. The embodiments of this application do not limit the number of applications.
[0046] Figure 2 shows a structural diagram of a memory recovery method provided by an exemplary embodiment of the present application. The method includes physical memory 141 and SWAP device 143 in a computer system.
[0047] The physical memory 141 includes at least one or a group of memory data, for example, as shown in Figure 2, including memory data 1, memory data 2, memory data 3, memory data 4 and memory data 5. Those skilled in the art will appreciate that the number of memory data may be more or less, for example, the above-mentioned memory data may be only one, or the above-mentioned memory data may be dozens or hundreds, or more. The embodiment of the present application does not limit the number of memory data. In a computer system, the physical memory 141 corresponds to a memory mapping table 142, and the memory mapping table 142 includes a page table entry (PTE) corresponding to the memory data, which is used to store or record the location of the corresponding memory data in the computer system. For example, PTE1 corresponds to memory data 1, PTE2 corresponds to memory data 2, and PTE3 corresponds to memory data 3.
[0048] The physical memory 141 realizes memory recovery by swapping out the memory data therein to the SWAP device 143. The SWAP device 143 includes the recovered memory recovery data 1421. Each SWAP device maintains an LRU linked list. The LRU linked list is used to maintain the order in which different memory recovery data 1421 are recovered into the SWAP device. The order is generally from the least recently used memory recovery data to the most recently used memory recovery data. Exemplarily, as shown in Figure 2, the SWAP device 143 maintains an LRU linked list 144. The LRU linked list stores or records swap-out placeholders. Exemplarily, the LRU linked list 144 records swap-out placeholder 1, swap-out placeholder 2, swap-out placeholder 3, and swap-out placeholder 4, wherein swap-out placeholder 1, swap-out placeholder 2, swap-out placeholder 3, and swap-out placeholder 4 are arranged in order in the LRU linked list 144. The swap-out placeholder is used to record the storage location information of the memory recovery data 1421. The storage location information includes information such as an identifier of the SWAP device where the memory reclaimed data 1421 is located and an offset of the memory reclaimed data in the SWAP device.
[0049] When memory reclaimed data is swapped out from physical memory 141 to SWAP device 143, the computer system allocates a corresponding swap-out placeholder and inserts the swap-out placeholder into LRU linked list 144. When memory reclaimed data is swapped back into physical memory 141 from SWAP device 143, the computer system writes a new PTE into memory mapping table 142.
[0050] FIG3 is a flow chart of a memory recovery method provided by an exemplary embodiment of the present application. The method is executed by a computer system including at least two levels of SWAP devices, and the method includes:
[0051] Step 220: Monitor the storage usage of at least two levels of SWAP devices.
[0052] Monitoring the storage usage of at least two levels of SWAP devices in a computer system. The at least two levels of SWAP devices include an upper-level SWAP device and a lower-level SWAP device according to different priorities. The upper-level SWAP device has a higher priority than the lower-level SWAP device. Therefore, when the computer system swaps out memory reclaimed data in physical memory, the memory reclaimed data is preferentially swapped out to the upper-level SWAP device.
[0053] The storage occupancy of any one level of SWAP device is separately counted. This storage occupancy refers to the usage of the free space in the SWAP device, which is used to reflect the memory recovery data stored in the SWAP device. For example, as shown in FIG4 , a computer system including an upper-level SWAP device 201 and a lower-level SWAP device 202 is used as an example for illustration. If the upper-level SWAP device 201 includes memory recovery data 2011 that has not been used for a long time, memory recovery data 2012 that is relatively frequently used, and remaining free space 2013, the storage occupancy of the upper-level SWAP device 201 is the sum of the memory recovery data 2011 that has not been used for a long time and the memory recovery data 2012 that is relatively frequently used. If the lower-level SWAP device 202 includes memory recovery data 2021 that has not been used for a long time, memory recovery data 2022 that is relatively frequently used, and remaining free space 2023, the storage occupancy of the lower-level SWAP device 202 is the sum of the memory recovery data 2021 that has not been used for a long time and the memory recovery data 2022 that is relatively frequently used.
[0054] Step 240: When the storage usage of the upper-level SWAP device reaches the watermark threshold, determine the least recently used data to be migrated stored in the upper-level SWAP device.
[0055] When the storage usage of the upper-level SWAP device reaches a watermark threshold, the least recently used data to be migrated stored in the upper-level SWAP device is determined.
[0056] The watermark threshold refers to the usage threshold of the free space in the upper-level SWAP device. The usage threshold is used to indicate that the remaining free space in the upper-level SWAP device is insufficient. When the storage occupancy of the upper-level SWAP device is less than or equal to the watermark threshold, it reflects that the remaining free space in the upper-level SWAP device is sufficient, and the memory can continue to be swapped out and the recovered data can be put into the upper-level SWAP device; when the storage occupancy of the upper-level SWAP device is greater than the watermark threshold, it reflects that the remaining free space in the upper-level SWAP device is insufficient, and there is a possibility that the memory cannot be swapped out and the recovered data cannot be put into the upper-level SWAP device.
[0057] Optionally, the water level threshold can be preset in the computer system, or it can be adjusted in real time according to the operating status of the computer system. For example, the water level threshold can be set to 60% or 80% of the maximum storage space of the upper-level SWAP device. For example, it can be adjusted according to the global pressure stall information (PSI) value of the computer system. When the global PSI value is small, it means that the delay in resource scheduling of the computer system is small at this time, so the water level threshold is lowered to reclaim more memory in time; when the global PSI value is large, it means that the delay in resource scheduling of the computer system is large at this time, so the water level threshold is raised to avoid affecting the normal operation of the computer system.
[0058] In some embodiments, a mapping comparison table between global PSI values and waterline thresholds is obtained; and the waterline thresholds are adjusted according to the corresponding relationship between the global PSI values and the waterline thresholds in the mapping comparison table.
[0059] For example, as the global PSI value decreases, the waterline threshold is adjusted lower; and as the global PSI value increases, the waterline threshold is adjusted higher.
[0060] The least recently used data to be migrated refers to memory reclaimed data stored in the upper-level SWAP device that has not been used for a long time. The least recently used data to be migrated can be quickly found through the LRU linked list maintained in the upper-level SWAP device. For example, as shown in Figure 4, when the storage usage of the upper-level SWAP device 201 reaches the watermark threshold, the memory reclaimed data 2011 in the upper-level SWAP device 201 that has not been used for a long time is determined to be the least recently used data to be migrated.
[0061] Step 260: Migrate the data to be migrated from the upper-level SWAP device to the lower-level SWAP device.
[0062] The least recently used data to be migrated stored in the upper-level SWAP device determined above is migrated from the upper-level SWAP device to the lower-level SWAP device. For example, as shown in FIG4 , it is determined that the least recently used data to be migrated stored in the upper-level SWAP device 201 is memory reclaimed data 2011 that has not been used for a long time. The memory reclaimed data is migrated from the upper-level SWAP device 201 to the lower-level SWAP device 202 to free up storage space in the upper-level SWAP device 201.
[0063] In some embodiments, when there is only one lower-level SWAP device and the space occupied by the data to be migrated is less than or equal to the space size of the target storage location, the data to be migrated is migrated from the upper-level SWAP device to the target storage location in the lower-level SWAP device.
[0064] In some embodiments, when there is only one lower-level SWAP device and the space required for the data to be migrated is larger than the space size of the target storage location, part of the data to be migrated is migrated from the upper-level SWAP device to the target storage location in the lower-level SWAP device.
[0065] The space occupied by part of the data to be migrated is equal to the space of the target storage location in the lower-level SWAP device. That is, when the target storage location is insufficient to accommodate the data to be migrated, only part of the data to be migrated is accommodated.
[0066] For example, the target storage location in the lower-level SWAP device can accommodate 520M of data, and the data size of the data to be migrated is 888M. The target storage location is not enough to accommodate all the data to be migrated. Therefore, part of the data to be migrated is placed in the lower-level SWAP device, that is, only 520M of data to be migrated is placed.
[0067] Optionally, a method for determining the portion of data to be migrated includes at least one of the following methods, but is not limited thereto:
[0068] Randomly select data from the data to be migrated;
[0069] Select data to be migrated based on the storage time of each data item. For example, sort the data to be migrated in descending order of storage time, and select some data to be migrated based on storage time.
[0070] Select data to be migrated based on the space occupied by each data item; for example, sort the data to be migrated in descending order of the space occupied by each data item, and select some data to be migrated based on the space occupied by the data items.
[0071] In some embodiments, when there are multiple lower-level SWAP devices, a lower-level SWAP device for storing the data to be migrated is selected according to the priorities of the multiple lower-level SWAP devices; the data to be migrated is migrated from the upper-level SWAP device to the target storage location in the lower-level SWAP device.
[0072] In some embodiments, when there are multiple lower-level SWAP devices, a lower-level SWAP device for placing the data to be migrated is selected based on the priorities of the multiple lower-level SWAP devices; when the space required for the data to be migrated is larger than the space size of the target storage location, the priorities of the multiple lower-level SWAP devices are rearranged, and a lower-level SWAP device with a target storage location space larger than the space required for the data to be migrated and a higher original priority is selected from the updated multiple lower-level SWAP devices as the lower-level SWAP device for storing the data to be migrated, and the data to be migrated is migrated from the upper-level SWAP device to the target storage location in the lower-level SWAP device.
[0073] To sum up, the method provided in this embodiment monitors the storage occupancy of at least two levels of SWAP devices. When the storage occupancy of the upper-level SWAP device reaches the watermark threshold, the least recently used data to be migrated stored in the upper-level SWAP device is migrated to the lower-level SWAP device, thereby swapping out the least recently used data to be migrated stored in the upper-level SWAP device to the lower-level SWAP device, freeing up the storage space in the upper-level SWAP device and avoiding performance degradation of the computer system due to unbalanced use of multi-level SWAP devices.
[0074] FIG5 is a flowchart of a memory reclamation method provided by an exemplary embodiment of the present application. The method is executed by a computer system, and the above step 260 further includes at least one of the following sub-steps:
[0075] Step 261: Determine an idle target storage location in the lower-level SWAP device.
[0076] A target storage location that is free is determined in the lower-level SWAP device. The target storage location refers to the remaining free space in the lower-level SWAP device, excluding the memory reclaimed data that has been stored in the physical memory and has not been used for a long time and the memory reclaimed data that is used relatively frequently. This remaining free space can be used to continue storing the memory reclaimed data. For example, as shown in FIG4 , the remaining free space 2023 in the lower-level SWAP device 202 is the target storage location.
[0077] Step 262: Migrate the data to be migrated from the upper-level SWAP device to the target storage location of the lower-level SWAP device.
[0078] The least recently used data to be migrated stored in the upper-level SWAP device determined above is migrated from the upper-level SWAP device to the target storage location of the lower-level SWAP device. For example, as shown in FIG6 , it is determined that the least recently used data to be migrated stored in the upper-level SWAP device 201 is memory reclaimed data 2011 that has not been used for a long time. The memory reclaimed data is migrated from the upper-level SWAP device 201 to the remaining free space 2023 in the lower-level SWAP device 202 to free up storage space in the upper-level SWAP device 201.
[0079] Step 263: Based on the target storage location, update the LRU linked list of the lower-level SWAP device.
[0080] Based on the target storage location that is idle in the lower-level SWAP device, the LRU linked list of the lower-level SWAP device is updated. In this embodiment, any SWAP device includes an LRU linked list, and the LRU linked list is used to maintain the order in which different memory recovery data are recovered into the SWAP device. The order is generally from the least recently used memory recovery data to the most recently used memory recovery data. When the memory recovery data is migrated from the upper-level SWAP device to the lower-level SWAP device, the LRU linked list corresponding to the upper-level SWAP device and the LRU linked list corresponding to the lower-level SWAP device need to be modified accordingly, including removing the swap-out placeholder corresponding to the data to be migrated in the LRU linked list of the upper-level SWAP device, and inserting the swap-out placeholder corresponding to the data to be migrated in the LRU linked list of the lower-level SWAP device. Exemplarily, as shown in Figure 6, the upper-level SWAP device 201 corresponds to LRU linked list 1, and the lower-level SWAP device 202 corresponds to LRU linked list 2. Based on the target storage location of the lower-level SWAP device 202 , the LRU linked list 2 of the lower-level SWAP device 202 is updated, and the swapped-out placeholder corresponding to the target storage location is inserted into the LRU linked list 2 of the lower-level SWAP device 202 .
[0081] To sum up, the method provided in this embodiment migrates the data to be migrated from the upper-level SWAP device to the target storage location of the lower-level SWAP device and updates the LRU linked list of the lower-level SWAP device, thereby swapping out the least recently used data to be migrated stored in the upper-level SWAP device to the lower-level SWAP device, thereby releasing the storage space in the upper-level SWAP device and updating the LRU linked list corresponding to the lower-level SWAP device, thereby avoiding the computer system being unable to accurately determine the storage location of memory recovery data due to untimely updates.
[0082] FIG7 is a flowchart of a memory recovery method provided by an exemplary embodiment of the present application, which is executed by a computer system. The above step 263 also includes at least one of the following sub-steps:
[0083] Step 2631: Allocate a lower-level swap-out placeholder pointing to the target storage location for the data to be migrated.
[0084] A lower-level swap-out placeholder item pointing to a target storage location is allocated to the least recently used data to be migrated stored in the upper-level SWAP device determined above.
[0085] The swap-out placeholder is used to record the storage location information of the memory recovery data. The storage location information includes information such as the identifier of the SWAP device where the memory recovery data is located and the offset of the memory recovery data in the SWAP device. When the memory recovery data is swapped out to the SWAP device, the computer system allocates a corresponding swap-out placeholder and writes the swap-out placeholder into the page table location where the PTE corresponding to the memory recovery data in the physical memory is located. Exemplarily, as shown in Figure 8, the memory recovery data in the upper-level SWAP device 201 corresponds to swap-out placeholder 1, and swap-out placeholder 1 includes the identifier of the upper-level SWAP device 201, the offset of the corresponding memory recovery data, etc. The memory recovery data in the lower-level SWAP device 202 corresponds to swap-out placeholder 2, and swap-out placeholder 2 includes the identifier of the lower-level SWAP device 202, the offset of the corresponding memory recovery data, etc.
[0086] When migrating data to be migrated from the upper-level SWAP device to the target storage location of the lower-level SWAP device, a lower-level swap-out placeholder entry pointing to the target storage location is allocated to the data to be migrated, such as swap-out placeholder entry 2 .
[0087] Step 2632: Based on the lower-level swapped-out placeholder, update the LRU linked list of the lower-level SWAP device.
[0088] Based on the lower-level swap-out placeholder pointing to the target storage location, the LRU linked list of the lower-level SWAP device is updated. In the present embodiment, any SWAP device includes an LRU linked list, and the LRU linked list is used to maintain the order in which different memory recovery data are recovered into the SWAP device. The order is generally from the least recently used memory recovery data to the most recently used memory recovery data. The LRU linked list stores the lower-level swap-out placeholders of different memory recovery data in sequence according to the storage time. Exemplarily, as shown in Figure 8, according to the corresponding lower-level swap-out placeholder 2 in the lower-level SWAP device 202, the LRU linked list 2 of the lower-level SWAP device is updated, and the lower-level swap-out placeholder 2 is added to the corresponding position in the LRU linked list 2.
[0089] In some embodiments, the upper-level SWAP device and the lower-level SWAP device each correspond to an LRU linked list.
[0090] After the lower-level swap-out placeholder is determined, the following methods are used to update the LRU list of the lower-level SWAP device:
[0091] The computer system inserts the lower-level swap-out placeholder corresponding to the data to be migrated into the LRU linked list of the lower-level SWAP device.
[0092] Optionally, the lower-level swap-out placeholder includes the identifier of the lower-level SWAP device, the offset of the data to be migrated in the lower-level SWAP device, etc.; the computer system inserts the identifier of the lower-level SWAP device corresponding to the data to be migrated, the offset of the data to be migrated in the lower-level SWAP device, etc. into the LRU linked list of the lower-level SWAP device.
[0093] After determining the lower-level swap-out placeholder, the methods for updating the upper-level SWAP device's LRU list include:
[0094] The computer system removes the upper-level swap-out placeholder item corresponding to the data to be migrated in the LRU linked list of the upper-level SWAP device.
[0095] Optionally, the upper swap-out placeholder includes the identifier of the upper SWAP device, the offset of the data to be migrated in the upper SWAP device, etc.; the computer system removes the identifier of the upper SWAP device corresponding to the data to be migrated in the LRU linked list of the upper SWAP device, the offset of the data to be migrated in the upper SWAP device, etc.
[0096] To sum up, the method provided in this embodiment updates the LRU linked list of the lower-level SWAP device by allocating a lower-level swap-out placeholder pointing to the target storage location for the data to be migrated, thereby updating the LRU linked list corresponding to the lower-level SWAP device according to the swap-out placeholder corresponding to the memory recovery data, thereby avoiding the computer system being unable to accurately determine the storage location of the memory recovery data due to untimely updates.
[0097] FIG9 is a flowchart of a memory recovery method provided by an exemplary embodiment of the present application, which is executed by a computer system. The above step 240 can also be implemented by step 241:
[0098] Step 241: when the storage usage of the upper-level SWAP device reaches the watermark threshold, the least recently used data to be migrated stored in the upper-level SWAP device is determined based on the LRU linked list corresponding to the upper-level SWAP device.
[0099] When the storage occupancy of the upper-level SWAP device reaches the watermark threshold, the least recently used data to be migrated stored in the upper-level SWAP device is determined based on the LRU linked list corresponding to the upper-level SWAP device. The watermark threshold refers to the usage threshold of the free space in the upper-level SWAP device. The usage threshold is used to indicate that the remaining free space in the upper-level SWAP device is insufficient. When the storage occupancy of the upper-level SWAP device is less than or equal to the watermark threshold, it reflects that the remaining free space in the upper-level SWAP device is sufficient and memory recovery data can continue to be swapped out to the upper-level SWAP device; when the storage occupancy of the upper-level SWAP device is greater than the watermark threshold, it reflects that the remaining free space in the upper-level SWAP device is insufficient and there is a possibility that memory recovery data cannot be swapped out to the upper-level SWAP device. The watermark threshold can be preset in the computer system or adjusted in real time according to the operating status of the computer system. For example, the watermark threshold can be set to 60% or 80% of the maximum storage space of the upper-level SWAP device.
[0100] At least two levels of SWAP devices each correspond to their own LRU linked lists. For example, as shown in Figure 6, the upper-level SWAP device 201 corresponds to LRU linked list 1, and the lower-level SWAP device 202 corresponds to LRU linked list 2. The LRU linked list is used to maintain the order in which different memory recovery data are recovered into the current SWAP device. The order is generally from the least recently used memory recovery data to the most recently used memory recovery data. When migrating memory recovery data from the upper-level SWAP device to the lower-level SWAP device, the LRU linked list corresponding to the upper-level SWAP device and the LRU linked list corresponding to the lower-level SWAP device need to be modified accordingly, including removing the swap-out placeholder corresponding to the data to be migrated in the LRU linked list of the upper-level SWAP device, and inserting the swap-out placeholder corresponding to the data to be migrated into the LRU linked list of the upper-level SWAP device. The least recently used data to be migrated refers to the memory recovery data stored in the upper-level SWAP device that has not been used for a long time. The least recently used data to be migrated can be quickly found through the LRU linked list maintained in the upper-level SWAP device.
[0101] To sum up, the method provided in this embodiment determines the least recently used data to be migrated stored in the upper-level SWAP device based on the LRU linked list corresponding to the upper-level SWAP device, and swaps out the least recently used data to be migrated stored in the upper-level SWAP device to the lower-level SWAP device, so that the storage space in the upper-level SWAP device can be released, avoiding the performance degradation of the computer system due to the unbalanced use of multi-level SWAP devices.
[0102] FIG10 is a flow chart of a memory recovery method provided by an exemplary embodiment of the present application. The method is executed by a computer system, and the method further includes:
[0103] Step 320: In the memory mapping table, replace the upper-level swap-out placeholder entry in the page table entry corresponding to the data to be migrated with the lower-level swap-out placeholder entry.
[0104] In a computer system, the physical memory corresponds to a memory mapping table, which includes the PTE corresponding to the memory data. The PTE is used to store or record the location of the corresponding memory data in the physical memory. When the corresponding memory data is swapped out from the physical memory to the SWAP device, the computer system reallocates a swap-out placeholder corresponding to the recovered memory data. The swap-out placeholder is used to record the storage location information of the memory recovery data. The storage location information includes information such as the identifier of the SWAP device where the memory recovery data is located and the offset of the memory recovery data in the SWAP device. The computer system also writes the swap-out placeholder to the PTE location corresponding to the memory data before it is swapped out from the physical memory. When the computer system accesses the swap-out placeholder, a page fault occurs. The computer system captures the information of the page fault to swap the memory data into the physical memory and simultaneously releases the swap-out placeholder on the SWAP device.
[0105] When the least recently used data to be migrated, stored in the upper-level SWAP device, is migrated from the upper-level SWAP device to the target storage location in the lower-level SWAP device, the upper-level swap-out placeholder corresponding to the data to be migrated is updated with the new lower-level swap-out placeholder. At this point, the location corresponding to the data to be migrated changes. In the memory mapping table, the upper-level swap-out placeholder in the page table entry corresponding to the data to be migrated is also replaced with the lower-level swap-out placeholder.
[0106] To sum up, the method provided in this embodiment replaces the upper-level swap-out placeholder item in the page table entry corresponding to the data to be migrated with the lower-level swap-out placeholder item in the memory mapping table, thereby replacing the upper-level swap-out placeholder item in the memory mapping table with the lower-level swap-out placeholder item according to the swap-out placeholder item corresponding to the data to be migrated, thereby avoiding the computer system being unable to accurately determine the storage location of memory recovered data due to untimely updates.
[0107] FIG11 is a flowchart of a memory recovery method provided by an exemplary embodiment of the present application, the method being executed by a computer system. The method further includes:
[0108] Step 420: When the storage usage of the upper-level SWAP device reaches the watermark threshold and the upper-level SWAP device has at least two lower-level SWAP devices, a target lower-level SWAP device for this migration is selected from the at least two lower-level SWAP devices.
[0109] The watermark threshold refers to the usage threshold of the free space in the upper-level SWAP device. The usage threshold is used to indicate that the remaining free space in the upper-level SWAP device is insufficient. When the storage occupancy of the upper-level SWAP device is less than or equal to the watermark threshold, it reflects that the remaining free space in the upper-level SWAP device is sufficient and memory can continue to be swapped out and recovered data can be transferred to the upper-level SWAP device. When the storage occupancy of the upper-level SWAP device is greater than the watermark threshold, it reflects that the remaining free space in the upper-level SWAP device is insufficient and there is a possibility that memory cannot be swapped out and recovered data cannot be transferred to the upper-level SWAP device. The watermark threshold can be preset in the computer system or adjusted in real time according to the operating status of the computer system. For example, the watermark threshold can be set to 60% or 80% of the maximum storage space of the upper-level SWAP device.
[0110] When the storage usage of the upper-level SWAP device reaches the watermark threshold and the upper-level SWAP device has at least two lower-level SWAP devices, a lower-level SWAP device is selected as the target for this migration from the at least two lower-level SWAP devices. The at least two lower-level SWAP devices are those whose usage order in the computer system has a lower priority than that of the upper-level SWAP device. Among the at least two lower-level SWAP devices, the SWAP device with a higher priority is arranged first in the computer system usage order, and the SWAP device with a lower priority is arranged last in the computer system usage order.
[0111] In some embodiments, the lower-level SWAP device with the largest free storage capacity among at least two lower-level SWAP devices is selected as the target lower-level SWAP device for this migration. The free storage capacity refers to the remaining free space of the SWAP device for storing or swapping out memory data.
[0112] In some embodiments, the lower-level SWAP device with the highest priority among at least two lower-level SWAP devices is selected as the target lower-level SWAP device for this migration.
[0113] In some embodiments, the lower-level SWAP device with the lowest priority among the at least two lower-level SWAP devices is selected as the target lower-level SWAP device for this migration.
[0114] To sum up, the method provided in this embodiment selects the target lower-level SWAP device for this migration from at least two lower-level SWAP devices when the upper-level SWAP device has at least two lower-level SWAP devices, thereby realizing the selection of corresponding migration methods or combinations according to different needs, thereby freeing up the storage space in the upper-level SWAP device and avoiding the performance degradation of the computer system due to the unbalanced use of multiple SWAP devices.
[0115] The embodiment of the present application proposes a memory recycling method that can automatically evaluate memory usage based on the characteristics of SWAP devices and balance the use of multi-level memory SWAP devices, thereby increasing the available memory of the computer system while taking into account performance. This method can fully utilize high-performance SWAP devices while maintaining a dynamic balance in the utilization of SWAP devices at different levels, avoiding performance degradation caused by unbalanced device utilization, and can adapt to any number and level of SWAP devices, without any additional overhead when swapping memory data from SWAP devices to physical memory.
[0116] The following uses the ZRAM device as the highest-level swap device as a general deployment example. The memory reclamation strategy should prioritize the use of the ZRAM device whenever possible to ensure swap-in and swap-out performance. After a computer system has been operating for a long time, the ZRAM device is often occupied by a large number of cold pages (memory data that has not been used for a long time) and cannot be fully utilized. This causes hot pages (memory data with relatively high frequency of use) to be squeezed into lower-level swap devices. Furthermore, the ZRAM device itself contains resident memory, which prevents memory from being fully released.
[0117] For example, consider the three-level SWAP devices: ZRAM, NVME, and HDD. ZRAM devices have the best performance and are the highest priority device, followed by NVME devices and HDD devices. Without using the memory reclamation method proposed in this application, a large number of cold pages will quickly accumulate in the highest-priority SWAP device.
[0118] In the embodiment of the present application, a watermark threshold is set for each SWAP device. When the usage of the SWAP device exceeds the watermark threshold, the coldest page is automatically flushed to a slower and cheaper SWAP device. The watermark threshold refers to the usage threshold of the free space in the upper-level SWAP device. The usage threshold is used to indicate that the remaining free space in the upper-level SWAP device is insufficient. When the storage occupancy of the upper-level SWAP device is less than or equal to the watermark threshold, it reflects that the remaining free space in the upper-level SWAP device is sufficient, and the memory recovery data can continue to be swapped out to the upper-level SWAP device; when the storage occupancy of the upper-level SWAP device is greater than the watermark threshold, it reflects that the remaining free space in the upper-level SWAP device is insufficient, and there is a possibility that the memory recovery data cannot be swapped out to the upper-level SWAP device. The water level threshold can be preset in the computer system, or it can be adjusted in real time according to the operating status of the computer system. For example, the water level threshold can be set to 60% or 80% of the maximum storage space of the upper-level SWAP device. It can be adjusted according to the global pressure stall information (PSI) value of the computer system. When the global PSI value is small, it means that the delay in resource scheduling of the computer system is small at this time, so the water level threshold is lowered to reclaim more memory in time; when the global PSI value is large, it means that the delay in resource scheduling of the computer system is large at this time, so the water level threshold is raised to avoid affecting the normal operation of the computer system.
[0119] By using the memory reclamation method proposed in an embodiment of the present application, memory reclaimed data in a high-priority SWAP device is released. The method includes migrating the coldest page in the ZRAM device to the NVME device, and then migrating the coldest page in the NVME device to the HDD device. This frees up space in the highest-priority ZRAM device, allowing hot pages to use the ZRAM device first, which not only ensures the operating performance of the computer system but also further reduces the memory pressure of the computer system.
[0120] The memory recovery method proposed in this application does not require modifying the existing SWAP device swap-out strategy, but instead performs balancing through a separate set of processes, which is less invasive and ensures that the logic is simple, understandable, and maintainable.
[0121] The memory recovery method proposed in this application is compatible with any multi-level SWAP devices. There is no need to make changes to SWAP devices with different rates and access methods. After meeting the engineering design requirements, it can automatically adapt to all types of SWAP devices.
[0122] The memory recovery method proposed in this application needs to implement hot and cold statistics of memory pages swapped out on the SWAP device. Virtual memory technology is the basis of memory management. The physical memory seen by each process has been mapped through a layer of page table, and each page table entry is a PTE pointing to a physical address. When swapping out, a SWAP device is selected and a swap-out placeholder is allocated. The swap-out placeholder is written to the page table location where the original PTE is located, and the physical memory page originally pointed to is released. The swap-out placeholder records the identifier of the SWAP device where the memory page is located, as well as information such as the offset. When a process accesses the swap-out placeholder, a page fault occurs. By capturing the page fault, the memory data is swapped from the SWAP device to the physical memory, and the swap-out placeholder on the SWAP device is released.
[0123] The memory reclamation method proposed in this application maintains a LRU linked list for each SWAP device. When a memory page is swapped out to a SWAP device, the swap-out placeholder assigned to that memory page is synchronously recorded in the LRU linked list. Since SWAP devices require page faults to be swapped in, and the allocation and release of swap-out placeholders also occur, they must be processed by the LRU linked list. Therefore, this method can accurately ensure the accuracy of the LRU linked list corresponding to the SWAP device.
[0124] Based on the physical memory pages that have been swapped out, the memory reclamation method provided by the embodiment of the present application includes:
[0125] According to the LRU linked list maintained by each SWAP device, the cold pages are found, among which the memory page that has not been used for the longest time is the coldest page. Determine the target SWAP device for migration. The SWAP device natively supports priority, and the priority can be specified when configuring the SWAP device, or by default, the device that is mounted first has the highest priority. After the usage of a relatively high-performance and high-priority SWAP device reaches the watermark threshold, find the first relatively idle SWAP device according to the priority. In the newly selected SWAP device, a new swap placeholder is directly allocated, and the corresponding content in the old swap placeholder is completely copied over, so that the newly selected SWAP device has a complete copy of the content of the old swap placeholder. Modify the page table and make the new page table point to the new swap placeholder. After the migration is completed, the PTE in the original page table still points to the swap placeholder in the old SWAP device, so it is necessary to modify the page table to point to the swap placeholder in the new SWAP device. The memory recovery method provided in the embodiment of the present application uses an asynchronous process for migration throughout the process, and the page table entry is directly changed by the process. When a page fault occurs again and memory data needs to be swapped in, the corresponding SWAP device after migration is directly read.
[0126] The memory reclamation method provided in the embodiments of the present application manages the heat level of swapped memory pages by maintaining an independent LRU linked list for each SWAP device. By migrating cold pages, it automatically balances multiple SWAP devices. This design balances versatility, performance, and accuracy. In a computer system using multiple SWAP devices, SWAP devices of different priorities can be fully utilized, thereby reducing memory pressure in the computer system and ensuring operational performance.
[0127] FIG12 shows a block diagram of a memory recovery device provided by an exemplary embodiment of the present application. The device includes at least two levels of SWAP devices, and the device includes:
[0128] The monitoring module 1210 is configured to monitor the storage usage of at least two levels of SWAP devices, where the at least two levels of SWAP devices include an upper-level SWAP device and a lower-level SWAP device.
[0129] The determining module 1220 is configured to determine the least recently used data to be migrated stored in the upper-level SWAP device when the storage usage of the upper-level SWAP device reaches a watermark threshold.
[0130] The migration module 1230 is used to migrate the data to be migrated from the upper-level SWAP device to the lower-level SWAP device.
[0131] The determination module 1220 is further configured to determine an idle target storage location in the lower-level SWAP device.
[0132] The migration module 1230 is further configured to migrate the data to be migrated from the upper-level SWAP device to the target storage location of the lower-level SWAP device. In some embodiments, the apparatus further includes: an update module 1240;
[0133] The updating module 1240 is used to update the LRU linked list of the lower-level SWAP device based on the target storage location.
[0134] The LRU linked list is used to maintain the order in which different memory reclaimed data is recycled to the lower-level SWAP device.
[0135] Illustratively, any SWAP device includes an LRU linked list, which is used to maintain the order in which different memory reclaimed data are reclaimed into the SWAP device. The order is generally from the least recently used memory reclaimed data to the most recently used memory reclaimed data.
[0136] The updating module 1240 is further configured to modify the LRU linked lists corresponding to the upper-level SWAP device and the LRU linked lists corresponding to the lower-level SWAP device when migrating memory reclaimed data from the upper-level SWAP device to the lower-level SWAP device.
[0137] The updating module 1240 is further configured to remove the swap-out placeholder corresponding to the data to be migrated from the LRU linked list of the upper-level SWAP device.
[0138] The updating module 1240 is further configured to insert a swap-out placeholder corresponding to the data to be migrated into the LRU linked list of the lower-level SWAP device.
[0139] The update module 1240 is further configured to allocate a lower-level swap-out placeholder pointing to a target storage location for the data to be migrated.
[0140] Exemplarily, the swap-out placeholder is used to record storage location information of the memory reclaimed data, including information such as an identifier of the SWAP device where the memory reclaimed data is located and an offset of the memory reclaimed data in the SWAP device.
[0141] In some embodiments, the update module 1240 is also used to allocate a swap-out placeholder when memory reclaimed data is swapped out to the SWAP device, and write the swap-out placeholder into the page table location where the PTE corresponding to the memory reclaimed data in the physical memory is located.
[0142] The updating module 1240 is further configured to update the LRU linked list of the lower-level SWAP device based on the lower-level swapped-out placeholder.
[0143] The LRU linked list stores the lower-level swap-out placeholders with different memory recovery data in sequence according to the storage time.
[0144] At least two levels of SWAP devices each have their own LRU linked list, which is used to maintain the order in which different memory reclaimed data is recycled into the current SWAP device.
[0145] Exemplarily, any SWAP device includes an LRU linked list, which is used to maintain the order in which different memory recovery data are recovered into the SWAP device. The order is generally from the least recently used memory recovery data to the most recently used memory recovery data. The LRU linked list stores the lower-level swap-out placeholders of different memory recovery data in sequence according to the storage time.
[0146] The determination module 1220 is further configured to determine the least recently used data to be migrated stored in the upper-level SWAP device based on the LRU linked list corresponding to the upper-level SWAP device when the storage usage of the upper-level SWAP device reaches the watermark threshold.
[0147] The watermark threshold refers to the usage threshold of the free space in the upper-level SWAP device. The usage threshold is used to indicate that the remaining free space in the upper-level SWAP device is insufficient. When the storage occupancy of the upper-level SWAP device is less than or equal to the watermark threshold, it reflects that the remaining free space in the upper-level SWAP device is sufficient, and the memory recovery data can continue to be swapped out to the upper-level SWAP device; when the storage occupancy of the upper-level SWAP device is greater than the watermark threshold, it reflects that the remaining free space in the upper-level SWAP device is insufficient, and there is a possibility that the memory recovery data cannot be swapped out to the upper-level SWAP device. The watermark threshold can be preset in the computer system or adjusted in real time according to the operating status of the computer system. For example, the watermark threshold can be set to 60% or 80% of the maximum storage space of the upper-level SWAP device. The update module 1240 is also used to replace the upper-level swap-out placeholder item in the page table entry corresponding to the data to be migrated with the lower-level swap-out placeholder item in the memory mapping table.
[0148] Among them, the page table entry is used to store the pointing information of the storage location of the data to be migrated in the physical memory, the upper-level swap-out placeholder item is the pointing information of the storage location of the data to be migrated in the upper-level SWAP device, and the lower-level swap-out placeholder item is the pointing information of the storage location of the data to be migrated in the lower-level SWAP device.
[0149] Exemplarily, in a computer system, the physical memory corresponds to a memory mapping table, and the memory mapping table includes PTEs corresponding to memory data, and the PTEs are used to store or record the locations of the corresponding memory data in the physical memory.
[0150] In some embodiments, the update module 1240 is further configured to reallocate a swap-out placeholder item corresponding to the reclaimed memory data when the corresponding memory data is swapped out from the physical memory to the SWAP device.
[0151] The swap-out placeholder is used to record the storage location information of the memory reclaimed data. The storage location information includes information such as the identifier of the SWAP device where the memory reclaimed data is located and the offset of the memory reclaimed data in the SWAP device. The computer system also writes the swap-out placeholder to the PTE position corresponding to the memory data before it is swapped out from the physical memory. When the computer system accesses the swap-out placeholder, a page fault occurs. By capturing the page fault information, the computer system swaps the memory data into the physical memory and simultaneously releases the swap-out placeholder on the SWAP device.
[0152] In some embodiments, the update module 1240 is further configured to update the upper-level swap-out placeholder corresponding to the data to be migrated to a new corresponding lower-level swap-out placeholder when the least recently used data to be migrated stored in the upper-level SWAP device is migrated from the upper-level SWAP device to the target storage location of the lower-level SWAP device. The migration module 1230 is further configured to select a target lower-level SWAP device for this migration from the at least two lower-level SWAP devices when the storage usage of the upper-level SWAP device reaches a watermark threshold and the upper-level SWAP device has at least two lower-level SWAP devices.
[0153] Exemplarily, the watermark threshold refers to the usage threshold of the free space in the upper-level SWAP device. The usage threshold is used to indicate that the remaining free space in the upper-level SWAP device is insufficient. When the storage occupancy of the upper-level SWAP device is less than or equal to the watermark threshold, it reflects that the remaining free space in the upper-level SWAP device is sufficient, and memory can continue to be swapped out to reclaim data in the upper-level SWAP device. When the storage occupancy of the upper-level SWAP device is greater than the watermark threshold, it reflects that the remaining free space in the upper-level SWAP device is insufficient, and there is a possibility that memory cannot be swapped out to reclaim data in the upper-level SWAP device. The watermark threshold can be preset in the computer system or adjusted in real time according to the operating status of the computer system. For example, the watermark threshold can be set to 60% or 80% of the maximum storage space of the upper-level SWAP device.
[0154] The at least two lower-level SWAP devices have a usage order priority in the computer system that is lower than the usage order priority of the upper-level SWAP device. Among the at least two lower-level SWAP devices, the SWAP device with a higher priority is arranged first in the usage order in the computer system, and the SWAP device with a lower priority is arranged last in the usage order in the computer system.
[0155] The migration module 1230 is further configured to select the lower-level SWAP device with the largest free storage capacity among the at least two lower-level SWAP devices as the target lower-level SWAP device for this migration.
[0156] The migration module 1230 is further configured to select the lower-level SWAP device with the highest priority among the at least two lower-level SWAP devices as the target lower-level SWAP device for this migration.
[0157] The migration module 1230 is further configured to select the lower-level SWAP device with the lowest priority among the at least two lower-level SWAP devices as the target lower-level SWAP device for this migration.
[0158] Figure 13 shows a schematic diagram of the structure of a computer device provided by an exemplary embodiment of the present application. Schematically, the computer device 1300 includes a central processing unit (CPU) 1301, a system memory 1304 including a random access memory (RAM) 1302 and a read-only memory (ROM) 1303, and a system bus 1305 connecting the system memory 1304 and the CPU 1301. The computer device 1300 also includes a basic input / output system (I / O system) 1306 that helps transfer information between various components within the computer, and a mass storage device 1307 for storing an operating system 1313, application programs 1314, and other program modules 1315.
[0159] The basic input / output system 1306 includes a display 1308 for displaying information and an input device 1309 such as a mouse and keyboard for user input. The display 1308 and the input device 1309 are connected to the central processing unit 1301 via an input / output controller 1310 connected to the system bus 1305. The basic input / output system 1306 may also include an input / output controller 1310 for receiving and processing input from a variety of other devices such as a keyboard, mouse, or electronic stylus. Similarly, the input / output controller 1310 also provides output to a display screen, printer, or other types of output devices.
[0160] The mass storage device 1307 is connected to the central processing unit 1301 via a mass storage controller (not shown) connected to the system bus 1305. The mass storage device 1307 and its associated computer-readable media provide non-volatile storage for the computer device 1300. In other words, the mass storage device 1307 may include a computer-readable medium (not shown) such as a hard disk or a compact disc read-only memory (CD-ROM) drive.
[0161] The computer-readable medium may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented by any method or technology for storing information such as computer-readable instructions, data structures, program modules or other data. Computer storage media include RAM, ROM, erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other solid-state storage technologies, CD-ROM, digital versatile disc (DVD) or other optical storage, tape cassettes, magnetic tape, disk storage or other magnetic storage devices. Of course, those skilled in the art will appreciate that the computer storage media are not limited to the above-mentioned ones. The above-mentioned system memory 1304 and mass storage device 1307 can be collectively referred to as memory.
[0162] According to various embodiments of the present application, the computer device 1300 may also be connected to a remote computer on a network such as the Internet for operation. That is, the computer device 1300 may be connected to a network 1312 via a network interface unit 1311 connected to the system bus 1305. Alternatively, the network interface unit 1311 may be used to connect to other types of networks or remote computer systems (not shown).
[0163] An exemplary embodiment of the present application further provides a computer-readable storage medium, in which at least one program is stored. The at least one program is loaded and executed by a processor to implement the memory recovery method provided by each of the above method embodiments.
[0164] An exemplary embodiment of the present application also provides a computer program product, which includes at least one program, and the at least one program is stored in a readable storage medium; the processor of the communication device reads signaling from the readable storage medium, and the processor executes the signaling, so that the communication device executes to implement the memory recovery method provided by the above-mentioned various method embodiments.
Claims
1. A memory recovery method, the method being executed by a computer system, the computer system comprising at least two levels of SWAP devices, the method comprising: Monitoring the storage occupancy of the at least two levels of SWAP devices, wherein the at least two levels of SWAP devices include an upper level SWAP device and a lower level SWAP device; When the storage usage of the upper-level SWAP device reaches a watermark threshold, determining the least recently used data to be migrated stored in the upper-level SWAP device; The data to be migrated is migrated from the upper-level SWAP device to the lower-level SWAP device.
2. The method according to claim 1, wherein: The step of migrating the data to be migrated from the upper-level SWAP device to the lower-level SWAP device includes: Determine an idle target storage location in the lower-level SWAP device; Migrating the data to be migrated from the upper-level SWAP device to the target storage location of the lower-level SWAP device; Based on the target storage location, the least recently used LRU linked list of the lower-level SWAP device is updated, and the LRU linked list is used to maintain the order in which different memory reclaimed data is reclaimed into the lower-level SWAP device.
3. The method according to claim 2, wherein: The updating of the least recently used LRU linked list of the subordinate SWAP device based on the target storage location includes: Allocating a subordinate swap-out placeholder pointing to the target storage location for the data to be migrated; Based on the lower-level swap-out placeholder, an LRU linked list of the lower-level SWAP device is updated; the LRU linked list sequentially stores the lower-level swap-out placeholders having different memory recovery data according to storage time.
4. The method according to any one of claims 1 to 3, wherein: The at least two levels of SWAP devices respectively correspond to their own LRU linked lists, and the LRU linked lists are used to maintain the order in which different memory recovery data is recovered to the current SWAP device; When the storage occupancy of the upper-level SWAP device reaches a watermark threshold, determining the data to be migrated stored in the upper-level SWAP device includes: When the storage occupancy of the upper-level SWAP device reaches the watermark threshold, the least recently used data to be migrated stored in the upper-level SWAP device is determined based on the LRU linked list corresponding to the upper-level SWAP device.
5. The method according to any one of claims 1 to 3, wherein: The method further comprises: In the memory mapping table, replacing the upper-level swap-out placeholder item in the page table item corresponding to the data to be migrated with the lower-level swap-out placeholder item; Among them, the page table entry is used to store the pointing information of the storage location of the data to be migrated in the physical memory, the upper-level swap-out placeholder item is the pointing information of the storage location of the data to be migrated in the upper-level SWAP device, and the lower-level swap-out placeholder item is the pointing information of the storage location of the data to be migrated in the lower-level SWAP device.
6. The method according to any one of claims 1 to 3, wherein: The method further comprises: When the storage usage of the upper-level SWAP device reaches the watermark threshold and the upper-level SWAP device has at least two lower-level SWAP devices, a target lower-level SWAP device for this migration is selected from the at least two lower-level SWAP devices.
7. The method according to claim 6, wherein: The step of selecting a target lower-level SWAP device for the current migration from the at least two lower-level SWAP devices includes: Selecting the lower-level SWAP device with the largest free storage capacity among the at least two lower-level SWAP devices as the target lower-level SWAP device for this migration; or, Selecting the lower-level SWAP device with the highest priority among the at least two lower-level SWAP devices as the target lower-level SWAP device for this migration; or, The lower-level SWAP device with the lowest priority among the at least two lower-level SWAP devices is selected as the target lower-level SWAP device for this migration.
8. A memory recovery device, wherein: The device comprises at least two levels of SWAP equipment, and the device comprises: A monitoring module, used for monitoring the storage occupancy of the at least two levels of SWAP devices, wherein the at least two levels of SWAP devices include an upper level SWAP device and a lower level SWAP device; A determination module, configured to determine the least recently used data to be migrated stored in the upper-level SWAP device when the storage occupancy of the upper-level SWAP device reaches a watermark threshold; The migration module is used to migrate the data to be migrated from the upper-level SWAP device to the lower-level SWAP device.
9. The device according to claim 8, wherein: The determination module is further used to determine an idle target storage location in the lower-level SWAP device; The migration module is further used to migrate the data to be migrated from the upper-level SWAP device to the target storage location of the lower-level SWAP device; The device also includes: An update module is used to update the LRU linked list of the lower-level SWAP device based on the target storage location, and the LRU linked list is used to maintain the order in which different memory recovery data is recovered to the lower-level SWAP device.
10. The device according to claim 9, wherein: The update module is further used to allocate a lower-level swap-out placeholder pointing to the target storage location for the data to be migrated; The update module is further used to update the LRU linked list of the lower-level SWAP device based on the lower-level swap-out placeholder item; the LRU linked list stores the lower-level swap-out placeholder items with different memory recovery data in sequence according to the storage time.
11. The device according to any one of claims 8 to 10, wherein: The at least two levels of SWAP devices respectively correspond to their own LRU linked lists, and the LRU linked lists are used to maintain the order in which different memory recovery data is recovered to the current SWAP device; The determination module is further configured to determine the least recently used data to be migrated stored in the upper-level SWAP device based on the LRU linked list corresponding to the upper-level SWAP device when the storage occupancy of the upper-level SWAP device reaches a watermark threshold.
12. The device according to any one of claims 8 to 10, wherein: The updating module is further used to replace the upper-level swap-out placeholder item in the page table item corresponding to the to-be-migrated data with the lower-level swap-out placeholder item in the memory mapping table; Among them, the page table entry is used to store the pointing information of the storage location of the data to be migrated in the physical memory, the upper-level swap-out placeholder item is the pointing information of the storage location of the data to be migrated in the upper-level SWAP device, and the lower-level swap-out placeholder item is the pointing information of the storage location of the data to be migrated in the lower-level SWAP device.
13. The device according to any one of claims 8 to 10, wherein: The migration module is further configured to select a target lower-level SWAP device for this migration from the at least two lower-level SWAP devices when the storage usage of the upper-level SWAP device reaches a watermark threshold and the upper-level SWAP device has at least two lower-level SWAP devices.
14. The device according to claim 13, wherein: The migration module is further used to select the lower-level SWAP device with the largest free storage capacity among the at least two lower-level SWAP devices as the target lower-level SWAP device for this migration; or, selecting the lower-level SWAP device with the highest priority among the at least two lower-level SWAP devices as the target lower-level SWAP device for this migration; Or, the lower-level SWAP device with the lowest priority among the at least two lower-level SWAP devices is selected as the target lower-level SWAP device for this migration.
15. A computer device, wherein: The computer device comprises: a processor and a memory, wherein at least one program is stored in the memory, and the at least one program is loaded and executed by the processor to implement the memory recovery method according to any one of claims 1 to 7.
16. A computer-readable storage medium, wherein: The readable storage medium stores at least one program, and the at least one program is loaded and executed by a processor to implement the memory recovery method according to any one of claims 1 to 7.
17. A computer program product, wherein: The computer program product includes at least one program, and the at least one program is stored in a computer-readable storage medium; the processor of the communication device reads the at least one program from the computer-readable storage medium, and the processor executes the at least one program, so that the communication device executes the memory recovery method as described in any one of claims 1 to 7.
