Memory testing method and electronic device

By first detecting the RSS occupied by the process in the electronic device and then further detecting the PSS as needed, the problem of memory detection time and inaccurate in the prior art is solved, and efficient and accurate memory detection is achieved.

WO2025055395A1PCT designated stage expired Publication Date: 2025-03-20HUAWEI TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/096500
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-09-14
Filing Date
2024-05-30
Publication Date
2025-03-20

AI Technical Summary

Technical Problem

The prior art takes a long time and inaccurate detection when detecting the memory occupied by electronic device processes, especially because RSS will calculate all the memory of the shared library to the application, resulting in inaccurate memory detection.

Method used

采用一种内存检测方法,先检测进程占用的实际使用物理内存(RSS),如果超过阈值,则进一步检测比例分配实际使用物理内存(PSS)。 通过这种方法,过滤掉大部分进程,提高内存检测的精确性,并节省检测时间。

Benefits of technology

Accurate memory detection is realized, which significantly reduces detection time and overhead by nearly 98.4%, while improving the accuracy of memory detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024096500_20032025_PF_FP_ABST
    Figure CN2024096500_20032025_PF_FP_ABST
Patent Text Reader

Abstract

Disclosed in the present application are a memory testing method and an electronic device. The method can comprise: an electronic device measures a first memory occupied by a first process, the first memory being a resident set size (RSS); when the first memory is greater than a first threshold, the electronic device measures a second memory occupied by the first process, the second memory being a proportional set size (PSS); and when the second memory is greater than the first threshold, the electronic device measures the memory of the first process according to a preset time. In this way, the electronic device first measures the RSS occupied by the first process, and if the RSS occupied by the first process exceeds a rated memory (i.e., the first threshold), the electronic device then measures the PSS occupied by the first process. Since the range of the RSS is larger than that of the PSS, the electronic device measures the RSS occupied by the first process to filter out most processes, and then measures the PSS occupied by the first process to accurately position the process having excess memory, thus improving the accuracy of memory testing.
Need to check novelty before this filing date? Find Prior Art

Description

Memory detection method and electronic device

