Memory recovery control method, electronic equipment and readable storage medium

By adjusting the memory threshold in electronic devices and skipping unnecessary memory recovery operations, the problem of CPU resource waste caused by frequent memory recovery is solved, the device operation efficiency is improved and the conflict between memory recovery and kernel ZRAM is avoided.

CN119201415APending Publication Date: 2024-12-27HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310757763.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-25
Publication Date
2024-12-27

AI Technical Summary

Technical Problem

Frequent memory recovery operations lead to wasting CPU resources of electronic devices, affecting the operation efficiency of equipment.

Method used

By adjusting the memory threshold and skipping some memory recovery operations after the memory usage of the target application reaches a certain threshold, unnecessary CPU resource usage is reduced and memory recovery is performed when appropriate to avoid frequent triggers.

Benefits of technology

It reduces the number of executions of memory recovery operations, reduces the waste of CPU resources, improves device operation efficiency and avoids the conflict between memory recovery and kernel ZRAM.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201415A_ABST
    Figure CN119201415A_ABST
Patent Text Reader

Abstract

The invention discloses a memory recovery control method, electronic equipment and a readable storage medium, and belongs to the technical field of terminals. The method is applied to the electronic equipment and comprises the steps that under the condition that the size of a memory occupied by a target application program reaches a first memory threshold value, a GC for the target application program is triggered; after the GC is triggered, determining an increment of compressed data in a target memory allocated for the target application program to obtain a first conversion reserve; under the condition that the first transfer capacity is larger than a first threshold value, a memory threshold value corresponding to the target application program is adjusted on the basis of the first transfer capacity, a second memory threshold value is obtained, GC operation of this time is skipped, and the second memory threshold value is a memory threshold value for triggering GC next time; and under the condition that the first conversion capacity is smaller than the first threshold value, GC operation is carried out. According to the method and the device, the GC operation is not necessarily executed after the GC is triggered, so that the execution frequency of the GC operation is reduced, and the situation that a large number of CPU resources are wasted is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of terminal technology, and in particular to a memory recycling control method, an electronic device and a readable storage medium. Background Art

[0002] With the development of terminal technology, more and more applications are installed in electronic devices, and each application will occupy a certain amount of memory. Since the size of the memory affects the smoothness of the operation of electronic devices, in order to improve the situation of freezing during the use of electronic devices, memory recycling (Garbage Collection, GC) can usually be performed to clean up the memory space. Among them, GC refers to an automatic memory management mechanism. When a part of the memory space occupied by an application is no longer accessed by the application, the application will return this part of the memory space to the operating system with the help of the garbage collection algorithm, thereby achieving the purpose of memory space cleaning.

[0003] Currently, when the size of the memory occupied by any application reaches a preset memory threshold, GC will be triggered, so that the electronic device can perform GC operations.

[0004] However, since the electronic device will occupy a large amount of central processing unit (CPU) resources during the GC operation, if the GC operation is performed frequently, a large amount of CPU resources will be wasted. Summary of the invention

[0005] The present application provides a memory recycling control method, an electronic device and a readable storage medium, which can be used to solve the problem of frequent GC leading to waste of CPU resources in related technologies. The technical solution is as follows:

[0006] In a first aspect, a memory recycling control method is provided, which is applied to an electronic device, and the method includes:

[0007] When the size of the memory occupied by the target application reaches a first memory threshold, triggering memory recycling GC for the target application;

[0008] After the GC is triggered, determining the increment of compressed data in the target memory allocated for the target application to obtain a first dump volume, wherein the target memory increases the usage space of the target memory by a first value after the compressed data is compressed in the target memory;

[0009] When the first dump volume is greater than a first threshold, adjusting the memory threshold corresponding to the target application based on the first dump volume to obtain a second memory threshold, and skipping the current GC operation, where the second memory threshold is the memory threshold for triggering the GC next time;

[0010] When the first dump volume is less than the first threshold, the GC operation is performed.

[0011] In this way, since the GC operation is not necessarily executed after the GC is triggered, the number of executions of the GC operation is reduced, and the situation of a large amount of CPU resource waste is reduced. In addition, since the memory threshold of the target application can be readjusted when the GC is triggered but the GC operation is not executed, the GC of the target application is avoided from being frequently triggered, thereby avoiding the occupation of a large amount of CPU resources.

[0012] As an example of the present application, when the first dump volume is greater than a first threshold, adjusting the memory threshold corresponding to the target application based on the first dump volume to obtain a second memory threshold includes:

[0013] In a case where the first dump volume is greater than the first threshold, determining a compression volume of the compressed data corresponding to the first dump volume after being compressed;

[0014] Subtract the compression amount from the first dump amount to obtain a second value;

[0015] Adding the second value to the first memory threshold to obtain a third value;

[0016] Based on the third value, the second memory threshold is determined.

[0017] In this way, by subtracting the compression amount from the first dump amount, the size of the usable space saved after the compressed data corresponding to the first dump amount in the target memory is compressed can be accurately determined, thereby improving the accuracy of determining the second memory threshold. Moreover, since the threshold of the target memory is adjusted, the number of GC triggering times is reduced.

[0018] As an example of the present application, determining the second memory threshold based on the third value includes:

[0019] When the third value is less than or equal to the second threshold, determining the third value as the second memory threshold;

[0020] When the third value is greater than the second threshold, the second threshold is determined as the second memory threshold.

[0021] In this way, by comparing the third value with the second threshold, it is possible to avoid the situation where the second memory threshold is set unreasonably.

[0022] As an example of the present application, after the GC is triggered, determining the increment of compressed data in the target memory allocated for the target application to obtain a first dump volume includes:

[0023] When the GC is triggered, obtaining the running state of the target application, wherein the running state includes a foreground running state or a background running state;

[0024] When the target application is in the background running state, determining the trigger type of the GC;

[0025] When the trigger type is a preset type, the first dump amount is determined.

[0026] In this way, by determining the running state of the target application and the trigger type of the GC, it is possible to accurately determine whether it is necessary to continue the operation of adjusting the memory threshold of the target application, thereby improving the running efficiency of the electronic device.

[0027] As an example of the present application, the electronic device includes a scene recognition module and a dump information reading module;

[0028] When the GC is triggered, obtaining the running status of the target application includes:

[0029] When the GC is triggered, the scene recognition module determines the running state of the target application from a state transition message sent by the target application, wherein the state transition message is a message sent to the scene recognition module when the target application switches between the foreground and the background;

[0030] When the trigger type is a preset type, determining the first dump amount includes:

[0031] In the case where the trigger type is the preset type, the scene recognition module sends a data acquisition message to the dump information reading module;

