Memory management method and device, electronic equipment and storage medium
By obtaining the average memory footprint of the resident service and determining the memory group, and obtaining the corresponding page replacement strategy, the problem of inflexible memory management in the existing technology is solved, and the system performance and effectiveness of memory management are improved.
Patent Information
- Application Number
- CN202311135611.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-04
- Publication Date
- 2025-03-04
AI Technical Summary
When the existing technology deals with insufficient memory, excessive dependence on Swap leads to serious decline in system performance, and it is impossible to distinguish different applications, and it is impossible to prioritize important applications, and lacks a dynamic adaptation memory management mechanism.
By obtaining the average memory footprint of the resident service, the corresponding memory group is determined, and the page replacement policy corresponding to the memory group is obtained, and the memory page that needs to be replaced is obtained based on this policy.
It realizes grouping of resident service programs based on the average memory usage, obtaining page replacement strategies corresponding to the divided memory groups, so that different service programs can be optimized more carefully, and improving the flexibility and effectiveness of memory management.
Smart Images

Figure CN119557079A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and more specifically, to a memory management method, device, electronic device and storage medium. Background Art
[0002] Swap refers to the swap partition (virtual memory partition) in the Linux system, which is similar to the virtual memory in Windows. The function of Swap is to virtualize the hard disk (disk) space (that is, the SWAP partition) into memory after the physical memory of the Linux system is used up, thereby solving the problem of insufficient memory capacity. However, although Swap can provide additional virtual memory space when the memory is insufficient, since the hard disk / Flash read and write speed is much lower than RAM, over-reliance on Swap may also seriously affect system performance. Summary of the invention
[0003] The present application proposes a memory management method, device, electronic device and storage medium to improve the above-mentioned problems.
[0004] In a first aspect, an embodiment of the present application provides a memory management method, which is applied to an electronic device, and the method includes: obtaining an average memory occupancy value of a resident service; determining a corresponding memory group based on the average memory occupancy value; obtaining a page replacement policy corresponding to the memory group; and obtaining a memory page that needs to be replaced in the resident service based on the page replacement policy.
[0005] In a second aspect, an embodiment of the present application provides a memory management device that runs on an electronic device, the device comprising: a memory occupancy value acquisition module for acquiring an average memory occupancy value of a resident service; a memory group determination module for determining a corresponding memory group based on the average memory occupancy value; a page replacement policy acquisition module for acquiring a page replacement policy corresponding to the memory group; and a memory management module for acquiring memory pages that need to be replaced in the resident service based on the page replacement policy.
[0006] In a third aspect, the present application provides an electronic device comprising one or more processors and a memory; one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the method of the first aspect above.
[0007] In a fourth aspect, the present application provides a computer-readable storage medium having program code stored therein, wherein the method of the first aspect is executed when the program code is run.
[0008] The present application provides a memory management method, device, electronic device and storage medium. The method obtains the average memory occupancy value of the resident service; determines the corresponding memory group according to the average memory occupancy value; obtains the page replacement policy corresponding to the memory group; and obtains the memory page that needs to be replaced in the resident service based on the page replacement policy. Thus, through the above method, it is possible to group the resident service programs according to the average memory occupancy, and then obtain the page replacement policy corresponding to the divided memory group, so that different service programs can be optimized more meticulously, improving the flexibility and effectiveness of memory management. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0010] Figure 1 A flowchart of a memory management method provided by an embodiment of the present application is shown.
[0011] Figure 2 A flowchart of a memory management method provided by another embodiment of the present application is shown.
[0012] Figure 3 A flowchart of a memory management method provided by yet another embodiment of the present application is shown.
[0013] Figure 4 A flowchart of a memory management method provided in yet another embodiment of the present application is shown.
[0014] Figure 5 A structural block diagram of a memory management device provided in an embodiment of the present application is shown.
[0015] Figure 6 A structural block diagram of an electronic device provided in an embodiment of the present application is shown.
[0016] Figure 7 A storage unit for storing or carrying program codes for implementing a memory management method according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0017] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0018] In Android or other Linux-based operating systems, Swap is a traditional memory management strategy that allows the operating system to "swap out" data in memory to the hard disk (or other storage media) to free up memory space for other processes. When the "swapped out" data is needed again, the operating system will "swap it back" from the hard disk to the memory.
[0019] Although Swap can provide additional virtual memory space when memory is insufficient, the inventors have found that since the read and write speed of the hard disk / sFlah is much lower than that of RAM, over-reliance on Swap may also seriously affect system performance; in addition, when performing Swap memory operations, different applications cannot be distinguished, and important applications cannot be given priority, that is, a Swap strategy that treats all applications equally may cause performance degradation of key applications (i.e., important applications); and there is a lack of a dynamically adaptive memory management mechanism, and the Swap strategy cannot be adjusted according to the actual memory usage of the application.
[0020] After long-term research, the inventor found that the average memory occupancy value of the resident service can be obtained; the corresponding memory group can be determined according to the average memory occupancy value; the page replacement policy corresponding to the memory group can be obtained; and the memory page that needs to be replaced in the resident service can be obtained based on the page replacement policy. Thus, the resident service programs can be grouped according to the average memory occupancy, and then the page replacement policy corresponding to the divided memory group can be obtained, so that different service programs can be optimized more meticulously, and the flexibility and effectiveness of memory management can be improved.
[0021] Therefore, in order to improve the above-mentioned problems, the inventor proposed the memory management method, electronic device and computer-readable storage medium provided in the present application, which can group resident service programs according to the average memory occupancy, and then obtain the page replacement strategy corresponding to the divided memory group, so that different service programs can be optimized more finely, thereby improving the flexibility and effectiveness of memory management.
[0022] In order to facilitate a better understanding of the solutions described in the embodiments of the present application, the relevant terms involved in the embodiments of the present application are briefly described below.
[0023] LRU algorithm: LRU is the abbreviation of Least Recently Used, which is a commonly used page replacement algorithm that selects the page that has not been used the longest to be eliminated. This algorithm gives each page an access field to record the time t that has elapsed since a page was last accessed. When a page needs to be eliminated, the page with the largest t value among the existing pages, that is, the page that has been used the least recently, is selected for elimination.
[0024] FIFO algorithm: First In First Out Algorithm, is the simplest paging replacement algorithm. It means that every time a new page needs to be loaded, the page that has been loaded into the memory the longest will be selected for swapping out.
[0025] The embodiments of the present application will be described in detail below with reference to the accompanying drawings.
[0026] See also Figure 1 , shows a flow chart of a memory management method provided by an embodiment of the present application, and this embodiment provides a memory management method, which can be applied to electronic devices, and specifically can be applied to an operating system configured in the electronic device, the electronic device can be a mobile phone, a computer, a tablet or a wearable electronic device, and the specific type of the electronic device may not be limited. The method includes:
[0027] Step S110: Obtain the average memory usage value of the resident service.
[0028] In this implementation, the resident service can be understood as the process of managing the core services of the operating system. These core services can be services that come with the system. For example, the core services can include services of functional types such as graphics display, audio, recording, and camera. These core services can also be third-party applications. For example, these third-party applications can include applications that are strongly related to user interaction, applications that are strongly related to the timeliness of user message processing, navigation applications, and music listening applications, etc. The specific types are not limited.
[0029] Once a resident service is started, it will continue to run and will not stop automatically unless there is human intervention.
[0030] As an implementation method, a resident service may be pre-selected and assigned a corresponding application ID so that the operating system can directly identify the resident service based on the application ID. The pre-selection criteria may be to select an application that is not expected to be disturbed by other programs or that the user considers to be more important as a resident service, or to set the selection criteria based on the actual needs of the user, and there is no specific limitation.
[0031] During the operation of a resident service, the memory usage of the operating system may change. For example, the initial memory usage of the resident service may be A. If the operating system's memory is insufficient, the data (or part of the data) of the resident service may be swapped out. At this time, the memory usage of the operating system by the resident service will be less than A. When the operating system needs the data swapped out by the resident service again, this part of the data will be swapped in. At this time, the memory usage of the operating system by the resident service may be equal to A or greater than A (as the running time of the resident service increases, the data it generates will increase, so it can have a larger memory usage value).
[0032] The average memory usage value of the resident service can be understood as the average memory usage value of the resident service in a specified time period. The specific value of the specified time period may not be limited. For example, the value of the specified time period may be 24 hours, one week, one month, etc.
[0033] As an implementation method, the memory usage value of the resident service at each time point within a specified time period can be obtained to obtain multiple memory usage values, and then the sum of the multiple memory usage values can be divided by the specified time period, and the obtained memory usage value can be used as the average memory usage value of the resident service. For the same resident service, the average memory usage value obtained can be different if the value range of the specified time period is different.
[0034] As an implementation method, after obtaining the average memory usage value of the resident service, if the average memory usage value changes, the changed average memory usage value can be used to update the average memory usage value, and the updated result can be used to execute subsequent steps. The specific process will not be repeated here, so that the operating system can dynamically adjust the memory group of the service program according to the memory usage of the service program, thereby enabling the system's resource management to better adapt to the operating environment.
[0035] Step S120: determining a corresponding memory group according to the average memory occupancy value.
[0036] As a method, at least one preset memory occupancy range can be obtained, each memory occupancy range corresponds to a memory group, and then the memory occupancy range corresponding to the average memory occupancy value is obtained, and the memory group corresponding to the memory occupancy range is used as the memory group corresponding to the average memory occupancy value.
[0037] Among them, the resident services can be grouped in advance according to their memory usage, so that the memory management of different service programs can be more detailed and targeted. Specifically, the running resident service programs can be divided into different memory groups according to the size of their memory usage values. Optionally, the more important the application is to the operation of the operating system, the larger the corresponding memory usage value can be.
[0038] In the process of dividing memory groups according to the memory usage values of resident services, as a specific implementation method, a memory usage range AB can be set. Each memory usage range can include multiple memory usage values, where A is smaller than B, and the difference between the two is greater than a specified threshold. The specific value of the specified threshold may not be limited. For example, the specified threshold may be 30MB. Service programs with memory usage values within the range AB are placed in the Set_1 memory group (service programs in the same Set combination will be divided into the same memory group); similarly, a memory usage range CD can be set. The memory usage range CD also meets the setting requirements of AB, and the memory usage range CD has no intersection with AB. Then, service programs with memory usage values within the range CD can be placed in the Set_2 memory group, and so on, until all service programs are grouped.
[0039] Among them, the size relationship between B and C may not be limited. For example, B may be smaller than C. In this case, the memory occupancy value within the memory occupancy range CD is greater than the memory occupancy value within the memory occupancy range AB; B may also be greater than C. In this case, the memory occupancy value within the memory occupancy range CD is less than the memory occupancy value within the memory occupancy range AB.
[0040] When implementing memory group division, the memory group division can be completed based on the memcg grouping mechanism in Linux. The specific implementation principle and implementation process will not be repeated here.
[0041] Step S130: Obtain a page replacement policy corresponding to the memory group.
[0042] After determining the memory group corresponding to the average memory occupancy value, the page replacement policy corresponding to the memory group can be obtained, and then the data of the resident service can be allocated and exchanged in a targeted manner according to the corresponding page replacement policy, so that memory management can be flexibly performed according to the memory occupancy size of the operating system by the service program.
[0043] Among them, different memory groups may correspond to different page replacement strategies.
[0044] Step S140: acquiring the memory page that needs to be replaced in the resident service based on the page replacement policy.
[0045] In this implementation, the page replacement policy is used to help the operating system decide which data needs to be “swapped out” and which data needs to be “swapped in”.
[0046] As a method, after obtaining the page replacement policy corresponding to the memory group, the memory pages that need to be replaced in the resident service can be directly obtained based on the page replacement policy, and then when the operating system has a memory space adjustment requirement, the determined memory pages that need to be replaced can be directly "swapped out" or "swapped in".
[0047] As an implementation mode, the memory page that needs to be replaced in the resident service may be a content page that does not affect the normal operation of the resident service.
[0048] The memory management method provided in this embodiment obtains the average memory occupancy value of the resident service; determines the corresponding memory group according to the average memory occupancy value; obtains the page replacement policy corresponding to the memory group; and obtains the memory page that needs to be replaced in the resident service based on the page replacement policy. Thus, through the above method, it is possible to group the resident service programs according to the average memory occupancy, and then obtain the page replacement policy corresponding to the divided memory group, so that different service programs can be optimized more meticulously, and the flexibility and effectiveness of memory management can be improved.
[0049] See also Figure 2 , shows a flow chart of a memory management method provided by another embodiment of the present application. This embodiment provides a memory management method that can be applied to an electronic device. The method includes:
[0050] Step S210: Obtain the average memory usage value of the resident service.
[0051] The specific implementation of step S210 may refer to the relevant description of step S110 in the aforementioned embodiment, which will not be repeated here.
[0052] Step S220: determining a corresponding memory group according to the average memory occupancy value.
[0053] The specific implementation of step S220 may refer to the relevant description of step S120 in the aforementioned embodiment, which will not be repeated here.
[0054] Step S230: obtaining page miss parameters corresponding to each of the plurality of page replacement strategies after implementing the plurality of page replacement strategies on the memory group.
[0055] In this embodiment, different page replacement strategies (i.e., Swap strategies) can be configured in advance for different memory groups, so that after determining to which memory group the average memory occupancy value of the resident service belongs, the page replacement strategy configured for the memory group can be directly used as the page replacement strategy corresponding to the resident service. Among them, different page replacement strategies may include not performing Swap, performing Swap using the LRU algorithm, and performing Swap using the FIFO algorithm, or may include other more types of page replacement algorithms (paging replacement algorithms), which are not listed here one by one.
[0056] In the process of pre-configuring the page replacement policy corresponding to each memory group, as an implementation method, a variety of page replacement policies can be implemented on each memory group in turn in an offline manner to see which replacement effect is better. Optionally, the larger the remaining memory of the operating system after the replacement, the better the replacement effect can be considered, and then the page replacement policy corresponding to the best replacement effect can be configured as the page replacement policy corresponding to the memory group.
[0057] As an implementation method, the page fault parameters corresponding to each memory group after implementing multiple page replacement strategies can be obtained in turn. The page fault parameter (pagefault) can also be understood as a page fault exception parameter, a page fault interrupt parameter, or a page fault error parameter. The smaller the value of the page fault parameter, the better the replacement effect.
[0058] Step S240: taking the page replacement policy corresponding to the page miss parameter with the smallest value as the page replacement policy corresponding to the memory group.
[0059] As an implementation mode, when the page miss parameters corresponding to each memory group are obtained in sequence after implementing multiple page replacement policies on each memory group, the page replacement policy corresponding to the page miss parameter with the smallest value can be configured as the page replacement policy corresponding to the memory group.
[0060] Step S250: acquiring the memory page that needs to be replaced in the resident service based on the page replacement policy.
[0061] The specific implementation of step S250 may refer to the relevant description of step S140 in the aforementioned embodiment, which will not be repeated here.
[0062] The memory management method provided in this embodiment obtains the average memory occupancy value of the resident service; determines the corresponding memory group according to the average memory occupancy value; obtains the page missing parameters corresponding to each of the memory groups after implementing multiple page replacement strategies; uses the page replacement strategy corresponding to the page missing parameter with the smallest value as the page replacement strategy corresponding to the memory group; and obtains the memory page that needs to be replaced in the resident service based on the page replacement strategy. Thus, through the above method, it is possible to group the resident service programs according to the average memory occupancy, and then obtain the page replacement strategy corresponding to the divided memory group, so that it is possible to optimize more carefully for different service programs, and improve the flexibility and effectiveness of memory management.
[0063] At the same time, by configuring different page replacement policies for different memory groups in advance, it is convenient to quickly determine the page replacement policy corresponding to the resident service, thereby effectively improving the memory management efficiency.
[0064] See also Figure 3 , shows a flowchart of a memory management method provided by another embodiment of the present application. This embodiment provides a memory management method that can be applied to an electronic device. The method includes:
[0065] Step S310: Obtain the average memory usage value of the resident service.
[0066] The specific implementation of step S310 may refer to the relevant description of step S110 in the aforementioned embodiment, which will not be repeated here.
[0067] Step S320: determining a corresponding memory group according to the average memory occupancy value.
[0068] The specific implementation of step S320 may refer to the relevant description of step S120 in the aforementioned embodiment, which will not be repeated here.
[0069] Step S331: If the memory group is the first memory group, no page replacement is performed as the page replacement strategy corresponding to the memory group.
[0070] In the process of pre-configuring the page replacement policy corresponding to each memory group, as an implementation method, the page replacement policy corresponding to each memory group can also be directly specified. The principle (basis) specified here can be that the larger the overall memory usage value in the memory group, the more remaining memory the operating system has after the corresponding page replacement policy is replaced; correspondingly, the smaller the overall memory usage value in the memory group, the less remaining memory the operating system has after the corresponding page replacement policy is replaced. Alternatively, the specified principle can also be randomly specified, which can be selected according to actual needs.
[0071] In this implementation, when the page replacement strategy corresponding to each memory group is specified, assuming that the page replacement strategy corresponding to the first memory group is pre-specified as "no page replacement", if it is determined that the memory group corresponding to the average memory occupancy value of the resident service is the first memory group, then no page replacement can be directly used as the page replacement strategy corresponding to the memory group.
[0072] Step S332: If the memory group is the second memory group, the LRU algorithm is used to perform page replacement as the page replacement strategy corresponding to the memory group.
[0073] Similarly, assuming that the page replacement policy corresponding to the second memory group is pre-specified as "using the LRU algorithm for page replacement", if it is determined that the memory group corresponding to the average memory occupancy value of the resident service is the second memory group, then the LRU algorithm for page replacement can be directly used as the page replacement policy corresponding to the memory group.
[0074] Step S333: If the memory group is the third memory group, a FIFO algorithm is used to perform page replacement as a page replacement strategy corresponding to the memory group, and the memory occupancy ranges of the first memory group, the second memory group and the third memory group are all different.
[0075] Similarly, assuming that the page replacement policy corresponding to the third memory group is pre-specified as "using the FIFO algorithm for page replacement", if it is determined that the memory group corresponding to the average memory occupancy value of the resident service is the third memory group, then the FIFO algorithm for page replacement can be directly used as the page replacement policy corresponding to the memory group.
[0076] It should be noted that, in this implementation, the memory occupation ranges of the first memory group, the second memory group and the third memory group are all different and do not overlap with each other.
[0077] Step S340: acquiring the memory page that needs to be replaced in the resident service based on the page replacement policy.
[0078] The specific implementation of step S340 may refer to the relevant description of step S140 in the aforementioned embodiment, which will not be repeated here.
[0079] The memory management method provided in this embodiment obtains the average memory occupancy value of the resident service; determines the corresponding memory group according to the average memory occupancy value; if the memory group is the first memory group, no page replacement will be performed as the page replacement strategy corresponding to the memory group; if the memory group is the second memory group, the LRU algorithm will be used for page replacement as the page replacement strategy corresponding to the memory group; if the memory group is the third memory group, the FIFO algorithm will be used for page replacement as the page replacement strategy corresponding to the memory group, and the memory occupancy ranges between the first memory group, the second memory group and the third memory group are all different; based on the page replacement strategy, the memory page that needs to be replaced in the resident service is obtained. Thus, through the above method, it is possible to group the resident service programs according to the average memory occupancy, and then obtain the page replacement strategy corresponding to the divided memory group, so that different service programs can be optimized more meticulously, and the flexibility and effectiveness of memory management can be improved.
[0080] At the same time, by specifying corresponding page replacement policies for different memory groups in advance, it is convenient to quickly determine the page replacement policy corresponding to the resident service, thereby effectively improving the memory management efficiency.
[0081] See also Figure 4 , shows a flowchart of a memory management method provided by another embodiment of the present application. This embodiment provides a memory management method that can be applied to an electronic device. The method includes:
[0082] Step S410: Obtain the average memory usage value of the resident service.
[0083] The specific implementation of step S410 may refer to the relevant description of step S110 in the aforementioned embodiment, which will not be repeated here.
[0084] Step S420: determining a corresponding memory group according to the average memory occupancy value.
[0085] The specific implementation of step S420 may refer to the relevant description of step S120 in the aforementioned embodiment, which will not be repeated here.
[0086] Step S430: Obtain a page replacement policy corresponding to the memory group.
[0087] The specific implementation of step S430 may refer to the relevant description of step S130 in the aforementioned embodiment, which will not be repeated here.
[0088] Step S440: acquiring the memory page that needs to be replaced in the resident service based on the page replacement policy.
[0089] The specific implementation of step S440 may refer to the relevant description of step S140 in the aforementioned embodiment, which will not be repeated here.
[0090] Step S450: determining the storage location of the memory page to be replaced after being replaced based on the memory group.
[0091] As an implementation method, after selecting the memory page to be replaced by the operating system through the page replacement strategy, the storage location of the memory page to be replaced after being replaced can be determined based on the memory group, or the storage location of the memory page to be replaced after being replaced can be determined according to actual business needs.
[0092] Among them, the storage position of the memory page to be replaced after being replaced corresponding to each memory group can be pre-specified, so that in the process of determining the storage position of the memory page to be replaced after being replaced based on the memory group, the memory page to be replaced can be directly placed in the corresponding storage position.
[0093] In this embodiment, the storage location after the memory page that needs to be replaced is replaced may include storage locations such as internal memory, memory to be compressed, flash memory or disk. Among them, the internal memory and the memory to be compressed have fast data transmission efficiency but high cost, while the flash memory and the disk have low cost and large storage capacity but slow data transmission efficiency. In this way, the storage location after the memory page that needs to be replaced is replaced can be determined according to actual needs and the size of the memory occupancy value in the memory group. For example, a memory group with generally large memory occupancy values may require a storage location with fast data transmission efficiency to avoid the low efficiency of memory page swapping out affecting the stability of the operating system; or a memory group with generally small memory occupancy values may require a low-cost storage location to save memory management costs as much as possible.
[0094] It should be noted that the method in the embodiment of the present application can also be applied to the memory space management of resources such as the CPU related to the operating system running core. The specific implementation principles and processes can be referred to the above description and will not be repeated here.
[0095] The memory management method provided in this embodiment obtains the average memory occupancy value of the resident service; determines the corresponding memory group according to the average memory occupancy value; obtains the page replacement policy corresponding to the memory group; obtains the memory page that needs to be replaced in the resident service based on the page replacement policy; and determines the storage location of the memory page that needs to be replaced after being replaced based on the memory group. Thus, through the above method, it is possible to group the resident service programs according to the average memory occupancy, and then obtain the page replacement policy corresponding to the divided memory group, so that it is possible to optimize more carefully for different service programs, and improve the flexibility and effectiveness of memory management.
[0096] At the same time, by predetermining the storage location of the memory page that needs to be replaced after it is replaced, accurate memory page replacement can be facilitated, thereby improving the reliability of memory management.
[0097] See also Figure 5 , is a structural block diagram of a memory management device provided in an embodiment of the present application. This embodiment provides a memory management device 500, which can be run on an electronic device. The device 500 includes a memory occupancy value acquisition module 510, a memory group determination module 520, a page replacement strategy acquisition module 530, and a memory management module 540:
[0098] The memory occupancy value acquisition module 510 is used to acquire the average memory occupancy value of the resident service.
[0099] Optionally, the apparatus 500 may further include an updating module for updating the average memory occupancy value with the changed average memory occupancy value after acquiring the average memory occupancy value of the resident service if the average memory occupancy value changes.
[0100] The memory group determination module 520 is used to determine the corresponding memory group according to the average memory occupancy value.
[0101] As an implementation method, the memory group determination module 520 can be used to obtain at least one preset memory occupancy range, each memory occupancy range corresponds to a memory group; obtain the memory occupancy range corresponding to the average memory occupancy value, and use the memory group corresponding to the memory occupancy range as the memory group corresponding to the average memory occupancy value.
[0102] The page replacement policy acquisition module 530 is used to acquire the page replacement policy corresponding to the memory group.
[0103] As an implementation mode, the page replacement strategy acquisition module 530 can be used to acquire the page miss parameters corresponding to each of the multiple page replacement strategies after implementing the memory group; and use the page replacement strategy corresponding to the page miss parameter with the smallest value as the page replacement strategy corresponding to the memory group.
[0104] As another implementation, the page replacement strategy acquisition module 530 may be configured to, if the memory group is the first memory group, use no page replacement as the page replacement strategy corresponding to the memory group;
[0105] If the memory group is the second memory group, the LRU algorithm will be used for page replacement as the page replacement strategy corresponding to the memory group; if the memory group is the third memory group, the FIFO algorithm will be used for page replacement as the page replacement strategy corresponding to the memory group, and the memory occupancy ranges among the first memory group, the second memory group and the third memory group are all different.
[0106] The memory management module 540 is used to obtain the memory page that needs to be replaced in the resident service based on the page replacement policy.
[0107] Optionally, the device 500 may further include a storage location determination module for determining, based on the memory group, a storage location of the memory page to be replaced after the memory page to be replaced in the resident service is obtained based on the page replacement policy.
[0108] As an implementation, the storage location may include a memory, a memory to be compressed, a flash memory, or a disk.
[0109] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the aforementioned method embodiments, and will not be repeated here.
[0110] In several embodiments provided in the present application, the coupling between modules may be electrical, mechanical or other forms of coupling.
[0111] In addition, each functional module in each embodiment of the present application can be integrated into a processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The above integrated modules can be implemented in the form of hardware or software functional modules.
[0112] See also Figure 6 Based on the above-mentioned memory management method and device, the embodiment of the present application also provides an electronic device 100 that can execute the above-mentioned memory management method. The electronic device 100 includes a memory 102 and one or more (only one is shown in the figure) processors 104 coupled to each other, and the memory 102 and the processor 104 are connected by a communication line. The memory 102 stores a program that can execute the content of the above-mentioned embodiment, and the processor 104 can execute the program stored in the memory 102.
[0113] Among them, the processor 104 may include one or more processing cores. The processor 104 uses various interfaces and lines to connect various parts of the entire electronic device 100, and executes various functions and processes data of the electronic device 100 by running or executing instructions, programs, code sets or instruction sets stored in the memory 102, and calling data stored in the memory 102. Optionally, the processor 104 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 104 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 104, but may be implemented separately through a communication chip.
[0114] The memory 102 may include a random access memory (RAM) or a read-only memory (ROM). The memory 102 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 102 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the aforementioned embodiments, etc. The data storage area may also store data (such as a phone book, audio and video data, chat record data) created by the electronic device 100 during use.
[0115] Please refer to Figure 7 , which shows a structural block diagram of a computer-readable storage medium provided in an embodiment of the present application. The computer-readable medium 600 stores program codes, which can be called by a processor to execute the method described in the above method embodiment.
[0116] The computer readable storage medium 600 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer readable storage medium 600 includes a non-transitory computer-readable storage medium. The computer readable storage medium 600 has storage space for program code 610 that performs any method step in the above method. These program codes can be read from or written to one or more computer program products. The program code 610 can be compressed, for example, in an appropriate form.
[0117] In summary, the embodiments of the present application provide a memory management method, device, electronic device and storage medium. The method is applied to electronic devices. The method obtains the average memory occupancy value of the resident service; determines the corresponding memory group according to the average memory occupancy value; obtains the page replacement policy corresponding to the memory group; and obtains the memory page that needs to be replaced in the resident service based on the page replacement policy. Thus, through the above method, it is possible to group the resident service programs according to the average memory occupancy, and then obtain the page replacement policy corresponding to the divided memory group, so that different service programs can be optimized more meticulously, and the flexibility and effectiveness of memory management can be improved.
[0118] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements 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 the present application.
Claims
1. A memory management method, characterized in that: The method comprises: Get the average memory usage of resident services; Determine a corresponding memory group according to the average memory occupancy value; Obtaining a page replacement policy corresponding to the memory group; A memory page that needs to be replaced in the resident service is obtained based on the page replacement policy.
2. The method according to claim 1, characterized in that The determining the corresponding memory group according to the average memory occupancy value includes: Obtain at least one preset memory usage range, where each memory usage range corresponds to a memory group; A memory occupancy range corresponding to the average memory occupancy value is obtained, and a memory group corresponding to the memory occupancy range is used as the memory group corresponding to the average memory occupancy value.
3. The method according to claim 1, characterized in that The acquiring of the page replacement strategy corresponding to the memory group includes: Obtaining page miss parameters corresponding to each of the plurality of page replacement strategies after implementing the plurality of page replacement strategies on the memory group; The page replacement policy corresponding to the page miss parameter with the smallest value is used as the page replacement policy corresponding to the memory group.
4. The method according to claim 1, characterized in that: The acquiring of the page replacement strategy corresponding to the memory group includes: If the memory group is the first memory group, not performing page replacement is used as a page replacement strategy corresponding to the memory group; If the memory group is the second memory group, the LRU algorithm is used to perform page replacement as the page replacement strategy corresponding to the memory group; If the memory group is the third memory group, the FIFO algorithm is used for page replacement as the page replacement strategy corresponding to the memory group, and the memory occupancy ranges of the first memory group, the second memory group and the third memory group are all different.
5. The method according to claim 1, characterized in that After acquiring the memory page that needs to be replaced in the resident service based on the page replacement strategy, the method further includes: The storage location of the memory page to be replaced after being replaced is determined based on the memory group.
6. The method according to claim 5, characterized in that The storage location includes a memory, a memory to be compressed, a flash memory, or a disk.
7. The method according to any one of claims 1 to 6, characterized in that: After obtaining the average memory usage value of the resident service, the method further includes: If the average memory occupancy value changes, the average memory occupancy value is updated with the changed average memory occupancy value.
8. A memory management device, characterized in that: The device comprises: A memory usage value acquisition module is used to obtain the average memory usage value of resident services; A memory group determination module, used to determine a corresponding memory group according to the average memory occupancy value; A page replacement policy acquisition module, used to acquire a page replacement policy corresponding to the memory group; A memory management module is used to obtain the memory page that needs to be replaced in the resident service based on the page replacement policy.
9. An electronic device, characterized in that: including one or more processors and memory; One or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program code, wherein when the program code is executed by a processor, the method according to any one of claims 1 to 7 is executed.