WO2021147838A1 - 一种闪存交换分区控制方法及移动设备 - Google Patents

一种闪存交换分区控制方法及移动设备 Download PDF

Info

Publication number
WO2021147838A1
WO2021147838A1 PCT/CN2021/072621 CN2021072621W WO2021147838A1 WO 2021147838 A1 WO2021147838 A1 WO 2021147838A1 CN 2021072621 W CN2021072621 W CN 2021072621W WO 2021147838 A1 WO2021147838 A1 WO 2021147838A1
Authority
WO
WIPO (PCT)
Prior art keywords
flash memory
initial
current
write
swap
Prior art date
Application number
PCT/CN2021/072621
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 WO2021147838A1 publication Critical patent/WO2021147838A1/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
    • G06F12/0223User address space allocation, e.g. contiguous or non contiguous base addressing
    • G06F12/023Free address space management
    • G06F12/0238Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory
    • G06F12/0246Memory management in non-volatile memory, e.g. resistive RAM or ferroelectric memory in block erasable memory, e.g. flash memory
    • 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
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/12Replacement control
    • G06F12/121Replacement control using replacement algorithms
    • G06F12/123Replacement control using replacement algorithms with age lists, e.g. queue, most recently used [MRU] list or least recently used [LRU] list

Definitions

  • This application relates to data storage technology, in particular to a flash memory swap partition control method, a mobile device, and a computer-readable storage medium.
  • the swap partition (Swap partition) technology can expand the memory space of electronic devices and is widely used.
  • the Swap partition technology will cause frequent reading of the storage device with the Swap partition, and accelerate the wear and tear of the storage device.
  • the actual service life of the flash memory with the swap partition will be greatly shortened. Therefore, for mobile devices with swap partitions set in flash memory, extending the actual service life of flash memory has become our demand.
  • this application proposes a method for controlling a flash memory swap partition, a mobile device, and a computer-readable storage medium.
  • a flash memory swap partition control method is provided.
  • the method can also respond to the user's immediate read and write request to the flash memory.
  • the time period from the increased master control write amount being 0 until the increased master control write amount is greater than or equal to the preset threshold is one stage.
  • the method further includes: updating the initial number of consumed P/E times to the current number of consumed P/E;
  • the master control write volume is updated to the current master control write volume;
  • the start swap write volume is updated to the current swap write volume;
  • the start life is updated to the current used Life; reset the timing duration to zero.
  • the initial number of consumed P/Es, initial master control write volume, initial swap write volume and initial lifespan update, and timing duration are achieved. Clear to zero, so that in the next preset period or the next stage of the prediction, the above formula can be used to correctly calculate the prediction.
  • the method further includes: timing with the current time as the timing starting point; when the first condition is satisfied or the second condition is satisfied , Detect the wear of the flash memory, obtain at least the first parameter and the second parameter of the flash memory; obtain a prediction result according to at least the first parameter and the second parameter; according to the prediction result, allow or prohibit subsequent Write to the swap partition in the flash memory.
  • the steps of the method are cyclically executed, and the prediction is continued in the next cycle or the next stage, and a new prediction result is obtained, and then according to the new prediction result, Allow or prohibit subsequent writing to the Swap partition in the flash memory, and if allowed, calculate the new writeable amount WS in the Swap partition in the flash memory in the subsequent unit time; thereby enabling the actual service life of the flash memory to be Extend, and approach or even reach the ideal service life.
  • the method allows instant read and write to the non-Swap partition area in the flash memory. That is to say, this method only allows or prohibits the writing of the swap partition in the flash memory, and does not restrict the instant read and write of the non-Swap partition in the flash memory. In this way, the user is also provided with instant read and write services to the flash memory, without affecting the normal use of the user.
  • a flash memory swap partition control method is provided.
  • the method is applied to a mobile device containing flash memory and includes: taking the current time as a timing starting point for timing; when the timing duration reaches a preset period, detecting the wear and tear of the flash memory, and acquiring at least the first parameter and the second parameter of the flash memory; Obtain a prediction result according to at least the first parameter and the second parameter; according to the prediction result, allow or prohibit subsequent writing to the swap partition in the flash memory;
  • the first parameter includes: capacity, P/E The number of times, the ideal service life, the initial number of consumed P/E, the initial master write amount, the initial life and the initial swap write amount;
  • the second parameter includes: the current number of consumed P/E, the current Master control write volume, current used service life, and current swap write volume; or, the first parameter includes: the initial number of consumed P/Es, the initial master control write volume, the initial life span, and the initial swap Write volume;
  • the second parameter includes: capacity, P/E times, ideal service life
  • the method can also respond to the user's immediate read and write request to the flash memory.
  • the method further includes: updating the initial number of consumed P/E times to the current number of consumed P/E;
  • the master control write volume is updated to the current master control write volume;
  • the start swap write volume is updated to the current swap write volume;
  • the start life is updated to the current used Life; reset the timing duration to zero.
  • the method further includes: timing with the current time as the timing starting point; and detecting the flash memory when the timing duration reaches the preset period At least obtain the first parameter and the current second parameter of the flash memory; obtain the prediction result according to at least the first parameter and the second parameter; according to the prediction result, allow or prohibit subsequent access to the flash memory Write to the Swap partition in the middle.
  • the method is made to execute the steps of the method in a loop after the end of the current cycle, continue to predict in the next cycle, and obtain a new prediction result, and then according to the new prediction result, allow or prohibit subsequent Write to the swap partition in the flash memory, and, if permitted, calculate the writable amount WS in the subsequent unit time of the swap partition in the new flash memory; thus, the actual service life of the flash memory can be prolonged and approach or even reach the ideal Service life.
  • the method allows instant reading and writing of areas in the flash memory that are not Swap partitions. That is to say, this method only allows or prohibits the writing of the swap partition in the flash memory, and does not restrict the instant read and write of the non-Swap partition in the flash memory. In this way, the user is also provided with instant read and write services to the flash memory, without affecting the normal use of the user.
  • a flash memory swap partition control method is provided.
  • the method is applied to a mobile device containing flash memory and includes: obtaining the current master control writing amount and the initial master control writing amount, and calculating the increased master control writing amount according to the following formula;
  • the increased master writing amount Current master control write volume-initial master control write volume; when the increased master control write volume is greater than or equal to the preset threshold, detect the wear of the flash memory, and at least acquire the first parameter and the second parameter of the flash memory;
  • the first parameter includes: capacity, P/E times , Ideal service life, initial number of consumed P/Es, initial master write amount, initial life and initial swap write amount;
  • the second parameter includes: current consumed P/E times, current master Control write volume, current used service life, and current swap write volume; or, the first parameter includes: the initial number of consumed P/Es, the initial master control write
  • the method can also respond to the user's immediate read and write request to the flash memory.
  • the time period from the increased master control write amount being 0 until the increased master control write amount is greater than or equal to the preset threshold is one stage.
  • the method further includes: updating the initial number of consumed P/E times to the current number of consumed P/E;
  • the master control write volume is updated to the current master control write volume;
  • the start swap write volume is updated to the current swap write volume;
  • the start life is updated to the current used life.
  • the method further includes: obtaining the current master write amount and the starting Master control write volume, calculate the increased master control write volume; when the increased master control write volume is greater than or equal to the preset threshold, detect the wear of the flash memory, and acquire at least the first parameter and the second parameter of the flash memory; at least according to The first parameter and the second parameter obtain a prediction result; according to the prediction result, subsequent writing to the swap partition in the flash memory is allowed or prohibited.
  • the method allows instantaneous reading and writing of non-Swap partitions in the flash memory. That is to say, this method only allows or prohibits the writing of the swap partition in the flash memory, and does not restrict the instant read and write of the non-Swap partition in the flash memory. In this way, the user is also provided with instant read and write services to the flash memory, without affecting the normal use of the user.
  • a mobile device which at least includes: a memory, one or more processors, and one or more computer programs; wherein one or more computer programs are stored in the memory; one or more processors When executing one or more computer programs, the mobile device is caused to implement any one of the first aspect to the third aspect and the flash memory swap partition control method in any one of the first aspect to the third aspect.
  • any implementation manner and corresponding technical effect of the fourth aspect please refer to the implementation manner and corresponding technical effect of any one of the first aspect to the third aspect and any one of the first aspect to the third aspect.
  • the implementation methods and corresponding technical effects will not be repeated here.
  • a computer-readable storage medium including instructions, which when the instructions run on the mobile device of the fourth aspect, cause the mobile device to execute any one of the first aspect to the third aspect and the first aspect To the flash memory swap partition control method in any implementation manner in the third aspect.
  • any implementation manner and corresponding technical effect of the fifth aspect please refer to the implementation manner and corresponding technical effect of any one of the first aspect to the third aspect and any one of the first aspect to the third aspect.
  • the implementation methods and corresponding technical effects will not be repeated here.
  • FIG. 1 is a schematic structural diagram of a mobile device provided by an embodiment of this application.
  • FIG. 2 is a schematic diagram of the hardware structure of data reading and writing between the SoC and the flash memory provided by an embodiment of the application.
  • FIG. 3 is a schematic structural diagram of a flash memory provided by an embodiment of the application.
  • FIG. 4 is a schematic diagram of the software operation of data reading and writing between the SoC and the flash memory provided by an embodiment of the application.
  • FIG. 5 is a schematic flowchart of a method for controlling a flash memory swap partition according to Embodiment 1 of this application.
  • FIG. 6 is a schematic flowchart of a flash memory swap partition control method according to Embodiment 2 of the application.
  • FIG. 7 is a schematic flowchart of a flash memory swap partition control method provided in Embodiment 3 of this application.
  • FIG. 8 is a block diagram of the hardware structure of a mobile device provided by an embodiment of the application.
  • FIG. 9 is a schematic diagram of the time relationship of the process execution when the timing duration reaches the preset period and/or the increased master write amount is greater than or equal to the preset threshold in the flash memory swap partition control method provided by an embodiment of the application.
  • Swap partition technology is when the memory resources of the electronic device are insufficient, the operating system stores some infrequently used data (also called cold data) in the memory in the swap partition.
  • the operating system can use the least recently used LRU (Least Recently Used) method to maintain the memory pages being used in an LRU linked list.
  • LRU Least Recently Used
  • PFRA Page Frame Real Address
  • Swap partition can be set in memory, hard disk or other storage devices.
  • the Swap partition set in the memory is also called ZRAM.
  • ZRAM Zero-power RAM
  • Swap partitions are generally set in flash memory (flash memory). Frequent data swap-in/swap-out will increase the amount of writes and writes within a unit time of the flash memory, which can easily cause excessive wear of the flash memory and reduce the service life of the flash memory.
  • flash memory with an ideal service life of 5 years, after setting the swap partition in the flash memory, the actual service life of the flash memory may be only 3 years. Therefore, for mobile devices in which the swap partition is set in the flash memory, it is necessary to extend the actual service life of the flash memory, and make the actual service life of the flash memory as close as possible or even reach the ideal service life.
  • FIG. 1 shows a schematic diagram of the structure of a mobile device 100.
  • the mobile 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, and an 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, buttons 190, motor 191, indicator 192, camera 193, display screen 194, and 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 sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, and ambient light Sensor 180L, bone conduction sensor 180M, etc.
  • the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the mobile device 100.
  • the mobile device 100 may include more or fewer components than shown, or combine certain components, or split certain components, or arrange different components.
  • the illustrated components can be implemented in hardware, software, or a combination of software and hardware.
  • the processor 110 may include one or more processing units.
  • the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), and an image signal processor. (image signal processor, ISP), controller, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural-network processing unit (NPU), etc.
  • AP application processor
  • modem processor modem processor
  • GPU graphics processing unit
  • image signal processor image signal processor
  • ISP image signal processor
  • controller video codec
  • digital signal processor digital signal processor
  • DSP digital signal processor
  • NPU neural-network processing unit
  • the different processing units may be independent devices or integrated in one or more processors.
  • the controller can generate operation control signals according to the instruction operation code and timing signals to complete the control of fetching instructions and executing instructions.
  • a memory may also be provided in the processor 110 to store instructions and data.
  • the memory in the processor 110 is a cache memory.
  • the memory can store instructions or data that have just been used or recycled by the processor 110. If the processor 110 needs to use the instruction or data again, it can be directly called from the memory. Repeated accesses are avoided, the waiting time of the processor 110 is reduced, and the efficiency of the system is improved.
  • the 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 transceiver receiver/transmitter, UART) interface, mobile industry processor interface (MIPI), general-purpose input/output (GPIO) interface, subscriber identity module (SIM) interface, and / Or 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 transceiver receiver/transmitter
  • MIPI mobile industry processor interface
  • GPIO general-purpose input/output
  • SIM subscriber identity module
  • USB Universal Serial Bus
  • the USB interface 130 is an interface that complies with the USB standard specification, and specifically may be a Mini USB interface, a Micro USB interface, a USB Type C interface, and so on. It can be understood that the interface connection relationship between the modules illustrated in the embodiment of the present invention is merely illustrative, and does not constitute a structural limitation of the mobile device 100. In some other embodiments of the present application, the mobile device 100 may also adopt different interface connection modes in the foregoing embodiments, or a combination of multiple interface connection modes.
  • the charging management module 140 is used to receive charging input from the charger.
  • the power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110.
  • the wireless communication function of the mobile device 100 can be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor.
  • the antenna 1 and the antenna 2 are used to transmit and receive electromagnetic wave signals.
  • Each antenna in the mobile device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve antenna utilization.
  • Antenna 1 can be multiplexed as a diversity antenna of a wireless local area network.
  • the antenna can be used in combination with a tuning switch.
  • the mobile communication module 150 may provide a wireless communication solution including 2G/3G/4G/5G and the like applied to the mobile device 100.
  • the mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), and the like.
  • the mobile communication module 150 can receive electromagnetic waves by the antenna 1, and perform processing such as filtering, amplifying and transmitting the received electromagnetic waves to the modem processor for demodulation.
  • the mobile communication module 150 can also amplify the signal modulated by the modem processor, and convert it into electromagnetic waves for radiation via the antenna 1.
  • at least part of the functional modules of the mobile communication module 150 may be provided in the processor 110.
  • 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 provided in the same device.
  • the modem processor may include a modulator and a demodulator.
  • the modulator is used to modulate the low frequency baseband signal to be sent into a medium and 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.
  • the application processor outputs a sound signal through an audio device (not limited to the speaker 170A, the receiver 170B, etc.), or displays an image or video through the display screen 194.
  • the modem processor may be an independent device.
  • the modem processor may be independent of the processor 110 and be provided in the same device as the mobile communication module 150 or other functional modules.
  • the wireless communication module 160 can provide applications on the mobile device 100 including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), and global navigation satellites.
  • WLAN wireless local area networks
  • BT wireless fidelity
  • GNSS global navigation satellite system
  • FM frequency modulation
  • NFC near field communication technology
  • 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 may also receive a signal to be sent from the processor 110, perform frequency modulation, amplify, and convert it into electromagnetic waves to radiate through the antenna 2.
  • the antenna 1 of the mobile device 100 is coupled with the mobile communication module 150, and the antenna 2 is coupled with the wireless communication module 160, so that the mobile 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), 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.
  • the GNSS may include global positioning system (GPS), global navigation satellite system (GLONASS), 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
  • BDS Beidou navigation satellite system
  • QZSS quasi-zenith satellite system
  • SBAS satellite-based augmentation systems
  • the mobile device 100 implements a display function through a GPU, a display screen 194, and an application processor.
  • the GPU is a microprocessor for image processing, connected to the display 194 and the application processor.
  • the GPU is used to perform mathematical and geometric calculations and is used for graphics rendering.
  • the 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, etc.
  • the display screen 194 includes a display panel.
  • the display panel can use liquid crystal display (LCD), organic light-emitting diode (OLED), active matrix organic light-emitting diode or active-matrix organic light-emitting diode (active-matrix organic light-emitting diode).
  • LCD liquid crystal display
  • OLED organic light-emitting diode
  • active-matrix organic light-emitting diode active-matrix organic light-emitting diode
  • AMOLED flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, quantum dot light-emitting diode (QLED), etc.
  • the mobile device 100 may include one or N display screens 194, where N is a positive integer greater than one.
  • the mobile device 100 can implement a shooting function through an ISP, a camera 193, a video codec, a GPU, a display screen 194, and an application processor.
  • the ISP is used to process the data fed back from the camera 193.
  • the camera 193 is used to capture still images or videos.
  • the object generates an optical image through the lens and is projected to the photosensitive element.
  • 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 mobile 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 mobile device 100 may support one or more video codecs. In this way, the mobile device 100 can play or record videos in multiple encoding formats, such as: moving picture experts group (MPEG) 1, MPEG2, MPEG3, MPEG4, and so on.
  • MPEG moving picture experts group
  • MPEG2 MPEG2, MPEG3, MPEG4, and so on.
  • NPU is a neural-network (NN) computing processor.
  • NN neural-network
  • the external memory interface 120 may be used to connect an external memory card, such as a Micro SD card, so as to expand the storage capacity of the mobile device 100.
  • the external memory card communicates with the processor 110 through the external memory interface 120 to realize the data storage function. For example, save music, video and other files in an external memory card.
  • the internal memory 121 may be used to store computer executable program code, where the executable program code includes instructions.
  • the internal memory 121 may include a storage program area and a storage data area.
  • the storage program area can store an operating system, at least one application program (such as a sound playback function, an image playback function, etc.) required by at least one function.
  • the data storage area can store data (such as audio data, phone book, etc.) created during the use of the mobile device 100.
  • 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, a flash memory device, a universal flash memory storage (UFS), and the like.
  • the processor 110 executes various functional applications and data processing of the mobile device 100 by running instructions stored in the internal memory 121 and/or instructions stored in a memory provided in the processor.
  • the mobile 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. For example, music playback, recording, etc.
  • the pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal.
  • the pressure sensor 180A may be provided on the display screen 194.
  • the capacitive pressure sensor may include at least two parallel plates with conductive materials.
  • the mobile device 100 determines the strength of the pressure according to the change in capacitance.
  • the mobile device 100 detects the intensity of the touch operation according to the pressure sensor 180A.
  • the mobile device 100 may also calculate the touched position based on the detection signal of the pressure sensor 180A.
  • touch operations that act on the same touch position but have different touch operation strengths may correspond to different operation instructions. For example: when a touch operation whose intensity of the touch operation is less than the first pressure threshold is applied to the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.
  • the gyro sensor 180B may be used to determine the movement posture of the mobile device 100.
  • the air pressure sensor 180C is used to measure air pressure.
  • the mobile 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 acceleration sensor 180E can detect the magnitude of the acceleration of the mobile device 100 in various directions (generally three axes).
  • Distance sensor 180F used to measure distance.
  • the mobile device 100 can measure the distance by infrared or laser. In some embodiments, when shooting a scene, the mobile device 100 may use the distance sensor 180F to measure the distance to achieve fast focusing.
  • the proximity light sensor 180G may include, for example, a light emitting diode (LED) and a light detector such as a photodiode.
  • the ambient light sensor 180L is used to sense the brightness of the ambient light.
  • the fingerprint sensor 180H is used to collect fingerprints.
  • the mobile device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photographs, fingerprint answering calls, and so on.
  • the temperature sensor 180J is used to detect temperature.
  • Touch sensor 180K also called “touch device”.
  • the touch sensor 180K may be disposed on the display screen 194, and the touch screen is composed of the touch sensor 180K and the display screen 194, which is also called a “touch screen”.
  • the touch sensor 180K is used to detect touch operations acting on or near it.
  • the touch sensor can pass the detected touch operation to the application processor to determine the type of touch event.
  • the 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 mobile device 100, which is different from the position of the display screen 194.
  • the bone conduction sensor 180M can acquire vibration signals.
  • the button 190 includes a power-on button, a volume button, and so on.
  • the button 190 may be a mechanical button. It can also be a touch button.
  • the mobile device 100 may receive key input, and generate key signal input related to user settings and function control of the mobile device 100.
  • the motor 191 can generate vibration prompts.
  • the indicator 192 may be an indicator light, which may be used to indicate the charging status, power change, or to indicate messages, missed calls, notifications, and so on.
  • the SIM card interface 195 is used to connect to the SIM card.
  • the SIM card can be inserted into the SIM card interface 195 or pulled out from the SIM card interface 195 to achieve contact and separation with the mobile device 100.
  • the mobile device 100 may support 1 or N SIM card interfaces, and N is a positive integer greater than 1.
  • the SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, etc.
  • the same SIM card interface 195 can insert multiple cards 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 may also be compatible with external memory cards.
  • the mobile device 100 interacts with the network through the SIM card to implement functions such as call and data communication.
  • the mobile device 100 adopts an eSIM, that is, an embedded SIM card.
  • the eSIM card can be embedded in the mobile device 100 and cannot be separated from the mobile device 100.
  • the software system of the mobile device 100 may adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture.
  • the flash memory swap partition control method provided by the embodiments of the present application can monitor and control the actual write volume in the flash memory unit time and the actual write volume in the swap partition unit time in the flash memory, prolong the actual service life of the flash memory, and make mobile The actual service life of the flash memory of the device is approaching or even reaching the ideal service life.
  • FIG. 2 is a schematic diagram of the hardware structure of data reading and writing between the SoC and the flash memory provided by an embodiment of the present application.
  • the SoC (System on Chip) 200 includes a central processing unit (CPU) (Central Processing Unit) 210, a graphics processing unit (GPU) (Graphics Processing Unit) 220, and a flash memory host controller (hereinafter referred to as the main controller). Control) 230, modem 240 and RAM controller 250.
  • the flash memory 300 is connected to the main control 230.
  • the CPU 210 reads and writes data through the bus, the main control 230, and the flash memory 300.
  • FIG. 3 is a schematic structural diagram of a flash memory provided by an embodiment of the application. As shown in FIG.
  • the flash memory 300 includes a flash memory device controller 310 and a flash memory storage medium 350.
  • the flash memory device controller 310 further includes an erasure management module 320, a read-write management module 330, and a garbage collection management module 340, which are used to perform erasing management, read-write management, and garbage collection management functions, respectively.
  • the flash memory 300 receives the data write command from the master control, it receives the write command from the master 230 through the flash memory device controller 310, and then erases and then writes.
  • the flash memory 300 receives the data read command from the main control 230, it receives the read command from the main control 230 through the flash memory device controller 310 and reads it directly.
  • the kernel space is provided with a memory management module 400 and a wear detection module 500, which are used to perform memory management and wear detection functions, respectively.
  • the memory management module 400 includes a cold data identification and exchange module 410.
  • the memory management module may also include a ZRAM management module 420. If the ZRAM 610 is provided in the memory RAM 600, the memory management module 400 includes the ZRAM management module 420 accordingly. If the ZRAM 610 is not set in the memory RAM 600, correspondingly, the memory management module 400 does not include the ZRAM management module 420.
  • the cold data identification and exchange module 410 identifies the cold data in the memory RAM600, and stores the identified cold data in the swap of the flash memory 700 Partition 710.
  • the cold data identification and exchange module 410 can identify the cold data in the memory RAM600, and the identified cold data is calculated according to the degree of cold data.
  • the colder data is stored in the Swap partition 710 of the flash memory 700, and the relatively not so cold data in the above cold data is compressed and stored in the ZRAM610; the cold data identification and exchange module 410 can also identify the cold data in the RAM 600 , And store the identified cold data in ZRAM610 after being compressed, and then store the colder data in the cold data of ZRAM610 in compressed or decompressed form in the swap partition of flash memory 700 according to the degree of cold data. 710 in.
  • the wear detection module 500 is used to perform wear detection on the flash memory 700 and obtain relevant parameters of the flash memory 700.
  • the relevant parameters include, but are not limited to, the capacity of flash memory, the number of P/E (Program/Erase), the number of currently consumed P/E, the number of initial consumed P/E, the current master write volume, The initial master control write volume, ideal service life, current used service life, initial life, current swap write volume and initial swap write volume.
  • the initial master write amount, initial life span, and initial swap write amount obtained for the first time are all 0.
  • the initial number of consumed P/Es obtained for the first time is the number of consumed P/Es of the flash memory.
  • the capacity of the flash memory and the number of P/Es that is, the number of erasing and writing of the flash memory, are provided by the flash memory manufacturer.
  • the Swap write volume is the write volume of the Swap partition in the flash memory.
  • the non-Swap write volume is the write volume of the non-Swap partition in the flash memory.
  • the command to write data to the swap partition or non-Swap partition of the flash memory includes an address, by which you can distinguish whether to write to the swap partition or the non-Swap partition. Therefore, the current Swap write volume and the initial Swap write volume can be obtained.
  • the current number of consumed P/E can be obtained through specific command query.
  • the current service life can be obtained by timing.
  • the ideal service life is set by the manufacturer of the mobile device, generally set to more than 5 years; sometimes it can be set to 3-5 years.
  • TBW Tera Byte Written
  • DWPD Device Writes Per Day
  • the number of P/E times per unit is the number of erasing and writing of the unit (BLOCK) included in the flash memory, which is also equal to the number of erasing and writing of the flash memory. Flash memory can only be written after being erased.
  • the Write Amplification Factor (WAF) in Formula 2 usually changes dynamically. For continuous workloads, WAF is usually in the range of one digit, and the dynamic range is small. For random workloads, WAF may reach or even exceed 100, with a large dynamic range. Because WAF changes dynamically, it will cause TBW to change, which leads to DWPD.
  • WAF and DWPD may change at any time.
  • the actual service life of the flash memory can be as close as possible or even reach the ideal service life.
  • the calculation is complicated and difficult to achieve.
  • controlling the daily write volume of the flash memory may make it impossible to write when the user needs to write to the flash memory, resulting in a bad user experience.
  • the embodiment of the present application predicts the acceptable write amount W1 in the subsequent unit time of the master control and the subsequent unit time of the non-Swap partition in the flash memory based on the data of the previous preset cycle or the previous stage of the master write and swap write respectively. Based on the predicted write volume W2, set the writeable volume in the subsequent unit time of the Swap partition based on the predicted result of the two, and at the same time improve the accuracy of WAF calculation during the above prediction process, so that the actual life of the flash memory is as close as possible Even reach the ideal service life. Moreover, the embodiment of the present application can also write to the flash memory when the user needs to write to the flash memory, without limitation. Wherein, the time period from the increased master control write amount being 0 until the increased master control write amount is greater than or equal to the preset threshold is one stage.
  • FIG. 5 shows a flow chart of a flash memory swap partition control method provided in Embodiment 1 of the present application.
  • the manufacturer of the mobile device presets the period T and the preset threshold N.
  • the period T can be set to any length of time such as 50 seconds, 30 minutes, 10 hours, 7 days, 3 months, 1 year, and so on.
  • the unit of the period T may be seconds, minutes, hours, days, months, years, and so on.
  • the purpose of setting the preset threshold value N is to determine whether the increase value of the master control write amount reaches the preset threshold value N.
  • the period T and the preset threshold N can be set by the manufacturer of the mobile device as needed before starting the method. After the method starts, first judge whether it is the first run.
  • the relevant parameters of the flash memory include but are not limited to capacity, P/E times, current consumption of P/E times, initial consumption of P/E times, current master write volume, initial master write volume, ideal use Life, current used life, initial life, current swap write volume and initial swap write volume.
  • the above-mentioned related parameters include the first parameter and the current second parameter of the flash memory in the last preset period or stage.
  • the first parameter includes: capacity, P/E times, ideal service life, initial consumed P/E times, initial master control write volume, initial life span, and initial swap write volume;
  • the second parameter includes : Current consumed P/E times, current master control write volume, current used life span, and current swap write volume.
  • the first parameter includes: the initial number of consumed P/Es, the initial master control write amount, the initial life span, and the initial swap write amount;
  • the second parameter includes: capacity, P/E times , Ideal service life, current consumed P/E times, current master write volume, current used service life and current swap write volume.
  • the first parameter includes: the initial number of consumed P/Es, the initial master write amount, the initial life span, and the initial swap write amount
  • the second parameter includes: the current consumed P/E The number of times, the current master control write volume, the current service life, and the current swap write volume
  • the method further includes: obtaining a third parameter
  • the third parameter includes: capacity, P/E times, and ideal service life. Then, based on the acquired first parameter and second parameter, or based on the acquired first parameter, second parameter, and third parameter, calculate the increased master write volume, the write amplification factor WAF, and the remaining available master control Write volume.
  • Increased master control write volume current master control write volume-initial master control write volume
  • WAF capacity * (currently consumed P/E times-initial consumed P /E times)/Increase master control write volume
  • master control remaining writable quantity capacity*(P/E times-current consumed P/E times)/WAF.
  • the number of P/E consumed in the previous preset period or the previous stage and the increased master write amount are used to calculate the WAF, and the calculated WAF is predicted as the next preset period or the next Stage of WAF.
  • the stages correspond to 0 to t1, t1 to t2.
  • the moment when the increased main control write amount is greater than or equal to the preset threshold N at this time corresponds to the end of the previous stage.
  • the data of the previous preset period can be used to predict the WAF of the next preset period or the next stage, or the data of the previous stage can be used to predict the WAF of the next preset period or the next stage, so that the The prediction of the WAF in the next preset period or the next stage is more accurate.
  • the specific use of the data of the last preset period or the last stage is determined based on whether the timing duration reaches T or the increased master write amount is greater than or equal to the preset threshold N first.
  • the above-mentioned more accurate WAF is used to calculate the remaining writable amount of the master control, so that the calculated remaining amount of the master control can be more accurate.
  • writing to the swap partition in the flash memory is prohibited or allowed. Even if allowed, it controls the amount of writes that can be written within the subsequent unit time of the Swap partition.
  • this method does not limit the writing of non-Swap partitions in the flash memory, users can write to the flash memory immediately when they need to write to the flash memory.
  • the embodiment of the present application controls the writing amount of the swap partition in the flash memory, which prolongs the actual service life of the flash memory.
  • the embodiments of the present application also allow users to write to non-Swap partitions in the flash memory instantly, without affecting the normal use of users.
  • update some of the parameters specifically: update the initial number of consumed P/E to the current number of consumed P/E; update the initial master write amount to the current master write amount;
  • the initial swap write volume is updated to the current swap write volume; the starting life is updated to the current used life; the timing duration is cleared.
  • the cycle is executed to the beginning, and it is judged again whether it is the first run; if it is not the first run, the current time is used as the new timing starting point, and the timing is restarted from the new timing starting point; to judge whether the timing duration reaches T, it is judged from the Whether the timing duration from the new timing starting point is greater than or equal to T starting from the new timing starting point.
  • T When the timing duration reaches T, continue execution according to the above procedure.
  • the timing duration does not reach T, continue execution according to the following procedure.
  • the timing duration does not reach T, then obtain the current master control write volume and the initial master control write volume; and calculate the increased master control write volume.
  • Increased master control write volume current master control write volume-initial master control write volume. Then, it is determined whether the increased main control write amount is greater than or equal to the preset threshold N. If the increased master control write amount is less than the preset threshold N, continue to determine whether the timing duration reaches T. If the increased main control write amount is greater than or equal to the preset threshold N, the wear of the flash memory is detected and related parameters are obtained.
  • Related parameters include, but are not limited to, the capacity of the flash memory, the number of P/Es, the current number of consumed P/Es, the initial number of consumed P/Es, the current master write volume, the initial master write volume, and ideal use Life, current used life, initial life, current swap write volume and initial swap write volume. Then, based on the obtained relevant parameters, according to the same process and formula as above, predict the acceptable write volume W1 in the subsequent unit time of the master control and the write volume W2 in the subsequent unit time of the non-Swap partition in the flash memory, according to W1 and W2 As a result of comparing the size of the Swap partition, set the writable amount WS in the subsequent unit time of the Swap partition.
  • the cycle is executed to the beginning, and it is judged again whether it is the first run; if it is not the first run, the current time is used as the new timing starting point, and the timing is restarted from the new timing starting point; to judge whether the timing duration reaches T, it is judged from the Whether the timing duration from the new timing starting point is greater than or equal to T starting from the new timing starting point. According to the judgment result, the corresponding process of this method is cyclically executed.
  • the timing is started with time 0 as the timing starting point.
  • the timing duration is t1 (t1 ⁇ T)
  • the increased master write amount is equal to the preset threshold N.
  • predict W1 and W2 according to the above procedure of this method, and set WS according to the comparison result of W1 and W2.
  • some parameters are updated.
  • set the time t1 as the new timing starting point and recalculate the new timing duration.
  • the increased master write amount is equal to the preset threshold N .
  • 0 to t1 correspond to the first stage; after taking t1 as the timing starting point, set t1 as 0, then 0 to t2-t1 corresponds to the second stage; taking t2 as the timing starting point, set t2 time As 0, then 0 to T corresponds to the first cycle at this time; after taking t2+T as the timing starting point, the time t2+T is taken as 0, then t2+T to t2+2T corresponds to the second cycle at this time.
  • the time t1 is taken as the new timing starting point, and then the event that the increased master write amount is greater than or equal to N occurs first, thereby generating the second stage.
  • the time t2 is taken as the new timing starting point, after which a new timing duration reaches T, and the first cycle is generated.
  • the time t2+T is taken as the new timing starting point, and then a new timing duration reaching T occurs first, thereby generating the second cycle.
  • the foregoing content and the content shown in FIG. 9a are only illustrative descriptions, and do not limit the scope of the embodiments of the present application.
  • the unit duration of the next stage in the first embodiment of the application is the same as the unit duration of the previous stage. For example, if the unit duration of the previous stage is 1 day, the unit duration of the next stage is also 1 day.
  • the above unit duration can be several minutes, several hours, several days, several months, several years, etc.
  • the specific value and unit of the aforementioned unit duration can be preset by the manufacturer of the mobile device as needed. This method can also provide a default value for the aforementioned unit duration, such as 1 day.
  • the manufacturer of the mobile device can choose to set other values as needed.
  • the manufacturer of the mobile device can also modify the above-mentioned default values. If the units of the ideal service life, the current service life, and the initial service life mentioned above are inconsistent with the units of the unit duration mentioned above, a conversion between units is required.
  • the following method can be used to determine whether it is running for the first time: record the accumulated running time. If it is detected that the accumulated running time is 0, it means that this is the first time; otherwise, it means that it is not this time. First run. Or, pre-record a state value indicating the first run. The state value is a specific value, such as 0, during the first run; the current state value is detected during the run, and if the current state value is the above specific value 0, it means this time It is the first run; otherwise, it means that this is not the first run.
  • the first embodiment of the present application predicts the subsequent write amplification factor WAF of the master control based on the data of the previous preset cycle or the previous stage written by the master control and Swap, which improves the calculation accuracy of the WAF; and according to the above prediction
  • the write amplification factor WAF is used to predict the acceptable write amount W1 in the subsequent unit time of the master control, thereby improving the prediction accuracy of the acceptable write amount W1 in the subsequent unit time of the master control.
  • the write volume W2 in the subsequent unit time of the non-Swap partition in the flash memory is predicted.
  • Fig. 6 shows a flow chart of a flash memory swap partition control method provided in the second embodiment of the present application.
  • the second embodiment of the present application it is no longer considered whether the increased master write amount is greater than or equal to the preset threshold N, and only whether the timing duration reaches T is considered.
  • the manufacturer of the mobile device presets the period T, and no longer presets the threshold N.
  • the method after the method is started, it is first judged whether it is the first run.
  • the wear of the flash memory is detected, and the acquisition includes but not limited to the capacity of the flash memory, the number of P/Es, the current number of consumed P/Es, the number of initial consumed P/Es, and the current master write volume ,
  • the above-mentioned related parameters include the first parameter of the flash memory in the last preset period and the current second parameter.
  • the first parameter includes: capacity, P/E times, ideal service life, initial consumed P/E times, initial master control write volume, initial life span, and initial swap write volume;
  • the second parameter includes : Current consumed P/E times, current master control write volume, current used life span, and current swap write volume.
  • the first parameter includes: the initial number of consumed P/Es, the initial master control write amount, the initial life span, and the initial swap write amount;
  • the second parameter includes: capacity, P/E times , Ideal service life, current consumed P/E times, current master write volume, current used service life and current swap write volume.
  • the first parameter includes: the initial number of consumed P/Es, the initial master write amount, the initial life span, and the initial swap write amount
  • the second parameter includes: the current consumed P/E The number of times, the current master control write volume, the current service life, and the current swap write volume
  • the method further includes: obtaining a third parameter
  • the third parameter includes: capacity, P/E times, and ideal service life. Then, based on the acquired first parameter and second parameter, or based on the acquired first parameter, second parameter, and third parameter, calculate the increased master write volume, the write amplification factor WAF, and the remaining available master control Write volume.
  • Increased master control write volume current master control write volume-initial master control write volume
  • WAF capacity * (currently consumed P/E times-initial consumed P /E times)/Increase master control write volume
  • master control remaining writable quantity capacity*(P/E times-current consumed P/E times)/WAF.
  • the above-mentioned more accurate WAF is used to calculate the remaining writable amount of the master control, so that the calculated remaining amount of the master control can be more accurate.
  • the embodiment of the present application also allows users to write to non-Swap partitions in the flash memory instantly, without affecting the normal use of users.
  • update some of the parameters specifically: update the initial number of consumed P/E to the current number of consumed P/E; update the initial master write amount to the current master write amount;
  • the initial swap write volume is updated to the current swap write volume; the starting life is updated to the current used life; the timing duration is cleared.
  • the cycle is executed to the beginning, and it is judged again whether it is the first run; if it is not the first run, the current time is used as the new timing starting point, and the timing is restarted from the new timing starting point; to judge whether the timing duration reaches T, it is judged from the Whether the timing duration from the new timing starting point is greater than or equal to T starting from the new timing starting point. According to the judgment result, the corresponding process of this method is cyclically executed.
  • timing duration does not reach T, return to continue to determine whether the timing duration reaches T. According to the judgment result, the corresponding process of this method is cyclically executed.
  • FIG. 9b is taken as an example for further explanation.
  • Start timing with 0 time as the starting point of timing.
  • T predict W1 and W2 according to the above-mentioned procedure of this method.
  • W1 and W2 according to the above-mentioned procedure of this method.
  • W1 and W2 According to the comparison result of W1 and W2, WS is set. Afterwards, some parameters are updated. Then set the time T as the new timing starting point, and recalculate the new timing duration. From the new timing starting point to time 2T, that is, when the new timing duration from time T is T, predict W1 and W2 according to the above procedure of the method, and set WS according to the comparison result of W1 and W2. Afterwards, some parameters are updated. Then set the 2T time as the new timing starting point, and recalculate the new timing duration.
  • 0 to T corresponds to the first cycle; after taking T as the timing starting point, the time T is taken as 0, then 0 to T under the new timing system corresponds to the second cycle, that is, time T to time 2T correspond to The second cycle: After taking T as the timing starting point, and taking time T as 0, then 0 to T under the new timing system corresponds to the third cycle, that is, time 2T to time 3T correspond to the third cycle.
  • the foregoing content and the content shown in FIG. 9b are only illustrative descriptions, and do not limit the scope of the embodiments of the present application.
  • the process in the second embodiment of the present application is basically the same as the process corresponding to the timing duration of T in the first embodiment. The only difference is that in the second embodiment of the present application, the number of P/E consumed in the previous preset period and the total number of P/Es are used.
  • the WAF is calculated by increasing the master's write volume, predicting the master's acceptable write volume W1 in the next preset cycle unit duration and the non-Swap partition of the flash memory in the next preset cycle write volume W2.
  • the writeable amount WS in the unit duration of the next preset period of the Swap partition and in the first embodiment, the number of P/E consumed in the previous preset period or the previous stage and the increased master write WAF is calculated based on the input volume, predicting the acceptable write volume W1 in the next preset cycle or the next stage of the master control and the write within the next preset cycle or the next stage of the non-Swap partition in the flash memory.
  • the second embodiment of the present application predicts the write amplification factor WAF of the next preset cycle based on the data written by the master control and the data of the previous preset cycle written by Swap, which improves the prediction accuracy of WAF; and writes according to the above prediction.
  • the amplification factor WAF is used to predict the acceptable write amount W1 within the unit duration of the next preset period of the master control, thereby improving the prediction accuracy of the acceptable write amount W1 within the unit duration of the next preset period of the master control.
  • the write volume W2 in the next preset cycle of the non-Swap partition in the flash memory is predicted according to the data of the previous preset cycle written by the master control and the swap.
  • the amount of writing in the unit duration of the next preset period of the swap partition is controlled, so that the actual service life of the flash memory is as close as possible or even reaches the ideal service life. At the same time, it can also respond to the user's demand for writing to the flash memory immediately.
  • the related content involved in the second embodiment of the present application is the same as the related content in the first embodiment of the present application. I won't repeat them here.
  • Fig. 7 shows a flow chart of a flash memory swap partition control method provided in the third embodiment of the present application.
  • the manufacturer of the mobile device presets the threshold N, and no longer presets the period T.
  • the purpose of setting the preset threshold value N is to determine whether the increase value of the master control write amount reaches the preset threshold value N.
  • the preset threshold N can be set by the manufacturer of the mobile device as needed before starting the method. After the method starts, first judge whether it is the first run.
  • the wear of the flash memory is detected and related parameters are obtained.
  • Related parameters include, but are not limited to, the capacity of the flash memory, the number of P/Es, the current number of consumed P/Es, the initial number of consumed P/Es, the current master write volume, the initial master write volume, and ideal use Life, current used life, initial life, current swap write volume and initial swap write volume.
  • the above-mentioned related parameters include the first parameter of the flash memory in the previous stage and the current second parameter.
  • the first parameter includes: capacity, P/E times, ideal service life, initial consumed P/E times, initial master control write volume, initial life span, and initial swap write volume;
  • the second parameter includes : Current consumed P/E times, current master control write volume, current used life span, and current swap write volume.
  • the first parameter includes: the initial number of consumed P/Es, the initial master control write amount, the initial life span, and the initial swap write amount;
  • the second parameter includes: capacity, P/E times , Ideal service life, current consumed P/E times, current master write volume, current used service life and current swap write volume.
  • the first parameter includes: the initial number of consumed P/Es, the initial master write amount, the initial life span, and the initial swap write amount
  • the second parameter includes: the current consumed P/E The number of times, the current master control write volume, the current service life, and the current swap write volume
  • the method further includes: obtaining a third parameter
  • the third parameter includes: capacity, P/E times, and ideal service life. Then, based on the acquired first parameter and second parameter, or based on the acquired first parameter, second parameter, and third parameter, calculate the increased master write volume, the write amplification factor WAF, and the remaining available master control Write volume.
  • increased master control write volume current master control write volume-initial master control write volume
  • WAF capacity * (currently consumed P/E times-initial consumed P/E times)/increase The master's write volume
  • the remaining writable volume of the master capacity * (P/E times-current consumed P/E times)/WAF.
  • the stage here corresponds to the situation from the end of the previous stage to the occurrence of the increase of the master write amount being greater than or equal to the preset threshold N. That is to say, the moment when the increased main control write amount is greater than or equal to the preset threshold N corresponds to the last stage just ending.
  • the above-mentioned more accurate WAF is used to calculate the remaining writable amount of the master control, so that the calculated remaining amount of the master control can be more accurate.
  • W2 Increased master control write volume/((current used service life-initial life) / unit duration)-(current swap write volume-initial swap write volume) / ((currently used Service life-initial life) / unit time). After that, it is judged whether W1 is greater than W2.
  • the swap partition in the flash memory is prohibited or allowed. Write. Even if allowed, it controls the amount of writes that can be written per unit time in the next stage of the Swap partition.
  • the embodiment of the present application controls the writing amount of the swap partition in the flash memory, which prolongs the actual service life of the flash memory.
  • the embodiments of the present application also allow users to write to non-Swap partitions in the flash memory instantly, without affecting the normal use of users.
  • update some of the parameters specifically: update the initial number of consumed P/E to the current number of consumed P/E; update the initial master write amount to the current master write amount; The initial Swap write amount is updated to the current Swap write amount; the initial life is updated to the current used life.
  • the loop is executed to the beginning, and it is judged again whether it is the first run; if it is not the first run, get the current master write volume and the initial master write volume; and calculate the increased master write volume.
  • Increased master control write volume current master control write volume-initial master control write volume. Determine whether the increased main control write amount is greater than or equal to the preset threshold N. According to the judgment result, the corresponding process of this method is cyclically executed.
  • the increased main control write volume is less than the preset threshold N, continue to obtain the current main control write volume and the initial main control write volume, and calculate the increased main control write volume and determine the increased main control write volume Whether the amount is greater than or equal to the preset threshold N. According to the judgment result, the corresponding process of this method is cyclically executed.
  • Figure 9c is taken as an example for further explanation.
  • the time when the increased master write amount is greater than or equal to the preset threshold N for the first time is t1.
  • some parameters are updated, especially the initial master control write volume is updated to the current master control write volume at time t1.
  • the increased master write volume is equal to the preset threshold N again.
  • predict W1 and W2 according to the above procedure of this method and set WS according to the comparison result of W1 and W2.
  • some parameters are updated, especially the initial master control write volume is updated to the current master control write volume at time t2.
  • the increased master write volume is equal to the preset threshold N again.
  • some parameters are updated, especially the initial master control write volume is updated to the current master control write volume at time t3. Then recalculate the increased master control write amount, and determine whether the increased master write amount is greater than or equal to N. At time t4, the increased master write volume is equal to the preset threshold N again. Then predict W1 and W2 according to the above procedure of this method, and set WS according to the comparison result of W1 and W2. Afterwards, some parameters are updated, especially the initial master control write volume is updated to the current master control write volume at t4. After that, further calculate the increased master control write amount and determine whether the increased master write amount is greater than or equal to N. According to the judgment result, the above-mentioned process of this method is executed cyclically.
  • 0 to t1 correspond to the first stage
  • t1 to t2 correspond to the second stage
  • t2 to t3 correspond to the third stage
  • t3 to t4 correspond to the fourth stage.
  • the foregoing content and the content shown in FIG. 9c are only illustrative descriptions, and do not limit the scope of the embodiments of the present application.
  • the process in the third embodiment of the present application is basically the same as the process corresponding to the increased master control write amount greater than or equal to N in the first embodiment. The only difference is that in the third embodiment of the present application, the P/ consumed in the previous stage is used.
  • the WAF is calculated by the number of E times and the increased master write volume, and the master can predict the acceptable write volume W1 in the next stage of the unit time and the write volume W2 in the next stage of the non-Swap partition in the flash memory.
  • the unit duration of the next stage in the third embodiment of the present application is the same as the unit duration of the previous stage. For example, if the unit duration of the previous stage is 1 day, the unit duration of the next stage is also 1 day.
  • the third embodiment of the application predicts the write amplification factor WAF of the next stage of the master control based on the data of the previous stage of master write and swap write, thereby improving the calculation accuracy of WAF; and based on the above predicted write amplification
  • the factor WAF is used to predict the acceptable write volume W1 within the unit duration of the next stage of the master control, thereby improving the prediction accuracy of the acceptable write volume W1 within the unit duration of the next stage of the master control.
  • predict the write volume W2 in the next stage of the non-Swap partition in the flash memory per unit time based on the data of the previous stage of master write and swap write.
  • the related content involved in the second embodiment of the present application is the same as the related content in the first embodiment of the present application. I won't repeat them here.
  • FIG. 8 shows a mobile device 800 provided by this application.
  • the mobile device 800 includes at least one processor 801 and a memory 802.
  • the processor 801 is coupled with the memory 802.
  • the coupling in the embodiment of the present application may be a communication connection, an electrical connection, or other forms.
  • the memory 802 is used to store program instructions.
  • the processor 801 is configured to call program instructions stored in the memory 802, so that the mobile device 800 executes the steps executed by the mobile device 800 in a flash memory swap partition control method provided in any one of Embodiment 1 to Embodiment 3 of the present application.
  • the mobile device 800 can be used to implement a flash memory swap partition control method provided in any one of Embodiment 1 to Embodiment 3 of the present application, and related features can be referred to the above, and will not be repeated here.
  • This application provides a computer program product containing instructions, which when the computer program product runs on a mobile device, causes the mobile device to execute a flash memory swap partition provided in any one of Embodiments 1 to 3 of this application The steps performed by the mobile device in the control method.
  • the present application provides a computer-readable storage medium, including instructions, which, when the instructions run on a mobile device, cause the mobile device to execute the flash memory swap partition control method provided in the embodiments of this application, which is executed by the mobile device A step of.
  • the embodiments of the present application can be implemented in hardware or in hardware and software. When implemented by hardware and software, the above functions can be stored in a computer-readable medium. Based on this understanding, the technical solutions of the embodiments of the present application are essentially or the part that contributes to the prior art, or all or part of the technical solutions can be embodied in the form of software products, and the computer software products are stored in a storage
  • the medium includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the methods described in the various embodiments of the present application.
  • the aforementioned storage media include: flash memory, mobile hard disk, read-only memory, random access memory, magnetic disk or optical disk and other media that can store program codes.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Techniques For Improving Reliability Of Storages (AREA)