[0032] The dump information reading module determines the first dump volume when receiving the data acquisition message.

[0033] In this way, the first dump volume is determined by the dump information reading module, so that the determination of the first dump volume is more accurate.

[0034] As an example of the present application, when the trigger type is a preset type, determining the first dump amount includes:

[0035] When the trigger type is the preset type, obtaining a second dump volume, where the second dump volume is the total amount of all compressed data in the target memory when the current GC is triggered;

[0036] In a case where the first memory threshold is a preset memory threshold, determining the second dump amount to be the first dump amount;

[0037] When the first memory threshold is not the preset memory threshold, the first dump volume is obtained by subtracting the third dump volume from the second dump volume, and the third dump volume is the total amount of all compressed data in the target memory when the last GC is triggered.

[0038] In this way, by comparing the first memory threshold with the preset memory threshold, the method for determining the first dump amount can be accurately selected, thereby improving the accuracy of determining the first dump amount.

[0039] As an example of the present application, when the trigger type is the preset type, obtaining the second dump volume includes:

[0040] In a case where the trigger type is the preset type, determining a first virtual address range corresponding to the target memory;

[0041] Reading status information of each virtual memory page corresponding to the first virtual address range;

[0042] Determine a second virtual address range of the virtual memory page including the compression indicator in the state information;

[0043] Determine the memory size corresponding to the second virtual address range to obtain the second dump volume.

[0044] In this way, by determining the status information of each virtual memory page in the target memory, it is possible to accurately find which data will be compressed, thereby improving the accuracy of determining the second dump volume.

[0045] As an example of the present application, the method further includes:

[0046] When the second dump volume is less than or equal to a third threshold, the GC operation is performed.

[0047] In this way, by determining whether the second dump volume is less than or equal to the third threshold, the speed of determining whether to perform the GC operation can be accelerated.

[0048] In a second aspect, an electronic device is provided, wherein the structure of the electronic device includes a processor and a memory, wherein the memory is used to store a program that supports the electronic device to execute the memory recycling control method provided in the first aspect, and to store data involved in implementing the memory recycling control method described in the first aspect. The processor is configured to execute the program stored in the memory. The electronic device may also include a communication bus, wherein the communication bus is used to establish a connection between the processor and the memory.

[0049] In a third aspect, a computer-readable storage medium is provided, wherein instructions are stored in the computer-readable storage medium, and when the computer-readable storage medium is executed on a computer, the computer executes the memory recycling control method described in the first aspect.

[0050] In a fourth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the memory recycling control method described in the first aspect.

[0051] The technical effects obtained by the above-mentioned second, third, fourth and fifth aspects are similar to the technical effects obtained by the corresponding technical means in the above-mentioned first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] Figure 1 It is a memory diagram of an application provided in an embodiment of the present application;

[0053] Figure 2 It is a schematic diagram of memory management provided by an embodiment of the present application;

[0054] Figure 3 It is a memory compression schematic diagram provided in an embodiment of the present application;

[0055] Figure 4 It is a schematic diagram of a software architecture of an electronic device provided in an embodiment of the present application;

[0056] Figure 5 This is a flow chart of a memory recycling control method provided by an embodiment of the present application;

[0057] Figure 6 is a schematic diagram of adjusting a memory threshold provided in an embodiment of the present application;

[0058] Figure 7 is a flow chart of another memory recycling control method provided by an embodiment of the present application;

[0059] Figure 8 is a flow chart of another memory recycling control method provided by an embodiment of the present application;

[0060] Fig. 9 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0061] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.

[0062] It should be understood that the "multiple" mentioned in this application refers to two or more. In the description of this application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in order to facilitate the clear description of the technical solution of this application, the words "first" and "second" are used to distinguish between the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the words "first" and "second" do not limit the quantity and execution order, and the words "first" and "second" do not limit them to be different.

[0063] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0064] In one application scenario, an electronic device is installed with applications written in Java. When these applications are running, in order to achieve compatibility on multiple platforms, the electronic device can usually create a corresponding virtual machine, and the application can run in the corresponding virtual machine, and the virtual machine can allocate a certain amount of memory to the application. Figure 1During the operation of the virtual machine, if the memory occupied by any application A reaches the preset memory threshold (usually also called the water mark), the virtual machine can trigger GC for application A and perform GC operations to reclaim the memory that is no longer used by application A so that this part of memory can be reused to improve the memory usage rate. The memory occupied by application A includes the memory used by application A (the size of this part of memory is called usedsize) and the reserved free memory (the size of this part of memory is called freesize).

[0065] However, whenever the memory occupied by application A reaches a preset memory threshold, the electronic device needs to perform a GC operation. If the GC operation is performed frequently, the CPU resources may be constantly occupied, resulting in a large amount of CPU resource waste.

[0066] In another possible scenario, see Figure 2 , the electronic device's management of the memory allocated to application A includes not only the virtual machine's GC, but also the kernel's ZRAM. Among them, GC is managed by object, and can be marked, recycled, and moved according to whether the object is in use; the kernel's ZRAM is managed by memory page, sorted by access order, and preferentially compresses cold pages in the memory, and then transfers the compressed cold pages to other storage spaces. That is, in order to save the usage space of the allocated memory by application A, the electronic device can compress the cold pages in the memory allocated by application A (virtual memory pages that are no longer used or are not frequently used in the memory) through a compression algorithm, and transfer the compressed cold pages to the ZRAM in the RAM. The compression of cold pages is to compress the memory data cached in the cold pages generated by application A during the running process. For example, see Figure 3 , compress the cold pages in the memory used by application A through the compression algorithm, and store the compressed data in the ZRAM, that is, compress the cold pages in the memory used by application A through the compression algorithm. Figure 3 The swap area (exchange area) is compressed. After the swap area is compressed, the actual usage space of the swap area by the application is as follows: Figure 3 shown.

[0067] After GC is triggered, the virtual machine will scan all objects in the memory allocated by application A. When scanning to the compressed area, the compressed area will be decompressed by ZRAM, and decompression takes time, resulting in the duration of GC being blocked by ZRAM decompression, which increases the duration of GC execution. In addition, after ZRAM decompresses the compressed area, GC no longer scans cold pages, and ZRAM will re-compress the cold pages in the memory of application A, which will also occupy a large amount of CPU resources and GPU resources. In this case, GC and ZRAM will both occupy CPU resources, and then occupy the CPU resources of the foreground application, making the CPU resource allocation unreasonable, causing the foreground application to freeze and drop frames.

