Memory detection method and electronic equipment

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

CN119621445APending Publication Date: 2025-03-14HUAWEI TECH CO LTD

Patent Information

Application Number
CN202311190275.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-14
Publication Date
2025-03-14

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

A memory detection method is adopted to first detect the actual physical memory (RSS) occupied by the process. If the threshold is exceeded, further detect the proportional allocation of actual physical memory (PSS) to achieve accurate memory detection and reduce detection time.

Benefits of technology

Through this method, electronic devices can quickly and accurately detect memory occupied by processes, reduce detection time and improve memory detection accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119621445A_ABST
    Figure CN119621445A_ABST
Patent Text Reader

Abstract

The invention discloses a memory detection method and electronic equipment. The method can comprise the steps that the electronic equipment detects a first memory occupied by a first process, wherein the first memory is an actually-used physical memory RSS; when the first memory is larger than the first threshold value, the electronic device detects a second memory occupied by the first process, and the second memory is a proportionally allocated actually used physical memory PSS. And when the second memory is greater than the first threshold value, the electronic equipment performs memory detection on the first process according to preset time. Thus, the electronic equipment detects the RSS occupied by the first process firstly, and if the RSS occupied by the first process exceeds the rated memory (namely the first threshold), the electronic equipment detects the PSS occupied by the first process. As the range of the RSS is larger than that of the PSS, the electronic equipment filters out most of the processes by detecting the RSS occupied by the first process, and then accurately locates the process with excessive memory by detecting the PSS occupied by the first process, so that the accuracy of memory detection is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] More and more applications (referred to as applications) are installed on electronic devices. When an application, i.e., a process corresponding to the application, is running in the operating system of an electronic device, the process will occupy the resources of the electronic device. However, the operating system of the electronic device has limited resources such as memory, central processing unit (CPU), input / output (IO), etc. Therefore, if the resource usage of the application in the background is not controlled, the resources required by the application in the foreground cannot be guaranteed.

[0003] At present, the measurement indicators of memory resources 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 shared libraries in proportion. During the memory detection process, the operating system of the electronic device sets quotas for memory, IO, etc. for each process in order to prevent applications from abusing resources in the background. For example, the memory quota is that the memory occupied by the front and back applications is at most about 50% of the memory of the electronic device. Afterwards, the electronic device detects the PSS occupied by each process. However, it takes a long time to detect the PSS occupied by each process. 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 memory of the shared library to the application, it will cause inaccurate memory detection. Summary of the invention

[0004] The memory detection method and electronic device provided in the present application realize accurate memory detection with low time consumption.

[0005] In order to achieve the above-mentioned purpose, this application adopts the following technical solution.

[0006] In a 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 used. 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 used. When the second memory is greater than the first threshold, processing the first process.

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

[0008] In one example, the first threshold may refer to the upper limit memory that the first process can use, 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.

[0009] 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 range of RSS is larger than that of PSS, the electronic device filters out most of the 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.

[0010] In some technical solutions, the memory detection method provided by the present 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, since the RSS 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.

[0011] 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.

[0012] In some technical schemes, before detecting the first memory occupied by the first process, the memory detection method provided in the present application also includes: determining device information of the electronic device and 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 the characteristic information changes, detecting the first memory occupied by the first process.

[0013] 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.

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

[0015] In a 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.

[0016] In a 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 may specifically be: when the system status is a non-idle state, the first memory occupied by the first process is detected.

[0017] In a 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, which can be specifically: when the user operation status is a no-operation status, the first memory occupied by the first process is detected.

[0018] 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 in combination with the state of the electronic device. That is, the electronic device comprehensively considers various user scenarios, and achieves accurate detection of the memory of the process and reduces the time consumption of detection on the basis of ensuring the minimum impact on the foreground.

[0019] In one example, according to the degree of influence of each electronic device on the foreground, the electronic device can configure the 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 influence on the foreground, so the electronic device can first judge the process status. Secondly, the foreground and background status may have a greater influence on the foreground, so the electronic device can secondly judge the foreground and background status. Thirdly, the system status may have a slightly smaller influence on the foreground, so the electronic device can judge the system status again. Finally, the user operation may have the least influence on the foreground, so the electronic device can secondly judge the user operation. Of course, this example only provides a feasible solution, and the embodiments of the present application are not limited to this.

