Memory recovery control method, electronic equipment and readable storage medium

After triggering GC in an electronic device, GC operation is performed on memory cells whose compression amount is less than the threshold, which solves the problem of inefficiency caused by the conflict between GC and ZRAM operation, and improves the speed of GC and the smoothness of equipment operation.

CN120429096APending Publication Date: 2025-08-05HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410121761.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-26
Publication Date
2025-08-05

AI Technical Summary

Technical Problem

In electronic devices, the conflict between GC operation and ZRAM operation leads to low GC efficiency and affects the smoothness of the device operation.

Method used

When the memory of the target application reaches the threshold, GC is triggered and the compression amount of each memory unit is determined. Only GC operations are performed on memory units whose compression amount is less than the threshold, so as to avoid the decompression time of the compression area being too long.

Benefits of technology

Improves the speed and efficiency of GC operations, reduces the use of CPU resources, and avoids the stuttering of the foreground application.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120429096A_ABST
    Figure CN120429096A_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 memory threshold value, a GC for the target application program is triggered; after the GC is triggered, the first compression amount of a compression area contained in each storage unit in the multiple storage units is determined, each storage unit is obtained after unit division is conducted on a target memory allocated to the target application program, and compression occurs under the condition that memory data in the compression area is dumped to other memory management spaces; and performing GC operation on the storage units of which the first compression amount is smaller than a first threshold value in the plurality of storage units. According to the method and the device, the compression amount of the compression area in the storage unit in which the GC operation is carried out is relatively small, and the time for decompressing the compression area is relatively short, so that the GC operation speed is increased, and the GC efficiency 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 terminal technology, and in particular to a memory recycling control method, an electronic device, and a readable storage medium. Background Art

[0002] With the advancement of terminal technology, more and more applications are installed in electronic devices, and each application consumes a certain amount of memory. Because memory size affects the smoothness of electronic device operation, garbage collection (GC) is often used to clear memory space to improve the lag that occurs during use. GC refers to an automatic memory management mechanism. When a portion of memory space occupied by an application is no longer accessed by the application, the application uses a garbage collection algorithm to return this memory space to the operating system, thereby achieving the purpose of memory space clearing.

[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 there is not only one memory management method in electronic devices, there may also be other memory management methods, for example, other memory management methods are ZRAM. During the GC operation of the electronic device, the GC operation may conflict with the ZRAM operation, resulting in low GC efficiency. Summary of the Invention

[0005] This application provides a memory recycling control method, electronic device, and readable storage medium, which can be used to solve the problem of low GC efficiency 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 memory threshold, memory recycling GC for the target application is triggered; after the GC is triggered, the first compression amount of the compression area contained in each storage unit in the multiple storage units is determined, each storage unit is obtained by dividing the target memory allocated to the target application, and compression occurs when the memory data in the compression area is dumped to other memory management spaces; GC operations are performed on the storage units in the multiple storage units whose first compression amount is less than the first threshold.

[0008] It should be noted that when allocating target memory for a target application, the target memory can be divided into units, that is, the target memory can be divided into several (N) storage units of the same or different sizes. The storage unit can be called a region, and the target memory can also be called a Java heap.

[0009] In this way, after GC is triggered, GC operations can be performed on storage cells in the target memory whose first compression amount is less than the first threshold. This allows for independent reclamation of storage cells and improves the richness of GC operations. Furthermore, because the compressed areas in the storage cells undergoing GC operations have a smaller compression amount, decompression of these compressed areas takes less time, minimizing the impact on GC operations. This improves GC speed and, consequently, efficiency.

[0010] As an example of the present application, after GC is triggered, the electronic device determines a first compression amount of a compression region included in each storage unit in a plurality of storage units, including:

[0011] After GC is triggered, a plurality of storage units whose usage status is used is determined from the target memory; and a first compression amount of a compression area included in each of the plurality of storage units is determined.

[0012] In some embodiments, each storage unit may include a usage status identifier. When the usage status identifier is a first identifier (the first identifier may be "1", "yes", etc.), it indicates that the corresponding storage unit is in use; when the usage status identifier is a second identifier (the second identifier may be "0", "no", etc.), it indicates that the corresponding storage unit is not in use. Therefore, the dump information reading module can determine the number of used storage units based on the usage status identifier of each storage unit.

[0013] In some embodiments, each storage unit corresponds to a unit name (region ID), and a usage list is set in the virtual machine corresponding to the target application. The usage list can record the unit names of the used storage units. Therefore, the electronic device can also determine multiple used storage units from the usage list.

[0014] In this way, by determining the multiple storage units that have been used, in the subsequent process of determining the first compression amount of each storage unit, the amount of confirmed data is reduced as much as possible, thereby improving data processing efficiency.

[0015] As an example of the present application, an operation of the electronic device determining a first compression amount of a compressed area included in each storage unit in a plurality of storage units includes:

[0016] Obtain status information of each virtual memory page in multiple virtual memory pages corresponding to a target storage unit, where the target storage unit is any one of the multiple storage units; determine the compression amount of the virtual memory page including a compression identifier in the status information to obtain at least one second compression amount, where the compression identifier is used to indicate that the corresponding virtual memory page contains compressed storage data; add the at least one second compression amount to obtain a first compression amount of the target storage unit.

[0017] It should be noted that the status 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).

[0018] 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 at least one second compression amount and the first compression amount.

[0019] As an example of the present application, the operation of the electronic device obtaining the status information of each virtual memory page among the multiple virtual memory pages corresponding to the target storage unit includes:

[0020] Obtain a first virtual address range of the target storage unit; determine, based on the first virtual address range of the target storage unit, a second virtual address range of each virtual memory page in the multiple virtual memory pages corresponding to the target storage unit from the correspondence between the first virtual address range and the second virtual address range; determine, based on the second virtual address range of each virtual memory page corresponding to the target storage unit, status information of each virtual memory page corresponding to the target storage unit.