[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on September 14, 2023, with application number 202311190275.1 and application name “Memory Detection Method and Electronic Device”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of memory management technology, and in particular to a memory detection method and electronic device. Background Art

[0003] An increasing number of applications (apps) are being installed on electronic devices. When an application (i.e., its corresponding application process) is running in the operating system of an electronic device, the process consumes resources on the electronic device. However, the operating system of an electronic device has limited resources such as memory, central processing unit (CPU), and input / output (IO). Therefore, if the resource usage of applications in the background is not controlled, the resources required by the foreground application cannot be guaranteed.

[0004] Currently, the measurement indicators of memory resources can include the actual physical memory used (resident set size, RSS) and the proportional physical memory used (proportional set size, PSS). Among them, RSS can include the memory occupied by shared libraries. PSS can include the memory occupied by proportional shared libraries. During the memory detection process, the operating system of the electronic device sets memory, IO and other quotas for each process to prevent applications from abusing resources in the background. For example, the memory quota is that the memory occupied by foreground and background applications is no more than about 50% of the electronic device's memory. Afterwards, the electronic device detects the PSS occupied by each process. However, the process of detecting the PSS occupied by each process is time-consuming. For example, it takes about 129ms for the electronic device to detect the PSS occupied by 479 processes. In order to solve the time-consuming problem, the electronic device detects the RSS occupied by each process. Since RSS will count all the shared library memory as the application, it will lead to inaccurate memory detection.

[0005] Summary of the Invention

[0006] The memory detection method and electronic device provided in this application achieve accurate memory detection with low time consumption.

[0007] In order to achieve the above objectives, this application adopts the following technical solutions.

[0008] In the first aspect, the present application provides a memory detection method, the execution subject of the method may be an electronic device, or a component located in the electronic device (for example, a chip, a chip system or a processor, etc.), and the following description is made using the execution subject being an electronic device as an example. The method may include: detecting a first memory occupied by a first process, where the first memory is the actual physical memory RSS. When the first memory is greater than a first threshold, detecting a second memory occupied by the first process, where the second memory is the proportionally allocated actual physical memory PSS. When the second memory is greater than the first threshold, processing the first process.

[0009] In one example, the first process can be understood as the running process of a first application on the electronic device. The first process can include one or more processes.

[0010] In one example, the first threshold may refer to an upper limit of memory that can be used by the first process, which is the rated memory of the first application. The rated memory may be the memory configured by the electronic device for the first application when the electronic device is started.

[0011] In this way, the electronic device first detects the RSS occupied by the first process. If the RSS occupied by the first process exceeds the rated memory (i.e., the first threshold), the electronic device then detects the PSS occupied by the first process. Because the RSS has a larger range than the PSS, the electronic device filters out most processes by detecting the RSS occupied by the first process. Then, by detecting the PSS occupied by the first process, the electronic device can accurately locate the process with excess memory, thereby improving the accuracy of memory detection.

[0012] In some technical solutions, the memory detection method provided in this application also includes: when the first memory is less than or equal to the first threshold, skipping the detection operation of whether the second memory is greater than the first threshold. That is, because the RSS range is larger than the PSS range, the electronic device detects that the RSS occupied by the first process does not exceed the rated memory, and can determine that the PSS occupied by the first process does not exceed the rated memory. In this way, the electronic device does not need to detect the PSS occupied by the first process, saving detection time and reducing the time consumption of memory detection of the electronic device. At the same time, accurate memory detection is achieved.

[0013] In some technical solutions, the memory detection method provided in the present application also includes: when the second memory is less than or equal to the first threshold, ending the detection operation.

[0014] In some technical solutions, before detecting the first memory occupied by the first process, the memory detection method provided in the present application also includes: determining the device information of the electronic device and the characteristic information of the first process, the device information of the electronic device is used to characterize the state of the electronic device, and the characteristic information of the first process is used to characterize the state of the first process; when the device information or characteristic information changes, detecting the first memory occupied by the first process.

[0015] In a technical solution, the device information of the electronic device includes at least one of the following: system status, user operation status; the characteristic information of the first process includes at least one of the following: process status and foreground and background status.

[0016] In a technical solution, the characteristic information of the first process includes a process status; when the characteristic information changes, the first memory occupied by the first process is detected, which can be specifically: when the process status is a non-suspended state, the first memory occupied by the first process is detected.

[0017] In one technical solution, the characteristic information of the first process includes foreground and background states; when the characteristic information changes, the first memory occupied by the first process is detected, which can be specifically: when the foreground and background states are background states, the first memory occupied by the first process is detected.

[0018] In one technical solution, the device information of the electronic device includes a system status; when the device information changes, the first memory occupied by the first process is detected, which can be specifically: when the system status is a non-idle state, the first memory occupied by the first process is detected.

[0019] In one technical solution, the device information of the electronic device includes a user operation status; when the device information changes, the first memory occupied by the first process is detected. Specifically, when the user operation status is a no-operation state, the first memory occupied by the first process is detected.

[0020] In the embodiment of the present application, the electronic device determines whether to use the above detection method to detect the memory occupied by the first process based on the state of the electronic device. In other words, the electronic device comprehensively considers various user scenarios and achieves accurate detection of the process memory and reduces the detection time while ensuring minimal impact on the foreground.

[0021] In one example, based on the degree of influence of each electronic device on the foreground, the electronic device can configure a judgment order for the above-mentioned process status, foreground and background status, system status, and user operation. That is, the process status may have the greatest impact on the foreground, so the electronic device can first judge the process status. Secondly, the foreground and background status may have a greater impact on the foreground, so the electronic device can secondly judge the foreground and background status. Thirdly, the system status may have a slightly smaller impact on the foreground, so the electronic device can again judge the system status. Finally, the user operation may have the least impact on the foreground, so the electronic device can secondly judge the user operation. Of course, this example only provides one feasible solution, and the embodiments of the present application are not limited to this.

[0022] In the embodiment of the present application, the electronic device determines whether to use the above detection method to detect the memory occupied by the first process based on the electronic device's state and the degree of impact of each state on the foreground. In other words, the electronic device comprehensively considers various user scenarios and the degree of impact of each state on the foreground, and achieves accurate detection of the process's memory and reduces detection time while ensuring minimal impact on the foreground.

[0023] In one technical solution, the first threshold is the rated memory of the first process. In other words, the first threshold is the rated memory of the first application.

[0024] In a technical solution, the processing of the first process may specifically be: when the second memory is greater than the first threshold, performing memory detection on the first process at a preset time interval; when the number of memory detections on the first process is greater than a second threshold, reporting the occupied memory of the first process.

[0025] In a technical solution, the processing of the first process may specifically include: when the second memory is greater than the first threshold, killing the first process.

[0026] Here, the electronic device killing the first process can be understood as the electronic device shutting down the first process. That is, the electronic device does not run the first process. Of course, in the embodiments of the present application, the electronic device's processing of the first process is not limited to killing the first process and may also include adjusting the rated memory of the first process, etc. This is not specifically limited in the embodiments of the present application.

[0027] In a second aspect, the present application provides a memory detection method. The execution subject of the method can be an electronic device or a component located in the electronic device (for example, a chip, a chip system, or a processor). The following description takes the execution subject as an electronic device as an example. The method may include: detecting a first memory occupied by a first process, where the first memory is the actual used physical memory RSS; if the first memory is less than or equal to the first threshold, skipping the detection operation of whether the second memory is greater than the first threshold.

[0028] In this way, the electronic device first detects the RSS occupied by the first process. If the RSS occupied by the first process does not exceed the rated memory (i.e., the first threshold), the electronic device no longer detects the PSS occupied by the first process. Since the RSS range is larger than the PSS range, the electronic device detects that the RSS occupied by the first process does not exceed the rated memory, indicating that the PSS occupied by the first process must also not exceed the rated memory. Therefore, there is no need to detect the PSS occupied by the first process, saving detection time and reducing the time consumed by the electronic device's memory detection.

[0029] In a third aspect, the present application provides a memory detection method, the execution subject of the method can be an electronic device, or a component located in the electronic device (for example, a chip, a chip system or a processor, etc.). The following description is based on the example of an electronic device being the execution subject. The method may include: detecting a first memory occupied by a first process, where the first memory is the actual physical memory RSS; when the first memory is greater than a first threshold, detecting a second memory occupied by the first process, where the second memory is the proportionally allocated actual physical memory PSS; when the second memory is less than or equal to the first threshold, ending the detection operation.

[0030] In this way, the electronic device first detects the RSS occupied by the first process. If the RSS occupied by the first process exceeds the rated memory (i.e., the first threshold), the electronic device then detects the PSS occupied by the first process. Because the RSS range is larger than the PSS range, the electronic device detects that the RSS occupied by the first process exceeds the rated memory and further detects that the PSS occupied by the first process does not exceed the rated memory, indicating that the memory resources occupied by the first process meet the requirements and no further detection operation is required.

[0031] In a fourth aspect, the present application provides an electronic device, comprising: a detection module and a processing module, wherein the detection module is configured to detect a first memory occupied by a first process, where the first memory is actual physical memory usage (RSS). The detection module is configured to detect a second memory occupied by the first process when the first memory is greater than a first threshold, where the second memory is proportionally allocated actual physical memory usage (PSS). The processing module is configured to process the first process when the second memory is greater than the first threshold.

[0032] In one example, the first process can be understood as the running process of a first application on the electronic device. The first process can include one or more processes.

[0033] In one example, the first threshold may refer to an upper limit of memory that can be used by the first process, which is the rated memory of the first application. The rated memory may be the memory configured by the electronic device for the first application when the electronic device is started.

[0034] In this way, the electronic device first detects the RSS occupied by the first process. If the RSS occupied by the first process exceeds the rated memory (i.e., the first threshold), the electronic device then detects the PSS occupied by the first process. Because the RSS has a larger range than the PSS, the electronic device filters out most processes by detecting the RSS occupied by the first process. Then, by detecting the PSS occupied by the first process, the electronic device can accurately locate the process with excess memory, thereby improving the accuracy of memory detection.

[0035] In some technical solutions, the electronic device further includes: an execution module, wherein the execution module is configured to: when the first memory is less than or equal to the first threshold, skip executing the detection operation of whether the second memory is greater than the first threshold. That is, because the RSS range is larger than the PSS range, the electronic device detects that the RSS occupied by the first process does not exceed the rated memory, and thus determines that the PSS occupied by the first process does not exceed the rated memory. In this way, the electronic device does not need to detect the PSS occupied by the first process, saving detection time and reducing the time consumption of memory detection of the electronic device. At the same time, accurate memory detection is achieved.

[0036] In one technical solution, the detection module is used to: end the detection operation when the second memory is less than or equal to the first threshold.

[0037] In some technical solutions, the electronic device further includes: a determination module, wherein the determination module is configured to determine device information of the electronic device and characteristic information of the first process, wherein the device information of the electronic device is used to characterize a state of the electronic device, and the characteristic information of the first process is used to characterize the state of the first process. The detection module is configured to detect the first memory occupied by the first process when the device information or the characteristic information changes.

[0038] In a technical solution, the device information of the electronic device includes at least one of the following: system status, user operation status; the characteristic information of the first process includes at least one of the following: process status and foreground and background status.

[0039] In a technical solution, the characteristic information of the first process includes a process state; and the detection module is configured to detect the first memory occupied by the first process when the process state is a non-suspended state.

[0040] In a technical solution, the characteristic information of the first process includes foreground and background states; and the detection module is used to detect the first memory occupied by the first process when the foreground and background states are background states.

[0041] In a technical solution, the device information of the electronic device includes a system state; and the detection module is configured to detect the first memory occupied by the first process when the system state is a non-idle state.

[0042] In a technical solution, the device information of the electronic device includes a user operation status; and the detection module is configured to detect the first memory occupied by the first process when the user operation status is a no-operation state.

[0043] In the embodiment of the present application, the electronic device determines whether to use the above detection method to detect the memory occupied by the first process based on the state of the electronic device. In other words, the electronic device comprehensively considers various user scenarios and achieves accurate detection of the process memory and reduces the detection time while ensuring minimal impact on the foreground.

[0044] In one technical solution, the first threshold is the rated memory of the first process.

[0045] In one technical solution, the processing module is used to: when the second memory is greater than the first threshold, perform memory detection on the first process at a preset time interval; when the number of memory detections on the first process is greater than a second threshold, report the occupied memory of the first process.

[0046] In one technical solution, the processing module is used to: when the second memory is greater than the first threshold, kill the first process.

[0047] Here, the electronic device killing the first process can be understood as the electronic device shutting down the first process. That is, the electronic device does not run the first process. Of course, in the embodiments of the present application, the electronic device's processing of the first process is not limited to killing the first process and may also include adjusting the rated memory of the first process, etc. This is not specifically limited in the embodiments of the present application.

[0048] In a fifth aspect, the present application provides an electronic device, comprising: one or more processors; and a memory, wherein the memory stores code; when the code is executed by the processor, the electronic device executes the method described in the first aspect.

[0049] In a sixth aspect, the present application provides a computer-readable storage medium comprising computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the method as described in the first aspect.

[0050] Among them, the specific implementation methods and corresponding technical effects of each of the above-mentioned second to sixth aspects can refer to the specific implementation methods and technical effects of the above-mentioned first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] FIG1 is a schematic diagram showing the time consumption during a memory detection process;