[0068] In order to avoid wasting CPU resources, an embodiment of the present application provides a method for controlling memory recycling, in which, when the size of the memory occupied by the target application reaches a first memory threshold, the GC operation is not directly performed, but the increment of the compressed data in the target memory allocated to the target application is first determined. When the increment reaches the first threshold, the current GC operation is skipped, and the memory threshold for triggering the GC next time is determined; when the increment does not reach the first threshold, the current GC operation is performed. Since the GC operation is not necessarily performed after the GC is triggered, the number of executions of the GC operation is reduced, and the situation in which a large amount of CPU resources are wasted is reduced. In addition, since the memory threshold of the target application can be readjusted when the GC is triggered and the GC operation is not performed, frequent triggering of the GC of the target application is avoided, thereby avoiding the occupation of a large amount of CPU resources.

[0069] Next, the software system of the electronic device 100 will be described.

[0070] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software system of the electronic device 100.

[0071] Figure 4 1 is a block diagram of a software system of an electronic device 100 provided in an embodiment of the present application. Figure 4 The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the Android runtime (Android runtime) and the system layer, and the kernel layer.

[0072] The application layer can include a series of application packages. Figure 4 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.

[0073] The application framework layer provides application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions. Figure 4 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, etc. The window manager is used to manage window programs. The window manager can obtain the size of the display screen, determine whether there is a status bar, lock the screen, capture the screen, etc. The content provider is used to store and obtain data and make these data accessible to applications. These data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc. The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc. The view system can be used to build the display interface of the application, and the display interface can be composed of one or more views, for example, including a view for displaying a text message notification icon, including a view for displaying text, and including a view for displaying pictures. The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including connecting, hanging up, etc.). The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, etc. The notification manager enables the application to display notification information in the status bar, which can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of an icon or scroll bar text, such as a notification of an application running in the background. The notification manager can also be a notification that appears on the screen in the form of a dialog window, such as a text message in the status bar, a reminder sound, an electronic device vibrating, an indicator light flashing, etc.

[0074] As an example, the application framework layer may also include a scene recognition module, which is used to identify the current running state of the application, for example, identifying whether the application is in the background running state or the foreground running state; the scene recognition module may also identify the trigger type of GC for the application.

[0075] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system. The core library consists of two parts: one is the function that the Java language needs to call, and the other is the Android core library. The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0076] As an example, the virtual machine also includes a GC control module, which may include a dump information reading module, a GC operation module, and a threshold adjustment module. The GC operation module is used to perform GC operations. The dump information reading module is used to obtain the size of the compressed and dumped memory data in the memory allocated for the application. The threshold adjustment module is used to adjust the memory threshold that triggers GC for the application.

[0077] The system library can include multiple functional modules, such as: surface manager, media library, 3D graphics processing library (such as: OpenGL ES), 2D graphics engine (such as: SGL), etc. The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications. The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc. The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing, etc. The 2D graphics engine is a drawing engine for 2D drawing.

[0078] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.

[0079] The following is an illustrative description of the workflow of the software and hardware of the electronic device 100 in conjunction with capturing a photo scene.

[0080] When the touch sensor 180K receives a touch operation, the corresponding hardware interrupt is sent to the kernel layer. The kernel layer processes the touch operation into a raw input event (including touch coordinates, timestamp of the touch operation, and other information). The raw input event is stored in the kernel layer. The application framework layer obtains the raw input event from the kernel layer and identifies the control corresponding to the raw input event. For example, if the touch operation is a single-click operation and the control corresponding to the single-click operation is the control of the camera application icon, the camera application calls the interface of the application framework layer, starts the camera application, and then calls the kernel layer to start the camera driver to capture static images or videos through the camera 193.

[0081] Based on the execution subject provided in the above embodiment, the control method of memory recycling provided in the embodiment of the present application is introduced below. Figure 5 , Figure 5 The following is a flow chart of a control method for memory recycling according to an exemplary embodiment. As an example but not a limitation, the method is applied to an electronic device. Figure 4 Taking the interaction of multiple modules shown in the figure as an example, the method may include some or all of the following contents:

[0082] Step 501: When the GC of the target application is triggered, the scene recognition module determines the running state of the target application.

[0083] As can be seen from the above, the target application runs in a virtual machine, so the virtual machine can detect whether the memory occupied by the target application reaches the first memory threshold, and trigger GC for the target application when it is detected that the memory occupied by the target application reaches the first memory threshold.

[0084] It should be noted that the first memory threshold may be a threshold obtained by adjusting the memory threshold of the target application when the GC for the target application was triggered last time, or may be a default preset memory threshold.

[0085] As an example, triggering the GC operation for the target application may include calling a GC execution function. Exemplarily, the GC execution function may be CollectGarbageInternal().

[0086] Since GC is usually performed when the application is in the background running state, when GC is triggered, the scene recognition module can determine the running state of the target application. That is, the scene recognition module can determine whether the target application is in the background running state.

[0087] As an example, when the running state of the target application changes, a state transition message may be sent to the scene recognition module, and the state transition message carries a state identifier, which is used to indicate the running state of the target application. When the scene recognition module needs to determine the running state of the target application, the state identifier may be read to determine the current state of the target application.

[0088] It should be noted that the status identifier can be pre-set according to requirements, and the status identifier can be composed of at least one of numbers, letters, symbols, etc.

[0089] As an example, the scene recognition module may read the status flag through a reading function, and the reading function may be IsProcessOnTop().

[0090] In some embodiments, the scene recognition module may also determine the running state of the target application in other ways. For example, the scene recognition module may monitor the running thread of the target application in real time or at preset time intervals to determine the running state of the target application. The embodiments of the present application do not impose specific restrictions on this.

[0091] Step 502: When the scene recognition module recognizes that the target application is in the background running state, it determines the trigger type of GC.

[0092] Normally, GC triggering situations include the following three situations: the first situation is when the memory occupied by the target application reaches the set memory threshold; the second situation is when GC is performed on the target application on a scheduled basis; and the third situation is when the user manually triggers GC when the target memory of the target application needs to be cleaned up. Each of the different triggering situations is considered a trigger type. When the GC for the target application is triggered due to the memory threshold of the target application, consideration will be given to whether to adjust the memory threshold of the target application. When GC is triggered due to other reasons, it is usually not necessary to adjust the memory threshold of the target application. Therefore, in order to accurately determine whether to adjust the memory threshold of the target application, the scene recognition module can determine the trigger type of GC.

[0093] It should be noted that different trigger types have different type identifiers, so the scene recognition module can determine the trigger type of GC by obtaining the type identifier corresponding to this GC. The trigger type can be represented by at least one identifier among numbers, letters and symbols.

[0094] As an example, when the type identifier is a preset type identifier, the trigger type of GC can be determined to be a preset type. The preset type is used to indicate that GC for the target application is triggered when the memory occupied by the target application reaches a corresponding memory threshold.