[0021] It should be noted that the status information of each virtual memory page can be stored in 8 bytes of pagemap, that is, the status information of each virtual memory page corresponds to 8 bytes of pagemap.

[0022] In this way, since the second virtual address of each virtual memory page corresponds to different bytes in the pagemap, the corresponding status information can be accurately determined according to the second virtual address of each virtual memory page.

[0023] As an example of this application, the method further includes:

[0024] When at least one second compression amount is greater than the first quantity threshold, and each second compression amount is greater than or equal to the second threshold, it is determined that the target storage unit does not need to perform a GC operation.

[0025] In this way, by determining in advance the storage units that do not need to be subjected to GC, the process of subsequently determining the storage units that need to be subjected to GC operations is reduced, thereby improving the efficiency of GC operations.

[0026] As an example of the present application, after GC is triggered, the electronic device determines from the target memory a plurality of storage units whose usage status is used, including:

[0027] When GC is triggered, the running state of the target application is obtained, which includes the foreground running state or the background running state; when the target application is in the background running state, the trigger type of GC is determined; when the trigger type is a preset type, multiple storage units whose usage is already used are determined from the target memory.

[0028] In this way, by determining the running state of the target application and the trigger type of GC, the object requiring GC operation can be accurately determined, thereby improving the running efficiency of the electronic device and the efficiency of GC operation.

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

[0030] Based on this, when GC is triggered, the operations for obtaining the running status of the target application include:

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

[0032] When the trigger type is a preset type, the operation of determining the plurality of storage units whose usage status is used from the target memory includes:

[0033] When the trigger type is the preset type, the scene recognition module sends a status acquisition message to the dump information reading module; and when the dump information reading module receives the status acquisition message, it determines a plurality of storage units from the target memory.

[0034] In this way, the plurality of storage units are determined by the dump information reading module, thereby making the determination of the plurality of storage units more accurate.

[0035] As an example of this application, the method further includes:

[0036] After GC is triggered, the number of cold pages in each of the plurality of storage units is determined; and a GC operation is performed on the storage unit whose number of cold pages is greater than a second number threshold.

[0037] It should be noted that a cold page refers to a virtual memory page that is no longer used or is not frequently used among the multiple virtual memory pages corresponding to the target storage unit.

[0038] In this way, by separately recycling storage units that meet other conditions, the richness of GC operations can be improved, and the efficiency of GC recycling and the usage space of the target memory can be improved.

[0039] 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 in executing 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 for establishing a connection between the processor and the memory.

[0040] In a third aspect, a computer-readable storage medium is provided, wherein instructions are stored in the computer-readable storage medium, which, when executed on a computer, enables the computer to execute the memory recycling control method described in the first aspect.

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

[0042] The technical effects obtained by the above-mentioned second, third and fourth 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

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

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

[0045] Figure 3 This is a memory compression schematic diagram provided by an embodiment of the present application;

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

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

[0048] Figure 6 This is a schematic diagram of a memory recycling process provided by an embodiment of the present application;

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

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

[0051] Figure 9 This is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

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

[0053] 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 merely 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, words such as “first” and “second” are used to distinguish between identical or similar items with basically the same functions and effects. Those skilled in the art can understand that words such as “first” and “second” do not limit the quantity and execution order, and words such as “first” and “second” do not necessarily limit them to be different.

[0054] References to "one embodiment" or "some embodiments" in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present application. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.

[0055] 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. The application can run in the corresponding virtual machine, and the virtual machine can allocate a certain amount of memory for the application. Figure 1During virtual machine operation, if the memory occupied by any application A reaches a preset memory threshold (often also called a watermark), the virtual machine can trigger garbage collection (GC) for application A and perform GC operations to reclaim memory no longer used by application A, allowing it to be reused and improving memory utilization. The memory occupied by application A includes the memory used by application A (this memory size is called the used size) and the reserved free memory (this memory size is called the free size).

[0056] 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 mark, recycle, and move objects according to whether they are in use; the kernel's ZRAM is managed by memory page, sorted by access order, and preferentially compresses cold pages in memory, and then transfers the compressed cold pages to other storage spaces. That is, in order to save the space used by application A for the allocated memory, the electronic device can compress the cold pages in the memory allocated by application A (cold pages refer to virtual memory pages that are no longer used or infrequently used in 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 operation. 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 or compression 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 As shown, the size of the swap area after compression is the first compression amount.

[0057] After GC is triggered, the virtual machine scans all objects in the memory allocated by application A. When the compressed area is scanned, it will be decompressed by ZRAM. This decompression takes time, which causes the GC execution time to be blocked by ZRAM decompression, increasing the GC execution time and reducing GC efficiency. In addition, after ZRAM decompresses the compressed area, GC no longer scans cold pages. ZRAM will re-compress the cold pages in application A's memory, and ZRAM will also occupy a large amount of CPU and GPU resources. In this case, both GC and ZRAM will preempt CPU resources, and then preempt the CPU resources of the foreground application, resulting in unreasonable CPU resource allocation and causing the foreground application to freeze and drop frames.

[0058] In order to improve the efficiency of GC, an embodiment of the present application provides a memory recycling control method, in which, when the size of the memory occupied by the target application reaches a memory threshold, the GC of the target application can be triggered, and after the GC is triggered, the first compression amount of the compressed area contained in each storage unit in the multiple storage units can be determined, and the GC operation can be performed on the storage unit in the multiple storage units whose first compression amount is less than the first threshold. Since the storage data in the compressed area is compressed when it is dumped to other memory management spaces, if the GC operation is performed on the compressed area, the compressed area needs to be decompressed. When the compression amount of the compressed area is small, the decompression time is short, and the hindrance to the GC operation is small. Therefore, by performing the GC operation on the storage unit in the multiple storage units whose first compression amount is less than the first threshold, the speed of the GC operation can be increased, thereby improving the efficiency of the GC.

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