[0052] FIG2 is a schematic diagram showing the time consumption during another memory detection process;

[0053] FIG3 is a schematic structural diagram of an electronic device provided in an embodiment of the present application;

[0054] FIG4 is another schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0055] FIG5 is a flow chart of a memory detection method provided in an embodiment of the present application;

[0056] FIG6 is another flowchart of a memory detection method provided in an embodiment of the present application;

[0057] FIG7 is another flowchart of a memory detection method provided in an embodiment of the present application;

[0058] FIG8 is a schematic diagram of another flow chart of the memory detection method provided in an embodiment of the present application;

[0059] FIG9 is a schematic diagram of another flow chart of the memory detection method provided in an embodiment of the present application;

[0060] FIG10 is another schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0061] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application. In the description of the present application, unless otherwise specified, " / " indicates that the objects associated before and after are in an "or" relationship. For example, A / B can represent A or B. The "or" in the present application is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. In addition, in the description of the present application, unless otherwise specified, "multiple" refers to two or more than two. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, a and b, a and c, b and c, or a and b and c, where a, b, c can be single or multiple. In addition, in order to facilitate the clear description of the technical solutions of the embodiments of the present application, in the embodiments of the present application, words such as "first" and "second" are used to distinguish between identical or similar items with substantially the same functions and effects. Those skilled in the art will understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit differences. At the same time, in the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or design schemes. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete way for easy understanding.

[0062] The measurement indicators of the memory resources of an electronic device may include the actual use of physical memory (resident set size, RSS) and the proportional allocation of actual use of physical memory (proportional set size, PSS). Among them, RSS may include the memory occupied by shared libraries. PSS may include the memory occupied by proportionally allocated shared libraries. In order to prevent applications on electronic devices from abusing memory resources. The electronic device configures a memory quota for each application. When the application on the electronic device is running, the electronic device detects the PSS occupied by each process. However, the process of detecting the PSS occupied by each process is time-consuming. As shown in Figure 1, it takes about 129ms for the electronic device to detect the PSS occupied by 479 processes.

[0063] To address the time consumption issue, the electronic device detects the RSS usage of each process. As shown in Figure 2, it takes approximately 18ms for the electronic device to detect the RSS usage of 479 processes, significantly reducing the time consumption. However, when detecting the RSS usage of each process, the electronic device counts all shared library memory towards each process. For example, if the electronic device configures a rated memory of 2048MB for each application, the corresponding process of each application can use 2048MB of memory. Process A uses 2050MB of private memory, process B uses 50MB of private memory, and processes A and B use 8MB of shared memory. Therefore, when detecting the RSS usage of each process, the electronic device determines that the RSS usage of process A is 2050MB + 8MB = 2058MB, and the memory usage of process B is 50MB + 8MB = 58MB. Therefore, since the electronic device counts all shared library memory towards each process when detecting the RSS usage of each process, the memory detection may be inaccurate.

[0064] To solve the above technical problems, an embodiment of the present application provides a memory detection method, which is applied to an electronic device. A first application is installed on the electronic device and is running, i.e., a first process. The first process may include one or more processes. The method may include: the electronic device detects a first memory occupied by the first process, where the first memory is the actual physical memory used (RSS). When the first memory is greater than a first threshold, the electronic device detects a second memory occupied by the first process, where the second memory is the proportionally allocated actual physical memory used (PSS). When the second memory is greater than the first threshold, the electronic device performs a memory detection on the first process according to a preset time. In this way, the electronic device first detects the RSS occupied by the first process. If the RSS occupied by the first process exceeds the rated memory (i.e., the first threshold), the electronic device then detects the PSS occupied by the first process. Since the RSS range is larger than the PSS range, the electronic device filters out most processes by detecting the RSS occupied by the first process, and then accurately locates the process with excess memory by detecting the PSS occupied by the first process, thereby improving the accuracy of memory detection.

[0065] In some embodiments, the method may further include: when the first memory is less than or equal to a first threshold, the electronic device skips executing the detection operation of whether the second memory is greater than the first threshold. That is, because the RSS is larger than the PSS, the electronic device detects that the RSS occupied by the first process does not exceed the rated memory, and thus determines that the PSS occupied by the first process does not exceed the rated memory. In this way, the electronic device does not need to detect the PSS occupied by the first process, saving detection time and reducing the time consumption of memory detection of the electronic device. At the same time, accurate memory detection is achieved.

[0066] Continuing with the above example, the electronic device configures a rated memory of 2048MB for each application. This means that the upper limit of memory that the process corresponding to the application can use is 2048MB. Process A occupies 2050MB of private memory, process B occupies 50MB of private memory, and the shared memory occupied by processes A and B is 8MB. Then:

[0067] For process A, the memory usage of process A is detected as: A_RSS=2050M+8M=2058M, which exceeds the rated memory of 2048M, so A_PSS=2050M+8 / 2M=2054M is collected, which exceeds the rated memory of 2048M, so the electronic device performs memory detection on the first process according to the preset time. Afterwards, the electronic device can check and kill the first process. Therefore, using the method provided in the embodiment of the present application, the electronic device first detects whether the RSS occupied by process A exceeds the rated memory. If the RSS occupied by process A does not exceed the rated memory, the electronic device does not need to detect whether the PSS occupied by process A exceeds the rated memory; if the RSS occupied by process A exceeds the rated memory, the electronic device further detects whether the PSS occupied by process A exceeds the rated memory; since the RSS is larger than the PSS range, the electronic device filters out most processes by detecting the RSS occupied by process A, thereby improving the accuracy of memory detection.

[0068] For process B, the memory usage of process B is detected as: B_RSS=50M+8M=58M, which does not exceed the rated memory of 2048M, so process B is filtered out and no PSS detection is performed on process B. In other words, the detection process of the PSS memory of process B is omitted, saving time. Therefore, using the method provided in the embodiment of the present application, since the RSS range is larger than the PSS range, the electronic device filters out most of the processes by detecting the RSS occupied by process B. In other words, the electronic device detects that the RSS occupied by process B does not exceed the rated memory, which means that the PSS occupied by process B does not exceed the rated memory. In this way, the electronic device does not need to detect the PSS occupied by process B, saving detection time and reducing the time consumption of memory detection of the electronic device. At the same time, accurate memory detection is achieved.

[0069] In some actual usage scenarios, the time it takes for an electronic device to detect the memory resources occupied by 479 processes can be optimized from 129ms to 2ms, reducing overhead by nearly 98.4%, significantly reducing time consumption, and at the same time, achieving accurate memory detection.

[0070] Of course, the embodiments of the present application are not limited to the electronic device detecting the memory of the first process. It can also be the electronic device detecting the resources of the electronic device called by the first process. For example, the electronic device detects the resources called by the first process (such as the calling interface (such as I / O), CPU resources). In the embodiments of the present application, the electronic device detecting the memory of the process is used as an example for detailed description.

[0071] Among them, the above-mentioned electronic devices can be mobile phones, tablet computers, laptops, notebook computers, ultra-mobile personal computers (UMPCs), handheld computers, netbooks, personal digital assistants (PDAs), wearable electronic devices and other devices. The specific form of the electronic devices is not particularly limited in the embodiments of the present application.

[0072] FIG3 is a structural block diagram of the electronic device.

[0073] As shown in FIG3 , the electronic device 100 may include a processor 210, a memory 220, a universal serial bus (USB) interface 230, a charging management module 240, a power management module 241, a battery 242, an antenna 1, a wireless communication module 260, a display 270, and a sensor module 250. The sensor module 250 may include a pressure sensor 250A, a touch sensor 250B, and the like.

[0074] It is understood that the structures illustrated in the embodiments of the present application do not constitute specific limitations on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0075] The processor 210 may include one or more processing units. For example, the processor 210 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, or a neural-network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors.

