Memory recovery method and device, electronic equipment and storage medium
By pre-checking and deleting the mapping relationship between referenced pages and page table entries, the referenced pages are directly reclaimed, which solves the problem of low memory reclamation efficiency in existing technologies and achieves more efficient memory management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
- Filing Date
- 2022-09-07
- Publication Date
- 2026-07-24
AI Technical Summary
Existing memory reclamation methods are inefficient and have a high load, especially when a large number of pages with mapped page table entries need to be reclaimed, which seriously affects system performance.
By performing a pre-check process, the mapping relationship between referenced related pages and page table entries is deleted from multiple related pages that are identified as having a relationship. The pages to be recycled that have undergone the pre-check process are then directly recycled, saving unnecessary deletion operations.
It improves the efficiency of memory reclamation, reduces the load on memory reclamation, and enhances system performance.
Smart Images

Figure CN116257461B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer memory management technology, and more specifically, to a memory reclamation method, apparatus, electronic device, and computer-readable storage medium. Background Technology
[0002] Main memory (also known as RAM) is the storage space that the processor of an electronic device can directly address. The RAM space in electronic devices is usually limited. To ensure the normal operation of the device, sufficient RAM is required. Therefore, electronic devices need to reclaim pages in RAM when they meet the reclamation criteria. However, existing methods for reclaiming RAM pages are inefficient and computationally expensive. Summary of the Invention
[0003] In view of this, this application proposes a memory reclamation method, apparatus, electronic device, and computer-readable storage medium.
[0004] In a first aspect, embodiments of this application provide a memory reclamation method, the method comprising: in response to a memory reclamation instruction, determining a referenced page to be reclaimed, wherein a referenced page refers to a page that has a mapping relationship with a page table entry; if the referenced page to be reclaimed is a page that has undergone pre-checking, reclaiming the referenced page to be reclaimed, wherein pre-checking refers to deleting the mapping relationship between the referenced related page and the page table entry when there is a referenced related page that has a mapping relationship with a page table entry among a plurality of related pages with a relationship.
[0005] Secondly, embodiments of this application provide a memory reclamation device, comprising: a determining module, configured to determine, in response to a memory reclamation instruction, a referenced page to be reclaimed, wherein a referenced page refers to a page that has a mapping relationship with a page table entry; and a reclamation module, configured to reclaim the referenced page to be reclaimed if the referenced page to be reclaimed is a page that has undergone pre-checking processing, wherein pre-checking processing refers to deleting the mapping relationship between the referenced related page and the page table entry when there is a referenced related page that has a mapping relationship with a page table entry among a plurality of related pages with a determined association relationship.
[0006] Thirdly, embodiments of this application provide an electronic device, including a memory and a processor, wherein the memory is coupled to the processor, the memory stores instructions, and the processor executes the above-described method when the instructions are executed by the processor.
[0007] Fourthly, embodiments of this application provide a computer-readable storage medium storing program code, which can be called by a processor to execute the above-described methods.
[0008] The memory reclamation method, apparatus, electronic device, and computer-readable storage medium provided in this application, through pre-lookup processing, delete the mapping relationship between referenced pages and page table entries in advance. This allows for direct reclamation of referenced pages that have undergone pre-lookup processing when they are to be reclaimed, without needing to delete the mapping relationship between the referenced pages and page table entries. This eliminates the memory consumption of deletion operations when reclaiming referenced pages, effectively improving memory reclamation efficiency and reducing the memory reclamation load. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0010] Figure 1 A flowchart illustrating a memory reclamation method provided in an embodiment of this application is shown;
[0011] Figure 2 A flowchart illustrating a memory reclamation method according to another embodiment of this application is shown;
[0012] Figure 3 A flowchart illustrating a memory reclamation method according to another embodiment of this application is shown;
[0013] Figure 4 This application shows Figure 3 A flowchart illustrating one embodiment of step S330 is shown.
[0014] Figure 5 A block diagram of a memory reclamation device provided in an embodiment of this application is shown;
[0015] Figure 6 A block diagram of an electronic device for performing a memory reclamation method according to an embodiment of this application is shown;
[0016] Figure 7 An embodiment of the present application shows a storage unit for storing or carrying program code that implements the memory reclamation method according to an embodiment of the present application. Detailed Implementation
[0017] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0018] For a computer's operating system, memory can be divided into multiple memory pages and managed in units of memory pages. Because the size of system memory is finite, memory reclamation is a common mechanism. There are two main reasons for memory reclamation: the system needs to provide sufficient memory space for any sudden memory requests to prevent cache usage and other related memory usage from causing a prolonged shortage of remaining memory. Also, memory reclamation is triggered when a request for more free memory arrives.
[0019] Currently, the Linux memory reclamation mechanism scans all page table entries mapped to a page using reverse mapping technology and deletes the mapping relationship between the page and all page table entries when reclaiming a page. However, if a page with a large number of mapped page table entries needs to be reclaimed (e.g., the page caches large files, applications, etc.), the time consumed by memory reclamation will increase, seriously affecting the system's memory reclamation performance and efficiency.
[0020] To address the aforementioned problems, the inventors, through extensive research, discovered and proposed the memory reclamation method, apparatus, electronic device, and computer-readable storage medium provided in the embodiments of this application. By performing a pre-check process, when a referenced associated page with a mapping relationship to a page table entry exists among multiple associated pages with a relationship, the mapping relationship between the referenced associated page and the page table entry is deleted. Therefore, when reclaiming referenced pages to be reclaimed, the pre-checked referenced pages are directly reclaimed, effectively improving the efficiency of memory reclamation and thus reducing the memory reclamation load. The specific memory reclamation method is described in detail in subsequent embodiments.
[0021] Please see Figure 1 , Figure 1 This paper illustrates a flowchart of a memory reclamation method provided in an embodiment of this application. The following will focus on... Figure 1 The process shown will be explained in detail. The memory reclamation method can specifically include the following steps:
[0022] Step S110: In response to a memory reclamation instruction, determine the referenced pages to be reclaimed. A referenced page is a page that has a mapping relationship with a page table entry.
[0023] In this embodiment, the memory reclamation instruction is an instruction that triggers the system to reclamation of memory, and there are multiple ways to generate the instruction that triggers the system to reclamation of memory.
[0024] As one implementation method, a memory reclamation instruction can be generated based on the current system memory size. In this approach, the system can detect the current available memory, and when the available memory falls below the target memory, a memory reclamation instruction is triggered to identify the referenced pages to be reclaimed. The target memory can also be the minimum memory required for normal system operation. For example, if the target memory size is 50MB and the detected available system memory size is 30MB, the available memory is below the target memory, and a memory reclamation instruction is triggered.
[0025] Optionally, the system can periodically check the available memory size, for example, automatically checking it every 30 minutes or 1 hour. Alternatively, the check can be triggered when a specific application starts. It's understood that applications require memory during operation, so when the system detects an application starting, it allocates a certain amount of memory space. However, if the current available memory is insufficient to support the memory needed for the application's startup, the system needs to reclaim memory. Therefore, the check can be triggered when a specific application starts, thus initiating a memory reclamation command.
[0026] As another implementation, the memory reclamation command can also be a memory reclamation command that is manually triggered by the user through an operation control. For example, a memory cleanup trigger control can be set in the interface of an electronic device (such as a computer) to provide the user with a command to trigger the reclamation of memory. When the memory cleanup trigger control is detected to be triggered, a command for performing memory reclamation is generated.
[0027] A referenced page is a page that has a mapping relationship with a page table entry. The system can store data information in a page and establish a mapping relationship between that page and a page table entry; this page can be a referenced page. Referenced pages can include anonymous pages and file pages. Anonymous pages can be pages without a file background, such as the heap, stack, or data segment; they do not exist in the form of a file. File pages are pages with a file background; they are cached in memory after the program reads a file. For example, data stored on a file page can be found on the disk.
[0028] A referenced page awaiting reclaiming refers to a referenced page identified from multiple referenced pages that is to be reclaimed. One implementation method for identifying a referenced page awaiting reclaiming is to use the LRU (Least Recently Used) algorithm to select the least recently used page, which can be the page at the end of the LRU list. This page is then identified as the referenced page awaiting reclaiming.
[0029] For each referenced page in the system, there is a corresponding page table (PT). The page table may include one or more page table entries (PTE) that have a mapping relationship with the referenced page. Each page table entry contains the mapping relationship between the physical address and the logical address of the referenced page. The mapping relationship can be a one-to-one correspondence between the physical address of the referenced page and the logical address corresponding to the page table entry.
[0030] For example, when it is necessary to reclaim referenced pages to be reclaimed, each page table entry in the page table corresponding to the referenced page to be reclaimed is scanned to determine the logical address corresponding to each page table entry. During memory reclamation, the mapping relationship between the referenced page to be reclaimed and the logical address corresponding to the page table entry is deleted.
[0031] Step S120: If the referenced page to be reclaimed is a page that has undergone pre-checking, the referenced page to be reclaimed is reclaimed. Pre-checking means that when there is a referenced related page that has a mapping relationship with a page table entry among multiple related pages with a relationship, the mapping relationship between the referenced related page and the page table entry is deleted.
[0032] In this embodiment, the pre-lookup process refers to the process of deleting the mapping relationship between the referenced related page and the corresponding page table entry when it is determined that there is a mapping relationship between the referenced related page and the page table entry among multiple related pages with a relationship.
[0033] When identifying multiple related pages, the principle of locality can be used. Locality states that when the CPU accesses memory, whether accessing instructions or data, the accessed memory units tend to cluster in a small, contiguous region. Types of locality include temporal locality and spatial locality. Temporal locality means that if a memory page is being accessed, it is likely to be accessed again in the near future. Spatial locality means that for a memory page being accessed, nearby memory pages are also likely to be accessed soon.
[0034] In this embodiment, when determining multiple related pages with an association relationship, the principle of computer locality can be based on spatial locality. It is understood that, according to the principle of spatial locality, related pages can refer to multiple pages that are physically located near a referenced page, and the association relationship can be a relationship where multiple related pages are located in similar physical locations.
[0035] For example, when performing a preliminary search on a referenced page to be reclaimed, based on the principle of spatial locality, multiple related pages in the vicinity of the physical address of the referenced page to be reclaimed are likely to be accessed in the near future. Therefore, multiple related pages in the vicinity of the physical address of the referenced page to be reclaimed can be obtained, and the preliminary search on multiple related pages can also be performed.
[0036] In one implementation, if the referenced page to be reclaimed is a page that has undergone pre-checking, it indicates that the mapping relationship between the page to be reclaimed and the page table entry has been deleted. In this case, the data information stored in the referenced page to be reclaimed is deleted, and the referenced page to be reclaimed is reclaimed.
[0037] This embodiment provides a memory reclamation method that, through pre-checking, deletes the mapping relationship between referenced pages and page table entries in advance. This allows for direct reclamation of referenced pages that have undergone pre-checking when they are to be reclaimed, without needing to delete the mapping relationship between the referenced pages and page table entries. This eliminates the memory consumption of deletion operations when reclaiming referenced pages, effectively improving memory reclamation efficiency and reducing the memory reclamation load.
[0038] Please see Figure 2 , Figure 2 A flowchart illustrating a memory reclamation method according to another embodiment of this application is shown below. Figure 2 The process shown will be explained in detail. The memory reclamation method can specifically include the following steps:
[0039] Step S210: In response to a memory reclamation instruction, determine the referenced pages to be reclaimed. A referenced page is a page that has a mapping relationship with a page table entry.
[0040] For a detailed description of step S210, please refer to step S110, which will not be repeated here.
[0041] Step S220: Obtain the page identifier of the referenced page to be recycled.
[0042] In this embodiment, the page identifier refers to the identifier used to indicate whether the referenced page to be recycled has been pre-checked. The page identifier can be represented by numbers, letters, or strings.
[0043] For example, if the page identifier is represented by a number, the page that has undergone pre-lookup processing can set the page identifier to 1, and the page that has not undergone pre-lookup processing can set the page identifier to 0; if the page identifier is represented by a letter, the page that has undergone pre-lookup processing can set the page identifier to Y, and the page that has not undergone pre-lookup processing can set the page identifier to N.
[0044] Step S230: If the page identifier of the referenced page to be reclaimed is the target page identifier, determine that the referenced page to be reclaimed is a page that has undergone pre-checking.
[0045] In this embodiment, the target page identifier is used to indicate that the referenced page to be reclaimed is a page that has undergone pre-checking. For example, when the target page identifier is 1, if the page identifier of the referenced page to be reclaimed is also 1, the referenced page to be reclaimed is determined to be a page that has undergone pre-checking.
[0046] It should be noted that the target page identifier of the referenced page to be reclaimed is configured when performing pre-query processing on the referenced page to be reclaimed. For example, when performing pre-query processing on a referenced page to be reclaimed, after deleting the mapping relationship between the referenced page to be reclaimed and the page table entry, the page identifier of the referenced page to be reclaimed can be configured as the target page identifier.
[0047] It is understandable that if the page identifier of the referenced page to be reclaimed is not the target page identifier, for example, if the page identifier of the referenced page to be reclaimed is 0, the letter N, or empty, then it is determined that the referenced page to be reclaimed is a page that has not undergone pre-checking.
[0048] Step S240: If the referenced page to be reclaimed is a page that has undergone pre-checking, reclaim the referenced page to be reclaimed.
[0049] For a detailed description of step S240, please refer to step S120, which will not be repeated here.
[0050] This embodiment provides a memory reclamation method that, through pre-checking, identifies referenced related pages that have a mapping relationship with page table entries among multiple related pages. The mapping relationship between the referenced related pages and page table entries is then deleted. This allows the pre-checked referenced pages to be reclaimed to be reclaimed directly, effectively improving memory reclamation efficiency and reducing the memory reclamation load.
[0051] Another memory reclamation method provided in this embodiment obtains the page identifier of the referenced page to be reclaimed, directly determines whether the referenced page to be reclaimed is a page that has undergone pre-checking processing through the page identifier, and reclaims the referenced page to be reclaimed when it is determined that the referenced page to be reclaimed is a page that has undergone pre-checking processing, thereby effectively improving the performance of memory reclamation.
[0052] Please see Figure 3 , Figure 3 This paper illustrates a flowchart of a memory reclamation method provided in another embodiment of this application. The following will focus on... Figure 3 The process shown will be explained in detail. The memory reclamation method can specifically include the following steps:
[0053] Step S310: In response to a memory reclamation instruction, determine the referenced pages to be reclaimed. A referenced page is a page that has a mapping relationship with a page table entry.
[0054] Step S320: Obtain the page identifier of the referenced page to be recycled.
[0055] For a detailed description of steps S310-S320, please refer to steps S210-S220, which will not be repeated here.
[0056] Step S330: If the referenced page to be reclaimed is a page that has not undergone pre-checking, delete the mapping relationship between the referenced page to be reclaimed and the page table entry.
[0057] As one implementation, if the page identifier of the referenced page to be reclaimed is not the target page identifier, the referenced page to be reclaimed is a page that has not undergone pre-checking, indicating that there is a mapping relationship between the page to be reclaimed and the page table entry. In this case, the mapping relationship between the referenced page to be reclaimed and the page table entry is deleted.
[0058] Step S340: Reclaim the referenced pages to be reclaimed.
[0059] It is understandable that after deleting the mapping relationship between the referenced page to be reclaimed and the page table entry, the corresponding data information stored in the referenced page to be reclaimed will be deleted, and the referenced page to be reclaimed will be reclaimed.
[0060] This embodiment provides another memory reclamation method. By obtaining the page identifier of the referenced page to be reclaimed, the referenced page to be reclaimed whose page identifier is the target page identifier is identified as a page that has undergone pre-checking and is reclaimed. For pages that have not undergone pre-checking, the mapping relationship between the page table entry is deleted and the referenced page to be reclaimed is reclaimed. This method realizes the reclamation of pages that have undergone pre-checking and the reclamation of pages that have not undergone pre-checking, effectively reducing the load during memory reclamation and improving the efficiency of memory reclamation.
[0061] Please see Figure 4 , Figure 4 This application shows Figure 3 The flowchart shown illustrates one embodiment of step S330. The following will focus on... Figure 4 The process shown will be explained in detail, and may include the following steps:
[0062] Step S410: Obtain multiple target associated pages and page table entries for the referenced page to be reclaimed. The multiple target associated pages include the referenced page to be reclaimed and pages that are associated with the referenced page to be reclaimed.
[0063] In this embodiment, the target associated page can be a page located within a certain range of the referenced page to be reclaimed in the physical address space. The association relationship can be that multiple target associated pages are located in the same physical address space. There can be multiple target associated pages, for example, up to 16, and these multiple target associated pages can include the referenced page to be reclaimed, as well as pages located in the vicinity of the referenced page to be reclaimed.
[0064] For example, if the number of target associated pages to be obtained is 16, then the referenced page to be reclaimed and 15 pages that are physically located near the referenced page to be reclaimed are selected. The obtained 16 pages can be used as target associated pages, and the page table entry corresponding to each associated page is obtained.
[0065] Optionally, there are several ways to obtain pages that are geographically close to the referenced page to be reclaimed in terms of physical address. For example, pages preceding the physical address of the referenced page to be reclaimed can be obtained as target associated pages, such as the 15 pages preceding the physical address of the referenced page to be reclaimed. Alternatively, pages following the physical address of the referenced page to be reclaimed can be obtained as target associated pages, such as the 15 pages following the physical address of the referenced page to be reclaimed. Another option is to simultaneously obtain pages following and preceding the physical address of the referenced page to be reclaimed as target associated pages, such as the 7 pages preceding the physical address of the referenced page to be reclaimed and the 8 pages following the physical address of the referenced page to be reclaimed, all of which can be used as target associated pages.
[0066] Step S420: Obtain the page table reference identifier for each target associated page.
[0067] In this embodiment, the page table reference identifier can be an identifier used to characterize whether there is a mapping relationship between the target associated page and the corresponding page table entry. The page table reference identifier can be represented by numbers, letters, or strings. For example, when using numbers to represent page references, if there is a mapping relationship between the target associated page and the corresponding page table entry, the page table reference identifier of the target associated page can be 1; if there is no mapping relationship between the target associated page and the corresponding page table entry, the page table reference identifier of the target associated page can be 0.
[0068] Step S430: If the page table reference identifier of the target associated page is the first page table reference identifier, it is determined that the target associated page and the page table entry have a mapping relationship. The first page table reference identifier of the target associated page is configured for the target associated page when the target associated page is referenced.
[0069] In this embodiment, the first page table reference identifier can be an identifier used to characterize the mapping relationship between the target associated page and the corresponding page table entry. For example, the first page table reference identifier can be 1. For instance, when the page table reference identifier of the target associated page is 1, it can be determined that there is a mapping relationship between the target associated page and the corresponding page table entry.
[0070] It should be noted that the first page table reference identifier of the target associated page is configured for the target associated page when it is referenced. For example, when the system needs the target associated page to store data, the data is stored in the target associated page, a mapping relationship is established between the target associated page and the logical address of the page table entry referencing the target associated page, and the page table reference identifier of the target associated page is configured as the first page table reference identifier, indicating that the mapping relationship between the target associated page and the page table entry has been established.
[0071] Step S440: If the page table reference identifier of the target associated page is the second page table reference identifier, it is determined that the target associated page and the page table entry do not have a mapping relationship. The second page table reference identifier of the target associated page is configured for the target associated page when the target associated page is not referenced.
[0072] In this embodiment, the second page table reference identifier can be an identifier used to indicate that there is no mapping relationship between the target associated page and the corresponding page table entry. For example, the second page table reference identifier can be 0. For instance, when the page table reference identifier of the target associated page is 0, it can be determined that there is no mapping relationship between the target associated page and the corresponding page table entry.
[0073] It should be noted that the second page table reference identifier for the target associated page is configured for the target associated page when it is not referenced. Optionally, the initial value of the page table reference identifier for the target associated page can be configured as the second reference identifier, indicating that the target associated page has not yet been referenced and there is no mapping relationship between the target associated page and the page table entry. The second page table reference identifier for the target associated page can also be configured after deleting the mapping relationship between the target associated page and the corresponding page table entry. For example, after deleting the mapping relationship between the target associated page and the page table entry, the page table reference identifier for the target associated page can be configured as the second page table reference identifier, indicating that there is no longer a mapping relationship between the target associated page and the page table entry.
[0074] Step S450: For each target associated page, if the target associated page has a mapping relationship with a page table entry, delete the mapping relationship between the target associated page and the page table entry.
[0075] After determining that the page table reference identifier of the target associated page is the first reference identifier, and confirming that there is a mapping relationship between the target associated page and the page table entry, the mapping relationship between the target associated page and the page table entry is deleted. Optionally, after deleting the mapping relationship between the target associated page and the page table entry, the page table reference identifier of the target associated page can be configured as the second page table reference identifier to indicate that there is no longer a mapping relationship between the target associated page and the page table entry.
[0076] Understandably, after determining that the page table reference identifier of the target associated page is the second reference identifier, and determining that there is no mapping relationship between the target associated page and the page table entry, it is possible to determine whether there is a mapping relationship between the next target associated page and the corresponding page table entry.
[0077] It should be noted that after deleting the mapping relationship between the target associated page and the page table entry, the page identifier of the target associated page can be configured as the target page identifier, indicating that the target associated page is a page that has undergone pre-check processing, that is, the page after the mapping relationship between the target associated page and the page table entry has been deleted.
[0078] In this embodiment, multiple target associated pages and page table entries of the referenced pages to be reclaimed are obtained. By judging the page table reference identifier of each target associated page, it is determined whether there is a mapping relationship between the target associated page and the page table entry. If there is a mapping relationship between the target associated page and the page table entry, the mapping relationship between the target associated page and the page table entry is deleted, thereby realizing the pre-checking processing of the target associated pages of the referenced pages to be reclaimed and improving the efficiency of memory reclamation.
[0079] Please see Figure 5 , Figure 5 This application illustrates a memory reclamation apparatus 500 provided in an embodiment of the present application. The memory reclamation apparatus 500 includes: a determining module 510 and a reclamation module 520, wherein:
[0080] The determination module 510 is used to determine the referenced pages to be reclaimed in response to a memory reclamation instruction. A referenced page is a page that has a mapping relationship with a page table entry.
[0081] The first recycling module 520 is used to recycle pages that have undergone pre-checking if the referenced pages to be recycled are pages that have undergone pre-checking. Pre-checking means that when there are referenced related pages that have a mapping relationship with page table entries among multiple related pages, the mapping relationship between the referenced related pages and page table entries is deleted.
[0082] Optionally, the memory reclamation device 500 is further configured to obtain the page identifier of the referenced page to be reclaimed; if the page identifier of the referenced page to be reclaimed is a target page identifier, it is determined that the referenced page to be reclaimed is a page that has undergone pre-check processing. The target page identifier of the referenced page to be reclaimed is configured for the referenced page to be reclaimed during the pre-check processing of the referenced page to be reclaimed.
[0083] Optionally, the memory reclamation device 500 further includes a second reclamation module, used to delete the mapping relationship between the referenced page to be reclaimed and the page table entry if the referenced page to be reclaimed is a page that has not undergone pre-checking; and to reclaim the page to be reclaimed.
[0084] Optionally, the second recycling module is further configured to obtain multiple target associated pages and page table entries corresponding to the referenced page to be recycled, wherein the multiple target associated pages include the referenced page to be recycled and pages that are associated with the referenced page to be recycled; for each target associated page, if the target associated page has a mapping relationship with the page table entry, the mapping relationship between the target associated page and the page table entry is deleted.
[0085] Optionally, the second recycling module is further configured to obtain the page table reference identifier of each target associated page; if the page table reference identifier of the target associated page is the first page table reference identifier, it is determined that the target associated page and the page table entry have a mapping relationship, and the first page table reference identifier of the target associated page is configured for the target associated page when the target associated page is referenced; if the page table reference identifier of the target associated page is the second page table reference identifier, it is determined that the target associated page and the page table entry do not have a mapping relationship, and the second page table reference identifier of the target associated page is configured for the target associated page when the target associated page is not referenced.
[0086] Optionally, the recycling module 520 is also used to delete the mapping relationship between the logical addresses of the referenced associated pages and page table entries.
[0087] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described device and module can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0088] In the several embodiments provided in this application, the coupling between modules can be electrical, mechanical, or other forms of coupling.
[0089] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.
[0090] Please see Figure 6 This diagram illustrates a structural block diagram of an electronic device 600 provided in an embodiment of this application. The electronic device 600 can be a smartphone, tablet computer, e-reader, or other electronic device capable of running applications. The electronic device 600 in this application may include one or more of the following components: a processor 610, a memory 620, and one or more applications, wherein the one or more applications can be stored in the memory 620 and configured to be executed by one or more processors 610, and the one or more applications are configured to perform the methods described in the foregoing method embodiments.
[0091] The processor 610 may include one or more processing cores. The processor 610 connects to various parts within the electronic device 600 using various interfaces and lines, and performs various functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 620, and by calling data stored in the memory 620. Optionally, the processor 610 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 610 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface, and applications; the GPU is responsible for rendering and drawing the content to be displayed; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 610 and may be implemented separately using a communication chip.
[0092] The memory 620 may include random access memory (RAM) or read-only memory (ROM). The memory 620 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 620 may include a program storage area and a data storage area. The program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as touch functionality, sound playback functionality, image playback functionality, etc.), and instructions for implementing the various method embodiments described below. The data storage area may also store data created by the electronic device 600 during use (such as phonebook data, audio and video data, chat log data, etc.).
[0093] Please see Figure 7 This diagram illustrates a structural block diagram of a computer-readable storage medium provided in an embodiment of this application. The computer-readable medium 700 stores program code that can be called by a processor to execute the methods described in the above method embodiments.
[0094] The computer-readable storage medium 700 may be an electronic memory such as flash memory, EEPROM (Electrically Erasable Programmable Read-Only Memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 700 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 700 has storage space for program code 710 that performs any of the method steps described above. This program code can be read from or written to one or more computer program products. The program code 710 may, for example, be compressed in a suitable form.
[0095] In summary, the memory reclamation method, apparatus, electronic device, and computer-readable storage medium provided in this application, through pre-lookup processing, delete the mapping relationship between referenced pages and page table entries in advance. This allows for direct reclamation of referenced pages that have undergone pre-lookup processing when they are to be reclaimed, without needing to delete the mapping relationship between the referenced pages and page table entries. This eliminates the memory consumption of deletion operations when reclaiming referenced pages, effectively improving memory reclamation efficiency and reducing the memory reclamation load.
[0096] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A memory reclamation method, characterized in that, The method includes: In response to a memory reclamation instruction, determine the referenced pages to be reclaimed, wherein the referenced pages are those that have a mapping relationship with page table entries; If the referenced page to be reclaimed is a page that has undergone pre-checking, the referenced page to be reclaimed is reclaimed; wherein, the pre-checking is triggered after multiple related pages with a relationship are detected, the pre-checking refers to deleting the mapping relationship between the referenced related page and the page table entry when it is determined that there is a referenced related page with a mapping relationship with the page table entry among the multiple related pages with a relationship.
2. The method according to claim 1, characterized in that, The method further includes: Obtain the page identifier of the referenced page to be reclaimed; If the page identifier of the referenced page to be reclaimed is a target page identifier, it is determined that the referenced page to be reclaimed is a page that has undergone pre-check processing. The target page identifier of the referenced page to be reclaimed is configured for the referenced page to be reclaimed when the pre-check processing is performed on the referenced page to be reclaimed.
3. The method according to claim 1, characterized in that, The method further includes: If the referenced page to be reclaimed is a page that has not undergone pre-checking, delete the mapping relationship between the referenced page to be reclaimed and the page table entry; The referenced pages to be reclaimed are reclaimed.
4. The method according to claim 3, characterized in that, If the referenced page to be reclaimed is a page that has not undergone pre-checking, the mapping relationship between the referenced page to be reclaimed and the page table entry is deleted, including: Obtain multiple target associated pages corresponding to the referenced page to be reclaimed and the page table entry, wherein the multiple target associated pages include the referenced page to be reclaimed and pages that are associated with the referenced page to be reclaimed; For each target associated page, if the target associated page has a mapping relationship with the page table entry, delete the mapping relationship between the target associated page and the page table entry.
5. The method according to claim 4, characterized in that, The method further includes: Obtain the page table reference identifier for each of the target associated pages; If the page table reference identifier of the target associated page is the first page table reference identifier, it is determined that the target associated page and the page table entry have a mapping relationship. The first page table reference identifier of the target associated page is configured for the target associated page when the target associated page is referenced. If the page table reference identifier of the target associated page is the second page table reference identifier, it is determined that the target associated page and the page table entry do not have a mapping relationship. The second page table reference identifier of the target associated page is configured for the target associated page when the target associated page is not referenced.
6. The method according to claim 1, characterized in that, Deleting the mapping relationship between the referenced associated page and the page table entry includes: Delete the mapping relationship between the referenced associated page and the logical address of the page table entry.
7. The method according to claim 1, characterized in that, The association includes the physical address of the page.
8. A memory reclamation device, characterized in that, The device includes: The determination module is used to determine the referenced pages to be reclaimed in response to a memory reclamation instruction. The referenced pages refer to pages that have a mapping relationship with page table entries. The first recycling module is used to recycle the referenced page if it is a page that has undergone pre-checking processing; wherein, the pre-checking processing is triggered after detecting multiple related pages with a relationship, and the pre-checking processing refers to deleting the mapping relationship between the referenced related page and the page table entry when it is determined that there is a referenced related page with a mapping relationship with the page table entry among the multiple related pages with a relationship.
9. An electronic device, characterized in that, The method includes a memory and a processor, the memory being coupled to the processor, the memory storing instructions, and the processor performing the method as described in any one of claims 1-7 when the instructions are executed by the processor.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium contains program code that can be invoked by a processor to execute the method as described in any one of claims 1-7.