[0060] The software system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a microservice architecture, or a cloud architecture. In the embodiment of the present application, the software system of the electronic device 100 is exemplarily described by taking the Android system of the layered architecture as an example.

[0061] Figure 4 This 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 software into several layers, each with distinct roles and responsibilities. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers: the application layer, the application framework layer, the Android runtime layer, the system layer, and the kernel layer.

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

[0063] 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, content provider, view system, telephony manager, resource manager, notification manager, and so on. The window manager is used to manage window programs. It can obtain the display size, determine whether there is a status bar, lock the screen, take screenshots, and so on. The content provider is used to store and retrieve data and make this data accessible to applications. This data may include video, images, audio, incoming and outgoing calls, browsing history and bookmarks, and the phone book. The view system includes visual controls, such as those for displaying text and images. The view system can be used to construct the application's display interface, which may consist of one or more views, such as a view that displays a text message notification icon, a view that displays text, and a view that displays images. The telephony manager is used to provide communication functions for electronic device 100, such as managing call status (including connected and ended calls). The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, and video files. The notification manager enables applications to display notification information in the status bar. This information can be used to convey notification messages and can be displayed briefly and then disappear automatically without user interaction. For example, a notification manager is used to notify users of completed downloads, message alerts, and more. A notification manager can also appear as an icon or scrolling text bar in the system's top status bar, such as notifications from background applications. A notification manager can also appear as a dialog window on the screen, such as a text message in the status bar, a beep, a vibration on an electronic device, or a flashing indicator light.

[0064] 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, or identifying; the scene recognition module may also identify the trigger type of GC for the application.

[0065] The Android Runtime consists of core libraries and a virtual machine (VM). The Android runtime is responsible for scheduling and management of the Android system. The core library consists of two parts: one for Java-based functions and the other for the Android core library. The application layer and application framework layer run in the VM. The VM executes Java files from the application layer and application framework layer as binary files. The VM is responsible for performing functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection.

[0066] As an example, the virtual machine may further include a dump information reading module, a GC decision module, and a GC execution module. The GC execution module is configured to perform GC operations. The dump information reading module is configured to obtain the size of compressed and dumped memory data in the memory allocated for the application. The GC decision module is configured to determine the objects to be GCed.

[0067] It should be noted that the GC running module may be a HeapTaskDaemon. The dump information reading module and the GC decision module may be located in a GC scheduler.

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

[0069] The kernel layer is the layer between hardware and software.

[0070] As an example, the kernel layer may also include ZRAM, a compression control module, and an information storage module. The ZRAM is used to manage the electronic device's memory and dump some memory data. The compression control module is used to compress or decompress data in the ZRAM. The information storage module is used to store virtual memory page status information.

[0071] In some embodiments, the compression control module may be a kswapd process, and the information storage module may be a pagemap.

[0072] Based on the execution subject provided by the above embodiment, the control method of memory recycling provided by the embodiment of this application is introduced below. Figure 5 , Figure 5 This is a flow chart of a method for controlling memory recycling according to an exemplary embodiment. As an example and not a limitation, the method is applied to an electronic device. Figure 4 The method may include some or all of the following:

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

[0074] As can be seen from the above, the target application runs in a virtual machine. Therefore, the virtual machine can detect whether the memory occupied by the target application reaches the preset memory threshold, and trigger GC for the target application when it detects that the memory occupied by the target application reaches the preset memory threshold.

[0075] 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().

[0076] It should be noted that the running status of the target application includes the target application being in the startup state, the exit state, the application transition state, the heavy load state (video playback state, game scene state, etc.), the foreground running state, the background running state, etc.

[0077] 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. In other words, the scene recognition module can determine whether the target application is in the background running state.

[0078] For example, when the target application's running state changes, it may send a state transition message to the scene recognition module. The state transition message carries a state identifier that indicates the target application's running state. If the scene recognition module needs to determine the target application's running state, it may read the state identifier to determine the target application's current state.

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

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

[0081] In some embodiments, the scene recognition module may also determine the running status of the target application through other means. 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 status of the target application. This embodiment of the present application does not impose specific limitations on this.

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

[0083] Normally, GC is triggered in the following three situations: the first is when the memory occupied by the target application reaches the set memory threshold; the second is when GC is performed on the target application on a scheduled basis; and the third 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, the specific objects for GC will be considered, that is, object screening will be performed. When GC is triggered for other reasons, the GC operation is usually performed directly on the target memory allocated for the target application, and no specific object screening will be performed. Therefore, in order to accurately determine the objects for GC, the scene recognition module can determine the trigger type of GC.

[0084] It should be noted that when allocating target memory for the target application, see Figure 6 , the target memory can be divided into units, that is, the target memory can be divided into several storage units of the same or different sizes. The storage unit can be called a region, and the target memory can also be called a Java heap.

[0085] It should also 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 selected from numbers, letters, and symbols.

[0086] As an example, when the type identifier is a preset type identifier, the GC trigger type 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.

[0087] In some embodiments, when the scene recognition module recognizes that the target application is in the foreground running state, or when the scene recognition module recognizes that the memory of the electronic device is tight (the memory of the electronic device is less than a certain value), the GC running module can send a running message to the GC running module. Upon receiving the running message, the GC running module executes the GC operation.

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

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

[0090] Step 504: The dump information reading module determines a plurality of storage units from the target memory.

[0091] As an example, the message transfer module may obtain usage status of all storage units in the target memory, where the usage status includes used or unused; and determine multiple storage units in the target memory whose usage status is used.