[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 in combination with the state of the electronic device and the degree of influence of each state on the foreground. That is, the electronic device comprehensively considers various user scenarios and the degree of influence of each state on the foreground, and realizes accurate detection of the memory of the process and reduces the time consumption of detection on the basis of ensuring the minimum influence on the foreground.

[0021] In a 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.

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

[0023] 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.

[0024] Among them, the electronic device checking and 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 embodiment of the present application, the processing of the first process by the electronic device is not limited to checking and killing the first process, and can also include adjusting the rated memory of the first process, etc. This is not specifically limited in the embodiment of the present application.

[0025] In a second 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 (e.g., a chip, a chip system, or a processor, etc.), and the following description is made by taking the execution subject being an electronic device as an example. The method may include: detecting a first memory occupied by a first process, the first memory being 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.

[0026] 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 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, and there is no need to detect the PSS occupied by the first process, which saves detection time and reduces the time consumption of electronic device memory detection.

[0027] In a third 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 by taking the execution subject being an electronic device as an example. The method may include: detecting a first memory occupied by a first process, the first memory being the actual physical memory RSS; the first memory being greater than a first threshold, detecting a second memory occupied by the first process, the second memory being the proportionally allocated actual physical memory PSS; when the second memory is less than or equal to the first threshold, terminating the detection operation.

[0028] 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 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.

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

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

[0031] In one example, the first threshold may refer to the upper limit memory that the first process can use, 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.

[0032] 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 range of RSS is larger than that of PSS, the electronic device filters out most of the 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.

[0033] In some technical solutions, the electronic device further includes: an execution module, and the execution module is used to: when the first memory is less than or equal to the first threshold, skip the detection operation of whether the second memory is greater than the first threshold. That is to say, since the RSS 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, which saves detection time and reduces the time consumption of memory detection of the electronic device. At the same time, accurate memory detection is achieved.

[0034] In a 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.

[0035] In some technical solutions, the electronic device further includes: a determination module, wherein the determination module is used to determine device information of the electronic device and 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. The detection module is used to detect the first memory occupied by the first process when the device information or the characteristic information changes.

[0036] 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.

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

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

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

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

[0041] 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 in combination with the state of the electronic device. That is, the electronic device comprehensively considers various user scenarios, and achieves accurate detection of the memory of the process and reduces the time consumption of detection on the basis of ensuring the minimum impact on the foreground.

[0042] In a technical solution, the first threshold is the rated memory of the first process.

[0043] In a 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.

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

[0045] Among them, the electronic device checking and 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 embodiment of the present application, the processing of the first process by the electronic device is not limited to checking and killing the first process, and can also include adjusting the rated memory of the first process, etc. This is not specifically limited in the embodiment of the present application.

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

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

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

[0049] Figure 1 It is a schematic diagram of the time consumption in a memory detection process;

[0050] Figure 2 It is another schematic diagram of the time consumption in the memory detection process;

[0051] Figure 3 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0052] Figure 4 Another structural schematic diagram of an electronic device provided in an embodiment of the present application;

[0053] Figure 5 A schematic diagram of a flow chart of a memory detection method provided in an embodiment of the present application;

[0054] Figure 6 Another schematic diagram of a flow chart of a memory detection method provided in an embodiment of the present application;

[0055] Figure 7 Another schematic diagram of a flow chart of a memory detection method provided in an embodiment of the present application;

[0056] Figure 8 A schematic diagram of another flow chart of the memory detection method provided in the embodiment of the present application;

[0057] Fig. 9 A schematic diagram of another flow chart of the memory detection method provided in the embodiment of the present application;

[0058] Fig.10 Another schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0059] 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. Among them, 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, which 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. And, 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 its similar expressions refers to any combination of these items, including any combination of single items 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, the words "first", "second" and the like are used to distinguish the same items or similar items with substantially the same functions and effects. Those skilled in the art will understand that the words "first", "second" and the like do not limit the quantity and execution order, and the words "first", "second" and the like do not necessarily limit the differences. At the same time, in the embodiments of the present application, the words "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 solutions. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a concrete manner for ease of understanding.

