Memory optimization method, system and device, chip, chip module and medium

By obtaining the memory requirements of the target program and utilizing ZRAM and processor-disabling strategies, the problem of small memory devices being unable to run large applications was solved, achieving the effect of efficiently running large applications on small memory devices.

CN119025274APending Publication Date: 2024-11-26SPREADTRUM SEMICON (NANJING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411121253.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-15
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

Devices with limited memory cannot effectively run large applications, leading to crashes and other issues, with performance bottlenecks becoming particularly pronounced in complex scenarios.

Method used

By obtaining the target program's memory requirements, ZRAM technology is used to write compressed memory data to disk, and the central processing unit is disabled when necessary to free up memory to meet the needs of large applications.

Benefits of technology

To efficiently run large applications on devices with limited memory, improve memory utilization, enhance user experience, and meet market demands.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119025274A_ABST
    Figure CN119025274A_ABST
Patent Text Reader

Abstract

The invention provides a memory optimization method, system and device, a chip, a chip module and a medium. The memory optimization method comprises the steps of obtaining running memory demand information corresponding to a target program; and in response to the condition that the running memory demand information meets a preset condition, enabling a memory optimization strategy to release the occupied memory, and providing a running memory for the target program. When the target program is operated by the equipment, if the operation memory demand information corresponding to the target program meets the preset condition, the memory optimization strategy can be enabled to release the memory, so that the available memory of the equipment is increased, the operation memory is provided for the target program, and the memory utilization rate is improved; and the requirement of running a large-scale application program on equipment with a relatively small memory is met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a memory optimization method, system, device, chip, chip module and medium. Background Art

[0002] Currently, small memory devices (devices with less than 2G random access memory) are competitive in the market. However, due to the small memory, large applications cannot run or crash, especially when it comes to complex scenarios such as code scanning, performance is a bottleneck. Therefore, how to achieve the best balance between function and performance on small memory devices is a huge challenge. Summary of the invention

[0003] The technical problem to be solved by the present disclosure is to overcome the defect in the prior art that insufficient device memory leads to the inability to run large applications, and to provide a memory optimization method, system, device, chip, chip module and medium.

[0004] The present invention solves the above technical problems through the following technical solutions:

[0005] In a first aspect, a memory optimization method is provided, the memory optimization method comprising:

[0006] Obtaining the running memory requirement information corresponding to the target program;

[0007] In response to the running memory requirement information satisfying a preset condition, a memory optimization strategy is enabled to release the occupied memory and provide running memory for the target program.

[0008] Preferably, the step of obtaining the running memory requirement information corresponding to the target program specifically includes:

[0009] In response to the target program being triggered, acquiring running memory requirement information corresponding to the target program;

[0010] The target program being triggered includes: the target program being started or the target program being run in the foreground.

[0011] Preferably, the running memory requirement information includes a process name, and the running memory requirement information satisfies a preset condition specifically including: the process name is recorded in an OOM (Out of Memory) log;

[0012] And / or, the running memory requirement information includes the running progress of the target program, and the running memory requirement information satisfies the preset condition specifically includes: the running progress satisfies the preset progress condition;

[0013] And / or, the running memory requirement information includes memory statistical information, the memory statistical information includes at least one of resident set size, shared memory and heap memory, and the running memory requirement information meets the preset conditions specifically including: the memory statistical information is greater than the corresponding memory threshold.

[0014] Preferably, the memory optimization strategy includes:

[0015] Write compressed memory data in ZRAM (Zero-page RAM, compressed memory or memory compression technology) to disk.

[0016] Preferably, the step of writing the compressed memory data in the ZRAM to the disk specifically includes:

[0017] Get the amount of swap space available in the operating system;

[0018] In response to the amount of available swap space being less than a space threshold, the compressed memory data in the ZRAM is written to a disk.

[0019] Preferably, the target program is run in a device comprising at least one central processing unit;

[0020] In response to the memory requirement information including memory statistics information and the memory statistics information after the compressed memory data is written to the disk is less than the memory threshold, the memory optimization strategy further includes:

[0021] Disable at least one CPU.

[0022] Preferably, the central processing unit includes: at least one large core processor and at least one small core processor, and the disabling priority of the small core processor is higher than the disabling priority of the large core processor.

[0023] Preferably, the memory optimization method further includes:

[0024] In response to the target program switching from foreground operation to background operation or the target program exiting operation, the memory optimization policy is closed.

[0025] In a second aspect, a memory optimization system is provided, the memory optimization system comprising:

[0026] A demand information acquisition module is used to obtain the running memory demand information corresponding to the target program;

[0027] The memory optimization module is used to enable a memory optimization strategy to release occupied memory and provide running memory for the target program in response to the running memory requirement information meeting a preset condition.

[0028] Preferably, the demand information acquisition module is specifically used to acquire the running memory demand information corresponding to the target program in response to the target program being triggered;

[0029] The target program being triggered includes: the target program being started or the target program being run in the foreground.

[0030] Preferably, the running memory requirement information includes a process name, and the running memory requirement information satisfies a preset condition specifically including: the process name is recorded in an OOM log;

[0031] And / or, the running memory requirement information includes the running progress of the target program, and the running memory requirement information satisfies the preset condition specifically includes: the running progress satisfies the preset progress condition;

[0032] And / or, the running memory requirement information includes memory statistical information, the memory statistical information includes at least one of resident set size, shared memory and heap memory, and the running memory requirement information meets the preset conditions specifically including: the memory statistical information is greater than the corresponding memory threshold.

[0033] Preferably, the memory optimization strategy includes: writing compressed memory data in ZRAM to a disk.

[0034] Preferably, the memory optimization module includes:

[0035] A swap space amount obtaining unit, used for obtaining the amount of available swap space in the operating system;

[0036] The writing unit is used for writing the compressed memory data in the ZRAM to the disk in response to the available swap space amount being less than a space threshold.

[0037] Preferably, the target program runs in a device comprising at least one central processing unit; in response to the memory requirement information including memory statistics and the memory statistics after the compressed memory data is written to the disk being less than a memory threshold, the memory optimization module is also used to disable at least one central processing unit.

[0038] Preferably, the central processing unit includes: at least one large core processor and at least one small core processor, and the disabling priority of the small core processor is higher than the disabling priority of the large core processor.

[0039] Preferably, the memory optimization module is further used to close the memory optimization strategy in response to the target program switching from foreground operation to background operation or the target program exiting operation.

[0040] According to a third aspect, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and used to run on the processor, wherein the processor implements any of the above-mentioned memory optimization methods when executing the computer program.

[0041] In a fourth aspect, a chip is provided, which is applied to an electronic device, and the chip is used to execute any of the memory optimization methods described above.

[0042] In a fifth aspect, a chip module is provided, which is applied to an electronic device, and includes a transceiver component and a chip, wherein the chip is used to execute any of the memory optimization methods described above.

[0043] In a sixth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the memory optimization method described in any one of the above items is implemented.

[0044] In a seventh aspect, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the memory optimization method described in any one of the above items is implemented.

[0045] On the basis of being in accordance with the common sense in the art, the above-mentioned preferred conditions can be arbitrarily combined to obtain the preferred embodiments of the present disclosure.

[0046] The positive progressive effect of the present disclosure is that when the device is preparing to start the target program or run the target program in the foreground, if the running memory requirement information corresponding to the target program meets the preset conditions, the memory optimization strategy can be enabled to release memory, so that the available memory of the device is increased, and running memory is provided for the target program, thereby improving memory utilization and meeting the needs of running large applications on devices with smaller memory. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] Figure 1 A flowchart of a memory optimization method provided for an exemplary embodiment of the present disclosure;