[0095] In some embodiments, when the scene recognition module recognizes that the target application is in the foreground running state, the scene recognition module may send a running message to the GC running module, and when the GC running module receives the running message, the GC running module executes the GC operation.

[0096] Step 503: When the trigger type of the GC is a preset type, the scene recognition module sends a data acquisition message to the dump information reading module.

[0097] In some embodiments, when the trigger type of the GC is not a preset type, the scene recognition module can also send an operation message to the GC operation module.

[0098] Step 504: The dump information reading module receives the data acquisition message.

[0099] Step 505: The dump information reading module determines the increment of the compressed data in the target memory allocated for the target application program to obtain a first dump volume.

[0100] It should be noted that after the compressed data is compressed in the target memory, the target memory increases the usage space of the first value, and the target memory may also be called Java heap.

[0101] As can be seen from the above, in the process of memory management, the kernel's ZRAM can compress the cold pages in the target memory and dump them. The compressed data is the memory data cached in the cold pages. In this way, some space will be added to the target memory for the target application to use. If these spaces are large, the memory threshold of the target application can be appropriately adjusted. The size of these spaces can be reflected by the first dump volume, so the dump information reading module can obtain the first dump volume.

[0102] In addition, to avoid misunderstanding, it is explained here that compressed data does not refer to the compressed data cached in the cold page, but some data generated by the target application during its operation. The target application accesses these data less frequently. Therefore, during the memory management process, ZRAM compresses these data and dumps the compressed data into ZRAM. These data compressed by ZRAM are called compressed data.

[0103] In some embodiments, the dump information reading module can obtain a second dump volume, which is the total amount of all compressed data in the target memory when the current GC is triggered; when the first memory threshold is a preset memory threshold, the second dump volume is determined to be the first dump volume; when the first memory threshold is not the preset memory threshold, the second dump volume is subtracted from the third dump volume to obtain the first dump volume, and the third dump volume is the total amount of all compressed data in the target memory when the last GC was triggered.

[0104] It should be noted that the dump information reading module may obtain the second dump size through a data acquisition function, and the data acquisition function may be GetCurSwapSize().

[0105] Since the preset memory threshold is the default memory threshold corresponding to the target application, when the first memory threshold is the preset memory threshold, it means that this GC is the first GC triggered by the memory threshold corresponding to the target application, or, this GC is the first GC triggered by the memory threshold corresponding to the target application after clearing the previously cached GC data, and the first dump size is the increment of the compressed data size starting from 0. Therefore, the total amount of all compressed data in the target memory when the GC is triggered this time, that is, the second dump size, can be determined as the first dump size.

[0106] Furthermore, since the first memory threshold is not the preset memory threshold, it means that the first memory threshold is the memory threshold obtained by adjusting the memory threshold of the target application when the last GC was triggered, and the operation of the last GC was not executed, the amount of compressed data in the target memory may change during the time period between the last GC triggering and the triggering of this GC. Therefore, the first dump amount can be obtained by subtracting the third dump amount from the second dump amount.

[0107] As an example, the dump information reading module can determine the first virtual address range corresponding to the target memory; read the status information of each virtual memory page corresponding to the first virtual address range; determine the second virtual address range of the virtual memory page including the compression identifier in the status information; determine the corresponding memory size within the second virtual address range, and obtain the second dump volume.

[0108] Since the target memory is composed of an array of M consecutive bytes, each byte has a unique virtual address, so the dump information reading module can determine the first virtual address range corresponding to the target memory. In addition, the dump information reading module can obtain the first virtual address range corresponding to the target memory from the region space.

[0109] Since the target memory can be divided into several virtual memory pages, the virtual memory pages are used in different ways, and the corresponding status information is also different. For example, if virtual memory page A (or the memory data in virtual memory page A) is compressed, the status information of virtual memory page A includes information indicating that virtual memory page A is compressed.

[0110] It should be noted that the state information of the virtual memory page may include information indicating whether the corresponding virtual memory page is free, compressed (or dumped, swapped), or mapped (null PFN), etc.

[0111] Since each process has a Pagemap, which is an array composed of PageMapEntry (PME), each PME represents a page in the virtual memory of the process. PME contains the status information of the page. Pagemap is a pseudo file system that provides a method to access Pagemap information. Therefore, as an example, the dump information reading module can read the status information of each virtual memory page in the target memory through Pagemap. The Pagemap is a data structure in the Linux kernel that can be used to track the status information of the virtual memory pages of the process. The status information of each virtual memory page can be used to determine which virtual memory pages are compressed, and then the second dump volume can be determined based on the second virtual address range of the compressed virtual memory page.

[0112] As an example, the dump information reading module may use the pread64 interface to read memory data within the second virtual address range to determine the second dump volume.

[0113] In some embodiments, after acquiring the second dump volume, the dump information reading module may also compare the second dump volume with a third threshold value, and when the second dump volume is less than or equal to the third threshold value, send an operation message to the GC operation module so that the GC operation module performs GC operations. When the second dump volume is greater than the third threshold value, determine whether the first memory threshold value is a preset threshold value, and determine the first dump volume in the above manner.

[0114] It should be noted that the third threshold is a threshold set in advance according to demand. Exemplarily, the third threshold may be 50% or 60% of the memory used by the target application.

[0115] Step 506: When the first dump volume is greater than the first threshold, the dump information module sends an adjustment message to the threshold adjustment module.

[0116] When the first dump volume is greater than the first threshold, it indicates that there is still a large amount of space in the target memory for the target application to use and no GC operation is required. Therefore, the dump information module can send an adjustment message to the threshold adjustment module.

[0117] It should be noted that the first threshold is a threshold set in advance according to demand. Exemplarily, the first threshold may be 30%, 40% or 50% of the memory used by the target application.

[0118] Step 507: The threshold adjustment module receives the adjustment message.

[0119] Step 508: The threshold adjustment module adjusts the memory threshold corresponding to the target application based on the first dump volume to obtain a second memory threshold.

[0120] As an example, the threshold adjustment module can determine the compression amount of the compressed data corresponding to the first dump volume after being compressed; subtract the compression amount from the first dump volume to obtain a second value; add the second value to the first memory threshold to obtain a third value; and determine the second memory threshold based on the third value.

[0121] Since the first dump volume is the increment of the compressed data in the target memory, it is necessary to determine the size of the increased usable space of the increment after compression, that is, to obtain the second value by subtracting the compression amount from the first dump volume.

[0122] It should be noted that, when the first dump volume is the second dump volume, the second value is the first value, and when the first dump volume is not the second dump volume, the second value is not the first value.