[0060] The measurement indicators of the memory resources of electronic devices 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, such as Figure 1 As shown, it takes about 129ms for the electronic device to detect the PSS occupied by 479 processes.

[0061] In order to solve the time-consuming problem, the electronic device detects the RSS occupied by each process. Figure 2As shown, it takes about 18ms for the electronic device to detect the RSS occupied by 479 processes, which significantly reduces the time consumption. However, in the process of detecting the RSS occupied by each process, the electronic device will count all the memory of the shared library to each process. For example, the electronic device configures a rated memory of 2048M for each application, and accordingly, the memory that can be used by the process corresponding to each application is 2048M. The private memory occupied by process A is 2050M, the private memory occupied by process B is 50M, and the public memory occupied by process A and process B is 8M. Then, when the electronic device detects the RSS occupied by each process, the electronic device determines that the RSS occupied by process A is 2050M+8M=2058M, and the memory occupied by process B is 50M+8M=58M. Therefore, since the electronic device will count all the memory of the shared library to each process in the process of detecting the RSS occupied by each process, it will cause inaccurate memory detection.

[0062] In order to solve the above technical problems, an embodiment of the present application provides a memory detection method, which is applied to an electronic device, and a first application is installed on the electronic device. The first application is running, that is, a first process, and the first process may include one or more processes. The method may include: the electronic device detects the first memory occupied by the first process, and the first memory is the actual use of physical memory RSS. When the first memory is greater than the first threshold, the electronic device detects the second memory occupied by the first process, and the second memory is the proportional allocation of the actual use of physical memory PSS. When the second memory is greater than the first threshold, the electronic device performs memory detection on the first process according to the 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 is larger than the PSS range, the electronic device filters out most of the processes by detecting the RSS occupied by the first process, and then accurately locates the process of excess memory by detecting the PSS occupied by the first process, thereby improving the accuracy of memory detection.

[0063] In some embodiments, the method may further include: when the first memory is less than or equal to the first threshold, the electronic device skips the detection operation of whether the second memory is greater than the first threshold. That is, since the RSS 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, which saves detection time and reduces the time consumption of memory detection of the electronic device. At the same time, accurate memory detection is achieved.

[0064] Using the above example, the rated memory configured by the electronic device for each application is 2048M, that is, the upper limit memory that the process corresponding to the application can use is 2048M. The private memory occupied by process A is 2050M, the private memory occupied by process B is 50M, and the public memory occupied by process A and process B is 8M. Then:

[0065] 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 of the processes by detecting the RSS occupied by process A, thereby improving the accuracy of memory detection.

[0066] 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. That is to say, 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 is larger than the PSS range, the electronic device filters out most of the processes by detecting the RSS occupied by process B. That is to say, 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.

[0067] 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.

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

[0069] Among them, the above-mentioned electronic device can be a mobile phone, a tablet computer, a laptop, a notebook computer, an ultra-mobile personal computer (UMPC), a handheld computer, a netbook, a personal digital assistant (PDA), a wearable electronic device and other devices. The specific form of the electronic device is not particularly limited in the embodiments of the present application.

[0070] Figure 3 It is a structural block diagram of the above electronic equipment.

[0071] like Figure 3 As shown, 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 screen 270, and a sensor module 250, etc. The sensor module 250 may include a pressure sensor 250A, a touch sensor 250B, etc.

[0072] It is to be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0073] 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 processor (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), etc. Different processing units may be independent devices or integrated into one or more processors.

[0074] 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.

[0075] The processor 210 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 210 is a cache memory. The memory may store instructions or data that the processor 210 has just used or cyclically used. If the processor 210 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 210, and thus improves the efficiency of the system.

[0076] 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.

[0077] The charging management module 240 is used to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 240 may receive charging input from a wired charger through the USB interface 230. In some wireless charging embodiments, the charging management module 240 may receive wireless charging input through a wireless charging coil of the electronic device. While the charging management module 240 is charging the battery 242, it may also power the electronic device through the power management module 241.

[0078] 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 supplies power to the processor 210, the internal memory 221, the display screen 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 number, battery health status (leakage, impedance), etc. 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.

[0079] 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.

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

