Full-disk defragmentation triggering method and related apparatus

By dynamically triggering full-disk defragmentation based on the IO status and lifespan of the UFS device, the problem of lag caused by physical address fragmentation in electronic devices is solved, improving user experience and device performance.

CN121116152BActive Publication Date: 2026-07-24HONOR DEVICE CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HONOR DEVICE CO LTD
Filing Date
2024-06-05
Publication Date
2026-07-24

AI Technical Summary

Technical Problem

Electronic devices may experience lag during operation, and this lag worsens with prolonged use, primarily due to the fragmentation of physical addresses in storage devices.

Method used

Based on factors such as the UFS device's IO status, remaining lifetime, and the time elapsed since the last FDD execution, full disk defragmentation (FDD) is dynamically calculated and triggered to reduce lag. By adjusting the execution frequency and interval of FDD, the lifespan of the storage device is optimized.

Benefits of technology

It reduces lag in electronic devices, improves user experience, extends the lifespan of storage devices, and enhances device operating efficiency and performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121116152B_ABST
    Figure CN121116152B_ABST
Patent Text Reader

Abstract

The full-disk defragmentation triggering method and related device provided by the embodiments of the present application relate to the technical field of terminals. The method comprises the following steps: determining whether to trigger the execution of FDD according to the IO state of the UFS device, the remaining life of the UFS device, and the time interval from the last execution of FDD, and dynamically calculating the interval time required for the next execution of FDD. In this way, the execution of FDD can be triggered on demand according to the state of the UFS device, such as the IO state and the remaining life, so that the freezing of the electronic device can be reduced, and the wear and tear on the UFS device can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of terminal technology, and in particular to a method and apparatus for triggering full disk defragmentation. Background Technology

[0002] With the gradual development of electronic technology, electronic devices are able to perform more and more functions, bringing convenience to users' lives.

[0003] However, electronic devices may experience lag during operation, and the longer a user uses the device, the more noticeable the lag may become, thus reducing the user experience. Summary of the Invention

[0004] The full-disk defragmentation triggering method and related apparatus provided in this application determine whether to trigger FDD execution based on factors such as the I / O state of the UFS device, the remaining lifetime of the UFS device, and the time elapsed since the last FDD execution, and dynamically calculate the interval time required for the next FDD execution. In this way, FDD execution can be triggered on demand based on factors such as the I / O state and remaining lifetime of the UFS device, thereby reducing electronic device lag and mitigating wear and tear on the UFS device's lifespan.

[0005] In a first aspect, embodiments of this application provide a method for triggering full disk defragmentation, the method comprising:

[0006] At the first moment, if the IO degradation of the target storage device is less than the degradation threshold, the target storage device does not perform full defragmentation. The interval between the first moment and the target moment is less than the first time interval, where the target moment is the moment when the target storage device last performed full defragmentation. At the second moment, if the IO degradation of the target storage device is greater than or equal to the degradation threshold, the target storage device does not perform full defragmentation. The interval between the second moment and the target moment is less than the first time interval. At the third moment, if the IO degradation of the target storage device is greater than or equal to the degradation threshold, the target storage device performs full defragmentation. The interval between the third moment and the target moment is greater than or equal to the first time interval. Here, IO degradation is the ratio of the number of long IO delays in the target storage device to the total IO delay of the storage device. The number of long IO delays is the number of IO delays in the storage device that are greater than the second threshold. Thus, based on the IO state of the target storage device and the time elapsed since the last FDD execution, it is determined whether to trigger FDD execution. Furthermore, FDD execution can be triggered on demand according to the actual situation of the target storage device, that is, the frequency of processing physical address fragmentation problems on the device side can be dynamically changed. Dynamically changing the frequency at which the device handles physical address fragmentation can include shortening the frequency of handling physical address fragmentation, extending the frequency of handling physical address fragmentation, or immediately executing FDD, thereby reducing electronic device lag and improving user experience.

[0007] In one possible implementation, the value of the first time interval is updated as the I / O degradation of the target storage device changes. The first time interval is inversely proportional to the I / O degradation, including linear inverse proportionality and exponential inverse proportionality. Thus, when the I / O state of the target storage device is good, the interval required to perform FDD can be appropriately increased to reduce unnecessary FDD executions, reduce computing power, improve the operating efficiency of electronic devices, and reduce unnecessary wear and tear on the UFS device's lifespan due to the appropriate reduction in FDD execution frequency.

[0008] In one possible implementation, the first time interval satisfies the following formula:

[0009] f(x) = k1*x; or f(x) = k2*2^x.

[0010] Where x is the control parameter for the first time interval, and the control parameter is inversely proportional to the IO degradation degree, k1 and k2 are coefficients of the control parameter. In this way, the calculation formula for the first time interval f(x) can be set differently according to the actual situation of the electronic equipment, increasing the flexibility of the implementation method.

[0011] In one possible implementation, the maximum value of the control parameter is a preset value, and the minimum value of the control parameter is related to the remaining lifetime of the target storage device. This minimum value reduces the likelihood of frequent FDD executions due to abnormal I / O states of the target storage device.

[0012] In one possible implementation, the maximum value of the control parameter is a preset value, and the minimum value of the control parameter is related to the remaining lifetime of the target storage device. Within a first remaining lifetime range, the minimum value of the control parameter is the first value; within a second remaining lifetime range, the minimum value of the control parameter is the second value, where the remaining lifetime of the target storage device in the second remaining lifetime range is less than that in the first remaining lifetime range, and the second value is greater than the first value; within a third remaining lifetime range, the minimum value of the control parameter is the third value, where the remaining lifetime of the target storage device in the third remaining lifetime range is less than that in the second remaining lifetime range, and the third value is greater than the second value. Thus, the shorter the remaining lifetime of the target storage device, the longer the minimum FDD interval, allowing for a trade-off between the lifetime and performance of the target storage device. When the remaining lifetime of the target storage device decreases, reducing the execution frequency of FDDs can mitigate the wear and tear on the target storage device.

[0013] In one possible implementation, when the IO degradation degree is greater than or equal to the first IO degradation degree, the control parameter is set to its minimum value. When the IO degradation degree is greater than or equal to the second IO degradation degree, the control parameter is decreased by a fourth value, where the second IO degradation degree is less than the first IO degradation degree. When the IO degradation degree is greater than or equal to the third IO degradation degree, the control parameter is decreased by a fifth value, where the third IO degradation degree is less than the second IO degradation degree and the fifth value is less than or equal to the fourth value. When the IO degradation degree is greater than or equal to the fourth IO degradation degree, the control parameter is increased by a sixth value, where the fourth IO degradation degree is less than the third IO degradation degree. In this way, when the IO degradation degree is greater than or equal to the first IO degradation degree, the control parameter is set to its minimum value instead of 0, thus preventing immediate FDD triggering. This reduces the possibility of frequent FDD triggering due to factors such as target memory device malfunctions, thereby reducing unnecessary wear and tear on device lifespan.

[0014] One possible implementation includes, after the third time step: updating the target time step to the third time step; updating the first time interval to the seventh value; and updating the control parameters based on the IO degradation. Thus, updating the control parameters can be understood as dynamically updating the value of the first time interval again based on the seventh value. This allows FDD detection to be triggered more quickly according to the actual state of the electronic device, enabling the read / write performance of the target storage device to recover promptly, thereby improving the user experience.

[0015] In one possible implementation, before the target storage device performs full disk defragmentation, the following steps are included: determining that the interval between the third time point and the target time point is greater than or equal to a first time interval, setting the time interval flag to an eighth value, where the eighth value indicates that the time interval between the third time point and the last full disk defragmentation meets the first time interval; determining that the IO degradation degree is greater than or equal to the IO degradation degree threshold, setting the IO degradation degree flag to a ninth value, where the ninth value indicates that the IO degradation degree at the third time point is severe; and the target storage device performs full disk defragmentation, including: performing full disk defragmentation when the time interval flag is the eighth value and the IO degradation degree flag is the ninth value. In this way, different values ​​of the IO degradation degree flag can more simply and intuitively identify whether the IO degradation degree has reached the preset IO degradation degree, and different values ​​of the time interval flag can more simply and intuitively identify whether the time interval between the current time and the last FDD trigger time meets the interval required for the next FDD trigger, improving code execution efficiency.

[0016] One possible implementation includes, before the first time step, a fourth time step where the target storage device performs full disk defragmentation, with the interval between the fourth time step and the target time step being greater than or equal to the second time interval. This reduces the likelihood of electronic devices failing to trigger FDD execution due to not meeting the triggering conditions set in the I / O strategy. Furthermore, if a priority is given to determining whether the minimum execution policy is met, an FDD execution command can be promptly sent to the kernel-level FDD driver, reducing unnecessary subsequent conditional judgment steps, saving computing power, and improving the execution efficiency of the electronic device.

[0017] In one possible implementation, before the first time step, the process includes: at the fifth time step, when the IO degradation of the target storage device is greater than or equal to the first IO degradation, the target storage device performs full disk defragmentation, and the interval between the fifth time step and the target time step is greater than or equal to the third time interval. This reduces the frequency of FDD execution by the electronic device when the target storage device malfunctions.

[0018] In one possible implementation, the method further includes: if the remaining lifetime of the target storage device is less than a preset lifetime threshold, then the target storage device will not undergo full disk defragmentation. By considering the remaining lifetime of the target storage device, FDD can be shut down promptly when its remaining lifetime is low, reducing wear and tear on the target storage device and thus extending the lifespan of the electronic device. Furthermore, prioritizing the determination of whether the remaining lifetime of the target storage device is less than the preset lifetime threshold can reduce unnecessary subsequent steps, saving computing power and improving the execution efficiency of the electronic device.

[0019] Secondly, embodiments of this application provide an apparatus for triggering full disk defragmentation. This apparatus can be a terminal device, or a chip or chip system within an electronic device. The apparatus may include a processing unit. The processing unit is used to implement any processing-related method executed by the electronic device in the first aspect or any possible implementation of the first aspect. When the apparatus is an electronic device, the processing unit may be a processor. The apparatus may also include a storage unit, which may be a memory. The storage unit is used to store instructions, and the processing unit executes the instructions stored in the storage unit to cause the electronic device to implement a method described in the first aspect or any possible implementation of the first aspect. When the apparatus is a chip or chip system within an electronic device, the processing unit may be a processor. The processing unit executes the instructions stored in the storage unit to cause the electronic device to implement a method described in the first aspect or any possible implementation of the first aspect. The storage unit may be a storage unit within the chip (e.g., a register, cache, etc.), or a storage unit located outside the chip within the electronic device (e.g., read-only memory, random access memory, etc.).

[0020] For example, a processing unit is used to perform full disk defragmentation.

[0021] In one possible implementation, the value of the first time interval is updated as the I / O degradation of the target storage device changes, and the first time interval is inversely proportional to the I / O degradation.

[0022] In one possible implementation, the first time interval satisfies the following formula:

[0023] f(x) = k1*x; or f(x) = k2*2^x.

[0024] Where x is the control parameter for the first time interval, and the control parameter is inversely proportional to the IO degradation degree, and k1 and k2 are both coefficients of the control parameter.

[0025] In one possible implementation, the maximum value of the control parameter is a preset value, and the minimum value of the control parameter is related to the remaining lifetime of the target storage device.

[0026] In one possible implementation, the remaining lifetime of the target storage device is within a first remaining lifetime range, and the minimum value of the control parameter is a first value; the remaining lifetime of the target storage device is within a second remaining lifetime range, and the minimum value of the control parameter is a second value, wherein the remaining lifetime of the target storage device within the second remaining lifetime range is less than the remaining lifetime of the target storage device within the first remaining lifetime range, and the second value is greater than the first value; the remaining lifetime of the target storage device is within a third remaining lifetime range, and the minimum value of the control parameter is a third value, wherein the remaining lifetime of the target storage device within the third remaining lifetime range is less than the remaining lifetime of the target storage device within the second remaining lifetime range, and the third value is greater than the second value.

[0027] In one possible implementation, when the IO degradation degree is greater than or equal to the first IO degradation degree, the control parameter is set to its minimum value; when the IO degradation degree is greater than or equal to the second IO degradation degree, the control parameter is decreased by a fourth value, and the second IO degradation degree is less than the first IO degradation degree; when the IO degradation degree is greater than or equal to the third IO degradation degree, the control parameter is decreased by a fifth value, and the third IO degradation degree is less than the second IO degradation degree, and the fifth value is less than or equal to the fourth value; when the IO degradation degree is greater than or equal to the fourth IO degradation degree, the control parameter is increased by a sixth value, and the fourth IO degradation degree is less than the third IO degradation degree.

[0028] In one possible implementation, the processing unit is used to update the target time to the third time; it is also used to update the first time interval to the seventh value; and specifically, it is used to update the control parameters based on the IO degradation degree.

[0029] In one possible implementation, the processing unit is configured to determine that the interval between the third time moment and the target time moment is greater than or equal to the first time interval, and set the time interval flag to the eighth value; it is also configured to determine that the IO degradation degree is greater than or equal to the IO degradation degree threshold, and set the IO degradation degree flag to the ninth value; specifically, it is also configured to perform full disk defragmentation when the time interval flag is the eighth value and the IO degradation degree flag is the ninth value.

[0030] In one possible implementation, the processing unit performs full disk defragmentation at the fourth time step, and the interval between the fourth time step and the target time step is greater than or equal to the second time interval.

[0031] In one possible implementation, the processing unit performs full disk defragmentation at a fifth time step when the IO degradation of the target storage device is greater than or equal to the first IO degradation. The interval between the fifth time step and the target time step is greater than or equal to the third time interval.

[0032] In one possible implementation, the target storage device does not perform full disk defragmentation if the remaining lifetime of the target storage device is less than a preset lifetime threshold.

[0033] Thirdly, embodiments of this application provide an electronic device including one or more processors and a memory, the memory being coupled to one or more processors, the memory being used to store computer program code, the computer program code including computer instructions, and one or more processors being used to invoke the computer instructions to perform the method described in the first aspect or any possible implementation of the first aspect.

[0034] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program or instructions that, when executed on a computer, cause the computer to perform the methods described in the first aspect or any possible implementation thereof.

[0035] Fifthly, embodiments of this application provide a computer program product including a computer program, which, when run on a computer, causes the computer to perform the methods described in the first aspect or any possible implementation of the first aspect.

[0036] Sixthly, this application provides a chip or chip system including at least one processor and a communication interface. The communication interface and the at least one processor are interconnected via a circuit. The at least one processor is used to run computer programs or instructions to perform the methods described in the first aspect or any possible implementation of the first aspect. The communication interface in the chip can be an input / output interface, pins, or circuits, etc.