[0048] Figure 2 A flowchart of releasing memory by ZRAM write-back in a memory optimization method provided by an exemplary embodiment of the present disclosure;

[0049] Figure 3 A flowchart of releasing memory by disabling a processor in a memory optimization method provided by an exemplary embodiment of the present disclosure;

[0050] Figure 4 Another flow chart of a memory optimization method provided for an exemplary embodiment of the present disclosure;

[0051] Figure 5A schematic diagram of a module of a memory optimization system provided by an exemplary embodiment of the present disclosure;

[0052] Figure 6 The present invention provides a schematic structural diagram of an electronic device according to an exemplary embodiment of the present invention. DETAILED DESCRIPTION

[0053] The present disclosure is further described below by way of examples, but the present disclosure is not limited to the scope of the examples.

[0054] Prefixes such as "first" and "second" are used in the embodiments of the present disclosure only to distinguish different description objects, and have no limiting effect on the position, order, priority, quantity or content of the described objects. The use of prefixes such as ordinal numbers to distinguish description objects in the embodiments of the present disclosure does not constitute a limitation on the described objects. For the statement of the described objects, please refer to the description in the context of the claims or embodiments, and no unnecessary limitation should be constituted due to the use of such prefixes. In addition, in the description of the present embodiment, unless otherwise specified, the meaning of "plurality" is two or more.

[0055] Example 1

[0056] The execution subject of the memory optimization method provided in this embodiment may be a chip or a chip module with computing capabilities.

[0057] With the iteration of Android system versions, the OS (Operating System) occupies more and more memory. For example, a 1G device can still achieve a good user experience on the Android 10.0 system, but on the Android 12.0 system, the user experience is relatively poor. In addition, it is generally not recommended to continue using less than 2G RAM (Random Access Memory) on the Android 12.0 system. Therefore, in order to meet the needs of the market, for small memory devices with less than 2G RAM, memory recovery and allocation must be optimized to meet some basic needs as much as possible.

[0058] Small memory devices are usually devices with less than 2G RAM. The memory optimization method provided in this embodiment can be used for small memory devices, so that executable programs with large memory requirements can be run in small memory devices. Such executable programs need a large memory to run, but small memory devices do not have this ability. Therefore, this embodiment releases part of the occupied memory for the target program to use, so as to meet its running memory requirements, bring better experience to users, and save costs.