[0081] The wireless communication module 260 can provide wireless communication solutions 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., which are applied to electronic devices. The wireless communication module 260 can be one or more devices integrating at least one communication processing module. The wireless communication module 260 receives electromagnetic waves via the antenna 1, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 210. The wireless communication module 260 can also receive the signal to be sent from the processor 210, modulate the frequency of the signal, amplify it, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, the wireless communication module 260 receives application messages sent by the server.

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

[0083] The display screen 270 is used to display images, videos, etc. The 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 or an active-matrix organic light emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device may include 1 or N display screens 270, where N is a positive integer greater than 1.

[0084] The memory 220 can be used to store computer executable program codes, which include 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.

[0085] The pressure sensor 250A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 250A can be set on the display screen 270. There are many types of pressure sensors 250A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 250A, the capacitance between the electrodes changes. The electronic device determines the intensity of the pressure based on the change in capacitance. When a touch operation acts on the display screen 270, the electronic device detects the touch operation intensity according to the pressure sensor 250A. The electronic device can also calculate the touch position according to the detection signal of the pressure sensor 250A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.

[0086] In one embodiment, the pressure sensor 250A can detect the user's operation such as clicking or sliding on the display screen 270 of the electronic device 100, and obtain the operation information. The pressure sensor 250A sends the operation information to the processor 210. The processor 210 can determine that there is a user operation based on the operation information. At this time, the processor 210 may not detect the memory occupied by the first process. The processor 210 can determine that there is no user operation based on the operation information. At this time, the processor 210 can detect the memory occupied by the first process.

[0087] The touch sensor 250B is also called a "touch control device". The touch sensor 250B can be set on the display screen 270, and the touch sensor 250B and the display screen 270 form a touch screen, also called a "touch control screen". The touch sensor 250B is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 270. In other embodiments, the touch sensor 250B can also be set on the surface of the electronic device, which is different from the position of the display screen 270.

[0088] In one embodiment, the touch sensor 250B can detect the user's operation such as clicking or sliding on the display screen 270 of the electronic device 100, and obtain the operation information. The touch sensor 250B sends the operation information to the processor 210. The processor 210 can determine that there is a user operation based on the operation information. At this time, the processor 210 may not detect the memory occupied by the first process. The processor 210 can determine that there is no user operation based on the operation information. At this time, the processor 210 can detect the memory occupied by the first process.

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

[0090] Figure 4 It is another structural block diagram of the above electronic device.

[0091] like Figure 4 As shown, the electronic device 100 may include a quota management module, an identification module, a detection module, and an execution module. Exemplarily, the quota management module, the identification module, the detection module, and the execution module may be deployed in Figure 3On the processor 210 shown in . Among them, 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 state of the electronic device, for example, the state of each process on the electronic device, the background / foreground state of each process, the state of the operating system of the electronic device, and the user's interface operation 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, the PSS occupied by the process is detected. The detection module is specifically used to determine whether to detect the RSS occupied by each process according to the state of the electronic device identified by the identification module (such as the device information of the electronic device and the characteristic information of the first process). The execution module is used to perform a check and kill operation on each process according to the detection result of the detection module. In some examples, the execution module can also be used to add a memory quota when the RSS occupied by the process exceeds the rated memory. Among them, 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 according to 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 the process when the RSS occupied by each process exceeds the rated memory.

[0092] In one example, if Figure 4 As shown, the workflow of the electronic device 100 is as follows: Step ① 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 the rated memory for the application. When the application is running, the upper limit memory that the process corresponding to the application can use is the rated memory. Step ② The identification module of the electronic device identifies the state of the electronic device (such as the device information of the electronic device and the characteristic information of the first process). Step ③ The decision module of the electronic device determines whether the state of the electronic device has changed according to the state of the electronic device identified by the identification module. Step ④ When the state 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 ⑤ 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 killing 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.

[0093] 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, the electronic device then detects the PSS occupied by the first process. Since the range of RSS is larger than that of PSS, the electronic device filters out most of the 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.

[0094] Figure 5 A flowchart of a memory detection method provided in an embodiment of the present application is shown as follows: Figure 5 As shown, the method is applied to an electronic device, and the first application is installed on the electronic device. The method may include S501-S504 (some of which are optional). For details of S501-S504, please refer to the description of the following embodiment. Specifically, it may be:

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

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