[0092] Since the target memory includes a plurality of storage units (or N storage units, where N is a positive integer greater than or equal to 1), during the execution of the target application, each of the plurality of storage units may have been used, or a portion of the storage units may have been used, while a portion of the storage units may still be unused. The unused storage units do not require GC operations, so the dump information reading module can determine the plurality of used storage units based on the usage of all storage units in the target memory.

[0093] In some embodiments, each storage unit may include a usage status identifier. When the usage status identifier is a first identifier (the first identifier may be "1", "yes", etc.), it indicates that the corresponding storage unit is in use; when the usage status identifier is a second identifier (the second identifier may be "0", "no", etc.), it indicates that the corresponding storage unit is not in use. Therefore, the dump information reading module can determine the number of used storage units based on the usage status identifier of each storage unit.

[0094] In some embodiments, each storage unit corresponds to a unit name, and a usage list is set in the virtual machine corresponding to the target application. The usage list can record the unit names of the used storage units. Therefore, the dump information reading module can also determine multiple used storage units from the usage list.

[0095] Step 505: The dump information reading module obtains a first virtual address range of each storage unit in the plurality of storage units.

[0096] It should be noted that the target memory can be organized into an array of M consecutive bytes, each byte having a unique virtual address. Therefore, the dump information reading module can determine the first virtual address range corresponding to each storage unit. In addition, the dump information reading module can obtain the first virtual address range corresponding to each storage unit from the region space.

[0097] Step 506: The dump information reading module sends a data acquisition message to the information storage module.

[0098] It should be noted that the data acquisition message carries the first virtual address range of each storage unit.

[0099] Step 507: The information storage module obtains a first compression amount of the compressed area included in each storage unit according to the first virtual address range of each storage unit.

[0100] Since the memory data in any storage unit may be dumped to other memory spaces, see Figure 6 , the memory data in the ZRAM is stored in multiple virtual memory pages (Page table), that is, in the kernel, the target memory can be divided into several virtual memory pages, and each storage unit can correspond to multiple virtual memory pages. In the process of memory management, the kernel's ZRAM can compress the memory data in the compression area of each storage unit and dump it. The amount of memory data in the compression area after dumping and compression is the first compression amount. Since the amount of memory data compressed and dumped by each storage unit is different, the first compression amount of each storage unit is different. Therefore, in order to accurately determine the first compression amount of each storage unit, the information storage module obtains the first compression amount of the compression area contained in each storage unit based on the first virtual address range of each storage unit.

[0101] In addition, to avoid misunderstanding, the memory data in the compression area does not refer to the data obtained after compression, but some data generated by the target application during 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. The data compressed by ZRAM is the memory data in the compression area.

[0102] In some embodiments, the information storage module includes status information of each virtual memory page. Therefore, the information storage module can obtain the status information of each virtual memory page in the multiple virtual memory pages corresponding to the target storage unit based on the first virtual address range of the target storage unit, and the target storage unit is any one of the multiple storage units; determine the compression amount of the virtual memory page including the compression identifier in the status information, and obtain at least one second compression amount, and the compression identifier is used to indicate that the corresponding virtual memory page contains compressed storage data; add at least one second compression amount to obtain the first compression amount of the target storage unit.

[0103] It should be noted that the status 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).

[0104] In some embodiments, the information storage module can determine the second virtual address range of each of the multiple virtual memory pages corresponding to the target storage unit based on the first virtual address range of the target storage unit from the correspondence between the first virtual address range and the second virtual address range; and determine the status information of each virtual memory page corresponding to the target storage unit based on the second virtual address range of each virtual memory page corresponding to the target storage unit.

[0105] Because the target memory can be divided into several virtual memory pages in the kernel, each virtual memory page corresponds to a second virtual address, and because each storage unit corresponds to multiple virtual memory pages, each first virtual address range corresponds to multiple second virtual address ranges. In other words, each first virtual address range forms a corresponding relationship with the corresponding multiple second virtual address ranges, that is, a corresponding relationship between the first virtual address range and the second virtual address range. Therefore, the information reading module can determine the multiple second virtual address ranges corresponding to the target storage unit based on the first virtual address range of the target storage unit from the corresponding relationship between the first virtual address range and the second virtual address range.

[0106] Since each process has a pagemap, the pagemap contains the status information (PTEs) of each virtual memory page. The pagemap is a pseudo file system that provides a way to access the pagemap information, so as an example, see Figure 6 The information storage module can read the status information of each virtual memory page in the target memory through a 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 a process. The compressed virtual memory pages can be determined based on the status information of each virtual memory page. Then, at least one second compression amount of each storage unit can be determined based on the second virtual address range of the compressed virtual memory pages.

[0107] In some embodiments, after obtaining at least one second compression amount corresponding to the target storage unit, the information storage module determines that a GC operation is not required for the target storage unit if at least one second compression amount is greater than a first threshold and each second compression amount is greater than or equal to the second threshold. The information storage module may not send the first compression amount of the target storage unit to the GC scheduling module.

[0108] Since the number of at least one second compression amount of the target storage unit is large and the second compression amount is large, the sum of at least one second compression amount must be greater than the first threshold. In this case, GC operation will not be performed on the target storage unit subsequently. Therefore, the information storage module may not send the first compression amount of the target storage unit to the GC scheduling module.

[0109] It should be noted that the first quantity threshold is a threshold set in advance according to needs. For example, the first quantity threshold can be half of the number of virtual storage pages corresponding to the target storage unit, and the second threshold can be 50% or 60% of the space size of the corresponding virtual storage page.

[0110] Step 508: The information storage module sends the first compression amount of the compressed area included in each storage unit to the GC scheduling module.