[0123] Since the memory threshold is adjusted based on the memory threshold for triggering GC this time, the second value can be added to the first memory threshold to obtain a third value; and the second memory threshold is determined based on the third value.

[0124] As an example, the threshold adjustment module determines the operation of the second memory threshold based on the third numerical value, including: when the third numerical value is less than or equal to the second threshold, determining the third numerical value as the second memory threshold; when the third numerical value is greater than the second threshold, determining the second threshold as the second memory threshold.

[0125] Since the size of the target memory is limited, the memory threshold corresponding to the target application cannot exceed the size of the target memory. Therefore, a second threshold can be set. The second threshold is any value less than or equal to the size of the target memory, and the second threshold is greater than the preset memory threshold. When the third value is less than or equal to the second threshold, it means that the third value is less than or equal to the size of the target memory. Therefore, the third value can be determined as the second memory threshold. When the third value is greater than the second threshold, it means that the third value exceeds the size of the target memory. In this case, it is unreasonable to set the third value as the second threshold memory. Therefore, the second threshold can be determined as the second memory threshold.

[0126] For example, see Figure 6 , the memory data in the swap area in the target memory is compressed data, and the size of the compressed data in the swap area before compression is the first dump size. The threshold adjustment module can determine the compression amount of the compressed data in the swap area, and the compression amount is the size of the actual usage space of the target application in the swap area; the first dump size is subtracted from the compression amount to obtain a second value, and the second value is the adjustment value of the first memory threshold. The second value is added to the first memory threshold to obtain the second memory threshold.

[0127] Step 509: The threshold adjustment module sends a stop message to the GC operation module.

[0128] It should be noted that the stop message can be sent by the threshold adjustment module to the GC operation module when the second memory threshold is adjusted, or it can be sent by the dump information reading module to the GC operation module when the adjustment message is sent to the threshold adjustment module. The embodiment of the present application does not impose any specific restrictions on this.

[0129] Step 510: The GC operation module receives a stop message.

[0130] Step 511: The GC running module skips the current GC operation.

[0131] As an example, when the GC running module receives a stop message, it can not only skip the operation of this GC, but also cache the GC data of this time, where the GC data includes the memory threshold adjusted this time, that is, the second memory threshold, and the trigger type that triggers this GC, the first dump volume, the second dump volume and the size of the actual used memory, etc.

[0132] As an example, the GC running module may skip the current GC operation after caching the current GC data.

[0133] In some embodiments, the first dump volume may be greater than the first threshold value, or may be less than or equal to the first threshold value. When the first dump volume is less than or equal to the first threshold value, it indicates that the amount of compressed data is not large. After the memory threshold value of the target application is adjusted, the memory occupied by the target application will soon reach the adjusted memory threshold value. Therefore, when the first dump volume is less than or equal to the first threshold value, the dump information reading module may send an operation message to the GC operation module. Upon receiving the operation message, the GC operation module performs GC operations.

[0134] As an example, when the GC running module receives the running message, it can clear the cached GC data and then perform the GC operation.

[0135] In a possible example, after skipping this GC operation, the virtual machine may continue to detect the size of the memory occupied by the target application, and when the memory size reaches a second memory threshold, trigger GC for the target application, and return to the operation of step 501 above.

[0136] In another possible example, after executing this GC operation, the virtual machine can also continue to detect the memory size occupied by the target application, and when the memory size reaches a preset threshold, trigger GC for the target application and return to the operation of the above step 501.

[0137] In the embodiment of the present application, since the GC operation is not necessarily executed after the GC is triggered, the number of executions of the GC operation is reduced, and the situation of a large amount of CPU resource waste is reduced. In addition, since the memory threshold of the target application can be readjusted when the GC is triggered and the GC operation is not executed, the frequent triggering of the GC of the target application is avoided, thereby avoiding the occupation of a large amount of CPU resources. In addition, since the frequency of executing the GC operation is reduced, the conflict between the GC and the kernel's ZRAM is avoided, and the waste of CPU resources is further reduced.

[0138] Next, please refer to Figure 7 , Figure 7 This is a flow chart of a control method for memory recycling according to another exemplary embodiment. As an example but not a limitation, the method is applied to an electronic device as an example for illustration. The method may include some or all of the following contents:

[0139] Step 701: when it is detected that the GC for the target application is triggered, determine whether the target application is in the background running state, if so, execute the operation of the following step 702, if not, execute the operation of the following step 712.

[0140] As can be seen from the above, GC is usually performed when the application is in the background. Therefore, when GC for the target application is triggered, it can be determined whether the target application is in the background running state.

[0141] It should be noted that the operation of the electronic device determining whether the target application is in the background running state can refer to the operation of the scene recognition module determining the running state of the target application in the above step 501, and the embodiments of the present application will not be described in detail.

[0142] When the target application is not in the background running state, the target application may be in the foreground running state, or in the stopped running state, etc. If the GC for the target application is triggered in other running states, the electronic device can directly execute the GC operation, that is, the electronic device can directly execute the operation of the following step 712.

[0143] Step 702: Determine whether the trigger type of the GC is a preset type. If so, execute the operation of the following step 703; if not, execute the operation of the following step 711.

[0144] As can be seen from the above, the preset type is used to indicate that the GC for the target application is triggered when the memory occupied by the target application reaches the corresponding memory threshold. Therefore, when the trigger type of GC is the preset type, it will be considered whether to adjust the memory threshold of the target application, that is, the operation of step 703 can be continued. When the trigger type of GC is not the preset type, it means that there is no need to adjust the memory threshold of the target application. Therefore, in this case, the relevant operations of GC can be continued, that is, the operation of the following step 711 can be executed, or the operation of the following step 712 can be directly executed. The embodiment of the present application does not impose specific restrictions on this.

[0145] It should be noted that the operation of the electronic device determining whether the trigger type of the GC is a preset type can refer to the operation of the above step 502, and the embodiment of the present application will not elaborate on this one by one.

[0146] Step 703: Obtain the second dump volume and the size of the memory used by the target application.

[0147] When the type of GC triggering is the preset type, it means that this GC is triggered because the size of the memory occupied by the target application reaches the first memory threshold. Therefore, in order to determine whether the memory threshold of the target application needs to be adjusted, it is necessary to obtain the second dump amount.

[0148] It should be noted that the electronic device can obtain the memory size used by the target application while obtaining the second dump size, and can also obtain the memory size used by the target application when the memory size used by the target application is needed later. The embodiment of the present application does not impose specific restrictions on this.

[0149] Step 704: Determine whether the second dump volume is greater than a third threshold value. If so, execute the operation of the following step 705; if not, execute the operation of the following step 711.