[0037] In one possible implementation, the chip or chip system described above in this application further includes at least one memory storing instructions. The memory can be an internal storage unit of the chip, such as a register or cache, or it can be a storage unit of the chip itself (e.g., read-only memory, random access memory, etc.).

[0038] It should be understood that the second to sixth aspects of this application correspond to the technical solutions of the first aspect of this application, and the beneficial effects achieved by each aspect and the corresponding feasible implementation are similar, and will not be repeated here. Attached Figure Description

[0039] Figure 1 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application;

[0040] Figure 2 A schematic diagram of the software structure of an electronic device provided in an embodiment of this application;

[0041] Figure 3 A schematic diagram of physical address fragmentation provided in this application embodiment;

[0042] Figure 4 This is a schematic diagram illustrating a fragmentation process provided in an embodiment of this application;

[0043] Figure 5 A flowchart for executing an FDD is provided as an embodiment of this application;

[0044] Figure 6 A schematic diagram illustrating I / O latency statistics at trace points, provided as an embodiment of this application;

[0045] Figure 7 This application provides an overall flowchart of a full disk defragmentation triggering method.

[0046] Figure 8 A hierarchical diagram illustrating a full disk defragmentation triggering method provided in an embodiment of this application;

[0047] Figure 9 This application provides a schematic diagram of the module interaction of a full disk defragmentation triggering method.

[0048] Figure 10 A schematic diagram illustrating the change in IO latency before and after triggering FDD, provided as an embodiment of this application;

[0049] Figure 11 A schematic diagram illustrating a full disk defragmentation triggering method provided in an embodiment of this application;

[0050] Figure 12 This is a schematic diagram of the structure of a chip provided in an embodiment of this application. Detailed Implementation

[0051] To facilitate a clear description of the technical solutions in the embodiments of this application, some terms and technologies involved in the embodiments of this application will be briefly introduced below:

[0052] 1. Terminology

[0053] In the embodiments of this application, terms such as "first" and "second" are used to distinguish identical or similar items with substantially the same function and purpose. For example, "first chip" and "second chip" are used only to distinguish different chips and do not limit their order of execution. Those skilled in the art will understand that terms such as "first" and "second" do not limit the quantity or execution order, and that "first" and "second" do not necessarily imply that they are different.

[0054] It should be noted that, in the embodiments of this application, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design scheme described as "exemplary" or "for example" in this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.

[0055] In this application embodiment, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, a--c, bc, or abc, where a, b, and c can be single or multiple.

[0056] 2. FDD: Full disk defragmentation (FDD) is a joint hardware and software technology proposed by electronic device manufacturers and universal flash storage (UFS) device manufacturers. UFS device manufacturers provide the device-side full disk defragmentation capability, while electronic device manufacturers provide the device-side triggering capability. This capability can defragment the entire UFS device, including data written to the UFS device and internal data, allowing electronic devices to perform full disk defragmentation after prolonged use, thereby improving file read and write performance.

[0057] 3. Logical address and physical address

[0058] In electronic devices, file storage can include a file system layer and a storage device layer. In the file system layer, files are stored as logical block addresses (LBAs), or simply logical addresses. In the storage device layer, files are stored as physical block addresses (PBAs), or simply physical addresses. The mapping relationship from LBA to PBA can be recorded in a logical-to-physics (L2P) table within the storage device.

[0059] 4. Physical address fragmentation: refers to the non-contiguous or free space between physical block addresses in the storage device layer.

[0060] 5. Dirty segment: In universal flash storage (UFS) devices, a dirty segment refers to a storage segment that has been written to but not yet erased. UFS devices manage data in units of storage segments, and each storage segment typically contains multiple pages.

[0061] It is understandable that when the data of the PBA corresponding to a segment of LBA in an electronic device is no longer needed, the file system can issue an unmap command to the UFS device. Based on the unmap command, the UFS device can mark the data of that segment of PBA as a dirty segment.

[0062] When data is written to a UFS device, the write operation allocates space in one or more storage segments to store the data. Some pages in these segments may have been written with new data, while others may still contain old data. This means that some pages in the storage segment have become dirty because they contain old data that needs to be updated or deleted. The UFS device cannot directly overwrite or update pages in a dirty segment before erasing it. Instead, a specific erase operation is required to clear the entire storage segment and mark it as free so that new data can be written to it.

[0063] Understandably, to optimize performance and improve the efficiency of erase and write operations, UFS devices typically employ a technique called wear-leveling. In a possible implementation, to distribute erase and write operations evenly, avoid excessive erasure of the same memory segment, and extend device lifespan, UFS devices may select younger blocks when writing data. Younger blocks can be understood as blocks with fewer erase / write cycles, while older blocks can be understood as blocks with more erase / write cycles. This can result in a situation where some data written by the UFS device is in older blocks and some in younger blocks, causing contiguous data in the LBA to be discontinuous in the PBA.

[0064] It should be noted that in the embodiments of this application, "device dirty" can be used to indicate that the device has a large number of dirty segments. It is understood that when a device becomes dirty, there will be more background operations on the device, such as requiring more data transfer operations, which will have a certain impact on IO performance. When the device has a very large number of dirty segments, it can be referred to as "device highly dirty," "device-side highly dirty," "highly dirty device," or "device-side highly dirty," etc.

[0065] 6. SCSI layer I / O requests

[0066] Input / output (I / O) requests at the Small Computer System Interface (SCSI) layer are used for data interaction and control with UFS devices. I / O requests allow electronic devices to send commands to UFS devices to perform operations such as reading, writing, positioning, and erasing, and to communicate and control the UFS devices.

[0067] 7. SCSI Layer I / O Latency: This refers to the time delay required to perform an I / O operation. It measures the time elapsed from when the electronic device issues an I / O request to when the UFS device completes the I / O operation. Understandably, lower latency means that the I / O operation can be completed faster, while higher latency means increased delay in the I / O operation.

[0068] 8. Long IO Latency: This refers to IO latency that is greater than a preset latency, and is simply called long IO. In this embodiment, long IO can also be used to represent the IO latency of completing a single SCSI layer IO request that is greater than the preset latency. The preset latency can be set by the electronic device based on experience. For example, the preset latency may include 16 microseconds (µs). The specific value of the preset latency is not limited in this embodiment.

[0069] 9. IO Degradation: This refers to the ratio of long IO delays (IO delays exceeding the preset delay) to the total number of IO delays. The unit is parts per million (ppm), where 1 ppm represents one part per million.

[0070] 10. FDD Interval Time: This refers to the time interval required between two FDD operations.

[0071] 11. Electronic equipment

[0072] The electronic devices in this application embodiment can also be any form of terminal device. For example, electronic devices may include: mobile phones, tablet computers, handheld computers, laptops, mobile internet devices (MIDs), wearable devices, virtual reality (VR) devices, augmented reality (AR) devices, wireless terminals in industrial control, wireless terminals in self-driving, wireless terminals in remote medical surgery, wireless terminals in smart grids, wireless terminals in transportation safety, wireless terminals in smart cities, wireless terminals in smart homes, cellular phones, cordless phones, session initiation protocol (SIP) phones, wireless local loop (WLL) stations, personal digital assistants (PDAs), handheld devices with wireless communication capabilities, computing devices or other processing devices connected to a wireless modem, in-vehicle devices, wearable devices, electronic devices in 5G networks, or future evolved public land mobile communication networks (PLANs). The embodiments of this application do not limit the scope of electronic devices in a mobile network (PLMN).

[0073] By way of example and not limitation, in this embodiment, the electronic device can also be a wearable device. Wearable devices, also known as wearable smart devices, are a general term for devices that utilize wearable technology to intelligently design and develop everyday wearables, such as glasses, gloves, watches, clothing, and shoes. Wearable devices are portable devices that are worn directly on the body or integrated into the user's clothing or accessories. Wearable devices are not merely hardware devices, but also achieve powerful functions through software support, data interaction, and cloud interaction. Broadly speaking, wearable smart devices include those that are feature-rich, large in size, and can achieve complete or partial functions without relying on a smartphone, such as smartwatches or smart glasses, as well as those that focus on a specific type of application function and require the use of other devices such as smartphones, such as various smart bracelets and smart jewelry for vital sign monitoring.

[0074] Furthermore, in this application embodiment, the electronic device can also be an electronic device in the Internet of Things (IoT) system. IoT is an important part of the future development of information technology. Its main technical feature is to connect objects to the network through communication technology, thereby realizing an intelligent network of human-machine interconnection and object-to-object interconnection.

[0075] The electronic equipment in the embodiments of this application may also be referred to as: user equipment (UE), mobile station (MS), mobile terminal (MT), access terminal, user unit, user station, mobile station, mobile station, remote station, remote terminal, mobile device, user terminal, terminal, wireless communication equipment, user agent, or user device, etc.

[0076] In this embodiment, the electronic device or various network devices include a hardware layer, an operating system layer running on top of the hardware layer, and an application layer running on top of the operating system layer. The hardware layer includes hardware such as a central processing unit (CPU), a memory management unit (MMU), and memory (also called main memory). The operating system can be any one or more computer operating systems that implement business processing through processes, such as Linux, Unix, Android, iOS, or Windows. The application layer includes applications such as browsers, address books, word processing software, and instant messaging software.

[0077] For example, Figure 1 A schematic diagram of the electronic device is shown.

[0078] The electronic device may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0079] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device. In other embodiments of this application, the electronic device may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may include hardware, software, or a combination of software and hardware.

[0080] Processor 110 may include one or more processing units, such as application processors (APs), modem processors, graphics processing units (GPUs), image signal processors (ISPs), controllers, video codecs, digital signal processors (DSPs), baseband processors, and / or neural network processing units (NPUs). These different processing units may be independent devices or integrated into one or more processors. The controller can generate operation control signals based on instruction opcodes and timing signals to control instruction fetching and execution.

[0081] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can directly retrieve it from the aforementioned memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system. For example, in the embodiments of this application, the processor 110 can be used to detect whether the FDD has reached the trigger condition, obtain system attributes, determine whether to execute the FDD process, etc.

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

[0083] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a limitation on the structure of the electronic device. In other embodiments of this application, the electronic device may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.

[0084] Internal memory 121 can be used to store computer executable program code, including instructions. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function, etc. The data storage area may store data created during the use of the electronic device, etc. Furthermore, internal memory 121 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, UFS device, etc. Processor 110 executes various functional applications and data processing of the electronic device by running instructions stored in internal memory 121 and / or instructions stored in memory disposed in the processor. For example, in this embodiment, internal memory 121 may be used to store code related to garbage collection (GC) and FDD processes, etc.

[0085] Figure 2 This is a software structure block diagram of an electronic device according to an embodiment of this application. The layered architecture divides the software into several layers, each with a clear role and function. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into five layers, from top to bottom: the application layer, the application framework layer, the Android runtime and system libraries, and the kernel layer.

[0086] The application layer, also known as the application layer, can include a series of application packages. For example... Figure 2 As shown, the application package can include applications such as phone, music, calendar, camera, games, notes, and video. Applications can include system applications and third-party applications.

[0087] The application framework layer, also known as the framework layer, provides application programming interfaces (APIs) and programming frameworks for applications in the application layer. The framework layer can include some predefined functions.

[0088] like Figure 2 As shown, the Framework layer may include the StorageManager module and the StorageManagerService, etc.

[0089] In this embodiment, the storage manager can interact with the application layer and provide relevant interfaces to the application layer; the storage manager can also interact with the storage management service to implement storage-related functions.

[0090] The storage management service can determine whether an electronic device meets the conditions for triggering garbage collection (GC), and it can also detect whether the current electronic device meets the conditions for triggering file-driven decision-making (FDD). If so, it can be responsible for triggering the FDD logic, i.e., when to trigger FDD. In addition, this storage management service module can also dynamically register to listen for screen-on broadcasts and screen-off broadcasts.

[0091] For example, when the conditions for triggering FDD execution are met, the storage management service can call a function to start a scheduled task, communicate with the Native layer through a binder mechanism, and call the interface provided by the target process in the Native layer to execute specific business logic. The interface provided by this target process is the interaction interface between the Framework layer and the Native layer, and can be used to receive notifications from the Framework layer.

[0092] It is understandable that the Framework layer may also include an activity manager, window manager, resource manager, notification manager, content provider, and view system, etc. For details, please refer to the relevant technologies, which will not be elaborated here.

[0093] The Android runtime consists of core libraries and a virtual machine. The Android runtime is responsible for the control and management of the Android system.

[0094] The core library consists of two parts: one part is the functionalities that need to be called by the Java language, and the other part is the Android core library.

[0095] The application layer and framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and framework layer as binary files. The virtual machine is used to perform functions such as object lifecycle management, stack management, thread management, security and exception management, and garbage collection. For example, in the embodiments of this application, the virtual machine can be used to query the execution status of FDD, enable or disable FDD functionality, etc.

[0096] The system library, also known as the native layer, can include multiple functional modules, such as the target process, one or more non-target processes, and function libraries.

[0097] In this embodiment, the target process can be responsible for the business logic of FDD and the encapsulation of data; that is, the target process can decide whether to perform FDD optimization. For example, the interface provided by the target process can call the function that runs the device GC, and further, the function that runs the device GC can call the function that runs the FDD process of the device GC to detect whether the current state of the electronic device meets the conditions for executing FDD, and update the interval time required for the next execution of FDD.

[0098] For example, if the conditions for executing FDD are met, the target process can send the execution command to the kernel-level FDD driver through the virtual file system (systemfile system, sysfs).

[0099] The media library supports playback and recording of various common audio and video formats, as well as still image files. It supports multiple audio and video encoding formats, such as MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG.

[0100] The function library provides developers with API interfaces for various services, making it easy for them to quickly integrate and implement various functions.

[0101] The graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.

[0102] The kernel layer is the layer between hardware and software. The kernel layer can include FDD drivers, display drivers, camera drivers, etc.

[0103] In this embodiment, the FDD driver can be responsible for executing logic; that is, the FDD driver can respond to commands issued by the Native layer and further issue commands to the UFS device. The FDD driver can also check whether the format of the issued commands conforms to the protocol format and detect whether the interaction with the UFS device has been completed.

[0104] It is understandable that the software architecture of electronic devices may also include other layers, such as the hardware adaptation layer (HAL), etc. For details, please refer to the relevant technologies, which will not be elaborated here.

[0105] It should be noted that the embodiments of this application are only illustrated using the Android system. In other operating systems (such as Windows system, iOS system, etc.), as long as the functions implemented by each functional module are similar to those in the embodiments of this application, the solution of this application can also be implemented.