[0076] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.

[0077] Processor 210 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 210 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 210. If processor 210 needs to use the same instruction or data again, it can directly access the memory. This avoids duplicate accesses, reduces processor 210 latency, and thus improves system efficiency.

[0078] In one embodiment, the electronic device is started, at which time the first application on the electronic device is running, that is, the first process is running. The processor 210 of the electronic device configures a rated memory for the first application, and when the application is running, the upper limit memory that the process corresponding to the application can use is the rated memory. The processor 210 of the electronic device identifies the device information of the electronic device and the characteristic information of the first process. The processor 210 of the electronic device determines whether the device information or the characteristic information has changed. When the device information or the characteristic information has changed, the processor 210 detects the RSS occupied by the first process. When the RSS occupied by the first process exceeds the rated memory, the processor 210 detects whether the PSS occupied by the first process exceeds the rated memory. When it is detected that the PSS occupied by the first process exceeds the rated memory, the processor 210 performs a killing operation on the first process.

[0079] The charging management module 240 is configured to receive charging input from a charger. The charger can be either a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 240 can receive charging input from the wired charger via the USB interface 230. In some wireless charging embodiments, the charging management module 240 can receive wireless charging input via the electronic device's wireless charging coil. While charging the battery 242, the charging management module 240 can also power the electronic device through the power management module 241.

[0080] The power management module 241 is used to connect the battery 242, the charging management module 240, and the processor 210. The power management module 241 receives input from the battery 242 and / or the charging management module 240 and provides power to the processor 210, the internal memory 221, the display 270, the camera 293, and the wireless communication module 260. The power management module 241 can also be used to monitor parameters such as battery capacity, battery cycle count, and battery health status (leakage, impedance). In some other embodiments, the power management module 241 can also be set in the processor 210. In other embodiments, the power management module 241 and the charging management module 240 can also be set in the same device.

[0081] The wireless communication function of the electronic device can be implemented through the antenna 1, the wireless communication module 260, the modem processor and the baseband processor.

[0082] Antenna 1 is used to transmit and receive electromagnetic wave signals. Each antenna in an electronic device can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve antenna utilization. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In other embodiments, the antenna can be used in conjunction with a tuning switch.

[0083] The wireless communication module 260 can provide wireless communication solutions for electronic devices, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc. The wireless communication module 260 can be one or more devices that integrate at least one communication processing module. The wireless communication module 260 receives electromagnetic waves via the antenna 1, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 210. The wireless communication module 260 can also receive signals to be sent from the processor 210, frequency modulate them, amplify them, and convert them into electromagnetic waves for radiation through the antenna 1. In some embodiments, the wireless communication module 260 receives application messages sent by the server.

[0084] The electronic device implements display functionality through a GPU, display screen 270, and an application processor. A GPU is a microprocessor for image processing that connects display screen 270 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 210 may include one or more GPUs that execute program instructions to generate or modify display information.

[0085] Display screen 270 is used to display images, videos, and the like. Display screen 270 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-oLed, or a quantum dot light-emitting diode (QLED). In some embodiments, the electronic device can include one or N display screens 270, where N is a positive integer greater than one.

[0086] The memory 220 can be used to store computer executable program code, which includes instructions. The memory 220 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device (such as audio data, a phone book, etc.), etc. In addition, the memory 220 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. The processor 210 executes various functional applications and data processing of the electronic device by running instructions stored in the memory 220, and / or instructions stored in a memory provided in the processor.

[0087] Pressure sensor 250A is used to sense pressure signals and convert them into electrical signals. In some embodiments, pressure sensor 250A can be located on display screen 270. There are many types of pressure sensors 250A, such as resistive, inductive, and capacitive. A capacitive pressure sensor can include at least two parallel plates made of conductive material. When force acts on pressure sensor 250A, the capacitance between the electrodes changes. The electronic device determines the intensity of the pressure based on this change in capacitance. When a touch operation is applied to display screen 270, the electronic device detects the intensity of the touch operation based on pressure sensor 250A. The electronic device can also calculate the location of the touch based on the detection signal from pressure sensor 250A. In some embodiments, touch operations applied to the same touch location but with different touch operation intensities can correspond to different operation instructions. For example, when a touch operation with an intensity less than a first pressure threshold is applied to a short message application icon, a command to view short messages is executed. When a touch operation with an intensity greater than or equal to the first pressure threshold is applied to a short message application icon, a command to create a new short message is executed.

[0088] In one embodiment, pressure sensor 250A can detect a user operation, such as a click or slide, on display screen 270 of electronic device 100 and obtain operation information. Pressure sensor 250A sends the operation information to processor 210. Processor 210 can determine, based on the operation information, that a user operation has occurred. In this case, processor 210 may not detect the memory occupied by the first process. Processor 210 can determine, based on the operation information, that no user operation has occurred. In this case, processor 210 may detect the memory occupied by the first process.

[0089] Touch sensor 250B, also known as a "touch-sensitive device," can be disposed on display screen 270. Touch sensor 250B and display screen 270 form a touch screen, also known as a "touch screen." Touch sensor 250B is configured to detect touch operations applied thereto or in the vicinity thereof. The touch sensor can transmit the detected touch operations to an application processor to determine the type of touch event. Visual output related to the touch operations can be provided via display screen 270. In other embodiments, touch sensor 250B can also be disposed on the surface of the electronic device, at a location different from that of display screen 270.

[0090] In one embodiment, the touch sensor 250B can detect a user operation such as a click or slide on the display screen 270 of the electronic device 100 and obtain operation information. The touch sensor 250B sends the operation information to the processor 210. The processor 210 can determine that a user operation has occurred based on the operation information. In this case, the processor 210 may not detect the memory occupied by the first process. The processor 210 can determine that a user operation has not occurred based on the operation information. In this case, the processor 210 may detect the memory occupied by the first process.

[0091] Of course, the electronic device may also include other functional units, which is not limited in the embodiments of the present application.

[0092] FIG4 is another structural block diagram of the electronic device.

[0093] As shown in Figure 4, electronic device 100 may include a quota management module, an identification module, a detection module, and an execution module. Exemplarily, the quota management module, identification module, detection module, and execution module may be deployed on processor 210 shown in Figure 3. The quota management module is used to record the memory occupied by each process on the electronic device, such as the rated memory of each process. The identification module is used to identify the status of the electronic device, such as the status of each process on the electronic device, whether each process is in the background or foreground, the status of the electronic device's operating system, and user interface operations on the electronic device. The detection module is used to detect the RSS occupied by each process and, when the RSS occupied by each process exceeds the rated memory, detect the PSS occupied by a process. The detection module is specifically used to determine whether to detect the RSS occupied by each process based on the status of the electronic device identified by the identification module (such as device information of the electronic device and feature information of the first process). The execution module is used to execute a check and kill operation on each process based on the detection results of the detection module. In some examples, the execution module may also be used to add a new memory quota when the RSS occupied by a process exceeds the rated memory. The detection module may include a decision module and a detection submodule. The decision module is used to determine whether the state of the electronic device has changed based on the state of the electronic device identified by the identification module. The detection submodule is used to detect the RSS occupied by each process when the state of the electronic device changes, and to detect the PSS occupied by each process when the RSS occupied by each process exceeds the rated memory.

