Method and electronic device for managing memory swap partition

By dynamically managing the storage space of the memory swap partition by creating and deleting files in the electronic device, the problem that the memory swap partition in the electronic device is fixed and cannot be returned is solved, achieving efficient utilization of storage space and flexible management of the memory swap partition.

CN116719633BActive Publication Date: 2024-09-06HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211148030.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-20
Publication Date
2024-09-06
Estimated Expiration
2042-09-20

AI Technical Summary

Technical Problem

In the existing technology, the fixed raw partition of the memory swap partition of the electronic device cannot be returned, resulting in the problem of wasted storage space.

Method used

Dynamically manage the storage space of the memory swap partition by creating and deleting files in electronic devices, using reserved files and non-reserved files as memory swap partitions to release storage space as needed and optimize the use of storage space.

Benefits of technology

It effectively reduces the waste of storage space, improves the flexibility and management efficiency of the memory swap partition, and dynamically adjusts the size of the memory swap partition to adapt to different usage situations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116719633B
    Figure CN116719633B
Patent Text Reader

Abstract

The embodiment of the present application provides a method and electronic device for managing memory swap partitions, the method is performed by the electronic device, including: when the electronic device receives a first operation, creating a first file in a first storage space, the first file includes a first preset number of bytes, wherein the storage space occupied by the first file in the first storage space is a memory swap partition, and the first operation is an operation of powering on the electronic device and / or turning on a function of using the memory swap partition; when the electronic device receives a second operation, deleting the first file in the first storage space, the second operation is an operation of turning off a function of using the memory swap partition. The method can return the storage space of the memory swap partition as needed, reducing the problem of storage space waste.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of storage technology, and in particular to a method and electronic device for managing memory swap partitions. Background Art

[0002] In electronic device systems, such as the Android system, a memory swap partition (Swap partition) solution is proposed to improve the problem of small memory space. Currently, a more popular solution is to release a portion of space in the memory, hard disk or other storage devices as a Swap partition for use by currently running programs.

[0003] Among them, in the related technology, when the electronic device leaves the factory, the fixed raw partition in the storage space is used as the Swap partition. However, in this solution, the storage space of the fixed raw partition cannot be returned, which easily causes the problem of storage space waste. Summary of the invention

[0004] The present application provides a method and electronic device for managing a memory swap partition, which can return the storage space of the memory swap partition as needed, thereby reducing the problem of storage space waste.

[0005] In a first aspect, the present application provides a method for managing a memory swap partition, which is executed by an electronic device, comprising: when the electronic device receives a first operation, creating a first file in a first storage space, the first file includes a first preset number of bytes, wherein the storage space occupied by the first file in the first storage space is a memory swap partition, and the first operation is an operation to power on the electronic device and / or to enable a function of using the memory swap partition; when the electronic device receives a second operation, deleting the first file in the first storage space, and the second operation is an operation to disable the function of using the memory swap partition.

[0006] Among them, the first file can be a non-reserved file, and the first file occupies a space size of a first preset number of bytes; the first storage space can be a storage disk of the electronic device, for example, it can be a data disk. When the electronic device is turned on or receives an operation to turn on the function of using the memory swap partition, it can create a first file occupying a first preset number of bytes in the first storage space, and use the storage space corresponding to the first file as a memory swap partition for subsequent use. In addition, the first file can be deleted when the function of using the memory swap partition is turned off to release the storage space occupied by it. Optionally, the above-mentioned first operation can be the first power-on operation of the electronic device, that is, the above-mentioned first file is only created when the electronic device is turned on for the first time.

[0007] Optionally, the electronic device may also periodically count usage of the memory swap partition, and when the memory swap partition is used less frequently, the first file may be automatically deleted to further reduce storage space waste.

[0008] In the above implementation, the electronic device creates a file on the storage space as a memory swap partition, and can delete the file as needed to release the storage space corresponding to the file, thereby reducing the problem of storage space waste.

[0009] In combination with the first aspect, in some implementations of the first aspect, the above-mentioned creation of the first file in the first storage space includes: determining whether there is available storage space in the first storage space that has continuous physical addresses and occupies a first preset number of bytes; if so, allocating the available storage space to the first file; if not, allocating available storage space in the first storage space that has discontinuous physical addresses and occupies a first preset number of bytes to the first file.

[0010] That is to say, when creating a first file that occupies a first preset number of bytes, a storage space with a continuous physical address is preferentially allocated to the first file to facilitate management of the first file. When there is no storage space with a continuous physical address that is large enough, a storage space with a discontinuous physical address is allocated to the first file so that the final total size is the first preset number of bytes to improve the success rate of creating the first file. Optionally, when creating the first file corresponding to the storage space with a continuous physical address, it can be created through the F2FS interface.

[0011] Optionally, when the physical address of the storage space corresponding to the first file is discontinuous, the storage space corresponding to the first file may include multiple sub-storage spaces with continuous physical addresses, each sub-storage space corresponds to a sub-file, that is, the first file includes multiple sub-files with continuous physical addresses, and the storage space occupied by these sub-files may be the same or different.

[0012] In combination with the first aspect, in some implementations of the first aspect, after the first file is created in the first storage space, the method further includes: when the physical address of the storage space corresponding to the first file is continuous, storing the first file in the form of a block device; when the physical address of the storage space corresponding to the first file is discontinuous, storing the first file in the form of a loop device.

[0013] In order to adapt to the I / O management strategy of current electronic devices, after creating the first file, the electronic device can also dump the first file as a block device. However, when the physical address of the storage space corresponding to the first file is discontinuous, it cannot be directly converted into an ordinary block device, and it needs to be dumped as a loop device, where the loop device is a special block device.

[0014] In the above implementation, the electronic device dumps the created first file as a block (or loop device) to adapt to the I / O management strategy of the current electronic device, thereby improving the compatibility of the above method for managing memory swap partitions.

[0015] In combination with the first aspect, in some implementations of the first aspect, the method further includes: adjusting the number of bytes included in the first file according to usage of the memory swap partition during operation of the electronic device.

[0016] Among them, the usage of the memory swap partition by the electronic device may include the usage probability and the usage ratio. The usage probability may be the number of times the memory swap partition is used per month (or per week, etc.), and the usage ratio may be the ratio of the used space size to the total size of the memory swap partition. If the usage frequency is high and the usage ratio is high, the number of bytes included in the first file may be increased, that is, the storage space corresponding to the first file may be expanded; if the usage frequency is low and the usage ratio is low, the number of bytes included in the first file may be reduced, that is, the storage space corresponding to the first file may be reduced. Thus, the electronic device may dynamically adjust the size of the memory swap partition to optimize the usage of the storage space.

[0017] In combination with the first aspect, in some implementations of the first aspect, when the electronic device receives the first operation, the above method also includes: creating a second file in the first storage space, the second file includes a second preset number of bytes, and the storage space occupied by the first file in the first storage space and the storage space occupied by the second file in the first storage space are memory swap partitions; when the electronic device receives the second operation, the above method also includes: not deleting the second file in the first storage space.

[0018] The second file may be a reserved file, that is, when the electronic device receives the first operation, the electronic device simultaneously creates the first file and the second file, and the difference is that the second file is not deleted subsequently, that is, the storage space corresponding to the second file is not released, so that the electronic device can always retain a part of the memory swap partition to ensure the normal operation of the electronic device. Optionally, the number of bytes included in the first file and the second file may be a preset fixed number, or a changeable number input by the user.

[0019] Optionally, in this implementation, the physical address of the storage space corresponding to the second file may be a continuous address, which may be a file created through the F2FS interface.

[0020] In one implementation, when the memory swap partition has been created, in order to facilitate the management of the corresponding first file and the second file, the electronic device can create a correspondence between the virtual address and the physical address of the storage space corresponding to the first file, and the virtual address and the physical address of the storage space corresponding to the second file. Then, when the memory swap partition is used subsequently, the electronic device can determine the physical address corresponding to the unused storage space based on the virtual address corresponding to the unused storage space and the correspondence, so as to find out which file the physical address corresponds to, and store the data to be stored in the file. Preferably, the electronic device can map the physical address of the storage space corresponding to the first file to the low bit of the virtual address, and the physical address of the storage space corresponding to the second file to the high bit of the virtual address, and give priority to using the reserved file (i.e., the second file) when using it.

[0021] In the above implementation, the electronic device applies for reserved files and non-reserved files as memory swap partitions, so that the non-reserved files can be released later to return the storage space, thereby reducing the waste of storage space; and the size of the non-reserved files can be dynamically adjusted to further optimize the use of storage space.

[0022] In a second aspect, the present application provides a device, which is included in an electronic device, and the device has the function of implementing the electronic device behavior in the above-mentioned first aspect and the possible implementation of the above-mentioned first aspect. The function can be implemented by hardware, or it can be implemented by hardware executing corresponding software. The hardware or software includes one or more modules or units corresponding to the above-mentioned functions. For example, a receiving module or unit, a processing module or unit, etc.

[0023] In a third aspect, the present application provides an electronic device, comprising: a processor, a memory, and an interface; the processor, the memory, and the interface cooperate with each other so that the electronic device executes any one of the methods in the technical solution of the first aspect.

[0024] In a fourth aspect, the present application provides a chip, including a processor. The processor is used to read and execute a computer program stored in a memory to perform the method in the first aspect and any possible implementation thereof.