[0106] During the operation of electronic devices, lag may occur, and the longer the user uses the device, the more noticeable the lag may become. One possible reason for this is the fragmentation of physical addresses of data within the electronic device's storage.

[0107] The storage devices may include UFS devices, etc. For ease of description, UFS devices will be used as an example in the following explanation.

[0108] Physical address fragmentation can be caused by the discontinuous allocation of data blocks resulting from file creation, deletion, and / or modification operations; or by the discontinuous distribution of physical blocks due to erase and / or write operations on UFS devices. For example, asynchronous update strategies of log file systems in electronic devices, frequent deletion and writing of various applications and / or files, alternating writes between different processes, and limited remaining contiguous space in the UFS device can all lead to physical address fragmentation.

[0109] For example, Figure 3 A schematic diagram of physical address fragmentation is shown.

[0110] In some scenarios, the software part or software framework of electronic devices can also be referred to as the host, and UFS devices can also be referred to as the device or device side.

[0111] like Figure 3 As shown in Figure a, the file system on the host side can include file A, which can exist in LBA format on the host side. File A can include 1-6 pages, and the LBAs of pages 1-6 can be consecutive or non-consecutive. On the device side, file A can exist in PBA format, and the PBAs of pages 1-6 of file A can be consecutive or non-consecutive.

[0112] Taking a file A where pages 1-6 have consecutive LBAs and PBAs as an example, when related data in file A is deleted or updated, the PBAs of pages 1-6 may become discontinuous on the device. For example... Figure 3 As shown in b, when page 4 of file A is deleted on the host side, and pages 2 and 5 are updated, on the device side, pages 2 and 5 of file A are stored in new data blocks, while the old data blocks become fragments and are marked as dirty. For example, the old data blocks corresponding to the original pages 2, 4, and 5 will be marked as dirty.

[0113] Then, the garbage collection (GC) mechanism transforms these data blocks marked as dirty back into free blocks, thus... Figure 3As shown in Figure c, when a new file B is included on the host side, and writing to file B is required on the device side, pages 8-11 of file B can be written to these available free blocks. Optionally, file A and file B can be the same file or different files. Of course, unavailable data blocks can also be included on the device side.

[0114] Over time, this process leads to a decrease in the physical correlation of data stored on the storage medium in the device. This manifests as logically adjacent data (with contiguous logical addresses LBA) being distributed in different locations on the device, i.e., logical addresses are contiguous, but physical addresses PBA are not, resulting in physical address fragmentation.

[0115] Physical address fragmentation can reduce the efficiency of data read and write operations. This is because when file data blocks are scattered across discontinuous locations on the device, read and write operations need to address and access different physical blocks, increasing addressing time.

[0116] For example, for read operations, the discontinuous distribution of Physical Address Base (PBA) prevents optimal concurrency from being utilized when reading data from the device, leading to decreased read performance. For write operations, such as when the device is at the end of its capacity, it needs to first reclaim dirty segments through garbage collection (GC) to meet the space requirements for writing data before it can write data, resulting in decreased write performance and thus reducing the device's read and write performance. Here, "end of capacity" can be understood as a situation where the available space on the device is small, and the used space on the device is close to the maximum storage capacity of the device.

[0117] When data storage on the device is severely dirty, it frequently triggers processes such as garbage collection (GC) and data migration, increasing the number of background tasks on the device and thus affecting the response of SCSI commands. Furthermore, when physical addresses are distributed discretely, the number and dispersion of L2P table entries within the device increase. Since the device's internal static random access memory (SRAM) has a limited size, the number of L2P table entries that can be loaded at one time is also limited. Therefore, frequent loading of the L2P table also generates significant latency.

[0118] Table 1 below shows a speed comparison of sequential reads and sequential writes before (Clean) and after (Dirty) fragmentation.

[0119] For example, Table 1 shows the test results of sequential read and sequential write operations before and after fragmentation on a certain chip platform. Taking a chip platform with 8 cores (i.e., 8 CPUs) as an example, since the frequency of each CPU may be different, this embodiment of the application locks the frequency of each CPU to its maximum point during testing to prevent frequency fluctuations, thus obtaining more accurate test results. Furthermore, this embodiment of the application uses 8 threads when testing sequential read and sequential write operations, allowing each CPU to run one thread. Therefore, this test scenario can be simply referred to as CPU frequency locking with 8 threads.

[0120] Table 1 also includes test scenarios where the device is at the capacity limit, with 1% of storage space remaining, and 100 target test files, each 128 MB. The capacity limit is only applied to the fragmented device, ensuring more thorough file fragmentation. The 100 target test files can be created using the Flexible I / O tester (FIO) tool, which assists in testing the device's I / O, storage, and other performance characteristics.

[0121] Understandably, in a laboratory setting, where the device is at the lower end of its capacity and files are highly fragmented, the speed of both sequential reads and writes on the device will decrease due to factors such as physical address fragmentation and the presence of numerous background tasks caused by device dirtiness. "Clean" can be understood as a scenario where the device is not at the lower end of its capacity and no fragmentation has been implemented.

[0122] As shown in Table 1, before fragmentation, the sequential read speed was around 3000 MB / s, and the sequential write speed was around 1600 MB / s. After fragmentation, the sequential read speed was around 1000 MB / s, and the sequential write speed was around 400 MB / s. In other words, before fragmentation, the sequential read and write speeds were relatively fast, while after fragmentation, the sequential read and write speeds were relatively slow.

[0123] As can be seen from the data in Table 1, compared to before fragmentation, the speed of both sequential reads and sequential writes on the device decreased after fragmentation. The decrease in sequential read speed was approximately 3 times, and the decrease in sequential write speed was approximately 4 times. This decrease can be calculated by dividing the speed before fragmentation by the speed after fragmentation, i.e., the decrease can satisfy the following formula:

[0124] Decrease factor = Clean / Dirty.

[0125] Optionally, the reduction factor can also be calculated in other ways. For example, the calculation method of the reduction factor can also include (Clean-Dirty) / Dirty, or (Clean-Dirty) / Clean, etc. The embodiments of this application are not limited.

[0126] It is understood that the data in Table 1 is exemplary data. Table 1 is used to show that after fragmentation, the speed of sequential read and sequential write on the device side has decreased compared with that before fragmentation. This trend is consistent with the trend obtained from laboratory test data.

[0127] Table 1

[0128]

[0129] Table 2 below shows a comparison of application cold start latency before (Clean) and after (Dirty) fragmentation.

[0130] For example, Table 2 shows the test results of cold start time for 10 applications before and after fragmentation on a certain chip platform. These 10 applications can be any 10 applications in the electronic device, such as frequently used applications. The specific applications selected are not limited in this embodiment. Application cold start can be understood as the system creating a new process for the application to run when it starts, since the application's corresponding process is not running in the background.

[0131] Understandably, in a laboratory setting, where half the device capacity remains and the other half is highly dirty (this can be achieved through write / delete operations using fragmentation tools), the application cold start latency may result in long I / O operations due to the influence of background tasks on the device.

[0132] As shown in Table 2, before fragmentation, the application cold start time was approximately 1400 milliseconds (ms), while after fragmentation, the application cold start time was approximately 2000 ms. In other words, before fragmentation, the application cold start time was relatively short, while after fragmentation, the application cold start time was relatively long.

[0133] As can be seen from the data in Table 2, the application cold start time increases after fragmentation compared to before fragmentation, with an increase of approximately 40%. This increase can be calculated by dividing the difference between the cold start time after fragmentation and the cold start time before fragmentation by the cold start time before fragmentation; that is, the increase can be expressed by the following formula:

[0134] Increase ratio = (Dirty - Clean / Clean) * 100%.

[0135] Optionally, the increase ratio can also be calculated in other ways. For example, the calculation method of the increase ratio can also include Dirty / Clean, or (Dirty-Clean) / Dirty, etc. The embodiments of this application are not limited.

[0136] It is understood that the data in Table 2 is exemplary data. Table 2 is used to show that the application cold start time increases after fragmentation compared to before fragmentation, and this trend is consistent with the trend obtained from laboratory test data.

[0137] Table 2

[0138]

[0139] Therefore, when the host and device interact with commands, if the physical address fragmentation of the device is severe, the increased physical address fragmentation of the target file or the increased background tasks on the device may increase IO latency, which may lead to a decrease in the read and write performance of the device and cause lag on the host.

[0140] In view of this, the full-disk defragmentation triggering method provided in this application determines whether to trigger FDD execution based on factors such as the I / O state of the UFS device, the remaining lifetime of the UFS device, and the time elapsed since the last FDD execution, and dynamically calculates the interval time required for the next FDD execution. In this way, FDD execution can be triggered on demand based on factors such as the I / O state and remaining lifetime of the UFS device, i.e., dynamically changing the frequency of the device's handling of physical address fragmentation. Dynamically changing the frequency of the device's handling of physical address fragmentation can include shortening the frequency of handling physical address fragmentation, extending the frequency of handling physical address fragmentation, or executing FDD immediately.

[0141] When the IO state of a UFS device deteriorates, the interval required to execute FDD can be shortened or FDD can be executed immediately. This allows the physical address fragments of the data stored in the electronic device and the internal data of the UFS device to be organized in a timely manner, thereby reducing IO latency, improving the read and write performance of the UFS device, reducing electronic device lag, and improving the user experience.

[0142] When the I / O status of the UFS device is good, the interval time required to perform FDD can be appropriately increased to reduce unnecessary FDD execution, reduce computing power, improve the operating efficiency of electronic devices, and reduce unnecessary wear and tear on the lifespan of the UFS device due to the appropriate reduction in the frequency of FDD execution.

[0143] In addition, considering the remaining lifespan of UFS devices, FDD can be turned off in a timely manner when the remaining lifespan of UFS devices is low, reducing the wear and tear on the lifespan of UFS devices and thus extending the service life of electronic devices.

[0144] For example, such as Figure 4 As shown, the device can refresh the corresponding PBA data on the device from low LBA to high LBA, which can also be understood as rewriting the corresponding PBA data on the device. By rearranging the PBA in order, the effect of defragmentation of the entire disk is achieved.

[0145] Understandably, after executing FDD, read and write performance can benefit regardless of whether a single file itself is fragmented.

[0146] On the one hand, if a file has fragmented physical addresses on the device, after performing FDD, the PBA corresponding to the file's LBA is reorganized, and the file will no longer be fragmented, or the degree of fragmentation will be significantly reduced. Since the degree of physical address fragmentation of the file is improved, the file read and write speed can be increased.

[0147] On the other hand, if the file's physical address on the device is not fragmented, when the device becomes dirty, IO latency increases and background operations on the device increase. After performing FDD, the internal device background operations (BKOPS) previously caused by device-side dirt will be reduced. BKOPS can include GC, block erase (BE), block reassignment (BR), and write booster flush (WBflush), etc. In some scenarios, WB flush can also be called write booster flush, write accelerator, or write auxiliary flush. WB flush can be used to write SLC data to TLC. Furthermore, the device's internal L2P table will become contiguous, increasing addressing speed. Therefore, the read and write speed of the file will also be improved.

[0148] In one possible implementation, when an electronic device uses FDD technology, the host can send a trigger command to the device, causing the device to periodically trigger the execution of FDD.

[0149] However, periodically triggering FDD execution cannot be triggered on demand based on the actual state of the host and / or device.

[0150] If the period for triggering FDD execution on the device side is too long, the read and write performance of the device cannot be restored in a timely manner. For example, when the physical address fragmentation rate of an electronic device is high, leading to a decline in IO status and lag, and FDD execution needs to be triggered, the device side may still have to wait a long time, such as a year, before it can be triggered due to the long period for triggering FDD execution. This prevents the timely clearing of physical address fragmentation, thus failing to reduce IO latency, resolve electronic device lag, and degrade the user experience.

[0151] If the FDD execution cycle on the device is too short, FDD may be triggered when the device is in a good state and does not need to be executed, resulting in frequent erase / write operations. Since each FDD execution is equivalent to a full disk erase (program / erase, PE), frequent FDD execution will rapidly reduce the lifespan of the device.

[0152] Therefore, in this embodiment, the decision to trigger FDD execution can also be determined based on factors such as the device's IO status, the device's remaining lifetime, and the time elapsed since the last FDD execution, and the interval time required for the next FDD execution can be dynamically calculated.

[0153] Figure 5 A flowchart for performing an FDD is shown.

[0154] S501. The host obtains whether the UFS device supports full disk defragmentation capability.

[0155] S502, The host determines whether to perform full disk defragmentation.

[0156] Before executing FDD, the host can check whether the device is currently executing FDD.

[0157] If the device is currently executing FDD and the host does not need to issue a command to execute FDD, then the subsequent steps S503 and S504 do not need to be executed.

[0158] If the device is not currently executing FDD, the host can issue a command to execute FDD, and the subsequent step S503 does not need to be executed. In a possible implementation, before issuing the command to execute FDD, the host can query whether FDD is being executed based on the relevant protocols in Table 3 below.

[0159] Understandably, FDD execution has a lower priority than other commands executed on the host side. During FDD execution, if the host side has other commands to execute, such as read or write commands, the FDD execution can be paused on the device side. After the other commands are completed, the FDD can be restarted by the device side. This ensures that FDD execution does not affect the normal business interactions of the electronic device. Therefore, before issuing an FDD execution command, the host side can first check whether the device side is currently executing FDD.

[0160] For example, Table 3 shows a list of protocols used by the host to query the FDD execution status from the device.

[0161] In some scenarios, this protocol list can also be called a specification list. Here, IDN is used to represent a specific register identifier 1; the host can identify the corresponding register through IDN identifier 1. Name is used to represent the attribute corresponding to this specific register, such as the attribute fFDDOperationStatus that identifies the FDD execution status, which can also be called the FDD running status. Type is used to represent the read / write type of this feature, which can include read-only, write-only, read-write, etc. Default Value is used to indicate whether the feature corresponding to this specific register is enabled. For example, a default value of 0 indicates that the feature is disabled, and a default value of 1 indicates that the feature is enabled.

[0162] The execution status of an FDD can include idle, running, interrupted by the host, and completed. For example, if the host queries the Description field and finds a value of 00h, it means the FDD is idle; if the host queries the Description field and finds a value of 01h, it means the FDD is running; if the host queries the Description field and finds a value of 02h, it means the FDD was interrupted by the host; if the host queries the Description field and finds a value of 03h, it means the FDD has completed execution.

[0163] Table 3

[0164]

[0165] S503: The host sends a command to start full disk defragmentation and performs full disk defragmentation.