[0094] In one example, as shown in FIG4 , the workflow of the electronic device 100 is as follows: Step 1: The electronic device is started. At this time, the first application on the electronic device is running, that is, the first process is running. The quota management module of the electronic device configures a rated memory for the application. When the application is running, the upper limit of the memory that can be used by the process corresponding to the application is the rated memory. Step 2: The identification module of the electronic device identifies the status of the electronic device (such as the device information of the electronic device and the characteristic information of the first process). Step 3: The decision module of the electronic device determines whether the status of the electronic device has changed based on the status of the electronic device identified by the identification module. Step 4: When the status of the electronic device changes, the detection submodule detects the RSS occupied by the first process. When the RSS occupied by the first process exceeds the rated memory, the detection submodule detects whether the PSS occupied by the first process exceeds the rated memory. Step 5: When it is detected that the PSS occupied by the first process exceeds the rated memory, the execution module of the electronic device performs a kill operation on the first process. At this time, the detection module of the electronic device reports the memory occupied by the first process to the quota management module.

[0095] In this way, the electronic device first detects the RSS of the first process. If the RSS of the first process exceeds the rated memory, the electronic device then detects the PSS of the first process. Because the RSS has a larger range than the PSS, the electronic device can filter out most processes by detecting the RSS of the first process. Then, by detecting the PSS of the first process, the electronic device can accurately locate the process with excessive memory, thereby improving the accuracy of memory detection.

[0096] FIG5 is a flow chart of a memory detection method provided in an embodiment of the present application. As shown in FIG5 , the method is applied to an electronic device on which a first application is installed. The method may include steps S501-S504 (some of which are optional). For details of steps S501-S504, please refer to the description of the following embodiment. Specifically, it may be:

[0097] S501: The electronic device is started and configures a rated memory for a first application. When the application is running, the upper limit of the memory that can be used by a process corresponding to the application is the rated memory.

[0098] The electronic device being started up can be understood as the electronic device being in a power-on state. Specifically, the electronic device being started up can be implemented by the electronic device executing the power-on operation in response to receiving a power-on operation from the user.

[0099] That is, after an electronic device is turned on, it can run multiple applications, each corresponding to a process. These processes consume electronic device resources, such as memory. To prevent these processes from abusing electronic device resources, the electronic device can pre-configure a specified amount of memory for the applications corresponding to these processes.

[0100] The first process may be understood as the running process of the first application on the electronic device.

[0101] The rated memory may be a memory pre-set for the first application. For example, the rated memory of the first application may be 2048 MB or 50 MB. Of course, the setting of the rated memory needs to be determined according to actual conditions and is not specifically limited in the embodiments of the present application.

[0102] In a specific implementation method, S501 can be specifically implemented as follows: after the electronic device is started, the electronic device receives the rated memory of each process pushed by the server. Specifically, the electronic device can receive the rated memory of each process pushed by the server in real time. Alternatively, the electronic device can receive the rated memory of each process pushed by the server according to a first preset time interval. Among them, the first preset time interval can be set according to actual conditions, such as 1 hour or 1 day, etc., and is not specifically limited in the embodiments of the present application. In one example, S501 can be specifically implemented as follows: after the electronic device is started, the quota management module of the electronic device receives the rated memory of each process pushed by the server. Afterwards, the electronic device executes step ① as shown in Figure 4. The quota management module of the electronic device sends the rated memory of each process to the detection module of the electronic device.

[0103] In another specific implementation, S501 may be implemented as follows: after the electronic device is powered on, the electronic device sends a request to a server to obtain the rated memory of each process. The server receives the request and, based on the request, obtains the rated memory of each process. The server then sends the rated memory of each process to the electronic device. Specifically, the electronic device may send the request to the server to obtain the rated memory of each process in real time. Alternatively, the electronic device may send the request to the server to obtain the rated memory of each process at a second preset time interval. The second preset time interval can be set based on actual circumstances, such as one hour or one day, and is not specifically limited in this embodiment of the present application. Alternatively, in response to a user operation, the electronic device sends the request to the server to obtain the rated memory of each process. User operations may include, for example, clicking the power button of the electronic device, or clicking the screen off operation, and so on, which are not specifically limited in this embodiment of the present application. In one example, S501 may be implemented as follows: after the electronic device is powered on, the quota management module of the electronic device sends a request to the server to obtain the rated memory of each process. The server receives the request and, based on the request, obtains the rated memory of each process. Afterwards, the server sends the rated memory of each process to the quota management module of the electronic device. Afterwards, the electronic device executes step ① shown in FIG4 : the quota management module of the electronic device sends the rated memory of each process to the detection module of the electronic device.

[0104] After the electronic device executes S501 and configures the rated memory for the first application corresponding to the first process, the electronic device executes S502 and the electronic device determines whether the memory occupied by the first process at the first moment exceeds the first memory based on the memory available to the first process. The first moment can be understood as the moment when the electronic device detects the memory occupied by the first process. The first memory can be understood as a predefined memory, and the memory size can be set according to actual conditions. In specific implementation, the first memory can be the rated memory of the first process. In the embodiment of the present application, the first memory is taken as the rated memory of the first process for illustration. In some examples, the electronic device can directly detect the memory occupied by the first process at the first moment, or it can detect the memory occupied by the first process at the first moment under the triggering of other conditions. The following is a detailed description of different situations:

[0105] In case 1, the electronic device directly detects the memory occupied by the first process at the first moment. As shown in FIG5 , S502 can be specifically implemented as follows:

[0106] S5021: The electronic device directly detects whether the RSS occupied by the first process at the first moment exceeds the rated memory. If the RSS occupied by the first process exceeds the rated memory, the electronic device executes S5022; if the RSS occupied by the first process does not exceed the rated memory, the electronic device executes the end detection operation.

[0107] In one specific implementation, the specific implementation of S5021 can be seen in the RSS detection unit shown in Figure 4, which is used to detect whether the RSS occupied by the first process at the first moment exceeds the rated memory. When the RSS detection unit detects that the RSS occupied by the first process exceeds the rated memory, the electronic device executes step 4 shown in Figure 4.

[0108] Continuing with the above example, the electronic device configures a rated memory of 2048MB for each application, and the corresponding memory available to each application process is 2048MB. Process A occupies 2050MB of private memory, process B occupies 50MB of private memory, and the shared memory occupied by processes A and B is 8MB. Then:

[0109] In Example 1, assuming that the first process is process A, the electronic device detects that the RSS occupied by the first process is A_RSS=2050M+8M=2058M, which exceeds the rated memory of 2048M. At this time, the electronic device executes S5022.

[0110] Example 2: Assuming the first process is process B, the electronic device detects that the RSS occupied by the first process is B_RSS=50M+8M=58M, which does not exceed the rated memory of 2048M. At this time, the electronic device performs the end detection operation.

[0111] This allows electronic devices to filter out nearly 99% of processes by detecting their RSS. Only the remaining 1% of processes needs to undergo PSS testing, significantly reducing power consumption. In practical applications, the time it takes for an electronic device to detect the memory resources occupied by 479 processes has been reduced from 129ms to 2ms, a nearly 98.4% reduction in overhead. This significantly reduces time consumption while achieving accurate memory detection.

[0112] Of course, the above examples are only used to illustrate the solutions in the embodiments of the present application, so the embodiments of the present application are not limited to the above examples. They will not be listed one by one here.

[0113] In an embodiment of the present application, since the RSS range is larger than that of the PSS, the electronic device first detects the RSS occupied by the first process. If the RSS occupied by the first process does not exceed the rated memory, it means that the PSS occupied by the first process also does not exceed the rated memory. In this way, the electronic device does not need to detect the PSS occupied by the first process, eliminating the detection process of the PSS memory of the first process, saving detection time, and reducing the time consumption of memory detection of the electronic device.

[0114] S5022: The electronic device detects whether the PSS occupied by the first process at the first moment exceeds the rated memory. If the PSS occupied by the first process exceeds the rated memory, the electronic device executes S503; if the PSS occupied by the first process does not exceed the rated memory, the electronic device executes the end detection operation.