[0097] That is, after the electronic device is started, multiple applications can be run on the electronic device, and each application corresponds to a process. These processes will occupy the resources of the electronic device, such as memory. In order to prevent these processes from abusing the resources of the electronic device, the electronic device can pre-configure rated memory for the applications corresponding to these processes.

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

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

[0100] In a specific implementation manner, 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 at 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., which 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 as follows Figure 4 In step ① shown, the quota management module of the electronic device sends the rated memory of each process to the detection module of the electronic device.

[0101] In another specific implementation, S501 can be specifically implemented as follows: after the electronic device is started, the electronic device sends a request to the server for obtaining the rated memory of each process. Accordingly, the server receives the request and obtains the rated memory of each process according to the request. Afterwards, the server sends the rated memory of each process to the electronic device. Specifically, the electronic device can send a request to the server for obtaining the rated memory of each process in real time. Alternatively, the electronic device can send a request to the server for obtaining the rated memory of each process according to a second preset time interval. The second preset time interval can be set according to actual conditions, such as 1 hour or 1 day, etc., which is not specifically limited in the embodiment of the present application. Alternatively, in response to a user operation, the electronic device sends a request to the server for obtaining the rated memory of each process. Among them, the user operation may include an operation in which the user clicks the power button of the electronic device. Alternatively, the user clicks the screen-off operation, etc., which is not specifically limited in the embodiment of the present application. In an example, S501 can be specifically implemented as follows: after the electronic device is started, the quota management module of the electronic device sends a request to the server for obtaining the rated memory of each process. Accordingly, the server receives the request and obtains the rated memory of each process according to the request. Afterwards, the server sends the rated memory of each process to the quota management module of the electronic device. Figure 4 In step ① shown, the quota management module of the electronic device sends the rated memory of each process to the detection module of the electronic device.

[0102] 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 explanation. 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:

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

[0104] 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.

[0105] In a specific implementation manner, the specific implementation of S5021 can be referred to as Figure 4 The RSS detection unit shown is used to detect whether the RSS occupied by the first process at a 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 the following Figure 4 Step ④ shown.

[0106] Using the above example, the rated memory configured by the electronic device for each application is 2048M, and the memory available to each application for the process is 2048M. The private memory occupied by process A is 2050M, the private memory occupied by process B is 50M, and the public memory occupied by process A and process B is 8M. Then:

[0107] 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.

[0108] Example 2, assuming that 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 2048M. At this time, the electronic device performs the end detection operation.

[0109] In this way, electronic devices can filter out nearly 99% of processes by detecting the RSS occupied by the processes. Only the remaining 1% of processes need to be tested for PSS, which greatly reduces power consumption. In actual applications, the time it takes for electronic devices to detect the memory resources occupied by 479 processes can be optimized from 129ms to 2ms, reducing the overhead by nearly 98.4%, significantly reducing time consumption, and at the same time, achieving accurate memory detection.

[0110] Of course, the above examples are only used to explain 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.

[0111] In the embodiment of the present application, since the range of RSS is larger than that of 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, thereby 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.

[0112] 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.

[0113] In a specific implementation manner, the specific implementation of S5022 can be referred to as Figure 4 The PSS detection unit shown 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 the following Figure 4 Step ⑤ shown in the figure, or the electronic device performs the following steps: Figure 4 Steps ⑥ and ⑤ are shown.

[0114] Using the above example 1, the electronic device further detects the PSS occupied by the first process, and the electronic device 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 time, the electronic device determines that the memory occupied by the first process exceeds the rated memory.

[0115] In the embodiment of the present 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, the electronic device then detects the PSS occupied by the first process. Since the RSS has a larger range than the PSS, the electronic device filters out most of the 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, which saves detection time and improves the accuracy of memory detection.

[0116] 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 as follows:

[0117] S503, the electronic device detects and kills the first process.

[0118] Among them, the electronic device checking and killing the first process can be understood as the electronic device closing the first process. That is, the electronic device does not run the first process. Of course, in the embodiment of the present application, the processing of the first process by the electronic device is not limited to checking and killing the first process, and can also include adjusting the rated memory of the first process, etc. This is not specifically limited in the embodiment of the present application. In the embodiment of the present application, the electronic device checking and killing the first process is taken as an example for explanation.