[0150] Since the second dump volume is the total amount of all compressed data in the target memory when this GC is triggered, if the second dump volume is small, it means that the adjustment range of the memory threshold of the target application is small and there is no need to adjust it. Therefore, when the second dump volume is not greater than the third threshold, that is, when the second dump volume is less than or equal to the third threshold, perform the operation of step 711 or the operation of step 712.

[0151] When the second dump volume is greater than the third threshold, it indicates that the memory threshold corresponding to the target application still has adjustable space, and therefore, the electronic device may perform the operation of step 705 described below.

[0152] Step 705: Determine whether GC data is cached, if so, execute the operation of the following step 706, if not, execute the operation of the following step 708.

[0153] Since there is no need to adjust the memory threshold of the target application when GC data is cached, and there is no need to adjust the memory threshold of the target application when GC is not cached, the electronic device needs to determine whether GC data is cached.

[0154] Step 706: Update the cached GC data and determine the first dump volume.

[0155] In the case where GC data is cached, the current GC data may replace the previously cached GC data, or the previously cached GC data may be retained and the current GC data may be stored.

[0156] Since the first dump volume is determined when GC data is stored, it means that this time the GC is triggered is not the first time, and the stored GC data has not been cleared before. Therefore, the GC was also triggered before this time. The second dump volume may change compared with the third dump volume when the GC was triggered last time. Therefore, the electronic device can subtract the third dump volume from the second dump volume to obtain the first dump volume.

[0157] Step 707: Determine whether the first dump volume is greater than a first threshold value. If so, execute the operation of the following step 709; if not, execute the operation of the following step 711.

[0158] Since the first dump volume is greater than the first threshold, it means that the memory threshold corresponding to the target application still has adjustable space, so the electronic device can perform the operation of the following step 709.

[0159] Step 708: Initialize the current GC operation.

[0160] It should be noted that the electronic device initializes the current GC operation, that is, stores the GC data of this GC.

[0161] Step 709: Adjust the memory threshold of the target application to obtain a second memory threshold.

[0162] In some embodiments, if step 709 is performed after step 707 is performed, the electronic device adjusts the memory threshold of the target application based on the first dump amount to obtain a second memory threshold. If step 709 is performed after step 708 is performed, the electronic device can adjust the memory threshold of the target application based on the second dump amount to obtain a second memory threshold.

[0163] It should be noted that the electronic device adjusts the memory threshold of the target application based on the second dump amount to obtain the second memory threshold by referring to the operation of adjusting the memory threshold of the target application based on the first dump amount to obtain the second memory threshold.

[0164] Step 710: Skip the current GC operation and end this round of operation.

[0165] Step 711: Clear cached GC data.

[0166] It should be noted that cleaning the cached GC data is to delete the stored GC data, so that the memory threshold of the target application is the default preset memory threshold.

[0167] Step 712: Execute GC operations and end this round of operations.

[0168] In the embodiment of the present application, since the GC operation is not necessarily executed after the GC is triggered, the number of executions of the GC operation is reduced, and the situation of a large amount of CPU resource waste is reduced. In addition, since the memory threshold of the target application can be readjusted when the GC is triggered and the GC operation is not executed, the frequent triggering of the GC of the target application is avoided, thereby avoiding the occupation of a large amount of CPU resources. In addition, since the frequency of executing the GC operation is reduced, the conflict between the GC and the kernel's ZRAM is avoided, and the waste of CPU resources is further reduced.

[0169] Next, please refer to Figure 8 , Figure 8 This is a flow chart of a control method for memory recycling according to another exemplary embodiment. As an example but not a limitation, the method is applied to an electronic device as an example for illustration. The method may include some or all of the following contents:

[0170] Step 801: When the size of the memory occupied by the target application reaches a first memory threshold, trigger GC for the target application.

[0171] It should be noted that the electronic device can detect the size of the memory occupied by the target application through the virtual machine corresponding to the target application, and trigger the GC of the target application when the size of the memory occupied by the target application is greater than or equal to the first memory threshold.

[0172] Step 802: After the GC is triggered, determine the increment of compressed data in the target memory allocated for the target application to obtain a first dump volume.

[0173] It should be noted that after the compressed data is compressed in the target memory, the target memory increases the usage space of the first value, and the compressed data does not refer to the cached data compressed in the target memory generated during the running of the target application, but refers to the memory data that needs to be compressed and dumped under the ZRAM management of the kernel.

[0174] As an example, after GC is triggered, the electronic device determines the increment of compressed data in the target memory allocated for the target application, and the operation of obtaining the first dump volume includes: when GC is triggered, obtaining the running state of the target application, which running state includes the foreground running state or the background running state; when the target application is in the background running state, determining the trigger type of GC; when the trigger type is a preset type, determining the first dump volume.

[0175] From the above, it can be seen that the triggering conditions of GC include at least three situations, and when the GC for the target application is triggered due to the memory threshold of the target application, it will be considered whether to adjust the memory threshold of the target application. When GC is triggered by other reasons, it is usually not necessary to adjust the memory threshold of the target application. Therefore, in order to accurately determine whether to adjust the memory threshold of the target application, the electronic device can determine the trigger type of GC.

[0176] As an example, when the type identifier is a preset type identifier, the trigger type of GC can be determined to be a preset type. The preset type is used to indicate that GC for the target application is triggered when the memory occupied by the target application reaches a corresponding memory threshold.

[0177] It is worth noting that by determining the running state of the target application and the trigger type of GC, it is possible to accurately determine whether it is necessary to continue to adjust the memory threshold of the target application, thereby improving the running efficiency of the electronic device.

[0178] As can be seen from the above, the electronic device may include a scene recognition module and a dump information reading module. Thus, as an example, when the GC is triggered, the operation of obtaining the running state of the target application may include: when the GC is triggered, the scene recognition module may determine the running state of the target application from the state transition message sent by the target application, and the state transition message is a message sent to the scene recognition module when the target application switches between the foreground and the background. As an example, when the trigger type is a preset type, the operation of determining the first dump volume includes: when the trigger type is a preset type, the scene recognition module sends a data acquisition message to the dump information reading module; when the dump information reading module receives the data acquisition message, it determines the first dump volume.

[0179] It should be noted that the operation of the scene recognition module determining the running status of the target application can refer to the operation of the above step 501, and the operation of the dump information reading module determining the first dump volume can refer to the operation of the above step 505, which will not be described in detail in this embodiment of the present application.

[0180] It is worth noting that the first dump volume is determined by the dump information reading module, so that the determination of the first dump volume is more accurate.