[0115] In one specific implementation, the specific implementation of S5022 can be seen in the PSS detection unit shown in Figure 4, which is used to detect whether the PSS occupied by the first process exceeds the rated memory at the first moment. When the PSS detection unit detects that the PSS occupied by the first process exceeds the rated memory, the electronic device executes step 5 as shown in Figure 4, or the electronic device executes steps 6 and 5 as shown in Figure 4.

[0116] Continuing with Example 1 above, the electronic device further detects the PSS occupied by the first process and detects that the RSS occupied by the first process is A_PSS=2050M+8 / 2M=2054M, which exceeds the rated memory of 2048M. At this point, the electronic device determines that the memory occupied by the first process exceeds the rated memory.

[0117] In an embodiment of the present application, the electronic device first detects the RSS of the first process. If the RSS of the first process exceeds the rated memory, the electronic device then detects the PSS of the first process. Because the RSS has a larger range than the PSS, the electronic device filters out most processes by detecting the RSS of the first process. It then accurately locates the process with excess memory by detecting the PSS of the first process, thus saving detection time and improving the accuracy of memory detection.

[0118] After the electronic device determines that the memory occupied by the first process exceeds the rated memory, the electronic device may execute S503, which is specifically as follows:

[0119] S503: The electronic device detects and kills the first process.

[0120] Here, the electronic device killing the first process can be understood as the electronic device shutting down the first process. That is, the electronic device does not run the first process. Of course, in the embodiments of the present application, the electronic device's processing of the first process is not limited to killing the first process and may also include adjusting the rated memory of the first process, etc. This is not specifically limited in the embodiments of the present application. In the embodiments of the present application, the electronic device killing the first process is used as an example for explanation.

[0121] In one specific implementation, as shown in FIG5 , S503 can be specifically implemented as follows: when the electronic device determines that the memory occupied by the first process exceeds the rated memory, the electronic device kills the first process. In other words, based on the detection result that the memory occupied by the first process exceeds the rated memory, the electronic device can directly kill the first process. Specifically, the specific implementation of S503 can be found in step 5 of FIG4 , and will not be further described here.

[0122] In another specific implementation, as shown in FIG6 , S503 may be specifically implemented as follows: S5031. At a first moment, the electronic device determines that the memory occupied by the first process exceeds the rated memory. Thereafter, the electronic device detects the memory occupied by the first process at a third preset time interval. The third preset time interval can be set based on actual circumstances, for example, one hour or one day, and is not specifically limited in this embodiment of the present application. Furthermore, S5032. The electronic device reports the memory occupied by the first process at each moment to the server. S5033. The server determines, based on the memory occupied by the first process at each moment, that the number of times the memory occupied by the first process exceeds the rated memory exceeds a threshold. The threshold can be three or six times, and is not specifically limited in this application. For example, the electronic device detects that the memory occupied by the first process exceeds the rated memory three times in a row. Alternatively, the server determines, based on the memory occupied by the first process at each moment, that the number of times the memory occupied by the first process exceeds the rated memory within a continuous period exceeds a threshold. For example, the server detects that the memory occupied by the first process exceeds the rated memory three times in a continuous period within four consecutive hours. In this case, S5034. The server may instruct the electronic device to kill the first process. S5035: The electronic device detects and kills the first process according to the instruction of the server. Specifically, the specific implementation of S503 can refer to steps 6 and 5 as shown in FIG4 , which will not be described in detail here.

[0123] In another specific implementation method, as shown in Figure 7, S503 can be specifically implemented as follows: S5031. At a first moment, the electronic device determines that the memory occupied by the first process exceeds the rated memory. Afterwards, the electronic device detects the memory occupied by the first process according to a third preset time interval. The third preset time interval is the same as the above-mentioned related description and will not be repeated here. S5036. The electronic device determines that the number of times the memory occupied by the first process exceeds the rated memory exceeds a threshold value based on the memory occupied by the first process at each moment. Alternatively, the electronic device determines that the number of times the memory occupied by the first process exceeds the rated memory in a continuous time exceeds a threshold value based on the memory occupied by the first process at each moment. Specifically, for the specific implementation of S5036, please refer to the relevant description in the above-mentioned S5033, which will not be repeated here. At this time, S5037, the electronic device checks and kills the first process. Specifically, for the specific implementation of S503, please refer to steps ⑥ and ⑤ as shown in Figure 4, which will not be repeated here.

[0124] In the second case, the electronic device detects the memory occupied by the first process at the first moment under the triggering of other conditions.

[0125] Among them, other conditions can be understood as conditions that trigger the detection of the memory occupied by the first process. The condition may include a condition that the state of the electronic device changes. In one example, the state of the electronic device may include at least one of the following: the process state of the process in the electronic device, the state of the process in the foreground or background of the electronic device (referred to as the foreground and background states), the state of the operating system of the electronic device (referred to as the system state), and user operations. In one example, the state of the electronic device changes, which may include at least one of the following: the process state is not suspended, the process is in the background, the system state is non-idle, and the user operation is no operation (such as no click or slide operation, etc.).

[0126] In one example, a process state of suspended state can be understood as follows: a suspended process can be defined as a process temporarily eliminated from memory in the operating system. Conversely, a process state of non-suspended state can be understood as follows: a non-suspended process can be defined as a process temporarily not eliminated from memory in the operating system.

[0127] In one example, a process being in the foreground state can be understood as the process running in the foreground. Conversely, a process being in the background state can be understood as the process running in the background.

[0128] In one example, the system status is idle, which can be understood as the electronic device's operating system being powered on but not operating. Conversely, the system status is non-idle, which can be understood as the electronic device's operating system being powered on and operating. For example, in the case of a mobile phone, the mobile phone can determine the system status based on code in its source code.

[0129] For example, a mobile phone can determine that the system state is idle based on the following codes in the source code, specifically as follows: IDLE, / / standby, no connection; ACTIVE, / / call; HOLDING, / / hang up the call; DIALING, / / ringing; ALERTING, / / reminder; INCOMING, / / incoming call; WAITING, / / waiting for the call to be connected; DISCONNECTED, / / after the connection is disconnected; DISCONNECTING; / / disconnection in progress, etc.

[0130] In one example, a user operation is a presence operation, which can be understood as: the user performs a touch operation on the display screen of the electronic device, and the touch operation can include a sliding operation, a pressing operation, a clicking operation, etc. Of course, the touch operation is not limited to this, and can also include a drag operation, etc. The embodiments of this application do not make specific limitations. Conversely, a user operation is a absence operation, which can be understood as: the user does not perform a touch operation on the display screen of the electronic device.

[0131] In some examples, the difference between the second case and the first case is that, as shown in FIG8 , the electronic device further performs the following steps before executing S502:

[0132] S504: The electronic device determines device information of the electronic device and characteristic information of the first process, where the device information of the electronic device is used to represent a state of the electronic device, and the characteristic information of the first process is used to represent the state of the first process.

[0133] In some examples, the device information of the electronic device includes at least one of the following: system status and user operation status. That is, the status of the electronic device. Of course, in the embodiments of the present application, the feature information is not limited to the information listed above and may also include other information, such as whether the electronic device is in the screen-off state, etc., which is not specifically limited in the embodiments of the present application.

[0134] In some examples, the characteristic information of the first process includes at least one of the following: process status and foreground and background status. Of course, in the embodiment of the present application, the characteristic information is not limited to the above-mentioned information, and is not specifically limited in the embodiment of the present application.

[0135] In a specific implementation method, S504 can be specifically implemented as follows: the electronic device identifies the device information and feature information. Specifically, as shown in FIG4 , the identification module of the electronic device identifies the process status of the process in the electronic device, the status of the process in the electronic device in the foreground or background, the status of the operating system of the electronic device, and the user operation. Among them, the electronic device identifies the device information and feature information, and the specific implementation method can refer to the identification method in the prior art. For example, the electronic device determines the user scenario and the impact on the user under the scenario based on big data analysis, thereby identifying the above-mentioned feature information. They are not listed one by one in the embodiments of the present application.