[0119] In a specific implementation, Figure 5 As shown, 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. That is, the electronic device can directly kill the first process based on the detection result that the memory occupied by the first process exceeds the rated memory. Figure 4 Step ⑤ shown will not be repeated here.

[0120] In another specific implementation, Figure 6 As shown, 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 at a third preset time interval. The third preset time interval can be set according to actual conditions, for example, the third preset time interval is 1 hour or 1 day, which is not specifically limited in the embodiment of the present application. In addition, S5032, the electronic device reports the memory occupied by the first process at each moment to the server. S5033, the server determines that the number of times the memory occupied by the first process exceeds the rated memory exceeds the threshold value based on the memory occupied by the first process at each moment. The threshold value can be 3 times or 6 times, which is not specifically limited in the present application. Exemplarily, 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 that the number of times the memory occupied by the first process exceeds the rated memory in a continuous time exceeds the threshold value based on the memory occupied by the first process at each moment. Exemplarily, the memory occupied by the first process exceeds the rated memory three times in a row within 4 consecutive hours. At this time, S5034, the server can instruct the electronic device to kill the first process. S5035, the electronic device kills the first process according to the instruction of the server. Specifically, the specific implementation of S503 can be found in Figure 4 Steps ⑥ and ⑤ shown are not repeated here.

[0121] In another specific implementation, Figure 7As shown, 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 at 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, 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. Alternatively, the electronic device 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 in a continuous time exceeds a threshold. Specifically, for the specific implementation of S5036, please refer to the relevant description in the above S5033 and 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 the following. Figure 4 Steps ⑥ and ⑤ shown are not repeated here.

[0122] 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.

[0123] 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 electronic device in the foreground or background (referred to as the foreground and background state), the state of the operating system of the electronic device (referred to as the system state), and user operation. 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.).

[0124] In one example, the process state is suspended, which can be understood as: a suspended process can be defined as a process temporarily eliminated from memory in the operating system. On the contrary, the process state is not suspended, which can be understood as: a not suspended process can be defined as a process temporarily not eliminated from memory in the operating system.

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

[0126] In one example, the system state is an idle state, which can be understood as: the operating system of the electronic device is powered on but not working. On the contrary, the system state is a non-idle state, which can be understood as: the operating system of the electronic device is powered on and working. Taking the electronic device as a mobile phone as an example, the mobile phone can determine the system state based on the code in the source code.

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

[0128] In one example, the 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 embodiment of the present application does not make specific limitations. On the contrary, the user operation is no operation, which can be understood as: the user does not perform a touch operation on the display screen of the electronic device.

[0129] In some examples, the difference between the second case and the first case is that, Figure 8 As shown, before executing S502, the electronic device further executes the following steps:

[0130] 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 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.

[0131] 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 above-mentioned electronic device. Of course, in the embodiment of the present application, the characteristic information is not limited to the above-mentioned information, 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 embodiment of the present application.

[0132] 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-listed information, and is not specifically limited in the embodiment of the present application.

[0133] In a specific implementation, S504 may be implemented as follows: the electronic device identifies the device information and feature information. Figure 4As shown, 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. 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 feature information. The embodiments of this application are not listed here one by one.

[0134] 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, which will not be repeated here.

[0135] 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.

[0136] In some examples, the feature 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.

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

[0138] 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.

[0139] Of course, the above examples can be combined arbitrarily, and the embodiments of the present application do not make specific limitations.

[0140] In a specific implementable manner, 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 ordering between these information can be arbitrary, and is not specifically limited in the embodiments of the present application. In the embodiments 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 the minimum impact on the foreground.

[0141] In another specific implementation, in order to achieve the best effect, the above device information and feature information can be judged in sequence. Fig. 9 As shown, S502 can be specifically implemented as follows: S5020, the electronic device determines whether the process state is a suspended state. If the electronic device determines that the process state is a suspended state, the electronic device executes not to detect the memory occupied by the first process. If the electronic device determines that the process state is not suspended, the electronic device executes 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 executes not to detect the memory occupied by the first process. If the electronic device determines that the first process is in the background state, the electronic device executes S5024. S5024, the electronic device determines whether the system state is an idle state. If the electronic device system state is an idle state, the electronic device executes not to detect the memory occupied by the first process. If the electronic device system state is a non-idle state, the electronic device executes S5025. S5025, the electronic device determines whether a user operation exists. If the electronic device determines that a user operation exists, the memory occupied by the first process is not detected. If the electronic device determines that there is no user operation, the electronic device executes S5021 and S5022.