[0025] Optionally, the chip also includes a memory, and the memory is connected to the processor via a circuit or wire.

[0026] Further optionally, the chip also includes a communication interface.

[0027] In a fifth aspect, the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the processor executes any one of the methods in the technical solution of the first aspect.

[0028] In a sixth aspect, the present application provides a computer program product, the computer program product comprising: a computer program code, when the computer program code runs on an electronic device, the electronic device executes any one of the methods in the technical solution of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0030] Figure 2 is a software structure block diagram of an electronic device provided in an embodiment of the present application;

[0031] Figure 3 It is a flowchart of a method for managing memory swap partitions provided in an embodiment of the present application;

[0032] Figure 4 This is a schematic diagram of a mapping relationship between a virtual address and a physical address provided in an embodiment of the present application;

[0033] Figure 5 This is a schematic diagram of a setting interface of a smart memory function provided in an embodiment of the present application;

[0034] Figure 6 is a schematic diagram of another setting interface of the smart memory function provided in an embodiment of the present application;

[0035] Figure 7 It is a flowchart of another method for managing memory swap partitions provided in an embodiment of the present application;

[0036] Figure 8 This is a schematic diagram of a process for allocating reserved files and non-reserved files provided in an embodiment of the present application;

[0037] Fig. 9 This is a schematic diagram of module interaction of a method for managing memory swap partitions provided in an embodiment of the present application. DETAILED DESCRIPTION

[0038] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0039] In the following, the terms "first", "second", and "third" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first", "second", and "third" may explicitly or implicitly include one or more of the features.

[0040] At present, in order to improve the problem of small memory space in the use of Android system, a memory saving solution is proposed, such as creating a Swap partition on the read-only memory (ROM), that is, dumping anonymous pages that are not frequently used in the system to the Swap partition of the ROM to expand the memory space. Among them, the Swap partition is a technology that releases part of the space in the memory, hard disk or other storage devices for use by the currently running program when the physical memory of the system is insufficient.

[0041] In the related art, some methods use the raw partition on the ROM as the Swap partition to expand the memory space, such as using the hyperhold raw partition as the Swap partition. However, this method generally divides the fixed partition space when the electronic device leaves the factory, and these fixed partition spaces cannot be returned to the ROM later, and the fixed partition space cannot be dynamically adjusted.

[0042] In view of this, an embodiment of the present application provides a method for managing memory swap partitions, which flexibly expands memory space by applying for reserved files and non-reserved files as memory swap partitions; wherein non-reserved files can be released to return storage space, and the method can also dynamically adjust the size of reserved files and non-reserved files. It should be noted that the method for managing memory swap partitions provided in the embodiment of the present application can be applied to electronic devices such as mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptops, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), etc. The embodiment of the present application does not impose any restrictions on the specific type of electronic devices.

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

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

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

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

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

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

[0049] The charging management module 140 is used to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive 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 may also power the electronic device through the power management module 141.

[0050] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and supplies power to 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 number, battery health status (leakage, impedance), etc. In some other embodiments, the power management module 141 can also be set in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 can also be set in the same device.

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

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

[0053] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.

[0054] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 170A, a receiver 170B, etc.), or displays an image or video through a display screen 194. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.

[0055] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.

[0056] In some embodiments, 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. The wireless communication technology may include 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, and / or IR technology, etc. GNSS may include the global positioning system (GPS), the global navigation satellite system (GLONASS), the Beidou navigation satellite system (BDS), the quasi-zenith satellite system (QZSS) and / or the satellite based augmentation system (SBAS).

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

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

[0059] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.

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

[0061] The internal memory 121 can be used to store computer executable program codes, and the executable program codes include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

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

[0063] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.