Abstract

本申请涉及数据存储领域,尤其涉及闪存交换分区控制方法。在应用于包含闪存的移动设备的闪存交换分区控制方法中,在以当前时刻为计时起点的计时时长达到预设周期时,或者,在计时时长没有达到预设周期但增加的主控写入量大于等于预设阈值时,检测闪存的磨损,至少获取所述闪存在上一个预设周期或者上一个阶段的第一参数和当前的第二参数,并至少根据获取的第一参数和第二参数得到预测结果,进而允许或禁止后续对所述闪存中Swap分区的写入;从所述增加的主控写入量为0直至所述增加的主控写入量大于等于预设阈值所用的时长为一个阶段。通过本申请提供的技术方案,可以延长闪存的实际使用寿命;还允许对所述闪存中非Swap分区的区域的即时读写。

Description

一种闪存交换分区控制方法及移动设备
本申请要求在2020年1月22日提交中国国家知识产权局、申请号为202010075706.X的中国专利申请的优先权,发明名称为“一种闪存交换分区控制方法及移动设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及数据存储技术,尤其涉及一种闪存交换分区控制方法、移动设备及计算机可读存储介质。
背景技术
交换分区(Swap分区)技术能够扩展电子设备的内存空间,得到广泛应用。不过,Swap分区技术会导致对设置Swap分区的存储设备的频繁读取,加速存储设备的器件磨损。尤其对于移动设备,会使得设置Swap分区的闪存的实际使用寿命大大缩短。因此,对于Swap分区设置在闪存中的移动设备,延长闪存的实际使用寿命成为我们的需求。
发明内容
为了解决现有技术中存在的上述技术问题,本申请提出了一种闪存交换分区的控制方法、移动设备及计算机可读存储介质。
第一方面,提供一种闪存交换分区控制方法。所述闪存交换分区控制方法应用于包含闪存的移动设备,包括:以当前时刻为计时起点进行计时;在满足第一条件或满足第二条件时,检测闪存的磨损,至少获取所述闪存的第一参数和第二参数;至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入;所述第一条件为计时时长达到预设周期;所述第二条件为计时时长没有达到预设周期,但增加的主控写入量大于等于预设阈值;所述增加的主控写入量=当前的主控写入量–起始主控写入量;所述第一参数包括:容量、P/E次数、理想使用寿命、起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;或者,所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:容量、P/E次数、理想使用寿命、当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;或者,所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;所述方法还包括:获取第三参数;所述第三参数包括: 容量、P/E次数和理想使用寿命;其中,所述理想使用寿命为所述移动设备的生产厂家根据需要预先自行设置;所述容量和所述P/E次数为所述闪存的生产厂家提供的参数;所述主控用于向所述闪存读写数据。这样,就能够根据上一个预设周期或上一个阶段的第一参数和当前的第二参数进行预测,并根据预测结果确定允许或禁止在下一个预设周期或下一个阶段中对所述闪存中Swap分区的写入,使得闪存的实际使用寿命得以延长,并逼近甚至达到理想使用寿命。同时,所述方法还能响应用户对闪存的即时读写请求。这里,从所述增加的主控写入量为0直至所述增加的主控写入量大于等于预设阈值所用的时长为一个阶段。
根据第一方面,在所述在以当前时刻为计时起点进行计时之前,所述方法还包括:在判断所述方法首次运行时,将起始主控写入量、起始Swap写入量和起始寿命初始化为0,将起始已消耗P/E次数初始化为闪存已消耗P/E次数;所述至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入;包括:根据所述第一参数和所述第二参数,或者,根据所述第一参数、所述第二参数和所述第三参数,按照如下公式,预测主控后续单位时长内可接受写入量W1和闪存中非Swap分区后续单位时长内的写入量W2,并判断W1和W2的大小关系;增加的主控写入量=当前的主控写入量–起始主控写入量;WAF=容量*(当前已消耗P/E次数–起始已消耗P/E次数)/增加的主控写入量;主控剩余的可写入量=容量*(P/E次数–当前已消耗P/E次数)/WAF;W1=主控剩余的可写入量/(理想使用寿命/单位时长–当前已使用寿命/单位时长);W2=增加的主控写入量/((当前已使用寿命–起始寿命)/单位时长)–(当前的Swap写入量–起始Swap写入量)/((当前已使用寿命–起始寿命)/单位时长);其中,所述单位时长为所述移动设备的生产厂家根据需要预先自行设置;如果W1大于W2,设置所述闪存中Swap分区后续单位时长内可写入量WS=W1-W2;如果W1小于等于W2,设置所述闪存中Swap分区后续单位时长内可写入量WS=0。这样,给出了具体的预测方式以及基于按照上述预测方式得出的预测结果,确定允许还是禁止后续对所述闪存中Swap分区的写入,从而提供了具体的执行方式。
根据第一方面,或者第一方面的任意一种实现方式,在所述设置所述闪存中Swap分区后续单位时长内可写入量WS=W1-W2之后;或者,在所述设置所述闪存中Swap分区后续单位时长内可写入量WS=0之后;所述方法还包括:将所述起始已消耗P/E次数更新为所述当前已消耗P/E次数;将所述起始主控写入量更新为所述当前的主控写入量;将所述起始Swap写入量更新为所述当前的Swap写入量;将所述起始寿命更新为所述当前已使用寿命;将所述计时时长清零。这样,在上一个预设周期或上一个阶段结束时,就实现起始已消耗P/E次数、起始主控写入量、起始Swap写入量和起始寿命的更新以及计时时长的清零,使得在下一个预设周期或下一个阶段的预测中,能够利用上述公式正确地计算预测。
根据第一方面,或者第一方面的任意一种实现方式,在将计时时长清零之后,所述方法还包括:以当前时刻为计时起点进行计时;在满足第一条件或满足第二 条件时,检测闪存的磨损,至少获取所述闪存的第一参数和第二参数;至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入。这样,就使得所述方法在当前周期或当前阶段的运行结束后,循环执行该方法的步骤,继续在下一周期或下一阶段进行预测,并得到新的预测结果,进而根据新的预测结果,允许或禁止后续对所述闪存中Swap分区的写入,以及在允许的情况下,计算得到新的所述闪存中Swap分区后续单位时长内可写入量WS;从而使得闪存的实际使用寿命得以延长,并逼近甚至达到理想使用寿命。
根据第一方面,或者第一方面的任意一种实现方式,所述方法允许对所述闪存中非Swap分区的区域的即时读写。也就是说,该方法仅允许或禁止所述闪存中的Swap分区的写入,不限制所述闪存中非Swap分区的区域的即时读写。这样,还向用户提供对所述闪存即时读写的服务,不影响用户的正常使用。
第二方面,提供一种闪存交换分区控制方法。所述方法应用于包含闪存的移动设备,包括:以当前时刻为计时起点进行计时;在计时时长达到预设周期时,检测闪存的磨损,至少获取所述闪存的第一参数和第二参数;至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入;所述第一参数包括:容量、P/E次数、理想使用寿命、起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;或者,所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:容量、P/E次数、理想使用寿命、当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;或者,所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;所述方法还包括:获取第三参数;所述第三参数包括:容量、P/E次数和理想使用寿命;其中,所述理想使用寿命为所述移动设备的生产厂家根据需要预先自行设置;所述容量和所述P/E次数为所述闪存的生产厂家提供的参数。这样,就能够根据上一个预设周期的第一参数和当前的第二参数进行预测,并根据预测结果确定允许或禁止在下一个预设周期中对所述闪存中Swap分区的写入,使得闪存的实际使用寿命得以延长,并逼近甚至达到理想使用寿命。同时,所述方法还能响应用户对闪存的即时读写请求。
根据第二方面,在所述在以当前时刻为计时起点进行计时之前,所述方法还包括:在判断所述方法首次运行时,将起始主控写入量、起始Swap写入量和起始寿命初始化为0,将起始已消耗P/E次数初始化为闪存已消耗P/E次数;所述至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入;包括:根据所述第一参数和所述第二参数,或者,根据所述第一参数、所述第二参数和所述第三参数,按照如下公 式,预测主控后续单位时长内可接受写入量W1和闪存中非Swap分区后续单位时长内的写入量W2,并判断W1和W2的大小关系;增加的主控写入量=当前的主控写入量–起始主控写入量;WAF=容量*(当前已消耗P/E次数–起始已消耗P/E次数)/增加的主控写入量;主控剩余的可写入量=容量*(P/E次数–当前已消耗P/E次数)/WAF;W1=主控剩余的可写入量/(理想使用寿命/单位时长–当前已使用寿命/单位时长);W2=增加的主控写入量/((当前已使用寿命–起始寿命)/单位时长)–(当前的Swap写入量–起始Swap写入量)/((当前已使用寿命–起始寿命)/单位时长);其中,所述单位时长为所述移动设备的生产厂家根据需要预先自行设置;如果W1大于W2,设置所述闪存中Swap分区后续单位时长内可写入量WS=W1-W2;如果W1小于等于W2,设置所述闪存中Swap分区后续单位时长内可写入量WS=0。这样,给出了具体的预测方式以及基于按照上述预测方式得出的预测结果,确定允许还是禁止后续对所述闪存中Swap分区的写入,从而提供了具体的执行方式。
根据第二方面,或者第二方面的任意一种实现方式,在所述设置所述闪存中Swap分区后续单位时长内可写入量WS=W1-W2之后;或者,在所述设置所述闪存中Swap分区后续单位时长内可写入量WS=0之后;所述方法还包括:将所述起始已消耗P/E次数更新为所述当前已消耗P/E次数;将所述起始主控写入量更新为所述当前的主控写入量;将所述起始Swap写入量更新为所述当前的Swap写入量;将所述起始寿命更新为所述当前已使用寿命;将所述计时时长清零。这样,在上一个预设周期结束时,就实现起始已消耗P/E次数、起始主控写入量、起始Swap写入量和起始寿命的更新以及计时时长的清零,使得在下一个预设周期的预测中,能够利用上述公式正确地计算预测。
根据第二方面,或者第二方面的任意一种实现方式,在将计时时长清零之后,所述方法还包括:以当前时刻为计时起点进行计时;在计时时长达到预设周期时,检测闪存的磨损,至少获取所述闪存的第一参数和当前的第二参数;至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入。这样,就使得所述方法在当前周期的运行结束后,循环执行该方法的步骤,继续在下一周期进行预测,并得到新的预测结果,进而根据新的预测结果,允许或禁止后续对所述闪存中Swap分区的写入,以及在允许的情况下,计算得到新的所述闪存中Swap分区后续单位时长内可写入量WS;从而使得闪存的实际使用寿命得以延长,并逼近甚至达到理想使用寿命。
根据第二方面,或者第二方面的任意一种实现方式,所述方法允许对所述闪存中非Swap分区的区域的即时读写。也就是说,该方法仅允许或禁止所述闪存中的Swap分区的写入,不限制所述闪存中非Swap分区的区域的即时读写。这样,还向用户提供对所述闪存即时读写的服务,不影响用户的正常使用。
第三方面,提供一种闪存交换分区控制方法。所述方法应用于包含闪存的移动设备,包括:获取当前的主控写入量和起始主控写入量,按照如下公式计算增加的主控写入量;增加的主控写入量=当前的主控写入量–起始主控写入量;在 增加的主控写入量大于等于预设阈值时,检测闪存的磨损,至少获取所述闪存第一参数和第二参数;至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入;所述第一参数包括:容量、P/E次数、理想使用寿命、起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;或者,所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:容量、P/E次数、理想使用寿命、当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;或者,所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;所述方法还包括:获取第三参数;所述第三参数包括:容量、P/E次数和理想使用寿命;其中,所述理想使用寿命为所述移动设备的生产厂家根据需要预先自行设置;所述容量和所述P/E次数为所述闪存的生产厂家提供的参数。这样,就能够根据上一个阶段的第一参数和当前的第二参数进行预测,并根据预测结果确定允许或禁止在下一个阶段中对所述闪存中Swap分区的写入,使得闪存的实际使用寿命得以延长,并逼近甚至达到理想使用寿命。同时,所述方法还能响应用户对闪存的即时读写请求。这里,从所述增加的主控写入量为0直至所述增加的主控写入量大于等于预设阈值所用的时长为一个阶段。
根据第三方面,在所述获取当前的主控写入量和起始主控写入量之前,所述方法还包括:在判断所述方法首次运行时,将起始主控写入量、起始Swap写入量和起始寿命初始化为0,将起始已消耗P/E次数初始化为闪存已消耗P/E次数;所述至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入;包括:根据所述第一参数和所述第二参数,或者,根据所述第一参数、所述第二参数和所述第三参数;按照如下公式,预测主控后续单位时长内可接受写入量W1和闪存中非Swap分区后续单位时长内的写入量W2;WAF=容量*(当前已消耗P/E次数–起始已消耗P/E次数)/增加的主控写入量;主控剩余的可写入量=容量*(P/E次数–当前已消耗P/E次数)/WAF;W1=主控剩余的可写入量/(理想使用寿命/单位时长–当前已使用寿命/单位时长);W2=增加的主控写入量/((当前已使用寿命–起始寿命)/单位时长)–(当前的Swap写入量–起始Swap写入量)/((当前已使用寿命–起始寿命)/单位时长);如果W1大于W2,设置所述闪存中Swap分区后续单位时长内可写入量WS=W1-W2;如果W1小于等于W2,设置所述闪存中Swap分区后续单位时长内可写入量WS=0;所述单位时长为所述移动设备的生产厂家根据需要预先自行设置。这样,给出了具体的预测方式以及基于按照上述预测方式得出的预测结果,确定允许还是禁止后续对所述闪存中Swap分区的写入,从而提供了具体的执行方式。
根据第三方面,或者第三方面的任意一种实现方式,在所述设置所述闪存中 Swap分区后续单位时长内可写入量WS=W1-W2之后;或者,在所述设置所述闪存中Swap分区后续单位时长内可写入量WS=0之后;所述方法还包括:将所述起始已消耗P/E次数更新为所述当前已消耗P/E次数;将所述起始主控写入量更新为所述当前的主控写入量;将所述起始Swap写入量更新为所述当前的Swap写入量;将所述起始寿命更新为所述当前已使用寿命。这样,在上一个阶段结束时,就实现起始已消耗P/E次数、起始主控写入量、起始Swap写入量和起始寿命的更新以及计时时长的清零,使得在下一个阶段的预测中,能够利用上述公式正确地计算预测。
根据第三方面,或者第三方面的任意一种实现方式,在将所述起始寿命更新为所述当前已使用寿命之后,所述方法还包括:获取当前的主控写入量和起始主控写入量,计算增加的主控写入量;在增加的主控写入量大于等于预设阈值时,检测闪存的磨损,至少获取所述闪存第一参数和第二参数;至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入。这样,就使得所述方法在当前阶段的运行结束后,循环执行该方法的步骤,继续在下一阶段进行预测,并得到新的预测结果,进而根据新的预测结果,允许或禁止后续对所述闪存中Swap分区的写入,以及在允许的情况下,计算得到新的所述闪存中Swap分区后续单位时长内可写入量WS;从而使得闪存的实际使用寿命得以延长,并逼近甚至达到理想使用寿命。
根据第三方面,或者第三方面的任意一种实现方式,所述方法允许对所述闪存中非Swap分区的区域的即时读写。也就是说,该方法仅允许或禁止所述闪存中的Swap分区的写入,不限制所述闪存中非Swap分区的区域的即时读写。这样,还向用户提供对所述闪存即时读写的服务,不影响用户的正常使用。
第四方面,提供一种移动设备,至少包括:存储器、一个或多个处理器以及一个或多个计算机程序;其中一个或多个计算机程序被存储在所述存储器中;一个或多个处理器在执行一个或多个计算机程序时,使得移动设备实现第一方面至第三方面中任意一个方面以及第一方面至第三方面中任意一种实现方式中的闪存交换分区控制方法。
另外,第四方面中任意一种实现方式和对应的技术效果可参见上述第一方面至第三方面中任意一个方面的实现方式和对应的技术效果以及第一方面至第三方面中任意一种实现方式和对应的技术效果,此处不再赘述。
第五方面,提供一种计算机可读存储介质,包括指令,当指令在第四方面的移动设备上运行时,使得所述移动设备执行第一方面至第三方面中任意一个方面以及第一方面至第三方面中任意一种实现方式中的闪存交换分区控制方法。
另外,第五方面中任意一种实现方式和对应的技术效果可参见上述第一方面至第三方面中任意一个方面的实现方式和对应的技术效果以及第一方面至第三方面中任意一种实现方式和对应的技术效果,此处不再赘述。
附图说明
图1为本申请实施例提供的一种移动设备的结构示意图。
图2为本申请实施例提供的SoC与闪存存储器之间数据读写的硬件结构示意图。
图3为本申请实施例提供的闪存存储器的结构示意图。
图4为本申请实施例提供的SoC与闪存存储器之间数据读写的软件操作示意图。
图5为本申请实施例一提供的一种闪存交换分区控制方法的流程示意图。
图6为本申请实施例二提供的一种闪存交换分区控制方法的流程示意图。
图7为本申请实施例三提供的一种闪存交换分区控制方法的流程示意图。
图8为本申请实施例提供的一种移动设备的硬件结构框图。
图9为本申请实施例提供的一种闪存交换分区控制方法中计时时长达到预设周期和/或增加的主控写入量大于等于预设阈值相应触发的流程执行的时间关系示意图。
具体实施方式
下面将结合附图,对本发明实施例中的技术方案进行清楚、完整地描述。显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有付出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。
Swap分区技术是当电子设备的内存资源不足时,操作系统将内存中一些不常使用的数据(也称冷数据)存放到Swap分区中。举例来说,操作系统可以使用最近最少使用LRU(Least Recently Used)方法,将正在使用的内存页面维护在一个LRU链表中。当内存空闲页面不足时,页框实地址PFRA(Page Frame Real Address)会从LRU链表中回收一些较少被用到的内存页面中的数据放到Swap分区中。如此可减少对内存资源的占用,释放更多的内存资源供当前进程使用。当操作系统需要Swap分区中的数据时,再将上述数据重新加载到内存中。因此,Swap分区在功能上扩展了内存空间。Swap分区可以设置在内存、硬盘或其他存储设备中。设置在内存中的Swap分区又称为ZRAM。在将内存中的冷数据存储在ZRAM中时,通常先对上述冷数据压缩之后再存储在ZRAM中。对于诸如智能手机的移动设备,现有技术中一般是将Swap分区设置在闪存(闪存Memory)中。频繁的数据换入(Swap in)/换出(Swap out)会使得闪存单位时长内的写入写出量变大,容易造成闪存过度磨损,降低闪存的使用寿命。比如理想使用寿命为5年的闪存,在将Swap分区设置在闪存中后,闪存的实际使用寿命可能仅为3年。因此,对于Swap分区设置在闪存中的移动设备,需要延长闪存的实际使用寿命,尽可能使得闪存的实际使用寿命逼近甚至达到理想使用寿命。
本申请实施例提供的方法可以应用于图1所示的移动设备100中。图1示出了移动设备100的结构示意图。
移动设备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可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。
处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
控制器可以根据指令操作码和时序信号,产生操作控制信号,完成取指令和执行指令的控制。
处理器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)接口等。
USB接口130是符合USB标准规范的接口,具体可以是Mini USB接口,Micro USB接口,USB Type C接口等。可以理解的是,本发明实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对移动设备100的结构限定。在本申请另一些实施例中,移动设备100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
充电管理模块140用于从充电器接收充电输入。电源管理模块141用于连接电池142,充电管理模块140与处理器110。移动设备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反馈的数据。摄像头193用于捕获静态图像或视频。物体通过镜头生成光学图像投射到感光元件。
数字信号处理器用于处理数字信号,除了可以处理数字图像信号,还可以处理其他数字信号。例如,当移动设备100在频点选择时,数字信号处理器用于对频点能量进行傅里叶变换等。
视频编解码器用于对数字视频压缩或解压缩。移动设备100可以支持一种或多种视频编解码器。这样,移动设备100可以播放或录制多种编码格式的视频,例如:动态图像专家组(moving picture experts group,MPEG)1,MPEG2,MPEG3,MPEG4等。
NPU为神经网络(neural-network,NN)计算处理器,通过借鉴生物神经网络结构,例如借鉴人脑神经元之间传递模式,对输入信息快速处理,还可以不断的自学习。
外部存储器接口120可以用于连接外部存储卡,例如Micro SD卡,实现扩展移动设备100的存储能力。外部存储卡通过外部存储器接口120与处理器110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部存储卡中。
内部存储器121可以用于存储计算机可执行程序代码,所述可执行程序代码包括指令。内部存储器121可以包括存储程序区和存储数据区。其中,存储程序区可存储操作系统,至少一个功能所需的应用程序(比如声音播放功能,图像播 放功能等)等。存储数据区可存储移动设备100使用过程中所创建的数据(比如音频数据,电话本等)等。此外,内部存储器121可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件,闪存器件,通用闪存存储器(universal闪存storage,UFS)等。处理器110通过运行存储在内部存储器121的指令,和/或存储在设置于处理器中的存储器的指令,执行移动设备100的各种功能应用以及数据处理。
移动设备100可以通过音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。
压力传感器180A用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器180A可以设置于显示屏194。压力传感器180A的种类很多,如电阻式压力传感器,电感式压力传感器,电容式压力传感器等。电容式压力传感器可以是包括至少两个具有导电材料的平行板。当有力作用于压力传感器180A,电极之间的电容改变。移动设备100根据电容的变化确定压力的强度。当有触摸操作作用于显示屏194,移动设备100根据压力传感器180A检测所述触摸操作强度。移动设备100也可以根据压力传感器180A的检测信号计算触摸的位置。在一些实施例中,作用于相同触摸位置,但不同触摸操作强度的触摸操作,可以对应不同的操作指令。例如:当有触摸操作强度小于第一压力阈值的触摸操作作用于短消息应用图标时,执行查看短消息的指令。当有触摸操作强度大于或等于第一压力阈值的触摸操作作用于短消息应用图标时,执行新建短消息的指令。
陀螺仪传感器180B可以用于确定移动设备100的运动姿态。气压传感器180C用于测量气压。在一些实施例中,移动设备100通过气压传感器180C测得的气压值计算海拔高度,辅助定位和导航。磁传感器180D包括霍尔传感器。加速度传感器180E可检测移动设备100在各个方向上(一般为三轴)加速度的大小。距离传感器180F,用于测量距离。移动设备100可以通过红外或激光测量距离。在一些实施例中,拍摄场景,移动设备100可以利用距离传感器180F测距以实现快速对焦。接近光传感器180G可以包括例如发光二极管(LED)和光检测器,例如光电二极管。环境光传感器180L用于感知环境光亮度。指纹传感器180H用于采集指纹。移动设备100可以利用采集的指纹特性实现指纹解锁,访问应用锁,指纹拍照,指纹接听来电等。温度传感器180J用于检测温度。
触摸传感器180K,也称“触控器件”。触摸传感器180K可以设置于显示屏194,由触摸传感器180K与显示屏194组成触摸屏,也称“触控屏”。触摸传感器180K用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。可以通过显示屏194提供与触摸操作相关的视觉输出。在另一些实施例中,触摸传感器180K也可以设置于移动设备100的表面,与显示屏194所处的位置不同。
骨传导传感器180M可以获取振动信号。按键190包括开机键,音量键等。 按键190可以是机械按键。也可以是触摸式按键。移动设备100可以接收按键输入,产生与移动设备100的用户设置以及功能控制有关的键信号输入。马达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分离。移动设备100的软件系统可以采用分层架构,事件驱动架构,微核架构,微服务架构,或云架构。
本申请实施例提供的一种闪存交换分区控制方法,能够监测和控制闪存单位时长内的实际写入量和闪存中Swap分区单位时长内的实际写入量,延长闪存的实际使用寿命,使得移动设备的闪存的实际使用寿命逼近甚至达到理想使用寿命。
图2是本申请实施例提供的SoC与闪存存储器之间数据读写的硬件结构示意图。如图2所示,片上系统SoC(System on Chip)200包括中央处理器CPU(Central Processing Unit)210、图形处理器GPU(Graphics Processing Unit)220、闪存主控(闪存Host Controller)(以下简称主控)230、调制解调器240和RAM控制器250。闪存存储器300与主控230连接。CPU210通过总线、主控230与闪存存储器300进行数据读写。图3为本申请实施例提供的闪存存储器的结构示意图。如图3所示,闪存存储器300包括闪存设备控制器310和闪存存储介质350。闪存设备控制器310进一步包括擦除管理模块320、读写管理模块330和垃圾回收管理模块340,分别用于执行擦除管理、读写管理和垃圾回收管理功能。闪存存储器300在接收主控的数据写命令时,是通过闪存设备控制器310接收主控230的写命令,然后先擦除后写入。闪存存储器300在接收主控230的数据读命令时,是通过闪存设备控制器310接收主控230的读命令,直接读取。图4为本申请实施例提供的SoC与闪存存储器之间数据读写的软件操作示意图。如图4所示,内核空间设置有内存管理模块400和磨损检测模块500,分别用于执行内存管理和磨损检测功能。内存管理模块400包括冷数据识别及交换模块410。内存管理模块还可以包括ZRAM管理模块420。如果内存RAM600中设置有ZRAM610,相应地,内存管理模块400就包括ZRAM管理模块420。如果内存RAM600中没有设置ZRAM610,相应地,内存管理模块400就不包括ZRAM管理模块420。在内存RAM600模块不包含ZRAM610,内存管理模块400也不包含ZRAM管理模块420时,冷数据识别及交换模块410识别内存RAM600中的冷数据,并将识别出的上述冷数据存储至闪存700的Swap分区710中。在内存 RAM600包含ZRAM610,内存管理模块400包含ZRAM管理模块420时,冷数据识别及交换模块410可以识别内存RAM600中的冷数据,并将识别出的冷数据按照冷数据的程度,将上述冷数据中更冷的数据存储在闪存700的Swap分区710中,将上述冷数据中相对不那么冷的数据经压缩后存储在ZRAM610中;冷数据识别及交换模块410也可以识别内存RAM600中的冷数据,并将识别出的冷数据经压缩后都存储在ZRAM610中,再按照冷数据的程度将ZRAM610的冷数据中更冷的数据以压缩的形式或者以解压缩的形式存储在闪存700的Swap分区710中。磨损检测模块500用于对闪存700进行磨损检测,获取闪存700的相关参数。
所述相关参数包括但不限于闪存的容量、P/E(Program/Erase,擦写)次数、当前已消耗P/E次数、起始已消耗P/E次数、当前主控写入量、起始主控写入量、理想使用寿命、当前已使用寿命、起始寿命、当前Swap写入量和起始Swap写入量。其中,首次获取的起始主控写入量、起始寿命和起始Swap写入量均为0。首次获取的起始已消耗P/E次数为闪存已消耗P/E次数。闪存的容量和P/E次数即闪存的擦写次数都是由闪存的生产厂家提供的。由于CPU210在通过总线、主控230写入闪存存储器即闪存300时,都是先将数据写入主控230,之后数据再从主控230写入闪存存储器即闪存300中的Swap分区和非Swap分区。因此,可以获取到当前主控写入量和起始主控写入量。并且主控写入量=Swap写入量+非Swap写入量。Swap写入量为闪存中Swap分区的写入量。非Swap写入量为闪存中非Swap分区的写入量。此外,将数据写入闪存的Swap分区或非Swap分区的命令都包含有地址,通过该地址可以区分出是写入Swap分区还是非Swap分区。因此,可以获取到当前的Swap写入量和起始Swap写入量。当前已消耗P/E次数可以通过特定命令查询获取。当前已使用寿命可通过计时获取。理想使用寿命是由移动设备的生产厂家自行设定的,一般设为5年以上;有时也可设为3-5年。
闪存的可写入的最大数据量是通过万亿字节写入TBW(Tera Byte Written)来衡量的。TBW的相关公式为:
TBW=DWPD*理想使用寿命(年)*365*容量(GB)/1000(GB/TB)  公式1
TBW=容量(GB)*(每单元P/E次数)/(1000(GB/TB)*WAF)  公式2
其中,每日整盘写入次数DWPD(Device Writes Per Day)是指按照理想使用寿命,闪存每日可写入的最大数据量。每单元P/E次数就是闪存所包括的单元(BLOCK)的擦写次数,也等于闪存的擦写次数。闪存只有在擦除之后才能写入。公式2中的写入放大因子WAF(Write Amplification Factor)通常是动态变化的。对于连续工作负载,WAF通常在一位数范围内,动态变化范围较小。对于随机工作负载,WAF可能会达到甚至超过100,动态变化范围较大。由于WAF是动态变化的,因而会导致TBW发生变化,从而导致DWPD发生变化。也就 是说,WAF和DWPD随时都可能发生变化。在理想使用寿命恒定的情况下,通过监测控制闪存每日写入量小于等于即时DWPD,来使得闪存的实际使用寿命尽可能逼近甚至达到理想使用寿命,计算复杂,不易实现。并且,控制闪存每日写入量可能会使得在用户需要写入闪存时无法写入,导致用户体验不好。
本申请实施例基于主控写入、Swap写入的上一个预设周期或上一个阶段的数据,分别预测主控后续单位时长内可接受写入量W1、闪存中非Swap分区后续单位时长内的写入量W2,并基于预测后的两者比较结果,设置Swap分区后续单位时长内可写入量,同时在上述预测过程中提高WAF计算的精准度,使得闪存的实际使用寿命尽可能逼近甚至达到理想使用寿命。并且,本申请实施例还在用户需要写入闪存时即可写入闪存,不受限制。其中,从增加的主控写入量为0直至增加的主控写入量大于等于预设阈值所用的时长为一个阶段。
实施例一
图5示出了本申请实施例一提供的一种闪存交换分区控制方法的流程图。如图5所示,移动设备的生产厂家预先设置好周期T和预设阈值N。周期T可以设置为诸如50秒、30分钟、10小时、7日、3个月、1年等任意时长。另外,周期T的单位可以为秒、分钟、小时、日、月、年等。设置预设阈值N的目的是用于判断主控写入量的增加值是否达到预设阈值N。周期T和预设阈值N可以由移动设备的生产厂家在启动该方法之前,根据需要自行设置。该方法开始后,首先判断是否为首次运行。若为首次运行,则将起始主控写入量、起始Swap写入量和起始寿命初始化为0,将起始已消耗P/E次数初始化为闪存已消耗P/E次数;之后,将当前时刻作为计时起点,从该计时起点开始计时。若不为首次运行,则将当前时刻作为计时起点,从该计时起点开始计时。然后,判断计时时长是否达到T。
若计时时长达到T,则检测闪存的磨损,获取闪存的相关参数。闪存的相关参数包括但不限于容量、P/E次数、当前已消耗P/E次数、起始已消耗P/E次数、当前的主控写入量、起始主控写入量、理想使用寿命、当前已使用寿命、起始寿命、当前的Swap写入量和起始Swap写入量。具体来说,上述相关参数包括闪存在上一个预设周期或者上一个阶段的第一参数和当前的第二参数。第一参数包括:容量、P/E次数、理想使用寿命、起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量。或者,所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:容量、P/E次数、理想使用寿命、当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量。或者,所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;所述方法还包括:获取第三参数;所述第三参数包括:容量、P/E次数和理想使用寿命。然后,基于获取的第一参数和第二参数,或者,基于获取的第 一参数、第二参数和第三参数,计算增加的主控写入量、写入放大因子WAF和主控剩余的可写入量。其中,相应的计算公式为:增加的主控写入量=当前的主控写入量–起始主控写入量;WAF=容量*(当前已消耗P/E次数–起始已消耗P/E次数)/增加的主控写入量;主控剩余的可写入量=容量*(P/E次数–当前已消耗P/E次数)/WAF。这样,就采用了上一个预设周期或上一个阶段所消耗的P/E次数和所增加的主控写入量来计算WAF,并将计算得到的WAF预测为下一个预设周期或下一个阶段的WAF。以图9a为例,所述阶段对应着0至t1、t1至t2。也就是说,此时出现增加的主控写入量大于等于预设阈值N情形的时刻对应着上一个阶段刚结束。具体地,可以采用上一个预设周期的数据来预测下一个预设周期或下一个阶段的WAF,也可以采用上一个阶段的数据来预测下一个预设周期或下一个阶段的WAF,使得对下一个预设周期或下一个阶段的WAF的预测更为准确。具体采用上一个预设周期或上一个阶段的数据,是根据先实现计时时长达到T还是先出现增加的主控写入量大于等于预设阈值N的情形来确定。并且运用上述更为准确的WAF来计算主控剩余的可写入量,从而使得计算得到的上述主控剩余的可写入量更为准确。之后,预测主控后续单位时长内可接受写入量W1。其中,预测公式为:W1=主控剩余的可写入量/(理想使用寿命/单位时长–当前已使用寿命/单位时长)。这样,由于W1的预测是基于上述更为准确的主控剩余的可写入量,也就使得W1的预测更为准确。然后,预测闪存中非Swap分区后续单位时长内的写入量W2。预测公式为:W2=增加的主控写入量/((当前已使用寿命–起始寿命)/单位时长)–(当前的Swap写入量–起始Swap写入量)/((当前已使用寿命–起始寿命)/单位时长)。之后,判断W1是否大于W2。如果W1大于W2,设置Swap分区后续单位时长内可写入量WS=W1-W2。如果W1小于等于W2,设置Swap分区后续单位时长内可写入量WS=0。这样,就根据预测的闪存中非Swap分区后续单位时长内的写入量W2与主控后续单位时长内可接受写入量W1的大小关系,禁止或者允许对闪存中的Swap分区的写入。即便在允许的情形下,也控制Swap分区后续单位时长内可写入量。此外,由于该方法没有限制对闪存中非Swap分区的写入,所以用户在需要写入闪存时可以即时写入闪存。本申请实施例对闪存中的Swap分区的写入量进行控制,延长了闪存的实际使用寿命。并且,本申请实施例还允许用户即时写入闪存中的非Swap分区,不影响用户的正常使用。最后,对部分参数进行更新;具体为:将起始已消耗P/E次数更新为当前已消耗P/E次数;将起始主控写入量更新为当前的主控写入量;将起始Swap写入量更新为当前的Swap写入量;将起始寿命更新为当前已使用寿命;计时时长清零。之后,循环执行至开始,再次判断是否为首次运行;非首次运行,将当前时刻作为新的计时起点,从所述新的计时起点重新开始计时;判断计时时长是否达到T,即判断从所述新的计时起点开始的所述计时时长是否大于等于从所述新的计时起点开始的T。在计时时长达到T时,按照上述流程继续执行。在计时时长未达到T时,按照下述流程继续执行。
若计时时长未达到T,则获取当前的主控写入量和起始主控写入量;并计算 增加的主控写入量。增加的主控写入量=当前的主控写入量–起始主控写入量。然后,判断增加的主控写入量是否大于等于预设阈值N。如果增加的主控写入量小于预设阈值N,则继续判断计时时长是否达到T。如果增加的主控写入量大于等于预设阈值N,则检测闪存的磨损,获取相关参数。相关参数包括但不限于闪存的容量、P/E次数、当前已消耗P/E次数、起始已消耗P/E次数、当前的主控写入量、起始主控写入量、理想使用寿命、当前已使用寿命、起始寿命、当前的Swap写入量和起始Swap写入量。然后,基于获取的上述相关参数,按照上述同样的流程和公式,预测主控后续单位时长内可接受写入量W1和闪存中非Swap分区后续单位时长内的写入量W2,根据W1和W2的大小比较结果,设置Swap分区后续单位时长内可写入量WS。即如果W1大于W2,设置Swap分区后续单位时长内可写入量WS=W1-W2;如果W1小于等于W2,设置Swap分区后续单位时长内可写入量WS=0。最后,对同样的参数进行更新;具体为:将起始已消耗P/E次数更新为当前已消耗P/E次数;将起始主控写入量更新为当前的主控写入量;将起始Swap写入量更新为当前的Swap写入量;将起始寿命更新为当前已使用寿命;计时时长清零。之后,循环执行至开始,再次判断是否为首次运行;非首次运行,将当前时刻作为新的计时起点,从所述新的计时起点重新开始计时;判断计时时长是否达到T,即判断从所述新的计时起点开始的所述计时时长是否大于等于从所述新的计时起点开始的T。根据判断结果,循环执行本方法的相应流程。
此处以图9a为例进一步说明,起始以0时刻为计时起点开始计时,在计时时长为t1时(t1<T),增加的主控写入量等于预设阈值N。然后按照本方法的上述流程预测W1和W2,根据W1和W2的比较结果,设置WS。之后,对部分参数进行更新。然后将时刻t1设置为新的计时起点,并重新计算新的计时时长。在从新的计时起点至t2时刻时(T<t2),即从t1时刻开始的新的计时时长为t2-t1时(t2-t1<T),增加的主控写入量等于预设阈值N。然后按照本方法的上述流程预测W1和W2,根据W1和W2的比较结果,设置WS。之后,对部分参数进行更新。然后将t2时刻设置为新的计时起点,并重新计算新的计时时长。在从新的计时起点t2时刻开始直至t2+T时,即从t2时刻开始的新的计时时长达到T时,按照上述流程预测W1和W2,根据W1和W2的比较结果,设置WS。之后,对部分参数进行更新。并循环执行。也就是说,在每次经过循环将当前时刻为新的计时起点后,判断从该新的计时起点开始,是先发生新的计时时长达到T的事件还是先发生增加的主控写入量大于等于N的事件,并根据先发生的事件调用相应的流程执行,执行完后按照上述流程进一步循环执行。具体来说,0至t1对应着第一阶段;以t1为计时起点后,将t1时刻作为0,那么此时0至t2-t1对应着第二阶段;以t2为计时起点后,将t2时刻作为0,那么此时0至T对应着第一周期;以t2+T为计时起点后,将t2+T时刻作为0,那么此时t2+T至t2+2T对应着第二周期。在第一阶段后,将t1时刻作为新的计时起点,之后先发生增加的主控写入量大于等于N的事件,从而产生第二阶段。在第二阶段后,将t2 时刻作为新的计时起点,之后先发生新的计时时长达到T的事件,从而产生第一周期。在第一周期后,将t2+T时刻作为新的计时起点,之后先发生新的计时时长达到T的事件,从而产生第二周期。上述内容以及图9a所示的内容仅为示意性说明,并不限制本申请实施例的范围。本申请实施例一中下一个阶段的单位时长与上一个阶段的单位时长相同。比如,上一个阶段的单位时长为1天,则下一个阶段的单位时长也为1天。
上述单位时长可以为若干分钟、若干小时、若干日、若干月、若干年等。上述单位时长的具体值和单位都可以根据需要由移动设备的生产厂家预先自行设置。该方法还可以为上述单位时长提供默认值,比如1天。移动设备的生产厂家可以根据需要选择设置其他值。另外,在移动设备出厂之前,移动设备的生产厂家还可以修改上述默认值。若上述的理想使用寿命、当前已使用寿命、起始寿命的单位与上述单位时长的单位不一致,则还需进行单位之间的转换。
另外,本申请实施例一中判断是否首次运行,可以采用以下方式:记录累计已运行的时长,如果检测到累计已运行时长为0,则表明本次是首次运行;反之,则表明本次不是首次运行。或者,预先记录一个表明首次运行的状态值,该状态值在首次运行时为某个特定值,比如0;在运行时检测当前状态值,如果当前状态值为上述特定值0,则表明本次是首次运行;反之,则表明本次不是首次运行。
本申请实施例一根据主控写入、Swap写入的上一个预设周期或上一个阶段的数据,预测主控后续的写入放大因子WAF,提升了WAF的计算准确度;并根据上述预测的写入放大因子WAF来预测主控后续单位时长内可接受写入量W1,进而提升了主控后续单位时长内可接受写入量W1的预测准确度。此外,还根据主控写入、Swap写入的上一个预设周期或上一个阶段的数据,预测闪存中非Swap分区后续单位时长内的写入量W2。基于预测后的W1和W2的比较结果,控制Swap分区后续单位时长内可写入量,允许或禁止后续对闪存中Swap分区的写入,使得闪存的实际使用寿命尽可能逼近甚至达到理想使用寿命。同时,还可即时响应用户写入闪存的需求。
实施例二
图6示出了本申请实施例二提供的一种闪存交换分区控制方法的流程图。在本申请实施例二中,不再考虑是否出现增加的主控写入量大于等于预设阈值N的情形,只考虑计时时长有没有达到T。如图6所示,移动设备的生产厂家预先设置好周期T,不再预先设置阈值N。本申请实施例二中,该方法开始后,首先判断是否为首次运行。若为首次运行,则将起始主控写入量、起始Swap写入量和起始寿命初始化为0,将起始已消耗P/E次数初始化为闪存已消耗P/E次数;之后,将当前时刻作为计时起点,从该计时起点开始计时。若不为首次运行,则将当前时刻作为计时起点,从该计时起点开始计时。然后,判断计时时长是否达到T。
若计时时长达到T,则检测闪存的磨损,获取包括但不限于闪存的容量、P/E 次数、当前已消耗P/E次数、起始已消耗P/E次数、当前的主控写入量、起始主控写入量、理想使用寿命、当前已使用寿命、起始寿命、当前的Swap写入量和起始Swap写入量的相关参数。具体来说,上述相关参数包括闪存在上一个预设周期的第一参数和当前的第二参数。第一参数包括:容量、P/E次数、理想使用寿命、起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量。或者,所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:容量、P/E次数、理想使用寿命、当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量。或者,所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;所述方法还包括:获取第三参数;所述第三参数包括:容量、P/E次数和理想使用寿命。然后,基于获取的第一参数和第二参数,或者,基于获取的第一参数、第二参数和第三参数,计算增加的主控写入量、写入放大因子WAF和主控剩余的可写入量。其中,相应的计算公式为:增加的主控写入量=当前的主控写入量–起始主控写入量;WAF=容量*(当前已消耗P/E次数–起始已消耗P/E次数)/增加的主控写入量;主控剩余的可写入量=容量*(P/E次数–当前已消耗P/E次数)/WAF。这样,就采用了上一个预设周期所消耗的P/E次数和所增加的主控写入量来计算WAF,并将计算得到的WAF预测为下一个预设周期的WAF。采用上一个预设周期的数据来预测下一个预设周期的WAF,使得对下一个预设周期的WAF的预测更为准确。并且运用上述更为准确的WAF来计算主控剩余的可写入量,从而使得计算得到的上述主控剩余的可写入量更为准确。之后,预测主控在下一个预设周期的单位时长内可接受写入量W1。其中,预测公式为:W1=主控剩余的可写入量/(理想使用寿命/单位时长–当前已使用寿命/单位时长)。这样,由于W1的预测是基于上述更为准确的主控剩余的可写入量,也就使得W1的预测更为准确。然后,预测闪存中非Swap分区下一个预设周期的单位时长内的写入量W2。预测公式为:W2=增加的主控写入量/((当前已使用寿命–起始寿命)/单位时长)–(当前的Swap写入量–起始Swap写入量)/((当前已使用寿命–起始寿命)/单位时长)。之后,判断W1是否大于W2。如果W1大于W2,设置Swap分区下一个预设周期的单位时长内可写入量WS=W1-W2;如果W1小于等于W2,设置Swap分区下一个预设周期的单位时长内可写入量WS=0。这样,就根据预测的闪存中非Swap分区下一个预设周期的单位时长内的写入量W2与主控下一个预设周期的单位时长内可接受写入量W1的大小关系,禁止或者允许对闪存中的Swap分区的写入。即便在允许的情形下,也控制Swap分区下一个预设周期的单位时长内可写入量。此外,由于没有限制对闪存中非Swap分区的写入,所以用户在需要写入闪存时仍可以写入闪存。本申请实施例对闪存中的Swap分区的写入量进行控制,延长了闪存的实际使用寿命。并且,本申请实施例还允许用户即时写入闪存中的非 Swap分区,不影响用户的正常使用。最后,对部分参数进行更新;具体为:将起始已消耗P/E次数更新为当前已消耗P/E次数;将起始主控写入量更新为当前的主控写入量;将起始Swap写入量更新为当前的Swap写入量;将起始寿命更新为当前已使用寿命;计时时长清零。之后,循环执行至开始,再次判断是否为首次运行;非首次运行,将当前时刻作为新的计时起点,从所述新的计时起点重新开始计时;判断计时时长是否达到T,即判断从所述新的计时起点开始的所述计时时长是否大于等于从所述新的计时起点开始的T。根据判断结果,循环执行本方法的相应流程。
若计时时长未达到T,则返回继续判断计时时长是否达到T。根据判断结果,循环执行本方法的相应流程。
此处以图9b为例进一步说明。起始以0时刻为计时起点开始计时。在计时时长为T时,按照本方法的上述流程预测W1和W2。根据W1和W2的比较结果,设置WS。之后,对部分参数进行更新。然后将时刻T设置为新的计时起点,并重新计算新的计时时长。在从新的计时起点至2T时刻时,即从T时刻开始的新的计时时长为T时,按照本方法的上述流程预测W1和W2,根据W1和W2的比较结果,设置WS。之后,对部分参数进行更新。然后将2T时刻设置为新的计时起点,并重新计算新的计时时长。在从新的计时起点2T时刻开始直至3T时,即从2T时刻开始的新的计时时长达到T时,按照上述流程预测W1和W2,根据W1和W2的比较结果,设置WS。之后,对部分参数进行更新。并循环执行。也就是说,在每次经过循环将当前时刻为新的计时起点后,判断从该新的计时起点开始,判断是否发生新的计时时长达到T的事件,若发生了上述事件,则调用相应的流程执行,执行完后按照上述流程进一步循环执行。具体来说,0至T对应着第一周期;以T为计时起点后,将T时刻作为0,那么新的计时体系下的0至T对应着第二周期,即T时刻至2T时刻对应着第二周期;以T为计时起点后,将T时刻作为0,那么新的计时体系下的0至T对应着第三周期,即2T时刻至3T时刻对应着第三周期。上述内容以及图9b所示的内容仅为示意性说明,并不限制本申请实施例的范围。
本申请实施例二中的流程与实施例一中计时时长达到T所对应的流程基本相同,区别仅在于本申请实施例二中是采用了上一个预设周期所消耗的P/E次数和所增加的主控写入量来计算WAF,预测主控在下一个预设周期的单位时长内可接受写入量W1和闪存中非Swap分区下一个预设周期的单位时长内的写入量W2,以及设置Swap分区下一个预设周期的单位时长内可写入量WS;而实施例一中是采用了上一个预设周期或上一个阶段所消耗的P/E次数和所增加的主控写入量来计算WAF,预测主控下一个预设周期或下一个阶段的单位时长内可接受写入量W1和闪存中非Swap分区下一个预设周期或下一个阶段的单位时长内的写入量W2,以及设置Swap分区下一个预设周期或下一个阶段的单位时长内可写入量WS。
本申请实施例二根据主控写入、Swap写入的上一个预设周期的数据,预测 下一个预设周期的写入放大因子WAF,提升了WAF的预测准确度;并根据上述预测的写入放大因子WAF来预测主控下一个预设周期的单位时长内可接受写入量W1,进而提升了主控下一个预设周期的单位时长内可接受写入量W1的预测准确度。此外,还根据主控写入、Swap写入的上一个预设周期的数据,预测闪存中非Swap分区下一个预设周期的单位时长内的写入量W2。基于预测后的W1和W2的比较结果,控制Swap分区下一个预设周期的单位时长内可写入量,使得闪存的实际使用寿命尽可能逼近甚至达到理想使用寿命。同时,还可即时响应用户写入闪存的需求。
在无特别说明的情况下,本申请实施例二涉及的相关内容与本申请实施例一中的相关内容相同。此处不再赘述。
实施例三
图7示出了本申请实施例三提供的一种闪存交换分区控制方法的流程图。在本申请实施例三中,不再考虑计时有没有达到T,只考虑是否出现增加的主控写入量大于等于预设阈值N的情形。如图7所示,移动设备的生产厂家预先设置好阈值N,不再预先设置周期T。设置预设阈值N的目的是用于判断主控写入量的增加值是否达到预设阈值N。预设阈值N可以由移动设备的生产厂家在启动该方法之前,根据需要自行设置。该方法开始后,首先判断是否为首次运行。若为首次运行,则将起始主控写入量、起始Swap写入量和起始寿命初始化为0,将起始已消耗P/E次数初始化为闪存已消耗P/E次数;之后,获取当前的主控写入量和起始主控写入量;并计算增加的主控写入量。增加的主控写入量=当前的主控写入量–起始主控写入量。判断增加的主控写入量是否大于等于预设阈值N。若不为首次运行,也获取当前的主控写入量和起始主控写入量;并计算增加的主控写入量。增加的主控写入量=当前的主控写入量–起始主控写入量。判断增加的主控写入量是否大于等于预设阈值N。
如果增加的主控写入量大于等于预设阈值N,则检测闪存的磨损,获取相关参数。相关参数包括但不限于闪存的容量、P/E次数、当前已消耗P/E次数、起始已消耗P/E次数、当前的主控写入量、起始主控写入量、理想使用寿命、当前已使用寿命、起始寿命、当前的Swap写入量和起始Swap写入量。具体来说,上述相关参数包括闪存在上一个阶段的第一参数和当前的第二参数。第一参数包括:容量、P/E次数、理想使用寿命、起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量。或者,所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:容量、P/E次数、理想使用寿命、当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量。或者,所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap 写入量;所述方法还包括:获取第三参数;所述第三参数包括:容量、P/E次数和理想使用寿命。然后,基于获取的第一参数和第二参数,或者,基于获取的第一参数、第二参数和第三参数,计算增加的主控写入量、写入放大因子WAF和主控剩余的可写入量。其中,增加的主控写入量=当前的主控写入量–起始主控写入量;WAF=容量*(当前已消耗P/E次数–起始已消耗P/E次数)/增加的主控写入量;主控剩余的可写入量=容量*(P/E次数–当前已消耗P/E次数)/WAF。这样,就采用了上一个阶段所消耗的P/E次数和上一个阶段所增加的主控写入量来计算WAF,并将计算得到的WAF预测为下一个阶段的WAF。采用上一个阶段的数据来预测下一个阶段的WAF,使得对下一个阶段的WAF的预测更为准确。此处的阶段对应着从上一个阶段结束至出现增加的主控写入量大于等于预设阈值N的情形。也就是说,出现增加的主控写入量大于等于预设阈值N情形的时刻对应着上一个阶段刚结束。并且运用上述更为准确的WAF来计算主控剩余的可写入量,从而使得计算得到的上述主控剩余的可写入量更为准确。之后,预测主控下一个阶段单位时长内可接受写入量W1。其中,预测公式为:W1=主控剩余的可写入量/(理想使用寿命/单位时长–当前已使用寿命/单位时长)。这样,由于W1的预测是基于上述更为准确的主控剩余的可写入量,也就使得W1的预测更为准确。然后,预测闪存中非Swap分区下一个阶段单位时长内的写入量W2。预测公式为:W2=增加的主控写入量/((当前已使用寿命–起始寿命)/单位时长)–(当前的Swap写入量–起始Swap写入量)/((当前已使用寿命–起始寿命)/单位时长)。之后,判断W1是否大于W2。如果W1大于W2,设置Swap分区下一个阶段单位时长内可写入量WS=W1-W2;如果W1小于等于W2,设置Swap分区下一个阶段单位时长内可写入量WS=0。这样,就根据预测的闪存中非Swap分区下一个阶段单位时长内的写入量W2与主控下一个阶段单位时长内可接受写入量W1的大小关系,禁止或者允许对闪存中的Swap分区的写入。即便在允许的情形下,也控制Swap分区下一个阶段单位时长内可写入量。此外,由于没有限制对闪存中非Swap分区的写入,所以用户在需要写入闪存时仍可以写入闪存。本申请实施例对闪存中的Swap分区的写入量进行控制,延长了闪存的实际使用寿命。并且,本申请实施例还允许用户即时写入闪存中的非Swap分区,不影响用户的正常使用。最后,对部分参数进行更新;具体为:将起始已消耗P/E次数更新为当前已消耗P/E次数;将起始主控写入量更新为当前的主控写入量;将起始Swap写入量更新为当前的Swap写入量;将起始寿命更新为当前已使用寿命。之后,循环执行至开始,再次判断是否为首次运行;非首次运行,获取当前的主控写入量和起始主控写入量;并计算增加的主控写入量。增加的主控写入量=当前的主控写入量–起始主控写入量。判断增加的主控写入量是否大于等于预设阈值N。根据判断结果,循环执行本方法的相应流程。
如果增加的主控写入量小于预设阈值N,则继续获取当前的主控写入量和起始主控写入量,并计算增加的主控写入量以及判断增加的主控写入量是否大于等于预设阈值N。根据判断结果,循环执行本方法的相应流程。
此处以图9c为例进一步说明。计算增加的主控写入量,并判断增加的主控写入量是否大于等于N。其中,起始主控写入量初始化为0;增加的主控写入量=当前的主控写入量–起始主控写入量。增加的主控写入量首次大于等于预设阈值N的时刻为t1。然后按照本方法的上述流程预测W1和W2,根据W1和W2的比较结果,设置WS。之后,对部分参数进行更新,尤其将起始主控写入量更新为t1时刻当前的主控写入量。然后重新计算增加的主控写入量,并判断增加的主控写入量是否大于等于N。在t2时刻时,增加的主控写入量再次等于预设阈值N。然后按照本方法的上述流程预测W1和W2,根据W1和W2的比较结果,设置WS。之后,对部分参数进行更新,尤其将起始主控写入量更新为t2时刻当前的主控写入量。然后重新计算增加的主控写入量,并判断增加的主控写入量是否大于等于N。在t3时刻时,增加的主控写入量又等于预设阈值N。然后按照本方法的上述流程预测W1和W2,根据W1和W2的比较结果,设置WS。之后,对部分参数进行更新,尤其将起始主控写入量更新为t3时刻当前的主控写入量。然后重新计算增加的主控写入量,并判断增加的主控写入量是否大于等于N。在t4时刻时,增加的主控写入量又等于预设阈值N。然后按照本方法的上述流程预测W1和W2,根据W1和W2的比较结果,设置WS。之后,对部分参数进行更新,尤其将起始主控写入量更新为t4时刻当前的主控写入量。之后,进一步计算增加的主控写入量并判断增加的主控写入量是否大于等于N。根据判断结果,按照本方法的上述流程循环执行。具体来说,0至t1对应着第一阶段;t1至t2对应着第二阶段;t2至t3对应着第三阶段;t3至t4对应着第四阶段。上述内容以及图9c所示的内容仅为示意性说明,并不限制本申请实施例的范围。
本申请实施例三中的流程与实施例一中增加的主控写入量大于等于N所对应的流程基本相同,区别仅在于本申请实施例三中是采用了上一个阶段所消耗的P/E次数和所增加的主控写入量来计算WAF,预测主控在下一个阶段的单位时长内可接受写入量W1和闪存中非Swap分区下一个阶段的单位时长内的写入量W2,以及设置Swap分区下一个阶段的单位时长内可写入量WS;而实施例一中是采用了上一个预设周期或上一个阶段所消耗的P/E次数和所增加的主控写入量来计算WAF,预测主控下一个预设周期或下一个阶段的单位时长内可接受写入量W1和闪存中非Swap分区下一个预设周期或下一个阶段的单位时长内的写入量W2,以及设置Swap分区下一个预设周期或下一个阶段的单位时长内可写入量WS。本申请实施例三中下一个阶段的单位时长与上一个阶段的单位时长相同。比如,上一个阶段的单位时长为1天,则下一个阶段的单位时长也为1天。
本申请实施例三根据主控写入、Swap写入的上一个阶段的数据,预测主控下一个阶段的写入放大因子WAF,提升了WAF的计算准确度;并根据上述预测的写入放大因子WAF来预测主控下一个阶段单位时长内可接受写入量W1,进而提升了主控下一个阶段单位时长内可接受写入量W1的预测准确度。此外,还根据主控写入、Swap写入的上一个阶段的数据,预测闪存中非Swap分区下一 个阶段单位时长内的写入量W2。基于预测后的W1和W2的比较结果,控制Swap分区后续单位时长内可写入量,使得闪存的实际使用寿命尽可能逼近甚至达到理想使用寿命。同时,还可即时响应用户写入闪存的需求。
在无特别说明的情况下,本申请实施例二涉及的相关内容与本申请实施例一中的相关内容相同。此处不再赘述。
图8所示为本申请提供的一种移动设备800。示例的,移动设备800包括至少一个处理器801和存储器802。其中,处理器801与存储器802耦合,本申请实施例中的耦合可以是通信连接,可以是电性,或其它的形式。具体的,存储器802用于存储程序指令。处理器801用于调用存储器802中存储的程序指令,使得移动设备800执行本申请实施例一至实施例三中任意一项提供的一种闪存交换分区控制方法中由移动设备800所执行的步骤。应理解,移动设备800可以用于实现本申请实施例一至实施例三中任意一项提供的一种闪存交换分区控制方法,相关特征可以参照上文,此处不再赘述。
本申请提供一种包含指令的计算机程序产品,当所述计算机程序产品在移动设备上运行时,使得所述移动设备执行本申请实施例一至实施例三中任意一项提供的一种闪存交换分区控制方法中由移动设备所执行的步骤。
本申请提供一种计算机可读存储介质,包括指令,当所述指令在移动设备上运行时,使得所述移动设备执行本申请实施例提供的一种闪存交换分区控制方法中由移动设备所执行的步骤。
所属领域的技术人员可以清楚地了解到本申请实施例可以用硬件实现,或硬件与软件的方式实现。当使用硬件与软件实现,可以将上述功能存储在计算机可读介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)或处理器执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:快闪存储器、移动硬盘、只读存储器、随机存取存储器、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本申请实施例的具体实施方式,但本申请实施例的保护范围并不局限于此,任何在本申请实施例揭露的技术范围内的变化或替换,都应涵盖在本申请实施例的保护范围之内。因此,本申请实施例的保护范围应以所述权利要求的保护范围为准。

Claims (11)

  1. 一种闪存交换分区控制方法,应用于包含闪存的移动设备,其特征在于,所述方法包括:
    以当前时刻为计时起点进行计时;
    在满足第一条件或第二条件时,检测所述闪存的磨损,至少获取所述闪存的第一参数和第二参数;至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入;
    所述第一条件为计时时长达到预设周期;所述第二条件为计时时长没有达到预设周期,但增加的主控写入量大于等于预设阈值;所述增加的主控写入量=当前的主控写入量–起始主控写入量;
    所述第一参数包括:容量、P/E次数、理想使用寿命、起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;
    或者,
    所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:容量、P/E次数、理想使用寿命、当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;
    或者,
    所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;所述方法还包括:获取第三参数;所述第三参数包括:容量、P/E次数和理想使用寿命;
    其中,所述理想使用寿命为所述移动设备的生产厂家根据需要预先自行设置;所述容量和所述P/E次数为所述闪存的生产厂家提供的参数;所述主控用于向所述闪存读写数据。
  2. 根据权利要求1所述的闪存交换分区控制方法,其特征在于,
    在所述在以当前时刻为计时起点进行计时之前,所述方法还包括:
    在判断所述方法首次运行时,将起始主控写入量、起始Swap写入量和起始寿命初始化为0,将起始已消耗P/E次数初始化为闪存已消耗P/E次数;
    所述至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入;包括:
    根据所述第一参数和所述第二参数,或者,根据所述第一参数、所述第二参数和所述第三参数,按照如下公式,预测主控后续单位时长内可接受写入量W1和闪存中非Swap分区后续单位时长内的写入量W2,并判断W1和W2的大小关系;
    增加的主控写入量=当前的主控写入量–起始主控写入量;
    WAF=容量*(当前已消耗P/E次数–起始已消耗P/E次数)/增加的主控写 入量;
    主控剩余的可写入量=容量*(P/E次数–当前已消耗P/E次数)/WAF;
    W1=主控剩余的可写入量/(理想使用寿命/单位时长–当前已使用寿命/单位时长);
    W2=增加的主控写入量/((当前已使用寿命–起始寿命)/单位时长)–(当前的Swap写入量–起始Swap写入量)/((当前已使用寿命–起始寿命)/单位时长);
    其中,所述单位时长为所述移动设备的生产厂家根据需要预先自行设置;
    如果W1大于W2,设置所述闪存中Swap分区后续单位时长内可写入量WS=W1-W2;
    如果W1小于等于W2,设置所述闪存中Swap分区后续单位时长内可写入量WS=0。
  3. 根据权利要求2所述的闪存交换分区控制方法,其特征在于,
    在所述设置所述闪存中Swap分区后续单位时长内可写入量WS=W1-W2之后;或者,在所述设置所述闪存中Swap分区后续单位时长内可写入量WS=0之后;所述方法还包括:
    将所述起始已消耗P/E次数更新为所述当前已消耗P/E次数;将所述起始主控写入量更新为所述当前的主控写入量;将所述起始Swap写入量更新为所述当前的Swap写入量;将所述起始寿命更新为所述当前已使用寿命;将所述计时时长清零。
  4. 根据权利要求3所述的闪存交换分区控制方法,其特征在于,在将所述计时时长清零之后,所述方法还包括:
    以当前时刻为计时起点进行计时;
    在满足第一条件或第二条件时,检测闪存的磨损,至少获取所述闪存的第一参数和第二参数;至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入。
  5. 根据权利要求1所述的闪存交换分区控制方法,其特征在于,在判断所述方法首次运行且满足所述第一条件时,
    将起始主控写入量、起始Swap写入量和起始寿命初始化为0,将起始已消耗P/E次数初始化为闪存已消耗P/E次数;
    检测闪存的磨损,至少获取所述闪存的容量、P/E次数、理想使用寿命、起始已消耗P/E次数、起始主控写入量、起始寿命、起始Swap写入量、当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;其中,所述理想使用寿命为所述移动设备的生产厂家根据需要预先自行设置;所述容量和所述P/E次数为所述闪存的生产厂家提供的参数;
    按照如下公式,预测主控后续单位时长内可接受写入量W1和闪存中非Swap分区后续单位时长内的写入量W2,并判断W1和W2的大小关系;
    增加的主控写入量=当前的主控写入量–起始主控写入量;
    WAF=容量*(当前已消耗P/E次数–起始已消耗P/E次数)/增加的主控写 入量;
    主控剩余的可写入量=容量*(P/E次数–当前已消耗P/E次数)/WAF;
    W1=主控剩余的可写入量/(理想使用寿命/单位时长–当前已使用寿命/单位时长);
    W2=增加的主控写入量/((当前已使用寿命–起始寿命)/单位时长)–(当前的Swap写入量–起始Swap写入量)/((当前已使用寿命–起始寿命)/单位时长);
    其中,所述单位时长为所述移动设备的生产厂家根据需要预先自行设置;
    如果W1大于W2,设置所述闪存中Swap分区后续单位时长内可写入量WS=W1-W2;
    如果W1小于等于W2,设置所述闪存中Swap分区后续单位时长内可写入量WS=0;
    将所述起始已消耗P/E次数更新为所述当前已消耗P/E次数;将所述起始主控写入量更新为所述当前的主控写入量;将所述起始Swap写入量更新为所述当前的Swap写入量;将所述起始寿命更新为所述当前已使用寿命;将所述计时时长清零;
    以当前时刻为计时起点进行计时;
    在满足所述第一条件时,检测闪存的磨损,至少获取所述闪存的第一参数和当前的第二参数;至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入。
  6. 一种闪存交换分区控制方法,应用于包含闪存的移动设备,其特征在于,所述方法包括:
    获取当前的主控写入量和起始主控写入量,按照如下公式计算增加的主控写入量;增加的主控写入量=当前的主控写入量–起始主控写入量;
    在增加的主控写入量大于等于预设阈值时,检测闪存的磨损,至少获取所述闪存第一参数和第二参数;至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入;
    所述第一参数包括:容量、P/E次数、理想使用寿命、起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;
    或者,
    所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:容量、P/E次数、理想使用寿命、当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;
    或者,
    所述第一参数包括:起始已消耗P/E次数、起始主控写入量、起始寿命和起始Swap写入量;所述第二参数包括:当前已消耗P/E次数、当前主控写入量、当前已使用寿命和当前Swap写入量;所述方法还包括:获取第三参数;所述第三参数包括:容量、P/E次数和理想使用寿命;
    其中,所述理想使用寿命为所述移动设备的生产厂家根据需要预先自行设置;所述容量和所述P/E次数为所述闪存的生产厂家提供的参数;所述主控用于向所述闪存读写数据。
  7. 根据权利要求6所述的闪存交换分区控制方法,其特征在于,
    在所述获取当前的主控写入量和起始主控写入量之前,所述方法还包括:
    在判断所述方法首次运行时,将起始主控写入量、起始Swap写入量和起始寿命初始化为0,将起始已消耗P/E次数初始化为闪存已消耗P/E次数;
    所述至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入;包括:
    根据所述第一参数和所述第二参数,或者,根据所述第一参数、所述第二参数和所述第三参数;按照如下公式,预测主控后续单位时长内可接受写入量W1和闪存中非Swap分区后续单位时长内的写入量W2;
    WAF=容量*(当前已消耗P/E次数–起始已消耗P/E次数)/增加的主控写入量;
    主控剩余的可写入量=容量*(P/E次数–当前已消耗P/E次数)/WAF;
    W1=主控剩余的可写入量/(理想使用寿命/单位时长–当前已使用寿命/单位时长);
    W2=增加的主控写入量/((当前已使用寿命–起始寿命)/单位时长)–(当前的Swap写入量–起始Swap写入量)/((当前已使用寿命–起始寿命)/单位时长);
    如果W1大于W2,设置所述闪存中Swap分区后续单位时长内可写入量WS=W1-W2;如果W1小于等于W2,设置所述闪存中Swap分区后续单位时长内可写入量WS=0;
    所述单位时长为所述移动设备的生产厂家根据需要预先自行设置。
  8. 根据权利要求7所述的闪存交换分区控制方法,其特征在于,在所述设置所述闪存中Swap分区后续单位时长内可写入量WS=W1-W2之后;或者,在所述设置所述闪存中Swap分区后续单位时长内可写入量WS=0之后;所述方法还包括:
    将所述起始已消耗P/E次数更新为所述当前已消耗P/E次数;将所述起始主控写入量更新为所述当前的主控写入量;将所述起始Swap写入量更新为所述当前的Swap写入量;将所述起始寿命更新为所述当前已使用寿命。
  9. 根据权利要求8所述的闪存交换分区控制方法,其特征在于,
    在将所述起始寿命更新为所述当前已使用寿命之后,所述方法还包括:
    获取当前的主控写入量和起始主控写入量,计算增加的主控写入量;
    在增加的主控写入量大于等于预设阈值时,检测闪存的磨损,至少获取所述闪存第一参数和第二参数;至少根据所述第一参数和所述第二参数得到预测结果;根据所述预测结果,允许或禁止后续对所述闪存中Swap分区的写入。
  10. 一种移动设备,至少包括:存储器、一个或多个处理器以及一个或多个计算机程序;其中所述一个或多个计算机程序被存储在所述存储器中;其特征在 于,所述一个或多个处理器在执行所述一个或多个计算机程序时,使得所述移动设备实现如权利要求1-9中任意一项所述的闪存交换分区控制方法。
  11. 一种计算机可读存储介质,包括指令,其特征在于,当所述指令在如权利要求10所述的移动设备上运行时,使得所述移动设备执行如权利要求1-9中任意一项所述的闪存交换分区控制方法。