[0166] On the one hand, when the host decides to perform full disk defragmentation, it can send an FDD enable command to the device, and then the device can execute FDD.

[0167] In a possible implementation, the host can issue an FDD enable command based on the flags (FLAGS) related protocol in Table 4 below.

[0168] In Table 4, IDN is used to represent a specific register identifier 2. The host can identify the corresponding register through the IDN identifier 2. Name indicates the characteristic corresponding to this specific register, such as FDD enable status (fFDDEn). Type indicates the read / write type of this characteristic, which can include read-only, write-only, read-write, etc. Default Value indicates whether the characteristic corresponding to this specific register is enabled. For example, a default value of 0 indicates that the characteristic is disabled, and a default value of 1 indicates that the characteristic is enabled.

[0169] The enabling state of FDD can include FDD off and FDD on. For example, if the host finds a 0b in the Description field of the FLAGS protocol, it means that FDD is off; if the host finds a 1b in the Description field of the FLAGS protocol, it means that FDD is on. In addition, the host can also disable FDD by setting 0b or enable FDD by setting 1b.

[0170] Table 4

[0171]

[0172] On the other hand, after the host successfully sends the FDD start command to the device, the device can send feedback to the host to confirm whether the command was successfully sent. For example, the device can return a message indicating whether the command was successfully sent or failed.

[0173] Optionally, after receiving a message indicating successful command issuance, the host can check the current execution status of the FDD on the device. This allows the host to promptly determine whether the FDD execution has been completed. The host can query the FDD execution status based on the relevant protocols in Table 3 of step S502, which will not be elaborated further.

[0174] S504. Refresh data from low logic address to high logic address and update internal device data. In a possible implementation, the host can periodically trigger FDD detection. For example, the host can trigger FDD detection once or multiple times per day, for example, the detection frequency can be 0 to 4 times per day. It is understood that different host devices can have different FDD detection frequencies, and the specific frequency of triggering FDD detection is not limited in this application embodiment.

[0175] When performing an FDD test, the host can update the interval required for the first or next FDD test based on relevant strategies. These strategies may include one or more of the following: (1) IO status determination strategy, (2) dynamic interval time strategy, (3) lifetime factor strategy, (4) immediate execution strategy, and (5) guaranteed execution strategy.

[0176] (1) IO status determination strategy

[0177] The host can periodically enable SCSI layer command I / O latency statistics to collect data on the I / O latency of all SCSI layer commands and calculate I / O degradation. For example, the host can enable SCSI layer command I / O latency statistics every 6 days. The specific frequency of enabling SCSI layer command I / O latency statistics is not limited in this embodiment.

[0178] In this embodiment, the IO degradation can be used to determine whether FDD detection needs to be maintained, shortened, extended, or performed immediately.

[0179] IO degradation can be obtained based on historical big data statistics reported by electronic devices equipped with UFS devices. It should be understood that different UFS device manufacturers and / or different versions of UFS devices may have different IO degradation levels.

[0180] Analysis of historical big data reveals that when application stuttering occurs—such as stuttering during clicking, swiping, switching, or dragging—the number of long I / O latency spikes will significantly increase, as observed in trace tools. Therefore, when the number of long I / O spikes increases and the I / O degradation exceeds a certain threshold, such as 50 ppm, it can be assumed that the UFS device is dirty, meaning there are many dirty segments of data within the UFS device. Alternatively, it can be assumed that the physical address space of the entire device, or parts thereof, is severely fragmented, leading to a large number of background tasks on the device, which may increase I / O latency.

[0181] Therefore, in order to facilitate the representation of the physical meaning of IO degradation, different levels can be set according to the different specific values ​​of IO degradation.

[0182] For example, as shown in Table 5, the IO degradation level can be set to four different levels, with corresponding status values ​​including GREEN, YELLOW, RED, and CRIMSON.

[0183] The status value GREEN can indicate that the IO status of the device is good, or it can be understood as almost no degradation. The threshold corresponding to the status value GREEN is α, which means that the IO degradation value is in the range of [0ppm, 50ppm).

[0184] The status value YELLOW indicates that the IO status of the device has deteriorated to a certain extent. The threshold corresponding to the status value YELLOW is β, which means that the IO degradation degree is in the range of [50ppm, 100ppm).

[0185] The status value RED indicates that the IO status of the device is severely degraded. The threshold corresponding to the status value RED is γ, which means that the IO degradation value is in the range of [100ppm, 150ppm).

[0186] The status value CRIMSON indicates that the IO status of the device is severely degraded. The threshold corresponding to the status value CRIMSON is δ, which means that the IO degradation value is greater than or equal to 150ppm.

[0187] Table 5

[0188]

[0189] It is understandable that Table 5 can also be set to more or fewer levels. The status value and threshold can be set as other fields, and the corresponding example values ​​can also be divided using other values; this embodiment of the application does not impose any limitations.

[0190] In one possible implementation, to measure SCSI layer I / O request latency, tracepoints can be inserted at the start and end of the I / O request. When the tracepoints are executed, stub functions are triggered to record the start and end times of the I / O request, thereby calculating the time taken to complete one I / O request. In other words, timestamps are added before and after the I / O request is issued at the SCSI layer; by calculating the difference between the timestamps, the latency of the I / O request can be determined.

[0191] During the host boot process, when the kernel initializes the UFS device, it can create the ` / proc / iomeasure / io_scsi_scatter` node to display the device's SCSI layer I / O latency information. The host can obtain I / O latency information by querying this node.

[0192] In a flash-friendly file system (F2FS), commands issued by the SCSI layer to the device can be divided into different chunk sizes, such as 4 kilobytes (kb), 8 kb, 16 kb, 32 kb, 128 kb, and 512 kb. Chunks larger than 512 kb can also be split into smaller chunks; for example, the file system's block layer can break down chunks larger than 512 kb into smaller chunks.

[0193] Based on the different types of IO request commands, they can be divided into: read type commands, write type commands, and other types of commands.

[0194] Other types of commands may include the unmap command. For example, the unmap command issued by the file system can be used to inform the device that a segment of data is no longer needed. For instance, if a segment of LBA corresponds to a PBA, the device can mark the corresponding data, i.e., the data segment containing the PBA, as dirty, so that it can be reclaimed at an appropriate time.

[0195] In this embodiment, the I / O latency can be divided into 12 granularities based on its magnitude: 1µs, 2µs, 4µs, 8µs, 16µs, 32µs, 64µs, 128µs, 256µs, 512µs, 1024µs, and more than 1024µs. Here, 1µs represents an I / O latency less than or equal to 1µs, 2µs represents an I / O latency greater than 1µs but less than or equal to 2µs, and so on. Further details are omitted.

[0196] like Figure 6 The diagram illustrates a method for statistically analyzing I / O latency using trace points. Electronic devices can statistically analyze the occurrence counts of different I / O types at various latency granularities for different block sizes. It should be understood that... Figure 6 The data provided is illustrative. Each of the 12 granularities can correspond to latency statistics for read, write, and other types.

[0197] In this embodiment of the application, the total IO latency may include summing the latency occurrences of each IO type corresponding to each of the 12 granularities.

[0198] Long IO latency can be IO latency greater than 16us. Therefore, the long IO latency count can include the sum of the latency counts for each IO type corresponding to granularities of 16us and greater than 16us.

[0199] Optionally, calculations related to I / O latency or long I / O latency can also be performed using... Figure 6 The maximum latency and / or average latency are calculated, but this application does not limit the specific implementation.

[0200] Optionally, the granularity of the delay can be divided in other ways, such as the granularity can be greater than or less than 12 granularities, which is not limited in the embodiments of this application.

[0201] Because new calculation and statistical statements have been added to the original function logic, the performance on the host side will be degraded, usually by no more than 3%.

[0202] In this embodiment, the electronic device can enable IO latency statistics every n days by obtaining system attributes or reading configuration files. When enabling statistics, the electronic device can calculate the latency of all IO operations within a day. Here, n can be set according to actual needs, and this embodiment does not impose any limitations.

[0203] In one possible implementation of calculating I / O degradation, the host side can disregard I / O type and weights. In this case, the I / O degradation can satisfy the following formula:

[0204] IO degradation = Number of long IO delays / Total number of IO delays.

[0205] Among these, the number of long IO delays is much smaller than the total number of IO delays. In other words, the IO degradation degree calculated by this formula is a very small number. For ease of representation, in some scenarios, the value of this IO degradation degree can be converted to a value in ppm. This application does not limit this.

[0206] In another possible implementation of calculating I / O degradation, the host can distinguish I / O types and assign corresponding weights to different I / O types. In this case, the I / O degradation can satisfy the following formula:

