WO2023051094A1 - 内存回收方法、装置、电子设备及可读存储介质 - Google Patents

内存回收方法、装置、电子设备及可读存储介质 Download PDF

Info

Publication number
WO2023051094A1
WO2023051094A1 PCT/CN2022/113964 CN2022113964W WO2023051094A1 WO 2023051094 A1 WO2023051094 A1 WO 2023051094A1 CN 2022113964 W CN2022113964 W CN 2022113964W WO 2023051094 A1 WO2023051094 A1 WO 2023051094A1
Authority
WO
WIPO (PCT)
Prior art keywords
shrinker
module
list
memory
activity index
Prior art date
Application number
PCT/CN2022/113964
Other languages
English (en)
French (fr)
Inventor
龚晨
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2023051094A1 publication Critical patent/WO2023051094A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]

Definitions

  • the present application relates to the field of terminals, and in particular to a memory recovery method, device, electronic equipment and readable storage medium.
  • the slab mechanism is a memory allocation mechanism based on the buddy system in the Linus (Linux) system.
  • memory is usually managed and allocated in units of 4kB pages.
  • the memory requirements in practical applications are mostly measured in bytes.
  • a page of memory in the partner system can be allocated and managed in units of bytes.
  • shrinker_list a global linked list
  • shrinker_list will be protected by the shrinker reader/writer semaphore (shrinker_rwsem) lock when reading and writing. This will cause other modules to register the shrinker and register the shrinker to the shrinker_list when the system reads the shrinker_list to reclaim the slab memory.
  • the embodiment of the present application provides a memory reclamation method, device, electronic device and readable storage medium, which can solve the problem that when the system reads the shrinker_list and reclaims the slab memory, other modules are blocked from registering the shrinker and registering the shrinker to the shrinker_list.
  • the embodiment of the present application provides a method for memory reclamation, including: reclaiming the memory of the modules registered in the first list in response to the memory reclamation instruction, and reclaiming the memory of the modules registered in the second list, wherein , the activity index of the modules registered in the first list is less than the first threshold, the activity index of the modules registered in the second list is greater than or equal to the first threshold, and the activity index is used to indicate the frequency of module registration and uninstallation.
  • the memory recovery method provided by the embodiment of the present application can be applied to mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (augmented reality, AR)/virtual reality (virtual reality, VR) equipment, notebook computers, super mobile personal computers (ultra-mobile personal computer, UMPC), netbook, personal digital assistant (personal digital assistant, PDA) and other electronic devices, the embodiments of the present application do not impose any restrictions on the specific types of electronic devices.
  • the activity index of the modules registered in the first list is less than the first threshold, modules with a lower unloading frequency are not registered.
  • the activity indices of the modules registered in the second list are greater than or equal to the first threshold, and they are modules with higher registration and uninstallation frequency.
  • the method further includes: when the module is registered, acquiring the activity index of the registered module. When the activity index of the module is less than the first threshold, the module is registered in the first list. When the activity index of the module is greater than or equal to the first threshold, the module is registered in the second list.
  • the method further includes: when uninstalling a module registered in the first list or the second list, adding one to the activity index of the uninstalled module.
  • each module corresponds to a shrinker
  • the shrinker includes a recycling function corresponding to the module, and the recycling function is used to reclaim the memory of the module during execution.
  • registering the module in the first list includes: registering a shrinker corresponding to the module in the first list.
  • registering the module in the second list includes: registering a shrinker corresponding to the module in the second list.
  • uninstalling the modules in the first list or the second list includes: uninstalling the shrinker corresponding to the modules in the first list or the second list from the first list or the second list.
  • obtaining the activity index of the registered module includes: obtaining a recycling function in the shrinker corresponding to the registered module.
  • the activity index of the shrinker is obtained in the pre-stored global array, and the pre-stored global array includes multiple recovery functions, and the activity index of the shrinker corresponding to each recovery function. Use the shrinker's activity index as the module's activity index.
  • adding one to the activity index of the unloaded module includes: acquiring a recycling function in the shrinker corresponding to the unloaded module.
  • the recovery function add one to the activity index of the shrinker in the pre-stored global array, and the pre-stored global array includes multiple recovery functions and the activity index of the shrinker corresponding to each recovery function.
  • the method further includes: obtaining the activity index of the shrinker in a pre-stored global array according to the recovery function in the shrinker, the pre-stored global array includes multiple recovery functions, and the shrinker's index corresponding to each recovery function active index. Store the shrinker's activity index in the shrinker.
  • obtaining the activity index of the shrinker in the pre-stored global array according to the recycling function in the shrinker includes: traversing the pre-stored global array according to the recycling function, and searching for the activity index of the shrinker corresponding to the recycling function.
  • the activity index of the shrinker corresponding to the recovery function is used as the activity index of the module.
  • the recovery function is added to the pre-stored global array, and the activity index of the shrinker corresponding to the recovery function is set to a preset value, and the preset value is used as the module active index.
  • obtaining the activity index of the registered module includes: obtaining the activity index of the shrinker in the shrinker corresponding to the registered module. Use the shrinker's activity index as the module's activity index.
  • uninstalling the modules registered in the first list or the second list includes: obtaining the activity index of the shrinker in the shrinker corresponding to the module to be uninstalled. When the activity index of the shrinker is less than the first threshold, the module is unloaded from the first list. When the activity index of the shrinker is greater than or equal to the first threshold, the module is unloaded from the second list.
  • adding one to the activity index of the uninstalled module includes: adding one to the activity index of the shrinker in the shrinker corresponding to the uninstalled module.
  • the method further includes: obtaining a recycling function in the shrinker corresponding to the unloaded module. According to the recycling function, add one to the activity index of the shrinker in the pre-stored global array.
  • reclaiming the memory of the modules registered in the first list, and reclaiming the memory of the modules registered in the second list includes: in response to the memory reclamation instruction, executing the memory of the modules registered in the first list The recycling function corresponding to each module in , reclaims the memory of each module registered in the first list. In response to the memory recovery instruction, execute the recovery function corresponding to each module registered in the second list, and recover the memory of each module registered in the second list.
  • the embodiment of the present application provides a memory reclamation device, including a reclamation module, which is used to reclaim the memory of the modules registered in the first list in response to the memory reclamation instruction, and reclaim the modules registered in the second list memory, wherein the activity index of the modules registered in the first list is less than the first threshold, the activity index of the modules registered in the second list is greater than or equal to the first threshold, and the activity index is used to indicate the frequency of module registration and unloading .
  • a reclamation module which is used to reclaim the memory of the modules registered in the first list in response to the memory reclamation instruction, and reclaim the modules registered in the second list memory, wherein the activity index of the modules registered in the first list is less than the first threshold, the activity index of the modules registered in the second list is greater than or equal to the first threshold, and the activity index is used to indicate the frequency of module registration and unloading .
  • the device further includes a registration module, configured to obtain the activity index of the registered module when the module is registered.
  • a registration module configured to obtain the activity index of the registered module when the module is registered.
  • the activity index of the module is less than the first threshold, the module is registered in the first list.
  • the activity index of the module is greater than or equal to the first threshold, the module is registered in the second list.
  • the device further includes an uninstall module, configured to add one to the activity index of the uninstalled module when uninstalling a module registered in the first list or the second list.
  • each module corresponds to a shrinker
  • the shrinker includes a recycling function corresponding to the module, and the recycling function is used to reclaim the memory of the module during execution.
  • the registering module is specifically configured to register the shrinker corresponding to the module in the first list.
  • the registering module is specifically configured to register the shrinker corresponding to the module in the second list.
  • the uninstalling module is specifically used to uninstall the shrinker corresponding to the module in the first list or the second list from the first list or the second list.
  • the registration module is specifically used to obtain the recycling function in the shrinker corresponding to the registered module.
  • the activity index of the shrinker is obtained in the pre-stored global array, and the pre-stored global array includes multiple recovery functions, and the activity index of the shrinker corresponding to each recovery function. Use the shrinker's activity index as the module's activity index.
  • the unloading module is specifically used to obtain the recycling function in the shrinker corresponding to the unloaded module.
  • the recovery function add one to the activity index of the shrinker in the pre-stored global array, and the pre-stored global array includes multiple recovery functions and the activity index of the shrinker corresponding to each recovery function.
  • the registration module is also used to obtain the activity index of the shrinker in the pre-stored global array according to the recycling function in the shrinker.
  • the pre-stored global array includes multiple recycling functions, and the shrinker corresponding to each recycling function activity index. Store the shrinker's activity index in the shrinker.
  • the registration module is specifically configured to traverse the pre-stored global array according to the recycling function, and find the activity index of the shrinker corresponding to the recycling function.
  • the activity index of the shrinker corresponding to the recovery function is found, the activity index of the shrinker is used as the activity index of the module.
  • the recovery function is added to the pre-stored global array, and the activity index of the shrinker corresponding to the recovery function is set to a preset value, and the preset value is used as the module active index.
  • the registration module is specifically used to obtain the activity index of the shrinker in the shrinker corresponding to the registered module. Use the shrinker's activity index as the module's activity index.
  • the uninstalling module is specifically used to obtain the activity index of the shrinker in the shrinker corresponding to the module to be uninstalled.
  • the activity index of the shrinker is less than the first threshold, the module is unloaded from the first list.
  • the activity index of the shrinker is greater than or equal to the first threshold, the module is uninstalled from the second list.
  • the unloading module is further used to add one to the activity index of the shrinker in the shrinker corresponding to the unloaded module.
  • the unloading module is also used to obtain a recovery function in the shrinker corresponding to the unloaded module. According to the recycling function, add one to the activity index of the shrinker in the pre-stored global array.
  • the recycling module is specifically configured to, in response to the memory recycling instruction, execute a recycling function corresponding to each module registered in the first list, and reclaim the memory of each module registered in the first list.
  • execute the recovery function corresponding to each module registered in the second list execute the recovery function corresponding to each module registered in the second list, and recover the memory of each module registered in the second list.
  • an embodiment of the present application provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and operable on the processor, and the processor implements the method provided in the first aspect when executing the computer program .
  • an embodiment of the present application provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the method as provided in the first aspect is implemented.
  • the embodiment of the present application provides a computer program product, which, when the computer program product is run on the electronic device, causes the electronic device to execute the method provided in the first aspect above.
  • an embodiment of the present application provides a chip system, the chip system includes a memory and a processor, and the processor executes a computer program stored in the memory to implement the method provided in the first aspect.
  • an embodiment of the present application provides a chip system, the chip system includes a processor, the processor is coupled to the computer-readable storage medium provided in the fourth aspect, and the processor executes the computer program stored in the computer-readable storage medium, To realize the method provided by the first aspect.
  • FIG. 1 shows a schematic structural diagram of an electronic device applying a memory recovery method
  • FIG. 2 shows a schematic diagram of the software structure of an electronic device applying a memory recovery method
  • FIG. 3 shows a schematic flowchart of a memory recovery method provided by the present application
  • FIG. 4 shows a schematic diagram of the first list and the second list in the memory recovery method provided by the present application
  • FIG. 5 shows another schematic diagram of the first list and the second list in the memory recovery method provided by the present application
  • FIG. 6 shows another schematic diagram of the first list and the second list in the memory recovery method provided by the present application
  • FIG. 7 shows a structural block diagram of a memory recycling device provided by an embodiment of the present application.
  • FIG. 8 shows a schematic structural diagram of another electronic device provided by an embodiment of the present application.
  • the term “if” may be construed, depending on the context, as “when” or “once” or “in response to determining” or “in response to detecting ".
  • references to "one embodiment” or “some embodiments” or the like in the specification of the present application means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application.
  • appearances of the phrases “in one embodiment,” “in some embodiments,” “in other embodiments,” “in other embodiments,” etc. in various places in this specification are not necessarily All refer to the same embodiment, but mean “one or more but not all embodiments” unless specifically stated otherwise.
  • the system kernel of the electronic device When the electronic device is running, the system kernel of the electronic device will reclaim the memory from time to time. For example, when the kernel receives a memory call application that is larger than the free memory, it will forcibly reclaim the memory and provide enough memory for the call. Alternatively, the kernel can also periodically reclaim memory to prepare for sudden memory calls.
  • the Linux kernel can reclaim memory through the slab mechanism.
  • the slab mechanism is a memory allocation mechanism based on the partner system in the Linux system.
  • memory is usually managed and allocated in units of 4kB pages.
  • the memory requirements in practical applications are mostly measured in bytes.
  • a page of memory (4kB) in the partner system can be allocated and managed in units of bytes.
  • each module will register a shrinker in the Linux kernel.
  • the shrinker registered by the f2fs module can be named f2fs_shrinker.
  • the shrinker registered by the erofs module can be named erofs_shrinker
  • the shrinker registered by the lmk module can be named lmk_shrinker
  • the shrinker registered by the gpu module can be named gpu_shrinker.
  • Shrinker is a structure in which there is a recycling function (scan_objects) used to reclaim the corresponding module slab memory.
  • the Linux kernel can reclaim the slab memory requested by the corresponding module by calling scan_objects in the structure.
  • f2fs_shrinker stores scan_objects corresponding to the f2fs module.
  • the Linux kernel calls scan_objects in f2fs_shrinker, the slab memory requested by the f2fs module can be recovered.
  • the shrinker corresponding to the module will be added to the global list shrinker_list.
  • the corresponding shrinker also needs to be uninstalled from the shrinker_list. Since all shrinkers are registered on the same shrinker_list, and the shrinker_list needs to be protected by the shrinker_rwsem lock when being read and written.
  • the Linux kernel reclaims the slab memory (need to read shrinker_list), the behavior of other modules to register or uninstall shrinker (need to write into shrinker_list) will be blocked, resulting in poor system operation and performance degradation.
  • the present application provides a method for memory reclamation, including: reclaiming the memory of modules registered in the first list in response to a memory reclamation instruction, and reclaiming the memory of modules registered in the second list, wherein the memory of the modules registered in the The activity index of the modules in the first list is less than the first threshold, the activity index of the modules registered in the second list is greater than or equal to the first threshold, and the activity index is used to indicate the frequency of module registration and uninstallation.
  • the modules (cold modules) with a lower unloading frequency are not registered.
  • the activity index of the modules registered in the second list is greater than or equal to the first threshold, and they are modules (hot modules) with high registration and uninstallation frequency.
  • the memory recovery method provided by the embodiment of the present application can be applied to mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (augmented reality, AR)/virtual reality (virtual reality, VR) equipment, notebook computers, super mobile personal computers (ultra-mobile personal computer, UMPC), netbook, personal digital assistant (personal digital assistant, PDA) and other electronic devices, the embodiments of the present application do not impose any restrictions on the specific types of electronic devices.
  • FIG. 1 shows a schematic structural diagram of an electronic device applying a memory reclamation method.
  • the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (universal serial bus, USB) interface 130, a charging management module 140, a power management module 141, a battery 142, Antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, earphone jack 170D, sensor module 180, button 190, motor 191, indicator 192, camera 193, A display screen 194, and a subscriber identification module (subscriber identification module, SIM) card interface 195, etc.
  • SIM subscriber identification module
  • the sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, bone conduction sensor 180M, etc.
  • the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100 .
  • the electronic device 100 may include more or fewer components than shown in the figure, or combine certain components, or separate certain components, or arrange different components.
  • the illustrated components can be realized in hardware, software or a combination of software and hardware.
  • the electronic device 100 when the electronic device 100 is a mobile phone, a tablet computer or a large-screen device, it may include all the components shown in the illustration, or may include only some of the components shown in the illustration.
  • the processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processing unit (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), controller, memory, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural network processor (neural-network processing unit, NPU) wait. Wherein, different processing units may be independent devices, or may be integrated in one or more processors.
  • application processor application processor, AP
  • modem processor graphics processing unit
  • GPU graphics processing unit
  • image signal processor image signal processor
  • ISP image signal processor
  • controller memory
  • video codec digital signal processor
  • DSP digital signal processor
  • baseband processor baseband processor
  • neural network processor neural-network processing unit, NPU
  • the controller may be the nerve center and command center of the electronic device 100 .
  • the controller can generate an operation control signal according to the instruction opcode and timing signal, and complete the control of fetching and executing the instruction.
  • a memory may also be provided in the processor 110 for storing instructions and data.
  • the memory in processor 110 is a cache memory.
  • the memory may hold instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to use the instruction or data again, it can be directly called from the memory. Repeated access is avoided, and the waiting time of the processor 110 is reduced, thereby improving the efficiency of the system.
  • processor 110 may include one or more interfaces.
  • the interface may include an integrated circuit (inter-integrated circuit, I2C) interface, an integrated circuit built-in audio (inter-integrated circuit sound, I2S) interface, a pulse code modulation (pulse code modulation, PCM) interface, a universal asynchronous transmitter (universal asynchronous receiver/transmitter, UART) interface, mobile industry processor interface (mobile industry processor interface, MIPI), general-purpose input and output (general-purpose input/output, GPIO) interface, subscriber identity module (subscriber identity module, SIM) interface, and /or universal serial bus (universal serial bus, USB) interface, etc.
  • I2C integrated circuit
  • I2S integrated circuit built-in audio
  • PCM pulse code modulation
  • PCM pulse code modulation
  • UART universal asynchronous transmitter
  • MIPI mobile industry processor interface
  • GPIO general-purpose input and output
  • subscriber identity module subscriber identity module
  • SIM subscriber identity module
  • USB universal serial bus
  • the I2C interface is a bidirectional synchronous serial bus, including a serial data line (serial data line, SDA) and a serial clock line (derail clock line, SCL).
  • processor 110 may include multiple sets of I2C buses.
  • the processor 110 can be respectively coupled to the touch sensor 180K, the charger, the flashlight, the camera 193 and the like through different I2C bus interfaces.
  • the processor 110 may be coupled to the touch sensor 180K through the I2C interface, so that the processor 110 and the touch sensor 180K communicate through the I2C bus interface to realize the touch function of the electronic device 100 .
  • the I2S interface can be used for audio communication.
  • processor 110 may include multiple sets of I2S buses.
  • the processor 110 may be coupled to the audio module 170 through an I2S bus to implement communication between the processor 110 and the audio module 170 .
  • the audio module 170 can transmit audio signals to the wireless communication module 160 through the I2S interface.
  • the PCM interface can also be used for audio communication, sampling, quantizing and encoding the analog signal.
  • the audio module 170 and the wireless communication module 160 may be coupled through a PCM bus interface.
  • the audio module 170 can also transmit audio signals to the wireless communication module 160 through the PCM interface. Both I2S interface and PCM interface can be used for audio communication.
  • the UART interface is a universal serial data bus used for asynchronous communication.
  • the bus can be a bidirectional communication bus. It converts the data to be transferred to and from parallel communication.
  • a UART interface is generally used to connect the processor 110 and the wireless communication module 160 .
  • the processor 110 communicates with the Bluetooth module in the wireless communication module 160 through the UART interface to realize the Bluetooth function.
  • the audio module 170 can transmit audio signals to the wireless communication module 160 through the UART interface, so as to realize the function of playing music through the Bluetooth headset.
  • the MIPI interface can be used to connect the processor 110 with peripheral devices such as the display screen 194 and the camera 193 .
  • MIPI interface includes camera serial interface (camera serial interface, CSI), display serial interface (display serial interface, DSI), etc.
  • the processor 110 communicates with the camera 193 through the CSI interface to realize the shooting function of the electronic device 100 .
  • the processor 110 and the display screen 194 communicate through the DSI interface to realize the display function of the electronic device 100.
  • the GPIO interface can be configured by software.
  • the GPIO interface can be configured as a control signal or as a data signal.
  • the GPIO interface can be used to connect the processor 110 with the camera 193 , the display screen 194 , the wireless communication module 160 , the audio module 170 , the sensor module 180 and so on.
  • the GPIO interface can also be configured as an I2C interface, I2S interface, UART interface, MIPI interface, etc.
  • the USB interface 130 is an interface conforming to the USB standard specification, specifically, it can be a Mini USB interface, a Micro USB interface, a USB Type C interface, and the like.
  • the USB interface 130 can be used to connect a charger to charge the electronic device 100 , and can also be used to transmit data between the electronic device 100 and peripheral devices. It can also be used to connect headphones and play audio through them. This interface can also be used to connect other electronic devices, such as AR devices.
  • the interface connection relationship between the modules shown in the embodiment of the present application is only a schematic illustration, and does not constitute a structural limitation of the electronic device 100 .
  • the electronic device 100 may also adopt different interface connection manners in the foregoing embodiments, or a combination of multiple interface connection manners.
  • the charging management module 140 is configured to receive a charging input from a charger.
  • the charger may be a wireless charger or a wired charger.
  • the charging management module 140 can receive charging input from the wired charger through the USB interface 130 .
  • the charging management module 140 may receive a wireless charging input through a wireless charging coil of the electronic device 100 . While the charging management module 140 is charging the battery 142 , it can also provide power for electronic devices through the power management module 141 .
  • the power management module 141 is used for connecting the battery 142 , the charging management module 140 and the processor 110 .
  • the power management module 141 receives the input from the battery 142 and/or the charging management module 140 to provide power for the processor 110 , the internal memory 121 , the external memory, the display screen 194 , the camera 193 , and the wireless communication module 160 .
  • the power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle times, and battery health status (leakage, impedance).
  • the power management module 141 may also be disposed in the processor 110 . In some other embodiments, the power management module 141 and the charging management module 140 may also be set in the same device.
  • the wireless communication function of the electronic device 100 can be realized by the antenna 1 , the antenna 2 , the mobile communication module 150 , the wireless communication module 160 , a modem processor, a baseband processor, and the like.
  • Antenna 1 and Antenna 2 are used to transmit and receive electromagnetic wave signals.
  • Each antenna in electronic device 100 may be used to cover single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization of the antennas.
  • Antenna 1 can be multiplexed as a diversity antenna of a wireless local area network.
  • the antenna may be used in conjunction with a tuning switch.
  • the mobile communication module 150 can provide wireless communication solutions including 2G/3G/4G/5G applied on the electronic device 100 .
  • the mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (low noise amplifier, LNA) and the like.
  • the mobile communication module 150 can receive electromagnetic waves through the antenna 1, filter and amplify the received electromagnetic waves, and send them to the modem processor for demodulation.
  • the mobile communication module 150 can also amplify the signals modulated by the modem processor, and convert them into electromagnetic waves through the antenna 1 for radiation.
  • At least part of the functional modules of the mobile communication module 150 may be set in the processor 110 . In some embodiments, at least part of the functional modules of the mobile communication module 150 and at least part of the modules of the processor 110 may be set in the same device.
  • a modem processor may include a modulator and a demodulator.
  • the modulator is used to modulate the low-frequency baseband signal to be transmitted into a medium-high frequency signal.
  • the demodulator is used to demodulate the received electromagnetic wave signal into a low frequency baseband signal. Then the demodulator sends the demodulated low-frequency baseband signal to the baseband processor for processing.
  • the low-frequency baseband signal is passed to the application processor after being processed by the baseband processor.
  • the application processor outputs sound signals through audio equipment (not limited to speaker 170A, receiver 170B, etc.), or displays images or videos through display screen 194 .
  • the modem processor may be a stand-alone device.
  • the modem processor may be independent from the processor 110, and be set in the same device as the mobile communication module 150 or other functional modules.
  • the wireless communication module 160 can provide wireless local area networks (wireless local area networks, WLAN) (such as wireless fidelity (Wireless Fidelity, Wi-Fi) network), bluetooth (bluetooth, BT), global navigation satellite, etc. applied on the electronic device 100.
  • System global navigation satellite system, GNSS
  • frequency modulation frequency modulation, FM
  • near field communication technology near field communication, NFC
  • infrared technology infrared, IR
  • the wireless communication module 160 may be one or more devices integrating at least one communication processing module.
  • the wireless communication module 160 receives electromagnetic waves via the antenna 2 , frequency-modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110 .
  • the wireless communication module 160 can also receive the signal to be sent from the processor 110 , frequency-modulate it, amplify it, and convert it into electromagnetic waves through the antenna 2 for radiation.
  • the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with the network and other devices through wireless communication technology.
  • Wireless communication technologies may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), broadband code division Multiple access (wideband code division multiple access, WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM , and/or IR technology, etc.
  • GNSS can include global positioning system (global positioning system, GPS), global navigation satellite system (global navigation satellite system, GLONASS), Beidou satellite navigation system (beidou navigation satellite system, BDS), quasi-zenith satellite system (quasi-zenith) satellite system (QZSS) and/or satellite based augmentation systems (SBAS).
  • GPS global positioning system
  • GLONASS global navigation satellite system
  • Beidou satellite navigation system beidou navigation satellite system, BDS
  • quasi-zenith satellite system quasi-zenith satellite system
  • QZSS quasi-zenith satellite system
  • SBAS satellite based augmentation systems
  • the electronic device 100 realizes the display function through the GPU, the display screen 194 , and the application processor.
  • the GPU is a microprocessor for image processing, and is connected to the display screen 194 and the application processor. GPUs are 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 change display information.
  • the display screen 194 is used to display images, videos and the like.
  • the display screen 194 includes a display panel.
  • the display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active matrix organic light emitting diode or an active matrix organic light emitting diode (active-matrix organic light emitting diode, AMOLED), flexible light-emitting diode (flex light-emitting diode, FLED), Miniled, MicroLed, Micro-oLed, quantum dot light emitting diodes (quantum dot light emitting diodes, QLED), etc.
  • the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
  • the electronic device 100 can realize the shooting function through the ISP, the camera 193 , the video codec, the GPU, the display screen 194 and the application processor.
  • the ISP is used for processing the data fed back by the camera 193 .
  • the light is transmitted to the photosensitive element of the camera through the lens, and the light signal is converted into an electrical signal, and the photosensitive element of the camera transmits the electrical signal to the ISP for processing, and converts it into an image visible to the naked eye.
  • ISP can also perform algorithm optimization on image noise, brightness, and skin color.
  • ISP can also optimize the exposure, color temperature and other parameters of the shooting scene.
  • the ISP may be located in the camera 193 .
  • Camera 193 is used to capture still images or video.
  • the object generates an optical image through the lens and projects it to the photosensitive element.
  • the focal length of the lens can be used to indicate the viewing range of the camera, and the smaller the focal length of the lens, the larger the viewing range of the lens.
  • the photosensitive element may be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor.
  • CMOS complementary metal-oxide-semiconductor
  • the photosensitive element converts the light signal into an electrical signal, and then transmits the electrical signal to the ISP to convert it into a digital image signal.
  • the ISP outputs the digital image signal to the DSP for processing.
  • DSP converts digital image signals into standard RGB, YUV and other image signals.
  • the electronic device 100 may include cameras 193 with two or more focal lengths.
  • Digital signal processors are used to process digital signals. In addition to digital image signals, they can also process other digital signals. For example, when the electronic device 100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the energy of the frequency point.
  • Video codecs are used to compress or decompress digital video.
  • the electronic device 100 may support one or more video codecs.
  • the electronic device 100 can play or record videos in various encoding formats, for example: moving picture experts group (moving picture experts group, MPEG) 1, MPEG2, MPEG3, MPEG4 and so on.
  • MPEG moving picture experts group
  • the NPU is a neural-network (NN) computing processor.
  • NN neural-network
  • Applications such as intelligent cognition of the electronic device 100 can be realized through the NPU, such as image recognition, face recognition, speech recognition, text understanding, and the like.
  • the NPU or other processors may be used to perform operations such as analysis and processing on the images in the video stored by the electronic device 100 .
  • the external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, so as to expand the storage capacity of the electronic device 100.
  • the external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. Such as saving music, video and other files in the external memory card.
  • the internal memory 121 may be used to store computer-executable program codes including instructions.
  • the processor 110 executes various functional applications and data processing of the electronic device 100 by executing instructions stored in the internal memory 121 .
  • the internal memory 121 may include an area for storing programs and an area for storing data.
  • the stored program area can store an operating system and at least one application program required by a function (such as a sound playing function, an image playing function, etc.).
  • the storage data area can store data created during the use of the electronic device 100 (such as audio data, phonebook, etc.).
  • 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 magnetic disk storage device, flash memory device, universal flash storage (universal flash storage, UFS) and the like.
  • a non-volatile memory such as at least one magnetic disk storage device, flash memory device, universal flash storage (universal flash storage, UFS) and the like.
  • the electronic device 100 can implement audio functions through the audio module 170 , the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor.
  • the audio module 170 is used for converting digital audio signals into analog audio signals for output, and also for converting analog audio input into digital audio signals.
  • the audio module 170 may also be used to encode and decode audio signals.
  • the audio module 170 may be set in the processor 110 , or some functional modules of the audio module 170 may be set in the processor 110 .
  • Speaker 170A also referred to as a "horn" is used to convert audio electrical signals into sound signals.
  • the electronic device 100 can listen to music through the speaker 170A, or listen to the hands-free call.
  • the speaker can play the comparison and analysis results provided by the embodiment of the present application.
  • Receiver 170B also called “earpiece” is used to convert audio electrical signals into sound signals.
  • the receiver 170B can be placed close to the human ear to receive the voice.
  • the microphone 170C also called “microphone” or “microphone” is used to convert sound signals into electrical signals. When making a phone call or sending a voice message, the user can put his mouth close to the microphone 170C to make a sound, and input the sound signal to the microphone 170C.
  • the electronic device 100 may be provided with at least one microphone 170C. In some other embodiments, the electronic device 100 may be provided with two microphones 170C, which may also implement a noise reduction function in addition to collecting sound signals. In some other embodiments, the electronic device 100 can also be provided with three, four or more microphones 170C to collect sound signals, reduce noise, identify sound sources, and realize directional recording functions, etc.
  • the earphone interface 170D is used for connecting wired earphones.
  • the earphone interface 170D can be a USB interface 130, or a 3.5mm open mobile terminal platform (OMTP) standard interface, or a cellular telecommunications industry association of the USA (CTIA) standard interface.
  • OMTP open mobile terminal platform
  • CTIA cellular telecommunications industry association of the USA
  • the pressure sensor 180A is used to sense the pressure signal and convert the pressure signal into an electrical signal.
  • pressure sensor 180A may be disposed on display screen 194 .
  • pressure sensors 180A such as resistive pressure sensors, inductive pressure sensors, and capacitive pressure sensors.
  • a capacitive pressure sensor may be comprised of at least two parallel plates with conductive material.
  • the electronic device 100 determines the intensity of pressure according to the change in capacitance.
  • the electronic device 100 detects the intensity of the touch operation according to the pressure sensor 180A.
  • the electronic device 100 may also calculate the touched position according to the detection signal of the pressure sensor 180A.
  • touch operations acting on the same touch position but with different touch operation intensities may correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view short messages is executed. When a touch operation whose intensity is greater than or equal to the first pressure threshold acts on the icon of the short message application, the instruction of creating a new short message is executed.
  • the gyro sensor 180B can be used to determine the motion posture of the electronic device 100 .
  • the angular velocity of the electronic device 100 around three axes may be determined by the gyro sensor 180B.
  • the gyro sensor 180B can be used for image stabilization. Exemplarily, when the shutter is pressed, the gyro sensor 180B detects the shaking angle of the electronic device 100, calculates the distance that the lens module needs to compensate according to the angle, and allows the lens to counteract the shaking of the electronic device 100 through reverse movement to achieve anti-shake.
  • the gyro sensor 180B can also be used for navigation and somatosensory game scenes.
  • the air pressure sensor 180C is used to measure air pressure.
  • the electronic device 100 calculates the altitude based on the air pressure value measured by the air pressure sensor 180C to assist positioning and navigation.
  • the magnetic sensor 180D includes a Hall sensor.
  • the electronic device 100 may detect opening and closing of the flip holster using the magnetic sensor 180D.
  • the electronic device 100 when the electronic device 100 is a clamshell machine, the electronic device 100 can detect opening and closing of the clamshell according to the magnetic sensor 180D.
  • features such as automatic unlocking of the flip cover are set.
  • the acceleration sensor 180E can detect the acceleration of the electronic device 100 in various directions (generally three axes). When the electronic device 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of electronic devices, and can be used in applications such as horizontal and vertical screen switching, pedometers, etc.
  • the distance sensor 180F is used to measure the distance.
  • the electronic device 100 may measure the distance by infrared or laser. In some embodiments, when shooting a scene, the electronic device 100 may use the distance sensor 180F for distance measurement to achieve fast focusing.
  • Proximity light sensor 180G may include, for example, light emitting diodes (LEDs) and light detectors, such as photodiodes.
  • the light emitting diodes may be infrared light emitting diodes.
  • the electronic device 100 emits infrared light through the light emitting diode.
  • Electronic device 100 uses photodiodes to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it may be determined that there is an object near the electronic device 100 . When insufficient reflected light is detected, the electronic device 100 may determine that there is no object near the electronic device 100 .
  • the electronic device 100 can use the proximity light sensor 180G to detect that the user is holding the electronic device 100 close to the ear to make a call, so as to automatically turn off the screen to save power.
  • the proximity light sensor 180G can also be used in leather case mode, automatic unlock and lock screen in pocket mode.
  • the ambient light sensor 180L is used for sensing ambient light brightness.
  • the electronic device 100 can adaptively adjust the brightness of the display screen 194 according to the perceived ambient light brightness.
  • the ambient light sensor 180L can also be used to automatically adjust the white balance when taking pictures.
  • the ambient light sensor 180L can also cooperate with the proximity light sensor 180G to detect whether the electronic device 100 is in the pocket, so as to prevent accidental touch.
  • the fingerprint sensor 180H is used to collect fingerprints.
  • the electronic device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access to application locks, take pictures with fingerprints, answer incoming calls with fingerprints, and the like.
  • the temperature sensor 180J is used to detect temperature.
  • the electronic device 100 uses the temperature detected by the temperature sensor 180J to implement a temperature treatment strategy. For example, when the temperature reported by the temperature sensor 180J exceeds the threshold, the electronic device 100 may reduce the performance of the processor located near the temperature sensor 180J, so as to reduce power consumption and implement thermal protection.
  • the electronic device 100 when the temperature is lower than another threshold, the electronic device 100 heats the battery 142 to prevent the electronic device 100 from being shut down abnormally due to the low temperature.
  • the electronic device 100 boosts the output voltage of the battery 142 to avoid abnormal shutdown caused by low temperature.
  • Touch sensor 180K also known as "touch panel”.
  • the touch sensor 180K can be disposed on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a “touch screen”.
  • the touch sensor 180K is used to detect a touch operation on or near it.
  • the touch sensor can pass the detected touch operation to the application processor to determine the type of touch event.
  • Visual output related to the touch operation can be provided through the display screen 194 .
  • the touch sensor 180K may also be disposed on the surface of the electronic device 100 , which is different from the position of the display screen 194 .
  • the bone conduction sensor 180M can acquire vibration signals.
  • the bone conduction sensor 180M can acquire the vibration signal of the vibrating bone mass of the human voice.
  • the bone conduction sensor 180M can also contact the human pulse and receive the blood pressure beating signal.
  • the bone conduction sensor 180M can also be disposed in the earphone, combined into a bone conduction earphone.
  • the audio module 170 can analyze the voice signal based on the vibration signal of the vibrating bone mass of the vocal part acquired by the bone conduction sensor 180M, so as to realize the voice function.
  • the application processor can analyze the heart rate information based on the blood pressure beating signal acquired by the bone conduction sensor 180M, so as to realize the heart rate detection function.
  • the keys 190 include a power key, a volume key and the like.
  • the key 190 may be a mechanical key. It can also be a touch button.
  • the electronic device 100 can receive key input and generate key signal input related to user settings and function control of the electronic device 100 .
  • the motor 191 can generate a vibrating reminder.
  • the motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback.
  • touch operations applied to different applications may correspond to different vibration feedback effects.
  • the motor 191 may also correspond to different vibration feedback effects for touch operations acting on different areas of the display screen 194 .
  • Different application scenarios for example: time reminder, receiving information, alarm clock, games, etc.
  • the touch vibration feedback effect can also support customization.
  • the indicator 192 can be an indicator light, and can be used to indicate charging status, power change, and can also be used to indicate messages, missed calls, notifications, and the like.
  • the SIM card interface 195 is used for connecting a SIM card.
  • the SIM card can be connected and separated from the electronic device 100 by inserting it into the SIM card interface 195 or pulling it out from the SIM card interface 195 .
  • the electronic device 100 may support 1 or N SIM card interfaces, where N is a positive integer greater than 1.
  • SIM card interface 195 can support Nano SIM card, Micro SIM card, SIM card etc. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of multiple cards may be the same or different.
  • the SIM card interface 195 is also compatible with different types of SIM cards.
  • the SIM card interface 195 is also compatible with external memory cards.
  • the electronic device 100 interacts with the network through the SIM card to implement functions such as calling and data communication.
  • the electronic device 100 adopts an eSIM, that is, an embedded SIM card.
  • the eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100 .
  • FIG. 2 shows a schematic diagram of a software structure of an electronic device applying a memory reclamation method.
  • the operating system in the electronic device 100 may be an Android system, a Linus (Linux) system, a Microsoft Windows system (Windows), an Apple mobile operating system (iOS) or a Harmony OS.
  • the method provided in this application is especially applicable to Linux systems or other systems derived from Linux systems.
  • the operating system of the electronic device 100 is the Hongmeng system as an example for description.
  • the Hongmeng system can be divided into four layers, including a kernel layer, a system service layer, a framework layer, and an application layer, and the layers communicate through software interfaces.
  • the kernel layer includes a kernel abstract layer (kernel abstract layer, KAL) and a driver subsystem.
  • KAL includes multiple kernels, such as the kernel Linux Kernel of the Linux system, the lightweight IoT system kernel LiteOS, etc.
  • the driver subsystem may include a hardware driver foundation (HDF).
  • the hardware driver framework can provide a unified peripheral access capability and a driver development and management framework.
  • the multi-core kernel layer can select the corresponding kernel for processing according to the requirements of the system.
  • the system service layer is a collection of core capabilities of the Hongmeng system, and the system service layer provides services to applications through the framework layer.
  • This layer can include:
  • System Basic Capabilities Subsystem Set Provides basic capabilities for the operation, scheduling, and migration of distributed applications on multiple devices in the Hongmeng system. It may include subsystems such as distributed soft bus, distributed data management, distributed task scheduling, multilingual runtime, public basic library, multimode input, graphics, security, artificial intelligence (AI), user program framework, etc.
  • the multilingual runtime provides C or C++ or JavaScript (JS) multilingual runtime and the basic system class library, and can also be a static Java program using a compiler (that is, the Java language is used in the application or framework layer to develop part) provides the runtime.
  • JS JavaScript
  • Basic software service subsystem set provide public and general software services for Hongmeng system. It can include event notification, telephone, multimedia, X-oriented design (design for X, DFX), MSDP&DV and other subsystems.
  • Enhanced software service subsystem set provide Hongmeng system with differentiated capability-enhanced software services for different devices. It can include smart screen proprietary services, wearable proprietary services, and Internet of Things (Internet of Things, IoT) proprietary business subsystems.
  • IoT Internet of Things
  • Hardware service subsystem set provide hardware services for Hongmeng system. It can include subsystems such as location services, biometric identification, wearable dedicated hardware services, and IoT dedicated hardware services.
  • the framework layer provides Java, C, C++, JS and other multi-language user program frameworks and ability frameworks for Hongmeng system application development, and two user interface (UI) frameworks (including Java UI for the Java language) framework, a JS UI framework suitable for the JS language), and a multilingual framework application programming interface (application programming interface, API) that is open to the outside world for various software and hardware services.
  • UI user interface
  • API application programming interface
  • the application layer includes system applications and third-party non-system applications.
  • System applications may include applications installed by default on electronic devices such as desktops, control bars, settings, and phones.
  • Extended applications may be non-essential applications developed and designed by electronic device manufacturers, such as electronic device housekeeper, replacement and migration, memo, weather and other applications.
  • Third-party non-system applications can be developed by other manufacturers, but can run applications in the Hongmeng system, such as games, navigation, social or shopping applications.
  • the application of Hongmeng system consists of one or more meta-programs (feature ability, FA) or meta-services (particle ability, PA).
  • FA has a UI interface, which provides the ability to interact with users.
  • PA has no UI interface and provides the ability to run tasks in the background and a unified data access abstraction.
  • PA mainly provides support for FA, such as providing computing power as a background service, or providing data access capabilities as a data warehouse.
  • Applications developed based on FA or PA can realize specific business functions, support cross-device scheduling and distribution, and provide users with a consistent and efficient application experience.
  • HarmonyOS can realize hardware mutual assistance and resource sharing through distributed soft bus, distributed device virtualization, distributed data management and distributed task scheduling.
  • Fig. 3 shows a schematic flow chart of the memory reclamation method provided by the present application.
  • the method can be applied to the above-mentioned electronic device 100, and the kernel subsystem of the Hongmeng system running on the electronic device 100 includes the Linux kernel .
  • the Linux kernel when it determines to reclaim the memory, it may determine the modules that need to be reclaimed through the slab mechanism and reclaim the memory corresponding to each module. If a module needs to reclaim memory, but is not registered on the first list or the second list. Then it is determined that the module needs to be registered. The Linux kernel generates a register directive that instructs the module to register.
  • the activity index of the shrinker of the module can be obtained from the pre-stored global list according to the recovery function stored in the shrinker of the module.
  • the global list can be stored in the cache, local storage, or cloud in the form of an array.
  • the global list includes multiple recycling functions and the activity index corresponding to each recycling function. Each recycling function corresponds to a shrinker, and the activity index of the shrinker is The activity index corresponding to the recovery function corresponding to the shrinker.
  • each module When each module is registered for the first time (that is, the recovery function corresponding to the module is not found in the pre-stored global list), it will write the recovery function corresponding to the shrinker of the module into the global list, and set the activity index of the shrinker to is a preset value, for example, the default value of the activity index corresponding to the recycling function can be set to 0.
  • the recycling function corresponding to the gpu_shrinker of the gpu module can be written as gpu_scan_objects.
  • the gup module When the gup module is registered for the first time (that is, gpu_scan_objects is not found in the global list), write gpu_scan_objects into the global list, and set the activity index corresponding to gpu_scan_objects to 0.
  • the activity index corresponding to gpu_scan_objects in the global list can be increased by 1.
  • the shrinker is a structure, and the structure is composed of at least one data, and each data forming the structure is called a "member" of the structure, that is, the structure includes at least one member.
  • the shrinker may include members such as a recovery function and an active index (active_index).
  • active_index an active index
  • two members, gpu_scan_objects and gpu_active_index can be included.
  • the active index of gpu_shrinker found from the global list can be stored in gpu_active_index.
  • the activity indexes of the shrinkers registered in the first list are all less than the first threshold. That is, the first list can also be called a "cold shrinker list", and the modules corresponding to the shrinkers registered in the first list can be called “cold shrinker lists”. Cold modules are modules that are less frequently uninstalled in the Linux kernel, such as f2fs modules, erofs modules, lmk modules, etc. Similarly, the activity indices of the shrinkers registered in the second list are all greater than or equal to the first threshold. That is, the second list may also be called a "hot shrinker list", and the modules corresponding to the shrinkers registered in the second list may be called “hot modules”. Hot modules are modules that are frequently uninstalled in the Linux kernel, such as gpu modules.
  • the first threshold may be a preset value.
  • the first threshold may be set to 20 during system initialization.
  • the first threshold may also be updated from a server or a cloud.
  • the system may obtain an updated first threshold from the server or the cloud every 10 minutes, and the updated first threshold may be calculated by the server according to the global list uploaded by each electronic device.
  • registering the shrinker in the first column or the second list refers to adding the shrinker to the corresponding list.
  • the registration of the shrinker in the first column or the second list will be described.
  • FIG. 4 shows a schematic diagram of the first list and the second list in the memory reclamation method provided in the present application
  • FIG. 5 shows another schematic diagram of the first list and the second list in the memory reclamation method provided in the present application.
  • the first list includes three shrinkers “f2fs_shrinker”, “erofs_shrinker” and “lmk_shrinker”.
  • the first list includes four shrinkers “f2fs_shrinker”, “erofs_shrinker”, “lmk_shrinker” and "X_shrinker”. Where "X_shrinker” is used to represent any module that may be registered in the first list.
  • the second list includes one shrinker "gpu_shrinker".
  • the second list includes four shrinkers “gpu_shrinker”, “A_shrinker”, “B_shrinker” and “C_shrinker” .
  • “A_shrinker”, “B_shrinker” and “C_shrinker” are used to represent any modules that may be registered in the second list.
  • the order of the shrinkers in the first list and the second list is sorted according to their registration time, and the earliest registration is sorted first.
  • the order of shrinkers is "f2fs_shrinker”, “erofs_shrinker”, “lmk_shrinker” and “X_shrinker”.
  • the order of shrinkers is "gpu_shrinker", "A_shrinker”, “B_shrinker” and "C_shrinker”.
  • the shrinker corresponding to the module needs to be uninstalled from the first list or the second list.
  • the shrinker's active index can be obtained from the shrinker's active_index first, and according to the shrinker's active index, it is determined whether to uninstall the shrinker from the first list or the second list.
  • the activity index of the shrinker needs to be increased by 1. That is, add 1 to the value of active_index, and at the same time, search the corresponding active index in the global list according to scan_objects in shrinker, and add 1 to the active index.
  • terminating the operation of a module may include that the electronic device terminates the corresponding module in response to the terminating operation. Or, the module is destroyed after executing the task, etc., and there is no limitation here.
  • unloading the shrinker from the first column or the second list refers to deleting the shrinker from the corresponding list.
  • unloading the shrinker from the first list or the second list will be described with reference to FIG. 5 and FIG. 6 .
  • FIG. 6 shows another schematic diagram of the first list and the second list in the memory reclamation method provided by the present application.
  • the first list includes four shrinkers “f2fs_shrinker”, “erofs_shrinker”, “lmk_shrinker” and “X_shrinker”.
  • “f2fs_shrinker” when “X_shrinker” is uninstalled, “X_shrinker” is deleted from the first list, and there are three shrinkers left in the first list: “f2fs_shrinker”, “erofs_shrinker” and “lmk_shrinker”.
  • the second list includes four shrinkers “gpu_shrinker”, “A_shrinker”, “B_shrinker” and “C_shrinker”.
  • “C_shrinker” is uninstalled, “C_shrinker” is deleted from the second list, and there are three shrinkers left in the second list: “gpu_shrinker”, “A_shrinker” and “B_shrinker”.
  • the activity index of the cold module can be continuously increased with the continuous uninstallation and registration of the Linux kernel, until after the cold module is uninstalled, the activity index corresponding to the cold module is greater than or equal to the first threshold, then the cold module can be Registered in the second list, the cold module turns into a hot module.
  • the system will monitor the remaining memory, and when the Linux kernel receives a memory call request larger than the free memory, it will forcibly reclaim the memory.
  • the Linux kernel can also regularly reclaim memory to prepare for sudden memory calls.
  • the system When the system forcibly reclaims memory or periodically reclaims memory, it will send a memory reclaim command to the Linux kernel. After receiving the memory reclaim command, the Linux kernel responds to the memory reclaim command, reclaims the memory of the shrinker registered in the first list, and reclaims the second Memory of the shrinkers registered in the list.
  • reclaiming the memory of the shrinkers registered in the first list or the second list may be realized by sequentially reading and executing scan_objects in each shrinker in the first list or the second list. For example, referring to Figure 5, when reclaiming the memory corresponding to the first list, read and execute the scan_objects in the shrinker in the order of "f2fs_shrinker”, “erofs_shrinker”, “lmk_shrinker”, and "X_shrinker" to reclaim the slab of the corresponding module Memory.
  • the scan_objects in the shrinker can be read and executed sequentially in the order of "gpu_shrinker", "A_shrinker”, “B_shrinker”, and "C_shrinker” to reclaim the slab memory of the corresponding module.
  • S201-S205 are the steps of registering the module in the list
  • S206-S209 are the steps of unloading the module from the list
  • S210 and S211 are the steps of reclaiming the memory corresponding to the list.
  • S201-S205, S206-S209, and S210 and S211 may be executed simultaneously or separately. For example, when a module is registered to the first list, the module can also be unloaded from the second list. Alternatively, when reclaiming the slab memory of the module corresponding to the first list, the module may be registered to the second list or unloaded from the second list.
  • the registration/unloading operation on the second list will not affect the reclaiming of the slab memory of the module corresponding to the first list, which can effectively reduce the probability of reclaiming memory and blocking the registration/unloading operation, effectively Improve the dynamic performance of the system in low memory state.
  • more than two lists can be set, and modules can be registered into corresponding lists according to multiple thresholds.
  • the methods of determining module ownership, registering modules, uninstalling modules, and reclaiming memory are similar to the present application. I won't go into details here.
  • FIG. 7 shows a structural block diagram of a memory reclamation device provided by the embodiment of the present application. For the convenience of description, only the parts related to the embodiment of the present application are shown.
  • the memory recovery device includes:
  • Recycling module 31 used for reclaiming the memory of the modules registered in the first list and reclaiming the memory of the modules registered in the second list in response to the memory reclamation instruction, wherein the active index of the modules registered in the first list If it is less than the first threshold, the activity index of the modules registered in the second list is greater than or equal to the first threshold, and the activity index is used to indicate the frequency of module registration and uninstallation.
  • the device further includes a registration module 32, configured to acquire the activity index of the registered module when the module is registered. When the activity index of the module is less than the first threshold, the module is registered in the first list. When the activity index of the module is greater than or equal to the first threshold, the module is registered in the second list.
  • the device further includes an uninstall module 33, configured to add one to the activity index of the uninstalled module when uninstalling a module registered in the first list or the second list.
  • each module corresponds to a shrinker
  • the shrinker includes a recycling function corresponding to the module, and the recycling function is used to reclaim the memory of the module during execution.
  • the registration module 32 is specifically configured to register the shrinker corresponding to the module in the first list.
  • the registration module 32 is specifically configured to register the shrinker corresponding to the module in the second list.
  • the uninstall module 33 is specifically configured to uninstall the shrinker corresponding to the module in the first list or the second list from the first list or the second list.
  • the registration module 32 is specifically configured to obtain the recycling function in the shrinker corresponding to the registered module. According to the recovery function, the activity index of the shrinker is obtained in the pre-stored global array, and the pre-stored global array includes multiple recovery functions, and the activity index of the shrinker corresponding to each recovery function. Use the shrinker's activity index as the module's activity index.
  • the registration module 32 is specifically configured to traverse the pre-stored global array according to the recycling function, and find the activity index of the shrinker corresponding to the recycling function. When the activity index of the shrinker corresponding to the recovery function is found, the activity index of the shrinker is used as the activity index of the module. When the activity index of the shrinker corresponding to the recovery function is not found, the recovery function is added to the pre-stored global array, and the activity index of the shrinker corresponding to the recovery function is set to a preset value, and the preset value is used as the module active index.
  • the unloading module 33 is specifically used to obtain the recycling function in the shrinker corresponding to the unloaded module. According to the recovery function, add one to the activity index of the shrinker in the pre-stored global array, and the pre-stored global array includes multiple recovery functions and the activity index of the shrinker corresponding to each recovery function.
  • the registration module 32 is also used to obtain the activity index of the shrinker in the pre-stored global array according to the recycling function in the shrinker.
  • the pre-stored global array includes a plurality of recycling functions, and each recycling function corresponds to Active index of shrinker. Store the shrinker's activity index in the shrinker.
  • the registration module 32 is specifically configured to obtain the activity index of the shrinker among the shrinkers corresponding to the registered module. Use the shrinker's activity index as the module's activity index.
  • the uninstall module 33 is specifically configured to obtain the activity index of the shrinker in the shrinker corresponding to the module to be uninstalled. When the activity index of the shrinker is less than the first threshold, the module is unloaded from the first list. When the activity index of the shrinker is greater than or equal to the first threshold, the module is uninstalled from the second list.
  • the unloading module 33 is further configured to add one to the activity index of the shrinker in the shrinker corresponding to the unloaded module.
  • the unloading module 33 is also used to obtain the recovery function in the shrinker corresponding to the unloaded module. According to the recycling function, add one to the activity index of the shrinker in the pre-stored global array.
  • the recovery module 31 is specifically configured to, in response to the memory recovery instruction, execute a recovery function corresponding to each module registered in the first list, and reclaim the memory of each module registered in the first list. In response to the memory recovery instruction, execute the recovery function corresponding to each module registered in the second list, and recover the memory of each module registered in the second list.
  • Fig. 8 shows a structural block diagram of an electronic device provided by an embodiment of the present application.
  • the electronic device 400 of this embodiment includes: at least one processor 401 (only one is shown in FIG. 8 ), a memory 402 and a computer stored in the memory 402 and capable of running on the at least one processor 401
  • the electronic device 400 may be a smart phone, a tablet computer, a wearable device, an augmented reality (augmented reality, AR)/virtual reality (virtual reality, VR) device, a large-screen device, a vehicle terminal, and the like.
  • the electronic device may include, but not limited to, a processor 401 and a memory 402 .
  • FIG. 8 is only an example of the electronic device 400, and does not constitute a limitation to the electronic device 400. It may include more or less components than shown in the figure, or combine some components, or different components. , for example, may also include input and output devices, network access devices, and so on.
  • the so-called processor 401 can be a central processing unit (central processing unit, CPU), and the processor 401 can also be other general processors, digital signal processors (digital signal processor, DSP), application specific integrated circuits (application specific integrated circuits) , ASIC), off-the-shelf programmable gate array (field-programmable gate array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
  • a general-purpose processor may be a microprocessor, or the processor may be any conventional processor, or the like.
  • the memory 402 may be an internal storage unit of the electronic device 400 in some embodiments, such as a hard disk or memory of the electronic device 400 .
  • the memory 402 may also be an external storage device of the electronic device 400 in other embodiments, such as a plug-in hard disk equipped on the electronic device 400, a smart memory card (smart media card, SMC), a secure digital (secure digital, SD) card, flash card, etc.
  • the memory 402 may also include both an internal storage unit of the electronic device 400 and an external storage device.
  • the memory 402 is used to store operating systems, application programs, bootloaders, data, and other programs, such as program codes of computer programs.
  • the memory 402 can also be used to temporarily store data that has been output or will be output.
  • the embodiment of the present application also provides a computer-readable storage medium, the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in each of the foregoing method embodiments can be realized.
  • An embodiment of the present application provides a computer program product.
  • the computer program product When the computer program product is run on a mobile terminal, the mobile terminal can implement the steps in the foregoing method embodiments when executed.
  • An embodiment of the present application provides a chip system, the chip system includes a memory and a processor, and the processor executes a computer program stored in the memory, so as to implement the steps in the foregoing method embodiments.
  • An embodiment of the present application provides a chip system, the chip system includes a processor, the processor is coupled to a computer-readable storage medium, and the processor executes a computer program stored in the computer-readable storage medium, so as to implement the above-mentioned method embodiments. step.
  • the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the procedures in the methods of the above embodiments in the present application can be completed by instructing related hardware through computer programs, and the computer programs can be stored in a computer-readable storage medium.
  • the computer program When executed by a processor, the steps in the above-mentioned various method embodiments can be realized.
  • the computer program includes computer program code, and the computer program code may be in the form of source code, object code, executable file or some intermediate form.
  • the computer-readable medium may at least include: any entity or device capable of carrying computer program codes to an electronic device, recording medium, computer memory, read-only memory (read-only memory, ROM), random access memory (random access) memory, RAM), electrical carrier signals, telecommunication signals, and software distribution media.
  • any entity or device capable of carrying computer program codes to an electronic device recording medium, computer memory, read-only memory (read-only memory, ROM), random access memory (random access) memory, RAM), electrical carrier signals, telecommunication signals, and software distribution media.
  • computer readable media may not be electrical carrier signals and telecommunication signals under legislation and patent practice.
  • the disclosed methods, devices and electronic equipment may be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of the modules or units is only a logical function division. In actual implementation, there may be other division methods.
  • multiple units or components can be Incorporation may either be integrated into another system, or some features may be omitted, or not implemented.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