[0064] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. For touch operations acting on different areas of the display screen 194, motor 191 can also correspond to different vibration feedback effects. Different application scenarios (for example: time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.

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

[0066] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to 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 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, and the like. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The electronic device 100 interacts with the network through the SIM card to implement functions such as calls and data communications. In some embodiments, the electronic device 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100.

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

[0068] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 100. Figure 2 1 is a software structure diagram of the electronic device 100 of the embodiment of the present application. The layered architecture divides the software into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into an application layer, a system layer, and a physical layer from top to bottom.

[0069] The application layer can include a series of application packages. Figure 2 As shown, the application package may include a setting application, and may also include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications (not shown in the figure). The user can set related functions of the electronic device through the setting application, such as turning on or off the smart memory function.

[0070] The modules in the system layer can provide support for the implementation of functions in the application layer. For example, the smart memory function Figure 2As shown, the system layer may include a dump module, a block module, etc. The dump module may include a file dump interface, a dump file management module, an encryption and decryption module, a block I / O scheduling module, and an eswap space management module. Among them, the eswap space management module can be used to apply for and manage memory swap partition space, such as applying for reserved files and non-reserved files. The file dump interface can be used to convert the non-reserved files with discontinuous physical addresses applied for into loop devices (which is a special block device), and can also convert the reserved files applied for and the non-reserved files with continuous physical addresses into block devices. The dump file management module can be used to manage the loop devices and block devices obtained by dumping. The block I / O scheduling module can be used to schedule block devices to unify I / O management. The encryption and decryption module can be used to encrypt and decrypt data that needs to be stored or used.

[0071] Continue to see Figure 2 The reserved files applied by the eswap space management module can be files with continuous physical addresses, and the non-reserved files can include files with continuous physical addresses and files with discontinuous physical addresses. These files are converted into block devices and stored in the block module (also called the block layer) after passing through the file dump interface.

[0072] The physical layer may include a series of memories, such as UFS memories, which may be used to store the reserved files and non-reserved files applied for above.

[0073] In addition, the software structure of the electronic device 100 may also include an application framework layer (not shown in the figure), which provides an application programming interface (API) and a programming framework for the application programs of the application layer, and the application framework layer includes some predefined functions. In some embodiments, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, etc.

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

[0075] The system layer may also include Android runtime (not shown in the figure), which includes a core library and a virtual machine, and is responsible for scheduling and management of the Android system. The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the core library of Android. The application layer and the application framework layer run in the virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0076] The system layer may also include multiple functional modules, such as a surface manager, media libraries, a 3D graphics processing library (eg, OpenGL ES), a 2D graphics engine (eg, SGL), etc. (not shown in the figure).

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

[0078] It is understandable that the above software structure does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer modules than those shown in the figure.

[0079] Based on the above Figure 1 and Figure 2 Taking the electronic device with the structure shown as an example, the method for managing memory swap partitions provided by the embodiment of the present application is specifically described below in combination with the accompanying drawings and application scenarios.

[0080] Figure 3 1 is a flow chart of a method for managing memory swap partitions provided in an embodiment of the present application. Taking the method applied to an electronic device as an example, the method includes:

[0081] S101, when the electronic device is powered on for the first time, allocating reserved files and non-reserved files as a memory swap partition.

[0082] Among them, the first startup of the electronic device in the embodiment of the present application refers to the first startup of the electronic device after leaving the factory. At this time, the electronic device can apply for the allocation of reserved files and non-reserved files. It is assumed here that when the electronic device is powered on for the first time, the smart memory function of the electronic device is turned on, that is, when it is powered on, it can automatically apply for the allocation of reserved files and non-reserved files from the storage space of the electronic device. For example, the storage space of the electronic device can be divided into multiple storage disks (such as data disks, system disks, etc.), and the electronic device can apply for the allocation of reserved files and non-reserved files from the data disk.

[0083] In some embodiments, the size of the reserved files and non-reserved files applied for allocation can be preset. For example, it is possible to apply for allocation of xGB of reserved files and yGB of non-reserved files, for example, x is 0.5 and y is 1.5. In other embodiments, the size of the reserved files and non-reserved files applied for allocation can be determined according to the memory size of the electronic device. For example, when the memory of the electronic device is large, the size of the reserved files and non-reserved files allocated can be smaller; when the memory of the electronic device is small, the size of the reserved files and non-reserved files allocated can be larger. In some other embodiments, the electronic device can count the usage frequency and usage size of the memory swap partition during operation, and dynamically adjust the size of the reserved files and non-reserved files. For example, when the usage frequency of the memory swap partition is small, the size of the non-reserved files is reduced (i.e., a portion of the space is released) to avoid waste of storage space; and the user's normal use of the electronic device is not affected during the dynamic adjustment process, and the user side is not aware of it.

[0084] When applying for allocation of a reserved file, the electronic device can allocate it through the F2FS (flash friendly file system) interface. The allocated physical addresses are continuous, and the reserved file is not released when the smart memory function is subsequently turned off.

[0085] When applying for allocation of non-reserved files, the electronic device may give priority to allocating files with continuous physical addresses (hereinafter referred to as continuous files) through the F2FS interface. If F2FS fails to apply for files with continuous physical addresses, it will apply to the system for ordinary files as non-reserved files, where the physical addresses of ordinary files may not be continuous (hereinafter referred to as non-continuous files). It should be noted that when the smart memory function is subsequently turned off, the non-reserved files can be released (that is, the non-reserved files are deleted) and the allocated space is returned to the ROM.

[0086] It can be understood that in order to distinguish between reserved files and non-reserved files, the electronic device can assign an identifier to each file, and different identifiers correspond to different file types, for example, identifier 1 corresponds to a reserved file, and identifier -1 corresponds to a non-reserved file. It can also be understood that if the non-reserved file applied for is a non-continuous file, the number of non-continuous files can be multiple. In order to improve the success rate of applying for non-reserved files, these multiple non-continuous files can be multiple continuous files with small spaces, and the continuous files with small spaces can be directly converted to block devices later to reduce the performance loss of the conversion process. For example, apply for multiple continuous files with a space size of 2MB.