[0181] In some embodiments, when the trigger type is a preset type, the operation of the electronic device determining the first dump size includes: when the trigger type is a preset type, obtaining a second dump size, the second dump size being the total amount of all compressed data in the target memory when the current GC is triggered; when the first memory threshold is the preset memory threshold, determining the second dump size to be the first dump size; when the first memory threshold is not the preset memory threshold, subtracting the third dump size from the second dump size to obtain the first dump size, the third dump size being the total amount of all compressed data in the target memory when the last GC was triggered.

[0182] Since the preset memory threshold is the default memory threshold corresponding to the target application, when the first memory threshold is the preset memory threshold, it means that this GC is the first GC triggered by the memory threshold corresponding to the target application, or, this GC is the first GC triggered by the memory threshold corresponding to the target application after clearing the previously cached GC data, and the first dump size is the increment of the compressed data size starting from 0. Therefore, the total amount of all compressed data in the target memory when the GC is triggered this time, that is, the second dump size, can be determined as the first dump size.

[0183] Furthermore, since the first memory threshold is not the preset memory threshold, it means that the first memory threshold is the memory threshold obtained by adjusting the memory threshold of the target application when the last GC was triggered, and the operation of the last GC was not executed, the amount of compressed data in the target memory may change during the time period between the last GC triggering and the triggering of this GC. Therefore, the first dump amount can be obtained by subtracting the third dump amount from the second dump amount.

[0184] It is worth noting that, by comparing the first memory threshold with the preset memory threshold, the method for determining the first dump amount can be accurately selected, thereby improving the accuracy of determining the first dump amount.

[0185] In some embodiments, when the trigger type is a preset type, the operation of obtaining the second dump volume includes: when the trigger type is a preset type, determining a first virtual address range corresponding to the target memory; reading status information of each virtual memory page corresponding to the first virtual address range; determining a second virtual address range of a virtual memory page including a compression identifier in the status information; determining a corresponding memory size within the second virtual address range to obtain a second dump volume.

[0186] It should be noted that the operation of the electronic device reading the status information of each virtual memory page corresponding to the first virtual address range can refer to the operation of the dump information reading module reading the status information of each virtual memory page corresponding to the first virtual address range recorded in the above step 505, and the embodiment of the present application will not go into details about this.

[0187] It is worth noting that by determining the status information of each virtual memory page in the target memory, it is possible to accurately find which data will be compressed, thereby improving the accuracy of determining the second dump volume.

[0188] In some embodiments, after the electronic device obtains the second dump volume, if the second dump volume is greater than the third threshold, the electronic device continues to determine whether the first memory threshold is a preset memory threshold, and then determines the first dump volume. When the second dump volume is less than or equal to the third threshold, the electronic device does not need to obtain the first dump volume again, but performs a GC operation.

[0189] It is worth noting that by determining whether the second dump volume is less than or equal to the third threshold, the speed of determining whether to perform the GC operation can be accelerated.

[0190] Step 803: When the first dump volume is greater than the first threshold, the memory threshold corresponding to the target application is adjusted based on the first dump volume to obtain a second memory threshold, and the current GC operation is skipped.

[0191] It should be noted that the second memory threshold is the memory threshold for triggering GC next time.

[0192] Since when the first dump volume is greater than the first threshold, it means that there is still a large amount of space in the target memory for the target application to use and there is no need to perform GC operation. Therefore, the electronic device can adjust the memory threshold corresponding to the target application based on the first dump volume, obtain the second memory threshold, and skip this GC operation.

[0193] In some embodiments, when the first dump volume is greater than the first threshold, the memory threshold corresponding to the target application is adjusted based on the first dump volume to obtain the second memory threshold. The operation includes: when the first dump volume is greater than the first threshold, determining the compression amount of the compressed data corresponding to the first dump volume after being compressed; subtracting the compression amount from the first dump volume to obtain a second value; adding the second value to the first memory threshold to obtain a third value; and determining the second memory threshold based on the third value.

[0194] Since the first dump volume is the increment of the compressed data in the target memory, it is necessary to determine the size of the increased usable space of the increment after compression, that is, to obtain the second value by subtracting the compression amount from the first dump volume.

[0195] It should be noted that, when the first dump volume is the second dump volume, the second value is the first value, and when the first dump volume is not the second dump volume, the second value is not the first value.

[0196] It is worth noting that by subtracting the compression amount from the first dump amount, the size of the usable space saved after the compressed data corresponding to the first dump amount in the target memory is compressed can be accurately determined, thereby improving the accuracy of determining the second memory threshold. Moreover, since the threshold of the target memory is adjusted, the number of GC triggers is reduced.

[0197] As an example, the operation of the electronic device determining the second memory threshold based on the third numerical value includes: when the third numerical value is less than or equal to the second threshold, determining the third numerical value as the second memory threshold; when the third numerical value is greater than the second threshold, determining the second threshold as the second memory threshold.

[0198] Since the size of the target memory is limited, when the third value is greater than the second threshold, it means that the third value is greater than or equal to the size of the target memory. Therefore, the second threshold can be determined as the second memory threshold.

[0199] It is worth noting that by comparing the third value with the second threshold, it is possible to avoid unreasonable setting of the second memory threshold.

[0200] It should be noted that since the GC operation is not necessarily executed after the GC is triggered, a large amount of CPU resource occupation is avoided and the waste of CPU resources is reduced.

[0201] In one possible example, after skipping this GC operation, the electronic device may continue to detect the size of the memory occupied by the target application. Since the electronic device adjusts the memory threshold of the target application to the second memory threshold, the electronic device may trigger GC for the target application when the size of the memory occupied by the target application reaches the second memory threshold, and return to the operation of the above step 801.

[0202] Step 804: When the first dump volume is less than the first threshold, perform a GC operation.

[0203] Since the first dump volume is smaller than the first threshold, it means that the space saved for the target memory after the first dump volume is compressed is very small and can be ignored. In this case, after the memory threshold of the target application is adjusted, the memory occupied by the target application will soon reach the adjusted memory threshold. Therefore, when the first dump volume is smaller than the first threshold, the GC operation can be performed.

[0204] As an example, when the first dump volume is less than the first threshold, if GC data is cached in the electronic device, the electronic device can clear the cached GC data and then perform GC operations; if GC data is not cached in the electronic device, the electronic device can directly perform GC operations.

[0205] It should be noted that after the electronic device executes the GC operation, the cached GC data will be cleared, so the memory threshold adjusted for the target application will be cleared, so that the memory threshold of the target application is updated to the default preset memory threshold.

[0206] In a possible example, after executing this GC operation, the electronic device can also continue to detect the memory size occupied by the target application, and when the memory size reaches a preset threshold, trigger GC for the target application and return to the operation of the above step 801.