[0136] Accordingly, S502 can be specifically implemented as follows: when the device information or feature information changes, the electronic device executes S5021 and S5022. The specific implementation of S5021-S5022 can refer to the relevant description in the above embodiment and will not be repeated here.

[0137] In some examples, the feature information may include a process state. Accordingly, S502 may be specifically implemented as follows: when the process state is not suspended, the electronic device executes S5021 and S5022. In addition, when the process state is suspended, the electronic device may not detect the memory occupied by the first process.

[0138] In some examples, the characteristic information may include foreground and background states. Accordingly, S502 may be specifically implemented as follows: when the current background state is the background state, the electronic device executes S5021 and S5022. In addition, when the current background state is the foreground state, the electronic device may not detect the memory occupied by the first process.

[0139] In some examples, the device information may include a system state. Accordingly, S502 may be specifically implemented as follows: when the system state is not idle, the electronic device executes S5021 and S5022. In addition, when the system state is idle, the electronic device may not detect the memory occupied by the first process.

[0140] In some examples, the device information may include a user operation state. Accordingly, S502 may be specifically implemented as follows: when the user operation state is a no-operation state, the electronic device executes S5021 and S5022. In addition, when the user operation state is an operation state, the electronic device may not detect the memory occupied by the first process.

[0141] Of course, the above examples can be combined in any way, and the embodiments of this application do not limit them specifically.

[0142] In a specific implementation method, the process status of the process in the above-mentioned electronic device, the status of the process in the electronic device in the foreground or background, the status of the operating system of the electronic device, and the user operation can be arbitrarily combined. Moreover, the order of these information can be arbitrary and is not specifically limited in the embodiment of the present application. In the embodiment of the present application, the electronic device determines whether to use the above-mentioned detection method to detect the memory occupied by the first process in combination with the status of the electronic device. That is to say, the electronic device comprehensively considers various user scenarios, and realizes accurate detection of the memory of the process and reduces the time consumption of detection on the basis of ensuring that the impact on the foreground is minimized.

[0143] In another specific implementation, to achieve optimal results, the above-mentioned device information and feature information can be judged in sequence. For example, as shown in FIG9 , S502 can be specifically implemented as follows: S5020: The electronic device determines whether the process state is suspended. If the electronic device determines that the process state is suspended, the electronic device performs a non-detection of the memory occupied by the first process. If the electronic device determines that the process state is not suspended, the electronic device performs S5023. S5023: The electronic device determines whether the first process is in the background state. If the electronic device determines that the first process is in the foreground state, the electronic device performs a non-detection of the memory occupied by the first process. If the electronic device determines that the first process is in the background state, the electronic device performs S5024. S5024: The electronic device determines whether the system state is idle. If the system state is idle, the electronic device performs a non-detection of the memory occupied by the first process. If the system state is not idle, the electronic device performs S5025. S5025: The electronic device determines whether a user operation has occurred. If the electronic device determines that a user operation has occurred, the electronic device does not detect the memory occupied by the first process. If the electronic device determines that there is no user operation, the electronic device performs S5021 and S5022.

[0144] In one example, based on the degree of influence of each electronic device on the foreground, the electronic device can configure a judgment order for the above-mentioned process status, foreground and background status, system status, and user operation. That is, the process status may have the greatest impact on the foreground, so the electronic device can first judge the process status. Secondly, the foreground and background status may have a greater impact on the foreground, so the electronic device can secondly judge the foreground and background status. Thirdly, the system status may have a slightly smaller impact on the foreground, so the electronic device can again judge the system status. Finally, the user operation may have the least impact on the foreground, so the electronic device can secondly judge the user operation. Of course, this example only provides one feasible solution, and the embodiments of the present application are not limited to this.

[0145] In the embodiment of the present application, the electronic device determines whether to use the above detection method to detect the memory occupied by the first process based on the electronic device's state and the degree of impact of each state on the foreground. In other words, the electronic device comprehensively considers various user scenarios and the degree of impact of each state on the foreground, and achieves accurate detection of the process's memory and reduces detection time while ensuring minimal impact on the foreground.

[0146] Unless otherwise specified or there is no logical conflict, the terms and / or descriptions between the various embodiments of the present application are consistent and can be referenced by each other. The technical features in different embodiments can be combined to form new embodiments based on their internal logical relationships.

[0147] The present application also provides an electronic device for implementing any of the above methods. For example, an electronic device is provided that includes a unit (or means) for implementing each step performed by the electronic device in the above method S501-S504. For example, please refer to Figure 10, which is a schematic diagram of an electronic device provided in an embodiment of the present application. The electronic device 1000 may include: a detection module 1010 and a processing module 1020, wherein:

[0148] Detection module 1010 is configured to detect a first memory occupied by a first process, where the first memory is the actual used physical memory RSS. Exemplarily, detection module 1010 may execute step S502 above. Specifically, detection module 1010 may execute step S5021 above. Detection module 1010 may be processor 210 shown in FIG. 3 . Specifically, detection module 1010 may be the RSS detection unit shown in FIG. 4 .

[0149] Detection module 1010 is configured to detect, when the first memory is greater than a first threshold, a second memory occupied by the first process, where the second memory is proportionally allocated physical memory (PSS). Exemplarily, detection module 1010 may execute step S502 above. Specifically, detection module 1010 may execute step S5022 above. Detection module 1010 may be processor 210 shown in FIG. 3 . Specifically, detection module 1010 may be the PSS detection unit shown in FIG. 4 .

[0150] The processing module 1020 is configured to process the first process when the second memory is greater than the first threshold. For example, the processing module 1020 may execute the above-mentioned step S503. The processing module 1020 may be the processor 210 shown in FIG3.

[0151] In some embodiments, the electronic device 1000 further includes an execution module 1030 configured to, when the first memory is less than or equal to the first threshold, skip detecting whether the second memory is greater than the first threshold. Exemplarily, the execution module 1030 may execute step S503 above. The execution module 1030 may be the processor 210 shown in FIG. 3 , and more specifically, the execution module 1030 may be the execution module shown in FIG. 4 .

[0152] In one embodiment, the detection module 1010 is configured to terminate the detection operation when the second memory is less than or equal to a first threshold.

[0153] In some embodiments, the electronic device 1000 further includes a determination module 1040, wherein the determination module 1040 is configured to determine device information of the electronic device and characteristic information of the first process, wherein the device information of the electronic device is used to characterize the state of the electronic device, and the characteristic information of the first process is used to characterize the state of the first process. The detection module is configured to detect the first memory occupied by the first process when the device information or characteristic information changes. Exemplarily, the determination module 1040 may execute the above-described step S504. The determination module 1040 may be the processor 210 shown in FIG. 3 , and specifically, the determination module 1040 may be the identification module shown in FIG. 4 .

[0154] In one embodiment, the device information of the electronic device includes at least one of the following: system status, user operation status; the characteristic information of the first process includes at least one of the following: process status and foreground and background status.

[0155] In one embodiment, the characteristic information of the first process includes a process state; and the detection module is configured to detect the first memory occupied by the first process when the process state is a non-suspended state.

[0156] In one embodiment, the characteristic information of the first process includes foreground and background states; the detection module is used to: when the current background state is the background state, detect the first memory occupied by the first process.

[0157] In one embodiment, the device information of the electronic device includes a system state; and the detection module is configured to detect a first memory occupied by a first process when the system state is a non-idle state.

[0158] In one embodiment, the device information of the electronic device includes a user operation state; and the detection module is configured to detect a first memory occupied by a first process when the user operation state is a no-operation state.

[0159] In one embodiment, the first threshold is the rated memory of the first process.