[0142] In one example, according to the degree of influence of each electronic device on the foreground, the electronic device can configure the 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 influence on the foreground, so the electronic device can first judge the process status. Secondly, the foreground and background status may have a greater influence on the foreground, so the electronic device can secondly judge the foreground and background status. Thirdly, the system status may have a slightly smaller influence on the foreground, so the electronic device can judge the system status again. Finally, the user operation may have the least influence on the foreground, so the electronic device can secondly judge the user operation. Of course, this example only provides a feasible solution, and the embodiments of the present application are not limited to this.

[0143] 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 in combination with the state of the electronic device and the degree of influence of each state on the foreground. That is, the electronic device comprehensively considers various user scenarios and the degree of influence of each state on the foreground, and realizes accurate detection of the memory of the process and reduces the time consumption of detection on the basis of ensuring the minimum influence on the foreground.

[0144] 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 to each other. The technical features in different embodiments can be combined to form new embodiments according to their internal logical relationships.

[0145] 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. Fig.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,

[0146] The detection module 1010 is used to detect the first memory occupied by the first process, where the first memory is the actual physical memory RSS. Exemplarily, the detection module 1010 can execute the above step S502, and specifically, the detection module 1010 can execute the above step S5021. The detection module 1010 can be Figure 3 The processor 210 shown in FIG. 1 , specifically, the detection module 1010 may be Figure 4 The detection RSS unit shown in FIG.

[0147] The detection module 1010 is used to detect the second memory occupied by the first process when the first memory is greater than the first threshold, where the second memory is the physical memory PSS actually used for the proportional allocation. Exemplarily, the detection module 1010 can execute the above step S502, and specifically, the detection module 1010 can execute the above step S5022. The detection module 1010 can be Figure 3 The processor 210 shown in FIG. 1 , specifically, the detection module 1010 may be Figure 4 The detection PSS unit shown in FIG.

[0148] The processing module 1020 is used to process the first process when the second memory is greater than the first threshold. Exemplarily, the processing module 1020 may execute the above step S503. The processing module 1020 may be Figure 3 The processor 210 shown in .

[0149] In some embodiments, the electronic device 1000 further includes: an execution module 1030, the execution module 1030 is used to: when the first memory is less than or equal to the first threshold, skip the detection operation of whether the second memory is greater than the first threshold. Exemplarily, the execution module 1030 can execute the above step S503. The execution module 1030 can be Figure 3 The processor 210 shown in FIG. 1 , specifically, the execution module 1030 may be Figure 4 The execution module shown in .

[0150] In one embodiment, the detection module 1010 is used to: end the detection operation when the second memory is less than or equal to a first threshold.

[0151] In some embodiments, the electronic device 1000 further includes: a determination module 1040, wherein the determination module 1040 is used to determine device information of the electronic device and 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. The detection module is used to detect the first memory occupied by the first process when the device information or characteristic information changes. Exemplarily, the determination module 1040 can execute the above step S504. The determination module 1040 can be Figure 3 The processor 210 shown in FIG. 1 , specifically, the determination module 1040 may be Figure 4 The identification module shown in .

[0152] 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.

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

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

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

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

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

[0158] 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.

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

[0160] In the present 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. Since the range of RSS is larger than that of PSS, the electronic device filters out most of the 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.

[0161] 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.

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

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

[0164] 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.

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

[0166] 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 merely a description of the association relationship of associated objects, indicating that three relationships may exist. 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 "plurality" means two or more. The words "first", "second", etc. do not limit the quantity and execution order, and the words "first", "second", etc. do not limit them to be different.

[0167] In the description of the present 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 the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0168] 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.

[0169] In the several embodiments provided in the present 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 only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another 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.

[0170] The units described as separate components may or may not be physically separated, 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 different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0171] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0172] 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, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0173] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope 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 for: 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 management method and device

    CN109558297A

  • Memory fault detection method and device

    CN114416411A

Cited By

  • Memory testing method and electronic device

    EP4697175A1

  • Memory testing method and electronic device

    WO2025055395A1