[0087] S102: Convert the allocated reserved files and non-reserved files into block devices for storage.

[0088] After applying for allocation of reserved files and non-reserved files, in order to unify the current I / O management, the electronic device needs to convert the reserved files and non-reserved files into block devices for use. It should be noted that the block device here is only a storage form of reserved files and non-reserved files, and the original reserved files and non-reserved files are still stored in the storage space.

[0089] For continuous files in reserved files and non-reserved files, the electronic device can directly convert these files into block devices. The specific conversion process is: obtain the file description structure struct file corresponding to the file, and convert it into a block device through the blkdev_get interface. The API involved is: filp_open / filp_close / bdgrab / blkdev_get.

[0090] For non-contiguous files in non-reserved files, electronic devices can convert these files into loop devices; wherein, loop devices are special block devices, which are virtual block devices formed by mapping normal files on the operating system. The specific conversion process is: first, obtain the corresponding file descriptor fd through the interface, and the API involved is: filp_open / vfs_truncate / vfs_fallocate / get_unused_fd_flags / fd_install / filp_close; then obtain the system-allocable device number devnr through the / dev / loop-control node, create the corresponding loop file / dev / block / loop_devnr, obtain its inode node, call the system interface blkdev_get_by_dev to convert it into a loop device, bind the above-obtained file descriptor fd through the LOOP_SET_FD operation in ioctl, and realize the loop device conversion, and the API involved is: filp_open / filp_close / blkdev_get_by_dev.

[0091] From the above description, it can be seen that after the reserved files and non-reserved files are converted to block devices, each file and the converted block device have a certain correspondence relationship, for example, the physical address of the reserved files and non-reserved files corresponds to the device number devnr of the block device.

[0092] In some embodiments, to facilitate the management of reserved files and non-reserved files, the electronic device can use virtual addresses for unified management, and the virtual address can use a bit map to uniformly allocate management space: assuming that each bit represents a 32KB space, the bit is marked as extent, and the total bit size is recorded as extent_total_bit. Each allocation starts from bit1 and searches for unused space recorded as bit_x. The actual virtual address used is vaddr = extent_total_bit-bit_x-1. From the above virtual address conversion relationship, it can be seen that when allocating space, the high bits of the virtual address are used first. To ensure efficiency, the reserved files are used first, and the high bits of the virtual address are mapped to the reserved files, and the remaining virtual addresses are mapped to the non-reserved files.

[0093] Exemplarily, the electronic device can allocate virtual addresses according to the overall size of the file. The reserved file and the non-reserved file have corresponding address separation thresholds. For example, the total size of the memory swap partition is 2GB, the reserved file is 512MB, and there is a non-reserved file. The mapping relationship between the virtual address and the physical address is shown in Figure 4 .like Figure 4 As shown, the virtual address vaddr is continuous, corresponding to a space size of 2GB; the address of the upper 512MB space corresponds to the physical address addr of the reserved file, and the reserved file also corresponds to the block device bdev1; the address of the lower 2GB-512MB space corresponds to the physical address addr of the non-reserved file, and the non-reserved file also corresponds to the block device bdev2.

[0094] It should be noted that the mapping relationship between virtual addresses and physical addresses in the embodiments of the present application is not limited to the correspondence between reserved files and high bits of virtual addresses and the correspondence between non-reserved files and low bits of virtual addresses, but may also be other mapping relationships as long as the virtual addresses and physical addresses can be mapped.

[0095] After the above process, the electronic device successfully allocates the reserved files and non-reserved files as the memory swap partition. If there is a subsequent application running that needs to use the space of the memory swap partition, the unused space in the memory swap partition can be searched to meet the operation requirements. In the process of searching, due to the above-mentioned mapping relationship between the virtual address and the physical address, the electronic device can search for the unused address space from the virtual address, and then determine the physical address corresponding to the unused address space according to the mapping relationship. The file space corresponding to the physical address is the actual usable space. In one implementation, in order to give priority to the use of reserved files, the electronic device gives priority to the unused address space in the high position of the virtual address, and then uses the unused address space in the low position of the virtual address.

[0096] As can be seen from the above description of S101, when the electronic device is turned on for the first time, the smart memory function is enabled by default. To improve the user experience, the electronic device may also provide an interface for turning on or off the smart memory function and display it to the user in the form of an interface. Figure 5 As shown, taking the electronic device being a mobile phone as an example, in the setting interface of the electronic device, there is a setting entrance for the smart memory function. After the user clicks the "smart memory" control, the electronic device can jump to the smart memory setting interface; when the current smart memory function is turned on, the user can turn off the smart memory function by clicking the switch control.