[0111] Step 509: The GC scheduling module determines a storage unit whose first compression amount is less than a first threshold.

[0112] It should be noted that the first threshold is a threshold preset according to demand.

[0113] Step 510: The GC scheduling module sends the unit names of the storage units whose first compression amount is less than the first threshold to the GC running module.

[0114] Step 511: The GC operation module performs a GC operation on the storage unit corresponding to the received unit name.

[0115] For example, see Figure 6 The GC operation module can filter out the storage unit corresponding to the unit name from multiple storage units, and then perform GC operations on the filtered storage unit. In other words, the GC operation module can reclaim memory for the storage unit corresponding to the unit name.

[0116] In the embodiments of the present application, after GC is triggered, GC operations can be performed on storage cells in the target memory whose first compression amount is less than a first threshold, thereby achieving independent recycling of storage cells and improving the richness of GC operations. In addition, since the compression amount of the compressed area in the storage cell undergoing GC operation is relatively small, the time spent on decompressing the compressed area is relatively short, which reduces the GC operation's hindrance. This improves the speed of GC operations and, in turn, the efficiency of GC operations.

[0117] Next, the memory recycling control method provided by the embodiment of the present application is described by taking other execution entities as examples. Figure 7 , Figure 7This is a flow chart of a memory recycling control method according to another exemplary embodiment. As an example and not a limitation, this method is described using an electronic device as an example. The method may include some or all of the following:

[0118] 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, perform the operation of the following step 702; if not, perform the operation of the following step 707.

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

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

[0121] 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 707.

[0122] In some embodiments, when the target application is running in the background, the electronic device can continue to detect whether the memory of the electronic device is tight, that is, detect whether the memory of the electronic device is less than a certain value. If so, perform the operation of the following step 702; if not, perform the operation of the following step 707.

[0123] 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 707.

[0124] As can be seen above, the preset type indicates that GC for the target application is triggered when the memory occupied by the target application reaches the corresponding memory threshold. Therefore, if the GC trigger type is the preset type, the process will consider specifically selecting objects for GC, and thus proceed to step 703. If the GC trigger type is not the preset type, it indicates that there is no need to specifically select objects for GC. Therefore, in this case, the GC-related operations can continue, namely, executing the following step 707.

[0125] It should be noted that the operation of the electronic device determining whether the trigger type of the GC is the preset type can refer to the operation of the above step 502, and this embodiment of the application will not be described in detail.

[0126] Step 703: Obtain usage status of all storage units in the target memory.

[0127] When the type of GC triggered is a preset type, it means that this GC is triggered because the size of the memory occupied by the target application reaches a preset memory threshold. Therefore, in order to select the object for GC, the electronic device can obtain the usage of all storage units in the target memory.

[0128] It should be noted that the usage status of all storage units includes used or unused.

[0129] As an example, since the target memory includes a plurality of storage units (or referred to as N storage units, where N is a positive integer greater than or equal to 1), during the execution of the target application, each of the plurality of storage units may have been used, or a portion of the storage units may have been used, while a portion of the storage units may still be unused. The unused storage units do not require GC operations, and the electronic device can record the usage of each storage unit. Therefore, the electronic device can obtain the usage of all storage units in the target memory.

[0130] Step 704: Determine a plurality of storage units in the target memory whose usage status is already used.

[0131] It should be noted that the operation of the electronic device determining multiple storage units from the target memory can refer to the operation of the above-mentioned step 504, and the embodiment of the present application will not describe them one by one.

[0132] Step 705: Determine a first compression amount of the compressed area included in each storage unit in the plurality of storage units.

[0133] In some embodiments, the electronic device can obtain status information of each virtual memory page in multiple virtual memory pages corresponding to a target storage unit, where the target storage unit is any one of the multiple storage units; determine the compression amount of the virtual memory page including a compression identifier in the status information, and obtain at least one second compression amount, where the compression identifier is used to indicate that the corresponding virtual memory page contains compressed storage data; add at least one second compression amount to obtain the first compression amount of the target storage unit.

[0134] Since the target storage unit is any one of the multiple storage units, the first compression amount of each storage unit can be obtained by repeatedly executing the method of determining the first compression amount of the target storage unit.

[0135] In some embodiments, the operation of an electronic device obtaining status information of each virtual memory page in a plurality of virtual memory pages corresponding to a target storage unit includes: obtaining a first virtual address range of the target storage unit; determining, based on the first virtual address range of the target storage unit, a second virtual address range of each virtual memory page in a plurality of virtual memory pages corresponding to the target storage unit from a correspondence between the first virtual address range and the second virtual address range; and determining, based on the second virtual address range of each virtual memory page corresponding to the target storage unit, status information of each virtual memory page corresponding to the target storage unit.

[0136] It should be noted that the operation of the electronic device obtaining the first virtual address range of the target storage unit can refer to the operation of the above step 505, and this embodiment of the application will not be described in detail.

[0137] Because in the kernel, the target memory can be divided into several virtual memory pages, each virtual memory page corresponds to a second virtual address, and because each storage unit corresponds to multiple virtual memory pages, each first virtual address range corresponds to multiple second virtual address ranges. In other words, each first virtual address range forms a corresponding relationship with the corresponding multiple second virtual address ranges, that is, a corresponding relationship between the first virtual address range and the second virtual address range. Therefore, the electronic device can determine the multiple second virtual address ranges corresponding to the target storage unit based on the first virtual address range of the target storage unit from the corresponding relationship between the first virtual address range and the second virtual address range.

[0138] Step 706: Perform GC operation on the storage units whose first compression amount is less than the first threshold among the multiple storage units.

[0139] It should be noted that the process of the electronic device performing GC operation on the storage unit whose first compression amount is less than the first threshold among multiple storage units can refer to the operations of the above steps 509 to 511, and the embodiments of the present application will not be described in detail.