[0207] IO degradation = (Read type long IO latency × Weight) R +Write type long IO latency × Weight W + Other types of long I / O latency × Weight O ) / ((Weight R +Weight W +Weight O () × total I / O latency).

[0208] Among them, Weight R Weight is the weight corresponding to the long I / O latency of read types. W Weight is the weight corresponding to the long I / O latency of the write type. O The weights corresponding to other types of long I / O latency.

[0209] Similarly, the IO degradation degree calculated by this formula can also be converted into a value in ppm, which is not limited in the embodiments of this application.

[0210] In possible implementations, the above IO degradation formula can be modified according to the actual situation. For example, a coefficient can be multiplied or added or subtracted from the above IO degradation formula. This application does not limit the specific implementation.

[0211] It should be noted that the IO degradation level is set in the algorithm program and can be set and updated according to actual needs. For example, depending on the UFS device manufacturer and / or the performance of the UFS device, this embodiment can set different IO degradation levels based on the actual measured long IO latency. The calculated IO degradation level can be used to calculate the interval time required to execute FDD.

[0212] (2) Dynamic interval time strategy

[0213] In this embodiment of the application, the interval for executing FDD may not be fixed; the interval for executing FDD may be dynamically adjusted according to the formula.

[0214] In a possible implementation, the interval for executing FDD can satisfy the following formula:

[0215] f(x) = 10x.

[0216] Where x represents the control parameter that determines the interval time, x can be a dynamically changing parameter, for example, x∈[MIN_X,MAX_X]. MIN_X can represent the minimum interval time for executing FDD, and MAX_X can represent the maximum interval time for executing FDD. For example, if MIN_X is 1 and MAX_X is 36, then x∈[1,36], f(x)∈[10,360]. MIN_X can also be set to a value greater than or less than 1, and MAX_X can also be set to a value greater than or less than 36. The specific values ​​of MIN_X and MAX_X can be set according to the actual situation of the electronic device, and this application embodiment does not limit them.

[0217] Understandably, the existence of the minimum interval MIN_X can reduce the frequent execution of FDD due to abnormal I / O states on the device side.

[0218] In this embodiment of the application, the host can determine whether the current condition for triggering FDD execution has been met based on the time interval, IO degradation degree, and device lifespan. Specifically, it includes (2.1) the condition for not triggering FDD execution and (2.2) the condition for triggering FDD execution.

[0219] (2.1) Cases where FDD execution is not triggered

[0220] For example, if the conditions for triggering FDD execution are not met, x can take different values ​​depending on the degree of IO degradation.

[0221] If the IO degradation is almost non-degraded, that is, when the IO degradation state value is GREEN, x can take the value x+1;

[0222] If the IO degradation is "some degradation", that is, when the IO degradation state value is YELLOW, x can take the value x-1;

[0223] If the IO degradation is severe, i.e., the IO degradation status value is RED, then x can take the value x / 2;

[0224] If the IO degradation is severe, that is, when the IO degradation status value is CRIMSON, x can take the value MIN_X.

[0225] The initial value of x can be preset by the electronic device. For example, the initial value of x can be set to 18, corresponding to an initial FDD execution interval of 180 days, or about half a year. The specific initial value of x can be set differently according to the actual situation of the electronic device, and this application embodiment does not limit it.

[0226] It is understandable that when the I / O status of the device is almost undegraded and the status value is GREEN, it indicates that the current status of the host is good. Therefore, the interval required for the next FDD execution can be appropriately increased.

[0227] When the I / O status of the device deteriorates to a certain extent and the status value is YELLOW, it indicates that the current status of the host is affected by certain factors and begins to deteriorate. Therefore, the interval time required for the next FDD execution can be appropriately reduced.

[0228] When the I / O degradation on the device side is severe and the status value is RED, the interval time can be reduced exponentially, but FDD will not be triggered immediately.

[0229] When the device's I / O performance is severely degraded, and the status value is CRIMSON, it indicates that the device's read / write performance has been severely affected or is about to be severely affected. FDD needs to be triggered promptly to restore the device's read / write performance. In this case, the minimum interval time (MIN_X) should be used instead of 0 to prevent immediate FDD triggering.

[0230] The host will not immediately trigger FDD because: First, the reason for a large number of long I / Os on a given day may not be due to a high overall physical address fragmentation rate on the device, but may be due to other factors, such as high host load, many background tasks, and / or device malfunction. In this case, the I / O state may recover once these factors are eliminated. Second, reducing the possibility of frequent FDD triggers caused by device malfunctions reduces unnecessary wear and tear on device lifespan. Third, the I / O state on the device may be improved by other functions deployed on the host or device.

[0231] (2.2) The conditions that trigger the execution of FDD are met

[0232] For example, when the conditions for triggering FDD execution are met, x can take a default value, such as 9. It should be understood that the default value can be preset by the electronic device, and the default value can also be set to other values. This application embodiment does not limit the specific value of the default value.

[0233] Taking a default value of 9 as an example, it can be understood that after triggering FDD, theoretically there will be almost no fragmentation on the device. Therefore, the host can set the interval to 90 days, or about 3 months, and re-observe. In other words, the value of x can be dynamically updated based on x being 9.

[0234] It should be noted that the above formula for calculating the dynamic interval time of FDD execution is one possible implementation. The specific calculation formula can be set differently depending on the host or device, and this application embodiment does not limit it. For example, the formula for calculating the dynamic interval time of FDD execution can also satisfy the following formula:

[0235] f(x) = 10 * 2^x.

[0236] In a possible implementation, to record the time of the last FDD trigger, the interval required for the next FDD trigger, and the control parameter x that controls the change of the interval, three persistent system properties (SystemProperties) can be added in this embodiment: persist.ufs.fdd.t1, persist.ufs.fdd.t2, and persist.ufs.fdd.x. Wherein, persist.ufs.fdd.t1 can represent the time t1 of the last FDD trigger, persist.ufs.fdd.t2 can represent the interval t2 required for the next FDD trigger, and persist.ufs.fdd.x can represent the control parameter x that determines the change of the interval t2. It should be understood that t1 can be used to calculate the current elapsed time.

[0237] For example, when an FDD detection is triggered on the host side, the algorithm can obtain the value of the system property persist.ufs.fdd.x. Taking an example where x is 36, the FDD trigger condition is not met, and the IO degradation is severe (state value is RED), x can be updated to 18 according to x = x / 2.

[0238] If the IO degradation remains severe, as described earlier, the host can trigger multiple FDD checks per day. Each check updates 'x' regardless of whether FDD is executed. Therefore, 'x' typically decreases to a smaller value within three days. Thus, compared to triggering FDD at fixed intervals, the full-disk defragmentation triggering method of this application allows FDD checks to be triggered more quickly based on the actual state of the host or device, enabling timely recovery of read / write performance on the device and improving user experience.

[0239] (3) Life Factor Strategy

[0240] In this embodiment, the minimum interval time MIN_X is affected by the remaining lifetime of the device.

[0241] In one possible implementation, the host can query the device's lifetime status based on the interfaces exposed by the device. For example, the host can query the proc node defined in the kernel layer ( / proc / bootdevice / life_time_est_typ_a), and then the FDD driver can query the device's registers (DESCRIPTOR IDN=09h, INDEX=00h and SELECTOR=00h) according to the protocol.

[0242] It is understandable that the remaining lifespan of the device can be equal to 100% minus the device's already used lifespan.

[0243] Based on the remaining lifespan of the device, the minimum interval time MIN_X can be set as a piecewise function. For example, the piecewise function can satisfy the following formula:

[0244]

[0245] Where life represents the remaining lifespan of the device.

[0246] Furthermore, when the lifespan is less than 20%, FDD can be disabled. This reduces the wear and tear on the device's lifespan, thereby extending the lifespan of the electronic device. This 20% can also be understood as the minimum lifespan threshold for disabling FDD functionality on the host side.

[0247] When the remaining lifetime of the device is greater than 80%, MIN_X can be set to 1. In the dynamic interval time strategy, the minimum value of the control parameter x can be MIN_X, that is, x can be 1. At this time, f(x) = 10 × 1, that is, f(x) is 10, indicating that the minimum interval time for FDD execution is 10 days.

[0248] When the remaining lifetime of the device is greater than 50% and less than or equal to 80%, MIN_X can be set to 3. Therefore, in the dynamic interval time strategy, the minimum value of the control parameter x can be 3. In this case, f(x) = 10 × 3, that is, f(x) is 30, indicating that the minimum interval time for FDD execution is 30 days.

[0249] When the remaining lifetime of the device is greater than or equal to 20% and less than or equal to 50%, MIN_X can be set to 9. Therefore, in the dynamic interval time strategy, the minimum value of the control parameter x can be 9. At this time, f(x) = 10 × 9, that is, f(x) is 90, indicating that the minimum interval time for FDD execution is 90 days.

[0250] Therefore, the less remaining lifetime the device has, the longer the minimum FDD interval should be. This allows for a trade-off between device lifetime and device performance. When the expected lifetime of the device decreases, reducing the frequency of FDD execution can mitigate the wear and tear on the device. When the remaining lifetime of the device is less than 20%, FDD should be turned off to maximize the usable lifespan of the device.

[0251] It should be noted that in the piecewise function of the minimum interval time MIN_X, the value of MIN_X is set according to the calculation formula of the dynamic interval time of FDD execution, that is, according to the formula f(x) = 10x. For example, MIN_X can be set to a value greater than 0. The specific value of MIN_X can be set according to the actual situation of the electronic device, and this application embodiment does not limit it.

[0252] In a possible implementation, the piecewise function of MIN_X can be set to different values ​​depending on the calculation formula of f(x). For example, when f(x) = 10 * 2^x, to avoid the value of MIN_X being too large and causing the interval for executing FDD to be too long, the piecewise function of MIN_X can satisfy the following formula:

[0253]

[0254] When the remaining lifetime of the device is greater than 80%, MIN_X can be set to 0. In the dynamic interval time strategy, the minimum value of the control parameter x can be MIN_X, that is, x can be 0. At this time, f(x) = 10 * 2^0, that is, f(x) is 10, indicating that the minimum interval time for FDD execution is 10 days.

[0255] When the remaining lifetime of the device is greater than 50% and less than or equal to 80%, MIN_X can be set to 2. In the dynamic interval time strategy, the minimum value of the control parameter x can be 2. At this time, f(x) = 10 * 2^2, that is, f(x) is 40, indicating that the minimum interval time for FDD execution is 40 days.

[0256] When the remaining lifetime of the device is greater than or equal to 20% and less than or equal to 50%, MIN_X can be set to 3. Therefore, in the dynamic interval time strategy, the minimum value of the control parameter x can be 3. At this time, f(x) = 10 * 2^3, that is, f(x) is 90, indicating that the minimum interval time for FDD execution is 90 days.

[0257] Similarly, the less remaining lifetime the device has, the longer the minimum FDD interval, thus allowing for a trade-off between the device's lifetime and the device's performance, which will not be elaborated further.

[0258] It is understood that the lifetime of the device can be further segmented in the segmentation function of MIN_X, and the value of MIN_X can also be set to other values. For example, MIN_X can be set to a value greater than or equal to 0. The specific value of MIN_X can be set according to the actual situation of the electronic device, and this application embodiment does not limit it. In addition, the lifetime factor strategy can also be adopted or not adopted according to the actual situation, and this application embodiment does not limit it.

[0259] In a possible implementation, the host can query the device's lifetime based on the relevant protocols of Device Health Descriptor Table 6 and / or Device Health Descriptor Table 7.

[0260] The offset can be understood as the device's address offset or represented as a device descriptor. The host can query the device's lifetime status based on device descriptor 1 in Table 6 and device descriptor 2 in Table 7. The Name describes the offset. The Value represents the device's lifetime value. The Description explains the possible values ​​for the Value.

[0261] Understandably, Tables 6 and 7 correspond to different device models. After retrieving the results from Tables 6 and 7, the host device can select values ​​with longer lifespans for calculation. This reduces the likelihood of FDD being performed when the device lifespan is very short.

[0262] It is understood that the specific contents in Tables 6 and 7 are exemplary. In fact, Tables 6 and 7 may include more or less information, which is not limited in this application embodiment.

[0263] Table 6

[0264]

[0265] Table 7

[0266]

[0267] (4) Implement the strategy immediately

[0268] In this embodiment of the application, under certain conditions, the host can immediately execute FDD.

[0269] For example, when the IO degradation is severe (status value is CRIMSON), it can be determined whether the current time is greater than or equal to T3 since the last FDD execution. If it is greater than or equal to T3, the host can execute FDD immediately.

[0270] T3 can be used to indicate the minimum interval required to immediately execute FDD. The value of T3 can be preset in the algorithm program by the host. For example, T3 can be set to 10 days, or to f(MIN_X), etc. The specific value of T3 can be set according to the actual situation of the host. This application embodiment does not limit it.

[0271] It should be understood that in mathematics, f(x) is a function with x as its independent variable. f(x) can also represent the result of the independent variable x under the correspondence rule f. For example, f(x) = 10x means that the result of the independent variable x under the correspondence rule f is 10x, and f(x) = 10 * 2^x means that the result of the independent variable x under the correspondence rule f is 10 * 2^x. Correspondingly, f(MIN_X) can represent the result of MIN_X under the correspondence rule f, and f(MAX_X) can represent the result of MAX_X under the correspondence rule f.

[0272] In a possible implementation, the host can read the newly added system property persist.ufs.fdd.t1 to get the time t1 when the FDD was last triggered. The host can also read the current system time to determine whether the difference between the two is greater than T3.

[0273] Understandably, although a minimum interval (T3) is set for executing FDD, the host side can usually meet the conditions for immediate FDD execution. This is because for new electronic devices or those that have triggered FDD, the device's state is usually relatively good or has recovered to a good state. This state can include internal data such as disk fragmentation status and device table entries. For the device's state to deteriorate from good to a certain level, a certain amount of writes is required, which takes time. The host side typically needs several days to accumulate a sufficient amount of writes. Therefore, when the device's IO state deteriorates to a severe state, it indicates that a certain amount of time has passed since the host side was used or the last FDD execution, thus meeting the minimum interval (T3) required for FDD execution.

[0274] The necessity of setting T3 lies in reducing the frequency of FDD executions on the host side when device-side anomalies occur. For example, when T3 is 10, it means a maximum of 36 executions per year. Typically, UFS devices have a lifespan of around 3000 PE cycles. Taking a UFS device with a lifespan of 3000 PE cycles and a usage period of 5 years as an example, under extreme conditions—that is, always satisfying the immediate execution of the FDD strategy—the maximum lifespan attenuation rate of the UFS device could be 36 × 5 / 3000 = 0.06 = 6%. It is understandable that the lifespan attenuation rate of UFS devices is usually less than or much less than 6%. The lifespan attenuation rate of UFS devices can be adjusted by changing the value of T3. For example, when T3 is adjusted to 20, the device's lifespan attenuation rate can be reduced to 3%.

[0275] (5) Guaranteed Execution Strategy

[0276] In this embodiment of the application, when the host has not executed FDD after the longest interval, the host will execute FDD once regardless of the detected IO state, provided that FDD is not turned off.

[0277] The longest interval time refers to the time T4 that has elapsed since the last FDD execution. The value of T4 can be preset in the algorithm program by the host. For example, T4 can be set to 365 days, or T4≥f(MAX_X), etc. The specific value of T4 can be set according to the actual situation of the host. This application embodiment does not limit it.

[0278] In a possible implementation, the host can read the newly added system property persist.ufs.fdd.t1, which represents the time t1 when the FDD was last triggered. The host can also read the current system time to determine whether the difference between the two is greater than T4.

[0279] The necessity of setting this strategy lies in reducing situations where the host fails to trigger FDD execution due to the inability to meet the triggering conditions set in the IO strategy. For example, since the IO latency and other information collected by the host are stored in memory, frequent restarts or factory resets of the host may clear the stored IO latency and other information, thus preventing the triggering conditions set in the IO strategy from being met.

[0280] Figure 7 The overall flowchart of the full disk defragmentation triggering method is shown. The relevant algorithm program for the FDD triggering method can be deployed in the Native layer on the host side.

[0281] S701 and the Framework layer determine that the triggering condition has been met, and call the function interface to perform FDD triggering condition detection.

[0282] like Figure 8 The diagram illustrates the hierarchical structure of the full disk defragmentation triggering method. When the Framework layer determines that the conditions for triggering host-side GC have been met, the Framework layer's StorageManagerService can issue a Socket command, instructing the target process in the Native layer to trigger device-side GC. Conditions for triggering host-side GC can include the host being in a charging and screen-off state for a certain period of time. Based on the upper-layer strategy settings and experimental tests, the Framework layer can trigger FDD trigger condition checks 0 to 4 times per day.

[0283] The target process can be understood as an algorithm program. The target process can call the FDD algorithm program function interface according to the algorithm flow, and the FDD algorithm program can execute step S702 to perform FDD trigger condition detection.

[0284] In a possible implementation, the storage management service module can dynamically register to listen for screen-on and screen-off broadcasts. For example, when the storage management service module receives a screen-on broadcast, it can set the screen-on flag mScreenOn to true to indicate that the current electronic device is in a screen-on state. When the storage management service module receives a screen-off broadcast, it can set the screen-on flag mScreenOn to false to indicate that the current electronic device is in a screen-off state.

[0285] Optionally, the screen-on indicator can also be identified using other fields, such as screenOn. Furthermore, the electronic device can also set a screen-off indicator, such as mScreenOff or screenOff, which is not limited in this application embodiment. It should be understood that this application embodiment does not limit the data type of the screen-on indicator and / or screen-off indicator; the data type can include integer, string, boolean, enumeration, etc.

[0286] When the conditions for triggering FDD execution are met, the target process can send the FDD execution command to the kernel-level FDD driver through the sysfs node created by the kernel driver. FDD trigger condition detection can include: determining whether the current host-side states meet the FDD execution conditions, including I / O status, device lifetime, and / or interval time, etc., to decide whether to send the FDD execution command to the FDD driver, and updating the interval time for the next FDD execution based on the current device-side state.

[0287] Optionally, the conditions for triggering FDD on the device side may also include that the IO statistics node is already open, so that IO statistics can be obtained, and the decision on whether to execute FDD can be made based on the obtained IO statistics.

[0288] S702: The host determines whether the device supports FDD capability and whether the IO statistics node is enabled.

[0289] The host can issue a query command during a preset phase, such as the power-on phase of an electronic device, to determine whether the device currently supports FDD capabilities. For example, the host can query the bits in the dExtendedUFSFeaturesSupport field of a specific register on the device to determine if the device supports FDD capabilities. This specific register can be understood as a register that can be used to query whether the device supports FDD capabilities.

[0290] The host can also determine whether the IO statistics node ( / proc / bootdevice / life_time_est_typ_a) is open. If the query returns -1, it indicates that the IO statistics node is not open; if the query returns 0 or 1, it indicates that the IO statistics node is open. It is understood that this application embodiment does not limit the specific return value of the node, as long as it can distinguish whether the IO statistics node is open or not.

[0291] If the device supports FDD capability and the IO statistics node is enabled, then step S703 can be executed.

[0292] If the device does not support FDD capability, and / or the IO statistics node is not enabled, the process will return and will not continue with the subsequent steps.

[0293] Optionally, the determination of whether the IO statistics node is open can also be performed in the Framework layer, without limitation.

[0294] S703: The host determines whether the device's lifespan is less than the threshold.

[0295] The host can check whether the remaining lifespan of the device is less than the minimum lifespan threshold. For example, the minimum lifespan threshold can be set to 20%, or it can be set to other values; this application embodiment does not limit this.

[0296] If the remaining lifetime of the device is greater than or equal to the minimum lifetime threshold, then proceed to step S704.

[0297] If the remaining lifetime of the device is less than the minimum lifetime threshold, FDD will be disabled, and subsequent steps will not be executed. Specifically, the host can disable FDD by setting the value of the relevant flags (FLAGS) in Table 4 to 0b on the device.

[0298] Understandably, disabling FDD when the remaining lifetime of the device is less than the minimum lifetime threshold can maximize the usable lifetime of the host. Furthermore, prioritizing step S703 to check if the remaining lifetime of the device is less than the minimum lifetime threshold can reduce unnecessary subsequent steps, save computing power, and improve the execution efficiency of the host.

[0299] S704: The host reads system properties and determines whether the FDD interval time meets the minimum execution policy.

[0300] The host can read the system property persist.ufs.fdd.t1 to get the time t1 when the FDD was last triggered, and can also read the current system time. By checking whether the difference between the two is greater than T4, it can be determined whether the FDD interval time meets the minimum execution policy.

[0301] If the FDD interval time meets the minimum execution policy, then step S708 is executed to send an FDD execution command to the FDD driver in the kernel layer.

[0302] If the FDD interval time does not meet the minimum execution strategy, then execute step S705 to obtain the FDD interval time.

[0303] Understandably, since the I / O latency and other information collected on the host are stored in memory, frequent restarts or factory resets on the host may reset this information, preventing the triggering conditions set in the I / O strategy from being met. Therefore, executing step S704 reduces the likelihood of the host failing to trigger FDD execution due to the inability to meet the I / O strategy's conditions. Furthermore, if the minimum execution guarantee strategy is met, an FDD execution command can be sent to the kernel-level FDD driver, reducing unnecessary subsequent steps, saving computing power, and improving host execution efficiency.

[0304] S705: The host reads system properties and obtains the FDD interval times t1 and t2.

[0305] The host can read the system property `persist.ufs.fdd.t1` to get the time `t1` of the last FDD trigger, and read the system property `persist.ufs.fdd.t2` to get the interval `t2` required for the next FDD trigger. The host can also read the current system time to determine whether the time interval between the current time and the last FDD trigger time `t1` meets the interval `t2` required for the next FDD trigger.

[0306] If the time interval between the current time and the last FDD trigger time t1 meets the interval time t2 required for the next FDD trigger, the host can set the variable FLAG_TIME to true; if the time difference does not meet the interval time required for the next FDD trigger, the host can set the variable FLAG_TIME to false; and execute step S806.

[0307] The variable FLAG_TIME can also be represented by other fields. The data type of the variable FLAG_TIME can be set not only to boolean type, but also to integer, string, enumeration and other data types, as long as it can indicate whether the time interval between the current time and the last time t1 of the FDD is sufficient to meet the interval t2 required for the next FDD trigger. This application embodiment does not limit this.

[0308] S706: The host reads the IO status node to obtain the IO degradation level.

[0309] The host can read the IO status node ( / proc / bootdevice / life_time_est_typ_a) to calculate the current IO status, that is, the level of IO degradation.

[0310] If the IO degradation level reaches the preset IO degradation level, the host can set the variable FLAG_IO to true; if the IO degradation level does not reach the preset IO degradation level, the host can set the variable FLAG_IO to false and execute step S707.

[0311] The variable FLAG_IO can also be represented by other fields. The data type of the variable FLAG_IO can be set not only to boolean type, but also to integer, string, enumeration and other data types, as long as it can indicate whether the IO degradation degree has reached the preset IO degradation degree. This application embodiment does not limit it.

[0312] In one possible implementation, the IO degradation level can be determined by checking whether the IO degradation level has reached a preset value.

[0313] For example, taking the preset state value as YELLOW, when the IO degradation state value reaches YELLOW, it means that the IO degradation has reached the preset IO degradation level. The IO degradation state value reaching YELLOW can include any of the following: the IO degradation state value is YELLOW, the IO degradation state value is RED, or the IO degradation state value is CRIMSON.

[0314] It should be understood that the preset state value can also be set to other state values, such as RED or CRIMSON, etc., and this application embodiment does not limit it.

[0315] If the preset state value is RED, then when the IO degradation state value reaches RED, it means that the IO degradation has reached the preset IO degradation level. The IO degradation state value reaching RED can include any of the following: the IO degradation state value is RED, or the IO degradation state value is CRIMSON.

[0316] If the preset status value is CRIMSON, then when the status value of IO degradation is CRIMSON, it means that the IO degradation has reached the preset IO degradation level.

[0317] In another possible implementation, the IO degradation level can be determined by whether the IO degradation level reaches a preset threshold.

[0318] For example, taking a preset threshold of β as an example, when the value of IO degradation is greater than or equal to β, it means that the IO degradation has reached the preset IO degradation level. Here, the value of IO degradation being greater than or equal to β can include any of the following: the value of IO degradation is greater than or equal to β, the value of IO degradation is greater than or equal to γ, and the value of IO degradation is greater than or equal to δ.

[0319] It should be understood that the preset threshold can also be set to other thresholds, such as γ or δ, and this application embodiment does not limit it.

[0320] If the preset threshold is γ, then when the IO degradation value is greater than or equal to γ, it indicates that the IO degradation has reached the preset IO degradation level. The IO degradation value being greater than or equal to γ ​​can include any of the following: the IO degradation value is greater than or equal to γ, or the IO degradation value is greater than or equal to δ.

[0321] If the preset threshold is γ, then when the IO degradation value is greater than or equal to γ, it means that the IO degradation has reached the preset IO degradation level.

[0322] In another possible implementation, the IO degradation level can be determined by whether the IO degradation level is within a preset range.

[0323] For example, taking a preset range of [50ppm, 100ppm) as an example, when the IO degradation value is in the range of [50ppm, 100ppm), it indicates that the IO degradation has reached the preset IO degradation. The preset range can also be set to other ranges, such as [100ppm, 150ppm), [150ppm, ∞), or [50ppm, ∞), etc., and this application embodiment does not limit the specific range.

[0324] S707, Host-side policy determination: Determine whether the execution policy is met, whether the FDD interval time is met, and whether the IO degradation has reached the execution threshold.

[0325] The host can first determine whether the IO degradation meets the immediate execution policy. The specific immediate execution policy can be referred to in the relevant description of the immediate execution policy above (4), and will not be repeated here.

[0326] If the IO degradation meets the immediate execution policy, then step S708 can be executed, whereby the host sends an FDD execution command to the FDD driver in the kernel layer.

[0327] If the IO degradation does not meet the immediate execution policy, the value of FLAG_TIME in step S705 and the value of FLAG_IO in step S706 can be further determined.

[0328] If FLAG_TIME is true and FLAG_IO is true, it means that the time interval between the current time and the last time FDD was triggered t1 meets the interval t2 required for the next FDD trigger, and the IO degradation has reached the preset IO degradation. Then step S708 can be executed, and the host sends an FDD execution command to the FDD driver in the kernel layer.

[0329] If FLAG_TIME is not true, and / or FLAG_IO is not true, it means that the time interval between the current time and the last FDD execution time t1 does not meet the interval time t2 required for the next FDD trigger, and / or the IO degradation has not reached the preset IO degradation. In this case, the FDD execution command will not be sent to the FDD driver in the kernel layer. Instead, step S709 will be executed, and the host side will calculate the interval time for the next FDD execution.

[0330] S708: The host determines the FDD execution command to the FDD driver in the kernel layer according to the policy.

[0331] When the conditions for executing FDD are met, the host can send an FDD execution command to the FDD driver in the kernel layer.

[0332] S709. The host calculates the interval for the next FDD execution and writes it to the system properties.

[0333] The host can dynamically update the system attribute values ​​required by the algorithm based on whether or not an FDD execution command is issued.

[0334] For example, after triggering FDD execution, the host can update the FDD trigger time to the moment when FDD execution was triggered. The host can also update the control parameter x based on the IO degradation and determine the time interval for FDD execution based on the control parameter x.

[0335] The S710 and FDD driver check command format sends host-side FDD commands to the device side for interaction.

[0336] After the FDD driver obtains the FDD execution command, it can send FDD commands to the FDD device.

[0337] The S711 and FDD devices add the FDD trigger function to the delayed work queue and wait for execution.

[0338] In some scenarios, a delayed work queue can also be simply referred to as a delayed queue.

[0339] Figure 9 The diagram illustrates the module interaction of the full disk defragmentation trigger method.

[0340] Once the host meets the conditions for FDD detection, it can obtain the FDD capability of the device.

[0341] Optionally, the FDD driver can define a sysfs node for the FDD descriptor, allowing the host to query the FDD descriptor on the device. The host can send a read command to the FDD driver through the sysfs node created by the kernel. Upon receiving the read command from the host, the FDD driver can send a device descriptor query command to the device to obtain the FDD descriptor information and return it to the host (writing it to the address provided by the host).

[0342] In this way, the host can obtain the FDD capabilities and constraints of the device by retrieving the device's FDD descriptor. It's understandable that whether the device has an FDD descriptor depends on its specific implementation. If the device has an FDD descriptor, it can be used to specify limitations related to FDD characteristics, such as internal device lifetime constraints. If the device does not have an FDD descriptor, the host can obtain the device's FDD capabilities through other methods agreed upon with the device manufacturer. For example, the host can query specific registers in Tables 3 and 4 to determine if the device supports FDD; if the device does not return an error code, it indicates support.

[0343] The host determines whether to disable FDD based on a device lifespan factoring policy. For example, the FDD driver can define a proc node for the device health descriptor, such as bDeviceLifeTimeEstA, to allow the host to query the device's remaining lifespan. The host can send a query command to the FDD driver via the proc node created by the kernel to read the device's remaining lifespan. Upon receiving the read command from the host, the FDD driver can send a device health descriptor query command to the device to obtain specific register information from the device's health descriptor and return this information to the host (written to an address provided by the host).

[0344] The host can read the key-value pairs stored in the system properties by calling the property_get() function, thereby obtaining the values ​​of the FDD system properties. For example, the system property values ​​of FDD may include the values ​​of persist.ufs.fdd.t1, persist.ufs.fdd.t2, and / or persist.ufs.fdd.x, etc. Then, based on the relevant policies, it can determine whether to execute FDD and update the values ​​of these system properties.

[0345] For example, an FDD driver can define a sysfs node for FDD triggering, allowing the host to trigger FDD execution on the device. If the algorithm determines that FDD execution is necessary, the host can send an FDD trigger command to the FDD driver through the sysfs node created by the kernel. Upon receiving the trigger command from the host, the FDD driver sends an FDD execution command to the device according to the FLAGS protocol, including setting a specific register (e.g., bFDDEn) to 0x1. Once the specific device register (e.g., bFDDEn) is set to 0x1 by the driver, the device begins FDD execution.

[0346] Depending on whether FDD execution has been triggered, the host can update the FDD's system attributes. For example, if the FDD trigger condition is not met (meaning FDD execution has not been triggered), the host can update the control parameter x according to the algorithm's relevant policies, determine the next FDD execution interval based on control parameter x, and update it accordingly. If the FDD trigger condition is met (meaning FDD execution has been triggered), the host can update the FDD trigger time to the moment the FDD execution was triggered, update the control parameter x to a preset default value (e.g., a default value could be 9), determine the next FDD execution interval based on control parameter x, and update it accordingly.

[0347] In addition, the host can also check the execution status of the FDD. For example, the FDD driver can define a sysfs node for the FDD execution status, allowing the host to query the device's FDD execution status. The host can send commands to the FDD driver through the kernel-created sysfs node to read the FDD's execution status. After receiving the command from the host, the FDD driver, according to the ATTRIBUTES protocol, sends instructions to the device to read FDD execution status attributes, such as fFDDOperationStatus, and returns the read specific attribute register information to the host (written to the address provided by the host). In this way, the host can promptly determine whether the FDD execution has completed.

[0348] It should be noted that the host-side check of the FDD execution status can be performed immediately after the FDD detection conditions are met. If the device is already executing FDD, subsequent steps are skipped, and the check waits for the next FDD detection. This optimizes the algorithm and avoids consuming excessive system resources.

[0349] Understandably, the host can check the execution status of the FDD multiple times or in cycles, so that the host can check the execution status of the FDD in a timely manner and determine whether the FDD has been completed.

[0350] The host can also interrupt FDD execution as needed, such as when an FDD exceeds a certain execution time. For example, the FDD driver can define a sysfs node for FDD triggering, allowing the host to interrupt the FDD execution being performed on the device. The host can send an interrupt command to the FDD driver through a sysfs node created by the kernel. Upon receiving the interrupt command from the host, the FDD driver sends an FDD interrupt command to the device according to the FLAGS protocol, including setting a specific register (e.g., bFDDEn) to 0x2. When the specific register (e.g., bFDDEn) on the device is set to 0x2 by the driver, the device suspends FDD execution, records the physical address position reached by the FDD, and changes the FDD execution status attribute to the value corresponding to the host-interrupted state. For example, the value corresponding to the host-interrupted state could be 02h as shown in Table 3. The device will resume FDD execution from the previously interrupted position upon receiving the next FDD execution command.

[0351] Table 8 below shows a speed comparison between sequential read and sequential write after performing FDD.

[0352] For example, Table 8 shows the test results of sequential read and sequential write in three scenarios: before fragmentation, after fragmentation, and after FDD execution, on a certain chip platform. The test was conducted with an 8-thread CPU, the device end of the capacity, 1% remaining storage space, 100 target test files, and each target test file being 128 MB.

[0353] The CPU frequency locking of 8 threads can be referred to the relevant description in the corresponding embodiment in Table 1. The capacity end is only for the fragmented device end. 100 target test files can be created using the FIO tool, which will not be elaborated further.

[0354] In a laboratory setting, before fragmentation, sequential read speeds were around 3000 MB / s and sequential write speeds were around 1600 MB / s. After fragmentation, sequential read speeds were around 1000 MB / s and sequential write speeds were around 400 MB / s. After performing FDD, sequential read speeds were around 3000 MB / s and sequential write speeds were around 800 MB / s.

[0355] In other words, both read and write performance can be restored to some extent after performing FDD. For example, read performance can be restored to near its pre-fragmentation state, and write performance can be restored to 50% of its pre-fragmentation state. Sequential write speed is faster than the post-fragmentation speed. Understandably, although FDD can be performed, the free PBA space that FDD can reclaim is limited because the test was conducted at the end of the device's capacity. Therefore, after performing FDD, the sequential write speed will still be less than or equal to the pre-fragmentation speed.

[0356] It is understood that the data in Table 8 is illustrative, and Table 8 is used to show that after performing FDD, the speed of both sequential reads and sequential writes on the device is improved compared to after fragmentation. After performing FDD, the speed of sequential reads on the device can be between the speed before and after fragmentation, or it can recover to the speed before fragmentation; the speed of sequential writes on the device can be between the speed before and after fragmentation, or it can recover to the speed before fragmentation. This trend is consistent with the trend obtained from laboratory test data.

[0357] Table 8

[0358]

[0359] Table 9 below shows a comparison of application cold start latency after executing FDD.

[0360] For example, Table 9 shows the test results of cold start time for 10 test applications on a certain chip platform, before and after electronic device fragmentation.

[0361] Understandably, the fragmentation here is not application fragmentation, but rather full disk fragmentation of the phone's remaining space through continuous file write and delete operations. This operation generates a large number of dirty segments, increasing the number of background tasks on the device and thus generating long I / O. This fragmentation method may affect the startup time of the 10 test applications.

[0362] In a laboratory setting, before fragmentation, the application cold start time was around 1000ms. After fragmentation, the application cold start time was around 2000ms. After executing FDD, the application cold start time was around 900ms to 1000ms. In other words, after executing FDD, the application cold start time was shortened, and the application startup latency could be restored to 90% or more of the pre-fragmentation level.

[0363] Understandably, the data in Table 9 is illustrative and is used to show that the application cold start time is shortened after performing FDD compared to after fragmentation. After performing FDD, the application cold start time falls between the speed before and after fragmentation, and this trend is consistent with the trend obtained from laboratory test data.

[0364] Table 9

[0365]

[0366] Figure 10 The results show the I / O latency statistics obtained over a period of time on the test electronic device.

[0367] The horizontal axis represents the time for statistical I / O latency, and the vertical axis represents the I / O latency of SCSI layer commands in the electronic device, in microseconds (µs). The time for statistical I / O latency can be a preset time period for the electronic device, such as the I / O latency of one day. The specific duration of the statistical period can be set by the electronic device according to actual conditions, and this embodiment does not limit this. The statistical I / O latency can be the average I / O latency within the preset time period, such as the average of all I / O latency in one day. Of course, the statistical I / O latency can also be calculated in other ways, and this embodiment does not limit this.

[0368] Understandable Figure 10 The data in the example is used to show that after FDD is triggered, the IO latency of SCSI layer commands decreases, and this trend is consistent with the trend obtained from laboratory test data.

[0369] Figure 10In the graph, a higher bar indicates higher I / O latency. The FDD execution is triggered between times t13 and t14; t13 represents the time before FDD execution, and t14 represents the time after FDD execution. As can be seen from the graph, before time t14, since FDD was not triggered, the I / O latency was relatively higher compared to after time t14. It is understandable that if FDD is not executed, the I / O latency may gradually increase over time, having a greater impact on the performance of electronic devices.

[0370] When an electronic device uses the method provided in this application embodiment, it can determine that IO degradation exists and promptly trigger the execution of FDD. For example, at time t14, the electronic device triggers FDD. It can be seen that after executing FDD, the IO latency of the electronic device is reduced. In other words, the method provided in this application embodiment can prevent IO degradation in the electronic device from lasting for too long. Compared to periodically triggering FDD, the electronic device can trigger FDD more promptly, thereby reducing IO latency and improving the performance of the electronic device.

[0371] Optionally, the electronic device may not need to wait until the I / O latency is severe to trigger FDD, or it may not need to wait until the remaining capacity on the device side is insufficient to trigger FDD. The execution effect can also be observed when the remaining capacity on the device side is sufficient, for example... Figure 10 The data shows the IO latency statistics for triggering FDD when the remaining capacity of the device is greater than half. It can be seen that after triggering FDD, the electronic device can quickly restore IO performance, improving the stability and smoothness of the device, thereby enhancing the user experience.

[0372] It is understood that the method of this application embodiment can also be used for defragmentation techniques of other granularities or non-UFS devices. Other granularities may include, for example, a specific disk or a specific PBA region corresponding to one or more LBA segments. If other defragmentation techniques or non-UFS devices can also provide full-disk defragmentation technology, then the method of this application embodiment can be used.

[0373] The methods of this application will be described in detail below through specific embodiments. The following embodiments can be combined with each other or implemented independently, and the same or similar concepts or processes may not be described again in some embodiments.

[0374] Figure 11 This application illustrates a method for triggering full disk defragmentation according to an embodiment of the present application. The method includes:

[0375] S1101. At the first moment, the IO degradation of the target storage device is less than the degradation threshold, and the target storage device does not perform full disk defragmentation. The interval between the first moment and the target moment is less than the first time interval. The target moment is the moment when the target storage device last performed full disk defragmentation.

[0376] In this embodiment of the application, the first moment can be understood as the moment when the electronic device triggers the detection of full disk defragmentation (FDD).

[0377] The IO degradation degree can be referred to the relevant description in the above embodiments, and will not be repeated here. The degradation degree threshold can be understood as the preset IO degradation degree.

[0378] In possible implementations, whether the IO degradation level has reached a preset IO degradation level can be determined by checking if the IO degradation state value has reached a preset state value, or by checking if the IO degradation threshold has reached a preset threshold, or by checking if the number of long IO delays has reached a preset number of long IO delays. For details, please refer to... Figure 7 The relevant descriptions in step S706 of the corresponding embodiment will not be repeated here.

[0379] The target storage device may include a UFS device, or other storage devices in electronic devices that can provide full disk defragmentation; this application does not limit the scope of the embodiments.

[0380] The target time can be understood as the time t1 of the last FDD trigger in the dynamic interval time strategy of (2) in the above embodiment, and the first time interval can be understood as the interval time t2 required for the next FDD trigger in the above embodiment. It can be understood that when the IO degradation of the target storage device is less than the degradation threshold, it means that the IO degradation of the target storage device is not very serious, so the target storage device does not need to perform FDD.

[0381] S1102. At the second time, if the IO degradation of the target storage device is greater than or equal to the degradation threshold, the target storage device does not perform full disk defragmentation, and the interval between the second time and the target time is less than the first time interval.

[0382] In this embodiment of the application, the second moment can be understood as the moment when the electronic device triggers the detection of FDD.

[0383] It is understandable that when the IO degradation of the target storage device is greater than or equal to the degradation threshold, it indicates that the IO degradation of the target storage device is relatively severe. However, since the time interval for performing FDD is not met, it is not necessary for the target storage device to perform FDD.

[0384] S1103. At the third time point, the IO degradation degree of the target storage device is greater than or equal to the degradation degree threshold, and the target storage device performs full disk defragmentation. The interval between the third time point and the target time point is greater than or equal to the first time interval. Wherein, the IO degradation degree is the ratio of the number of long IO delays of the target storage device to the total number of IO delays of the storage device, and the number of long IO delays is the number of IO delays in the storage device that are greater than the second threshold.

[0385] In this embodiment of the application, the third moment can be understood as the moment when the electronic device triggers the detection of FDD.

[0386] It is understandable that when the IO degradation of the target storage device is greater than or equal to the degradation threshold, it indicates that the IO degradation of the target storage device is relatively severe. Since the time interval for performing FDD is met, the target storage device can be instructed to perform FDD.

[0387] In this embodiment, the decision to trigger FDD execution is determined based on factors such as the I / O state of the target storage device and the time elapsed since the last FDD execution. This allows for on-demand FDD execution based on the actual situation of the target storage device, dynamically changing the frequency at which the device handles physical address fragmentation. Dynamically changing the frequency of physical address fragmentation handling can include shortening the frequency, extending the frequency, or immediately executing FDD, thereby reducing electronic device lag and improving user experience.

[0388] Optional, in Figure 11 Based on the corresponding embodiment, the value of the first time interval is updated as the IO degradation of the target storage device changes, and the first time interval is inversely proportional to the IO degradation.

[0389] In this embodiment, the first time interval is inversely proportional to the IO degradation degree, including linear inversely proportional to the IO degradation degree, exponential inversely proportional to the IO degradation degree, etc. The specific calculation formula that the first time interval is inversely proportional to the IO degradation degree is not limited.

[0390] When the I / O state of the target storage device deteriorates, the interval required to execute FDD can be shortened or FDD can be executed immediately. This allows the physical address fragments of the data stored in the electronic device and the internal data of the UFS device to be organized in a timely manner, thereby reducing I / O latency, improving the read and write performance of the target storage device, reducing electronic device lag, and improving user experience.

[0391] When the I / O status of the target storage device is good, the interval time required to perform FDD can be appropriately increased to reduce unnecessary FDD execution, reduce computing power, improve the operating efficiency of electronic devices, and reduce unnecessary wear and tear on the lifespan of UFS devices due to the appropriate reduction in the frequency of FDD execution.

[0392] Optional, in Figure 11 Based on the corresponding embodiments, the first time interval satisfies the following formula:

[0393] f(x) = k1*x; or f(x) = k2*2^x.

[0394] Where f(x) is the first time interval, x is the control parameter of the first time interval, the control parameter is inversely proportional to the IO degradation degree, and k1 and k2 are both coefficients of the control parameter.

[0395] In this embodiment, k1 and k2 can be preset by the electronic device. k1 and k2 can be equal or unequal. For example, both k1 and k2 can be 10. The specific values ​​of k1 and k2 are not limited in this embodiment.

[0396] It is understood that the formula for calculating the first time interval f(x) can be set differently depending on the actual situation of the electronic device, and this application embodiment does not limit it. For specific descriptions of f(x), please refer to the relevant descriptions in the dynamic interval time strategy of (2) of the above embodiment, which will not be repeated here.

[0397] Optional, in Figure 11 Based on the corresponding embodiments, the maximum value of the control parameter is a preset value, and the minimum value of the control parameter is related to the remaining lifetime of the target storage device.

[0398] In this embodiment, the control parameter x can be a dynamically changing parameter, as described in the dynamic interval time strategy of embodiment (2) above. The range of x can be [MIN_X, MAX_X], where MIN_X is the minimum value of x, which can represent the minimum interval time for executing FDD, and MAX_X is the maximum value of x, which can represent the maximum interval time for executing FDD. For specific descriptions of x, MIN_X and MAX_X, please refer to the relevant descriptions in the dynamic interval time strategy of embodiment (2) and the lifetime factor strategy of embodiment (3) above, which will not be repeated here.

[0399] The maximum value of the control parameter is a preset value, which can be understood as a fixed value set in advance. It should be understood that since the lifespan of different target storage devices can vary, in a possible implementation, different maximum values ​​of the control parameter can be set for different target storage devices in the configuration file within the electronic device.

[0400] Understandably, the existence of the minimum value MIN_X can reduce the frequency of FDD execution due to abnormal I / O states of the target storage device.

[0401] Optional, in Figure 11 Based on the corresponding embodiments, the remaining lifetime of the target storage device is within a first remaining lifetime range, and the minimum value of the control parameter is a first value; the remaining lifetime of the target storage device is within a second remaining lifetime range, and the minimum value of the control parameter is a second value, wherein the remaining lifetime of the target storage device within the second remaining lifetime range is less than the remaining lifetime of the target storage device within the first remaining lifetime range, and the second value is greater than the first value; the remaining lifetime of the target storage device is within a third remaining lifetime range, and the minimum value of the control parameter is a third value, wherein the remaining lifetime of the target storage device within the third remaining lifetime range is less than the remaining lifetime of the target storage device within the second remaining lifetime range, and the third value is greater than the second value.

[0402] In this embodiment, the first remaining lifetime range may include a remaining lifetime of the target storage device greater than 80%. Taking the formula f(x) = k1*x satisfying the first time interval as an example, the first value may include 1. Taking the formula f(x) = 10*2^x satisfying the first time interval as an example, the first value may include 0.

[0403] The second remaining lifetime range can include a remaining lifetime of the target storage device that is greater than 50% and less than or equal to 80%. Taking the formula f(x) = k1*x satisfied by the first time interval as an example, the second value can include 3. Taking the formula f(x) = 10*2^x satisfied by the first time interval as an example, the first value can include 2.

[0404] The third remaining lifetime range can include the remaining lifetime of the target storage device being greater than or equal to 20% and less than or equal to 50%. Taking the formula f(x) = k1*x satisfied by the first time interval as an example, the second value can include 9. Taking the formula f(x) = 10*2^x satisfied by the first time interval as an example, the first value can include 3.

[0405] For a detailed description of x and the remaining lifetime of the target storage device, please refer to the relevant description in the lifetime factor strategy of embodiment (3) above, which will not be repeated here. It is understood that the remaining lifetime of the target storage device can also be divided into other segments. The specific values ​​of the first value, the second value, and the third value can be preset by the electronic device, and this application embodiment does not limit them.

[0406] In this embodiment, the shorter the remaining lifetime of the target storage device, the longer the minimum FDD interval. This allows for a trade-off between the lifetime and performance of the target storage device. When the remaining lifetime of the target storage device decreases, the execution frequency of FDD is reduced, thereby mitigating the wear and tear on the target storage device.

[0407] Optional, in Figure 11 Based on the corresponding embodiment, when the IO degradation degree is greater than or equal to the first IO degradation degree, the control parameter is set to the minimum value of the control parameter; when the IO degradation degree is greater than or equal to the second IO degradation degree, the control parameter is reduced by a fourth value, and the second IO degradation degree is less than the first IO degradation degree; when the IO degradation degree is greater than or equal to the third IO degradation degree, the control parameter is reduced by a fifth value, and the third IO degradation degree is less than the second IO degradation degree, and the fifth value is less than or equal to the fourth value; when the IO degradation degree is greater than or equal to the fourth IO degradation degree, the control parameter is increased by a sixth value, and the fourth IO degradation degree is less than the third IO degradation degree.

[0408] In this embodiment, if the IO degradation degree is greater than or equal to the first IO degradation degree, it indicates that the IO degradation is severe, and the read / write performance of the target storage device has been severely affected or will be severely affected, requiring timely triggering of FDD to restore the read / write performance of the target storage device. In this case, the minimum value of the control parameter, i.e., MIN_X, can be set.

[0409] If the IO degradation degree is greater than or equal to the second IO degradation degree, it indicates that the IO degradation is severe. In this case, the control parameters can be reduced, thereby shortening the time interval for FDD execution. For example, the control parameter exponent can be reduced, such as by x / 2, resulting in a fourth value of x / 2.

[0410] If the IO degradation degree is greater than or equal to the third IO degradation degree, it indicates that the IO degradation has reached a certain level, and the read / write performance of the target storage device has begun to deteriorate due to certain factors. Therefore, the interval time required for the next FDD execution can be appropriately reduced. For example, the control parameter can be linearly reduced, such as by decreasing it by 1, i.e., the fifth value is 1.

[0411] If the IO degradation degree is greater than or equal to the fourth IO degradation degree, it indicates that the IO degradation is very small or almost non-existent, and the target storage device is in good condition. Therefore, the interval required for the next FDD execution can be appropriately increased. For example, the control parameter can be increased linearly, such as by increasing it by 1, i.e., the sixth value is 1.

[0412] For a detailed description of the IO degradation degree and control parameters, please refer to the relevant description in the dynamic interval time strategy of embodiment (2) above, which will not be repeated here. It is understood that the IO degradation degree can also be set to more or fewer levels. The fourth, fifth, and sixth values ​​can be the same or different, and the specific values ​​of the fourth, fifth, and sixth values ​​can be preset by the electronic device. This application embodiment does not limit this.

[0413] In this embodiment, when the IO degradation degree is greater than or equal to the first IO degradation degree, the control parameter is set to its minimum value instead of 0, thus preventing immediate FDD triggering. This is because, firstly, the cause of a large number of long IOs on a given day may not be due to a high overall physical address fragmentation rate of the target storage device, but may be caused by other factors, such as high host load, numerous background tasks, and / or device malfunction. In this case, the IO state may recover once these other factors are eliminated. Secondly, this reduces the possibility of frequent FDD triggering due to factors such as target storage device malfunction, thereby reducing unnecessary wear and tear on device lifespan. Thirdly, the IO state of the target storage device may be improved due to other functions deployed on the host or the target storage device.

[0414] Optional, in Figure 11 Based on the corresponding embodiment, after the third time point, it may further include: updating the target time point to the third time point; updating the first time interval to the seventh value; and updating the control parameters based on the IO degradation degree.

[0415] In this embodiment, the seventh value can be understood as the default time interval after FDD execution. The seventh value can be preset by the electronic device, for example, the seventh value can include 90. The specific value of the seventh value can be preset by the electronic device, and this embodiment does not limit it.

[0416] Understandably, when performing FDD, updating the time of the last full disk defragmentation of the target storage device to the current time in a timely manner can more accurately calculate the time interval for performing FDD, thereby performing FDD at a more reasonable frequency.

[0417] After FDD is triggered, theoretically there will be almost no fragmentation on the target storage device. Therefore, the electronic device can set a longer interval, such as 90 days, or about 3 months, to re-observe.

[0418] Furthermore, updating the control parameters can also be understood as dynamically updating the value of the first time interval based on the seventh value. This allows FDD detection to be triggered more quickly according to the actual state of the electronic device, enabling the read / write performance of the target storage device to be restored in a timely manner, thereby improving the user experience.

[0419] Optional, in Figure 11 Based on the corresponding embodiments, before the target storage device performs full disk defragmentation, it may further include: determining that the interval between the third time and the target time is greater than or equal to the first time interval, setting the time interval flag to the eighth value, the eighth value being used to indicate that the time interval between the third time and the last full disk defragmentation meets the first time interval; determining that the IO degradation degree is greater than or equal to the IO degradation degree threshold, setting the IO degradation degree flag to the ninth value, the ninth value being used to indicate that the IO degradation degree at the third time is severe; the target storage device performing full disk defragmentation may include: when the time interval flag is the eighth value and the IO degradation degree flag is the ninth value, the target storage device performs full disk defragmentation.

[0420] In this embodiment, the time interval flag can be understood as... Figure 7 In step S705 of the corresponding embodiment, FLAG_TIME, the IO degradation flag can be understood as... Figure 7 This corresponds to step S706 of the embodiment, FLAG_IO. For example, the eighth value can be true. The ninth value can be true.

[0421] For details on the values ​​and judgments of FLAG_TIME and FLAG_IO, please refer to [link / reference]. Figure 7 The relevant descriptions in steps S705-S707 of the corresponding embodiments will not be repeated here.

[0422] By using different values ​​for FLAG_IO, we can more easily and intuitively identify whether the IO degradation level has reached the preset IO degradation level. Similarly, by using different values ​​for FLAG_TIME, we can more easily and intuitively identify whether the time interval between the current time and the last time t1 when FDD was triggered meets the interval t2 required for the next FDD trigger, thereby improving the execution efficiency of the code.

[0423] Optional, in Figure 11 Based on the corresponding embodiment, before the first time point, it may also include: a fourth time point, in which the target storage device performs full disk defragmentation, and the interval between the fourth time point and the target time point is greater than or equal to the second time interval.

[0424] In this embodiment of the application, the fourth moment can be understood as the moment when the electronic device triggers the detection of FDD.

[0425] The second time interval can be understood as T4 in the guaranteed execution strategy (5) of the above embodiment. Further details are omitted. For example, the second time interval can be set to 365 days, or set to a second time interval ≥ f(MAX_X), etc. The specific value of the second time interval can be set according to the actual situation of the electronic device, and this application embodiment does not limit it.

[0426] This reduces the likelihood of electronic devices failing to trigger FDD execution due to the inability to meet the triggering conditions set in the IO strategy. For example, since the IO latency and other information collected by the electronic device are stored in memory, frequent restarts or factory resets may clear this stored IO latency and other information, preventing the device from meeting the triggering conditions set in the IO strategy.

[0427] Furthermore, if a priority is given to determining whether the minimum execution policy is met, an FDD execution command can be promptly sent to the FDD driver at the kernel level, thereby reducing unnecessary subsequent conditional judgment steps, saving computing power, and improving the execution efficiency of electronic devices.

[0428] Optional, in Figure 11 Based on the corresponding embodiment, before the first time point, it may further include: at the fifth time point, the IO degradation degree of the target storage device is greater than or equal to the first IO degradation degree, the target storage device performs full disk defragmentation, and the interval between the fifth time point and the target time point is greater than or equal to the third time interval.

[0429] In this embodiment of the application, the fifth moment can be understood as the moment when the electronic device triggers the detection of FDD.

[0430] The third time interval can be understood as T3 in the immediate execution strategy (4) of the above embodiment. Further details are omitted. For example, the third time interval can be set to 10 days, or f(MIN_X), etc. The specific value of the third time interval can be set according to the actual situation of the electronic device, and this application embodiment does not limit it.

[0431] This reduces the frequency of FDD execution by electronic devices when the target storage device malfunctions.

[0432] Optional, in Figure 11 Based on the corresponding embodiments, the method may further include: when the remaining lifetime of the target storage device is less than a preset lifetime threshold, the target storage device does not perform full disk defragmentation.

[0433] In this embodiment, the preset lifetime threshold may include situations where the remaining lifetime of the target storage device is low, for example, the preset lifetime threshold may be 20%. It is understood that by considering the remaining lifetime of the target storage device, the FDD can be turned off in a timely manner when the remaining lifetime of the target storage device is low, thereby reducing the wear and tear on the lifespan of the target storage device and extending the service life of the electronic device.

[0434] Furthermore, prioritizing the determination of whether the remaining lifespan of the target storage device is less than a preset lifespan threshold can reduce unnecessary subsequent steps, save computing power, and improve the execution efficiency of electronic devices.

[0435] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.

[0436] The foregoing primarily describes the solutions provided by the embodiments of this application from a methodological perspective. To achieve the aforementioned functions, it includes corresponding hardware structures and / or software modules for executing each function. Those skilled in the art should readily recognize that, based on the method steps of the examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0437] This application embodiment can divide the apparatus for implementing the method into functional modules based on the above method examples. For example, each function can be divided into its own functional modules, or two or more functions can be integrated into one processing module. The integrated module can be implemented in hardware or as a software functional module. It should be noted that the module division in this application embodiment is illustrative and only represents one logical functional division; other division methods may be used in actual implementation.

[0438] like Figure 12 The diagram shows a chip structure according to an embodiment of this application. The chip 1200 includes one or more processors 1201, communication lines 1202, communication interfaces 1203, and memory 1204.

[0439] In some implementations, memory 1204 stores elements such as executable modules or data structures, or subsets thereof, or extended sets thereof.

[0440] The methods described in the embodiments of this application can be applied to or implemented by the processor 1201. The processor 1201 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuit in the hardware of the processor 1201 or by instructions in the form of software. The processor 1201 may be a general-purpose processor (e.g., a microprocessor or conventional processor), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gates, transistor logic devices, or discrete hardware components. The processor 1201 can implement or execute the various processing-related methods, steps, and logic block diagrams disclosed in the embodiments of this application.

[0441] The steps of the method disclosed in the embodiments of this application can be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software modules can be located in mature storage media in the art, such as random access memory, read-only memory, programmable read-only memory, or electrically erasable programmable read-only memory (EEPROM). This storage medium is located in memory 1204, and processor 1201 reads information from memory 1204 and, in conjunction with its hardware, completes the steps of the above method.

[0442] The processor 1201, memory 1204 and communication interface 1203 can communicate with each other via communication line 1202.

[0443] In the above embodiments, the instructions stored in the memory for execution by the processor can be implemented in the form of a computer program product. This computer program product can be pre-written into the memory, or it can be downloaded and installed into the memory as software.

[0444] This application also provides a computer program product comprising one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions may be transmitted from a website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or data center that integrates one or more available media. For example, available media may include magnetic media (e.g., floppy disk, hard disk, or magnetic tape), optical media (e.g., digital versatile disc (DVD)), or semiconductor media (e.g., solid-state disk (SSD)).

[0445] This application also provides a computer-readable storage medium. The methods described in the above embodiments can be implemented, in whole or in part, by software, hardware, firmware, or any combination thereof. The computer-readable medium may include computer storage media and communication media, and may also include any medium capable of transferring a computer program from one place to another. The storage medium can be any target medium accessible by a computer.

[0446] As one possible design, computer-readable media may include compact disc read-only memory (CD-ROM), RAM, ROM, EEPROM, or other optical disc storage; computer-readable media may also include disk storage or other disk storage devices. Furthermore, any connecting cable may also be appropriately referred to as computer-readable media. For example, if software is transmitted from a website, server, or other remote source using coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave, then coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of media. As used herein, disks and optical discs include optical discs (CD), laser discs, optical discs, digital versatile discs (DVD), floppy disks, and Blu-ray discs, where disks typically reproduce data magnetically, while optical discs optically reproduce data using lasers.

[0447] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processing unit of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processing unit of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

Claims

1. A method for triggering full disk defragmentation, characterized in that, The electronic device includes a target storage device, and the method includes: At the first moment, the IO degradation of the target storage device is less than the degradation threshold, and the target storage device does not perform full disk defragmentation. The interval between the first moment and the target moment is less than the first time interval. The target moment is the moment when the target storage device last performed full disk defragmentation. At the second moment, if the IO degradation of the target storage device is greater than or equal to the degradation threshold, the target storage device does not perform full disk defragmentation, and the interval between the second moment and the target moment is less than the first time interval. At the third moment, the IO degradation of the target storage device is greater than or equal to the degradation threshold, and the target storage device performs full disk defragmentation. The interval between the third moment and the target moment is greater than or equal to the first time interval. Wherein, the IO degradation degree is the ratio of the number of long IO delays of the target storage device to the total number of IO delays of the storage device, and the number of long IO delays is the number of IO delays in the storage device that are greater than the second threshold. The value of the first time interval is updated as the I / O degradation of the target storage device changes, and the first time interval is inversely proportional to the I / O degradation.