[0160] In one embodiment, the processing module 1020 is used to: when the second memory is greater than the first threshold, perform memory detection on the first process at a preset time interval; when the number of memory detections on the first process is greater than the second threshold, report the occupied memory of the first process.

[0161] In one embodiment, the processing module 1020 is configured to: when the second memory is greater than a first threshold, kill the first process.

[0162] In this application, the electronic device first detects the RSS occupied by the first process. If the RSS occupied by the first process exceeds the rated memory (i.e., the first threshold), the electronic device then detects the PSS occupied by the first process. Because the RSS range is larger than the PSS range, the electronic device filters out most processes by detecting the RSS occupied by the first process. Then, by detecting the PSS occupied by the first process, the electronic device accurately locates the process with excess memory, thereby improving the accuracy of memory detection.

[0163] It should be noted that all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module and will not be repeated here.

[0164] An embodiment of the present application also provides a computer-readable storage medium, comprising instructions, which, when executed on a computer, enables the computer to execute any of the above methods.

[0165] An embodiment of the present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above methods.

[0166] An embodiment of the present application also provides a chip, which includes a processor and an interface circuit, the interface circuit is coupled to the processor, the processor is used to run a computer program or instruction to implement the above method, and the interface circuit is used to communicate with other modules outside the chip.

[0167] All or part of any features or steps in the various embodiments of the present application may be freely combined, and the combined technical solutions are also within the scope of the present application.

[0168] In the description of this application, unless otherwise specified, " / " means "or", for example, A / B can mean A or B. "And / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, "at least one" means one or more, and "a plurality" means two or more. Words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not limit them to be different.

[0169] In the description of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be construed as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.

[0170] Through the description of the above implementation methods, technical personnel in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0171] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the modules or units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0172] The units described as separate components may or may not be physically separate, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple places. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0173] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0174] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0175] The above content is only a specific embodiment of this application, but the scope of protection of this application is not limited to this. Any changes or replacements within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.

Claims

1. A memory detection method, applied to electronic equipment, characterized in that: The method comprises: Detecting a first memory occupied by a first process, where the first memory is an actually used physical memory RSS; When the first memory is greater than a first threshold, detecting a second memory occupied by the first process, where the second memory is a proportionally allocated actually used physical memory PSS; When the second memory is greater than the first threshold, the first process is processed.

2. The method according to claim 1, characterized in that Also includes: When the first memory is less than or equal to the first threshold, skip executing the detection operation of whether the second memory is greater than the first threshold.

3. The method according to claim 1 or 2, characterized in that: Also includes: When the second memory is less than or equal to the first threshold, the detection operation is terminated.

4. The method according to any one of claims 1 to 3, characterized in that Before detecting the first memory occupied by the first process, the method further includes: Determine device information of the electronic device and feature information of the first process, wherein the device information is used to characterize a state of the electronic device, and the feature information is used to characterize a state of the first process; When the device information or the characteristic information changes, the first memory occupied by the first process is detected.

5. The method according to claim 4, characterized in that The device information includes at least one of the following: system status, user operation status; the feature information includes at least one of the following: process status and foreground and background status.

6. The method according to claim 5, characterized in that The characteristic information includes process status; When the characteristic information changes, detecting the first memory occupied by the first process includes: When the process state is in a non-suspended state, the first memory occupied by the first process is detected.

7. The method according to claim 5 or 6, characterized in that: The characteristic information includes foreground and background status; When the characteristic information changes, detecting the first memory occupied by the first process includes: When the foreground and background states are background states, the first memory occupied by the first process is detected.

8. The method according to any one of claims 5 to 7, characterized in that: The device information includes system status; When the device information changes, detecting the first memory occupied by the first process includes: When the system state is a non-idle state, the first memory occupied by the first process is detected.

9. The method according to any one of claims 5 to 8, characterized in that: The device information includes user operation status; When the device information changes, detecting the first memory occupied by the first process includes: When the user operation state is a no-operation state, the first memory occupied by the first process is detected.

10. The method according to any one of claims 1 to 9, characterized in that The first threshold is the rated memory of the first process.

11. The method according to any one of claims 1 to 10, characterized in that The processing of the first process includes: When the second memory is greater than the first threshold, performing memory detection on the first process at a preset time interval; When the number of times the memory detection is performed on the first process is greater than a second threshold, the memory occupied by the first process is reported.

12. The method according to any one of claims 1 to 11, characterized in that The processing of the first process includes: When the second memory is greater than the first threshold, the first process is checked and killed.

13. An electronic device, characterized in that: The electronic device comprises: a detection module and a processing module, wherein: The detection module is used to detect a first memory occupied by a first process, where the first memory is an actually used physical memory RSS; The detection module is used for detecting the second memory occupied by the first process when the first memory is greater than a first threshold, where the second memory is a proportionally allocated actually used physical memory PSS; The processing module is used to process the first process when the second memory is greater than the first threshold.

14. The electronic device according to claim 13, characterized in that: Also includes: An execution module, wherein the execution module is used to: When the first memory is less than or equal to the first threshold, skip executing the detection operation of whether the second memory is greater than the first threshold.

15. The electronic device according to claim 13 or 14, characterized in that: The detection module is used for: When the second memory is less than or equal to the first threshold, the detection operation is terminated.

16. The electronic device according to any one of claims 13 to 15, characterized in that: Also includes: Determine the module, where The determining module is used to determine device information of the electronic device and feature information of the first process, wherein the device information is used to characterize the state of the electronic device, and the feature information is used to characterize the state of the first process; The detection module is used to detect the first memory occupied by the first process when the device information or the characteristic information changes.

17. The electronic device according to claim 16, characterized in that: The device information includes at least one of the following: system status, user operation status; the feature information includes at least one of the following: process status and foreground and background status.

18. The electronic device according to claim 17, characterized in that: The characteristic information includes a process state; and the detection module is used to: When the process state is in a non-suspended state, the first memory occupied by the first process is detected.

19. The electronic device according to claim 17 or 18, characterized in that: The characteristic information includes foreground and background states; the detection module is used to: When the foreground and background states are background states, the first memory occupied by the first process is detected.

20. The electronic device according to any one of claims 17 to 19, characterized in that: The device information includes system status; the detection module is used to: When the system state is a non-idle state, the first memory occupied by the first process is detected.

21. The electronic device according to any one of claims 17 to 20, characterized in that: The device information includes the user operation status; the detection module is used to: When the user operation state is a no-operation state, the first memory occupied by the first process is detected.

22. The electronic device according to any one of claims 13 to 21, characterized in that: The first threshold is the rated memory of the first process.

23. The electronic device according to any one of claims 13 to 22, characterized in that: The processing module is used for: When the second memory is greater than the first threshold, performing memory detection on the first process at a preset time interval; When the number of times the memory detection is performed on the first process is greater than a second threshold, the memory occupied by the first process is reported.

24. The electronic device according to any one of claims 13 to 23, characterized in that: The processing module is used for: When the second memory is greater than the first threshold, the first process is checked and killed.

25. An electronic device, characterized in that: The electronic device comprises: one or more processors; and a memory, wherein codes are stored in the memory; when the codes are executed by the processor, the electronic device executes the method according to any one of claims 1 to 12.

26. A computer-readable storage medium, characterized in that: The method comprises computer instructions, which, when executed on an electronic device, cause the electronic device to execute the method according to any one of claims 1 to 12.

Citation Information

Patent Citations

  • Memory detection method and electronic equipment

    CN119621445A

  • Method and device for monitoring leakage of memory

    CN104182320A

  • Memory management method and device

    CN109558297A

  • Process management method, electronic equipment, process management system and storage medium

    CN115220881A

  • Precisely tracking memory usage in multi-process computing environment

    US20150363113A1