[0097] When the electronic device receives a closing operation input by the user, the electronic device may release the storage space corresponding to the non-reserved file, that is, delete the non-reserved file to return the storage space occupied by the non-reserved file to the ROM.

[0098] Optionally, in Figure 5 Based on the smart memory setting interface shown in Figure 6 As shown, the capacity of the reserved files and non-reserved files allocated can also be displayed. In addition, the interface can also have a capacity setting control (not shown) for the reserved files and non-reserved files, that is, the user can set the reserved files and non-reserved files of how much size to allocate.

[0099] In the above method for managing memory swap partitions, the electronic device applies for reserved files and non-reserved files as memory swap partitions, so that the non-reserved files can be released later to return the storage space, thereby reducing the waste of storage space.

[0100] against Figure 3 In the embodiment shown, the electronic device automatically applies for allocation of reserved files and non-reserved files when it is turned on. In other embodiments, the electronic device may not automatically apply for allocation of reserved files and non-reserved files when it is turned on (i.e., the smart memory function is not turned on when it is turned on), but applies for allocation of reserved files and non-reserved files when the user turns on the smart memory function. Figure 7 As shown, the process may include:

[0101] S201, receiving an operation of starting a smart memory function input by a user.

[0102] Among them, users can Figure 5 The interface shown is used to input the operation of turning on the smart memory function, that is, clicking the switch control; the smart memory function can also be turned on through voice commands. The embodiment of the present application does not impose specific restrictions on the method of inputting operations.

[0103] S202: In response to the above operation, the electronic device allocates reserved files and non-reserved files as memory swap partitions.

[0104] S203: Convert the allocated reserved files and non-reserved files into block devices for storage.

[0105] For the process of allocating reserved files and non-reserved files by the electronic device in S202 and the process of converting reserved files and non-reserved files into block devices in S203, refer to the description of S101-S102 above, which will not be repeated here.

[0106] In this scenario, users can also use the above Figure 5 In the interface shown, click the switch control to turn off the smart memory function. When the electronic device receives a shutdown operation input by the user, the electronic device can release the above-mentioned non-reserved files, that is, delete the non-reserved files to return the storage space occupied by the non-reserved files to the ROM.

[0107] In the above method for managing memory swap partitions, when the user turns on the smart memory function, the electronic device applies for reserved files and non-reserved files as memory swap partitions, so that the non-reserved files can be released later to return the storage space, thereby reducing the waste of storage space. In addition, the electronic device only performs the corresponding operation when the user turns on the smart memory function, which also meets the user's needs.

[0108] In the above S101 process, in some embodiments, the electronic device may first apply for a reserved file and then apply for a non-reserved file, because the electronic device has relatively little storage space when it is first powered on, and the success rate of applying for a reserved file is higher. Figure 8 As shown, the step of S101 may include:

[0109] S101a, determine whether there is a reserved file currently, if not, execute S101b, if yes, execute S101d.

[0110] The electronic device may search whether there is a reserved file currently according to the identifier of the reserved file. For example, when the identifier of the reserved file is 1, the electronic device may search whether there is a file with the identifier 1 in the current storage space.

[0111] S101b, allocating a reserved file.

[0112] Among them, the electronic device can allocate reserved files with continuous physical addresses through the F2FS interface.

[0113] S101c, determine whether the reserved file is allocated successfully, if so, execute S101d, if not, end the process.

[0114] S101d, check whether the reserved file is normal, if so, execute S101e, if not, end the process.

[0115] When verifying whether the reserved file is normal, you can verify its file name, file identifier, file size and other attributes. If all attributes are normal, execute the subsequent steps.

[0116] S101e, record the block device and the start and end physical addresses corresponding to the reserved file.

[0117] After the electronic device successfully allocates the reserved file, it will be converted into a block device, and this step will not be described in this embodiment.

[0118] S101f, determine whether there is currently a non-reserved file with a continuous physical address, if not, execute S101g, if yes, execute S101i.

[0119] Among them, the electronic device can also search whether there is a non-reserved file according to the identifier of the non-reserved file. For example, when the identifier of the non-reserved file is -1, the electronic device can search whether there is a file identified as -1 in the current storage space and determine whether the physical address of the file is continuous.

[0120] S101g, allocate non-reserved files with consecutive physical addresses.

[0121] The electronic device may also allocate non-reserved files with continuous physical addresses through the F2FS interface.

[0122] S101h, determine whether the non-reserved file with continuous physical address is allocated successfully, if yes, execute S101i, if not, execute S101n.

[0123] S101i, check whether the non-reserved files are normal, if yes, execute S101j, if not, execute S101m.