本申请适用于终端技术领域,提供了一种内存回收方法、装置、电子设备及可读存储介质。该内存回收方法,包括:响应于内存回收指令,回收注册在第一列表中的模块的内存,以及回收注册在第二列表中的模块的内存,其中,注册在第一列表中的模块的活跃指数小于第一阈值,注册在第二列表中的模块的活跃指数大于或等于第一阈值,活跃指数用于指示模块注册卸载的频繁程度。由于在第一列表中注册的模块注册卸载频率较低。在第二列表中注册的模块注册卸载频率较高。使得第一列表中的模块在回收内存时,发生写入/读取的概率降低,进而降低回收内存时发生阻塞的概率,有效提高低内存状态下系统的动态性能。

Description

内存回收方法、装置、电子设备及可读存储介质
本申请要求于2021年09月29日提交国家知识产权局、申请号为202111167835.2、申请名称为“内存回收方法、装置、电子设备及可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及终端领域,尤其涉及一种内存回收方法、装置、电子设备及可读存储介质。
背景技术
切片(slab)机制是林纳斯(Linux)系统中的一种基于伙伴系统(buddy system)的内存分配机制。在伙伴系统中,通常是以4kB的页为单位对内存进行管理和分配。但是,实际应用时的内存需求大多以字节为单位。通过slab机制,可以以字节为单位,将伙伴系统中的一页内存进行分配和管理。
Linux内核(kernel)中,多个模块均会申请slab内存,在每个模块申请slab内存时,会在Linux内核中注册一个回收器(shrinker)。每个shrinker都会注册到一个全局链表(shrinker_list)上。当系统需要回收slab内存时,会遍历shrinker_list,依次访问各个模块注册的shrinker,回收各个模块的slab内存。
但是,由于shrinker_list在进行读写时都会通过shrinker读写信标(shrinker reader/writer semaphore,shrinker_rwsem)锁进行保护。这会使得系统在读取shrinker_list回收slab内存时,导致其他模块注册shrinker并将shrinker注册到shrinker_list的行为被阻塞。
发明内容
本申请实施例提供了内存回收方法、装置、电子设备及可读存储介质,可以解决系统在读取shrinker_list回收slab内存时,导致其他模块注册shrinker并将shrinker注册到shrinker_list的行为被阻塞的问题。
第一方面,本申请实施例提供了一种内存回收方法,包括:响应于内存回收指令,回收注册在第一列表中的模块的内存,以及回收注册在第二列表中的模块的内存,其中,注册在第一列表中的模块的活跃指数小于第一阈值,注册在第二列表中的模块的活跃指数大于或等于第一阈值,活跃指数用于指示模块注册卸载的频繁程度。
本申请实施例提供的内存回收方法可以应用于手机、平板电脑、可穿戴设备、车载设备、增强现实(augmented reality,AR)/虚拟现实(virtual reality,VR)设备、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本、个人数字助理(personal digital assistant,PDA)等电子设备上,本申请实施例对电子设备的具体类型不作任何限制。
在第一方面中,由于在第一列表中注册的模块的活跃指数小于第一阈值,为注册 卸载频率较低的模块。在第二列表中注册的模块的活跃指数大于或等于第一阈值,为注册卸载频率较高的模块。使得第一列表中的模块在回收内存时,发生写入/读取的概率降低,进而降低回收内存时发生阻塞的概率,有效提高低内存状态下系统的动态性能。
一些实施方式中,该方法还包括:当模块注册时,获取注册的模块的活跃指数。当模块的活跃指数小于第一阈值时,将模块注册在第一列表中。当模块的活跃指数大于或等于第一阈值时,将模块注册在第二列表中。
一些实施方式中,该方法还包括:当卸载第一列表或第二列表中注册的模块时,将卸载的模块的活跃指数加一。
一些实施方式中,每个模块对应一个shrinker,shrinker中包括模块对应的回收函数,回收函数用于在执行时回收模块的内存。
一些实施方式中,将模块注册在第一列表中,包括:将模块对应的shrinker注册在第一列表中。
一些实施方式中,将模块注册在第二列表中,包括:将模块对应的shrinker注册在第二列表中。
一些实施方式中,卸载第一列表或第二列表中的模块,包括:将第一列表或第二列表中的模块对应的shrinker从第一列表或第二列表中卸载。
一些实施方式中,当模块注册时,获取注册的模块的活跃指数,包括:获取注册的模块对应的shrinker中的回收函数。根据回收函数,在预先存储的全局数组中获取shrinker的活跃指数,预先存储的全局数组中包括多个回收函数,以及每个回收函数对应的shrinker的活跃指数。将shrinker的活跃指数作为模块的活跃指数。
一些实施方式中,将卸载的模块的活跃指数加一,包括:获取卸载的模块对应的shrinker中的回收函数。根据回收函数,在预先存储的全局数组中将shrinker的活跃指数加一,预先存储的全局数组中包括多个回收函数,以及每个回收函数对应的shrinker的活跃指数。
一些实施方式中,该方法还包括:根据shrinker中的回收函数在预先存储的全局数组中获取shrinker的活跃指数,预先存储的全局数组中包括多个回收函数,以及每个回收函数对应的shrinker的活跃指数。将shrinker的活跃指数存储在shrinker中。
一些实施方式中,根据shrinker中的回收函数在预先存储的全局数组中获取shrinker的活跃指数包括:根据回收函数,遍历预先存储的全局数组,查找与回收函数对应的shrinker的活跃指数。当查找到与回收函数对应的shrinker的活跃指数时,将shrinker的活跃指数作为模块的活跃指数。当未查找到与回收函数对应的shrinker的活跃指数时,将回收函数添加进预先存储的全局数组中,并将回收函数对应的shrinker的活跃指数设为预设数值,将预设数值作为模块的活跃指数。
一些实施方式中,获取注册的模块的活跃指数,包括:获取注册的模块对应的shrinker中shrinker的活跃指数。将shrinker的活跃指数作为模块的活跃指数。
一些实施方式中,卸载第一列表或第二列表中注册的模块,包括:获取待卸载的模块对应的shrinker中shrinker的活跃指数。当shrinker的活跃指数小于第一阈值时,从第一列表中卸载模块。当shrinker的活跃指数大于或等于第一阈值时,从第二列表 中卸载模块。
一些实施方式中,将卸载的模块的活跃指数加一,包括:将卸载的模块对应的shrinker中shrinker的活跃指数加一。
一些实施方式中,在将卸载的模块对应的shrinker中shrinker的活跃指数加一之后,还包括:获取卸载的模块对应的shrinker中的回收函数。根据回收函数,在预先存储的全局数组中将shrinker的活跃指数加一。
一些实施方式中,响应于内存回收指令,回收注册在第一列表中的模块的内存,以及回收注册在第二列表中的模块的内存,包括:响应于内存回收指令,执行注册在第一列表中的每个模块对应的回收函数,回收第一列表中注册的每个模块的内存。响应于内存回收指令,执行注册在第二列表中的每个模块对应的回收函数,回收第二列表中注册的每个模块的内存。
第二方面,本申请实施例提供了一种内存回收装置,包括回收模块,用于响应于内存回收指令,回收注册在第一列表中的模块的内存,以及回收注册在第二列表中的模块的内存,其中,注册在第一列表中的模块的活跃指数小于第一阈值,注册在第二列表中的模块的活跃指数大于或等于第一阈值,活跃指数用于指示模块注册卸载的频繁程度。
一些实施方式中,该装置还包括注册模块,用于当模块注册时,获取注册的模块的活跃指数。当模块的活跃指数小于第一阈值时,将模块注册在第一列表中。当模块的活跃指数大于或等于第一阈值时,将模块注册在第二列表中。
一些实施方式中,该装置还包括卸载模块,用于当卸载第一列表或第二列表中注册的模块时,将卸载的模块的活跃指数加一。
一些实施方式中,每个模块对应一个shrinker,shrinker中包括模块对应的回收函数,回收函数用于在执行时回收模块的内存。
一些实施方式中,注册模块,具体用于将模块对应的shrinker注册在第一列表中。
一些实施方式中,注册模块,具体用于将模块对应的shrinker注册在第二列表中。
一些实施方式中,卸载模块,具体用于将第一列表或第二列表中的模块对应的shrinker从第一列表或第二列表中卸载。
一些实施方式中,注册模块,具体用于获取注册的模块对应的shrinker中的回收函数。根据回收函数,在预先存储的全局数组中获取shrinker的活跃指数,预先存储的全局数组中包括多个回收函数,以及每个回收函数对应的shrinker的活跃指数。将shrinker的活跃指数作为模块的活跃指数。
一些实施方式中,卸载模块,具体用于获取卸载的模块对应的shrinker中的回收函数。根据回收函数,在预先存储的全局数组中将shrinker的活跃指数加一,预先存储的全局数组中包括多个回收函数,以及每个回收函数对应的shrinker的活跃指数。
一些实施方式中,注册模块,还用于根据shrinker中的回收函数在预先存储的全局数组中获取shrinker的活跃指数,预先存储的全局数组中包括多个回收函数,以及每个回收函数对应的shrinker的活跃指数。将shrinker的活跃指数存储在shrinker中。
一些实施方式中,注册模块,具体用于根据回收函数,遍历预先存储的全局数组,查找与回收函数对应的shrinker的活跃指数。当查找到与回收函数对应的shrinker的活 跃指数时,将shrinker的活跃指数作为模块的活跃指数。当未查找到与回收函数对应的shrinker的活跃指数时,将回收函数添加进预先存储的全局数组中,并将回收函数对应的shrinker的活跃指数设为预设数值,将预设数值作为模块的活跃指数。
一些实施方式中,注册模块,具体用于获取注册的模块对应的shrinker中shrinker的活跃指数。将shrinker的活跃指数作为模块的活跃指数。
一些实施方式中,卸载模块,具体用于获取待卸载的模块对应的shrinker中shrinker的活跃指数。当shrinker的活跃指数小于第一阈值时,从第一列表中卸载模块。当shrinker的活跃指数大于或等于第一阈值时,从第二列表中卸载模块。
一些实施方式中,卸载模块,还用于将卸载的模块对应的shrinker中shrinker的活跃指数加一。
一些实施方式中,卸载模块,还用于获取卸载的模块对应的shrinker中的回收函数。根据回收函数,在预先存储的全局数组中将shrinker的活跃指数加一。
一些实施方式中,回收模块,具体用于响应于内存回收指令,执行注册在第一列表中的每个模块对应的回收函数,回收第一列表中注册的每个模块的内存。响应于内存回收指令,执行注册在第二列表中的每个模块对应的回收函数,回收第二列表中注册的每个模块的内存。
第三方面,本申请实施例提供了一种电子设备,包括:存储器、处理器以及存储在存储器中并可在处理器上运行的计算机程序,处理器执行计算机程序时实现第一方面提供的方法。
第四方面,本申请实施例提供了一种计算机可读存储介质,计算机可读存储介质存储有计算机程序,计算机程序被处理器执行时实现如第一方面提供的方法。
第五方面,本申请实施例提供了一种计算机程序产品,当计算机程序产品在电子设备上运行时,使得电子设备执行上述第一方面提供的方法。
第六方面,本申请实施例提供了一种芯片系统,芯片系统包括存储器和处理器,处理器执行存储器中存储的计算机程序,以实现第一方面提供的方法。
第七方面,本申请实施例提供了一种芯片系统,芯片系统包括处理器,处理器与第四方面提供的计算机可读存储介质耦合,处理器执行计算机可读存储介质中存储的计算机程序,以实现第一方面提供的方法。
可以理解的是,上述第二方面至第七方面的有益效果可以参见上述第一方面中的相关描述,在此不再赘述。
附图说明
图1示出了一种应用内存回收方法的电子设备的结构示意图;
图2示出了一种应用内存回收方法的电子设备的软件结构示意图;
图3示出了本申请提供的内存回收方法的示意性流程图;
图4示出了本申请提供的内存回收方法中第一列表和第二列表的示意图;
图5示出了本申请提供的内存回收方法中第一列表和第二列表的另一种示意图;
图6示出了本申请提供的内存回收方法中第一列表和第二列表的另一种示意图;
图7示出了本申请实施例提供的内存回收装置的结构框图;
图8示出了本申请实施例提供的另一种电子设备的结构示意图。
具体实施方式
以下描述中,为了说明而不是为了限定,提出了诸如特定系统结构、技术之类的具体细节,以便透彻理解本申请实施例。然而,本领域的技术人员应当清楚,在没有这些具体细节的其它实施例中也可以实现本申请。在其它情况中,省略对众所周知的系统、装置、电路以及方法的详细说明,以免不必要的细节妨碍本申请的描述。
应当理解,当在本申请说明书和所附权利要求书中使用时,术语“包括”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或多个其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。
还应当理解,在本申请说明书和所附权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。
如在本申请说明书和所附权利要求书中所使用的那样,术语“如果”可以依据上下文被解释为“当...时”或“一旦”或“响应于确定”或“响应于检测到”。
另外,在本申请说明书和所附权利要求书的描述中,术语“第一”、“第二”、“第三”等仅用于区分描述,而不能理解为指示或暗示相对重要性。
在本申请说明书中描述的参考“一个实施例”或“一些实施例”等意味着在本申请的一个或多个实施例中包括结合该实施例描述的特定特征、结构或特点。由此,在本说明书中的不同之处出现的语句“在一个实施例中”、“在一些实施例中”、“在其他一些实施例中”、“在另外一些实施例中”等不是必然都参考相同的实施例,而是意味着“一个或多个但不是所有的实施例”,除非是以其他方式另外特别强调。
在电子设备运行时,电子设备的系统内核会不时的对内存进行回收。例如,当内核接收到大于空闲内存的内存调用申请时,会强制回收内存,提供足够的内存以供调用。或者,内核还可以定时回收内存,为突发的内存调用做准备等。
以Linux系统为例,Linux内核可通过slab机制回收内存。slab机制是Linux系统中的一种基于伙伴系统的内存分配机制。在伙伴系统中,通常是以4kB的页为单位对内存进行管理和分配。但是,实际应用时的内存需求大多以字节为单位。通过slab机制,可以以字节为单位,将伙伴系统中的一页内存(4kB)进行分配和管理。
在Linux内核中,存在多个需要内存回收的模块,如闪存友好文件系统(Flash Friendly File System,f2fs)模块、可扩展只读文件系统(Extendable Read-Only File System,erofs)模块、低内存杀手(LowMemoryKiller,lmk)模块、图形处理器(graphics processing unit,gpu)模块等。这些需要内存回收的模块在申请slab内存时,每个模块会在Linux内核中注册一个shrinker,例如,f2fs模块注册的shrinker可以命名为f2fs_shrinker。类似的,erofs模块注册的shrinker可以命名为erofs_shrinker、lmk模块注册的shrinker可以命名为lmk_shrinker、gpu模块注册的shrinker可以命名为gpu_shrinker。
shrinker是一种结构体,结构体中存有用于实现对应模块slab内存回收的回收函数(scan_objects),Linux内核可以通过调用结构体中的scan_objects来回收对应模块申请的slab内存。例如,f2fs_shrinker中存有f2fs模块对应的scan_objects,当Linux内核调用f2fs_shrinker中的scan_objects后,可以回收f2fs模块申请的slab内存。
目前,一个模块初始化时,会将该模块对应的shrinker添加到全局列表shrinker_list 上。模块卸载时,也需要从shrinker_list上将对应的shrinker卸载。由于所有shrinker均注册在同一个shrinker_list上,而shrinker_list在被读写时,需通过shrinker_rwsem锁进行保护。导致当Linux内核回收slab内存(需读shrinker_list)时,其他模块注册或卸载shrinker(需写入shrinker_list)的行为会被阻塞,导致系统运行不畅,性能下降。
对此,本申请提供了一种内存回收方法,包括:响应于内存回收指令,回收注册在第一列表中的模块的内存,以及回收注册在第二列表中的模块的内存,其中,注册在第一列表中的模块的活跃指数小于第一阈值,注册在第二列表中的模块的活跃指数大于或等于第一阈值,活跃指数用于指示模块注册卸载的频繁程度。
由于在第一列表中注册的模块的活跃指数小于第一阈值,为注册卸载频率较低的模块(冷模块)。在第二列表中注册的模块的活跃指数大于或等于第一阈值,为注册卸载频率较高的模块(热模块)。使得第一列表中的模块在回收内存时,发生写入/读取的概率降低,进而降低回收内存时发生阻塞的概率,有效提高低内存状态下系统的动态性能。
本申请实施例提供的内存回收方法可以应用于手机、平板电脑、可穿戴设备、车载设备、增强现实(augmented reality,AR)/虚拟现实(virtual reality,VR)设备、笔记本电脑、超级移动个人计算机(ultra-mobile personal computer,UMPC)、上网本、个人数字助理(personal digital assistant,PDA)等电子设备上,本申请实施例对电子设备的具体类型不作任何限制。
图1示出了一种应用内存回收方法的电子设备的结构示意图。
在图1中,电子设备100可以包括处理器110,外部存储器接口120,内部存储器121,通用串行总线(universal serial bus,USB)接口130,充电管理模块140,电源管理模块141,电池142,天线1,天线2,移动通信模块150,无线通信模块160,音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,传感器模块180,按键190,马达191,指示器192,摄像头193,显示屏194,以及用户标识模块(subscriber identification module,SIM)卡接口195等。其中传感器模块180可以包括压力传感器180A,陀螺仪传感器180B,气压传感器180C,磁传感器180D,加速度传感器180E,距离传感器180F,接近光传感器180G,指纹传感器180H,温度传感器180J,触摸传感器180K,环境光传感器180L,骨传导传感器180M等。
可以理解的是,本申请实施例示意的结构并不构成对电子设备100的具体限定。在本申请另一些实施例中,电子设备100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
作为举例,当电子设备100为手机、平板电脑或大屏设备时,可以包括图示中的全部部件,也可以仅包括图示中的部分部件。
处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,存储器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理 器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
其中,控制器可以是电子设备100的神经中枢和指挥中心。控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。
处理器110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理器110中的存储器为高速缓冲存储器。该存储器可以保存处理器110刚用过或循环使用的指令或数据。如果处理器110需要再次使用该指令或数据,可从存储器中直接调用。避免了重复存取,减少了处理器110的等待时间,因而提高了系统的效率。
在一些实施例中,处理器110可以包括一个或多个接口。接口可以包括集成电路(inter-integrated circuit,I2C)接口,集成电路内置音频(inter-integrated circuit sound,I2S)接口,脉冲编码调制(pulse code modulation,PCM)接口,通用异步收发传输器(universal asynchronous receiver/transmitter,UART)接口,移动产业处理器接口(mobile industry processor interface,MIPI),通用输入输出(general-purpose input/output,GPIO)接口,用户标识模块(subscriber identity module,SIM)接口,和/或通用串行总线(universal serial bus,USB)接口等。
I2C接口是一种双向同步串行总线,包括一根串行数据线(serial data line,SDA)和一根串行时钟线(derail clock line,SCL)。在一些实施例中,处理器110可以包含多组I2C总线。处理器110可以通过不同的I2C总线接口分别耦合触摸传感器180K,充电器,闪光灯,摄像头193等。例如:处理器110可以通过I2C接口耦合触摸传感器180K,使处理器110与触摸传感器180K通过I2C总线接口通信,实现电子设备100的触摸功能。
I2S接口可以用于音频通信。在一些实施例中,处理器110可以包含多组I2S总线。处理器110可以通过I2S总线与音频模块170耦合,实现处理器110与音频模块170之间的通信。在一些实施例中,音频模块170可以通过I2S接口向无线通信模块160传递音频信号。
PCM接口也可以用于音频通信,将模拟信号抽样,量化和编码。在一些实施例中,音频模块170与无线通信模块160可以通过PCM总线接口耦合。
在一些实施例中,音频模块170也可以通过PCM接口向无线通信模块160传递音频信号。I2S接口和PCM接口都可以用于音频通信。
UART接口是一种通用串行数据总线,用于异步通信。该总线可以为双向通信总线。它将要传输的数据在与并行通信之间转换。
在一些实施例中,UART接口通常被用于连接处理器110与无线通信模块160。例如:处理器110通过UART接口与无线通信模块160中的蓝牙模块通信,实现蓝牙功能。在一些实施例中,音频模块170可以通过UART接口向无线通信模块160传递音频信号,实现通过蓝牙耳机播放音乐的功能。
MIPI接口可以被用于连接处理器110与显示屏194,摄像头193等外围器件。MIPI接口包括摄像头串行接口(camera serial interface,CSI),显示屏串行接口(display serial interface,DSI)等。在一些实施例中,处理器110和摄像头193通过CSI接口通信,实现电子设备100的拍摄功能。处理器110和显示屏194通过DSI接口通信,实现电子 设备100的显示功能。
GPIO接口可以通过软件配置。GPIO接口可以被配置为控制信号,也可被配置为数据信号。在一些实施例中,GPIO接口可以用于连接处理器110与摄像头193,显示屏194,无线通信模块160,音频模块170,传感器模块180等。GPIO接口还可以被配置为I2C接口,I2S接口,UART接口,MIPI接口等。
USB接口130是符合USB标准规范的接口,具体可以是Mini USB接口,Micro USB接口,USB Type C接口等。USB接口130可以用于连接充电器为电子设备100充电,也可以用于电子设备100与外围设备之间传输数据。也可以用于连接耳机,通过耳机播放音频。该接口还可以用于连接其他电子设备,例如AR设备等。
可以理解的是,本申请实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对电子设备100的结构限定。在本申请另一些实施例中,电子设备100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
充电管理模块140用于从充电器接收充电输入。其中,充电器可以是无线充电器,也可以是有线充电器。在一些有线充电的实施例中,充电管理模块140可以通过USB接口130接收有线充电器的充电输入。在一些无线充电的实施例中,充电管理模块140可以通过电子设备100的无线充电线圈接收无线充电输入。充电管理模块140为电池142充电的同时,还可以通过电源管理模块141为电子设备供电。
电源管理模块141用于连接电池142,充电管理模块140与处理器110。电源管理模块141接收电池142和/或充电管理模块140的输入,为处理器110,内部存储器121,外部存储器,显示屏194,摄像头193,和无线通信模块160等供电。电源管理模块141还可以用于监测电池容量,电池循环次数,电池健康状态(漏电,阻抗)等参数。
在其他一些实施例中,电源管理模块141也可以设置于处理器110中。在另一些实施例中,电源管理模块141和充电管理模块140也可以设置于同一个器件中。
电子设备100的无线通信功能可以通过天线1,天线2,移动通信模块150,无线通信模块160,调制解调处理器以及基带处理器等实现。
天线1和天线2用于发射和接收电磁波信号。电子设备100中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提高天线的利用率。例如:可以将天线1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开关结合使用。
移动通信模块150可以提供应用在电子设备100上的包括2G/3G/4G/5G等无线通信的解决方案。移动通信模块150可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块150可以由天线1接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块150还可以对经调制解调处理器调制后的信号放大,经天线1转为电磁波辐射出去。
在一些实施例中,移动通信模块150的至少部分功能模块可以被设置于处理器110中。在一些实施例中,移动通信模块150的至少部分功能模块可以与处理器110的至少部分模块被设置在同一个器件中。
调制解调处理器可以包括调制器和解调器。其中,调制器用于将待发送的低频基 带信号调制成中高频信号。解调器用于将接收的电磁波信号解调为低频基带信号。随后解调器将解调得到的低频基带信号传送至基带处理器处理。低频基带信号经基带处理器处理后,被传递给应用处理器。应用处理器通过音频设备(不限于扬声器170A,受话器170B等)输出声音信号,或通过显示屏194显示图像或视频。在一些实施例中,调制解调处理器可以是独立的器件。在另一些实施例中,调制解调处理器可以独立于处理器110,与移动通信模块150或其他功能模块设置在同一个器件中。
无线通信模块160可以提供应用在电子设备100上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块160可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块160经由天线2接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器110。无线通信模块160还可以从处理器110接收待发送的信号,对其进行调频,放大,经天线2转为电磁波辐射出去。
在一些实施例中,电子设备100的天线1和移动通信模块150耦合,天线2和无线通信模块160耦合,使得电子设备100可以通过无线通信技术与网络以及其他设备通信。无线通信技术可以包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),BT,GNSS,WLAN,NFC,FM,和/或IR技术等。GNSS可以包括全球卫星定位系统(global positioning system,GPS),全球导航卫星系统(global navigation satellite system,GLONASS),北斗卫星导航系统(beidou navigation satellite system,BDS),准天顶卫星系统(quasi-zenith satellite system,QZSS)和/或星基增强系统(satellite based augmentation systems,SBAS)。
电子设备100通过GPU,显示屏194,以及应用处理器等实现显示功能。GPU为图像处理的微处理器,连接显示屏194和应用处理器。GPU用于执行数学和几何计算,用于图形渲染。处理器110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。
显示屏194用于显示图像,视频等。例如本申请实施例中的教学视频和用户动作画面视频,显示屏194包括显示面板。显示面板可以采用液晶显示屏(liquid crystal display,LCD),有机发光二极管(organic light-emitting diode,OLED),有源矩阵有机发光二极体或主动矩阵有机发光二极体(active-matrix organic light emitting diode的,AMOLED),柔性发光二极管(flex light-emitting diode,FLED),Miniled,MicroLed,Micro-oLed,量子点发光二极管(quantum dot light emitting diodes,QLED)等。在一些实施例中,电子设备100可以包括1个或N个显示屏194,N为大于1的正整数。
电子设备100可以通过ISP,摄像头193,视频编解码器,GPU,显示屏194以及应用处理器等实现拍摄功能。
ISP用于处理摄像头193反馈的数据。例如,拍照时,打开快门,光线通过镜头 被传递到摄像头感光元件上,光信号转换为电信号,摄像头感光元件将电信号传递给ISP处理,转化为肉眼可见的图像。ISP还可以对图像的噪点,亮度,肤色进行算法优化。ISP还可以对拍摄场景的曝光,色温等参数优化。在一些实施例中,ISP可以设置在摄像头193中。
摄像头193用于捕获静态图像或视频。物体通过镜头生成光学图像投射到感光元件。镜头的焦段可以用于表示摄像头的取景范围,镜头的焦段越小,表示镜头的取景范围越大。感光元件可以是电荷耦合器件(charge coupled device,CCD)或互补金属氧化物半导体(complementary metal-oxide-semiconductor,CMOS)光电晶体管。感光元件把光信号转换成电信号,之后将电信号传递给ISP转换成数字图像信号。ISP将数字图像信号输出到DSP加工处理。DSP将数字图像信号转换成标准的RGB,YUV等格式的图像信号。
在本申请中,电子设备100可以包括2个或2个以上焦段的摄像头193。
数字信号处理器用于处理数字信号,除了可以处理数字图像信号,还可以处理其他数字信号。例如,当电子设备100在频点选择时,数字信号处理器用于对频点能量进行傅里叶变换等。
视频编解码器用于对数字视频压缩或解压缩。电子设备100可以支持一种或多种视频编解码器。这样,电子设备100可以播放或录制多种编码格式的视频,例如:动态图像专家组(moving picture experts group,MPEG)1,MPEG2,MPEG3,MPEG4等。
NPU为神经网络(neural-network,NN)计算处理器,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。通过NPU可以实现电子设备100的智能认知等应用,例如:图像识别,人脸识别,语音识别,文本理解等。
在本申请实施例中,NPU或其他处理器可以用于对电子设备100存储的视频中的图像进行分析处理等操作。
外部存储器接口120可以用于连接外部存储卡,例如Micro SD卡,实现扩展电子设备100的存储能力。外部存储卡通过外部存储器接口120与处理器110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部存储卡中。
内部存储器121可以用于存储计算机可执行程序代码,可执行程序代码包括指令。处理器110通过运行存储在内部存储器121的指令,从而执行电子设备100的各种功能应用以及数据处理。内部存储器121可以包括存储程序区和存储数据区。其中,存储程序区可存储操作系统,至少一个功能所需的应用程序(比如声音播放功能,图像播放功能等)。存储数据区可存储电子设备100使用过程中所创建的数据(比如音频数据,电话本等)。
此外,内部存储器121可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件,闪存器件,通用闪存存储器(universal flash storage,UFS)等。
电子设备100可以通过音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,以及应用处理器等实现音频功能。
音频模块170用于将数字音频信号转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块170还可以用于对音频信号编码和解码。在一些实施例中,音频模块170可以设置于处理器110中,或将音频模块170的部分功能模块设置于处理器110中。
扬声器170A,也称“喇叭”,用于将音频电信号转换为声音信号。电子设备100可以通过扬声器170A收听音乐,或收听免提通话,例如扬声器可以播放本申请实施例提供的比对分析结果。
受话器170B,也称“听筒”,用于将音频电信号转换成声音信号。当电子设备100接听电话或语音信息时,可以通过将受话器170B靠近人耳接听语音。
麦克风170C,也称“话筒”,“传声器”,用于将声音信号转换为电信号。当拨打电话或发送语音信息时,用户可以通过人嘴靠近麦克风170C发声,将声音信号输入到麦克风170C。电子设备100可以设置至少一个麦克风170C。在另一些实施例中,电子设备100可以设置两个麦克风170C,除了采集声音信号,还可以实现降噪功能。在另一些实施例中,电子设备100还可以设置三个,四个或更多麦克风170C,实现采集声音信号,降噪,还可以识别声音来源,实现定向录音功能等。
耳机接口170D用于连接有线耳机。耳机接口170D可以是USB接口130,也可以是3.5mm的开放移动电子设备平台(open mobile terminal platform,OMTP)标准接口,美国蜂窝电信工业协会(cellular telecommunications industry association of the USA,CTIA)标准接口。
压力传感器180A用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器180A可以设置于显示屏194。压力传感器180A的种类很多,如电阻式压力传感器,电感式压力传感器,电容式压力传感器等。电容式压力传感器可以是包括至少两个具有导电材料的平行板。当有力作用于压力传感器180A,电极之间的电容改变。电子设备100根据电容的变化确定压力的强度。当有触摸操作作用于显示屏194,电子设备100根据压力传感器180A检测触摸操作强度。电子设备100也可以根据压力传感器180A的检测信号计算触摸的位置。
在一些实施例中,作用于相同触摸位置,但不同触摸操作强度的触摸操作,可以对应不同的操作指令。例如:当有触摸操作强度小于第一压力阈值的触摸操作作用于短消息应用图标时,执行查看短消息的指令。当有触摸操作强度大于或等于第一压力阈值的触摸操作作用于短消息应用图标时,执行新建短消息的指令。
陀螺仪传感器180B可以用于确定电子设备100的运动姿态。在一些实施例中,可以通过陀螺仪传感器180B确定电子设备100围绕三个轴(即,x,y和z轴)的角速度。陀螺仪传感器180B可以用于拍摄防抖。示例性的,当按下快门,陀螺仪传感器180B检测电子设备100抖动的角度,根据角度计算出镜头模组需要补偿的距离,让镜头通过反向运动抵消电子设备100的抖动,实现防抖。陀螺仪传感器180B还可以用于导航,体感游戏场景。
气压传感器180C用于测量气压。在一些实施例中,电子设备100通过气压传感器180C测得的气压值计算海拔高度,辅助定位和导航。
磁传感器180D包括霍尔传感器。电子设备100可以利用磁传感器180D检测翻盖 皮套的开合。在一些实施例中,当电子设备100是翻盖机时,电子设备100可以根据磁传感器180D检测翻盖的开合。进而根据检测到的皮套的开合状态或翻盖的开合状态,设置翻盖自动解锁等特性。
加速度传感器180E可检测电子设备100在各个方向上(一般为三轴)加速度的大小。当电子设备100静止时可检测出重力的大小及方向。还可以用于识别电子设备姿态,应用于横竖屏切换,计步器等应用。
距离传感器180F,用于测量距离。电子设备100可以通过红外或激光测量距离。在一些实施例中,拍摄场景,电子设备100可以利用距离传感器180F测距以实现快速对焦。
接近光传感器180G可以包括例如发光二极管(LED)和光检测器,例如光电二极管。发光二极管可以是红外发光二极管。电子设备100通过发光二极管向外发射红外光。电子设备100使用光电二极管检测来自附近物体的红外反射光。当检测到充分的反射光时,可以确定电子设备100附近有物体。当检测到不充分的反射光时,电子设备100可以确定电子设备100附近没有物体。电子设备100可以利用接近光传感器180G检测用户手持电子设备100贴近耳朵通话,以便自动熄灭屏幕达到省电的目的。接近光传感器180G也可用于皮套模式,口袋模式自动解锁与锁屏。
环境光传感器180L用于感知环境光亮度。电子设备100可以根据感知的环境光亮度自适应调节显示屏194亮度。环境光传感器180L也可用于拍照时自动调节白平衡。环境光传感器180L还可以与接近光传感器180G配合,检测电子设备100是否在口袋里,以防误触。
指纹传感器180H用于采集指纹。电子设备100可以利用采集的指纹特性实现指纹解锁,访问应用锁,指纹拍照,指纹接听来电等。
温度传感器180J用于检测温度。在一些实施例中,电子设备100利用温度传感器180J检测的温度,执行温度处理策略。例如,当温度传感器180J上报的温度超过阈值,电子设备100执行降低位于温度传感器180J附近的处理器的性能,以便降低功耗实施热保护。在另一些实施例中,当温度低于另一阈值时,电子设备100对电池142加热,以避免低温导致电子设备100异常关机。在其他一些实施例中,当温度低于又一阈值时,电子设备100对电池142的输出电压执行升压,以避免低温导致的异常关机。
触摸传感器180K,也称“触控面板”。触摸传感器180K可以设置于显示屏194,由触摸传感器180K与显示屏194组成触摸屏,也称“触控屏”。触摸传感器180K用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。可以通过显示屏194提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传感器180K也可以设置于电子设备100的表面,与显示屏194所处的位置不同。
骨传导传感器180M可以获取振动信号。在一些实施例中,骨传导传感器180M可以获取人体声部振动骨块的振动信号。骨传导传感器180M也可以接触人体脉搏,接收血压跳动信号。
在一些实施例中,骨传导传感器180M也可以设置于耳机中,结合成骨传导耳机。音频模块170可以基于骨传导传感器180M获取的声部振动骨块的振动信号,解析出 语音信号,实现语音功能。应用处理器可以基于骨传导传感器180M获取的血压跳动信号解析心率信息,实现心率检测功能。
按键190包括开机键,音量键等。按键190可以是机械按键。也可以是触摸式按键。电子设备100可以接收按键输入,产生与电子设备100的用户设置以及功能控制有关的键信号输入。
马达191可以产生振动提示。马达191可以用于来电振动提示,也可以用于触摸振动反馈。例如,作用于不同应用(例如拍照,音频播放等)的触摸操作,可以对应不同的振动反馈效果。作用于显示屏194不同区域的触摸操作,马达191也可对应不同的振动反馈效果。不同的应用场景(例如:时间提醒,接收信息,闹钟,游戏等)也可以对应不同的振动反馈效果。触摸振动反馈效果还可以支持自定义。
指示器192可以是指示灯,可以用于指示充电状态,电量变化,也可以用于指示消息,未接来电,通知等。
SIM卡接口195用于连接SIM卡。SIM卡可以通过插入SIM卡接口195,或从SIM卡接口195拔出,实现和电子设备100的接触和分离。电子设备100可以支持1个或N个SIM卡接口,N为大于1的正整数。SIM卡接口195可以支持Nano SIM卡,Micro SIM卡,SIM卡等。同一个SIM卡接口195可以同时插入多张卡。多张卡的类型可以相同,也可以不同。SIM卡接口195也可以兼容不同类型的SIM卡。SIM卡接口195也可以兼容外部存储卡。电子设备100通过SIM卡和网络交互,实现通话以及数据通信等功能。在一些实施例中,电子设备100采用eSIM,即:嵌入式SIM卡。eSIM卡可以嵌在电子设备100中,不能和电子设备100分离。
图2示出了一种应用内存回收方法的电子设备的软件结构示意图。
作为示例,电子设备100中的操作系统可以是安卓(Android)系统,林纳斯(Linux)系统,微软窗口系统(Windows),苹果移动操作系统(iOS)或者鸿蒙系统(Harmony OS)等。本申请提供的方法尤其适用于Linux系统或基于Linux系统衍生的其他系统。在此,以电子设备100的操作系统为鸿蒙系统为例进行说明。
在一些实施例中,可将鸿蒙系统分为四层,包括内核层、系统服务层、框架层以及应用层,层与层之间通过软件接口通信。
如图2所示,内核层包括内核抽象层(kernel abstract layer,KAL)和驱动子系统。KAL下包括多个内核,如Linux系统的内核Linux Kernel、轻量级物联网系统内核LiteOS等。驱动子系统则可以包括硬件驱动框架(hardware driver foundation,HDF)。硬件驱动框架能够提供统一外设访问能力和驱动开发、管理框架。多内核的内核层可以根据系统的需求选择相应的内核进行处理。
系统服务层是鸿蒙系统的核心能力集合,系统服务层通过框架层对应用程序提供服务。该层可包括:
系统基本能力子系统集:为分布式应用在鸿蒙系统多设备上的运行、调度、迁移等操作提供了基础能力。可包括分布式软总线、分布式数据管理、分布式任务调度、多语言运行时、公共基础库、多模输入、图形、安全、人工智能(artificial intelligence,AI)、用户程序框架等子系统。其中,多语言运行时提供了C或C++或JavaScript(JS)多语言运行时和基础的系统类库,也可以为使用编译器静态化的Java程序(即应用程 序或框架层中使用Java语言开发的部分)提供运行时。
基础软件服务子系统集:为鸿蒙系统提供公共的、通用的软件服务。可包括事件通知、电话、多媒体、面向X设计(design for X,DFX)、MSDP&DV等子系统。
增强软件服务子系统集:为鸿蒙系统提供针对不同设备的、差异化的能力增强型软件服务。可包括智慧屏专有业务、穿戴专有业务、物联网(internet of things,IoT)专有业务子系统组成。
硬件服务子系统集:为鸿蒙系统提供硬件服务。可包括位置服务、生物特征识别、穿戴专有硬件服务、IoT专有硬件服务等子系统。
框架层为鸿蒙系统应用开发提供了Java、C、C++、JS等多语言的用户程序框架和能力(ability)框架,两种用户界面(user interface,UI)框架(包括适用于Java语言的Java UI框架、适用于JS语言的JS UI框架),以及各种软硬件服务对外开放的多语言框架应用程序接口(application programming interface,API)。根据系统的组件化裁剪程度,鸿蒙系统设备支持的API也会有所不同。
应用层包括系统应用和第三方非系统应用。系统应用可包括桌面、控制栏、设置、电话等电子设备默认安装的应用程序。扩展应用可以是由电子设备的制造商开发设计的、非必要的应用,如电子设备管家、换机迁移、便签、天气等应用程序。而第三方非系统应用则可以是由其他厂商开发,但是可以在鸿蒙系统中运行应用程序,如游戏、导航、社交或购物等应用程序。
鸿蒙系统的应用由一个或多个元程序(feature ability,FA)或元服务(particle ability,PA)组成。其中,FA有UI界面,提供与用户交互的能力。而PA无UI界面,提供后台运行任务的能力以及统一的数据访问抽象。PA主要为FA提供支持,例如作为后台服务提供计算能力,或作为数据仓库提供数据访问能力。基于FA或PA开发的应用,能够实现特定的业务功能,支持跨设备调度与分发,为用户提供一致、高效的应用体验。
多个运行鸿蒙系统的电子设备之间可以通过分布式软总线、分布式设备虚拟化、分布式数据管理和分布式任务调度实现硬件互助和资源共享。
图3示出了本申请提供的内存回收方法的示意性流程图,作为示例而非限定,该方法可以应用于上述电子设备100中,电子设备100运行的鸿蒙系统的内核子系统中包括Linux内核。
S201、响应于注册指令,获取注册模块的shrinker的活跃指数。
一些实施方式中,当Linux内核确定回收内存时,可以通过slab机制确定需要进行内存回收的模块并回收每个模块对应的内存。若一个模块需要回收内存,但是并未在第一列表或第二列表上注册。则确定该模块需要进行注册。Linux内核生成注册指令,指示该模块进行注册。
在注册之前,可以先根据该模块的shrinker中存储的回收函数,从预先存储的全局列表中获取该模块的shrinker的活跃指数。全局列表可以通过数组的形式存储在缓存、本地存储或云端中,全局列表中包括多个回收函数和与每个回收函数对应的活跃指数,每个回收函数对应一个shrinker,shrinker的活跃指数即为该shrinker对应的回收函数所对应的活跃指数。每个模块在第一次注册时(即在预先存储的全局列表中未 找到该模块对应的回收函数),会将模块的shrinker对应的回收函数写入全局列表中,并将shrinker的活跃指数设为预设数值,例如,回收函数对应的活跃指数的预设数值可以设为0。
作为示例,gpu模块的gpu_shrinker对应的回收函数可以写作gpu_scan_objects。当gup模块第一次注册时(即在全局列表中未找到gpu_scan_objects),将gpu_scan_objects写入全局列表中,并将gpu_scan_objects对应的活跃指数设为0。每当gpu模块卸载时,可以将全局列表中gpu_scan_objects对应的活跃指数加1。
当gpu模块再次注册时,根据gpu_scan_objects在全局列表中查找对应的活跃指数,并将查找到的活跃指数作为gpu_shrinker的活跃指数。
S202、将shrinker的活跃指数保存到shrinker中。
其中,shrinker是一个结构体,结构体由至少一个数据组成,组成结构体的每个数据称为结构体的一个“成员”,即结构体中包括至少一个成员。
本实施例中shrinker可以包括回收函数和活跃指数(active_index)等成员。例如,gpu_shrinker中,可以包括gpu_scan_objects以及gpu_active_index两个成员。参考S201,从全局列表中查找到的gpu_shrinker的活跃指数,可以存储在gpu_active_index中。
S203、确定shrinker的活跃指数是否小于第一阈值,若小于,则执行S204,否则执行S205。
S204、将shrinker注册到第一列表,执行S210。
S205、将shrinker注册到第二列表,执行S210。
一些实施方式中,第一列表中注册的shrinker的活跃指数均小于第一阈值。即第一列表也可称为“冷列表(cold shrinker list)”,第一列表中注册的shrinker对应的模块可称为“冷模块”。冷模块是Linux核心中卸载频率较低的模块,例如f2fs模块、erofs模块、lmk模块等。类似的,第二列表中注册的shrinker的活跃指数均大于或等于第一阈值。即第二列表也可称为“热列表(hot shrinker list)”,第二列表中注册的shrinker对应的模块可称为“热模块”。热模块是Linux核心中卸载频率较高的模块,例如gpu模块等。
其中,第一阈值可以是预先设置的数值。作为示例,在系统初始化时,可以将第一阈值设置为20。或者,第一阈值还可以从服务器或云端等地获取更新。例如,系统可以每隔10分钟从服务器或云端获取一个更新的第一阈值,更新的第一阈值可以是服务器根据每个电子设备上传的全局列表进行计算得到的。
需要说明的是,将shrinker注册到第一列或第二列表,指的是将该shrinker添加到对应的列表中。以下,结合图4和图5,对将shrinker注册到第一列或第二列表进行说明。
图4示出了本申请提供的内存回收方法中第一列表和第二列表的示意图,图5示出了本申请提供的内存回收方法中第一列表和第二列表的另一种示意图。
参考图4,第一列表中包括了“f2fs_shrinker”、“erofs_shrinker”以及“lmk_shrinker”3个shrinker。当“X_shrinker”注册到第一列表后,参考图5,第一列表中包括了“f2fs_shrinker”、“erofs_shrinker”、“lmk_shrinker”以及“X_shrinker”4个shrinker。其中“X_shrinker”用于表示可能注册到第一列表中的任意模块。
类似的,参考图4,第二列表中包括了“gpu_shrinker”1个shrinker。当“A_shrinker”、“B_shrinker”以及“C_shrinker”3个shrinker注册到第二列表后,参考图5,第二列表中包括了“gpu_shrinker”、“A_shrinker”、“B_shrinker”以及“C_shrinker”4个shrinker。其中“A_shrinker”、“B_shrinker”以及“C_shrinker”用于表示可能注册到第二列表中的任意模块。
一些实施方式中,第一列表和第二列表中shrinker的顺序根据其注册时间进行排序,注册最早的排序最靠前。例如,参考图5,在第一列表中,shrinker的顺序依次为“f2fs_shrinker”、“erofs_shrinker”、“lmk_shrinker”以及“X_shrinker”。在第二列表中,shrinker的顺序依次为“gpu_shrinker”、“A_shrinker”、“B_shrinker”以及“C_shrinker”。
S206、响应于卸载指令,获取待卸载的模块对应的shrinker中shrinker的活跃指数。
S207、确定shrinker的活跃指数是否小于第一阈值,若小于,则执行S208,否则执行S209。
S208、将shrinker从第一列表卸载。
S209、将shrinker从第二列表卸载。
一些实施方式中,当一个模块终止运行时,需将该模块对应的shrinker从第一列表或第二列表中卸载。卸载时,可以先从shrinker的active_index中获取该shrinker的活跃指数,并根据shrinker的活跃指数,确定从第一列表还是第二列表中卸载该shrinker。参考S201,当卸载一个shrinker后,还需将该shrinker的活跃指数加1。即,将active_index的数值加1,同时,根据shrinker中的scan_objects在全局列表中搜索对应的活跃指数,并将该活跃指数加1。
其中,S207的执行方式与S203相同,在此不做赘述。
一些实施方式中,模块终止运行,可以包括电子设备响应终止操作,终止对应的模块。或者,模块执行完任务后进行销毁等,在此不做限制。
需要说明的是,将shrinker从第一列或第二列表卸载,指的是将该shrinker从对应的列表中删除。以下,结合图5和图6,对将shrinker从第一列或第二列表卸载进行说明。
图6示出了本申请提供的内存回收方法中第一列表和第二列表的另一种示意图。
参考图5,第一列表中包括了“f2fs_shrinker”、“erofs_shrinker”、“lmk_shrinker”以及“X_shrinker”4个shrinker。参考图6,当卸载“X_shrinker”时,从第一列表中删除“X_shrinker”,第一列表中还剩下“f2fs_shrinker”、“erofs_shrinker”以及“lmk_shrinker”3个shrinker。
类似的,参考图5,第二列表中包括了“gpu_shrinker”、“A_shrinker”、“B_shrinker”以及“C_shrinker”4个shrinker。参考图6,当卸载“C_shrinker”时,从第二列表中删除“C_shrinker”,第二列表还剩下“gpu_shrinker”、“A_shrinker”以及“B_shrinker”3个shrinker。
需要说明的是,冷模块的活跃指数可以随着Linux核心的不断卸载、注册的行为,不断提高,直至卸载冷模块后,冷模块对应的活跃指数大于或等于第一阈值,则可以将冷模块注册到第二列表中,冷模块转变为热模块。
S210、确定是否接收到内存回收指令,若接收到,则执行S211,否则继续等待接收内存回收指令。
S211、响应于内存回收指令,回收第一列表中注册的shrinker的内存,以及回收第二列表中注册的shrinker的内存。
一些实施方式中,系统会监控剩余内存,当Linux内核接收到大于空闲内存的内存调用申请时,会强制回收内存。或者,Linux内核还可以定时回收内存,为突发的内存调用做准备等。
当系统强制回收内存或定期回收内存时,会向Linux内核发送内存回收指令,Linux内核接收到内存回收指令后,响应于内存回收指令,回收第一列表中注册的shrinker的内存,以及回收第二列表中注册的shrinker的内存。
一些实施方式中,回收第一列表或第二列表中注册的shrinker的内存,可以通过依次读取并执行第一列表或第二列表中每个shrinker中的scan_objects实现。例如,参考图5,回收第一列表对应的内存时,可按照“f2fs_shrinker”、“erofs_shrinker”、“lmk_shrinker”、“X_shrinker”的顺序,依次读取并执行shrinker中的scan_objects,回收对应模块的slab内存。
类似的,回收第二列表对应的内存时,可按照“gpu_shrinker”、“A_shrinker”、“B_shrinker”、“C_shrinker”的顺序,依次读取并执行shrinker中的scan_objects,回收对应模块的slab内存。
在本申请中,S201-S205为向列表中注册模块的步骤,S206-S209为从列表中卸载模块的步骤,S210和S211为回收列表对应的内存的步骤。S201-S205、S206-S209以及S210和S211可以同时执行或单独执行。例如,将模块注册到第一列表时,还可以从第二列表中卸载模块。或者,回收第一列表对应模块的slab内存时,可以将模块注册到第二列表或从第二列表卸载模块。
由于第一列表和第二列表相互独立,对第二列表进行注册/卸载操作不会影响回收第一列表对应模块的slab内存,可以有效的减少回收内存和注册/卸载操作发生阻塞的概率,有效提高低内存状态下系统的动态性能。
还有一些实施方式中,可以设置两个以上的列表,并根据多个阈值将模块的注册到对应的列表中,其确定模块归属、注册模块、卸载模块以及回收内存的方式与本申请类似,在此不做赘述。
应理解,上述实施例中各步骤的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。
对应于上文实施例所述的内存回收方法,图7示出了本申请实施例提供的内存回收装置的结构框图,为了便于说明,仅示出了与本申请实施例相关的部分。
参照图7,该内存回收装置包括:
回收模块31,用于响应于内存回收指令,回收注册在第一列表中的模块的内存,以及回收注册在第二列表中的模块的内存,其中,注册在第一列表中的模块的活跃指数小于第一阈值,注册在第二列表中的模块的活跃指数大于或等于第一阈值,活跃指数用于指示模块注册卸载的频繁程度。
一些实施方式中,该装置还包括注册模块32,用于当模块注册时,获取注册的模块的活跃指数。当模块的活跃指数小于第一阈值时,将模块注册在第一列表中。当模块的活跃指数大于或等于第一阈值时,将模块注册在第二列表中。一些实施方式中,该装置还包括卸载模块33,用于当卸载第一列表或第二列表中注册的模块时,将卸载的模块的活跃指数加一。
一些实施方式中,每个模块对应一个shrinker,shrinker中包括模块对应的回收函数,回收函数用于在执行时回收模块的内存。
一些实施方式中,注册模块32,具体用于将模块对应的shrinker注册在第一列表中。
一些实施方式中,注册模块32,具体用于将模块对应的shrinker注册在第二列表中。
一些实施方式中,卸载模块33,具体用于将第一列表或第二列表中的模块对应的shrinker从第一列表或第二列表中卸载。
一些实施方式中,注册模块32,具体用于获取注册的模块对应的shrinker中的回收函数。根据回收函数,在预先存储的全局数组中获取shrinker的活跃指数,预先存储的全局数组中包括多个回收函数,以及每个回收函数对应的shrinker的活跃指数。将shrinker的活跃指数作为模块的活跃指数。
一些实施方式中,注册模块32,具体用于根据回收函数,遍历预先存储的全局数组,查找与回收函数对应的shrinker的活跃指数。当查找到与回收函数对应的shrinker的活跃指数时,将shrinker的活跃指数作为模块的活跃指数。当未查找到与回收函数对应的shrinker的活跃指数时,将回收函数添加进预先存储的全局数组中,并将回收函数对应的shrinker的活跃指数设为预设数值,将预设数值作为模块的活跃指数。
一些实施方式中,卸载模块33,具体用于获取卸载的模块对应的shrinker中的回收函数。根据回收函数,在预先存储的全局数组中将shrinker的活跃指数加一,预先存储的全局数组中包括多个回收函数,以及每个回收函数对应的shrinker的活跃指数。
一些实施方式中,注册模块32,还用于根据shrinker中的回收函数在预先存储的全局数组中获取shrinker的活跃指数,预先存储的全局数组中包括多个回收函数,以及每个回收函数对应的shrinker的活跃指数。将shrinker的活跃指数存储在shrinker中。
一些实施方式中,注册模块32,具体用于获取注册的模块对应的shrinker中shrinker的活跃指数。将shrinker的活跃指数作为模块的活跃指数。
一些实施方式中,卸载模块33,具体用于获取待卸载的模块对应的shrinker中shrinker的活跃指数。当shrinker的活跃指数小于第一阈值时,从第一列表中卸载模块。当shrinker的活跃指数大于或等于第一阈值时,从第二列表中卸载模块。
一些实施方式中,卸载模块33,还用于将卸载的模块对应的shrinker中shrinker的活跃指数加一。
一些实施方式中,卸载模块33,还用于获取卸载的模块对应的shrinker中的回收函数。根据回收函数,在预先存储的全局数组中将shrinker的活跃指数加一。
一些实施方式中,回收模块31,具体用于响应于内存回收指令,执行注册在第一 列表中的每个模块对应的回收函数,回收第一列表中注册的每个模块的内存。响应于内存回收指令,执行注册在第二列表中的每个模块对应的回收函数,回收第二列表中注册的每个模块的内存。
需要说明的是,上述模块之间的信息交互、执行过程等内容,由于与本申请方法实施例基于同一构思,其具体功能及带来的技术效果,具体可参见方法实施例部分,此处不再赘述。
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,仅以上述各功能单元、模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元、模块完成,即将所述装置的内部结构划分成不同的功能单元或模块,以完成以上描述的全部或者部分功能。实施例中的各功能单元、模块可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中,上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。另外,各功能单元、模块的具体名称也只是为了便于相互区分,并不用于限制本申请的保护范围。上述系统中单元、模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
图8示出了本申请一实施例提供的电子设备的结构框图。如图8所示,该实施例的电子设备400包括:至少一个处理器401(图8中仅示出一个)、存储器402以及存储在存储器402中并可在至少一个处理器401上运行的计算机程序403,处理器401执行计算机程序403时实现上述各个实施例中网络切换方法的步骤。
电子设备400可以是智能手机、平板电脑、可穿戴设备、增强现实(augmented reality,AR)/虚拟现实(virtual reality,VR)设备、大屏设备、车载终端等。该电子设备可包括,但不仅限于,处理器401、存储器402。
本领域技术人员可以理解,图8仅仅是电子设备400的举例,并不构成对电子设备400的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件,例如还可以包括输入输出设备、网络接入设备等。
所称处理器401可以是中央处理单元(central processing unit,CPU),该处理器401还可以是其他通用处理器、数字信号处理器(digital signal processor,DSP)、专用集成电路(application specific integrated circuit,ASIC)、现成可编程门阵列(field-programmable gate array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
存储器402在一些实施例中可以是电子设备400的内部存储单元,例如电子设备400的硬盘或内存。存储器402在另一些实施例中也可以是电子设备400的外部存储设备,例如电子设备400上配备的插接式硬盘,智能存储卡(smart media card,SMC),安全数字(secure digital,SD)卡,闪存卡(flash card)等。
进一步地,存储器402还可以既包括电子设备400的内部存储单元也包括外部存储设备。存储器402用于存储操作系统、应用程序、引导装载程序(bootloader)、数据以及其他程序等,例如计算机程序的程序代码等。存储器402还可以用于暂时地存储已经输出或者将要输出的数据。
本申请实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现可实现上述各个方法实施例中的步骤。
本申请实施例提供了一种计算机程序产品,当计算机程序产品在移动终端上运行时,使得移动终端执行时实现可实现上述各个方法实施例中的步骤。
本申请实施例提供了一种芯片系统,芯片系统包括存储器和处理器,处理器执行存储器中存储的计算机程序,以实现上述各个方法实施例中的步骤。
本申请实施例提供了一种芯片系统,芯片系统包括处理器,处理器与计算机可读存储介质耦合,处理器执行计算机可读存储介质中存储的计算机程序,以实现上述各个方法实施例中的步骤。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实现上述实施例方法中的全部或部分流程,可以通过计算机程序来指令相关的硬件来完成,所述的计算机程序可存储于一计算机可读存储介质中,该计算机程序在被处理器执行时,可实现上述各个方法实施例的步骤。其中,所述计算机程序包括计算机程序代码,所述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读介质至少可以包括:能够将计算机程序代码携带到电子设备的任何实体或装置、记录介质、计算机存储器、只读存储器(read-only memory,ROM)、随机存取存储器(random access memory,RAM)、电载波信号、电信信号以及软件分发介质。例如U盘、移动硬盘、磁碟或者光盘等。在某些司法管辖区,根据立法和专利实践,计算机可读介质不可以是电载波信号和电信信号。
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述或记载的部分,可以参见其它实施例的相关描述。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
在本申请所提供的实施例中,应该理解到,所揭露的方法、装置和电子设备,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通讯连接可以是通过一些接口,装置或单元的间接耦合或通讯连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
最后应说明的是:以上所述,仅为本申请的具体实施方式,但本申请的保护范围 并不局限于此,任何在本申请揭露的技术范围内的变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。

Claims (19)

  1. 一种内存回收方法,其特征在于,包括:
    响应于内存回收指令,回收注册在第一列表中的模块的内存,以及回收注册在第二列表中的模块的内存,其中,注册在所述第一列表中的模块的活跃指数小于第一阈值,注册在所述第二列表中的模块的活跃指数大于或等于第一阈值,所述活跃指数用于指示所述模块注册卸载的频繁程度。
  2. 根据权利要求1所述的方法,其特征在于,所述方法还包括:
    当模块注册时,获取注册的模块的活跃指数;
    当所述模块的活跃指数小于第一阈值时,将所述模块注册在所述第一列表中;
    当所述模块的活跃指数大于或等于第一阈值时,将所述模块注册在所述第二列表中。
  3. 根据权利要求1或2所述的方法,其特征在于,所述方法还包括:
    当卸载所述第一列表或所述第二列表中注册的模块时,将卸载的模块的活跃指数加一。
  4. 根据权利要求2或3所述的方法,其特征在于,每个所述模块对应一个shrinker,所述shrinker中包括所述模块对应的回收函数,所述回收函数用于在执行时回收所述模块的内存。
  5. 根据权利要求4所述的方法,其特征在于,将所述模块注册在所述第一列表中,包括:
    将所述模块对应的所述shrinker注册在所述第一列表中。
  6. 根据权利要求4或5所述的方法,其特征在于,将所述模块注册在所述第二列表中,包括:
    将所述模块对应的所述shrinker注册在所述第二列表中。
  7. 根据权利要求4-6任一项所述的方法,其特征在于,卸载所述第一列表或所述第二列表中的模块,包括:
    将所述第一列表或所述第二列表中的模块对应的所述shrinker从所述第一列表或所述第二列表中卸载。
  8. 根据权利要求4-6任一项所述的方法,其特征在于,当所述模块注册时,获取注册的模块的活跃指数,包括:
    获取注册的模块对应的所述shrinker中的回收函数;
    根据所述回收函数,在预先存储的全局数组中获取所述shrinker的活跃指数,所述预先存储的全局数组中包括多个回收函数,以及每个所述回收函数对应的shrinker的活跃指数;
    将所述shrinker的活跃指数作为所述模块的活跃指数。
  9. 根据权利要求8所述的方法,其特征在于,所述根据所述回收函数,在预先存储的全局数组中获取所述shrinker的活跃指数,包括:
    根据所述回收函数,遍历所述预先存储的全局数组,查找与所述回收函数对应的shrinker的活跃指数;
    当查找到与所述回收函数对应的shrinker的活跃指数时,将所述shrinker的活跃 指数作为所述模块的活跃指数;
    当未查找到与所述回收函数对应的shrinker的活跃指数时,将所述回收函数添加进所述预先存储的全局数组中,并将所述回收函数对应的shrinker的活跃指数设为预设数值,将所述预设数值作为所述模块的活跃指数。
  10. 根据权利要求4或7所述的方法,其特征在于,将卸载的所述模块的活跃指数加一,包括:
    获取卸载的模块对应的所述shrinker中的回收函数;
    根据所述回收函数,在预先存储的全局数组中将所述shrinker的活跃指数加一,所述预先存储的全局数组中包括多个回收函数,以及每个所述回收函数对应的shrinker的活跃指数。
  11. 根据权利要求4-10任一项所述的方法,其特征在于,所述方法还包括:
    根据所述shrinker中的回收函数在预先存储的全局数组中获取所述shrinker的活跃指数,所述预先存储的全局数组中包括多个回收函数,以及每个所述回收函数对应的shrinker的活跃指数;
    将所述shrinker的活跃指数存储在所述shrinker中。
  12. 根据权利要求11所述的方法,其特征在于,获取注册的模块的活跃指数,包括:
    获取注册的模块对应的所述shrinker中所述shrinker的活跃指数;
    将所述shrinker的活跃指数作为所述模块的活跃指数。
  13. 根据权利要求11或12所述的方法,其特征在于,所述卸载所述第一列表或所述第二列表中注册的模块,包括:
    获取待卸载的模块对应的shrinker中所述shrinker的活跃指数;
    当所述shrinker的活跃指数小于所述第一阈值时,从所述第一列表中卸载所述模块;
    当所述shrinker的活跃指数大于或等于所述第一阈值时,从所述第二列表中卸载所述模块。
  14. 根据权利要求11或13所述的方法,其特征在于,将卸载的所述模块的活跃指数加一,包括:
    将卸载的模块对应的所述shrinker中所述shrinker的活跃指数加一。
  15. 根据权利要求14所述的方法,其特征在于,在将卸载的模块对应的所述shrinker中所述shrinker的活跃指数加一之后,还包括:
    获取所述卸载的模块对应的所述shrinker中的回收函数;
    根据所述回收函数,在所述预先存储的全局数组中将所述shrinker的活跃指数加一。
  16. 根据权利要求4-15任一项所述的方法,其特征在于,所述响应于内存回收指令,回收注册在第一列表中的模块的内存,以及回收注册在第二列表中的模块的内存,包括:
    响应于所述内存回收指令,执行注册在所述第一列表中的每个模块对应的回收函数,回收所述第一列表中注册的每个模块的内存;
    响应于所述内存回收指令,执行注册在所述第二列表中的每个模块对应的回收函数,回收所述第二列表中注册的每个模块的内存。
  17. 一种内存回收装置,其特征在于,包括:
    回收模块,用于响应于内存回收指令,回收注册在第一列表中的模块的内存,以及回收注册在第二列表中的模块的内存,其中,注册在所述第一列表中的模块的活跃指数小于第一阈值,注册在所述第二列表中的模块的活跃指数大于或等于第一阈值,所述活跃指数用于指示所述模块注册卸载的频繁程度。
  18. 一种电子设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,其特征在于,所述处理器执行所述计算机程序时实现如权利要求1至15任一项所述的方法。
  19. 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现如权利要求1至15任一项所述的方法。
PCT/CN2022/113964 2021-09-29 2022-08-22 内存回收方法、装置、电子设备及可读存储介质 WO2023051094A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111167835.2A CN115878500A (zh) 2021-09-29 2021-09-29 内存回收方法、装置、电子设备及可读存储介质
CN202111167835.2 2021-09-29

Publications (1)

Publication Number Publication Date
WO2023051094A1 true WO2023051094A1 (zh) 2023-04-06

Family

ID=85756793

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/113964 WO2023051094A1 (zh) 2021-09-29 2022-08-22 内存回收方法、装置、电子设备及可读存储介质

Country Status (2)

Country Link
CN (1) CN115878500A (zh)
WO (1) WO2023051094A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116795298A (zh) * 2023-08-28 2023-09-22 麒麟软件有限公司 一种Linux下NVME存储器的IO优化方法及系统

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140095838A1 (en) * 2012-09-28 2014-04-03 Vijaykumar Vijay Kadgi Physical Reference List for Tracking Physical Register Sharing
CN107220076A (zh) * 2016-09-27 2017-09-29 华为技术有限公司 一种内存回收方法及装置
CN108228339A (zh) * 2017-07-28 2018-06-29 珠海市魅族科技有限公司 一种内存回收方法及装置、终端设备及计算机可读存储介质

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140095838A1 (en) * 2012-09-28 2014-04-03 Vijaykumar Vijay Kadgi Physical Reference List for Tracking Physical Register Sharing
CN107220076A (zh) * 2016-09-27 2017-09-29 华为技术有限公司 一种内存回收方法及装置
CN108228339A (zh) * 2017-07-28 2018-06-29 珠海市魅族科技有限公司 一种内存回收方法及装置、终端设备及计算机可读存储介质

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116795298A (zh) * 2023-08-28 2023-09-22 麒麟软件有限公司 一种Linux下NVME存储器的IO优化方法及系统
CN116795298B (zh) * 2023-08-28 2023-11-24 麒麟软件有限公司 一种Linux下NVME存储器的IO优化方法及系统

Also Published As

Publication number Publication date
CN115878500A (zh) 2023-03-31

Similar Documents

Publication Publication Date Title
CN114443277A (zh) 内存管理方法、装置、电子设备以及计算机可读存储介质
WO2021017901A1 (zh) 一种屏幕显示方法及电子设备
EP3859576B1 (en) Application permission management method and electronic device
WO2021159746A1 (zh) 文件共享方法、系统及相关设备
WO2021253975A1 (zh) 应用程序的权限管理方法、装置和电子设备
CN113168461A (zh) 一种删除安全业务的方法及电子设备
CN113805797B (zh) 网络资源的处理方法、电子设备及计算机可读存储介质
WO2021218429A1 (zh) 应用窗口的管理方法、终端设备及计算机可读存储介质
WO2021093626A1 (zh) 一种内存的管理方法及电子设备
CN114116191A (zh) 内存冷页的处理方法及电子设备
WO2023273543A1 (zh) 一种文件夹管理方法及装置
CN113973398A (zh) 无线网络连接方法、电子设备及芯片系统
WO2023051094A1 (zh) 内存回收方法、装置、电子设备及可读存储介质
CN114077519B (zh) 一种系统服务恢复方法、装置和电子设备
CN114968543A (zh) 文件页的处理方法及相关装置
CN115022982B (zh) 多屏协同无感接入方法、电子设备及存储介质
CN113901485B (zh) 应用程序加载方法、电子设备及存储介质
CN114461589B (zh) 读取压缩文件的方法、文件系统及电子设备
WO2022022466A1 (zh) 一种确定文件存储位置的方法、装置及终端
CN116828100A (zh) 蓝牙音频播放方法、电子设备及存储介质
CN114489469A (zh) 一种数据读取方法、电子设备及存储介质
CN110737916A (zh) 通信终端及处理方法
CN113704209B (zh) 数据共享方法、电子设备及存储介质
CN116048772B (zh) 中央处理单元频率的调整方法、装置和终端设备
WO2023185623A1 (zh) 后台应用恢复方法、装置、电子设备及可读存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22874487

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE