Memory page management method and device and storage medium
By distinguishing and processing memory pages that have been accessed by the CPU and those that have not been accessed in the memory page management method, the memory thrashing problem is solved and application performance and user experience are improved.
Patent Information
- Application Number
- CN202310917764.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-24
- Publication Date
- 2025-01-24
AI Technical Summary
In electronic devices, the repeated recycled and redistribution of memory pages of application processes lead to memory bumps, affecting application performance and user experience.
In the memory page management method, memory pages that have been accessed by the CPU are maintained in the hot page linked list, and memory pages that have not been accessed are moved into the cold page linked list to prevent hot memory pages from being placed in the cold page linked list and reduce the cost. Number of memory thrashes.
It effectively reduces the number of memory thrashing in the memory pages of the application process, improving application performance and user experience.
Smart Images

Figure CN119357086A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of memory management technology, and in particular to a memory page management method, device and storage medium. Background Art
[0002] Since the random access memory (RAM) resources of electronic devices are limited, when a user opens multiple applications while using an electronic device, the system of the electronic device will recycle the memory pages of some application processes to meet the memory requirements of the foreground application at this time. After the memory page is recycled, if the user accesses the application whose memory page was recycled again, the memory needs to be reallocated.
[0003] However, if the memory pages of the application process are repeatedly recycled and reallocated, memory thrashing will occur, causing a certain degree of delay to the current business, thereby affecting application performance and even the user experience. Summary of the invention
[0004] The purpose of the present application is to provide a memory page management method, device and storage medium, which can reduce the number of memory thrashing that occurs in the memory pages of an application process.
[0005] In the first aspect, the present application discloses a memory page management method, which can be applied to electronic devices such as mobile phones, computers, tablet computers, wearable electronic devices (such as smart watches). The method includes: when the memory pages in the cold page list are recycled for the first time, the first group of memory pages accessed by the central processing unit before the first recycling is maintained in the hot page list, and each memory page in the second group of memory pages that have not been accessed by the central processing unit before the first recycling is moved into the cold page list in sequence; when the memory pages in the cold page list are recycled for the second time, the third group of memory pages accessed by the central processing unit after the first recycling and before the second recycling is maintained in the hot page list, and each memory page in the fourth group of memory pages that have not been accessed by the central processing unit after the first recycling and before the second recycling is moved into the cold page list in sequence. Thus, it is avoided that the hotter memory pages are placed in the cold page list, the risk of recycling the hotter memory pages is reduced, and the number of memory thrashings that occur in the memory pages of the application process is reduced.
[0006] In some possible implementations, each memory page in the above-mentioned first group of memory pages, second group of memory pages, third group of memory pages and fourth group of memory pages corresponds to a first parameter and a second parameter, respectively. When the first parameter is a first value, it indicates that the memory page has been accessed by the central processing unit. When the first parameter is a second value, it indicates that the memory page has not been accessed by the central processing unit. When the second parameter is a first value, it indicates that the hot and cold state of the memory page is hot. When the second parameter is a second value, it indicates that the hot and cold state of the memory page is cold.
[0007] In some possible implementations, the above-mentioned maintaining that the first group of memory pages accessed by the central processor before the first recycling is in the hot page list includes: maintaining that the first parameter and the second parameter of each memory page in the first group of memory pages accessed by the central processor before the first recycling are both the first value, so that the above-mentioned first group of memory pages is maintained in the hot page list. In this way, it is avoided that the hotter memory pages are placed in the cold page list, the risk of recycling the hotter memory pages is reduced, and the number of memory thrashings occurring in the memory pages of the application process is reduced.
[0008] In some possible implementations, the above-mentioned sequentially moving each memory page in the second group of memory pages that have not been accessed by the central processing unit before the first recycling into the Inactive linked list includes: changing the first parameter of each memory page in the second group of memory pages that have not been accessed by the central processing unit before the first recycling from the second value to the first value, and changing the second parameter from the first value to the second value, so as to sequentially move each memory page in the second group of memory pages into the Inactive linked list. Thus, it is avoided that the hot memory page is placed in the cold page linked list, and the risk of recycling the hot memory page is reduced, thereby reducing the number of memory thrashings that occur in the memory pages of the application process.
[0009] In some possible implementations, the above-mentioned maintaining that the third group of memory pages accessed by the central processor are in the Active linked list after the first recycling and before the second recycling includes: maintaining that the first parameter and the second parameter of each memory page in the third group of memory pages accessed by the central processor are both the first value after the first recycling and before the second recycling, so that the third group of memory pages are maintained in the Active linked list. In this way, it is avoided that the hot memory pages are placed in the cold page linked list, the risk of recycling the hot memory pages is reduced, and the number of memory thrashings occurring in the memory pages of the application process is reduced.
[0010] In some possible implementations, the above-mentioned moving each memory page in the fourth group of memory pages that have not been accessed by the central processing unit into the Inactive linked list in sequence after the first recycling and before the second recycling includes: changing the first parameter of each memory page in the fourth group of memory pages that have not been accessed by the central processing unit from the second value to the first value after the first recycling and before the second recycling, and changing the second parameter from the first value to the second value, so as to move each memory page in the fourth group of memory pages into the Inactive linked list in sequence. In this way, it is avoided that the hotter memory pages are placed in the cold page linked list, and the risk of recycling the hotter memory pages is reduced, thereby reducing the number of memory thrashings that occur in the memory pages of the application process.
[0011] In some possible implementations, the method further includes: when a page fault exception occurs, allocating an initial new page in a cold page list; and setting parameters of the initial new page according to an identifier of the initial new page, the parameters of the initial new page being used to characterize the activity level of the initial new page.
[0012] In some possible implementations, the identifier of the initial new page includes a foreground application identifier and a non-foreground application identifier; the parameters of the initial new page include a first parameter and a second parameter, when the first parameter is a first value, it indicates that the initial new page has been accessed by the central processing unit, when the first parameter is a second value, it indicates that the initial new page has not been accessed by the central processing unit, and the second parameter indicates that the hot and cold state of the initial new page is cold; then, according to the identifier of the initial new page, the parameters of the initial new page are set, including: according to the foreground application identifier, the first parameter of the initial new page is set to the first value; or, according to the non-foreground application identifier, the first parameter of the initial new page is set to the second value. Thus, when a page fault exception occurs in an application containing a foreground application identifier, the initial new page can be placed in a cold page list and the first parameter can be set to the first value. As long as the initial new page is accessed again, it can be added to the hot page list, thereby avoiding placing hotter pages in the cold page list, greatly reducing the risk of memory page recycling, and thereby reducing the number of memory thrashings that occur in the memory pages of the application process.
[0013] In some possible implementations, the heating process of the memory page is the central processing unit accessing the memory page, and the method also includes: when the memory page in the cold page list is heated for the first time, each memory page in the fifth group of memory pages that has been accessed by the central processing unit before the first heating process is moved into the hot page list in sequence; when the memory page in the cold page list is heated for the second time, each memory page in the seventh group of memory pages that has been accessed by the central processing unit after the first heating process and before the second heating process is moved into the hot page list in sequence.
[0014] In some possible implementations, the method further includes: if the sixth group of memory pages that have not been accessed by the central processor before the first heating process is maintained in the cold page list for a number of times greater than a preset threshold, recycling the sixth group of memory pages.
[0015] In some possible implementations, the method further includes: if the eighth group of memory pages that have not been accessed by the central processing unit are in the cold page list for a number of times greater than a preset threshold after the first heating process and before the second heating process, the eighth group of memory pages are recycled.
[0016] In some possible implementations, each memory page in the fifth group of memory pages, the sixth group of memory pages, the seventh group of memory pages, and the eighth group of memory pages corresponds to a first parameter and a second parameter, respectively. When the first parameter is a first value, it indicates that the memory page has been accessed by the central processing unit. When the first parameter is a second value, it indicates that the memory page has not been accessed by the central processing unit. When the second parameter is a first value, it indicates that the hot and cold state of the memory page is hot. When the second parameter is a second value, it indicates that the hot and cold state of the memory page is cold.
[0017] In some possible implementations, before the first heating process, each memory page in the fifth group of memory pages accessed by the central processing unit is moved into the hot page list in sequence, including: changing the first parameter of each memory page in the fifth group of memory pages accessed by the central processing unit before the first heating process from the first value to the second value, and changing the second parameter from the second value to the first value, so that each memory page in the fifth group of memory pages is moved into the hot page list in sequence.
[0018] In some possible implementations, each memory page in the seventh group of memory pages accessed by the central processing unit after the first heating treatment and before the second heating treatment is moved into the hot page list in sequence, including: changing the first parameter of each memory page in the seventh group of memory pages accessed by the central processing unit after the first heating treatment and before the second heating treatment from the first value to the second value, and changing the second parameter from the second value to the first value, so that each memory page in the seventh group of memory pages is moved into the hot page list in sequence.
[0019] In a second aspect, the present application discloses an electronic device, including a processor and a memory; the memory is used to store computer execution commands; the processor is used to execute the computer execution commands stored in the memory, so that the processor executes the memory page management method as in the first aspect.
[0020] In a third aspect, the present application discloses a computer-readable storage medium, in which a computer program or instruction is stored. When the computer program or instruction is executed, the memory page management method in the first aspect is implemented.
[0021] In a fourth aspect, the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the memory page management method in the first aspect.
[0022] In a fifth aspect, the present application discloses a memory page management device, including a first recycling module and a second recycling module. Specifically, the first recycling module is used to maintain the first group of memory pages accessed by the central processing unit before the first recycling in the hot page list when the memory pages in the cold page list are recycled for the first time, and move each memory page in the second group of memory pages that have not been accessed by the central processing unit before the first recycling into the cold page list in sequence. The second recycling module is used to maintain the third group of memory pages accessed by the central processing unit after the first recycling and before the second recycling in the hot page list when the memory pages in the cold page list are recycled for the second time, and move each memory page in the fourth group of memory pages that have not been accessed by the central processing unit after the first recycling and before the second recycling into the cold page list in sequence. As a result, it is avoided that the hotter memory pages are placed in the cold page list, the risk of recycling the hotter memory pages is reduced, and the number of memory thrashings that occur in the memory pages of the application process is reduced.
[0023] Based on the above technical solution, this application has the following beneficial effects:
[0024] The present application discloses a memory page management method, device and storage medium, the method comprising: when the memory pages in the cold page list are recycled for the first time, the first group of memory pages accessed by the central processing unit before the first recycling is maintained in the hot page list, and each memory page in the second group of memory pages that have not been accessed by the central processing unit before the first recycling is moved into the cold page list in sequence; when the memory pages in the cold page list are recycled for the second time, the third group of memory pages that have been accessed by the central processing unit after the first recycling and before the second recycling is maintained in the hot page list, and each memory page in the fourth group of memory pages that have not been accessed by the central processing unit after the first recycling and before the second recycling is moved into the cold page list in sequence. Thus, it is avoided that the hotter memory pages are placed in the cold page list, the risk of recycling the hotter memory pages is reduced, and the number of memory thrashings that occur in the memory pages of the application process is reduced.
[0025] It should be understood that the description of technical features, technical solutions, beneficial effects or similar language in this application does not imply that all features and advantages can be realized in any single embodiment. On the contrary, it is understood that the description of features or beneficial effects means that specific technical features, technical solutions or beneficial effects are included in at least one embodiment. Therefore, the description of technical features, technical solutions or beneficial effects in this specification does not necessarily refer to the same embodiment. Furthermore, the technical features, technical solutions and beneficial effects described in the present embodiment can also be combined in any appropriate manner. Those skilled in the art will understand that the embodiment can be realized without one or more specific technical features, technical solutions or beneficial effects of a specific embodiment. In other embodiments, additional technical features and beneficial effects can also be identified in a specific embodiment that does not embody all embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 A schematic diagram of Linux kernel memory management provided in an embodiment of the present application;
[0027] Figure 2 A schematic diagram of an existing memory page management method;
[0028] Figure 3 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;
[0029] Figure 4 A flowchart of a memory page management method provided in an embodiment of the present application;
[0030] Figure 5 A flowchart of another memory page management method provided in an embodiment of the present application;
[0031] Figure 6 A flowchart of a third memory page management method provided in an embodiment of the present application;
[0032] Figure 7 A schematic diagram of a memory page management method provided in an embodiment of the present application;
[0033] Figure 8 A schematic diagram of a memory page management device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0034] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. The terms used in the following embodiments are only for the purpose of describing specific embodiments and are not intended to be used as limitations on the present application. As used in the specification and the appended claims of the present application, the singular expressions "one", "a kind", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the embodiments of the present application, "one or more" refers to one, two or more; "and / or" describes the association relationship of the associated objects, indicating that three relationships may exist; for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship.
[0035] References to "one embodiment" or "some embodiments" etc. described in this specification mean that a particular feature, structure or characteristic described in conjunction with the embodiment is included in one or more embodiments of the present application. Thus, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear at different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0036] The multiple involved in the embodiments of the present application means greater than or equal to two. It should be noted that in the description of the embodiments of the present application, the words "first", "second", etc. are only used for the purpose of distinguishing the description, and cannot be understood as indicating or implying relative importance, nor can they be understood as indicating or implying an order.
[0037] First, the terms involved in one or more embodiments of this specification are explained.
[0038] Random Access Memory (RAM), also known as main memory, is an internal memory that directly exchanges data with the Central Processing Unit (CPU). It can be read and written at any time (except when refreshed) and is very fast. It is usually used as a temporary data storage medium for operating systems or other running programs. When working, random access memory can write (store) or read (retrieve) information from any specified address at any time. Random access memory is used in computers and digital systems to temporarily store programs, data, and intermediate results.
[0039] When the electronic device is under business load, it needs to access memory pages. In the embodiments disclosed in the present application, the memory pages in the hot page list (i.e., the Active LRU list) are hot pages, and the memory pages in the cold page list (i.e., the Inactive LRU list) are cold pages. Among them, LRU refers to the least recently used algorithm. The least recently used algorithm is a memory data elimination strategy. It is commonly used when the memory is insufficient and the least recently used data needs to be eliminated. In the embodiments disclosed in the present application, the memory page can be moved to a list that matches its hotness or coldness according to the LRU algorithm, or the memory page can be recycled.
[0040] In order to determine the hotness or coldness of a memory page, the memory pages in the hot page list and the cold page list both contain a first parameter and a second parameter. Specifically, the first parameter is a Referenced parameter, which can indicate whether the current memory page has been accessed by the central processing unit. When the first parameter is a first value, it means that the memory page has been accessed by the central processing unit, and when the first parameter is a second value, it means that the memory page has not been accessed by the central processing unit. Exemplarily, the first value may be 1, and the second value may be 0, that is, if Referenced=1, that is, the value of the first parameter is 1, it means that the current memory page has been accessed by the central processing unit in the past period of time; if Referenced=0, that is, the value of the first parameter is 0, it means that the current memory page has not been accessed by the central processing unit in the past period of time.
[0041] The second parameter is the Active parameter, which can indicate the hot or cold state of the current memory page. When the second parameter is the first value, it means that the hot or cold state of the memory page is hot; when the second parameter is the second value, it means that the hot or cold state of the memory page is cold. Exemplarily, the first value can be 1, and the second value can be 0. That is to say, if Active=1, that is, the value of the second parameter is 1, it means that the current memory page is in a hot state and is in the hot page list; if Active=0, that is, the value of the second parameter is 0, it means that the current memory page is in a cold state and is in the cold page list.
[0042] Therefore, the setting of the above two states can more accurately determine the activity level of the memory page. It should be noted that the Active state can also be set as the first parameter, the Referenced state can be set as the second parameter, and the memory pages in the hot page list and the cold page list can also include other states. This application does not limit the specific state settings and numbers. For ease of understanding, the following description will be based on the first value being 1 and the second value being 0.
[0043] See also Figure 1 , which is a schematic diagram of Linux kernel memory management provided by an embodiment of the present application. Since the random access memory resources of electronic devices are limited, when a user opens multiple applications during the use of electronic devices, the Linux OS system of the electronic device will recycle the memory pages of the application process at the end of the cold page list (i.e., the Inactive LRU list). Figure 1 As shown, the right side of the hot page list and the cold page list is the head, and the left side of the hot page list and the cold page list is the tail.
[0044] After the memory page is reclaimed, if the user accesses the application again, the memory needs to be reallocated. Figure 1As shown in the figure, after reallocating memory due to page fault exception caused by memory page recycling, the allocated memory page is put into the head of the cold page list to set the memory page as a cold page. In this way, if the memory page of the application process is repeatedly recycled and reallocated, memory thrashing will occur, which will cause a certain degree of delay to the current business, thereby affecting application performance and even the user experience.
[0045] In addition, it is understandable that any cold page in the cold page list can be transferred to the head of the hot page list after marking SetPageActive to change from a cold page to a hot page. And the hot page at the end of the hot page list can be transferred to the head of the cold page list after marking Shrink_active to change from a hot page to a cold page.
[0046] See also Figure 2 , which is a schematic diagram of an existing memory page management method.
[0047] In the existing memory page management method, when an initial new page is allocated due to a page fault exception, the initial new page is first placed in a cold page list, the second parameter of the initial new page is set to 0 (i.e., Active=0), and the first parameter is also set to 0 (i.e., Referenced=0). At this time, the parameters of the initial new page can be expressed as AR:00.
[0048] In the existing memory page management method, when a memory page in the hot page list needs to be placed in the cold page list, the memory page can be marked as Shrink_active, and then the memory page can be placed in the cold page list. Based on this, there is no need to distinguish whether the memory page is accessed by the central processing unit or the process. The second parameter of the memory page is uniformly cleared, that is, Active=0 is set, and the first parameter is not modified, that is, Referenced is maintained unchanged. At this time, the parameter of the memory page can be changed from AR:10 to AR:00, or from AR:11 to AR:01. Since the second parameter is 0, it can be considered that the memory page is placed in the cold page list.
[0049] However, there are still problems with memory page management according to the above existing memory page management method. When a memory page in the hot page list needs to be placed in the cold page list and marked as Shrink_active, the memory page is placed in the cold page list regardless of whether the memory page has been accessed recently. Therefore, if the user accesses the application again after the memory page is recycled, the memory needs to be reallocated, causing memory thrashing, affecting application performance, and even affecting the user's experience.
[0050] In view of this, the present application provides a memory page management method, device and storage medium, the method comprising: when the memory pages in the cold page list are recycled for the first time, the first group of memory pages accessed by the central processing unit before the first recycling is maintained in the hot page list, and each memory page in the second group of memory pages that have not been accessed by the central processing unit before the first recycling is moved into the cold page list in sequence; when the memory pages in the cold page list are recycled for the second time, the third group of memory pages that have been accessed by the central processing unit after the first recycling and before the second recycling is maintained in the hot page list, and each memory page in the fourth group of memory pages that have not been accessed by the central processing unit after the first recycling and before the second recycling is moved into the cold page list in sequence. Thus, it is avoided that the hotter memory pages are placed in the cold page list, the risk of recycling the hotter memory pages is reduced, and the number of memory thrashings that occur in the memory pages of the application process is reduced.
[0051] It should be noted that it is impossible to absolutely avoid memory thrashing, but the memory page management method in the implementation manner provided in the present application can be used to identify and distinguish between cold and hot pages as accurately as possible, and pages that are not currently too cold can be avoided from being recycled into the cold page list as much as possible, thereby reducing the risk of recycling hotter memory pages, and thereby reducing the number of memory thrashing that occurs in the memory pages of the application process.
[0052] See also Figure 3 , which is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. It should be noted that the electronic device can be a mobile phone, a laptop computer, a wearable electronic device (such as a smart watch), a tablet computer, an augmented reality (AR) device, a virtual reality (VR) device, and a vehicle-mounted device, etc.
[0053] like Figure 3 As shown, the electronic device 100 may include a processor 110, an internal memory 120, a display screen 150, a button 160, etc.
[0054] It is to be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device. In other embodiments, the electronic device may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0055] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors. For example, in the present application, when the processor 110 recycles the memory pages in the cold page list for the first time, the first group of memory pages accessed by the CPU before the first recycling is maintained in the hot page list, and each memory page in the second group of memory pages that have not been accessed by the CPU before the first recycling is moved into the cold page list in sequence; when the memory pages in the cold page list are recycled for the second time, the third group of memory pages that have been accessed by the CPU after the first recycling and before the second recycling is maintained in the hot page list, and each memory page in the fourth group of memory pages that have not been accessed by the CPU after the first recycling and before the second recycling is moved into the cold page list in sequence. In this way, the hotter memory pages are avoided from being placed in the cold page list, the risk of recycling the hotter memory pages is reduced, and the number of memory thrashings that occur in the memory pages of the application process is reduced.
[0056] The controller can be the nerve center and command center of the electronic device. The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.
[0057] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0058] It is understandable that the interface connection relationship between the modules illustrated in this embodiment is only a schematic illustration and does not constitute a structural limitation of the electronic device. In other embodiments of the present application, the electronic device may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0059] The internal memory 120 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device by running the instructions stored in the internal memory 120. The internal memory 120 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device (such as audio data, a phone book, etc.), etc. In addition, the internal memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. The processor 110 executes various functional applications and data processing of the electronic device by running the instructions stored in the internal memory 120, and / or the instructions stored in the memory provided in the processor.
[0060] The electronic device implements the display function through a GPU, a display screen 150, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 150 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0061] The display screen 150 is used to display images, videos, etc. The display screen 150 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Mini-LED, Micro-Led, Micro-oled, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device may include N display screens 150, where N is a positive integer greater than 1.
[0062] In addition, an operating system is running on the above components, such as the Android open source operating system developed by Google and the Windows operating system developed by Microsoft. Application programs can be installed and run on the operating system.
[0063] See also Figure 4 , which is a flow chart of a memory page management method provided by an embodiment of the present application. All memory pages can set priorities according to the first parameter and the second parameter. The highest level is AR:11, the second highest level is AR:10, the second lowest level is AR:01, and the lowest level is AR:00. The method includes:
[0064] S401: When the memory pages in the cold page list are recycled for the first time, the first group of memory pages accessed by the central processing unit before the first recycling is maintained in the hot page list.
[0065] The first group of memory pages refers to the memory pages in the hot page list and accessed by the central processor before the first recycling of the memory pages.
[0066] The hot page list refers to the Active LRU list. The memory pages included in the hot page list are all hot pages, which are frequently accessed memory pages.
[0067] When the memory pages in the cold page list are recycled for the first time, the first group of memory pages needs to be maintained in the hot page list. Each memory page in the first group of memory pages includes a first parameter and a second parameter. The first parameter can be a Referenced parameter, which can indicate whether the current memory page is accessed by the process of the central processing unit, and the second parameter can be an Active parameter, which can indicate the hot and cold state of the current memory page. The first parameter and the second parameter have a first value and a second value respectively. When the first parameter is the first value, it indicates that the memory page has been accessed by the central processing unit, and when the first parameter is the second value, it indicates that the memory page has not been accessed by the central processing unit; when the second parameter is the first value, it indicates that the hot and cold state of the memory page is hot, and when the second parameter is the second value, it indicates that the hot and cold state of the memory page is cold. The above-mentioned first value can be 1, and the second value can be 0. Therefore, the setting of the above two parameters can more accurately judge the activity level of the memory page.
[0068] Furthermore, since the first group of memory pages refers to the memory pages in the hot page list and have been accessed by the CPU before the first memory page recycling, the first group of memory pages can be represented as AR: 11. Therefore, it is necessary to maintain the first parameter and the second parameter of each memory page in the first group of memory pages to be the first value, that is, to maintain the first group of memory pages represented as AR: 11, so that the first group of memory pages can be maintained in the hot page list.
[0069] It should be noted that the specific function that represents "whether the memory page is accessed by the CPU" can be PTEyoung. If the memory page is accessed by the CPU, it is represented as PTE young = 1; if the memory page is not accessed by the CPU, it is represented as PTE young = 0. This application does not limit the specific representation form. Since the first group of memory pages are memory pages that have been accessed by the CPU, the first group of memory pages can be represented as PTE young = 1.
[0070] S402: When the memory pages in the cold page linked list are recycled for the first time, each memory page in the second group of memory pages that has not been accessed by the central processing unit before the first recycling is moved into the cold page linked list in sequence.
[0071] The second group of memory pages refers to the memory pages in the hot page list and have not been accessed by the central processor before the first recycling of the memory pages.
[0072] The cold page list refers to the Inactive LRU list. The memory pages contained in the cold page list are all cold pages, which are memory pages that are seldom accessed.
[0073] When the memory pages in the cold page linked list are recycled for the first time, each memory page in the second group of memory pages needs to be moved into the cold page linked list in sequence.
[0074] Similar to S401, each memory page in the second group of memory pages also includes a first parameter and a second parameter. Since the second group of memory pages refers to memory pages in the hot page list that have not been accessed by the central processing unit before the first recycling of the memory pages, the second group of memory pages can be represented as AR: 10. Then, it is necessary to change the first parameter of each memory page in the second group of memory pages from the second value to the first value, and the second parameter from the first value to the second value, that is, to update the second group of memory pages to AR: 01, so as to move each memory page in the second group of memory pages into the cold page list in sequence. And, since the second group of memory pages are memory pages that have not been accessed by the central processing unit, the second group of memory pages can be represented as PTEyoung = 0.
[0075] In some specific implementations, when the memory pages in the cold page list are first recycled, it can be determined whether each memory page in the second group of memory pages is an anonymous page. Anonymous pages can be understood as memory pages without file backgrounds, such as heaps, stacks, data segments, etc., and do not exist in the form of files.
[0076] Specifically, it is possible to determine whether each memory page in the second group of memory pages is an anonymous page based on the existence form of each memory page in the second group of memory pages. If each memory page in the second group of memory pages exists in the form of a file, it is determined that each memory page in the second group of memory pages is not an anonymous page, and each memory page in the second group of memory pages can be moved into the cold page list in sequence; if each memory page in the second group of memory pages exists in the form of a heap, stack, or data segment, etc., it is determined that each memory page in the second group of memory pages is an anonymous page, and it is necessary to protect each memory page in the second group of memory pages without performing a recycling operation. Among them, protection here refers to the process of ensuring that memory pages are not recycled.
[0077] S403: When the memory pages in the cold page list are recycled for the second time, the third group of memory pages accessed by the CPU after the first recycling and before the second recycling are in the hot page list.
[0078] The third group of memory pages refers to the memory pages in the hot page list that have been accessed by the CPU after the first memory page recycling and before the second memory page recycling. When the memory pages in the cold page list are recycled for the second time, the third group of memory pages needs to be maintained in the hot page list.
[0079] Similar to S401, each memory page in the third group of memory pages also includes a first parameter and a second parameter. Since the third group of memory pages refers to the memory pages in the hot page list and have been accessed by the central processing unit after the first recycling of the memory pages and before the second recycling, the third group of memory pages can be represented as AR: 11. Then, it is necessary to maintain the first parameter and the second parameter of each memory page in the third group of memory pages as the first value, so that the third group of memory pages is maintained in the Active list, that is, the third group of memory pages is maintained as AR: 11, so that the third group of memory pages can be maintained in the hot page list. And, since the second group of memory pages are memory pages that have been accessed by the central processing unit, the three groups of memory pages can be represented as PTE young = 1.
[0080] In some specific implementations, if a memory page in the cold page list is judged to have been accessed by the central processing unit when the memory page is recycled last, and is still judged to have been accessed by the central processing unit when the memory page in the cold page list is recycled next, then the memory page can be marked so that the memory page remains in the hot page list within a preset time range and will not be recycled.
[0081] S404: When the memory pages in the cold page linked list are recycled for the second time, each memory page in the fourth group of memory pages that has not been accessed by the central processor after the first recycling and before the second recycling is moved into the cold page linked list in sequence.
[0082] The fourth group of memory pages refers to the memory pages in the hot page list that have not been accessed by the CPU after the first memory page recycling and before the second memory page recycling. When the memory pages in the cold page list are recycled for the second time, each memory page in the fourth group of memory pages needs to be moved into the cold page list in sequence.
[0083] Similar to S401, each memory page in the fourth group of memory pages also includes a first parameter and a second parameter. Since the fourth group of memory pages refers to memory pages in the hot page list that have not been accessed by the central processing unit after the first recycling of the memory pages and before the second recycling, the fourth group of memory pages can be represented as AR: 10. Then, it is necessary to change the first parameter of each memory page in the fourth group of memory pages from the second value to the first value, and the second parameter from the first value to the second value, that is, to update the fourth group of memory pages to AR: 01, so as to move each memory page in the fourth group of memory pages into the cold page list in sequence. And, since the fourth group of memory pages are memory pages that have not been accessed by the central processing unit, the fourth group of memory pages can be represented as PTE young = 0.
[0084] In some specific implementations, the memory pages in the hot page list can also be cleaned up. Specifically, the first parameter and the second parameter of the memory page in the hot page list that needs to be cleaned up can be changed to the second value, so that the memory page can be directly placed in the cold page list. Exemplarily, the Deactivate_page function can be called to clean up the memory page. Regardless of whether the parameter of this memory page is AR:10 or AR:11, the first parameter and the second parameter can be directly updated to the second value, that is, expressed as AR:00, so as to clean up the memory page and speed up the recovery.
[0085] It is understandable that when the existing memory page management method places the memory page in the hot page list into the cold page list, it does not distinguish whether the memory page is accessed by the process of the central processing unit, and uniformly changes the second parameter to the second value, that is, sets Active=0, without modifying the first parameter, that is, maintaining Referenced unchanged. In other words, the parameter of the memory page can be changed from AR:10 to AR:00, or from AR:11 to AR:01. If the parameter of the modified memory page is AR:00, it is necessary to access the memory page twice before it can be represented as AR:10 and added to the hot page list, and the risk of memory page recycling is increased, so that the memory may also experience memory thrashing, causing a certain degree of delay to the current business, thereby affecting application performance.
[0086] The memory page management method disclosed in the present application is different from the existing memory page management method in that when the present application places the second group of memory pages and each memory page in the fourth group of memory pages into the cold page list, the memory page is represented as AR:01. Therefore, as long as the memory page is accessed again, it can be represented as AR:10 and added to the hot page list, thereby avoiding placing hotter pages in the cold page list, reducing the risk of memory page recycling, and further reducing the number of memory thrashing occurring in the memory pages of the application process.
[0087] In summary, the present application provides a memory management method, when the memory pages in the cold page list are recycled for the first time, the first group of memory pages that have been accessed by the central processing unit before the first recycling are maintained in the hot page list, and each memory page in the second group of memory pages that have not been accessed by the central processing unit before the first recycling is moved into the cold page list in sequence; when the memory pages in the cold page list are recycled for the second time, the third group of memory pages that have been accessed by the central processing unit after the first recycling and before the second recycling are maintained in the hot page list, and each memory page in the fourth group of memory pages that have not been accessed by the central processing unit after the first recycling and before the second recycling is moved into the cold page list in sequence. In this way, the hotter memory pages are avoided from being placed in the cold page list, the risk of recycling the hotter memory pages is reduced, and the number of memory thrashings that occur in the memory pages of the application process is reduced.
[0088] See also Figure 5 , which is a flow chart of another memory page management method provided by an embodiment of the present application. The method includes:
[0089] S501: When a page fault exception occurs, an initial new page is allocated in the cold page list.
[0090] Page fault exceptions can include hardware errors, hard interrupts, paging faults, page misses, page fault interrupts, page faults, etc. When the software attempts to access a page that is mapped in the virtual address space but is not currently loaded in the physical memory, an interrupt is issued by the memory management unit of the central processing unit.
[0091] In some specific implementations, the page fault exception may be caused by the first access triggering a page fault exception when the address space mapping relationship of the application is not established and the application applies for a virtual address space but does not allocate an actual physical page; in addition, the page fault exception may also be caused by the illegal access of the address space. It should be noted that this application does not limit the specific method of triggering the page fault exception.
[0092] When a page fault exception occurs, the initial new page corresponding to the page fault must first be allocated in the cold page list. In some specific implementations, an identifier is attached to the initial new page, which can be used to characterize the type of the initial new page. For example, the initial new page can be marked as a foreground application identifier and a non-foreground application identifier. Among them, the foreground application identifier can be understood as an identifier set when the initial new page is a page for foreground user interaction (that is, the identifier of the VIP application and the SystemServer system application), and the non-foreground application identifier can be understood as an identifier set when the initial new page is not a page for foreground user interaction.
[0093] S502: Setting parameters of the initial new page according to the identifier of the initial new page.
[0094] According to the foreground application identifier and the non-foreground application identifier, the electronic device can set the first parameter and the second parameter of the initial new page. Since the initial new page is in the cold page list, the initial new page also has a first parameter (i.e., the Referenced parameter) and a second parameter (i.e., the Active parameter), and the second parameter of the initial new page is the second value, i.e., 0. According to the foreground application identifier, the first parameter of the initial new page can be set to the first value, i.e., 1, and the parameter of the initial new page can be expressed as AR: 01. Alternatively, according to the non-foreground application identifier, the first parameter of the initial new page can be set to the second value, i.e., 0, and the parameter of the initial new page can be expressed as AR: 00.
[0095] It is understandable that the existing memory page management method does not distinguish whether the initial new page is a foreground application when placing the initial new page into the cold page list, and uniformly sets Active = 0 and Referenced = 0. However, if you want to place the initial new page into the hot page link, you need to change the parameters of the initial new page from AR:00 to AR:01, and then from AR:01 to AR:10, that is, you need to access the initial new page twice before you can represent it as AR:10 and add it to the hot page list, which increases the risk of recycling the initial new page, and the memory may also experience memory thrashing, causing a certain degree of delay to the current business, thereby affecting application performance.
[0096] The memory page management method disclosed in the present application is different from the existing memory page management method in that, see Table 1, which is a comparison table of initial new pages provided in an embodiment of the present application.
[0097] Table 1
[0098]
[0099] When an application containing a foreground application identifier (i.e., a VIP application and a SystemServer system application) encounters a page fault exception, the present application can place the initial new page into a cold page list and set the first parameter to the second value, i.e., 1. That is, the parameter of the initial new page can be represented as AR:01. Therefore, as long as the initial new page is accessed again, it can be represented as AR:10 and added to the hot page list, thereby avoiding placing hotter pages into the cold page list, greatly reducing the risk of memory page recovery, and thereby reducing the number of memory thrashings that occur in the memory pages of the application process.
[0100] It is understandable that after the initial new page is added to the hot page link, the operations of the above steps S401 to S404 can be performed.
[0101] See also Figure 6 , which is a flow chart of the third memory page management method provided by the embodiment of the present application. The method is applied to heat the memory page, that is, when the central processor of the electronic device 100 accesses the memory page, the following steps can be triggered, and the method includes:
[0102] S601: When the memory pages in the cold page list are heated for the first time, each memory page in the fifth group of memory pages accessed by the central processing unit before the first heating process is moved into the hot page list in sequence.
[0103] The fifth group of memory pages refers to the memory pages in the cold page list that have been accessed by the CPU before the first heating of the memory pages. When the first heating process is performed on the memory pages in the cold page list, each memory page in the fifth group of memory pages needs to be moved into the hot page list in sequence.
[0104] Similar to S401, each memory page in the fifth group of memory pages also includes a first parameter and a second parameter. Since the fifth group of memory pages refers to the memory pages in the cold page list and have been accessed by the central processing unit before the first heating of the memory pages, the fifth group of memory pages can be represented as AR: 01. Then, it is necessary to change the first parameter of each memory page in the fifth group of memory pages from the first value to the second value, and the second parameter from the second value to the first value, that is, to update the fifth group of memory pages to AR: 10, so as to move each memory page in the fifth group of memory pages into the hot page list in sequence. And, since the fifth group of memory pages are memory pages that have been accessed by the central processing unit, the fifth group of memory pages can be represented as PTE young = 1.
[0105] In some specific implementations, when the memory pages in the cold page list are heated for the first time, it can be determined whether each memory page in the fifth group of memory pages is an anonymous page. Specifically, it can be determined whether each memory page in the fifth group of memory pages is an anonymous page based on the existence form of each memory page in the fifth group of memory pages. If the existence form of each memory page in the fifth group of memory pages is in the form of a file, it is determined that each memory page in the fifth group of memory pages is not an anonymous page, and each memory page in the fifth group of memory pages can be moved into the hot page list in sequence; if the existence form of each memory page in the fifth group of memory pages is a heap, stack or data segment, etc., it is determined that each memory page in the fifth group of memory pages is an anonymous page, then it is necessary to protect each memory page in the fifth group of memory pages without performing a heating operation. Among them, protection here refers to the process of ensuring that the memory page is not heated.
[0106] S602: When the memory pages in the cold page list are heated for the second time, each memory page in the seventh group of memory pages accessed by the CPU after the first heating process and before the second heating process is moved into the hot page list in sequence.
[0107] The seventh group of memory pages refers to the memory pages in the cold page list that have been accessed by the CPU before the second heating of the memory pages and after the first heating. When the memory pages in the cold page list are heated for the second time, each memory page in the seventh group of memory pages needs to be moved into the hot page list in sequence.
[0108] Similar to S401, each memory page in the seventh group of memory pages also includes a first parameter and a second parameter. It is necessary to change the first parameter of each memory page in the seventh group of memory pages from the first value to the second value, and change the second parameter from the second value to the first value, that is, update the seventh group of memory pages to AR: 10, so as to move each memory page in the seventh group of memory pages into the hot page list in sequence. In addition, since the seventh group of memory pages are memory pages that have been accessed by the central processing unit, the seventh group of memory pages can be characterized as PTE young = 1.
[0109] It is understandable that after executing steps S601 and S602 to place the fifth group of memory pages and the seventh group of memory pages into the hot page list, the operations of steps S401 to S404 can be performed.
[0110] S603: If the number of times that the sixth group of memory pages that have not been accessed by the central processing unit before the first heating process is in the cold page list is greater than a preset threshold, the sixth group of memory pages is recycled.
[0111] S604: If the eighth group of memory pages that have not been accessed by the central processing unit are in the cold page list for a number of times greater than the preset threshold after the first heating process and before the second heating process, the eighth group of memory pages are recycled.
[0112] Since each memory page in the sixth group of memory pages and the eighth group of memory pages in steps S603 and S604 is in the cold page linked list and is not accessed by the CPU, the sixth group of memory pages and the eighth group of memory pages can be represented as AR: 00. Then, each memory page in the sixth group of memory pages and the eighth group of memory pages can be directly recycled.
[0113] In some specific implementations, after determining that the sixth group of memory pages and the eighth group of memory pages are not accessed by the central processing unit, it is possible to determine whether the current available memory of the electronic device system meets the memory page management requirements. If it does not meet the memory page management requirements, memory page recovery is performed to meet the memory page management requirements.
[0114] In other specific implementations, after determining that the sixth group of memory pages and the eighth group of memory pages are not accessed by the central processing unit, it can also be determined whether a new application is downloaded and installed. When a new application is downloaded and installed, memory page recycling is executed to meet memory page management requirements.
[0115] In other specific implementations, after determining that the sixth group of memory pages and the eighth group of memory pages have not been accessed by the central processing unit, it is also possible to determine whether the system's available memory is less than a preset threshold. If the system's available memory is less than the preset threshold, memory page recycling is executed to meet memory page management requirements (i.e., memory page recycling is triggered based on memory usage information of applications installed in the electronic device).
[0116] It should be noted that this application does not limit the specific recycling method.
[0117] See also Figure 7 , which is a schematic diagram of a memory page management method provided in an embodiment of the present application. From this figure, Table 2 can be obtained, which is a comparison table of hot page recovery provided in an embodiment of the present application.
[0118] Table 2
[0119] deal with Existing memory page management methods This application memory page management method LRU where the hot page is located ActiveLRU or InactiveLRU ActiveLRU Minimum number of changes before a hot page is recycled 1 (in InactiveLRU) 3
[0120] As can be seen from Table 2, the memory page management method provided by the present application increases the minimum number of changes for hot pages to be recycled from 1 to 3 times, avoiding the placement of hotter memory pages in the cold page list, reducing the risk of recycling hotter memory pages, and thereby reducing the number of memory thrashing that occurs in the memory pages of the application process.
[0121] An embodiment of the present application also provides a computer-readable storage medium, characterized in that a computer program or instruction is stored in the computer-readable storage medium, and when the computer program or instruction is executed, each function or step performed by the electronic device in the above method embodiment is implemented.
[0122] An embodiment of the present application also provides a computer program product, including a computer program or instructions, characterized in that when the computer program or instructions are executed by a processor, each function or step performed by the electronic device 100 in the above method embodiment is implemented.
[0123] See also Figure 8 , which is a schematic diagram of a memory page management device provided by an embodiment of the present application. The memory page management device 800 includes: a first recycling module 801 and a second recycling module 802.
[0124] Specifically, the first recycling module 801 is used to: when recycling the memory pages in the cold page list for the first time, maintain the first group of memory pages accessed by the central processing unit before the first recycling in the hot page list, and move each memory page in the second group of memory pages that have not been accessed by the central processing unit before the first recycling into the cold page list in sequence;
[0125] The above-mentioned second recycling module 802 is used for: when the memory pages in the cold page list are recycled for the second time, the third group of memory pages that have been accessed by the central processing unit after the first recycling and before the second recycling are maintained in the hot page list, and each memory page in the fourth group of memory pages that have not been accessed by the central processing unit after the first recycling and before the second recycling is moved into the cold page list in sequence.
[0126] In some specific implementations, each memory page in the first group of memory pages, the second group of memory pages, the third group of memory pages and the fourth group of memory pages corresponds to a first parameter and a second parameter, respectively. When the first parameter is a first value, it indicates that the memory page has been accessed by the central processing unit. When the first parameter is a second value, it indicates that the memory page has not been accessed by the central processing unit. When the second parameter is a first value, it indicates that the hot and cold state of the memory page is hot. When the second parameter is a second value, it indicates that the hot and cold state of the memory page is cold.
[0127] In some specific implementations, the first recycling module 801 is specifically used to maintain the first parameter and the second parameter of each memory page in the first group of memory pages accessed by the central processing unit before the first recycling as the first value, so that the first group of memory pages is maintained in the hot page list.
[0128] In some specific implementations, the above-mentioned first recycling module 801 is specifically used to: change the first parameter of each memory page in the second group of memory pages that has not been accessed by the central processing unit before the first recycling from the second value to the first value, and change the second parameter from the first value to the second value, so as to move each memory page in the second group of memory pages into the cold page list in turn.
[0129] In some specific implementations, the above-mentioned second recycling module 802 is specifically used to: maintain that after the first recycling and before the second recycling, the first parameter and the second parameter of each memory page in the third group of memory pages accessed by the central processing unit are both the first value, so that the third group of memory pages is maintained in the hot page list.
[0130] In some specific implementations, the above-mentioned second recycling module 802 is specifically used to: change the first parameter of each memory page in the fourth group of memory pages that has not been accessed by the central processing unit after the first recycling and before the second recycling from the second value to the first value, and change the second parameter from the first value to the second value, so as to move each memory page in the fourth group of memory pages into the cold page list in sequence.
[0131] In some specific implementations, the memory page management device 800 further includes a first new page module and a second new page module; specifically, the first new page module is used to allocate an initial new page in a cold page list when a page fault exception occurs; the second new page module is used to set parameters of the initial new page according to an identifier of the initial new page, and the parameters of the initial new page are used to characterize the activity level of the initial new page.
[0132] In some specific implementations, the identifier of the initial new page includes a foreground application identifier and a non-foreground application identifier; the parameters of the initial new page include a first parameter and a second parameter, when the first parameter is a first value, it indicates that the initial new page has been accessed by the central processing unit, when the first parameter is a second value, it indicates that the initial new page has not been accessed by the central processing unit, and the second parameter indicates that the hot and cold state of the initial new page is cold. Then, the second new page module is used to: set the first parameter of the initial new page to the first value according to the foreground application identifier; or, set the first parameter of the initial new page to the second value according to the non-foreground application identifier.
[0133] In some specific implementations, the heating process for the memory page is the central processing unit accessing the memory page, and the memory page management device 800 further includes: a first heating module and a second heating module; the first heating module is used for: when the memory pages in the cold page list are heated for the first time, each memory page in the fifth group of memory pages accessed by the central processing unit before the first heating process is moved into the hot page list in sequence; the second heating module is used for: when the memory pages in the cold page list are heated for the second time, each memory page in the seventh group of memory pages accessed by the central processing unit after the first heating process and before the second heating process is moved into the hot page list in sequence.
[0134] In some specific implementations, the memory page management device 800 further includes: a third recycling module. The third recycling module is specifically used to recycle the sixth group of memory pages if the number of times that the sixth group of memory pages that have not been accessed by the central processor before the first heating process is maintained in the cold page list is greater than a preset threshold.
[0135] In some specific implementations, the memory page management device 800 further includes: a fourth recycling module. If the eighth group of memory pages that have not been accessed by the central processor are in the cold page list for a number of times greater than a preset threshold after the first heating process and before the second heating process, the eighth group of memory pages are recycled.
[0136] In some specific implementations, each memory page in the fifth group of memory pages, the sixth group of memory pages, the seventh group of memory pages and the eighth group of memory pages corresponds to a first parameter and a second parameter, respectively. When the first parameter is a first value, it indicates that the memory page has been accessed by the central processing unit. When the first parameter is a second value, it indicates that the memory page has not been accessed by the central processing unit. When the second parameter is a first value, it indicates that the hot and cold state of the memory page is hot. When the second parameter is a second value, it indicates that the hot and cold state of the memory page is cold.
[0137] In some specific implementations, the above-mentioned first heating module is specifically used to: change the first parameter of each memory page in the fifth group of memory pages accessed by the central processing unit before the first heating process from the first value to the second value, and change the second parameter from the second value to the first value, so that each memory page in the fifth group of memory pages is moved into the hot page list in turn.
[0138] In some specific implementations, the second heating module is specifically used to: change the first parameter of each memory page in the seventh group of memory pages accessed by the central processing unit after the first heating treatment and before the second heating treatment from the first value to the second value, and change the second parameter from the second value to the first value, so that each memory page in the seventh group of memory pages is moved into the hot page list in sequence.
[0139] To sum up, the present application discloses a memory page management device, including a first recycling module and a second recycling module, thereby avoiding placing hotter memory pages into a cold page list, reducing the risk of recycling hotter memory pages, and thereby reducing the number of memory thrashing occurring in the memory pages of an application process.
[0140] Through the description of the above implementation methods, technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0141] In the several embodiments provided in this embodiment, it should be understood that the disclosed system and method can be implemented in other ways. For example, the embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0142] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0143] In addition, each functional unit in each embodiment of the present embodiment may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0144] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this embodiment is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform all or part of the steps of the method described in each embodiment. The aforementioned storage medium includes: flash memory, mobile hard disk, read-only memory, random access memory, disk or optical disk and other media that can store program codes.
[0145] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A memory page management method, characterized in that: The method comprises: When the memory pages in the cold page Inactive list are recycled for the first time, the first group of memory pages accessed by the CPU before the first recycling is maintained in the hot page Active list, and each memory page in the second group of memory pages that has not been accessed by the CPU before the first recycling is moved into the Inactive list in sequence; When the memory pages in the Inactive linked list are recycled for the second time, the third group of memory pages that have been accessed by the central processing unit after the first recycling and before the second recycling are maintained in the Active linked list, and each memory page in the fourth group of memory pages that has not been accessed by the central processing unit after the first recycling and before the second recycling is moved into the Inactive linked list in sequence.
2. The method according to claim 1, characterized in that: Each memory page in the first group of memory pages, the second group of memory pages, the third group of memory pages and the fourth group of memory pages corresponds to a first parameter and a second parameter respectively. When the first parameter is a first value, it indicates that the memory page has been accessed by the central processing unit. When the first parameter is a second value, it indicates that the memory page has not been accessed by the central processing unit. When the second parameter is a first value, it indicates that the hot and cold state of the memory page is hot. When the second parameter is a second value, it indicates that the hot and cold state of the memory page is cold.
3. The method according to claim 2, characterized in that The maintaining, before the first recycling, that the first group of memory pages accessed by the central processor are in the hot page active list includes: The first parameter and the second parameter of each memory page in the first group of memory pages accessed by the central processing unit before the first recycling are maintained as the first value, so that the first group of memory pages is maintained in the hot page active linked list.
4. The method according to claim 2, characterized in that: The step of sequentially moving each memory page in the second group of memory pages that has not been accessed by the central processing unit before the first recycling into the Inactive linked list includes: The first parameter of each memory page in the second group of memory pages that has not been accessed by the central processing unit before the first recycling is changed from the second value to the first value, and the second parameter is changed from the first value to the second value, so as to move each memory page in the second group of memory pages into the Inactive linked list in sequence.
5. The method according to claim 2, characterized in that: The maintaining, after the first recycling and before the second recycling, that the third group of memory pages accessed by the central processing unit are in the Active linked list comprises: After the first recycling and before the second recycling, the first parameter and the second parameter of each memory page in the third group of memory pages accessed by the central processing unit are maintained to be the first value, so that the third group of memory pages is maintained in the Active linked list.
6. The method according to claim 2, characterized in that The step of sequentially moving each memory page in the fourth group of memory pages that has not been accessed by the central processing unit after the first recycling and before the second recycling into the Inactive linked list includes: After the first recycling and before the second recycling, the first parameter of each memory page in the fourth group of memory pages that has not been accessed by the central processing unit is changed from the second value to the first value, and the second parameter is changed from the first value to the second value, so as to move each memory page in the fourth group of memory pages into the Inactive linked list in sequence.
7. The method according to claim 1, characterized in that The method further comprises: When a page fault exception occurs, an initial new page is allocated in the Inactive linked list; According to the identifier of the initial new page, an initial new page parameter is set, and the initial new page parameter is used to characterize the activity level of the initial new page.
8. The method according to claim 7, characterized in that The identifier of the initial new page includes a foreground application identifier and a non-foreground application identifier; the initial new page parameter includes a first parameter and a second parameter, when the first parameter is a first value, it indicates that the initial new page has been accessed by the central processing unit, when the first parameter is a second value, it indicates that the initial new page has not been accessed by the central processing unit, and the second parameter indicates that the hot and cold state of the initial new page is cold; The step of setting the initial new page parameters according to the identifier of the initial new page includes: According to the foreground application identifier, setting the first parameter to a first value; Or, according to the non-foreground application identifier, the first parameter is set to a second value.
9. The method according to claim 1, characterized in that: The heating process for the memory page is that the central processing unit accesses the memory page, and the method further includes: When the memory pages in the Inactive linked list are heated for the first time, each memory page in the fifth group of memory pages accessed by the central processing unit before the first heating process is sequentially moved into the Active linked list; When the memory pages in the Inactive linked list are heated for the second time, each memory page in the seventh group of memory pages accessed by the central processing unit after the first heating process and before the second heating process is moved into the Active linked list in sequence.
10. The method according to claim 9, characterized in that The method further comprises: If the number of times that the sixth group of memory pages that have not been accessed by the central processing unit before the first heating process are maintained in the Inactive linked list is greater than a preset threshold, the sixth group of memory pages are recycled.
11. The method according to claim 10, characterized in that The method further comprises: If the eighth group of memory pages that have not been accessed by the central processing unit are maintained in the Inactive linked list for a number of times greater than the preset threshold after the first heating process and before the second heating process, the eighth group of memory pages are recycled.
12. The method according to any one of claims 9 to 11, characterized in that: Each memory page in the fifth group of memory pages, the sixth group of memory pages, the seventh group of memory pages and the eighth group of memory pages corresponds to a first parameter and a second parameter respectively. When the first parameter is a first value, it indicates that the memory page has been accessed by the central processing unit. When the first parameter is a second value, it indicates that the memory page has not been accessed by the central processing unit. When the second parameter is a first value, it indicates that the hot and cold state of the memory page is hot. When the second parameter is a second value, it indicates that the hot and cold state of the memory page is cold.
13. The method according to claim 12, characterized in that Before the first heating process, each memory page in the fifth group of memory pages accessed by the central processing unit is sequentially moved into the Active linked list, including: The first parameter of each memory page in the fifth group of memory pages accessed by the central processing unit before the first heating process is changed from the first value to the second value, and the second parameter is changed from the second value to the first value, so that each memory page in the fifth group of memory pages is moved into the Active linked list in sequence.
14. The method according to claim 12, characterized in that The step of sequentially moving each memory page in the seventh group of memory pages accessed by the central processing unit after the first heating process and before the second heating process into the Active linked list comprises: The first parameter of each memory page in the seventh group of memory pages accessed by the central processing unit after the first heating treatment and before the second heating treatment is changed from the first value to the second value, and the second parameter is changed from the second value to the first value, so that each memory page in the seventh group of memory pages is moved into the Active linked list in sequence.
15. An electronic device, characterized in that: including a processor and a memory; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor performs the method according to any one of claims 1 to 14.
16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program or instruction, and when the computer program or instruction is executed, the method according to any one of claims 1 to 14 is implemented.