Memory adjustment method and electronic device
By distinguishing the virtual memory addresses of the apk file and the so file, determining and recycling the memory occupied by the real apk file, the problem of running abnormalities caused by electronic devices when reclaiming application memory is solved, and timely memory recycling and performance improvements are achieved.
Patent Information
- Application Number
- CN202411670772.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2044-11-21
AI Technical Summary
When electronic devices reclaim the memory of the application, it may cause the application to run abnormally, affecting the normal use of the user.
By distinguishing the virtual memory addresses of the apk file and the so file, determine the virtual memory address corresponding to the real apk file, and recycle the memory address after the application is started to achieve timely memory recycling and optimization.
It realizes timely memory recycling, reduces memory pressure, improves the performance of electronic devices, ensures the normal operation of applications, and improves user experience.
Smart Images

Figure CN119166368B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a memory adjustment method and an electronic device. Background Art
[0002] With the development of electronic devices (such as mobile phones), more and more applications (APPs) are installed on electronic devices, but the memory of electronic devices is limited. Therefore, electronic devices need to allocate and recycle the memory of applications during operation.
[0003] However, when the electronic device directly reclaims part of the memory of the application, although it can reduce the memory usage, it may cause the application to run abnormally and affect the normal use of the user. Summary of the invention
[0004] The embodiments of the present application provide a memory adjustment method and an electronic device for implementing memory recycling to reduce memory usage and ensure the normal operation of an application.
[0005] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:
[0006] In a first aspect, the present application provides a memory adjustment method, which is applied to an electronic device. The electronic device receives a first operation. The first operation is used to trigger the start of an application of the electronic device.
[0007] In response to the first operation, the electronic device starts to start the above application. After the application is started, the electronic device can recycle the first target memory address corresponding to the installation package apk file of the application, which represents the virtual memory address corresponding to the actual apk file of the application, that is, the virtual memory address corresponding to the real apk file.
[0008] The first target memory address is obtained based on a virtual memory address corresponding to the first apk file determined during application startup and a virtual memory address corresponding to the second apk file determined after the application startup is completed.
[0009] In the present application, during the application startup, the electronic device determines the virtual memory address corresponding to the first apk file of the current application. Since the first apk file loaded by the electronic device does not include other types of resource files, such as so files, during the application startup, the electronic device determines that the first apk file is a real apk file. Afterwards, after the application startup is completed, the electronic device determines the virtual memory address corresponding to the current second apk file of the application. At this time, the second apk file may include other types of resource files. Therefore, the electronic device needs to use the virtual memory address corresponding to the first apk file and the virtual memory address corresponding to the second apk file to determine the virtual memory address corresponding to the current real apk file and use it as the first target memory address. Afterwards, the electronic device can directly recycle the first target memory address, thereby reclaiming the memory occupied by the real apk file, realizing timely memory recovery, reducing memory pressure, and thus improving the performance of the electronic device. And after the startup is completed, the apk file has little effect on the operation of the application, so even if the memory occupied by the apk file is recycled, the electronic device can run the application normally to ensure the user experience.
[0010] In a possible design, after the application is started, the electronic device can not only determine the first target memory address corresponding to the real apk file, but also determine the second target memory address corresponding to other resource files, such as so files. The second target memory address includes the virtual memory address corresponding to the second apk file except the first target memory address.
[0011] Afterwards, for each second target memory address, the electronic device may reclaim the second target memory address without using the resource file indicated by the second target memory address, and does not reclaim the second target memory address when using the resource file indicated by the second target memory address.
[0012] Based on this, the electronic device can recycle the second target memory address according to demand, release the memory occupied by other resource files, reduce memory pressure, ensure the smooth operation of the electronic device, and do not affect the normal operation of the application, thereby improving user satisfaction. In addition, targeted recycling of different types of addresses is also achieved.
[0013] In a possible design, when the remaining memory of the electronic device is less than a preset memory threshold, the electronic device can determine whether to recycle the second target memory address according to whether the resource file indicated by the second target memory address is used. Based on this, the electronic device can determine whether to recycle the second target memory address when the memory is insufficient, so as to avoid affecting the operation of the application after the second target memory address is recycled.
[0014] Optionally, whether to use the resource file indicated by the second target memory address can be determined by whether the application has a dependency relationship with the second target memory address.
[0015] In one possible design, the above-mentioned first target memory address includes a virtual memory address in the intersection of a first virtual memory address set and a second virtual memory address set, the first virtual memory address set includes the virtual memory addresses corresponding to all first apk files, and the second virtual memory address set includes the virtual memory addresses corresponding to all second apk files.
[0016] Based on this, for each virtual memory address in the second virtual memory address set, if the virtual memory address also belongs to the first virtual memory address set, it indicates that the virtual memory address is the virtual memory address corresponding to the real apk file, and the virtual memory address has not been reallocated. Therefore, the electronic device can determine that the virtual memory address is an address that can be directly recycled at present, so that the electronic device can directly recycle the virtual memory address, which not only reduces memory pressure, but also avoids application crashes caused by memory error recycling.
[0017] Alternatively, the first target memory address includes a virtual memory address corresponding to the identifier of the apk file in the intersection of the first identifier set and the second identifier set. The first identifier set includes the identifiers of all first apk files; the second identifier set includes the identifiers of all second apk files. Based on this, the address that can be directly recycled can be accurately determined.
[0018] In a possible design, the electronic device reclaims the first target memory address through the memory suggestion interface, that is, reclaims the physical memory address corresponding to the first target memory address, in other words, reclaims the memory corresponding to the physical memory address. Based on this, the electronic device can reclaim the memory occupied by the apk file through the memory suggestion interface.
[0019] In a possible design, after receiving the above-mentioned first operation, the electronic device starts the process of the application. After that, the electronic device reads the first process memory mapping maps file of the application. After that, the electronic device can traverse the first maps file to determine the mapping information of the first apk file from the first maps file. The mapping information of the first apk file includes the virtual memory address corresponding to the first apk file. After that, the electronic device initializes the process of the application.
[0020] Based on this, before the application process is initialized, the apk file loaded by the electronic device is more likely to be a real apk file, while the possibility of loading other types of resource files, such as so files, is very small. Therefore, the electronic device can read the memory mapping of the current application, that is, the first maps file, to obtain the mapping information of the first apk file from the first maps file, and ensure that the mapping information of the first apk file is the mapping information of the real apk file.
[0021] Optionally, the first maps file includes an identifier of a resource file and a corresponding address. Accordingly, the process of traversing the first maps file to determine the mapping information of the first apk file from the first maps file may include:
[0022] For the identifier of each resource file in the first map file, when the identifier of the resource file indicates an apk type, the electronic device can use the identifier of the resource file as the identifier of the first apk file and use the address corresponding to the identifier of the resource file as the virtual memory address corresponding to the first apk file.
[0023] Optionally, if the identifier of the resource file indicates an apk type, and the type of the address corresponding to the identifier of the resource file is a cache type, the electronic device can use the address corresponding to the identifier of the resource file as the virtual memory address corresponding to the first apk file.
[0024] In a possible design, after the application is started, the electronic device can read the second maps file of the application. Afterwards, the electronic device can traverse the second maps file to determine the mapping information of the second apk file from the second maps file, and the mapping information of the second apk file includes the virtual memory address corresponding to the second apk file.
[0025] Based on this, after the application is started, the memory occupied by the application is basically stable, and the memory occupied by the apk file of the application includes not only the memory occupied by the real apk file but also the memory occupied by the so file. Therefore, the electronic device reads the memory mapping of the current application, that is, the second maps file, to obtain the mapping information of the second apk file from the second maps file, and then determines the real apk file from the mapping information of the second apk file.
[0026] In a second aspect, the present application provides a chip, the chip comprising a communication interface and at least one processor:
[0027] The communication interface is used to input and / or output signaling or data;
[0028] The at least one processor is used to execute a computer program to implement the memory adjustment method as described in any one of the first aspects above.
[0029] In a third aspect, the present application provides an electronic device, comprising a memory and one or more processors; the display screen, the memory and the processor are coupled; the memory is used to store computer program code, and the computer program code comprises computer instructions; when the processor executes the computer instructions, the electronic device executes a memory adjustment method as described in any one of the above-mentioned first aspects.
[0030] In a fourth aspect, the present application provides a computer-readable storage medium, comprising computer instructions, which, when executed on an electronic device, enables the electronic device to execute a memory adjustment method as described in any one of the above-mentioned first aspects.
[0031] In a fifth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the memory adjustment method as described in any one of the first aspects above.
[0032] It can be understood that the beneficial effects that can be achieved by the chip described in the second aspect, the electronic device described in the third aspect, the computer-readable storage medium described in the fourth aspect, and the computer program product described in the fifth aspect provided above can refer to the beneficial effects in the first aspect and any possible implementation method thereof, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 A schematic diagram of a memory statistical distribution provided in an embodiment of the present application Figure 1 ;
[0034] Figure 2 A schematic diagram of a virtual memory address mapping provided in an embodiment of the present application;
[0035] Figure 3 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application Figure 1 ;
[0036] Figure 4 A flowchart of a memory adjustment method provided in an embodiment of the present application;
[0037] Figure 5 A schematic diagram of a startup scenario provided in an embodiment of the present application;
[0038] Figure 6 A schematic diagram of a memory statistical distribution provided in an embodiment of the present application Figure 2 ;
[0039] Figure 7 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application Figure 2 ;
[0040] Figure 8 A schematic diagram of the structure of a chip system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0041] In order to facilitate the clear description of the technical solutions of the embodiments of the present application, in the embodiments of the present application, the words "exemplary" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" or "for example" in the present application should not be interpreted as being more preferred or more advantageous than other embodiments or design solutions. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way. In the embodiments of the present application, "at least one" refers to one or more, and "multiple" refers to two or more. "And / or" describes the association relationship of the associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple. In the embodiments of the present application, "first", "second", "1", "2" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this embodiment, unless otherwise specified, "multiple" means two or more.
[0042] In order to facilitate understanding of the technical solution provided by this application, some technical terms involved in this application are explained below.
[0043] Virtual memory address refers to the address of virtual memory, which is the memory address that an application (hereinafter referred to as application) can see when it is running. When an application is running, the electronic device allocates an independent virtual memory space for the application. The address of the virtual memory space is continuous, and other applications cannot directly access the virtual memory space.
[0044] The physical memory address represents the address of the physical memory, which is the actual memory hardware of the electronic device, namely the random access memory (RAM). The physical memory is used to store the data of the running application. There is a mapping relationship (or correspondence relationship) between the physical memory address and the above virtual memory address. When the application accesses the virtual memory address, the electronic device accesses the corresponding physical memory address through the virtual memory address to access the corresponding data.
[0045] Memory recycling means recycling the physical memory address corresponding to the virtual memory address, while the virtual memory address itself is still retained. In addition, after the physical memory address corresponding to the virtual memory address is recycled, when the application accesses the virtual memory address again, since the physical memory address corresponding to the virtual memory address does not exist, the electronic device reloads the data requested by the application to the physical memory and re-records the mapping relationship between the virtual memory address and the physical memory address storing the data.
[0046] Proportional set size (Pss) indicates the physical memory actually occupied by a single process when it is running (including the memory occupied by proportionally allocated shared libraries). The shared library memory in PSS is calculated proportionally. If a shared library is used by N processes, the size of the PSS proportionally allocated to a process can be: 1 / N. PSS can clearly indicate the actual usage of a single process in the total system memory.
[0047] The memory advise (madvise) interface is used to provide the kernel of the electronic device with operation advice or instructions for a certain memory space. In most cases, the goal of the operation advice or instruction is to improve the performance of the system or application. For example, the operation advice for the memory space with the starting address of addr and the length of length is to recycle. Exemplarily, the memory advise interface can be located in the sys / mman.h function library.
[0048] A cold start refers to the way an application process is started from scratch. Before the application is started, the electronic device does not have a process for the application. During the application startup, the electronic device creates the process for the application and also creates an activity for the application. For example, starting an application for the first time after the electronic device is turned on, or starting the application process again after being cleared, can be called a cold start. It should be understood that the application's activity is used to implement the application's interface, the application's activity can belong to the application's process, and the application's activity can run in the application's process.
[0049] A shared object file (so) is a binary file format used to store executable code and data of an application. When an application is running, the so file is dynamically linked to other applications or libraries.
[0050] The above introduces the terms involved in this application, and the following will continue to introduce the technical solutions involved in this application.
[0051] During the use of electronic devices (such as mobile phones), applications on the mobile phone may occupy a large amount of memory (i.e., physical memory). In order to avoid the phone from freezing due to excessive memory usage, the phone needs to recycle memory to reduce unnecessary memory usage. In some embodiments, the phone can recycle memory through a garbage collection mechanism. The phone (such as the phone's operating system) can automatically detect memory that is no longer used by the application. Afterwards, the phone can recycle memory that is no longer used by the application. However, when the phone uses the garbage collection mechanism to recycle memory, it may not be able to effectively recycle certain non-stack memory, such as the memory occupied by the application's installation package (Android package, apk), resulting in excessive memory usage of the phone, reduced phone performance, and affecting the user's normal use.
[0052] For example, see Figure 1 As shown in the memory statistics distribution diagram, the memory that can be reclaimed by the garbage collection mechanism includes the memory corresponding to DalvikHeap and .art mmap, that is, the private memory corresponding to Dalvik Heap and .art mmap can be reclaimed. The private memory is the sum of private dirty memory pages (Private Dirty) and private clean memory pages (Private Clean). The size of the private memory is (19088+0)+(1156+0)=20244KB. In other words, the Java Heap can be reclaimed. However, the garbage collection mechanism cannot reclaim the memory corresponding to .apk mmap, that is, it cannot reclaim the private memory corresponding to .apk mmap, and the size of the private memory is 26024KB.
[0053] in addition, Figure 1 The proportional setting size (Pss) corresponding to the Code in area 10 shown is Figure 1 The sum of the private memory (i.e., Private Clean and Private Dirty) corresponding to the sub-items such as .so mmap, .jar mmap, .apk mmap, .dex mmap, and .oat mmap in area 11 shown. The Pss corresponding to Code represents the sum of the private memory occupied by the shared library so file, jar file, apk file, dex file, and oat file.
[0054] And the total amount of proportional setting size in the above area 11 (i.e. Pss Total) includes not only the memory exclusively used by the process (i.e. private memory), but also the shared memory between processes (i.e. the above shared library memory). The size of this shared memory is the Pss corresponding to System in area 10. Therefore, Pss Total in area 11 (i.e. 118380KB) is the sum of the TOTAL of PrivateClean, the TOTAL of Private Dirty, and the Pss corresponding to System, i.e. Pss Total=77248KB+27028KB+14104KB.
[0055] Although the memory occupied by the apk file (such as the private memory occupied by the above-mentioned apk file) cannot be recovered through the garbage collection mechanism, the mobile phone can reclaim the memory through the madvise interface. The mobile phone can use the starting address, length and the flag indicating recovery (such as MADV_DONTNEE) of the virtual memory address corresponding to the apk file to be recovered as the input parameters of the madvise interface to call the madvise interface to recover the physical memory address corresponding to the virtual memory address occupied by the apk file, thereby realizing the recovery of the memory occupied by the apk file. It should be understood that the flag indicating recovery represents the above-mentioned operation suggestion or instruction, which is used to trigger the recovery of memory.
[0056] However, the apk file of the application includes the so file. When some mobile phones load the apk file of the application, they directly load the so file in the apk file. That is to say, when loading the apk file, the so file is loaded, so that the memory space occupied by the apk file includes the memory space occupied by the so file. Optionally, the so file can be loaded in a dynamic link (loadLibrary) manner.
[0057] For example, if Figure 2 The virtual memory address 15 corresponding to the apk file shown is actually the virtual memory address corresponding to the so file, and the virtual memory address corresponding to the actual apk file (i.e., the real apk file) is the virtual memory address 16. In other words, the physical memory space corresponding to the physical memory address corresponding to the virtual memory address 15 (in short, the memory space corresponding to the virtual memory address 15) is actually the memory space occupied by the so file, but the mobile phone will mistakenly believe that the memory space corresponding to the virtual memory address 15 is the memory space occupied by the apk file.
[0058] Therefore, if the memory space occupied by the apk file of the application is directly reclaimed, the mobile phone will also reclaim the memory space occupied by the so file. The operation of the application depends on the so file, which may cause abnormal operation of the application and affect the normal use of the user.
[0059] It should be noted that some electronic devices do not load the so file directly from the apk file, but first decompress the apk file and obtain the so file from the decompressed apk file. After that, the mobile phone loads the apk file that does not include the so file, and then, when the so file needs to be loaded, it loads the so file. In other words, the apk file and the so file are loaded separately, so the memory space occupied by the apk file does not include the memory space occupied by the so file. In this way, even if the memory space occupied by the apk file of the application is directly reclaimed, the memory space occupied by the so file will not be reclaimed, so it will not affect the operation of the application.
[0060] It should be understood that when starting an application, the mobile phone needs to load the apk file of the application. After the application is started, the mobile phone can recycle the apk file, and recycle the apk file has no effect on the process of the application, that is, after the application is started, even if the apk file is recycled, the application can run normally.
[0061] Based on this, in response to the above problems, the present application provides a solution for distinguishing the virtual memory addresses of apk files and so files. Considering that although the so file belongs to the apk file, the order in which the so file is loaded is later than the actual apk file. Therefore, the electronic device compares the virtual memory addresses loaded when and after the application is started, determines the virtual memory address corresponding to the apk file, and the virtual memory address corresponding to the so file, and realizes accurate identification of different types of virtual memory addresses. Afterwards, the electronic device adopts different recycling methods for different types of virtual memory addresses, thereby realizing targeted memory recycling, so that no longer needed memory resources can be recycled in time, and the required memory is avoided from being recycled, thereby improving the performance of the electronic device, avoiding application crashes due to memory error recycling, and improving user satisfaction.
[0062] Exemplarily, the electronic device in the embodiments of the present application may be a mobile phone, a tablet computer, a desktop, a laptop, a handheld computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, as well as a wearable device, a personal digital assistant (PDA), an augmented reality (AR) device, a virtual reality (VR) device, and other devices that can install an APP. The embodiments of the present application do not impose any special restrictions on the specific form of the electronic device.
[0063] For example, Figure 3 FIG. 2 shows a schematic diagram of the structure of the electronic device 200. Figure 3 As shown, the electronic device 200 may include a processor 210, an external memory interface 220, an internal memory 221, a universal serial bus (USB) interface 230, a charging management module 211, a power management module 212, a battery 213, an antenna 1, an antenna 2, a mobile communication module 240, a wireless communication module 250, an audio module 270, a speaker 270A, a receiver 270B, a microphone 270C, an earphone interface 270D, a sensor module 280, a button 290, a motor 291, an indicator 292, a camera 293, a display screen 294, and a subscriber identification module (SIM) card interface 295, etc.
[0064] It is to be understood that the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the electronic device 200. In other embodiments of the present application, the electronic device 200 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.
[0065] The processor 210 may include one or more processing units, for example, the processor 210 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a 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.
[0066] The controller may be the nerve center and command center of the electronic device 200. 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.
[0067] The processor 210 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 210 is a cache memory. The memory may store instructions or data that the processor 210 has just used or cyclically used. If the processor 210 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 210, and thus improves the efficiency of the system.
[0068] In some embodiments, the memory in the electronic device may also include RAM and read-only memory (ROM). RAM can also be used as internal memory.
[0069] The wireless communication function of the electronic device 200 can be implemented through the antenna 1, the antenna 2, the mobile communication module 240, the wireless communication module 250, the modem processor and the baseband processor.
[0070] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in the electronic device 200 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.
[0071] The mobile communication module 240 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 200. The mobile communication module 240 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 240 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 240 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 240 can be set in the processor 210. In some embodiments, at least some of the functional modules of the mobile communication module 240 can be set in the same device as at least some of the modules of the processor 210.
[0072] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 270A, a receiver 270B, etc.), or displays an image or video through a display screen 294. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 210 and be set in the same device as the mobile communication module 240 or other functional modules.
[0073] The wireless communication module 250 can provide wireless communication solutions including wireless local area networks (WLAN) (such as Wi-Fi (wireless fidelity)), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 200. The wireless communication module 250 can be one or more devices integrating at least one communication processing module. The wireless communication module 250 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and filters it, and sends the processed signal to the processor 210. The wireless communication module 250 can also receive the signal to be sent from the processor 210, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0074] The electronic device 200 implements the display function through a GPU, a display screen 294, and an application processor.
[0075] The display screen (or screen) 294 is used to display images, videos, etc. In some embodiments, the electronic device 200 may include 1 or N display screens 294 , where N is a positive integer greater than 1.
[0076] The electronic device 200 can realize the shooting function through ISP, camera 293, video codec, GPU, display screen 294 and application processor.
[0077] The external memory interface 220 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 200.
[0078] The internal memory 221 can be used to store computer executable program codes, which include instructions. The processor 210 executes various functional applications and data processing of the electronic device 200 by running the instructions stored in the internal memory 221. The internal memory 221 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 200 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 221 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.
[0079] The electronic device 200 can implement audio functions such as music playing and recording through the audio module 270, the speaker 270A, the receiver 270B, the microphone 270C, the headphone jack 270D, and the application processor.
[0080] The buttons 290 include a power button, a volume button, etc. The indicator 292 may be an indicator light.
[0081] The sensor module 280 may include a pressure sensor, a gyro sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, and the like.
[0082] The present application provides a memory adjustment method. After receiving a startup operation for an application, in response to the startup operation, the electronic device starts to start the application and reads the process memory mapping (maps) file 1 of the application. The maps file 1 records the memory mapping of the current application, which includes the identifier of the apk file 1 and its corresponding virtual memory address. Here, apk file 1 is a real apk file and does not include a so file. Afterwards, after the application is started, the so file has also been loaded, and the electronic device can re-read maps file 2, which includes the identifier of the apk file 2 and its corresponding virtual memory address. Here, apk2 not only includes a real apk file, but may also include a so file.
[0083] Therefore, the electronic device can take the intersection of the virtual memory address corresponding to the identifier of apk file 1 and the virtual memory address corresponding to the identifier of apk file 2 to obtain the immediate recovery address. The immediate recovery address set represents the virtual memory address corresponding to the current real apk file, and realizes the screening of the virtual memory address of the apk file. The electronic device can directly recover the immediate recovery address through the madvise interface to realize the timely and accurate recovery of the memory occupied by the apk file, reduce unnecessary memory occupation, ensure the performance of the electronic device, and because the memory occupied by the so file is not recovered, the normal operation of the application can be guaranteed. In addition, the electronic device can also use the address other than the immediate recovery address in the virtual memory address corresponding to the identifier of apk file 2 as the marked recovery address. The marked recovery address includes the virtual memory address corresponding to the so file, and realizes the distinction between the virtual memory address of the so file and the virtual address of the apk file. Afterwards, when the memory pressure is large, the electronic device can determine whether the marked recovery address needs to be recovered by judging whether the marked recovery address will be used again, thereby reducing the memory pressure, improving the system performance, and avoiding the user's use being affected.
[0084] The following will take the above electronic device as a mobile phone and the application as a social application as an example to introduce the above memory adjustment method. Figure 4 As shown, the memory adjustment method may include the following steps:
[0085] S301. A mobile phone receives a start-up operation for a social application.
[0086] S302: In response to the start operation, the mobile phone cold starts the social application to start the process of the social application.
[0087] The startup operation (as an example of the first operation) may be an operation that can trigger a cold start of the social application. For example, the startup operation may be a click operation on an icon of the social application. Figure 5 The click operation of the social application icon 21 on the desktop 20 shown in the figure, because the mobile phone does not have the process of the social application, the mobile phone starts the cold start of the social application, starts the process of the social application, that is, creates the process of the social application. Of course, the click operation of the social application icon here is only an example operation of the start operation, and the start operation can also be other types of operations, such as voice operation, etc.
[0088] S303: After the process of the social application is started, the mobile phone reads the maps file and uses it as the process memory mapping file 1.
[0089] Among them, maps file 1 (or the first maps file) represents the memory mapping status after the process of the social application is started and before the process is initialized. Maps file 1 includes the identifier of resource file 1 currently mapped to the memory and its corresponding virtual memory address. Here, resource file 1 includes the apk file of the social application.
[0090] Exemplarily, the mobile phone can read the maps file of the social application from the / proc / pid of the social application / maps file path, and use the maps file as the maps file 1. The pid of the social application represents the port number of the social application.
[0091] S304 , the mobile phone traverses the process memory mapping file 1 to determine the identifier of the installation package file 1 .
[0092] The identifier of resource file 1 indicates the type of resource file 1. For example, the identifier may be a name. The suffix of the name of resource file 1 indicates the type of resource file 1. For example, Figure 2 The / system / app / HnLanucher6 / HnLanucher6.apk shown is a resource file, and its suffix is apk, so the resource file is an apk file. Of course, the identifier may not be a name, such as the number of the resource file, and the characters at a specific position of the number indicate the type of the resource file.
[0093] In the embodiment of the present application, for each identifier of resource file 1 in map file 1, the mobile phone determines whether the identifier of resource file 1 indicates an apk type. In the case where the identifier of resource file 1 indicates an apk type, the mobile phone can determine that resource file 1 is apk file 1 (or referred to as the first apk file), that is, the identifier of resource file 1 is the identifier of apk file 1.
[0094] When the identifier of the resource file 1 does not indicate the apk type, the mobile phone can determine that the resource file 1 is not an apk file, that is, the identifier of the resource file 1 is not the identifier of the apk file 1.
[0095] Exemplarily, for the name of each resource file 1 in the map file 1, when the suffix of the name of the resource file 1 is of the apk type, the mobile phone can determine that the name of the resource file 1 is the name of the apk file 1. When the suffix of the name of the resource file 1 is not of the apk type, the mobile phone can determine that the name of the resource file 1 is not the name of the apk file 1.
[0096] S305 . The mobile phone obtains a startup address set based on the virtual memory address corresponding to the identifier of the installation package file 1 in the process memory mapping file 1 .
[0097] The startup address set (or first virtual memory address set) includes at least one startup address, which represents the virtual memory address corresponding to apk file 1. That is, the startup address set represents the memory address set of the apk file mapping when the social application is started. For example, the startup address set includes the above Figure 2 Each of the virtual memory addresses 16 is shown.
[0098] In the embodiment of the present application, when the social application is started, the mobile phone initializes the memory recycling mechanism. The memory recycling mechanism records the type of resource files that need to be recycled, such as the apk type. Afterwards, after the social application is created and before it is initialized, the mobile phone can read the maps file 1 and determine the identifier of the apk file 1 that needs to be recycled in the maps file 1. Afterwards, the mobile phone can use the virtual memory address corresponding to the identifier of the apk file 1 as the startup address.
[0099] Optionally, the memory recycling mechanism also records the address type that needs to be recycled. For example, the address type includes a cache address type, that is, a virtual memory address type. Accordingly, the above-mentioned maps file 1 may include the identifier of the resource file 1 and its corresponding address.
[0100] When the identifier of resource file 1 in maps file 1 is the identifier of apk file, and the type of address corresponding to the identifier of resource file 1 is a virtual memory address type, it can be determined that the file is apk file 1.
[0101] In some embodiments, the mobile phone can call the attachBaseContext function to initialize the memory recycling mechanism.
[0102] S306. The mobile phone caches a set of startup addresses.
[0103] In some embodiments, the cached boot address set is only an example of storing the boot address set, and the mobile phone can also store the boot address set in other ways, such as storing it in ROM. However, the cached boot address set can improve the reading speed of subsequent boot address sets.
[0104] S307, the mobile phone initializes the process of social application.
[0105] In the embodiment of the present application, since the possibility of loading the so file of the social application before the process of the social application is initialized is very small, therefore, the possibility that the virtual memory address corresponding to the apk file 1 before the process of the social application is initialized includes the virtual memory address corresponding to the so file is very small, and the possibility that the apk file 1 is a real apk file is very high, thereby achieving accurate determination of the virtual memory address corresponding to the apk file of the social application.
[0106] S308. The mobile phone displays the startup content through the process of the social application.
[0107] In the embodiment of the present application, after the process of the social application is initialized, the mobile phone can load the startup content of the social application through the process of the social application. Figure 5 As shown, the mobile phone starts cold starting the social application and displays the startup content 22 of the social application.
[0108] In some embodiments, considering that after the application is started, the so file of the application has been loaded, that is, there is a virtual memory address corresponding to the so file. However, since the so file is loaded from the apk file, the virtual memory address corresponding to the so file is also used as the virtual memory address corresponding to the apk file. Therefore, the mobile phone needs to filter out the virtual memory address corresponding to the real apk file from the virtual memory address corresponding to the apk file so that the mobile phone can reclaim the memory occupied by the real apk file. In order to filter out the virtual memory address corresponding to the real apk file, the mobile phone needs to determine the virtual memory address corresponding to the apk file after the startup is completed. The following will continue to introduce the process of determining the virtual memory address corresponding to the apk file after the startup is completed.
[0109] S309 . In response to the initiation of the content stopping display, the mobile phone displays the interface 1 of the social application.
[0110] For example, the mobile phone can also draw the interface 1 of the social application through the process of the social application. Afterwards, after the startup is completed, the mobile phone stops displaying the startup content and continues to display the interface 1 of the social application. For example, as described above Figure 5 As shown, after the mobile phone is started up, the interface 23 of the social application is displayed, and the interface 23 can be understood as the interface 1.
[0111] In some embodiments, the above S303-S305 introduces the process of determining the virtual memory address corresponding to the apk file before the process is initialized. That is, the mobile phone determines the startup address set before the process of the social application is initialized. This is only an example. The mobile phone can also determine the startup address set at other times. For example, the mobile phone determines the startup address set after the initialization process but before the startup is completed. In general, the mobile phone can read the maps file 1 during the startup of the social application to use the maps file to determine the startup address set.
[0112] S310: The mobile phone re-reads the process memory mapping file and uses it as process memory mapping file 2.
[0113] In the embodiment of the present application, after the startup is completed, the memory resources occupied by the social application have been basically stable, and the so file has been loaded, that is, the so file has been mapped to the memory. Therefore, the mobile phone can read the latest maps file and use the read maps file as maps file 2.
[0114] Similar to the above-mentioned maps file 1, maps file 2 (or referred to as the second maps file) represents the memory mapping after the process is initialized. Maps file 2 includes the identifier of resource file 2 of the social application currently mapped to the memory and its corresponding virtual memory address. Here, resource file 2 may include the apk file of the social application, but the apk file may be a so file.
[0115] Exemplarily, the mobile phone may also read the maps file 2 from the / proc / social application's pid / maps file path.
[0116] In some embodiments, after the social application is started, the mobile phone can reinitialize the memory recycling mechanism to use the initialized memory recycling mechanism to determine the identifier of the required apk file and its corresponding virtual memory address. The use of the memory recycling mechanism to determine the identifier of the apk file and its corresponding virtual memory address can refer to the relevant content of the memory recycling mechanism introduced above.
[0117] S311. The mobile phone traverses the process memory mapping file 2 to determine the identifier of the installation package file 2.
[0118] The process of the mobile phone determining the identifier of the apk file 2 (or the second apk file) is similar to the process of determining the identifier of the apk file 1, which will not be repeated here.
[0119] S312: The mobile phone obtains a set of running addresses based on the virtual memory address corresponding to the identifier of the installation package file 2 in the process memory mapping file 2.
[0120] The running address set (or referred to as the second virtual memory address set) includes at least one running address, which represents the virtual memory address corresponding to the apk file 2. That is, the running address set represents the memory address set of the apk file mapping after the social application is started.
[0121] In the embodiment of the present application, after the social application is started, the mobile phone parses the read maps file 2 to match the identifier of the recyclable apk file 2 in the maps file 2. Afterwards, the mobile phone can use the virtual memory address corresponding to the identifier of the apk file 2 as the running address.
[0122] For example, after the process of the social application is started, the mobile phone can read the maps file 2 after time 1 has passed. In other words, when the mobile phone receives the start operation of the social application, it can read the maps file 2 after time 1 has passed. For example, in response to the user's start operation of the social application, the mobile phone starts the process of the social application, and the mobile phone first reads the maps file 1. Afterwards, after 5 minutes, the mobile phone reads the maps file 2.
[0123] Among them, time 1 is greater than the startup time of the social application, so that maps file 2 is read after the social application has been started. The specific value of time 1 can be set according to demand, and this application does not limit it.
[0124] In some embodiments, after determining the running address set, the mobile phone may also cache the running address set, so that the mobile phone can use the running address set and the above-mentioned startup address set to determine the immediate recovery address and the marked recovery address described below according to needs. For example, after determining the running address set, the mobile phone can use the running address set and the above-mentioned startup address set to determine the immediate recovery address and the marked recovery address. Alternatively, when the memory is insufficient, the mobile phone can read the running address set and the above-mentioned startup address set from the cache to determine the immediate recovery address and the marked recovery address.
[0125] As can be seen from the above statements, since the so file is loaded from the apk, the identifier of apk file 2 may actually be the identifier of the so file, and the virtual memory address corresponding to the apk file in maps file 2 may actually be the virtual memory address corresponding to the so file. In addition, the recycling of the memory occupied by the real apk file will not affect the normal operation of the social application, while the recycling of the memory occupied by the so file will affect the normal operation of the social application. Therefore, the mobile phone needs to filter the real apk file in apk file 2. The following will continue to introduce the screening process of the real apk file.
[0126] S313. The mobile phone determines the intersection of the startup address set and the running address set to obtain an immediate recovery address.
[0127] S314. The mobile phone uses the running addresses in the running address set except the immediate recovery addresses as marked recovery addresses.
[0128] In some embodiments, the above S314 may also be alternatively described as taking the running addresses in the running address set except the startup address set as marked recycling addresses.
[0129] The immediately reclaimed address (or first target memory address) indicates the virtual memory address corresponding to the real apk file that belongs to both the startup address set and the running address set, that is, the virtual memory address corresponding to the apk file that has not been reallocated. Specifically, the immediately reclaimed address indicates the virtual memory address that can be reclaimed immediately.
[0130] The marked recovery address (or second target memory address) indicates a virtual memory address that belongs to the running address set but not to the startup address set. The virtual memory address may be the virtual memory address of the so file. Specifically, the marked recovery address indicates that the virtual memory address that may affect the normal operation of the social application is immediately recovered.
[0131] In the embodiment of the present application, since the startup address set is recorded before the process of the social application is initialized, the apk file corresponding to the startup address in the startup address set is a real apk file. In addition, considering that during the startup period or the operation period, the mobile phone may have recovered the virtual memory addresses corresponding to some apk files loaded before the process is initialized, and the recovered virtual memory addresses are reallocated to other resource files. Therefore, for each running address in the running address set, if the startup address set also has the same startup address as the running address, it indicates that the running address is the virtual memory address corresponding to the real apk file, and the virtual memory address has not been reallocated, so the mobile phone can use the running address as an immediate recovery address.
[0132] If the startup address set does not contain the same startup address as the running address, it indicates that the running address is not the virtual memory address corresponding to the real apk file. The running address may be the virtual memory address corresponding to other resource files, such as so files, and the virtual memory address has not been reallocated. In this way, the mobile phone can use the running address as a marked recovery address and does not directly recycle the marked recovery address. In addition, it can be understood that the virtual memory address that belongs to the startup address set but does not belong to the running address set has been reallocated, so there is no need to recycle the virtual memory address.
[0133] The above-mentioned running period refers to the period after the social application has been started and completed.
[0134] For example, the above startup address set includes: Figure 2 The virtual memory address 16 shown in FIG. 16. The above-mentioned operation address set includes: Figure 2The virtual memory address 15 shown. The mobile phone can determine the virtual memory address 16 corresponding to the real apk file and the virtual memory address 15 corresponding to the so file by taking the intersection of the virtual memory address 16 and the virtual memory address 15, thereby accurately distinguishing the virtual memory addresses corresponding to different types of files.
[0135] In some embodiments, the above-mentioned immediate recycling address may include multiple addresses, which is actually an address range, including a start address and an end address. Figure 2 The address range 7c13ee6000-7c145a7000 shown in the figure represents an immediate recovery address. 7c13ee6000 is the starting address of the immediate recovery address, and 7c145a7000 is the ending address of the immediate recovery address. The difference between 7c145a7000 and 7c13ee6000 represents the length of the immediate recovery address.
[0136] Similarly, a marked recycling address is actually an address area, which includes multiple addresses. For example, Figure 2 The address range 7c1b946000-7c1b94e000 shown in the figure represents a mark recovery address. 7c1b946000 is the starting address of the mark recovery address, and 7c1b94e000 is the ending address of the mark recovery address. The difference between 7c1b94e000 and 7c1b946000 represents the length of the mark recovery address.
[0137] In some embodiments, the method in which the mobile phone determines the immediate recovery address and the marked recovery address by taking the intersection of the startup address set and the running address set and using the intersection is only a possible implementation method for determining the immediate recovery address and the marked recovery address. The mobile phone can also obtain a startup identification set (or a first identification set) based on the identification of the above-mentioned apk file 1, and the startup identification set includes the identification of apk file 1. And the mobile phone obtains a running identification set (or a second identification set) based on the identification of the above-mentioned apk file 2, and the running identification set includes the identification of apk file 2.
[0138] Afterwards, the mobile phone obtains an immediate recycling flag based on the intersection of the startup flag set and the running flag set, and uses the virtual memory address corresponding to the immediate recycling flag as the immediate recycling address. Also, the mobile phone can use the flags other than the immediate recycling flag in the running flag set as marked recycling flags, and use the virtual memory address corresponding to the marked recycling flag as the marked recycling address.
[0139] Specifically, the process by which the mobile phone determines the immediate recovery address and the marked recovery address through the identifier of apk file 1 and the identifier of apk file 2 is similar to the implementation process by which the above-mentioned mobile phone determines the immediate recovery address and the marked recovery address through the virtual memory address corresponding to the identifier of apl file 1 and the virtual memory address corresponding to the identifier of apk file 2.
[0140] In some embodiments, after obtaining the marked recycling address, the mobile phone may cache the marked recycling address for subsequent recycling of the marked recycling address by the mobile phone.
[0141] After filtering out the immediate recovery addresses and the marked recovery addresses, the immediate recovery addresses and the marked recovery addresses can be targeted for recovery based on different address types, thereby reducing unnecessary memory usage and avoiding social operation crashes. The implementation process of targeted memory recovery will continue to be introduced below.
[0142] S315. The mobile phone recycles the immediate recycle address through the memory suggestion interface.
[0143] Exemplarily, for each immediate recovery address, the mobile phone can call the madvise interface, and use the starting address, address length, and identifier indicating recovery of the immediate recovery address as input parameters of the madvise interface, so as to recover the immediate recovery address through the madvise interface, that is, to recover the physical memory address corresponding to the immediate recovery address, thereby realizing timely and accurate recovery of the memory occupied by the real apk file, reducing the memory occupation of social applications, and ensuring the performance of the mobile phone. Of course, the mobile phone can also use the starting address, end address, and identifier indicating recovery of the immediate recovery address as input parameters of the madvise interface. Exemplarily, the identifier indicating the type of recovery can be MADV_DONTNEED.
[0144] S316: When the remaining memory is less than the preset memory threshold, for each marked recycling address, the mobile phone determines whether to use the marked recycling address.
[0145] Whether to use the marked recycling address indicates whether to use the resource file corresponding to the marked recycling address.
[0146] In the embodiment of the present application, when the mobile phone memory is insufficient, the mobile phone can recycle the occupied memory to reduce the memory pressure. For each marked recycling address, when the mobile phone uses the marked recycling address, it indicates that the social application needs to use the resource file corresponding to the marked recycling address. If the marked recycling address is recycled, it may cause the social application to crash. Therefore, the mobile phone cannot directly recycle the marked recycling address, and the mobile phone can execute S317.
[0147] In the case where the marked recycling address is not used, it indicates that the social application does not need to use the resource file corresponding to the marked recycling address, and recycling the marked recycling address will not affect the operation of the social application. Therefore, the mobile phone can directly recycle the marked recycling address, that is, the mobile phone can execute S318.
[0148] In some embodiments, the mobile phone can determine whether to use the marked recycling address by judging whether the social application has a dependency relationship with the recycling address. If there is a dependency relationship, it indicates that the operation of the social application also needs to rely on the resource file corresponding to the marked recycling address, and the mobile phone can determine to use the marked recycling address. If there is no dependency relationship, it indicates that the social application does not need to rely on the resource file corresponding to the marked recycling address, and the mobile phone can determine not to use the marked recycling address.
[0149] Specifically, if the marked recycling address is referenced by the process of the social application, the marked recycling address has a dependency relationship with the social application. If the marked recycling address is not referenced by the process of the social application, the marked recycling address has no dependency relationship with the social application.
[0150] S317. The mobile phone does not recycle the marked recycling address.
[0151] S318, the mobile phone recycles the marked recycling address.
[0152] In the embodiment of the present application, the above S316-S318 can be implemented by the mobile phone through the kernel. The mobile phone determines whether to use the marked recycling address through the kernel. If used, the kernel does not need to recycle the marked recycling address. If not used, the kernel recycles the marked recycling address. Of course, in essence, the above S316-S318 are still implemented by the mobile phone.
[0153] Exemplarily, the key pseudo code of the implementation process of the above S311-S318 may be as follows:
[0154] Try to open / proc / social application's pid / maps file: / / traverse the maps file (i.e. the maps file 2 mentioned above);
[0155] While traversing the maps file is not finished:
[0156] If the name of the apk file is matched:
[0157] Parse the name and address of the apk file;
[0158] If the file address is a cache type address:
[0159] Run address set Add the address of the current apk file; / / The cache type address refers to the virtual memory address;
[0160] Reclaim address set immediately = (running address set RetainAll starting address set); / / RetainAll means taking the intersection;
[0161] Mark the recycled address set = (run address set RemoveAll start address set); / / RemoveAll means remove;
[0162] While Immediately Reclaim Address Collection:
[0163] Madvise(start address, end address, MADV_DONTNEED); / / MADV_DONTNEED indicates recycling;
[0164] While mark the collection of recycled addresses:
[0165] Madvise(start address, end address, MADV_COLD) / / MADV_COLD indicates that the kernel needs to determine whether to recycle.
[0166] The above-mentioned immediate recycling address set includes the above-mentioned immediate recycling address. The above-mentioned marked recycling address set includes the above-mentioned marked recycling address.
[0167] In some embodiments, the above S315 introduces that the immediate recovery address is only recovered through the madvise interface as a possible implementation method of the immediate recovery address. The mobile phone can also recover the immediate recovery address through other methods. For example, the mobile phone can also recover the immediate recovery address through the kernel. However, when recovering through the kernel, the mobile phone needs to determine whether to use the immediate recovery address. Therefore, compared with recovering the immediate recovery address through the kernel, recovering the immediate recovery address through the madvise interface can increase the recovery speed of the immediate recovery address.
[0168] In some embodiments, the process of determining the marked recycling address described in S314 and recovering the marked recycling address described in S316-S318 is optional, and the mobile phone may not determine the marked recycling address, and accordingly, there is no need to recover the marked recycling address.
[0169] It should be noted that the social application introduced above is only an example, and the mobile phone can use the memory adjustment method introduced above to reclaim the memory occupied by any application on the mobile phone. Correspondingly, the startup operation of the application can not only be an operation for the application, but also an operation that is not targeted at the application, but can trigger the startup of the application. For example, after the mobile phone is turned on, the mobile phone automatically starts the desktop application, and the startup operation here can be an operation that can trigger the startup of the desktop application.
[0170] In the embodiment of the present application, the mobile phone determines the virtual memory address corresponding to the actual apk file of the application based on the virtual memory address corresponding to the apk file during and after the application is started, so as to accurately identify the memory resources that are no longer needed. Afterwards, the mobile phone can use the virtual memory address corresponding to the actual apk file as the immediate recycling address to directly recycle the immediate recycling address, thereby reducing the content occupied by the application and reclaiming the .apk mmap part of the memory in the memory corresponding to the mobile phone's Code. For example, Figure 6 As shown in the figure, the Pss Total corresponding to .apk mmap has dropped to 2129KB. Figure 1 The 31856KB shown is reduced by 29727KB (31856KB-2129KB) by reclaiming the virtual memory address corresponding to the apk file.
[0171] In some embodiments, the memory adjustment scheme provided by the present application is universal, does not require any adaptation of the operating system of the electronic device, does not need to rely on the operating system to provide customized combinations, and the electronic device can directly trigger the memory adjustment scheme when the application is started. In addition, the memory adjustment scheme provided by the present application can be used in various scenarios that require memory optimization, such as memory optimization scenarios involved in desktop operating systems and server operating systems.
[0172] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of the method. It is understandable that in order to realize the above functions, the electronic device includes a hardware structure and / or software module corresponding to each function. In combination with the units and algorithm steps of each example described in the embodiment disclosed in this application, the embodiment of the present application can be implemented in the form of hardware or a combination of hardware and computer software.
[0173] Whether a function is executed in hardware or in a computer-driven hardware manner depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the technical solution of the embodiment of the present application.
[0174] The present application is an embodiment that can divide the functional modules of the electronic device according to the above method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of units in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0175] like Figure 71 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device 1000 can be used to implement the methods performed by the electronic devices described in the above method embodiments. For example, the electronic device 1000 may include a processing unit 1001, a communication unit 1002, and a display unit 1003. The processing unit 1001 is used to support the electronic device 1000 to perform Figures 1 to 6 The processing function of any of the electronic devices described above, the communication unit 1002 is used to support the communication function of the electronic device 1000. The display unit 1003 is used to support the display function of the electronic device 1000.
[0176] Optional, Figure 7 The electronic device 1000 shown may also include a storage unit ( Figure 7 ), the storage unit stores a program or instruction. When the processing unit 1001 executes the program or instruction, Figure 7 The electronic device 1000 shown can execute the method described in the above method embodiment.
[0177] Figure 7 The technical effects of the electronic device 1000 shown can refer to the technical effects described in the above method embodiment, and will not be repeated here. Figure 7 The processing unit 1001 involved in the electronic device 1000 shown can be implemented by a processor or a processor-related circuit component, which can be a processor or a processing module. The communication unit 1002 can be implemented by a transceiver or a transceiver-related circuit component, which can be a transceiver or a transceiver module. The display unit 1003 can be implemented by display screen-related components.
[0178] The present application also provides a chip system, such as Figure 8 As shown, the chip system includes at least one processor 1101 and at least one interface circuit 1102. The processor 1101 and the interface circuit 1102 can be interconnected through lines. For example, the interface circuit 1102 can be used to receive signals from other devices. For another example, the interface circuit 1102 can be used to send signals to other devices (such as processor 1101). Exemplarily, the interface circuit 1102 can read instructions stored in the memory and send the instructions to the processor 1101. When the instructions are executed by the processor 1101, the electronic device can execute the various steps performed by the electronic device in the above embodiment. Of course, the chip system can also include other discrete devices, which are not specifically limited in the embodiments of the present application.
[0179] Optionally, the processor in the chip system may be one or more. The processor may be implemented by hardware or by software. When implemented by hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented by software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.
[0180] Optionally, the memory in the chip system may be one or more. The memory may be integrated with the processor or may be separately provided with the processor, which is not limited in the present application. Exemplarily, the memory may be a non-transient processor, such as a read-only memory ROM, which may be integrated with the processor on the same chip or may be provided on different chips. The present application does not specifically limit the type of memory and the arrangement of the memory and the processor.
[0181] Exemplarily, the chip system can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD) or other integrated chips.
[0182] It should be understood that each step in the above method embodiment can be completed by an integrated logic circuit of hardware in a processor or by instructions in the form of software. The method steps disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware processor, or by a combination of hardware and software modules in a processor.
[0183] An embodiment of the present application also provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on an electronic device, the electronic device executes the memory adjustment method described in the above method embodiment.
[0184] An embodiment of the present application provides a computer program product, which includes: a computer program or instructions, when the computer program or instructions are executed on an electronic device, the electronic device executes the memory adjustment method described in the above method embodiment.
[0185] In addition, the embodiment of the present application also provides a device, which can be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory, so that the device executes the memory adjustment method in the above-mentioned method embodiments. Among them, the electronic device, computer-readable storage medium, computer program product or chip provided in this embodiment are all used to execute the corresponding method provided above, so the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be repeated here.
[0186] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0187] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The various embodiments can be combined with each other or referenced to each other without conflict. The device embodiments described above are merely schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0188] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0189] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0190] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0191] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A memory adjustment method, characterized in that: Applied to electronic equipment, the method comprises: Receiving a first operation; wherein the first operation is used to trigger starting an application of the electronic device; After the application is started, the first target memory address corresponding to the installation package apk file of the application is recovered; wherein the first target memory address represents the virtual memory address corresponding to the actual apk file of the application; The first target memory address includes a virtual memory address in an intersection of a first virtual memory address set and a second virtual memory address set, the first virtual memory address set includes virtual memory addresses corresponding to all first apk files, and the second virtual memory address set includes virtual memory addresses corresponding to all second apk files; Alternatively, the first target memory address includes the virtual memory address corresponding to the identifier of the apk file in the intersection of the first identifier set and the second identifier set, the first identifier set includes the identifiers of all first apk files, and the second identifier set includes the identifiers of all second apk files; The first apk file is determined during the startup of the application, and the second apk file is determined after the startup of the application is completed.
2. The method according to claim 1, characterized in that After the application is started, the method further includes: Without using the resource file indicated by the second target memory address, reclaim the second target memory address; wherein the second target memory address includes virtual memory addresses corresponding to the second apk file except the first target memory address.
3. The method according to claim 2, characterized in that Before reclaiming the second target memory address without using the resource file indicated by the second target memory address, the method further includes: Determine whether the remaining memory of the electronic device is less than a preset memory threshold.
4. The method according to any one of claims 1 to 3, characterized in that The step of recovering the first target memory address corresponding to the installation package apk file of the application includes: The first target memory address is reclaimed through a memory suggestion interface.
5. The method according to any one of claims 1 to 3, characterized in that After receiving the first operation, the method further includes: Starting a process of the application; Read the first process memory mapping maps file of the application; Traversing the first maps file to determine mapping information of the first apk file; wherein the mapping information of the first apk file includes a virtual memory address corresponding to the first apk file; Initialize the application's process.
6. The method according to any one of claims 1 to 3, characterized in that After the application is started, the method further includes: Reading a second maps file of the application; Traverse the second maps file to determine mapping information of the second apk file; wherein the mapping information of the second apk file includes a virtual memory address corresponding to the second apk file.
7. An electronic device, characterized in that: The electronic device includes a memory and one or more processors; the memory and the processor are coupled; the memory is used to store computer program code, and the computer program code includes computer instructions; when the processor executes the computer instructions, the electronic device executes the memory adjustment method as described in any one of claims 1 to 6.
8. A computer-readable storage medium, characterized in that: The method comprises computer instructions, which, when executed on an electronic device, enable the electronic device to execute the memory adjustment method as claimed in any one of claims 1 to 6.
9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the memory adjustment method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
A method and apparatus for memory reclamation
CN107912063B
Method for loading android system so files, and electronic device
WO2018045733A1