[0140] Step 707: Perform a GC operation on each of the multiple storage units.

[0141] In the embodiments of the present application, after GC is triggered, GC operations can be performed on storage cells in the target memory whose first compression amount is less than a first threshold, thereby achieving independent recycling of storage cells and improving the richness of GC operations. In addition, since the compression amount of the compressed area in the storage cell undergoing GC operation is relatively small, the time spent on decompressing the compressed area is relatively short, which reduces the GC operation's hindrance. This improves the speed of GC operations and, in turn, the efficiency of GC operations.

[0142] Next, please refer to Figure 8 , Figure 8 This is a flow chart of a memory recycling control method according to another exemplary embodiment. As an example and not a limitation, this method is described using an electronic device as an example. The method may include some or all of the following:

[0143] Step 801: When the size of the memory occupied by the target application reaches a memory threshold, GC for the target application is triggered.

[0144] 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 GC of the target application when the size of the memory occupied by the target application is greater than or equal to the memory threshold.

[0145] Step 802: After GC is triggered, determine a first compression amount of a compressed area included in each storage unit in a plurality of storage units.

[0146] It should be noted that each storage unit is obtained by dividing the target memory allocated to the target application into units, and compression occurs when the memory data within the compressed area is dumped to other memory management spaces. As can be seen from the above, when allocating target memory for the target application, the target memory can be divided into units, that is, the target memory can be divided into several (N) storage units of equal or different sizes. The storage units can be called regions, and the target memory can also be called Java heap. In the embodiments of this application, N storage units of equal size are used as an example for explanation.

[0147] Exemplarily, the size of the target memory is 512 MB. After the target memory is divided, 2048 storage units of the same size are obtained, and the size of each storage unit is 256 KB.

[0148] As an example, after GC is triggered, the operation of the electronic device determining the first compression amount of the compression area contained in each storage unit in multiple storage units includes: after GC is triggered, determining multiple storage units whose usage is used from the target memory; determining the first compression amount of the compression area contained in each storage unit in the multiple storage units.

[0149] Because the target memory includes N storage units, each of these N storage units can be in use while the target application is running. It's also possible that the electronic device is using some of these storage units, while others remain unused. Unused storage units do not require GC operations. Therefore, the electronic device can determine the number of used storage units from all storage units in the target memory.

[0150] In some embodiments, each storage unit may include a usage status identifier. When the usage status identifier is a first identifier (the first identifier may be "1", "yes", etc.), it indicates that the corresponding storage unit is in use; when the usage status identifier is a second identifier (the second identifier may be "0", "no", etc.), it indicates that the corresponding storage unit is not in use. Therefore, the dump information reading module can determine the number of used storage units based on the usage status identifier of each storage unit.

[0151] In some embodiments, each storage unit corresponds to a unit name (region ID), and a usage list is set in the virtual machine corresponding to the target application. The usage list can record the unit names of the used storage units. Therefore, the electronic device can also determine multiple used storage units from the usage list.

[0152] It is worth noting that, by determining the multiple storage units that have been used, in the subsequent process of determining the first compression amount of each storage unit, the amount of confirmed data is reduced as much as possible, thereby improving data processing efficiency.

[0153] In some embodiments, after GC is triggered, the operation of determining multiple storage units that have been used from the target memory includes: when GC is triggered, obtaining the running status of the target application, which running status includes a foreground running status or a background running status; when the target application is in the background running status, determining the trigger type of GC; when the trigger type is a preset type, determining multiple storage units that have been used from the target memory.

[0154] As can be seen from the above, GC triggering situations include at least three situations. When the GC for the target application is triggered due to the memory threshold of the target application, the specific object for the GC operation will be considered. When the GC is triggered for other reasons, it is usually not necessary to select the specific object for the GC operation. Therefore, in order to accurately select the object for the GC operation, the electronic device can determine the trigger type of GC.

[0155] As an example, when the type identifier is a preset type identifier, the GC trigger type 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.

[0156] It is worth noting that by determining the running state of the target application and the trigger type of GC, the object requiring GC operation can be accurately determined, thereby improving the running efficiency of the electronic device and the efficiency of GC operation.

[0157] From the above, it can be seen that the electronic device may include a scene recognition module and a dump information reading module. Thus, as an example, when GC is triggered, the operation of obtaining the running status of the target application may include: when GC is triggered, the scene recognition module may determine the running status of the target application from the state transition message sent by the target application. The state transition message is a message sent to the scene recognition module when the target application switches between the foreground and background.

[0158] As an example, when the trigger type is a preset type, the operation of determining multiple storage units in use from the target memory includes: when the trigger type is a preset type, the scene recognition module sends a status acquisition message to the dump information reading module; when the dump information reading module receives the status acquisition message, it determines multiple storage units from the target memory.

[0159] It should be noted that the operation of the scene recognition module to determine 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 to determine multiple storage units can refer to the operation of the above step 504. The embodiment of the present application will not go into details on this.

[0160] It is worth noting that the multiple storage units are determined by the dump information reading module, thereby making the determination of the multiple storage units more accurate.

[0161] In some embodiments, the operation of an electronic device determining a first compression amount of a compressed area contained in each of a plurality of storage units includes: obtaining status information of each virtual memory page in a plurality of virtual memory pages corresponding to a target storage unit, where the target storage unit is any one of the plurality of storage units; determining the compression amount of a virtual memory page including a compression identifier in the status information, and obtaining at least one second compression amount, where the compression identifier is used to indicate that the corresponding virtual memory page contains compressed storage data; and adding at least one second compression amount to obtain the first compression amount of the target storage unit.

[0162] As can be seen from the above, the memory data in any storage unit may be dumped to other memory spaces, and the memory data in ZRAM is stored in multiple virtual memory pages (Page table), that is, in the kernel, the target memory can be divided into several virtual memory pages, and each storage unit can correspond to multiple virtual memory pages. For example, the size of each virtual memory page can be 4kb. In this way, when the size of each storage unit is 256kb, each storage unit can correspond to 64 virtual memory pages. For the multiple virtual memory pages corresponding to the target storage unit, since not every virtual memory page has compressed data, the electronic device can determine the compression amount of the virtual memory page including the compression identifier in the status information, obtain at least one second compression amount, and add the at least one second compression amount to obtain the first compression amount of the target storage unit.

[0163] It should be noted that the status information of the virtual memory page may include information indicating whether the corresponding virtual memory page is free, compressed (or swapped), or mapped (null PFN), etc. Therefore, the electronic device can obtain the virtual memory page including the compression identifier from the multiple virtual memory pages corresponding to the target storage unit, and determine the compression amount of each virtual memory page in the obtained virtual memory pages to obtain at least one second compression amount.

[0164] 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 at least one second compression amount and the first compression amount.

[0165] In some embodiments, the operation of an electronic device obtaining status information of each virtual memory page in a plurality of virtual memory pages corresponding to a target storage unit includes: obtaining a first virtual address range of the target storage unit; determining, based on the first virtual address range of the target storage unit, a second virtual address range of each virtual memory page in a plurality of virtual memory pages corresponding to the target storage unit from a correspondence between the first virtual address range and the second virtual address range; and determining, based on the second virtual address range of each virtual memory page corresponding to the target storage unit, status information of each virtual memory page corresponding to the target storage unit.

[0166] Because in the kernel, the target memory can be divided into several virtual memory pages, each virtual memory page corresponds to a second virtual address, and because each storage unit corresponds to multiple virtual memory pages, each first virtual address range corresponds to multiple second virtual address ranges. In other words, each first virtual address range forms a corresponding relationship with the corresponding multiple second virtual address ranges, that is, a corresponding relationship between the first virtual address range and the second virtual address range. Therefore, the electronic device can determine the multiple second virtual address ranges corresponding to the target storage unit based on the first virtual address range of the target storage unit from the corresponding relationship between the first virtual address range and the second virtual address range.

[0167] It should be noted that the status information of each virtual memory page can be stored in the 8 bytes of the pagemap, that is, the status information of each virtual memory page corresponds to the 8 bytes of the pagemap. For example, the status information of virtual memory page A corresponds to the "0000" byte in the pagemap, the status information of virtual memory page B corresponds to the "1000" byte in the pagemap, the status information of virtual memory page C corresponds to the "2000" byte in the pagemap, the status information of virtual memory page D corresponds to the "3000" byte in the pagemap, and so on. And the status information of each virtual memory page is sorted by the memory page address in the pagemap, so that the electronic device can determine the status information of each virtual memory page corresponding to the target storage unit according to the second virtual address range of each virtual memory page corresponding to the target storage unit.

[0168] It is worth noting that, since the second virtual address of each virtual memory page corresponds to different bytes in the pagemap, the corresponding status information can be accurately determined according to the second virtual address of each virtual memory page.

[0169] In some embodiments, after obtaining at least one second compression amount corresponding to the target storage unit, the electronic device can determine that the target storage unit does not need to perform GC operation if at least one second compression amount is greater than the first quantity threshold and each second compression amount is greater than or equal to the second threshold.

[0170] Since the number of at least one second compression amount of the target storage unit is large and the second compression amount is large, the sum of at least one second compression amount must be greater than the first threshold. In this case, the GC operation will not be performed on the target storage unit subsequently. Therefore, the electronic device can determine that the target storage unit does not need to perform the GC operation.

[0171] It is worth noting that by determining in advance the storage units that do not require GC, the process of subsequently determining the storage units that require GC operations is reduced, thereby improving the efficiency of GC.

[0172] Step 803: Perform GC operation on the storage units whose first compression amount is less than the first threshold among the multiple storage units.

[0173] Since when an electronic device performs GC operations on a storage unit with a smaller compression amount, the process of decompressing the storage unit is short, takes less time, and wastes less CPU resources, in order to improve the efficiency of GC, the electronic device can perform GC operations on the storage unit whose first compression amount is less than the first threshold among multiple storage units.

[0174] In some embodiments, the electronic device may screen out storage cells having a first compression amount less than a first threshold from a plurality of storage cells, and then perform a GC operation on the screened storage cells.

[0175] It should be noted that after a GC, the swap information of the region space can be viewed through the process's smaps node. If the swap information is still not zero after the GC, it is considered that some region reclamation logic was skipped. In other words, if the swap information is still not zero after the GC, it is considered that the storage unit with a first compression amount less than the first threshold was reclaimed.

[0176] In some embodiments, the electronic device may perform GC operations not only on the storage units whose first compression amount is less than the first threshold value among the multiple storage units, but may also perform GC operations on other storage units that meet certain conditions.

[0177] Illustratively, after GC is triggered, the electronic device may further determine the number of cold pages in each of the multiple storage units; and perform GC operations on the storage units whose number of cold pages is greater than a second threshold.

[0178] It should be noted that a cold page refers to a virtual memory page that is no longer used or is not frequently used among the multiple virtual memory pages corresponding to the target storage unit.

[0179] It should also be noted that the second quantity threshold can be pre-set according to demand. For example, the second quantity threshold can be 50%, 40%, etc. of the number of multiple virtual memory pages corresponding to the target storage unit.

[0180] It is worth noting that by separately recycling storage units that meet other conditions, the richness of GC operations can be improved, and the efficiency of GC recycling and the usage space of the target memory can be improved.