PCT/CN2021/072621 2020-01-22 2021-01-19 一种闪存交换分区控制方法及移动设备 WO2021147838A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010075706.X 2020-01-22
CN202010075706.XA CN113157599B (zh) 2020-01-22 2020-01-22 一种闪存交换分区控制方法及移动设备

Publications (1)

Publication Number Publication Date
WO2021147838A1 true WO2021147838A1 (zh) 2021-07-29

Family

ID=76881901

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/072621 WO2021147838A1 (zh) 2020-01-22 2021-01-19 一种闪存交换分区控制方法及移动设备

Country Status (2)

Country Link
CN (1) CN113157599B (zh)
WO (1) WO2021147838A1 (zh)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140317373A1 (en) * 2013-04-19 2014-10-23 Samsung Electronics Co., Ltd. Method and apparatus for managing memory
CN104298615A (zh) * 2014-10-09 2015-01-21 重庆大学 一种存储器交换分区损耗的均衡方法
WO2017136220A1 (en) * 2016-02-01 2017-08-10 Qualcomm Incorporated Flash device lifetime monitor systems and methods

Family Cites Families (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2008225576A (ja) * 2007-03-08 2008-09-25 Ricoh Co Ltd Nand型フラッシュメモリの制御装置
US8601202B1 (en) * 2009-08-26 2013-12-03 Micron Technology, Inc. Full chip wear leveling in memory device
US8832371B2 (en) * 2011-04-04 2014-09-09 Hitachi, Ltd. Storage system with multiple flash memory packages and data control method therefor
KR101404260B1 (ko) * 2011-12-23 2014-06-05 한양대학교 산학협력단 플래시 메모리의 수명 인디케이터를 제공하는 장치 및 장치
KR102165460B1 (ko) * 2013-11-27 2020-10-14 삼성전자 주식회사 전자 장치 및 전자 장치의 메모리 관리 방법
US9928169B2 (en) * 2014-05-07 2018-03-27 Sandisk Technologies Llc Method and system for improving swap performance
CN104156317A (zh) * 2014-08-08 2014-11-19 浪潮(北京)电子信息产业有限公司 一种非易失性闪存的擦写管理方法及系统
CN107908571B (zh) * 2017-10-31 2021-04-20 成都华为技术有限公司 一种数据写入方法、闪存装置及存储设备

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140317373A1 (en) * 2013-04-19 2014-10-23 Samsung Electronics Co., Ltd. Method and apparatus for managing memory
CN104298615A (zh) * 2014-10-09 2015-01-21 重庆大学 一种存储器交换分区损耗的均衡方法
WO2017136220A1 (en) * 2016-02-01 2017-08-10 Qualcomm Incorporated Flash device lifetime monitor systems and methods

Also Published As

Publication number Publication date
CN113157599B (zh) 2023-12-15
CN113157599A (zh) 2021-07-23

Similar Documents

Publication Publication Date Title
WO2021083378A1 (zh) 一种加速应用程序启动的方法及电子设备
CN113704014B (zh) 日志获取系统、方法、电子设备及存储介质
CN114443277A (zh) 内存管理方法、装置、电子设备以及计算机可读存储介质
CN114116191B (zh) 内存冷页的处理方法及电子设备
CN114461588B (zh) 调节预读窗口的方法及电子设备
CN113704205B (zh) 日志存储的方法、芯片、电子设备和可读存储介质
CN110687998A (zh) 一种应用管理方法及装置
WO2022078105A1 (zh) 内存管理方法、电子设备以及计算机可读存储介质
CN114461589B (zh) 读取压缩文件的方法、文件系统及电子设备
CN116055859B (zh) 图像处理方法和电子设备
WO2023051094A1 (zh) 内存回收方法、装置、电子设备及可读存储介质
WO2021147838A1 (zh) 一种闪存交换分区控制方法及移动设备
CN116828100A (zh) 蓝牙音频播放方法、电子设备及存储介质
CN114489469A (zh) 一种数据读取方法、电子设备及存储介质
CN113704209B (zh) 数据共享方法、电子设备及存储介质
CN116048772B (zh) 中央处理单元频率的调整方法、装置和终端设备
CN116684520B (zh) 一种关机方法、电子设备、存储介质及芯片
CN117082165B (zh) 拍照操作方法、终端设备及存储介质
CN113886060B (zh) 压缩内存的方法和装置
CN115529379B (zh) 防止蓝牙音频Track音轨抖动的方法、电子设备及存储介质
CN116723384B (zh) 进程的控制方法、电子设备及可读存储介质
CN116719699B (zh) 总线监听及控制方法、电子设备、芯片及存储介质
CN117130959B (zh) 总线控制方法、电子设备及计算机存储介质
CN114449094B (zh) 管控方法及电子设备、芯片、存储介质
CN116841455A (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: 21744310

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21744310

Country of ref document: EP

Kind code of ref document: A1