[0124] When verifying whether a non-reserved file is normal, you can verify its file name, file identifier, file size and other attributes. If all attributes are normal, execute the subsequent steps.

[0125] S101j, record the block devices and the starting and ending physical addresses corresponding to the non-reserved files with continuous physical addresses.

[0126] After the electronic device successfully allocates a non-reserved file with a continuous physical address, it converts it into a block device, and this step is not described in this embodiment.

[0127] S101k, bind block device to zram, and initialize memory swap partition successfully.

[0128] Among them, zram is a memory optimization technology of Linux, which demarcates an area and puts the compressed hard disk data into the area to achieve high-speed reading.

[0129] S101m, delete non-reserved files with consecutive physical addresses.

[0130] That is to say, if the non-reserved file with continuous physical address is not checked normally, it can be deleted, and then apply for the non-reserved file with discontinuous physical address later.

[0131] S101n, determine whether there is currently a non-reserved file with a discontinuous physical address, if not, execute S101p, if yes, execute S101r.

[0132] S101p, allocate non-reserved files with discontinuous physical addresses.

[0133] S101q, determine whether the non-reserved file with discontinuous physical address is allocated successfully, if so, execute S101r, if not, end the process.

[0134] S101r, check whether the non-reserved files are normal, if yes, execute S101s, if not, execute S101u.

[0135] S101s, converts non-reserved files with discontinuous physical addresses into loop devices.

[0136] S101t, records the loop device and the starting and ending physical addresses corresponding to the non-reserved file with discontinuous physical addresses, and returns to execute S101k.

[0137] S101u, delete the non-reserved files with discontinuous physical addresses and end the process.

[0138] The difference from the non-reserved file with continuous physical address is that the electronic device converts the non-reserved file with discontinuous physical address into a loop device. The conversion process is described in S102 above.

[0139] After the above process, the electronic device applies for reserved files and non-reserved files as memory swap partitions, so that the non-reserved files can be released later to return the storage space, thereby reducing the waste of storage space.

[0140] against Figure 4 The embodiment shown can also be combined with the above Figure 2 The software structure shown in the figure is implemented. Figure 2 The software structure shown describes the method for managing memory swap partitions provided in the embodiment of the present application, such as Fig. 9 As shown, it is a timing flow diagram of a method for managing memory swap partitions provided in an embodiment of the present application, which may specifically include:

[0141] S11, the setting application receives the operation of starting the smart memory function input by the user.

[0142] The operation of setting the application to receive user input to start the smart memory function can be performed through the above Figure 5 Input is done through the interface shown.

[0143] S12, setting the application to send an instruction to the eswap space management module to apply for a memory swap partition.

[0144] S13, the eswap space management module applies for allocation of reserved files and non-reserved files according to the received instructions.

[0145] S14, the eswap space management module sends the identifier of the reserved file and the identifier of the non-reserved file to the file dump interface.

[0146] S15, the file dump interface converts the non-reserved file with discontinuous physical addresses into a loop device and converts the reserved file with continuous physical addresses into a block device according to the identifier of the reserved file and the identifier of the non-reserved file.

[0147] Optionally, the instructions sent between the modules can be inter-process communication (IPC) instructions, or other communication instructions, which are not limited in the present application embodiment. The eswap space management module applies for the allocation of reserved files and non-reserved files, and the file dump interface converts the block device. Please refer to the description of the above embodiment, which will not be repeated here.

[0148] The above describes in detail an example of a method for managing memory swap partitions provided by an embodiment of the present application. It is understandable that, in order to implement the above functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to exceed the scope of the present application.

[0149] The embodiment of the present application can divide the functional modules of the electronic device according to the above method example. For example, each function can be divided into various functional modules, such as a detection unit, a processing unit, a display unit, etc., or two or more functions can be integrated into one module. The above integrated module can be implemented in the form of hardware or in the form of a software functional module. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0150] It should be noted that all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module and will not be repeated here.

[0151] The electronic device provided in this embodiment is used to execute the above-mentioned method for managing memory swap partitions, and thus can achieve the same effect as the above-mentioned implementation method.

[0152] In the case of an integrated unit, the electronic device may further include a processing module, a storage module and a communication module. The processing module may be used to control and manage the actions of the electronic device. The storage module may be used to support the electronic device to execute stored program codes and data, etc. The communication module may be used to support the electronic device to communicate with other devices.

[0153] Among them, the processing module can be a processor or a controller. It can implement or execute various exemplary logic boxes, modules and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module can be a memory. The communication module can specifically be a device that interacts with other electronic devices, such as a radio frequency circuit, a Bluetooth chip, a Wi-Fi chip, etc.

[0154] In one embodiment, when the processing module is a processor and the storage module is a memory, the electronic device involved in this embodiment may be a Figure 1 Device of the structure shown.

[0155] An embodiment of the present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the processor executes the method for managing memory swap partitions in any of the above embodiments.

[0156] An embodiment of the present application also provides a computer program product. When the computer program product is run on a computer, the computer is caused to execute the above-mentioned related steps to implement the method for managing memory swap partitions in the above-mentioned embodiment.

[0157] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory so that the chip executes the method for managing memory swap partitions in the above-mentioned method embodiments.

[0158] Among them, the electronic device, computer-readable storage medium, computer program product or chip provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above and will not be repeated here.

[0159] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0160] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0161] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

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

[0163] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium, including several instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.

[0164] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for managing memory swap partitions, It is characterized in that The method is performed by an electronic device, comprising: In the case where the electronic device receives the first operation, if the second file does not currently exist in the electronic device, a second file with a continuous physical address is allocated in the first storage space; When the second file is successfully allocated and verified to be normal, the block device and the start and end physical addresses corresponding to the second file are recorded; If the electronic device currently does not have a first file with a continuous physical address, allocating a first file with a continuous physical address in the first storage space; When the first file with the continuous physical address is successfully allocated and the first file is verified to be normal, the block device and the starting and ending physical addresses corresponding to the first file with the continuous physical address are recorded; In the case where the first file with continuous physical addresses is not allocated successfully, or the first file is checked to be abnormal, if the electronic device currently does not have a first file with discontinuous physical addresses, the first file with discontinuous physical addresses is allocated in the first storage space; When the first file with discontinuous physical addresses is successfully allocated and the first file is verified to be normal, the loop device and the starting and ending physical addresses corresponding to the first file with discontinuous physical addresses are recorded; wherein the first file includes a first preset number of bytes, the second file includes a second preset number of bytes, the storage space occupied by the first file in the first storage space and the storage space occupied by the second file in the first storage space are memory swap partitions, and the first operation is a power-on operation of the electronic device and / or an operation of starting a function of using the memory swap partition; When the electronic device receives a second operation, the first file is deleted from the first storage space, and the second file is not deleted from the first storage space, where the second operation is an operation of disabling a function of using the memory swap partition.

2. The method according to claim 1, It is characterized in that In the case where a first file with discontinuous physical addresses is allocated in the first storage space, the storage space corresponding to the first file includes a plurality of sub-storage spaces with continuous physical addresses, and each sub-storage space corresponds to a sub-file.

3. The method according to claim 1, It is characterized in that The method further comprises: The number of bytes included in the first file is adjusted according to the usage of the memory swap partition during the operation of the electronic device.

4. The method according to any one of claims 1 to 3, It is characterized in that The method further comprises: When using the memory swap partition, determining a first physical address corresponding to the unused storage space according to a virtual address corresponding to the unused storage space and a mapping relationship, wherein the mapping relationship includes a correspondence relationship between the virtual address and the physical address of the storage space corresponding to the first file, and a correspondence relationship between the virtual address and the physical address of the storage space corresponding to the second file; The data to be stored is stored in a file corresponding to the first physical address, where the file is the first file or the second file.

5. The method according to claim 4, It is characterized in that Before using the memory swap partition, the method further includes: A correspondence between the virtual address and the physical address of the storage space corresponding to the first file, and a correspondence between the virtual address and the physical address of the storage space corresponding to the second file are established.

6. The method according to claim 5, It is characterized in that The physical address of the storage space corresponding to the first file is mapped to the lower bits of the virtual address, and the physical address of the storage space corresponding to the second file is mapped to the higher bits of the virtual address.

7. The method according to any one of claims 1 to 3, It is characterized in that In the case where the electronic device receives a first operation, the method further includes: Determine whether the electronic device currently has the second file; if the second file already exists, check whether the second file is normal.

8. The method according to claim 7, It is characterized in that After recording the block device and the start and end physical addresses corresponding to the second file, the method further includes: It is determined whether the electronic device currently has a first file with a continuous physical address. If the first file with a continuous physical address already exists, it is checked whether the first file is normal.

9. The method according to any one of claims 1 to 3, It is characterized in that The first operation is the first power-on operation of the electronic device.

10. The method according to any one of claims 1 to 3, It is characterized in that The second file with continuous physical addresses and the first file with continuous physical addresses are files created through the F2FS interface.

11. The method according to any one of claims 1 to 3, It is characterized in that In the case where the first file with discontinuous physical addresses is successfully allocated and the first file is verified to be normal, the method further includes: The first file with discontinuous physical addresses is converted into a loop device.

12. An electronic device, It is characterized in that include: one or more processors; one or more memories; The memory stores one or more programs, and when the one or more programs are executed by the processor, the electronic device executes the method according to any one of claims 1 to 11.

13. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 11.