[0059] This embodiment provides a memory optimization method. Figure 1 , memory optimization methods include:

[0060] S101, obtaining the operating memory requirement information corresponding to the target program.

[0061] The target program is usually an executable program with large memory requirements, such as large evaluation software such as AnTuTu and Geekbench (a cross-platform benchmark software) and large applications required by certain specific industries. The specific selection can be based on actual conditions and is not particularly limited here.

[0062] S102: In response to the running memory requirement information satisfying a preset condition, a memory optimization strategy is enabled to release the occupied memory and provide running memory for the target program.

[0063] Enable is generally used to describe a state in which a certain function (in this embodiment, the memory optimization policy) is activated or allowed to run.

[0064] The preset conditions are determined based on the data collected during the test and are set according to the actual situation. They are not specifically limited here. If the operating memory requirement information corresponding to the target program meets the preset conditions, it means that the target program requires a larger memory to run normally. To avoid the target program being unable to run or flashing back, the memory optimization strategy is enabled to release the occupied memory and provide the target program with operating memory, thereby ensuring that the target program can run normally.

[0065] In an optional implementation, S101 specifically includes: in response to the target program being triggered, acquiring the running memory requirement information corresponding to the target program.

[0066] The target program being triggered includes: the target program being started or the target program being run in the foreground.

[0067] In an optional implementation, the running memory requirement information includes a process name, and the running memory requirement information satisfies a preset condition specifically including: the process name is recorded in an OOM (Out of Memory) log.

[0068] The preset conditions are determined based on the data collected during the test. Specifically, during the test, the OOM logs of the device that trigger OOM during operation are automatically collected. It should be noted that OOM is a memory management mechanism. When the available memory in the operating system is insufficient to meet current needs, the OOM Killer (a kernel process in the operating system) will be triggered to select and end some processes to recycle memory and ensure that the operating system does not crash due to memory exhaustion. When OOM is triggered, the operating system will output the OOM log, which includes but is not limited to the process name that triggered OOM.

[0069] Specifically, if it is found during the test that the device crashes when running the target program, the process name of the target program can be obtained and recorded, specifically the package name information, to determine the program with large memory requirements. In most cases, each application runs in its own process, and the process name is the same as the package name by default, which is used to distinguish different programs.

[0070] After determining the preset conditions based on the data records collected during the test, when the target program is triggered, it is determined that the running memory requirement information meets the preset conditions, that is, whether the target program has been recorded is determined based on the process name of the target program. If it has been recorded, it means that the target program requires a larger memory to run normally, and the memory optimization strategy is enabled to release the occupied memory and provide running memory for the target program.

[0071] In an optional implementation, the running memory requirement information includes the running progress of the target program, and the running memory requirement information meeting the preset condition specifically includes: the running progress meets the preset progress condition.

[0072] Specifically, if it is found during the test that the target program crashes when the running progress meets the preset progress condition, the current running progress of the target program can be obtained and recorded.

[0073] After determining the preset conditions based on the data records collected during the test process, when the target program is triggered, it is judged that the running memory requirement information meets the preset conditions, that is, when the running progress of the target program meets the preset progress conditions, it is determined that the target program requires a larger memory to run normally, and the memory optimization strategy is enabled to release the occupied memory to provide running memory for the target program.

[0074] The representation of the running progress includes but is not limited to numerical values, which can be selected according to actual conditions and are not particularly limited here. Assuming that the running progress is a numerical value, the numerical value is usually the percentage of the target program completing the task, and the preset progress condition is also a numerical value. The running progress satisfies the preset progress condition, that is, the numerical value of the running progress is greater than the numerical value of the preset progress condition. When the running progress is 0%, it means that the target program has just started running and has not completed any substantial work. When the running progress is 100%, it means that the target program has completed all tasks and achieved the predetermined goal. If the preset progress condition is set to 70% and the running progress is greater than 70%, it means that the running progress meets the preset progress condition, enabling the memory optimization strategy to release occupied memory and provide running memory for the target program. The above numerical values ​​are only used for example, and the specific numerical values ​​can be selected according to actual conditions and are not particularly limited here.

[0075] For example, during the test, it was found that when the running progress of the AnTuTu benchmark program was about 70%, a large amount of memory was required to run normally. The preset condition can be determined as the running progress reaching 70%. After determining the preset condition, if the AnTuTu benchmark program is running, the current running progress of the AnTuTu benchmark program is extracted with the help of the information in the display window. When the obtained running progress is 70%, the memory optimization strategy is enabled to release the occupied memory.

[0076] In an optional implementation, the running memory requirement information includes memory statistical information, the memory statistical information includes at least one of resident set size, shared memory and heap memory, and the running memory requirement information meets the preset conditions specifically including: the memory statistical information is greater than the corresponding memory threshold.

[0077] Each process corresponds to a memory statistic (statm information), which is used to reflect the statistical information of the memory used by the process. Specifically, with the help of proc / pid / statm information in procfs (a virtual file system) (a specific path of the virtual file system, where proc represents the virtual file system, pid represents the process ID, and statm represents the memory statistic corresponding to the process), the memory statistic is monitored. When the memory statistic is greater than the corresponding memory threshold, the memory optimization strategy is enabled to release the occupied memory. Assuming that the memory statistic includes: resident set size and shared memory, the corresponding memory thresholds include: resident set threshold and shared memory threshold.

[0078] The memory threshold may be set according to actual conditions, such as 500M, and is not particularly limited here.

[0079] The memory statistics include at least one of the resident set size, shared memory, and heap memory. The resident set size, shared memory, and heap memory can be compared with the corresponding memory thresholds to determine whether the memory optimization strategy needs to be enabled. The memory statistics also include virtual memory, which can be used to assist in determining the memory usage of the process, thereby more accurately determining whether the memory optimization strategy needs to be enabled.

[0080] When the target program is triggered, it is determined that the running memory requirement information meets the preset conditions, that is, the memory statistics are greater than the corresponding memory threshold. If it is greater than the corresponding memory threshold, it means that the target program requires a larger memory to run normally, and the memory optimization strategy is enabled to release the occupied memory and provide running memory for the target program. The above three types of memory statistics can be combined according to actual conditions to determine whether the running memory requirement information meets the preset conditions, that is, the resident set size, shared memory and heap memory can be combined as needed, so as to more accurately determine whether the memory optimization strategy needs to be enabled.

[0081] In an optional implementation, the memory optimization strategy includes: writing compressed memory data in the ZRAM to a disk.

[0082] RAM (Random Access Memory), also known as main memory, is an internal memory that directly exchanges data with the CPU (Central Processing Unit). ZRAM is a RAM compression technology that compresses and stores data in RAM to improve memory utilization and thus improve system performance.

[0083] Under the premise of a certain compression rate, the system can run more stably because unpredictable performance problems caused by compression rate fluctuations can be avoided. Therefore, under the premise of a certain compression rate of ZRAM, the compressed memory data in ZRAM can be written to the disk to release memory.

[0084] Specifically, with the help of the characteristics of init (a program in Unix and Unix-like operating systems), init is used to start the native program of ZRAMWB (program name). ZRAMWB is used to write the compressed memory data in ZRAM to the disk, thereby realizing the data migration of ZRAM.

[0085] In an optional embodiment, the step of writing the compressed memory data in the ZRAM to the disk specifically includes: obtaining the amount of available swap space in the operating system. In response to the amount of available swap space being less than a space threshold, writing the compressed memory data in the ZRAM to the disk.

[0086] Specifically, an automated tool is used to monitor the amount of available swap space (swap free) in proc / meminfo (a virtual file in the operating system, located in the proc directory). If the amount of available swap space is less than the space threshold, it means that the amount of available swap space is small. To avoid memory exhaustion, the compressed memory data in ZRAM is written to the disk to provide running memory for the target program when the memory is tight.

[0087] The swap partition (swap) is used to store inactive memory data. When the operating system is running, it moves data from RAM to swap space (swap space) or from swap space to RAM as needed.

[0088] See also Figure 2, through the scene recognition algorithm, the large memory demand scene is identified. Specifically, the identification is performed by judging whether the running memory demand information meets the preset conditions. If the running memory demand information meets the preset conditions, it indicates that the current scene is a large memory demand scene, and the attribute (persist.xx) is set to true. On the contrary, if the running memory demand information does not meet the preset conditions, it indicates that the current scene is not a large memory demand scene, and the attribute (persist.xx) is set to false. The attribute (persist.xx) is true, indicating that the target program requires a large memory, and the memory optimization strategy needs to be enabled to release the occupied memory, and the ZRAMWB service is activated. Assuming that the space threshold is set to 300M, when the swap free (available swap space) is less than 300M, the compressed memory data in the ZRAM is written to the disk with the help of the ZRAM write-back mechanism. On the contrary, the attribute (persist.xx) is false, indicating that the target program does not need a large memory, and the memory optimization strategy needs to be turned off to release the occupied memory, and the ZRAMWB service is stopped, that is, the compressed memory data in the ZRAM is stopped from being written to the disk. The above numerical values ​​are only used as examples. The specific numerical values ​​can be selected according to the actual situation and are not particularly limited here.

[0089] In an optional embodiment, the target program runs in a device including at least one central processing unit. In response to the memory demand information including memory statistics and the memory statistics after the compressed memory data is written to the disk being less than a memory threshold, the memory optimization strategy also includes: disabling at least one central processing unit.

[0090] In order to bring better performance, small memory devices usually have multiple CPUs, and the target usually runs in multiple threads, that is, at the same time, in addition to the OS-related threads being scheduled, there are also multiple target program-related threads running. When multiple threads run at the same time, the required memory increases exponentially. By disabling at least one central processing unit and making at least one central processing unit power off and stop working, the number of threads running at the same time can be reduced, thereby providing running memory for the target program.

[0091] Disabling the CPU can be achieved by relying on the rc (run commands, run control script) configuration file of init. The specific implementation method can be set according to the actual situation and is not specifically limited here. The number of CPUs can be set according to the actual situation and is not specifically limited here.

[0092] Since there is a size limit on the amount of compressed memory data in ZRAM that can be written to disk, when the compressed memory data in ZRAM still cannot meet the memory demand after being written to disk, it is necessary to release the occupied memory by disabling the central processing unit.

[0093] See also Figure 3 , through the scene recognition algorithm, the large memory demand scene is identified. Specifically, the identification is performed by judging whether the running memory demand information meets the preset conditions. If the running memory demand information meets the preset conditions, it indicates that the current scene is a large memory demand scene, and the attribute (persist.xx) is set to true. On the contrary, if the running memory demand information does not meet the preset conditions, it indicates that the current scene is not a large memory demand scene, and the attribute (persist.xx) is set to false. The attribute (persist.xx) is true, indicating that the target program requires a large memory, and the memory optimization strategy needs to be enabled to release the occupied memory. Write the node / sys / devices / system / cpu / cpu* / online 0 to disable the core, that is, disable at least one central processing unit. On the contrary, the attribute (persist.xx) is false, indicating that the target program does not need a large memory, and the memory optimization strategy needs to be turned off to release the occupied memory. Write the node / sys / devices / system / cpu / cpu* / online1 to activate the core, that is, activate the disabled central processing unit.

[0094] In an optional implementation, the central processing unit includes: at least one large core processor and at least one small core processor, and the disabling priority of the small core processor is higher than the disabling priority of the large core processor.

[0095] In an optional implementation, the memory optimization method further includes: in response to the target program switching from foreground execution to background execution or the target program exiting execution, closing the memory optimization policy.

[0096] Disabling the memory optimization strategy includes at least one of stopping writing compressed memory data in the ZRAM to the disk and activating a disabled central processing unit. The specific selection can be made according to actual conditions and is not particularly limited here.

[0097] See also Figure 4 , the process of memory optimization method is further explained.

[0098] The target program is generally a large application. After the large application is started, the scene recognition algorithm is used to identify the large memory demand scene. Specifically, the recognition is performed by judging whether the running memory demand information meets the preset conditions. If the running memory demand information meets the preset conditions, it indicates that the current scene is a large memory demand scene, and the memory optimization strategy is enabled to release the occupied memory and provide running memory for the target program.

[0099] If the target program changes from running in the foreground to running in the background, re-evaluate other programs running in the foreground. If the target program changes from running in the background to running in the foreground, re-evaluate whether the running memory requirement information corresponding to the target program meets the preset conditions. If the running memory requirement information corresponding to the target program does not meet the preset conditions, it indicates that the current scenario is not a scenario with large memory requirements, and the memory optimization strategy is turned off. If a large application is exited, that is, the target program exits, re-evaluate other programs running in the foreground.

[0100] In an optional implementation, the memory optimization method further includes: in response to the target program switching from foreground operation to background operation or the target program exiting operation, reclaiming the memory occupied by the target program.

[0101] In this embodiment, when the device runs a target program, if the running memory requirement information corresponding to the target program meets the preset conditions, the memory optimization strategy can be enabled to release memory, so that the available memory of the device is increased, and running memory is provided for the target program, thereby improving memory utilization, meeting the needs of running large applications on devices with smaller memory, and improving the user experience of using small memory devices.

[0102] Example 2

[0103] Corresponding to the aforementioned memory optimization method embodiment, the present disclosure also provides an embodiment of a memory optimization system.

[0104] The memory optimization system provided in this embodiment may specifically be a chip or a chip module with computing capabilities.

[0105] The various modules / units included in the memory optimization system may be software modules / units, hardware modules / units, or partly software modules / units and partly hardware modules / units. For example, for various devices and products applied to or integrated in a chip, the various modules / units included therein may all be implemented in the form of hardware such as circuits, or at least some of the modules / units may be implemented in the form of software programs, which run on a processor integrated inside the chip, and the remaining modules / units may be implemented in the form of hardware such as circuits. For various devices and products applied to or integrated in a chip module, the various modules / units included therein may all be implemented in the form of hardware such as circuits, and different modules / units may be located in the same component (e.g., chip, circuit module, etc.) or different components of the chip module, or at least some of the modules / units may be implemented in the form of software programs, which run on a processor integrated inside the chip module, and the remaining modules / units may be implemented in the form of hardware such as circuits.

[0106] Figure 5A schematic diagram of a module of a memory optimization system provided by an exemplary embodiment of the present disclosure, the memory optimization system comprising:

[0107] The demand information acquisition module 21 is used to acquire the running memory demand information corresponding to the target program.

[0108] The target program is usually an executable program with large memory requirements, such as large-scale evaluation software such as Antutu and geekbench, and large-scale applications required by certain specific industries. The specific selection can be based on actual conditions and is not particularly limited here.

[0109] The memory optimization module 22 is used to enable a memory optimization strategy to release the occupied memory and provide the target program with the running memory in response to the running memory requirement information satisfying the preset condition.

[0110] Enable is generally used to describe a state in which a certain function (in this embodiment, the memory optimization policy) is activated or allowed to run.

[0111] The preset conditions are determined based on the data collected during the test and are set according to the actual situation. They are not specifically limited here. If the operating memory requirement information corresponding to the target program meets the preset conditions, it means that the target program requires a larger memory to run normally. To avoid the target program being unable to run or flashing back, the memory optimization strategy is enabled to release the occupied memory and provide the target program with operating memory, thereby ensuring that the target program can run normally.

[0112] In an optional implementation, the demand information acquisition module 21 is specifically configured to acquire the running memory demand information corresponding to the target program in response to the target program being triggered.

[0113] The target program being triggered includes: the target program being started or the target program being run in the foreground.

[0114] In an optional implementation, the running memory requirement information includes a process name, and the running memory requirement information meets a preset condition specifically including: the process name is recorded in the OOM log.

[0115] The preset conditions are determined based on the data collected during the test. Specifically, during the test, the OOM logs of the device that trigger OOM during operation are automatically collected. It should be noted that OOM is a memory management mechanism. When the available memory in the operating system is insufficient to meet the current demand, the OOM Killer will be triggered to select and kill some processes to recycle memory and ensure that the operating system does not crash due to memory exhaustion. When OOM is triggered, the operating system will output the OOM log, which includes but is not limited to the process name that triggered OOM.

[0116] Specifically, if it is found during the test that the device crashes when running the target program, the process name of the target program can be obtained and recorded, specifically the package name information, to determine the program with large memory requirements. In most cases, each application runs in its own process, and the process name is the same as the package name by default, which is used to distinguish different programs.

[0117] After determining the preset conditions based on the data records collected during the test, when the target program is triggered, it is determined that the running memory requirement information meets the preset conditions, that is, whether the target program has been recorded is determined based on the process name of the target program. If it has been recorded, it means that the target program requires a larger memory to run normally, and the memory optimization strategy is enabled to release the occupied memory and provide running memory for the target program.

[0118] In an optional implementation, the running memory requirement information includes the running progress of the target program, and the running memory requirement information meeting the preset condition specifically includes: the running progress meets the preset progress condition.

[0119] Specifically, if it is found during the test that the target program crashes when the running progress meets the preset progress condition, the current running progress of the target program can be obtained and recorded.

[0120] After determining the preset conditions based on the data records collected during the test process, when the target program is triggered, it is judged that the running memory requirement information meets the preset conditions, that is, when the running progress of the target program meets the preset progress conditions, it is determined that the target program requires a larger memory to run normally, and the memory optimization strategy is enabled to release the occupied memory to provide running memory for the target program.

[0121] The representation of the running progress includes but is not limited to numerical values, which can be selected according to actual conditions and are not particularly limited here. Assuming that the running progress is a numerical value, the numerical value is usually the percentage of the target program completing the task, and the preset progress condition is also a numerical value. The running progress meets the preset progress condition, that is, the numerical value of the running progress is greater than the numerical value of the preset progress condition. When the running progress is 0%, it means that the target program has just started running and has not completed any substantial work. When the running progress is 100%, it means that the target program has completed all tasks and achieved the predetermined goal. If the preset progress condition is set to 70%, and the running progress is greater than 70%, it means that the running progress meets the preset progress condition, enabling the memory optimization strategy to release the occupied memory and provide running memory for the target program.

[0122] For example, during the test, it was found that when the running progress of the AnTuTu benchmark program was about 70%, a large amount of memory was required to run normally. The preset condition can be determined as the running progress reaching 70%. After determining the preset condition, if the AnTuTu benchmark program is running, the current running progress of the AnTuTu benchmark program is extracted with the help of the information in the display window. When the obtained running progress is 70%, the memory optimization strategy is enabled to release the occupied memory.

[0123] In an optional implementation, the running memory requirement information includes memory statistical information, the memory statistical information includes at least one of resident set size, shared memory and heap memory, and the running memory requirement information meets the preset conditions specifically including: the memory statistical information is greater than the corresponding memory threshold.

[0124] Each process corresponds to a memory statistic (statm information), which is used to reflect the statistical information of the memory used by the process. Specifically, the memory statistics are monitored with the help of proc / pid / statm information in procfs (a virtual file system). When the memory statistics are greater than the corresponding memory threshold, the memory optimization strategy is enabled to release the occupied memory. Assuming that the memory statistics include: resident set size and shared memory, the corresponding memory thresholds include: resident set threshold and shared memory threshold.

[0125] The memory threshold may be set according to actual conditions, such as 500M, and is not particularly limited here.

[0126] The memory statistics include at least one of the resident set size, shared memory, and heap memory. The resident set size, shared memory, and heap memory can be compared with the corresponding memory thresholds to determine whether the memory optimization strategy needs to be enabled. The memory statistics also include virtual memory, which can be used to assist in determining the memory usage of the process, thereby more accurately determining whether the memory optimization strategy needs to be enabled.

[0127] When the target program is triggered, it is determined that the running memory requirement information meets the preset conditions, that is, the memory statistical information is greater than the corresponding memory threshold. If it is greater than the corresponding memory threshold, it means that the target program requires a larger memory to run normally. The memory optimization strategy is enabled to release the occupied memory and provide running memory for the target program.

[0128] In an optional implementation, the memory optimization strategy includes: writing compressed memory data in the ZRAM to a disk.

[0129] RAM, also known as main memory, is an internal memory that directly exchanges data with the CPU (Central Processing Unit). ZRAM is a RAM (Random Access Memory) compression technology that compresses data in RAM to improve memory utilization and thus improve system performance.

[0130] Under the premise of a certain compression rate, the system can run more stably because unpredictable performance problems caused by compression rate fluctuations can be avoided. Therefore, under the premise of a certain compression rate of ZRAM, the compressed memory data in ZRAM can be written to the disk to release memory.

[0131] Specifically, with the help of the characteristics of init (a program in Unix and Unix-like operating systems), init is used to start the native program of ZRAMWB (program name). ZRAMWB is used to write the compressed memory data in ZRAM to the disk, thereby realizing the data migration of ZRAM.

[0132] In an optional embodiment, the memory optimization module 22 includes:

[0133] The swap space amount obtaining unit is used to obtain the amount of available swap space in the operating system.

[0134] The writing unit is configured to write the compressed memory data in the ZRAM to the disk in response to the amount of available swap space being less than a space threshold.

[0135] Specifically, an automated tool is used to monitor the amount of available swap space (swapfree) in proc / meminfo information. If the amount of available swap space is less than the space threshold, it means that the amount of available swap space is small. To avoid memory exhaustion, the compressed memory data in ZRAM is written to the disk to provide running memory for the target program when the memory is tight.

[0136] The swap partition (swap) is used to store inactive memory data. When the operating system is running, it moves data from RAM to swap space (swap space) or from swap space to RAM as needed.

[0137] In an optional embodiment, the target program runs in a device including at least one central processing unit; in response to the memory demand information including memory statistics and the memory statistics after the compressed memory data is written to the disk being less than a memory threshold, the memory optimization module 22 is also used to disable at least one central processing unit.

[0138] In order to bring better performance, small memory devices usually have multiple CPUs, and the target usually runs in multiple threads, that is, at the same time, in addition to the OS-related threads being scheduled, there are also multiple target program-related threads running. When multiple threads run at the same time, the required memory increases exponentially. By disabling at least one central processor, the number of threads running at the same time can be reduced, thereby providing running memory for the target program.

[0139] Disabling the CPU can be achieved by relying on the rc configuration file of init. The specific implementation method can be set according to the actual situation and is not specifically limited here. The number of CPUs can be set according to the actual situation and is not specifically limited here.

[0140] Since there is a size limit on the amount of compressed memory data in ZRAM that can be written to disk, when the compressed memory data in ZRAM still cannot meet the memory demand after being written to disk, it is necessary to release the occupied memory by disabling the central processing unit.

[0141] In an optional implementation, the central processing unit includes: at least one large core processor and at least one small core processor, and the disabling priority of the small core processor is higher than the disabling priority of the large core processor.

[0142] In an optional implementation, the memory optimization module is further configured to close the memory optimization policy in response to the target program switching from foreground execution to background execution or the target program exiting execution.

[0143] Disabling the memory optimization strategy includes at least one of stopping writing compressed memory data in the ZRAM to the disk and activating a disabled central processing unit. The specific selection can be made according to actual conditions and is not particularly limited here.

[0144] In an optional implementation, the memory optimization module is further configured to reclaim the memory occupied by the target program in response to the target program switching from foreground operation to background operation or the target program exiting operation.

[0145] In this embodiment, when the device runs a target program, if the running memory requirement information corresponding to the target program meets the preset conditions, the memory optimization strategy can be enabled to release memory, so that the available memory of the device is increased, and running memory is provided for the target program, thereby improving memory utilization, meeting the needs of running large applications on devices with smaller memory, and improving the user experience of using small memory devices.

[0146] As for the system embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The system embodiment described above is only illustrative, wherein the units described as separate components may or may not be physically separated, and the components as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the disclosed solution.

[0147] Example 3

[0148] Figure 6 This is a structural schematic diagram of an electronic device shown in an example embodiment of the present disclosure, the electronic device includes a memory, a processor, and a computer program stored in the memory and used to run on the processor, and the processor implements the memory optimization method described in any of the above embodiments when executing the computer program. Figure 6 The electronic device 30 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0149] like Figure 6 As shown, the electronic device 30 may be in the form of a general-purpose computing device, for example, it may be a server device. The components of the electronic device 30 may include, but are not limited to: at least one processor 31, at least one memory 32, and a bus 33 connecting different system components (including the memory 32 and the processor 31).

[0150] The bus 33 includes a data bus, an address bus, and a control bus.

[0151] The memory 32 may include a volatile memory, such as a random access memory (RAM) 321 and / or a cache memory 322 , and may further include a disk (ROM) 323 .