[0207] In the embodiment of the present application, since the GC operation is not necessarily executed after the GC is triggered, the number of executions of the GC operation is reduced, and the situation of a large amount of CPU resource waste is reduced. In addition, since the memory threshold of the target application can be readjusted when the GC is triggered and the GC operation is not executed, the frequent triggering of the GC of the target application is avoided, thereby avoiding the occupation of a large amount of CPU resources. In addition, since the frequency of executing the GC operation is reduced, the conflict between the GC and the kernel's ZRAM is avoided, and the waste of CPU resources is further reduced.

[0208] Next, the electronic device involved in the embodiment of the present application is described.

[0209] The method provided in the embodiments of the present application can be executed by an electronic device. As an example and not limitation, the electronic device can be but not limited to a mobile phone sports camera (GoPro), a digital camera, a tablet computer, a desktop, a laptop, a handheld computer, a notebook computer, a vehicle-mounted device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook, a cellular phone, a personal digital assistant (personal digital assistant, PDA), an augmented reality (augmentedreality, AR)\virtual reality (virtual reality, VR) device, a mobile phone, a door lock, a smart appliance, etc., and the embodiments of the present application are not limited to this.

[0210] Fig. 9 is a schematic diagram of the structure of a terminal provided in an embodiment of the present application. Fig. 9The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. Among them, the sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

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

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

[0213] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

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

[0215] In some embodiments, the processor 110 may include one or more interfaces, such as an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0216] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.

[0217] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.

[0218] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of the antennas. 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.

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

[0220] The display screen 194 is used to display images, videos, etc. The display screen 194 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 100 may include 1 or N display screens 194, where N is an integer greater than 1.

[0221] The electronic device 100 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.

[0222] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.

[0223] The internal memory 121 can be used to store computer executable program codes, which include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 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 by the electronic device 100 during use (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 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.

[0224] The electronic device 100 can implement audio functions, such as music playback, recording, etc., through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone interface 170D and the application processor.

[0225] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, 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 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure based on the change in capacitance. When a touch operation acts on the display screen 194, the electronic device 100 detects the touch operation intensity according to the pressure sensor 180A. The electronic device 100 can also calculate the touch position according to the detection signal of the pressure sensor 180A. 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 a pressure threshold acts on a 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 pressure threshold acts on a short message application icon, an instruction to create a new short message is executed.

[0226] The touch sensor 180K is also called a "touch panel". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor 180K 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 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.

[0227] Indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, messages, missed calls, notifications, etc.

[0228] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be transmitted from a website site, computer, server or data center by wired (such as: coaxial cable, optical fiber, data subscriber line (Digital Subscriber Line, DSL)) or wireless (such as: infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that a computer can access, or a data storage device such as a server or data center that includes one or more available media integrations. The available medium may be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a digital versatile disc (DVD)), or a semiconductor medium (such as a solid state disk (SSD)).

[0229] The above are optional embodiments provided for the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the technical scope disclosed in the present application shall be included in the protection scope of the present application.

Claims

1. A memory recycling control method, characterized in that: Applied in an electronic device, the method comprises: When the size of the memory occupied by the target application reaches a first memory threshold, triggering memory recycling GC for the target application; After the GC is triggered, determining the increment of compressed data in the target memory allocated for the target application to obtain a first dump volume, wherein the target memory increases the usage space of the target memory by a first value after the compressed data is compressed in the target memory; When the first dump volume is greater than a first threshold, adjusting the memory threshold corresponding to the target application based on the first dump volume to obtain a second memory threshold, and skipping the current GC operation, where the second memory threshold is the memory threshold for triggering the GC next time; When the first dump volume is less than the first threshold, the GC operation is performed.

2. The method according to claim 1, characterized in that When the first dump volume is greater than a first threshold, adjusting the memory threshold corresponding to the target application based on the first dump volume to obtain a second memory threshold includes: In a case where the first dump volume is greater than the first threshold, determining a compression volume of the compressed data corresponding to the first dump volume after being compressed; Subtract the compression amount from the first dump amount to obtain a second value; Adding the second value to the first memory threshold to obtain a third value; Based on the third value, the second memory threshold is determined.

3. The method according to claim 2, characterized in that The determining the second memory threshold based on the third value includes: When the third value is less than or equal to the second threshold, determining the third value as the second memory threshold; When the third value is greater than the second threshold, the second threshold is determined as the second memory threshold.

4. The method according to any one of claims 1 to 3, characterized in that After the GC is triggered, determining the increment of compressed data in the target memory allocated for the target application to obtain a first dump volume includes: When the GC is triggered, obtaining the running state of the target application, wherein the running state includes a foreground running state or a background running state; When the target application is in the background running state, determining the trigger type of the GC; When the trigger type is a preset type, the first dump amount is determined.

5. The method according to claim 4, characterized in that The electronic device comprises a scene recognition module and a dump information reading module; When the GC is triggered, obtaining the running status of the target application includes: When the GC is triggered, the scene recognition module determines the running state of the target application from a state transition message sent by the target application, wherein the state transition message is a message sent to the scene recognition module when the target application switches between the foreground and the background; When the trigger type is a preset type, determining the first dump amount includes: In the case where the trigger type is the preset type, the scene recognition module sends a data acquisition message to the dump information reading module; The dump information reading module determines the first dump volume when receiving the data acquisition message.

6. The method according to claim 4, characterized in that When the trigger type is a preset type, determining the first dump amount includes: When the trigger type is the preset type, obtaining a second dump volume, where the second dump volume is the total amount of all compressed data in the target memory when the current GC is triggered; In a case where the first memory threshold is a preset memory threshold, determining the second dump amount to be the first dump amount; When the first memory threshold is not the preset memory threshold, the first dump volume is obtained by subtracting the third dump volume from the second dump volume, and the third dump volume is the total amount of all compressed data in the target memory when the last GC is triggered.

7. The method according to claim 6, characterized in that When the trigger type is the preset type, obtaining the second dump volume includes: In a case where the trigger type is the preset type, determining a first virtual address range corresponding to the target memory; Reading status information of each virtual memory page corresponding to the first virtual address range; Determine a second virtual address range of the virtual memory page including the compression indicator in the state information; Determine the memory size corresponding to the second virtual address range to obtain the second dump volume.

8. The method according to claim 6, characterized in that The method further comprises: When the second dump volume is less than or equal to a third threshold, the GC operation is performed.

9. An electronic device, characterized in that: The structure of the electronic device includes a processor and a memory; The memory is used to store a program that supports the electronic device to execute the method according to any one of claims 1 to 8, and to store data involved in implementing the method according to any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, which, when executed on a computer, enable the computer to execute the method according to any one of claims 1 to 8.