[0181] In the embodiments of the present application, after GC is triggered, GC operations can be performed on storage cells in the target memory whose first compression amount is less than a first threshold, thereby achieving independent recycling of storage cells and improving the richness of GC operations. In addition, since the compression amount of the compressed area in the storage cell undergoing GC operation is relatively small, the time spent on decompressing the compressed area is relatively short, which reduces the GC operation's hindrance. This improves the speed of GC operations and, in turn, the efficiency of GC operations.

[0182] Next, the electronic device involved in the embodiments of the present application is described.

[0183] The method provided in the embodiments of the present application can be executed by an electronic device. As an example and not a limitation, the electronic device can be, but is not limited to, a mobile phone sports camera (GoPro), a digital camera, a tablet computer, a desktop computer, a laptop computer, a handheld computer, a notebook computer, a vehicle-mounted device, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), an augmented reality (AR) / 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.

[0184] Figure 9 This is a schematic diagram of the structure of a terminal provided by an embodiment of the present application. Figure 9 The 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 can 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.

[0185] It should be understood that the structures illustrated in the embodiments of the present application do 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, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0186] The processor 110 may include one or more processing units, for example, an application processor (AP), a modem processor, a graphics processing unit (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). The different processing units may be independent devices or integrated into one or more processors.

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

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

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

[0190] It is understood that the interface connection relationship between the modules illustrated in the embodiments of the present application is merely an illustrative 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 from the above embodiments, or a combination of multiple interface connection methods.

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

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

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

[0194] Display screen 194 is used to display images, videos, and the like. 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 (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-oLed, or a quantum dot light-emitting diode (QLED). In some embodiments, electronic device 100 may include one or N display screens 194, where N is an integer greater than one.

[0195] The electronic device 100 can implement a shooting function through an ISP, a camera 193, a video codec, a GPU, a display screen 194, and an application processor.

[0196] 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 via the external memory interface 120 to implement data storage functions. For example, files such as music and videos can be stored on the external memory card.

[0197] 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 can 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 can 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.

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

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

[0200] The touch sensor 180K is also called a "touch panel." The touch sensor 180K can be disposed on the display screen 194. 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 applied thereto or in the vicinity thereof. The touch sensor 180K can transmit the detected touch operations to the application processor to determine the type of touch event. Visual output related to the touch operations can be provided via the display screen 194. In other embodiments, the touch sensor 180K can also be disposed on the surface of the electronic device 100, at a location different from that of the display screen 194.

[0201] The indicator 192 may be an indicator light, which may be used to indicate the charging status, power level changes, messages, missed calls, notifications, etc.

[0202] 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 can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions can 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 can be transmitted from a website, computer, server or data center to another website, computer, server or data center via a wired (such as a coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) method. The computer-readable storage medium can 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 (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital versatile disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).

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

Claims

1. A memory recycling control method, characterized in that: Applied to electronic equipment, the method includes: When the memory occupied by the target application reaches a memory threshold, triggering memory recycling GC for the target application; After the GC is triggered, determining a first compression amount of a compression area contained in each of a plurality of storage units, wherein each storage unit is obtained by dividing a target memory allocated by the target application, and compression occurs when memory data in the compression area is dumped to another memory management space; The GC operation is performed on a storage unit among the plurality of storage units whose first compression amount is less than a first threshold.

2. The method according to claim 1, wherein After the GC is triggered, determining a first compression amount of the compression area included in each storage unit in the plurality of storage units includes: After the GC is triggered, determining the plurality of storage units whose usage status is used from the target memory; A first compression amount of a compressed region included in each of the plurality of storage units is determined.

3. The method according to claim 2, wherein The determining a first compression amount of the compressed area included in each storage unit in the plurality of storage units includes: Obtaining status information of each virtual memory page in a plurality of virtual memory pages corresponding to a target storage unit, wherein the target storage unit is any one of the plurality of storage units; Determining a compression amount of a virtual memory page including a compression identifier in the state information to obtain at least one second compression amount, wherein the compression identifier is used to indicate that the corresponding virtual memory page contains compressed storage data; The at least one second compression amount is added to obtain a first compression amount of the target storage unit.

4. The method according to claim 3, wherein The obtaining of status information of each virtual memory page among the plurality of virtual memory pages corresponding to the target storage unit includes: Obtaining a first virtual address range of the target storage unit; determining, according to the first virtual address range of the target storage unit, a second virtual address range of each virtual memory page in a plurality of virtual memory pages corresponding to the target storage unit from a correspondence between the first virtual address range and the second virtual address range; The status information of each virtual memory page corresponding to the target storage unit is determined according to the second virtual address range of each virtual memory page corresponding to the target storage unit.

5. The method according to claim 3, wherein The method further comprises: When the at least one second compression amount is greater than the first quantity threshold, and each second compression amount is greater than or equal to the second threshold, it is determined that the target storage unit does not need to perform the GC operation.

6. The method according to any one of claims 2 to 5, wherein: After the GC is triggered, determining the plurality of storage units in the target memory as being in use 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; In a case where the trigger type is a preset type, the plurality of storage units whose usage status is that they are already used are determined from the target memory.

7. The method according to claim 6, wherein The electronic device includes 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, where the state transition message is a message sent to the scene recognition module when the target application switches between foreground and background. When the trigger type is a preset type, determining the plurality of storage units in the target memory whose usage status is that they are already used includes: In a case where the trigger type is the preset type, the scene recognition module sends a status acquisition message to the dump information reading module; Upon receiving the status acquisition message, the dump information reading module determines the plurality of storage units from the target memory.

8. The method according to claim 1, wherein The method further comprises: After the GC is triggered, determining the number of cold pages in each of the plurality of storage units; The GC operation is performed on the storage unit where the number of cold pages is greater than a second number threshold.

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.

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.