[0152] The memory 32 may also include a program tool 325 (or utility) having a set (at least one) of program modules 324, such program modules 324 including but not limited to: an operating system, one or more application programs, other program modules and program data, each of which or some combination may include an implementation of a network environment.

[0153] The processor 31 executes various functional applications and data processing by running the computer program stored in the memory 32, such as the memory optimization method provided in any of the above embodiments.

[0154] The electronic device 30 may also communicate with one or more external devices 34 (e.g., keyboards, pointing devices, etc.). Such communication may be performed via an input / output (I / O) interface 35. Furthermore, the electronic device 30 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 36. As shown, the network adapter 36 communicates with other modules of the electronic device 30 via a bus 33. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 30, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, and data backup storage systems, etc.

[0155] It should be noted that although several units / modules or sub-units / modules of the electronic device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be embodied.

[0156] Example 4

[0157] The embodiments of the present disclosure further provide a computer-readable storage medium having a computer program stored thereon, and when the program is executed by a processor, the memory optimization method provided by any of the above embodiments is implemented.

[0158] The readable storage medium may include, but is not limited to, a portable disk, a hard disk, a random access memory, a magnetic disk, an erasable programmable disk, an optical storage device, a magnetic storage device, or any suitable combination thereof.

[0159] Example 5

[0160] The embodiment of the present disclosure further provides a computer program product, including a computer program, wherein when the computer program is executed by a processor, the memory optimization method described in any one of the above items is implemented.

[0161] Among them, the program code for executing the computer program product of the present disclosure can be written in any combination of one or more programming languages, and the program code can be executed completely on the user device, partially on the user device, as an independent software package, partially on the user device and partially on a remote device, or completely on the remote device.

[0162] Although the specific embodiments of the present disclosure are described above, those skilled in the art should understand that this is only an example, and the protection scope of the present disclosure is defined by the appended claims. Those skilled in the art may make various changes or modifications to these embodiments without departing from the principles and essence of the present disclosure, but these changes and modifications all fall within the protection scope of the present disclosure.

Claims

1. A memory optimization method, It is characterized in that The memory optimization method comprises: Obtaining the running memory requirement information corresponding to the target program; In response to the running memory requirement information satisfying a preset condition, a memory optimization strategy is enabled to release the occupied memory and provide running memory for the target program.

2. The memory optimization method according to claim 1, It is characterized in that The step of obtaining the running memory requirement information corresponding to the target program specifically includes: In response to the target program being triggered, acquiring running memory requirement information corresponding to the target program; The target program being triggered includes: the target program being started or the target program being run in the foreground.

3. The memory optimization method according to claim 1, It is characterized in that The running memory requirement information includes a process name, and the running memory requirement information satisfies a preset condition specifically including: the process name is recorded in the OOM log; And / or, the running memory requirement information includes the running progress of the target program, and the running memory requirement information satisfies the preset condition specifically includes: the running progress satisfies the preset progress condition; And / or, the running memory requirement information includes memory statistical information, the memory statistical information includes at least one of resident set size, shared memory and heap memory, and the running memory requirement information meets the preset conditions specifically including: the memory statistical information is greater than the corresponding memory threshold.

4. The memory optimization method according to any one of claims 1 to 3, It is characterized in that The memory optimization strategy includes: Write compressed memory data in ZRAM to disk.

5. The memory optimization method according to claim 4, It is characterized in that The step of writing the compressed memory data in the ZRAM to the disk specifically includes: Get the amount of swap space available in the operating system; In response to the amount of available swap space being less than a space threshold, the compressed memory data in the ZRAM is written to a disk.

6. The memory optimization method according to claim 4, It is characterized in that The target program is run in a device comprising at least one central processing unit; In response to the memory requirement information including memory statistics information and the memory statistics information after the compressed memory data is written to the disk is less than the memory threshold, the memory optimization strategy further includes: Disable at least one CPU.

7. The memory optimization method according to claim 6, It is characterized in that The central processing unit includes: at least one large core processor and at least one small core processor, and the disabling priority of the small core processor is higher than the disabling priority of the large core processor.

8. The memory optimization method according to claim 1, It is characterized in that The memory optimization method further includes: In response to the target program switching from foreground operation to background operation or the target program exiting operation, the memory optimization policy is closed.

9. A memory optimization system, It is characterized in that The memory optimization system comprises: A demand information acquisition module is used to obtain the running memory demand information corresponding to the target program; The memory optimization module is used to enable a memory optimization strategy to release occupied memory and provide running memory for the target program in response to the running memory requirement information meeting a preset condition.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and for running on the processor, It is characterized in that When the processor executes the computer program, the memory optimization method according to any one of claims 1 to 8 is implemented.

11. A chip, used in electronic equipment, It is characterized in that The chip is used to execute the memory optimization method as described in any one of claims 1-8.

12. A chip module, used in electronic equipment, It is characterized in that It comprises a transceiver component and a chip, and the chip is used to execute the memory optimization method as described in any one of claims 1-8.

13. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the memory optimization method according to any one of claims 1 to 8 is implemented.

14. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the memory optimization method according to any one of claims 1 to 8 is implemented.