2. The method according to claim 1, characterized in that, The first time interval satisfies the following formula: ; Where x is the control parameter of the first time interval, the control parameter is inversely proportional to the IO degradation degree, and k1 and k2 are both coefficients of the control parameter.

3. The method according to claim 2, characterized in that, The maximum value of the control parameter is a preset value, and the minimum value of the control parameter is related to the remaining lifespan of the target storage device.

4. The method according to claim 3, characterized in that, The remaining lifetime of the target storage device is within a first remaining lifetime range, and the minimum value of the control parameter is a first value; The remaining lifetime of the target storage device is within a second remaining lifetime range, and the minimum value of the control parameter is a second value, wherein the remaining lifetime of the target storage device within the second remaining lifetime range is less than the remaining lifetime of the target storage device within the first remaining lifetime range, and the second value is greater than the first value. The remaining lifetime of the target storage device is within a third remaining lifetime range, and the minimum value of the control parameter is a third value, wherein the remaining lifetime of the target storage device within the third remaining lifetime range is less than the remaining lifetime of the target storage device within the second remaining lifetime range, and the third value is greater than the second value.

5. The method according to any one of claims 2-4, characterized in that, If the IO degradation degree is greater than or equal to the first IO degradation degree, the control parameter is set to the minimum value of the control parameter; When the IO degradation degree is greater than or equal to the second IO degradation degree, the control parameter is reduced to a fourth value, and the second IO degradation degree is less than the first IO degradation degree; If the IO degradation degree is greater than or equal to the third IO degradation degree, the control parameter is reduced to a fifth value, where the third IO degradation degree is less than the second IO degradation degree, and the fifth value is less than or equal to the fourth value; If the IO degradation degree is greater than or equal to the fourth IO degradation degree, the control parameter is increased by a sixth value, where the fourth IO degradation degree is less than the third IO degradation degree.

6. The method according to any one of claims 2-4, characterized in that, Following the third moment, the following also includes: Update the target time to the third time. Update the first time interval to the seventh value; The control parameters are updated based on the IO degradation.

7. The method according to any one of claims 1-4, characterized in that, Before performing full disk defragmentation on the target storage device, the following steps are also included: The interval between the third time point and the target time point is determined to be greater than or equal to the first time interval. The time interval flag is set to the eighth value, which is used to indicate that the time interval between the third time point and the last full disk defragmentation is satisfied with the first time interval. If the IO degradation degree is determined to be greater than or equal to the IO degradation degree threshold, the IO degradation degree flag is set to the ninth value, which is used to indicate the severity of the IO degradation degree at the third time point; The target storage device performs full disk defragmentation, including: When the time interval flag is the eighth value and the IO degradation flag is the ninth value, the target storage device performs full disk defragmentation.

8. The method according to any one of claims 1-4, characterized in that, Prior to the first moment, it also includes: At the fourth time point, the target storage device performs full disk defragmentation, and the interval between the fourth time point and the target time point is greater than or equal to the second time interval.

9. The method according to claim 5, characterized in that, Prior to the first moment, it also includes: At the fifth time point, the IO degradation of the target storage device is greater than or equal to the first IO degradation, and the target storage device performs full disk defragmentation. The interval between the fifth time point and the target time point is greater than or equal to the third time interval.

10. The method according to any one of claims 1-4, 9, characterized in that, The method further includes: If the remaining lifetime of the target storage device is less than a preset lifetime threshold, the target storage device will not perform full disk defragmentation.

11. An electronic device, characterized in that, The electronic device includes: one or more processors and memory; The memory is coupled to the one or more processors, the memory being used to store computer program code, the computer program code including computer instructions, the one or more processors invoking the computer instructions to cause the electronic device to perform the method as described in any one of claims 1-10.

12. A chip system, characterized in that, The chip system is applied to an electronic device, the chip system including one or more processors, the one or more processors being configured to invoke computer instructions to cause the electronic device to perform the method as described in any one of claims 1-10.

13. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes computer instructions that, when executed on an electronic device, cause the electronic device to perform the method as described in any one of claims 1-10.

14. A computer program product, characterized in that, The computer program product includes computer program code that, when run on an electronic device, causes the electronic device to perform the method as described in any one of claims 1-10.