Data processing method and related device

By using reinforcement learning to adjust the threshold judgment conditions during file-level defragmentation, the problem of insignificant reduction in overall file fragmentation rate in existing technologies is solved, achieving resource savings and performance improvement.

CN121166558BActive Publication Date: 2026-07-10HONOR DEVICE CO LTD

Patent Information

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

AI Technical Summary

Technical Problem

Existing technologies cannot effectively reduce the overall fragmentation rate of files when performing file-level defragmentation, resulting in wasted computing resources and reduced lifespan of storage devices. In particular, when the LBA segments of a file are relatively discrete, performing defragmentation on only a small portion has little effect.

Method used

By determining the first proportion and overall fragmentation rate of the file, a second threshold is dynamically adjusted using reinforcement learning to determine whether to perform file-level defragmentation. This ensures that defragmentation is performed when the file proportion and fragmentation rate reach the threshold, avoiding operations on only a small part of the file.

Benefits of technology

It effectively saves computing resources of electronic devices, reduces the wear and tear on storage devices, improves file reading performance, and enhances the accuracy and efficiency of defragmentation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121166558B_ABST
    Figure CN121166558B_ABST
Patent Text Reader

Abstract

The application discloses a data processing method and related equipment, and the method comprises the following steps: determining a first proportion corresponding to a first file, wherein the first proportion corresponding to the first file is a proportion of a first total size corresponding to the first file in a second total size corresponding to the first file, the first total size corresponding to the first file is a total size of logical block address (LBA) segments corresponding to the first file and having a size greater than or equal to a first threshold, and the second total size corresponding to the first file is a total size of the LBA segments corresponding to the first file; and if the first proportion corresponding to the first file is greater than or equal to a second threshold, and an overall fragmentation rate of the first file is greater than or equal to a third threshold, performing FBO on the first file. By implementing the application, the situation that FBO is performed on a small part of the first file can be effectively avoided, thereby saving the computing resources of the electronic equipment and reducing the damage to the service life of the storage device.
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 data processing methods and related equipment. Background Technology

[0002] When users use electronic devices for extended periods, the files stored in the device's storage devices may become increasingly fragmented due to frequent deletion and / or alternating write operations by multiple processes. This can lead to a decrease in the electronic device's file reading performance and cause lag or stuttering.

[0003] Currently, file-based optimization (FBO) can be used to reduce the physical fragmentation of files (i.e., the fragmentation rate). A file corresponds to multiple consecutive logical block address (LBA) segments, and each LBA segment corresponds to a physical block address (PBA) in the storage device. The electronic device determines LBA segments whose size is greater than or equal to a threshold from these LBA segments and performs FBO on the PBAs corresponding to these LBA segments. However, when the LBA segments corresponding to a file are highly discrete, if the number of LBA segments greater than or equal to the threshold is small, FBO can only be performed on a small portion of the file. This has virtually no impact on the overall fragmentation rate of the file, wasting the electronic device's computing resources and unnecessarily shortening the lifespan of the storage device. Summary of the Invention

[0004] This application provides a data processing method and related equipment that can save computing resources of electronic devices and reduce the wear and tear on the lifespan of storage devices.

[0005] In a first aspect, embodiments of this application provide a data processing method, the method comprising: determining a first proportion corresponding to a first file, wherein the first proportion corresponding to the first file is the ratio of a first total size corresponding to the first file to a second total size corresponding to the first file, the first total size corresponding to the first file is the total size of logical block address (LBA) segments whose size is greater than or equal to a first threshold, and the second total size corresponding to the first file is the total size of the LBA segments corresponding to the first file; if the first proportion corresponding to the first file is greater than or equal to the second threshold, and the overall fragmentation rate of the first file is greater than or equal to a third threshold, then performing file-level defragmentation (FBO) on the first file.

[0006] Implementing the embodiments described in the first aspect, when the first proportion corresponding to the first file is larger, it means that there are more LBA segments greater than or equal to the first threshold among all LBA segments corresponding to the first file, that is, there are more LBA segments corresponding to the first file that can be used to perform FBO. Therefore, when the first proportion corresponding to the first file is greater than or equal to the second threshold and the overall fragmentation rate of the first file is greater than or equal to the third threshold, performing FBO on the first file can effectively avoid the situation of performing FBO on only a small part of the first file, thereby saving the computing resources of electronic devices and reducing the wear and tear on the lifespan of storage devices.

[0007] In one possible implementation, the second threshold is a fixed value. This allows the determination of whether an FBO can be performed on the first file using both the fixed value and the third threshold.

[0008] In one possible implementation, before determining the first ratio corresponding to the first file, the method further includes: obtaining a first file set, wherein the overall fragmentation rate of each file in the first file set is greater than or equal to a third threshold; grouping the files in the first file set to obtain M file groups; where M is a positive integer greater than or equal to 1; and determining a second threshold based on the M file groups through reinforcement learning.

[0009] Since the storage state of the first file in the storage device may change over a long period of time, a fixed second threshold cannot be used for determining whether to perform an FBO on the first file in the long run. Learning a non-fixed second threshold through reinforcement learning can help improve the accuracy of determining whether to perform an FBO on the first file.

[0010] In one possible implementation, the method of grouping the files in the first file set to obtain M file groups specifically includes: determining a first proportion corresponding to each file in the first file set; and grouping the files in the first file set to obtain M file groups based on the first proportion corresponding to each file in the first file set.

[0011] In this way, files can be grouped based on the first proportion corresponding to the files to obtain M file groups; for example, files can be evenly grouped according to the first proportion to obtain uniformly distributed training data, thereby improving the learning effect of the second threshold. For example, if the first proportions corresponding to the files in the first file set are {90%, 88%, 45%, 50%, 10%, 10%}, the first file set can be divided into two groups, and the first proportions corresponding to the files in the two groups are {90%, 45%, 10%} and {88%, 50%, 10%}, respectively.

[0012] In one possible implementation, the method of determining the second threshold based on M filegroups through reinforcement learning specifically includes: selecting a first filegroup from the M filegroups, and learning the interception threshold based on the first filegroup through reinforcement learning; the first filegroup can be any one of the M filegroups; if the termination condition of reinforcement learning is not triggered, then selecting a second filegroup from the M filegroups, and learning the interception threshold based on the second filegroup through reinforcement learning; wherein, the second threshold is the interception threshold when the termination condition of reinforcement learning is triggered.

[0013] In this way, file groups can be continuously selected from M file groups to learn the interception threshold, and a second threshold can be obtained when the termination condition of reinforcement learning is triggered.

[0014] In one possible implementation, the above-mentioned learning of the interception threshold based on the first file group through reinforcement learning includes: updating the interception threshold based on the state information of the first file group and the first policy; updating the state information of the first file group based on the updated interception threshold; obtaining the reward value after the interception threshold update, and updating the first policy based on the reward value after the interception threshold update and the updated state information of the first file group.

[0015] In one possible implementation, the status information of the first filegroup includes a first quantity, a second quantity, a third quantity, a fourth quantity, a fifth quantity, and a sixth quantity associated with the first filegroup; the first quantity is the number of files in the first filegroup whose first proportion is greater than or equal to the interception threshold; the second quantity is the number of files in the first filegroup whose first proportion is less than the interception threshold; the third quantity is the number of files in the first filegroup whose first proportion is greater than or equal to the interception threshold and whose overall fragmentation rate decreases after performing FBO; the fourth quantity is the number of files in the first filegroup whose first proportion is greater than or equal to the interception threshold and whose overall fragmentation rate does not decrease after performing FBO; the fifth quantity is the number of files in the first filegroup whose first proportion is less than the interception threshold and whose overall fragmentation rate decreases after performing FBO; and the sixth quantity is the number of files in the first filegroup whose first proportion is less than the interception threshold and whose overall fragmentation rate does not decrease after performing FBO.

[0016] In one possible implementation, the method for obtaining the updated reward value of the interception threshold specifically includes: determining the updated status information of the first file group based on the updated interception threshold and whether the overall fragmentation rate of each file in the first file group has decreased or not decreased after performing FBO; and determining the updated reward value of the interception threshold based on the status information of the first file group and the updated status information of the first file group.

[0017] In this way, the reward value can be quickly determined by comparing the changes in the status information of the first file group before and after the interception threshold is updated.

[0018] In one possible implementation, determining the updated reward value for the interception threshold based on the status information of the first file group and the updated status information of the first file group includes: determining, based on the status information of the first file group and the updated status information of the first file group, whether the first file group shows all positive improvement, only positive improvement and no deterioration, overall positive improvement, no overall improvement, overall deterioration, only deterioration and no improvement, or all deterioration; and determining the updated reward value for the interception threshold based on the following conditions: all positive improvement, only positive improvement and no deterioration, overall positive improvement, no overall improvement, overall deterioration, only deterioration and no improvement, or all deterioration.

[0019] In this way, the degree of positive improvement and / or deterioration of the first file group can be determined based on the changes in the status information of the first file group. For example, depending on the degree of positive improvement and / or deterioration, the first file group may show all positive improvement, only positive improvement and no deterioration, overall positive improvement, overall no improvement, overall deterioration, only deterioration and no improvement, or all deterioration. Thus, the reward value can be determined based on the degree of positive improvement and / or deterioration of the first file group.

[0020] In one possible implementation, the above-mentioned determination of the updated reward value for the interception threshold based on the following conditions: all positive improvements in the first file group, only positive improvements without deterioration, overall positive improvement, no overall improvement, overall deterioration, only deterioration without improvement, or all deterioration, includes: if the first file group is determined to be positively improved, not improved, or deteriorated overall based on the status information of the first file group and the updated status information of the first file group, then the reward value corresponding to each file in the first file group is determined based on the first proportion corresponding to each file in the first file group and whether the overall fragmentation rate decreases after each file performs FBO; and the updated reward value for the interception threshold is determined based on the reward value corresponding to each file in the first file group.

[0021] In this way, when the first file group is improving as a whole, showing no improvement, or deteriorating as a whole, a more accurate updated reward value for the interception threshold can be obtained by determining the reward value corresponding to each file (such as through formula calculation).

[0022] In one possible implementation, if the first file group is all positively improved, only positively improved, only worsened and not improved, or all worsened, then the reward value after the interception threshold is updated is a fixed value.

[0023] In one possible implementation, the method for obtaining the updated reward value of the interception threshold specifically includes: determining the reward value corresponding to each file in the first file group based on the first ratio corresponding to each file in the first file group and whether the overall fragmentation rate decreases after each file performs FBO; and determining the updated reward value of the interception threshold based on the reward value corresponding to each file in the first file group.

[0024] In this way, the reward value corresponding to each file in the first file group can be determined first, and then a more accurate reward value after the interception threshold is obtained based on the reward value corresponding to each file.

[0025] In one possible implementation, the second file is a file in the first file group and the first proportion corresponding to the second file is greater than or equal to the updated interception threshold; if the overall fragmentation rate of the second file decreases after performing FBO on the second file, the reward value corresponding to the second file is positive; or, if the overall fragmentation rate of the second file does not decrease after performing FBO on the second file, the reward value corresponding to the second file is negative or zero.

[0026] Since the goal of reinforcement learning is that files with a first proportion greater than or equal to the updated interception threshold can effectively reduce the fragmentation rate after FBO, the reward value of the second file can be set to be positive when the fragmentation rate decreases, and negative or zero when the fragmentation rate decreases.

[0027] In one possible implementation, the third file is a file in the first file group and the first proportion corresponding to the third file is less than the updated interception threshold; if the overall fragmentation rate of the third file does not decrease after performing FBO on the third file, then the reward value corresponding to the third file is positive; or, if the overall fragmentation rate of the third file decreases after performing FBO on the third file, then the reward value corresponding to the third file is negative.

[0028] Since the goal of reinforcement learning is that the fragmentation rate of files with a first proportion less than the updated interception threshold does not decrease after FBO, the reward value of the third file can be set to be positive when the fragmentation rate does not decrease, and negative or zero when the fragmentation rate does decrease.

[0029] Secondly, embodiments of this application provide an electronic device including one or more processors and one or more memories. The one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program code, which includes computer instructions. When the one or more processors execute the computer instructions, the electronic device performs the data processing method described in the first aspect and any of its possible implementations.

[0030] Thirdly, embodiments of this application provide a data processing apparatus, which includes functions / units for performing the data processing method in the first aspect and any possible implementation thereof.

[0031] Fourthly, embodiments of this application provide a chip system applied to an electronic device. The chip system includes at least one processor and an interface, the interface being used to receive computer instructions and transmit them to the at least one processor; the at least one processor executes the computer instructions to cause the electronic device to perform the data processing method described in the first aspect and any of its possible implementations.

[0032] Fifthly, this application provides a computer-readable storage medium storing computer instructions that, when executed on an electronic device, cause the electronic device to perform the data processing method described in the first aspect and any of its possible implementations.

[0033] Sixthly, this application provides a computer program product, including computer instructions that, when executed by a processor, cause an electronic device to perform the data processing method described in the first aspect and any possible implementation thereof.

[0034] Understandably, the beneficial effects that the electronic devices, data processing devices, chip systems, computer-readable storage media, and computer program products provided above can be referred to in the first aspect and any of its possible implementations, and will not be repeated here. Attached Figure Description

[0035] Figure 1 These are schematic diagrams illustrating two scenarios that may lead to severe physical fragmentation, as provided in the embodiments of this application.

[0036] Figure 2 This is a schematic diagram illustrating the effect of an FBO before and after an embodiment of this application;

[0037] Figure 3 This is a schematic diagram of an FBO process provided in an embodiment of this application;

[0038] Figure 4 This is an example diagram of an FBO provided in an embodiment of this application;

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

[0040] Figure 6 This is a flowchart illustrating a data processing method provided in an embodiment of this application;

[0041] Figure 7This is a schematic diagram illustrating the principle of reinforcement learning provided in an embodiment of this application;

[0042] Figure 8 This is a flowchart illustrating another data processing method provided in an embodiment of this application;

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

[0044] Figure 10 This is a schematic diagram of a software interaction process provided in an embodiment of this application;

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

[0046] The technical solutions in the embodiments of this application will be clearly and thoroughly described below with reference to the accompanying drawings. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B; the word "and / or" in the text is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Furthermore, in the description of the embodiments of this application, "multiple" refers to two or more than two.

[0047] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.

[0048] To facilitate understanding of the solutions provided in the embodiments of this application, the relevant terms involved in the embodiments of this application are introduced below:

[0049] I. Logical Block Address (LBA) and Physical Block Address (PBA)

[0050] File storage involves a file system layer and a storage device layer. The file system layer uses Logical Abbreviation (LBA) as the data addressing mechanism, where LBA represents the logical location of data on the storage device. The storage device layer uses Physical Abbreviation (PBA) as the data addressing mechanism, where PBA represents the physical location of data on the storage device (i.e., its actual location on the storage device). In other words, a file stored in a storage device can be represented by LBA at the file system layer and by PBA at the storage device layer. In the following description and embodiments of this application, one LBA corresponds to one PBA. For example, this LBA and this PBA respectively represent the logical location and physical location of the first page of data (i.e., the first 4KB of data) of the file. Thus, by accessing the LBA corresponding to the file, the corresponding PBA can be accessed, thereby enabling operations such as reading or writing the file.

[0051] II. Physical Fragmentation of Files

[0052] Physical fragmentation of a file refers to the phenomenon where, when the logically consecutive logical base arguments (LBAs) of a file are arranged consecutively, the physical base arguments (PBAs) corresponding to these consecutively arranged LBAs become discontinuous. During prolonged use of electronic devices, files stored on storage devices may experience severe physical fragmentation (i.e., the file fragmentation rate increases) due to one or more factors, thus affecting file reading performance.

[0053] Figure 1 The diagram illustrates two scenarios that could lead to severe physical fragmentation. It is understood that severe physical fragmentation can also be caused by other factors, including but not limited to... Figure 1 Two of them.

[0054] Taking a single file as an example, this file corresponds to 6 logically consecutive LBAs, namely LBA1 to LBA6. LBA1 corresponds to PBA1, LBA2 corresponds to PBA2, LBA3 corresponds to PBA3, LBA4 corresponds to PBA4, LBA5 corresponds to PBA5, and LBA6 corresponds to PBA6.

[0055] like Figure 1 As shown, in a scenario of frequent file deletion and writing, assuming that during the initial writing to the storage device, PBA1 to PBA6 consecutively occupy the 1st to 6th positions of the storage device (at this time, the PBAs are arranged consecutively); when it is necessary to modify the data corresponding to LBA2, the data in PBA2 occupying the 2nd position must first be deleted, and then the data must be rewritten in an empty position. Optionally, this empty position is usually a new position, such as... Figure 1As shown, rewriting data at position 8 (no data was written before position 8) is equivalent to PBA2 re-occupying position 8 of the storage device. Simultaneously, when data corresponding to LBA4 needs to be deleted, the data in PBA4, which occupies position 4, needs to be deleted. Therefore, after modifying the data corresponding to LBA2 and deleting the data corresponding to LBA4, the PBAs for this file sequentially occupy positions 1, 3, 5, 6, and 8 of the storage device, resulting in a discontinuous PBA arrangement. It should be noted that when rewriting modified data, it's also possible to write data to the original position. For example, if data in PBA2 at position 2 is deleted, the storage device reclaims position 2, making it usable again for writing modified data. However, since in most cases, the storage device writes data to a new position rather than the original position, modifying file data will generally lead to a discontinuous PBA arrangement.

[0056] In a scenario of thread-interleaved writes, assuming multiple threads alternate writing to the storage device during the initial write operation, each thread may not immediately begin writing from the position where the previous thread finished, but instead finds a new free position in the storage device to start writing. Therefore, the following issues may occur: Figure 1 The phenomenon shown is that PBA1 and PBA2 occupy the first and second positions of the storage device consecutively, PBA3 and PBA4 occupy the fourth and fifth positions of the storage device consecutively, and PBA5 and PBA6 occupy the seventh and eighth positions of the storage device consecutively, resulting in a discontinuous arrangement of PBAs.

[0057] III. File-based Defragmentation (FBO)

[0058] FBO is a file-level defragmentation technology supported by Universal Flash Storage (UFS) Device 4.0 as specified in the Joint Electron Device Engineering Council (JEDEC) protocol. It involves a combination of hardware and software, with UFS being one type of storage device. FBO is primarily used to reorder the discontinuous PBAs and write the reordered PBAs into the storage device.

[0059] Figure 2 This diagram illustrates the effect before and after FBO (File Optimizer). LBA1 to LBA6 correspond one-to-one with PBA1 to PBA6. It is assumed that before FBO, the PBA corresponding to the file occupies a certain position in the storage device. Figure 2 As shown on the left, PBA1 and PBA2 consecutively occupy the first and second positions of the storage device, PBA3 and PBA4 consecutively occupy the fourth and fifth positions, and PBA5 and PBA6 consecutively occupy the seventh and eighth positions. When performing FBO on this file, PBA1 to PBA6 are first reordered consecutively, and then the consecutively arranged PBA1 to PBA6 are written into the six free consecutive positions. Optionally, a position segment with at least six free positions can be searched in the storage device to write PBA1 to PBA6, or the original positions occupied by PBA1 to PBA6 can be reclaimed first, and then a position segment with at least six free positions can be searched near the reclaimed position to write PBA1 to PBA6 (e.g., ...). Figure 2 (As shown on the right side of the middle section). Figure 2 It is known that FBO can effectively reduce the file fragmentation rate (that is, make the PBA corresponding to the file change from discontinuous arrangement to continuous arrangement). At this time, the correlation between the continuous arrangement of PBA can be used to improve the file reading performance.

[0060] Figure 3 A flowchart of the FBO process is shown, as follows: Figure 3 As shown, the host is a processor or controller, in which software is deployed to control the storage device to perform the FBO. The storage device is the storage medium that performs the FBO. For example, Figure 3 The storage device in this context can be universal flash storage (UFS). For example... Figure 3 As shown, the FBO process includes steps 301 to 305, wherein:

[0061] 301. The host obtains the FBO capability of the storage device.

[0062] Before the host controls the storage device to execute FBO, the host can send a query command to the storage device to query whether the storage device supports FBO and whether the storage device is currently executing FBO.

[0063] 302. The host determines the files to be optimized and the fragmentation rate threshold.

[0064] If the host determines that the storage device supports FBO and that FBO is not currently being performed on the storage device, the host can retrieve the LBA information of the file to be optimized from the file system. The file to be optimized refers to the file for which FBO needs to be performed, and the LBA information includes information indicating the LBAs corresponding to the file to be optimized. It should be noted that the LBAs corresponding to the file to be optimized may be distributed in segments; that is, all LBAs corresponding to the file to be optimized can be divided into multiple LBA segments (an LBA segment can also be called an entry). The LBAs within each LBA segment are contiguous; therefore, the LBA information of the file to be optimized includes information from each LBA segment of the file to be optimized.

[0065] The host also obtains the fragmentation level threshold required to perform FBO. The fragmentation level threshold is a preset condition that the storage device must meet when performing FBO according to the JEDEC protocol. Specifically, this preset condition means that the storage device will only perform FBO on the file to be optimized if the overall fragmentation rate of the file to be optimized is greater than or equal to the fragmentation level threshold; or, the storage device will only perform FBO on the file to be optimized if the fragmentation rate of certain LBA segments in the file to be optimized is greater than or equal to the fragmentation level threshold.

[0066] Optionally, different fragmentation rate thresholds can be pre-configured for different services. The host can first identify the service corresponding to the file to be optimized, and then obtain the fragmentation rate threshold for the file to be optimized based on the service it corresponds to.

[0067] 303. The host sends a fragmentation rate analysis command to the storage device.

[0068] The host sends a fragmentation rate analysis command to the storage device, which carries the LBA information of the file to be optimized. Based on the LBA information of the file to be optimized carried in the fragmentation rate analysis command, the storage device looks up the corresponding PBA of the file to be optimized in the LBA-PBA mapping table (flash translation layer, FTL). By analyzing the dispersion of the PBAs corresponding to the file to be optimized, the fragmentation rate level of each LBA segment in the file to be optimized and the overall fragmentation rate level of the file to be optimized are obtained.

[0069] 304. Host query fragmentation rate analysis completed and fragmentation rate analysis results obtained.

[0070] After the host issues a fragmentation rate analysis command, it can actively query the storage device to see if the fragmentation rate analysis is complete. Upon confirmation that the analysis is complete, the fragmentation rate analysis results are obtained. These results include the overall fragmentation rate level of the file to be optimized and the fragmentation rate level of each LBA segment within the file.

[0071] 305. The host sends a fragmentation rate optimization command to the storage device, and then queries whether the fragmentation rate optimization is complete.

[0072] The host compares the overall fragmentation rate of the file to be optimized with a fragmentation rate threshold, or compares the fragmentation rate of each LBA segment in the file with the fragmentation rate threshold. When the overall fragmentation rate of the file to be optimized is greater than or equal to the fragmentation rate threshold, or when the fragmentation rate of some LBA segments in the file is greater than or equal to the fragmentation rate threshold, a fragmentation rate optimization instruction (also known as a fragmentation rate defragmentation instruction, FBO execution instruction, etc.) is issued to the storage device. After receiving the fragmentation rate optimization instruction, the storage device performs FBO on the file to be optimized. After issuing the fragmentation rate optimization instruction, the host can also actively query whether the storage device's fragmentation rate optimization is complete (i.e., whether FBO is complete).

[0073] It should be noted that the specific hardware and software interactions between the FBO host and the device involved in steps 301 to 305 above can be referred to the relevant provisions of the FBO in the JEDEC protocol, and will not be elaborated here.

[0074] IV. Problems in FBO

[0075] For example, such as Figure 4 As shown, all LBAs corresponding to the file to be optimized are LBA1 to LBA7, where LBA1 to LBA7 occupy the 1st, 2nd, 4th, 5th, 6th, 8th and 9th positions respectively. Since LBA1 and LBA2 occupy consecutive positions, LBA3, LBA4 and LBA5 occupy consecutive positions, and LBA6 and LBA7 occupy consecutive positions, LBA1 to LBA7 are divided into three LBA segments: LBA segment 1 includes LBA1 and LBA2, LBA segment 2 includes LBA3, LBA4 and LBA5, and LBA segment 3 includes LBA6 and LBA7.

[0076] In related technologies, before the host sends a fragmentation rate optimization instruction to the storage device, the host compares the size (i.e., the length of each LBA segment) of the file to be optimized with an LBA segment size threshold. When the size of an LBA segment is greater than or equal to the LBA segment size threshold, the host sends a fragmentation rate optimization instruction to the storage device. This instruction carries information about the LBA segment, causing the storage device to perform a Free-Breakdown (FBO) on the PBA corresponding to that LBA segment. When the size of an LBA segment is less than the LBA segment size threshold, the fragmentation rate optimization instruction does not carry information about that LBA segment. Consequently, the storage device will not perform an FBO on the PBA corresponding to that LBA segment. This avoids the storage device frequently performing FBO on smaller LBA segments, thus protecting the lifespan of the storage device and improving the effectiveness of FBO. For example, if the LBA segment size threshold is equal to the size of three LBAs, then... Figure 4 The size of LBA segment 1 is less than the LBA segment size threshold, the size of LBA segment 2 is equal to the LBA segment size threshold, and the size of LBA segment 3 is less than the LBA segment size threshold. Therefore, the storage device only performs FBO on the PBA corresponding to each LBA in LBA segment 2.

[0077] However, in scenarios where the LBAs corresponding to the file to be optimized are relatively discrete, the number of LBA segments in the file to be optimized is large. If the number of LBA segments whose size is greater than or equal to the threshold size of that LBA segment is too small, performing FBO on it is equivalent to performing FBO on a small part of the file to be optimized, which cannot affect the overall fragmentation rate of the file to be optimized. That is, the overall fragmentation rate of the entire file to be optimized remains basically unchanged or decreases only slightly, wasting the computing resources of electronic devices and needlessly shortening the lifespan of storage devices. For example, when the LBA segments are relatively discrete, the number of LBA segments corresponding to the file to be optimized is much greater than 10. If there is only one LBA segment whose size is greater than or equal to the threshold size of that LBA segment, and this one LBA segment accounts for a very small portion of the total file size, then performing FBO on the file to be optimized in this case will likely not significantly reduce the overall fragmentation rate.

[0078] Normally, reducing the overall fragmentation rate of a file improves file read performance. However, in scenarios where the LBA (Level of Component Analysis) of the file to be optimized is highly discrete, performing an FBO (File Optimizer) leaves the overall fragmentation rate of the file largely unchanged or only slightly reduced, resulting in no change or even a decrease in read performance. Possible reasons for this decrease include, but are not limited to, the following two:

[0079] 1) The number of PBAs read in parallel may decrease, but will still be... Figure 4 For example, before performing FBO on the PBA corresponding to the LBA segment, such as Figure 4As shown on the left, PBA1 corresponding to LBA1, PBA3 corresponding to LBA3, and PBA2 corresponding to LBA2 occupy consecutive positions, and PBA6 corresponding to LBA6, PBA5 corresponding to LBA5, and PBA7 corresponding to LBA7 occupy consecutive positions. Therefore, PBA1, PBA3, and PBA2 can be read in parallel, as can PBA6, PBA5, and PBA7. However, after performing FBO on the PBA corresponding to the LBA segment, as... Figure 4 As shown on the right, only PBA3 corresponding to LBA3, PBA4 corresponding to LBA4, and PBA5 corresponding to LBA5 occupy consecutive positions. Only PBA3, PBA4, and PBA5 can be read in parallel. Therefore, the reading performance of the file to be optimized is reduced.

[0080] 2) When the processor is not frequency-locked, the file read speed is not fixed and will fluctuate under normal circumstances. Applying FBO to only a small part of the file to be optimized cannot significantly reduce the fragmentation rate of the entire file to be optimized. Therefore, FBO has limited improvement on the read performance of the file to be optimized and may not be able to offset the decrease in read performance during normal fluctuations.

[0081] In order to save computing resources of electronic devices and reduce the wear and tear on storage devices, this application proposes a data processing method and an electronic device, which includes, but is not limited to, terminal devices such as smartphones, tablets, laptops, desktop computers, smart speakers, smartwatches, smart vehicles, etc.

[0082] Figure 5 A schematic diagram of the hardware structure of an electronic device is shown. It should be understood that the electronic device can have more than Figure 5 The more or fewer components shown can be combined into two or more components, or they can have different component configurations. Figure 5 The various components shown can be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application-specific integrated circuits.

[0083] like Figure 5 As shown, the electronic device may include: a processor 110, a memory 120, and a display screen 194. Wherein:

[0084] Processor 110 may be a central processing unit (CPU), and may include one or more processing units, such as an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors.

[0085] The controller can serve as the nerve center and command center of an electronic device. Based on the instruction opcode and timing signals, the controller generates operation control signals to control the fetching and execution of instructions.

[0086] 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 subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0087] The processor 110 may also include a memory 120 for storing instructions and data. In some embodiments, the memory 120 in the processor 110 is a cache memory. The memory 120 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 memory 120. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system. In the embodiments of this application, the memory 120 can be non-volatile memory, such as flash memory, solid-state drive (SSD), etc.

[0088] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a miniature LED, a microLED, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device may have one or more display screens 194.

[0089] In this embodiment, the processor 110 controls whether to perform FBO on the file in the memory 120. Taking the processor 110 as a CPU and the memory 120 as UFS as an example, when the processor 110 determines that the FBO subprocess in the defragmentation process is triggered, the processor 110 can determine whether to perform FBO on the file in the UFS based on the first ratio corresponding to the file and the overall fragmentation rate of the file. Whether the fragmentation process is triggered can be determined based on whether the electronic device is in a screen-off charging state, the duration of the current screen-off charging of the display 194, and whether the interval between two adjacent screen-off charging sessions meets the triggering conditions. The first ratio corresponding to the file can characterize the proportion of LBA segments whose size exceeds the LBA segment size threshold among all LBA segments of the file. This avoids performing FBO on a small portion of the file, which not only saves the computing resources of the electronic device and reduces the wear and tear on the storage device, but also improves the file reading performance.

[0090] Based on the above, the data processing method provided in the embodiments of this application will be described in general below:

[0091] Figure 6 A flowchart illustrating a data processing method provided in an embodiment of this application is shown. Figure 6 The subject of the method shown can be an electronic device, or the subject can be a chip in the electronic device. Figure 6 The method will be explained using an electronic device as the execution subject as an example. The execution subjects of the methods shown in other figures of this application are similar and will not be repeated hereafter. The hardware structure of the electronic device can be referred to the above. Figure 5 The structure shown. Figure 6 The image processing method shown includes steps 601 to 602.

[0092] in:

[0093] Step 601: The electronic device determines the first ratio corresponding to the first file.

[0094] Wherein, the first proportion corresponding to the first file is the ratio of the first total size of the first file to the second total size of the first file. The first total size corresponding to the first file is the total size of LBA segments in the first file whose size is greater than or equal to the first threshold, and the second total size corresponding to the first file is the total size of the LBA segments in the first file. The first threshold is also the LBA segment size threshold introduced above.

[0095] For example, the first file has N LBA segments, including LBA segment 1, LBA segment 2, LBA segment 3, ... and LBA segment N. Assuming the first threshold is indicated by the value in the "dFBOMINLBARangeSize" field, and there are K LBA segments among these N LBA segments whose size is greater than or equal to the first threshold, and these K LBA segments are LBA segment 1, LBA segment 2, LBA segment 3, ..., LBA segment K, then the first proportion corresponding to the first file can be expressed by the following formula 1:

[0096]

[0097] Among them, L fn1The first proportion corresponds to the first file fn1, and SIZE() is used to calculate the total size of the LBA segments. The numerator in Formula 1 is the first total size corresponding to the first file, and the denominator is the second total size corresponding to the first file. It is understood that the K LBA segments in the above example can also be K discontinuous LBA segments. This application does not limit this. For example, if N is 10, and there are 3 LBA segments among the 10 LBA segments whose size is greater than or equal to the first threshold, then these 3 LBA segments can be LBA segment 1, LBA segment 2, and LBA segment 3, or these 3 LBA segments can be LBA segment 1, LBA segment 3, and LBA segment 9.

[0098] Specifically, firstly, the electronic device can obtain the LBA information corresponding to the first file. Then, based on the LBA information, it calculates the first total size and the second total size of the first file. Finally, the electronic device determines the first proportion corresponding to the first file based on the first total size and the second total size. The LBA information corresponding to the first file includes the information of each LBA segment (i.e., the information of logical address interval segments) in all LBA segments of the first file. The electronic device calculates the size of each LBA segment in all LBA segments of the first file based on the LBA information. After obtaining the statistical results, the electronic device compares the size of each LBA segment with a first threshold and determines the first total size and the second total size of the first file based on the comparison result.

[0099] Step 602: If the first ratio corresponding to the first file is greater than or equal to the second threshold, and the overall fragmentation rate of the first file is greater than or equal to the third threshold, then the electronic device performs FBO on the first file.

[0100] In this embodiment, the electronic device can determine the overall fragmentation rate of the first file. Specifically, the first file is actually stored on the first device. The electronic device sends the LBA information corresponding to the first file to the first device. The first device first finds the PBA corresponding to each LBA segment of the first file based on the LBA information (e.g., by looking up the PBA in the LBA-PBA mapping table (FTL table)). Then, it calculates the dispersion of the PBA corresponding to each LBA segment to obtain the fragmentation rate of each LBA segment (i.e., the fragmentation rate of the PBA corresponding to the LBA segment). Based on the fragmentation rate of each LBA segment, the overall fragmentation rate of the first file is obtained. Finally, the first device can report the fragmentation rate of each LBA segment and the overall fragmentation rate of the first file to the electronic device.

[0101] For example, the fragmentation rate of each LBA segment and the overall fragmentation rate of the first file can be represented as a level. For instance, the FBO protocol specified by JEDEC defines a regression level, also known as a fragmentation rate level, which includes the following 10 levels: 0x00 (corresponding to a fragmentation rate of 0%), 0x01 (corresponding to a fragmentation rate of 1%–10%), 0x02 (corresponding to a fragmentation rate of 11%–20%), 0x03 (corresponding to a fragmentation rate of 21%–30%), 0x04 (corresponding to a fragmentation rate of 31%–40%), 0x05 (corresponding to a fragmentation rate of 41%–50%), 0x06 (corresponding to a fragmentation rate of 51%–60%), 0x07 (corresponding to a fragmentation rate of 61%–70%), 0x08 (corresponding to a fragmentation rate of 71%–80%), 0x09 (corresponding to a fragmentation rate of 81%–90%), and 0x0A (corresponding to a fragmentation rate of 91%–100%).

[0102] Then, the electronic device can compare the first ratio corresponding to the first file with a second threshold, and compare the overall fragmentation rate of the first file with a third threshold. The second threshold is the condition that the first ratio must meet when performing FBO, and the third threshold is the condition that the overall fragmentation rate must meet when performing FBO (i.e.,...). Figure 3 The fragmentation rate thresholds described in the text can be, for example, level 0x05 (corresponding to a fragmentation rate of 41% to 50%):

[0103] If the first proportion corresponding to the first file is greater than or equal to the second threshold, and the overall fragmentation rate of the first file is greater than or equal to the third threshold, then the electronic device performs FBO on the first file. Conversely, if the first proportion corresponding to the first file is less than the second threshold, and / or the overall fragmentation rate of the first file is less than the third threshold, then the electronic device does not perform FBO on the first file.

[0104] Optionally, the electronic device may first obtain a first judgment result of whether the first ratio corresponding to the first file is greater than or equal to the second threshold, and a second judgment result of whether the overall fragmentation rate of the first file is greater than or equal to the third threshold, and then decide whether to perform FBO on the first file based on the first judgment result and the second judgment result.

[0105] Optionally, the electronic device can first obtain a first judgment result. If the first judgment result indicates that the first proportion corresponding to the first file is greater than or equal to a second threshold, a second judgment result can be obtained. Conversely, if the first judgment result indicates that the first proportion corresponding to the first file is less than the second threshold, it is not necessary to obtain the second judgment result. In this way, when the first proportion corresponding to the first file is less than the second threshold, the determination of the overall fragmentation rate (e.g., there is no need to issue fragmentation rate analysis instructions or fragmentation rate analysis result query instructions to the storage device) and the judgment can be reduced, thereby improving the judgment efficiency. Similarly, the electronic device can first obtain a second judgment result. If the second judgment result indicates that the overall fragmentation rate of the first file is greater than or equal to a third threshold, a first judgment result can be obtained. Conversely, if the second judgment result indicates that the overall fragmentation rate of the first file is less than the third threshold, it is not necessary to obtain the first judgment result. In this way, when the overall fragmentation rate of the first file is less than the third threshold, the determination of the first proportion (e.g., there is no need to determine the first total size and the second total size corresponding to the first file) and the judgment can be reduced, thereby improving the judgment efficiency.

[0106] It should be noted that the embodiments of this application preferentially adopt the method of obtaining the first judgment result first and then obtaining the second judgment result (that is, first judging the first ratio corresponding to the first file, and then judging the overall fragmentation rate corresponding to the first file).

[0107] The aforementioned second threshold (the condition that the first proportion must meet when performing FBO) can be obtained in the following two ways:

[0108] Method 1: The second threshold is a fixed value.

[0109] For example, a second threshold can be configured before the electronic device leaves the factory, or the second threshold can be configured by receiving a server and then kept unchanged. In this method, the second threshold can be an experience value set by professionals, for example, the second threshold can be set to P = 60%. If the third threshold is configured to level 0x05, then when the overall fragmentation rate level of the first file is greater than or equal to 0x05, and the first proportion L corresponding to the first file... fn1 If the percentage is ≥60%, perform FBO on the first file; otherwise, do not perform FBO on the first file.

[0110] Method 2: The second threshold can be a non-fixed value.

[0111] The electronic device can obtain the second threshold through reinforcement learning, specifically involving the following two steps:

[0112] 1) Electronic devices acquire training data.

[0113] In one possible implementation, the training data includes M file groups. The M file groups are obtained by the electronic device acquiring a first file set, where the overall fragmentation rate of each file in the first file set is greater than or equal to a third threshold, and the files in the first file set are grouped to obtain M file groups.

[0114] When applying the scheme, this application determines whether to execute FBO based on the first ratio and the overall fragmentation rate. In order to follow the principle of a single variable to learn the influence of the second threshold on whether the first ratio meets the condition, training data with an overall fragmentation rate greater than or equal to the third threshold can be selected.

[0115] In one possible implementation, the electronic device can first determine the files with an overall fragmentation rate greater than or equal to a third threshold from the file set corresponding to the first service, thus obtaining the first file set.

[0116] In one example, the first service could be the service to which the first file belongs. In another example, the first service could be a service with similar storage attributes to the service to which the first file belongs. Storage attributes include, but are not limited to, one or more of the following: file content, file importance, file hotness / coldness, or file storage granularity.

[0117] Because file storage attributes differ across different services, such as file content, importance, popularity, or storage granularity, the first proportion corresponding to files across different services may vary too much, making the same second threshold unsuitable for files from different services. Therefore, a first file set can be determined based on files corresponding to the first service to which the first file belongs, or files corresponding to services with similar storage attributes to the first file, in order to learn a second threshold applicable to the first file based on the first file set.

[0118] Optionally, the electronic device may also identify files with an overall fragmentation rate greater than or equal to a third threshold from all files, regardless of business differences, to obtain a first set of files, and then determine a more general second threshold.

[0119] Furthermore, the electronic device can group the first set of files into M file groups, where M is a positive integer greater than or equal to 1.

[0120] In one possible implementation, the electronic device determines a first proportion corresponding to each file in the first file set; based on the first proportion corresponding to each file in the first file set, the files in the first file set are grouped to obtain M file groups.

[0121] To ensure a uniform distribution of training data and improve the learning effect of the second threshold, the files in the first file set can be uniformly grouped. Uniform grouping means that the similarity between the distribution of the first proportion of files in any two file groups is greater than the similarity threshold.

[0122] In one example, the electronic device can first divide the files in the first file set into groups corresponding to different intervals according to the intervals in which the first proportion is located, and then evenly select files from the groups corresponding to different intervals and distribute them into M file groups.

[0123] For example, the first proportions corresponding to the files in the first file set are {90%, 88%, 45%, 50%, 10%, 10%}. Assuming three pre-set intervals for the first proportions are interval 1 (0%–33%), interval 2 (33%–66%), and interval 3 (67%–100%), the electronic device first assigns files with first proportions of 90% and 88% to the group corresponding to interval 3, files with first proportions of 45% and 50% to the group corresponding to interval 2, and files with first proportions of 10% and 10% to the group corresponding to interval 1. Then, it evenly selects one file from each interval's corresponding group and places it into the file group, resulting in two file groups: file group 1 contains files with first proportions of {90%, 45%, 10%}, and file group 2 contains files with first proportions of {88%, 50%, 10%}.

[0124] In another example, the electronic device may first sort the files in the first file set according to a first ratio from high to low or from low to high, and then distribute the files in the first file set evenly into M file groups according to the sorting results. For example, if the first proportions of each file in the first file set are {8%, 10%, 23%, 29%}, and we need to obtain two file groups (i.e., M is 2), to make the distribution of the first proportions of the files in the two file groups similar, we can select a file in the first round of grouping according to the order of the first proportion from low to high and assign it to file group 1 and file group 2 (e.g., assign the file with the first proportion of 8% to file group 1 and the file with the first proportion of 10% to file group 2). Then, in the second round of grouping, we can select a file in the order of the first proportion from high to low and assign it to file group 2 and file group 1 (e.g., assign the file with the first proportion of 23% to file group 2 and the file with the first proportion of 29% to file group 1). In this way, the first proportions of the files in file group 1 are {8%, 29%}, and the first proportions of the files in file group 2 are {10%, 23%}.

[0125] It should be noted that the methods for obtaining M filegroups include, but are not limited to, the two examples mentioned above, and this application does not limit them. Furthermore, the value of M can be the same or different for different business needs, and this application does not limit it either way.

[0126] 2) The electronic device determines the second threshold based on the training data through reinforcement learning.

[0127] The training data consists of M file groups obtained in step 1).

[0128] In one possible implementation, the electronic device selects a first file group from M file groups and learns the interception threshold based on the first file group through reinforcement learning; if the termination condition of reinforcement learning is not triggered, a second file group is selected from the M file groups and the interception threshold is learned based on the second file group through reinforcement learning.

[0129] In this context, both the first and second filegroups are arbitrary filegroups from the M filegroups. This possible implementation is equivalent to selecting any filegroup from the M filegroups each time to participate in one round of reinforcement learning for the interception threshold. The second threshold is the interception threshold when the termination condition of reinforcement learning is triggered.

[0130] To facilitate understanding, the basic principles of reinforcement learning will be introduced below:

[0131] like Figure 7 As shown, reinforcement learning is a learning process where an agent learns through trial and error. It gains rewards by interacting with the environment, guiding its actions to achieve greater rewards. Reinforcement learning consists of multiple rounds. In each round, the agent learns the state of the environment, selects an action to perform, and then receives the reward for that action and the new environment after the action is executed, to proceed to the next round of learning. Reinforcement learning algorithms can be divided into two main categories: model-free reinforcement learning and model-based reinforcement learning. Model-based reinforcement learning relies on an environment model (state transition probabilities and reward functions). Model-free reinforcement learning does not rely on an environment model (state transition probabilities and reward functions); it directly acquires experience data through interaction with the environment and learns and optimizes based on this data.

[0132] The Q-learning algorithm used in this embodiment of the application is a model-free reinforcement learning algorithm. The specific steps of the Q-learning algorithm include steps ① to ⑦:

[0133] ① Initialize the Q-value list.

[0134] The Q-value list records the long-term reward obtainable by taking different actions in each state. Initializing the Q-value list includes, but is not limited to, setting all values ​​in the list to 0 or setting them to preset values.

[0135] ② Determine the current state S;

[0136] In the initial case, the current state S can be any state.

[0137] ③ In the current state S, select action A according to the strategy;

[0138] The strategy can be an ∈-greedy strategy, where ∈-greedy means that each time there is a probability ∈ to randomly select an action from all actions corresponding to the current state S, and each time there is a probability of 1-∈ to select the action with the largest Q value from all actions corresponding to the current state S. For example, the initial value of ∈ can be 1, and as the number of learning rounds increases, the value of ∈ is gradually decreased, such as decreasing by 0.05 per round.

[0139] ④ Perform the selected action A;

[0140] ⑤ Determine the new state S to which action A transitions after execution. ′ And obtain the reward R after the action a is performed;

[0141] ⑥ Update the Q-value list.

[0142] The formula for updating the Q value (also referred to below as the Q-value function) can be found in Formula 2 below:

[0143] Q(S,A)←Q(S,A)+α(R+γmax a Q(S ′ ,a)-Q(S,A))(Formula 2)

[0144] Where S represents the current state, A represents the current action, and R represents the immediate reward obtained from executing A. ′ Let S represent the new state, 'a' represent the next action, α represent the learning rate, and γ represent the decay (discount) factor (e.g., 0.9). Q(S,A) represents the Q value of performing action A when the state is S. a Q(S ′ a) indicates that in state S ′ When that happens, select the action with the largest Q value from all actions.

[0145] The Q-value update function means that the current Q-value and the newly estimated Q-value are weighted averaged, and the Q-value is gradually converged to the optimal value through Q-value updates. α controls the weight of the new estimated value, and γ controls the degree of emphasis on future returns.

[0146] ⑦ Change the new state S′ The current value is determined as S, and the above steps ③ to ⑦ are executed again until the termination condition of reinforcement learning is triggered.

[0147] This application embodiment can perform reinforcement learning based on the Q-learning algorithm described above. In this application, the termination condition for reinforcement learning in step ⑦ can be one or more of the following: a preset number of learning rounds, a preset learning duration (e.g., 7 days), or convergence of the Q-value function. The specific implementation method of each learning round in this application is as follows:

[0148] Taking a single round of learning as an example, assuming the files participating in the first round of learning are the first file group, the process includes:

[0149] Based on the status information of the first file group and the first policy, the interception threshold is updated; the status information of the first file group is updated based on the updated interception threshold; the reward value after the interception threshold is updated is obtained, and the first policy is updated based on the reward value after the interception threshold is updated, the updated status information of the first file group, and the first policy.

[0150] The following describes how the status information, the first strategy, and the reward value of the first file group are set in this application:

[0151] Status information for the first file group:

[0152] The state information of the first file group is the state in the Q-learning algorithm. Determining the state information of the first file group is equivalent to determining the current state S in step ② of the Q-learning algorithm.

[0153] In one possible implementation, the status information of the first file group includes a first quantity, a second quantity, a third quantity, a fourth quantity, a fifth quantity, and a sixth quantity associated with the first file group.

[0154] The electronic device can obtain the interception threshold corresponding to the current learning round, and then determine the first, second, third, fourth, fifth, and sixth quantities based on the interception threshold. For the first round, the interception threshold can be a preset initial value or a value obtained after the previous multi-round reinforcement learning; for the remaining rounds other than the first round, the interception threshold is the value obtained after the previous round of learning.

[0155] The first quantity is the number of files in the first file group whose first proportion is greater than or equal to the interception threshold.

[0156] The second quantity is the number of files in the first file group whose first proportion is less than the interception threshold.

[0157] The third quantity is the number of files in the first file group whose first proportion is greater than or equal to the interception threshold and whose overall fragmentation rate decreases after FBO is executed.

[0158] The fourth quantity is the number of files in the first file group whose first proportion is greater than or equal to the interception threshold and whose overall fragmentation rate does not decrease after FBO is executed.

[0159] The fifth quantity is the number of files in the first file group whose first proportion is less than the interception threshold and whose overall fragmentation rate decreases after FBO is executed.

[0160] The sixth quantity is the number of files in the first file group whose first proportion is less than the interception threshold and whose overall fragmentation rate does not decrease after FBO is executed.

[0161] For example, suppose the first file group contains T files. Then, according to the above definition, the sum of the first and second numbers is T, the sum of the third and fourth numbers is the first number, and the sum of the fifth and sixth numbers is the second number.

[0162] For example, T is 4. Table 1 is a state information table proposed in the embodiments of this application. The state information corresponding to the first file group can be any of the ones in Table 1. Optionally, the state information table may be empty in the initial case, and state information is gradually added through each round of learning.

[0163] Table 1

[0164]

[0165]

[0166] If the first ratio of all four files in the first filegroup is greater than or equal to the interception threshold, then after FBO is performed on the first filegroup, the overall fragmentation rate of each file will decrease or not decrease, corresponding to S1 to S5 in Table 1; if the first ratio of three files in the first filegroup is greater than or equal to the interception threshold and the first ratio of one file is less than the interception threshold, then after FBO is performed on the first filegroup, the overall fragmentation rate of each file will decrease or not decrease, corresponding to S6 to S13 in Table 1; if the first ratio of two files in the first filegroup is greater than or equal to the interception threshold and the first ratio of two files is less than the interception threshold... If, after performing FBO on the first file group, the overall fragmentation rate of each file decreases or does not decrease, the results correspond to S14 to S22 in Table 1. If the first proportion corresponding to one file in the first file group is greater than or equal to the interception threshold and the first proportion corresponding to three files is less than the interception threshold, the overall fragmentation rate of each file after performing FBO on the first file group decreases or does not decrease, the results correspond to S23 to S30 in Table 1. If the first proportion corresponding to all four files in the first file group is less than the interception threshold, the overall fragmentation rate of each file after performing FBO on the first file group decreases or does not decrease, the results correspond to S31 to S35 in Table 1.

[0167] First strategy:

[0168] The first strategy can be an ∈-greedy strategy, and the Q-value update in the ∈-greedy strategy can refer to Formula 2 above, which will not be elaborated further here. The action in the first strategy refers to updating the interception threshold corresponding to the current learning round. The update method is equivalent to the action type, and can be defined as follows:

[0169] In one example, the electronic device can raise the current blocking threshold, lower the current blocking threshold, or keep the current blocking threshold unchanged.

[0170] Optionally, the amount of change for both the increase and decrease can be fixed values.

[0171] Optionally, the amount of increase or decrease can be a value determined based on a first proportion.

[0172] For example, suppose the interception threshold corresponding to the current learning round is P1, the updated interception threshold is P2, and the first proportion greater than or equal to P1 is L. R The first ratio corresponding to files smaller than P1 is L. U , {L R} indicates that the first proportion of the files in the first filegroup is L. R The set formed, {L U} indicates that the first proportion of the files in the first filegroup is L.U The set constitutes the first file group. For example, the first file group consists of 4 files, and the first proportions of these 4 files are {40%, 50%, 60%, 70%}. Assuming P1 is 55%, then {L R} is {60%, 70%}, {L U} is {40%, 50%}.

[0173] Based on these definitions, Table 2 shows the possible ways to update the current blocking threshold:

[0174] Table 2

[0175]

[0176] The update method for serial number A1, "P2 = min(P1 + 5%, 100%)", means that P2 takes the minimum value between P1 + 5% and 100%, which allows P1 to be increased by 5% and P1 to be increased to a maximum of 100%.

[0177] The update method for serial number A2, "P2 = max(0, P1 - 5%)", means that P2 takes the maximum value between 0 and P1 - 5%, which allows P1 to be fixedly reduced by 5% and P1 to be reduced to a minimum of 0%.

[0178] The update method for serial number A3 includes two cases: "If max({L U If})+5%>P1, then P2=min(max({L U}+5%)min({L R}))” means: if {L R If the sum of the maximum value in} and 5% is higher than P1, then P2 takes the value max({L U}+5%) and min({L) R The minimum value in}); "If max({L U If})+5%≤P1, then P2=min(P1+5%,min({L) R}))” means: if {L R If the sum of the maximum value and 5% in} is less than P1, then P2 takes the value of P1 + 5% and min({L R The minimum value in}. This allows P1 to increase by at most 5% to obtain P2. With P1 at 55%, {L R} is {60%, 70%}, {L U Taking {40%, 50%} as an example, since max({L U})+5%=55% satisfies the second of the two cases above, and P1+5%=60%, min({L) R}) = 60%, so P2 = min(60%, 60%) = 60%. With P1 being 55%, {L R}) being {60%, 70%}, {L U}) being {40%, 53%} as an example, since max({L U}) + 5% = 58% meets the first of the above two cases, and max({L U}+5%) = 58%, min({L R}) = 60%, so P2 = min(58%, 60%) = 58%.

[0179] The update method of serial number A4 "P2 = max({L R})" means that: P2 takes the maximum value in {L R}}.

[0180] The update method of serial number A5 includes two cases: "If min({L R}) - 5% < P1, then P2 = max(min({L R}) - 5%, max({L U}))" means that: If the difference between the minimum value in {L R}} and 5% is lower than P1, then P2 takes the maximum value between min({L R}) - 5% and max({L U}); "If min({L R}) - 5% ≥ P1, then P2 = max(P1 - 5%, max({L U}))" means that: If the difference between the minimum value in {L R}} and 5% is higher than P1, then P2 takes the maximum value between P1 - 5% and max({L U}). This can make P1 decrease by at most 5% to obtain P2. With P1 being 55%, {L R}) being {60%, 70%}, {L U}) being {40%, 50%} as an example, since min({L R}) - 5% = 55% meets the second of the above two cases, and P1 - 5% = 50%, max({L U}) = 50%, so P2 = max(50%, 50%) = 50%. With P1 being 55%, {L R}) being {58%, 70%}, {L U}) being {40%, 50%} as an example, since min({L R}) - 5% = 53% meets the first of the above two cases, and min({L R})-5%=53%,max({L U Since 50% = 50%, therefore P2 = max(53%, 50%) = 53%.

[0181] The update method for serial number A6 is "P2 = min({L U})” means: P2 takes the value {L U The minimum value in}.

[0182] The update method "P2 = P1" for serial number A7 means: keep P1 unchanged.

[0183] The update method "P2 = 0%" for serial number A8 means: reduce P1 to 0% to obtain P2.

[0184] It is understood that the above-mentioned method for updating the current interception threshold is only an example, and there may be other methods in specific implementations, which are not limited in this application.

[0185] Reward value:

[0186] The reward value is the immediate reward in the Q-learning algorithm. The reward value after the interception threshold is updated is equivalent to the reward obtained after the action is executed in step ⑤ of the Q-learning algorithm above.

[0187] In one round of learning, after the electronic device determines the status information of the first file group, it can update the interception threshold corresponding to the current round according to the first strategy, and then perform FBO on all files in the first file group. Then, the electronic device can obtain the reward value after the interception threshold is updated in this round of learning.

[0188] The reward value is set as follows:

[0189] The objective of reinforcement learning in this application is to reduce the overall fragmentation rate of all files whose first proportion is greater than or equal to the interception threshold, while ensuring that the overall fragmentation rate of all files whose first proportion is less than the interception threshold remains unchanged. Based on this objective, this application can determine the reward value in the following manner:

[0190] In the first approach, the updated status information of the first file group is determined based on the updated interception threshold and whether the overall fragmentation rate of each file in the first file group decreases or does not decrease after FBO is executed; the reward value after the updated interception threshold is determined based on the status information of the first file group and the updated status information of the first file group.

[0191] Based on the updated interception threshold and whether the overall fragmentation rate of each file in the first file group decreases or does not decrease after FBO is executed, the first, second, third, fourth, fifth, and sixth quantities in the status information of the first file group can be updated (i.e., the updated status information of the first file group is obtained).

[0192] Electronic devices can determine the following based on the changes in these six quantities before and after the interception threshold update: all positive improvements / only positive improvements with no deterioration / overall positive improvements / overall no improvements / overall deterioration / only deterioration with no improvement / all deterioration (equivalent to determining based on the changes in the groups into which files in the first filegroup are assigned before and after the interception threshold update), in order to obtain the reward value after the interception threshold update. The meanings of all positive improvements / only positive improvements with no deterioration / overall positive improvements / overall no improvements / overall deterioration / only deterioration with no improvement / all deterioration are explained below:

[0193] All positive improvements: If, before the interception threshold is updated, there are fourth and / or fifth quantities that are not zero (i.e., before the interception threshold is updated, the overall fragmentation rate of files with a first proportion greater than or equal to the interception threshold has not decreased (not in line with the reinforcement learning objective), and / or, the overall fragmentation rate of files with a first proportion less than the interception threshold has decreased (not in line with the reinforcement learning objective)), and after the interception threshold is updated, both the fourth and fifth quantities are zero (the overall fragmentation rate of all files with a first proportion greater than or equal to the updated interception threshold has decreased; and the overall fragmentation rate of all files with a first proportion less than the updated interception threshold has not decreased), then it means that the results after the interception threshold is updated all meet the reinforcement learning objective. This situation is considered an all positive improvement for the first file group. For example, the first file group includes 4 files with first proportions of 10%, 11%, 20% and 70% respectively, and overall fragmentation rates of no reduction, no reduction, no reduction and reduction respectively. If the interception threshold was previously 15%, the status information of the first file group corresponds to S21 in Table 1 above (at this time, the fourth quantity is not 0 because the interception threshold is set too low and is not suitable for 20% of the files). If the interception threshold is updated to 30%, the status information of the first file group is updated to S29 in Table 1 above.

[0194] Only positive improvement and no deterioration: If the fourth and / or fifth numbers are not zero before the interception threshold is updated, and the fourth and / or fifth numbers decrease after the interception threshold is updated, but the fourth and / or fifth numbers are still not zero, then it means that the result after the interception threshold is updated can approach the reinforcement learning target, but still cannot reach the reinforcement learning target. This situation is called the first file group having only positive improvement and no deterioration. For example, the first file group includes 4 files with first proportions of 10%, 11%, 18% and 23%, and overall fragmentation rates of no reduction, no reduction, no reduction and no reduction, respectively. If the interception threshold was 15% before, the state information of the first file group corresponds to S22 in Table 1 above (at this time, the fourth number is not zero because the interception threshold is set too low and is not suitable for 18% and 23% of the files). If the interception threshold is updated to 20%, the state information of the first file group is updated to S30 in Table 1 above (at this time, the fourth number decreases from 2 to 1 because the updated interception threshold is suitable for 18% of the files, but is still not suitable for 23% of the files).

[0195] Optionally, if there are fourth and / or fifth non-zero numbers before the interception threshold is updated, and the fourth number decreases and the fifth number increases after the interception threshold is updated, or the fifth number decreases or the fourth number increases, then it means that the result of the updated interception threshold can bring some files closer to the reinforcement learning target and make other files farther away from the reinforcement learning target. In this case, the first file group is generally positively improved / not improved / deteriorated.

[0196] Overall positive improvement: If the number of files closer to the reinforcement learning target (hereinafter referred to as A) exceeds the number of files farther from the reinforcement learning target (hereinafter referred to as B), then the first file group has an overall positive improvement. For example, the first file group includes 4 files with first proportions of 10%, 20%, 21%, and 35%, respectively, and overall fragmentation rates of no reduction, no reduction, no reduction, and reduction, respectively. If the interception threshold was previously 15%, then the status information of the first file group corresponds to S12 in Table 1 above (at this time, the fourth quantity is 2, which is not equal to 0, because the interception threshold is set too low and is not suitable for 20% and 21% of the files). If the interception threshold is increased to 50%, then the status information of the first file group is updated to S34 in Table 1 above (at this time, the fourth quantity decreases from 2 to 0, but because the interception threshold is increased too high and is not suitable for 35% of the files, the fifth quantity increases from 0 to 1), which is equivalent to A equaling 2 and B equaling 1. At this time, the first file group has an overall positive improvement.

[0197] No overall improvement: If A equals B, then the first filegroup shows no overall improvement. For example, the first filegroup includes four files with first proportions of 10%, 20%, 29%, and 35%, respectively, and overall fragmentation rates of no reduction, no reduction, reduction, and reduction, respectively. If the interception threshold was previously 15%, the status information of the first filegroup corresponds to S11 in Table 1 above (at this time, the fourth quantity is 1, not equal to 0, because the interception threshold is set too low and is unsuitable for 20% of the files). If the interception threshold is increased to 30%, the status information of the first filegroup is updated to S27 in Table 1 above (at this time, the fourth quantity decreases from 1 to 0, but because the interception threshold is increased too high and is unsuitable for 29% of the files, the fifth quantity increases from 0 to 1), equivalent to A equaling 1 and B equaling 1. In this case, the first filegroup shows no overall improvement. Optionally, no overall improvement may also occur if the first, second, third, fourth, fifth, and sixth quantities remain unchanged before and after the interception threshold update, equivalent to the status information of the first filegroup being the same before and after the update. For example, the first file group includes 4 files with first proportions of 10%, 20%, 29% and 35% respectively, and overall fragmentation rates of no reduction, no reduction, reduction and reduction respectively. If the interception threshold was previously 15%, the status information of the first file group corresponds to S11 in Table 1 above. If the interception threshold is increased from 15% to 18%, the status information of the first file group is still S11 in Table 1 above.

[0198] Overall Deterioration: If A is less than B, then the first file group deteriorates overall. For example, the first file group includes 4 files with first proportions of 10%, 20%, 29%, and 35%, respectively, and overall fragmentation rates of no reduction, no reduction, reduction, and reduction, respectively. If the interception threshold was previously 15%, then the status information of the first file group corresponds to S11 in Table 1 above (at this time, the fourth quantity is 1, not equal to 0, because the interception threshold is set too low and is not suitable for 20% of the files). If the interception threshold is increased to 50%, then the status information of the first file group is updated to S33 in Table 1 above (at this time, the fourth quantity decreases from 1 to 0, but because the interception threshold is increased too high and is not suitable for 29% and 35% of the files, the fifth quantity increases from 0 to 2), which is equivalent to A equaling 1 and B equaling 2. At this time, the first file group deteriorates overall.

[0199] Only deterioration without improvement: If the fourth and / or fifth numbers are not zero before the interception threshold is updated, and the fourth and / or fifth numbers do not decrease but increase after the interception threshold is updated, but the third and / or sixth numbers are still zero, then it means that the result after the interception threshold update is far from the reinforcement learning target, but not completely far from the reinforcement learning target. This situation is called the first file group only deteriorating without improvement. For example, the first file group includes 4 files with first proportions of 10%, 12%, 18% and 23%, and overall fragmentation rates of no reduction, no reduction, no reduction and no reduction, respectively. If the interception threshold was 15% before, the state information of the first file group corresponds to S22 in Table 1 above (at this time, the fourth number is 2 and not zero because the interception threshold is set too low and is not suitable for 18% and 23% of the files). If the interception threshold is reduced to 11%, the state information of the first file group is updated to S13 in Table 1 above (at this time, the fourth number increases from 2 to 3 because the updated interception threshold is not suitable for 12%, 18% and 23% of the files).

[0200] All deteriorate: If the fourth and / or fifth numbers are not zero before the interception threshold is updated, and the fourth and / or fifth numbers do not decrease but increase after the interception threshold is updated, and the third and sixth numbers are both zero, then it means that the result after the interception threshold is updated is completely far from the reinforcement learning target. This situation is called the first file group deteriorating. For example, the first file group includes 4 files with first proportions of 10%, 12%, 18%, and 23%, and overall fragmentation rates of no reduction, no reduction, no reduction, and no reduction, respectively. If the interception threshold was 15% before, the state information of the first file group corresponds to S22 in Table 1 above (at this time, the fourth number is 2 and not zero because the interception threshold is set too low and is not suitable for 18% and 23% of the files). If the interception threshold is reduced to 8%, the state information of the first file group is updated to S5 in Table 1 above (at this time, the fourth number increases from 2 to 4, and the third and sixth numbers are both zero because the updated interception threshold is not suitable for 10%, 12%, 18%, and 23% of the files).

[0201] Furthermore, the updated reward values ​​for the interception thresholds corresponding to the above-mentioned positive improvements, only positive improvements and no deterioration, overall positive improvements, no overall improvements, overall deterioration, only deterioration and no improvement, and all deterioration can be found according to Table 3 below.

[0202] Table 3

[0203]

[0204] It should be noted that the values ​​of each reward in Table 3 are only examples, and there may be other ways to take the values ​​in the actual implementation. This application does not limit this.

[0205] In the second approach, the reward value after the interception threshold update can also be determined based on the changes in the six quantities mentioned above before and after the interception threshold update (i.e., the changes from the first to the sixth quantity) and the reward value corresponding to each file. Specifically, based on the changes in these six quantities before and after the interception threshold update, it can be determined whether the first file group is one of the following: all positive improvements, only positive improvements without deterioration, overall positive improvement, overall no improvement, overall deterioration, only deterioration without improvement, or all deterioration. If the first file group is any one of all positive improvements, only positive improvements without deterioration, only deterioration without improvement, or all deterioration, then the reward value after the interception threshold update is a fixed value. If the first file group is any one of overall positive improvement, overall no improvement, or overall deterioration, then the reward value after the interception threshold update is a non-fixed value calculated according to the formula. For example, this approach can correspond to the following Table 4:

[0206] Table 4

[0207]

[0208] For example, in Table 4, all positive improvements, only positive improvements with no deterioration, only deterioration with no improvement, or all deterioration correspond to fixed reward values ​​of 100, 2, -2, and -100, respectively. These fixed reward values ​​can also have other values, which are not limited. Overall positive improvement, overall no improvement, or overall deterioration need to be calculated using a formula. It should be noted that the maximum reward value calculated using the formula must be less than the reward value corresponding to only positive improvements with no deterioration (i.e., less than 2), and the minimum reward value calculated using the formula must be greater than the reward value corresponding to only deterioration with no improvement (i.e., greater than -2). This setting allows for a more accurate determination of the reward values ​​corresponding to overall positive improvement, no overall improvement, or overall deterioration. For example, when A is 2 and B is 1, it is determined that two files in the first file group are close to the reinforcement learning target, and one file is far away from the reinforcement learning target. Although the first file group shows overall positive improvement in terms of the number of files, if the total degree of the two files close to the reinforcement learning target is less than the degree of the one file far away from the reinforcement learning target, the first file group may not show overall positive improvement in terms of whether it is close to the reinforcement learning target. Therefore, in order to obtain the accurate reward values ​​corresponding to overall positive improvement, no overall improvement, or overall deterioration, it is necessary to calculate the reward value corresponding to each file according to the formula, and then determine the reward value after the interception threshold is updated based on the reward value corresponding to each file.

[0209] In the third method, the changes in the above six quantities before and after the interception threshold update can be ignored, and the reward value after the interception threshold update can be directly calculated based on the formula.

[0210] The following explains how to calculate and determine the updated reward value for the interception threshold based on a formula:

[0211] Specifically, the electronic device determines the reward value for each file in the first file group based on the first ratio corresponding to each file in the first file group and whether the overall fragmentation rate decreases after each file performs FBO; based on the reward value corresponding to each file in the first file group, it determines the reward value after the interception threshold is updated.

[0212] Specifically, the electronic device can perform a weighted summation of the reward values ​​corresponding to each file in the first file group to obtain the updated reward value after the interception threshold is set. For example, the updated reward value R after the interception threshold is obtained by referring to the following formula 3:

[0213] R = R File1 *W1+R Fike2 *W2+...(Formula 3)

[0214] Among them, R File1 W1 refers to the reward value corresponding to the first file in the first file group, and R refers to the weight corresponding to the first file. File2 W1 refers to the reward value corresponding to the second file in the first file group, W2 refers to the weight corresponding to the second file, and so on.

[0215] Optionally, assuming the second file is a file in the first file group, and the first proportion corresponding to the second file is greater than or equal to the updated interception threshold (i.e., P2 above), the reward value corresponding to the second file is determined as follows:

[0216] 1) If the overall fragmentation rate of the second file decreases after performing FBO on the second file, the reward value corresponding to the second file will be positive; 2) If the overall fragmentation rate of the second file does not decrease after performing FBO on the second file, the reward value corresponding to the second file will be negative or zero.

[0217] Case 1 (When the overall fragmentation rate of the second file decreases after performing FBO on the second file):

[0218] In one example, the electronic device can determine the reward value corresponding to the second file based on the first ratio corresponding to the second file.

[0219] For example, the reward value (positive value) corresponding to the second file can be determined according to the following formula 4:

[0220] R File =1-L File (Formula 4)

[0221] In formula 4, L File R represents the first proportion corresponding to a file. File This represents the reward value corresponding to a file. In Formula 4, L File With R File It is inversely proportional, and this setting is because: when L File The higher the threshold, the more LBA segments in a file are greater than or equal to the first threshold. This means there are more LBA segments in a file that will execute FBO, and therefore the probability of a file's overall fragmentation rate decreasing after FBO is executed is higher. For example, L... File When L = 100%, the probability of a decrease in the overall fragmentation rate is itself 100%; File When L = 0%, the probability of a decrease in the overall fragmentation rate is inherently 0. Based on this, when L... File The higher the value, the more R will be. File (Positive value) is set lower, that is, L in formula 4 File With R File It shows an inverse relationship.

[0222] In another example, the electronic device can also determine the reward value corresponding to the second file based on the first ratio and the fourth threshold.

[0223] The fourth threshold is used to represent the degree of influence of the first ratio corresponding to the file on the reduction of file fragmentation rate. The fourth threshold can be an experience value set by professionals. For example, when the first ratio corresponding to the file is greater than or equal to the fourth threshold, it means that the first ratio corresponding to the file has a significant impact on the reduction of the overall file fragmentation rate; conversely, when the first ratio corresponding to the file is less than the fourth threshold, it means that the first ratio corresponding to the file has a very small impact on the reduction of the overall file fragmentation rate.

[0224] Based on this principle, when the first proportion corresponding to the second file is greater than or equal to the fourth threshold, the reward value corresponding to the second file can be determined according to Formula 5 below; when the first proportion corresponding to the second file is less than the fourth threshold, the reward value corresponding to the second file can be determined according to Formula 6 below.

[0225] R File =1-(L File -FIL) (Formula 5)

[0226] R File =1-L File +(FIL-L File ) (Formula 6)

[0227] Formula 6, compared to Formula 4, adds "+(FIL-L"). FileThis setting is based on the fact that when the first proportion is less than the fourth threshold, the probability of an overall fragmentation rate decrease is inherently low. Therefore, if an overall fragmentation rate decrease occurs despite the already low probability of such a decrease, a positive reward value should be added, i.e., through "+(FIL-L)". File To further improve the calculation, Formula 4 can be modified to Formula 5 to calculate the reward value corresponding to the second file when the first proportion is greater than or equal to the fourth threshold. Formula 5 adds "-(-FIL)" compared to Formula 4, which is equivalent to "+FIL". This reduces the gap with Formula 6, making the data distribution more balanced during the learning process. It is understood that the reward value of the positive value obtained based on Formula 6 can be greater than 1, and this application does not limit this.

[0228] For example, suppose the first filegroup contains four files: File1, File2, File3, and File4. If File1 corresponds to the first proportion L... File1 The first ratio L corresponding to File2 File2 The first ratio L corresponding to File3 is greater than or equal to the updated interception threshold (i.e., P2 above). File3 The first scale L corresponding to File4 File4 If the fragmentation rate is less than the updated interception threshold (i.e., P2 above), then File1 and File2 are equivalent to two second files in the first filegroup. Assuming that performing FBO on File1 reduces its overall fragmentation rate, then in the following example:

[0229] In one example, according to Formula 4 above:

[0230] When L File1 When = 95%, R File1 =1-L File1 =1 - 95% = 0.05;

[0231] When L File1 When = 70%, R Filel =1-L Filel =1 - 70% = 0.30;

[0232] When L File1 When = 20%, R Filel =1-L Filel =1 - 20% = 0.80;

[0233] When L Filel When = 15%, R Filel =1-L Filel =1-15%=0.85.

[0234] In another example:

[0235] When L Filel When = 95%, according to Formula 5 above, R Filel =1-(L File1 -FIL)=1-(95%-30%)=0.35;

[0236] When L File1 When = 70%, according to formula 5 above, R File1 =1-(L File1 -FIL)=1-(70%-30%)=0.60;

[0237] When L File1 When = 20%, according to formula 6 above, R File1 =1-L File1 +(FIL-L File1 ) = 1 - 20% + (30% - 20%) = 0.90;

[0238] When L File1 When = 15%, according to formula 6 above, R File1 =1-L File1 +(FIL-L File1 = 1 - 15% + (30% - 15%) = 1.00.

[0239] Case 2 (When the overall fragmentation rate of the second file does not decrease after performing FBO on the second file):

[0240] In one example, the electronic device can determine the reward value corresponding to the second file based on the first ratio corresponding to the second file.

[0241] For example, the reward value (negative or zero) corresponding to the second file can be determined according to the following formula 7:

[0242] R File =-L File (Formula 7)

[0243] In Formula 7, when L File The higher the value, the more LBA segments in a file are greater than or equal to the first threshold. This is equivalent to more LBA segments in a file undergoing FBO, thus increasing the probability of a file's fragmentation rate decreasing after FBO, and conversely, decreasing the probability of a file's fragmentation rate not decreasing after FBO. Therefore, when L... File The higher the value, the more R will be. File (Negative or zero) sets it lower (i.e., R) File (where the absolute value is larger), that is, in formula 7, L... File With R File It shows an inverse relationship.

[0244] In another example, the electronic device can also determine the reward value corresponding to the second file based on the first ratio and the fourth threshold.

[0245] For example, when the first proportion corresponding to a file is greater than or equal to the fourth threshold, it means that the first proportion corresponding to the file has a significant impact on reducing the overall fragmentation rate of the file, thus making the probability of reducing the overall fragmentation rate very high; conversely, when the first proportion corresponding to a file is less than the fourth threshold, it means that the first proportion corresponding to the file has a very small impact on reducing the overall fragmentation rate of the file, thus making the probability of reducing the overall fragmentation rate very low.

[0246] Based on this principle, when the first proportion corresponding to the second file is greater than or equal to the fourth threshold, the reward value (negative or zero) corresponding to the second file can be determined according to the following formula 8; when the first proportion corresponding to the second file is less than the fourth threshold, the reward value (negative or zero) corresponding to the second file can be determined according to the following formula 9:

[0247] R File =-(L File -FIL) (Formula 8)

[0248] R File =-L File +(FIL-L File ) (Formula 9)

[0249] Where FIL is the fourth threshold. Formula 9, compared to Formula 7, adds "+(FIL-L)". File The reason for this setting is that when the first proportion is less than the fourth threshold, the probability of the overall fragmentation rate decreasing is inherently low, which is equivalent to the probability of the overall fragmentation rate not decreasing being inherently high. Therefore, if the overall fragmentation rate does not decrease when the probability of not decreasing is inherently high, a positive reward value should be added to reduce the absolute value of the negative reward value, i.e., by using "+(FIL-L)". File The addition of a positive value makes the negative reward value larger (i.e., the absolute value of the negative value smaller) or even equal to 0. Furthermore, to narrow the gap with Formula 9, Formula 7 can be modified to Formula 8 to calculate the reward value corresponding to the second file when the first proportion is greater than or equal to the fourth threshold. Formula 8 adds "(-FIL)" compared to Formula 7, equivalent to "+FIL". This narrows the gap with Formula 9, balancing the data values ​​and achieving better results. It should be noted that since the reward value obtained from Formula 9 may be greater than or equal to 0, in such cases, the reward value is directly set to 0.

[0250] For example, suppose File2 in the first filegroup is the second file in the first filegroup, and after performing FBO on File2, the overall fragmentation rate of File2 does not decrease, then in the following example:

[0251] In one example, according to Formula 7 above:

[0252] When L File2 When = 95%, R File2 =-L File2 =-95% =-0.95;

[0253] When L File2 When = 70%, R File2 =-L File2 =-70% =-0.75;

[0254] When L File2 When = 20%, R File2 =-L File2 =-20% =-0.20;

[0255] When L File2 When = 15%, R File2 =-L File2 =-15% =-0.15.

[0256] In another example:

[0257] When L File2 When = 95%, according to formula 8 above, R File2 =-(L File2 -FIL)=-(95%-30%)=-0.65;

[0258] When L File2 When = 70%, according to formula 8 above, R File2 =-(L File2 -FIL)=-(70%-30%)=-0.40;

[0259] When L File2 When = 20%, according to formula 9 above, R File2 =-L File2 +(FIL-L File2 ) = -20% + (30% - 20%) = -0.10;

[0260] When L File2 When = 15%, according to formula 9 above, R File2 =-L File2 +(FIL-L File2 ) = -15% + (30% - 15%) = 0.

[0261] Optionally, assuming the third file is a file in the first file group, and the first proportion corresponding to the third file is less than the updated interception threshold (i.e., P2 above), the reward value corresponding to the third file is determined as follows:

[0262] 1) If the overall fragmentation rate of the third file does not decrease after performing FBO on the third file, the reward value corresponding to the third file is positive; 2) If the overall fragmentation rate of the third file decreases after performing FBO on the third file, the reward value corresponding to the third file is negative or zero.

[0263] Case 3 (When the overall fragmentation rate of the third file does not decrease after performing FBO on the third file):

[0264] In one example, the electronic device can determine the reward value corresponding to the third document based on the first ratio corresponding to the third document.

[0265] For example, the reward value (positive value) corresponding to the third file can be determined according to the following formula 10:

[0266] R File =L File (Formula 10)

[0267] In Formula 10, L File With R File It is directly proportional, and this setting is because: when L File The higher the value of L, the higher the probability that the overall fragmentation rate of a file will decrease after performing FBO, meaning the lower the probability that the overall fragmentation rate will not decrease. Therefore, when L... File A higher R value actually does not reduce the overall fragmentation rate; therefore, R should be adjusted accordingly. File (Positive value) is set higher, that is, L in formula 10 File With R File It is directly proportional.

[0268] In another example, the electronic device can also determine the reward value corresponding to the third file based on the first ratio and the fourth threshold.

[0269] The meaning of the fourth threshold can be referred to as in case 1 or case 2 above. Based on the meaning of the fourth threshold, when the first proportion corresponding to the third file is greater than or equal to the fourth threshold, the reward value (positive value) corresponding to the third file can be determined according to the following formula 11; when the first proportion corresponding to the third file is less than the fourth threshold, the reward value (positive value) corresponding to the third file can be determined according to the following formula 12:

[0270] R File =L File +(L File -FIL) (Formula 11)

[0271] R File =L File +FIL (Formula 12)

[0272] In Formula 11, compared to Formula 10, "+(L" is added. File The setting of "-FIL)" is because when the first ratio is greater than or equal to the fourth threshold, the probability of the overall fragment rate decreasing is inherently high, which is equivalent to the probability of the overall fragment rate not decreasing being inherently low. Therefore, if the overall fragment rate does not decrease when the probability of not decreasing is inherently low, a positive reward value should be added, i.e., through "+(L File Adding a positive reward value ("+FIL") further reduces the gap with Formula 11. Formula 10 can be modified to Formula 12 to calculate the reward value corresponding to the second file when the first proportion is less than the fourth threshold. Formula 12 adds "+FIL" compared to Formula 10, thus narrowing the gap with Formula 11, balancing the data values, and achieving better results. Optionally, if the reward value obtained based on Formula 9 is greater than or equal to 0, then the obtained reward value is directly set to 0. It is understood that the positive reward value obtained based on Formula 11 and Formula 12 can be greater than 1, and this application does not limit this.

[0273] For example, suppose the first filegroup contains four files: File1, File2, File3, and File4. If File1 corresponds to the first proportion L... File1 The first ratio L corresponding to File2 File2 The first ratio L corresponding to File3 is greater than or equal to the updated interception threshold (i.e., P2 above). File3 The first scale L corresponding to File4 File4 If the fragmentation rate is less than the updated interception threshold (i.e., P2 above), then File3 and File4 are equivalent to two third files in the first filegroup. Assuming that performing an FBO on File3 does not reduce its overall fragmentation rate, then in the following example:

[0274] In one example, according to Formula 10 above:

[0275] When L File3 When = 70%, R File3 =L File3 =70% = 0.70;

[0276] When L File3 When = 50%, R File3 =L File3 =50% = 0.50;

[0277] When L File3 When = 30%, RFile3 =L File3 =30% = 0.30;

[0278] When L File3 When = 20%, R File3 =L File3 =20% = 0.20;

[0279] When L File3 When = 10%, R File3 =L File3 =10% =0.10.

[0280] In another example:

[0281] When L File3 When = 70%, according to formula 11 above, R File3 =L File3 +(L File3 -FIL)=70%+(70%-30%)=1.1;

[0282] When L File3 When = 50%, according to formula 11 above, R File3 =L File3 +(L File3 -FIL)=50%+(50%-30%)=0.70;

[0283] When L File3 When = 30%, according to formula 11 above, R File3 =L File3 +(L File3 -FIL)=30%+(30%-30%)=0.30;

[0284] When L File3 When = 20%, according to formula 12 above, R File3 =L File3 +FIL = 20% + 30% = 0.50;

[0285] When L File3 When = 10%, according to formula 12 above, R File3 =L File3 +FIL = 10% + 30% = 0.40.

[0286] Case 4 (When the overall fragmentation rate of the third file decreases after performing FBO on the third file):

[0287] In one example, the electronic device can determine the reward value corresponding to the third document based on the first ratio corresponding to the third document.

[0288] For example, the reward value (negative or zero) corresponding to the third file can be determined according to the following formula 13:

[0289] R File =-(1-L) File ) (Formula 13)

[0290] In formula 13, when L File The higher the value, the more LBA segments in a file are greater than or equal to the first threshold. This is equivalent to more LBA segments in a file undergoing FBO, thus increasing the likelihood of a file experiencing a lower overall fragmentation rate after FBO. Therefore, when L... File A higher R value results in a lower overall fragmentation rate, which in turn reduces the overall fragmentation rate. File (Negative or zero) set higher (or R) File (the absolute value is smaller), that is, L File With R File It is directly proportional.

[0291] In another example, the electronic device can also determine the reward value corresponding to the third file based on the first ratio and the fourth threshold.

[0292] The meaning of the fourth threshold can be referred to as in case 1 or case 2 above. Based on the meaning of the fourth threshold, when the first proportion corresponding to the third file is greater than or equal to the fourth threshold, the reward value (negative value) corresponding to the third file can be determined according to the following formula 14; when the first proportion corresponding to the third file is less than the fourth threshold, the reward value (negative value) corresponding to the third file can be determined according to the following formula 15:

[0293] R File =-(1-L) File )-FIL (Formula 14)

[0294] R File =-(1-L) File )-(FIL-L File ) (Formula 15)

[0295] Formula 15, compared to Formula 13, adds "-(FIL-L"). File This setting is because: when the first proportion is less than the fourth threshold, the probability of an overall fragmentation rate decrease is inherently low. Therefore, if an overall fragmentation rate decrease occurs despite the inherently low probability of such a decrease, a negative reward value should be added, i.e., through "-(FIL-L)". FileTo reduce the negative reward value, formula 13 can be modified to formula 14 to calculate the reward value corresponding to the second file when the first ratio is greater than or equal to the fourth threshold. Formula 14 adds "-FIL" compared to formula 13, thus reducing the gap with formula 15, balancing the data values, and achieving better results. It is understood that the reward value for negative values ​​obtained based on formula 14 or 15 can be less than -1, and this application does not limit this.

[0296] For example, suppose File4 in the first filegroup is one of two second files in the first filegroup, and after performing FBO on File4, the overall fragmentation rate of File4 decreases, then in the following example:

[0297] In one example, according to Formula 13 above:

[0298] When L File4 When = 70%, R File4 =-(1-L) File4 ) = -(1-70%) = -0.30;

[0299] When L File4 When = 50%, R File4 =-(1-L) File4 ) = -(1-50%) = -0.50;

[0300] When L File4 When = 30%, R File4 =-(1-L) File4 ) = -(1-30%) = -0.70;

[0301] When L File4 When = 20%, R File4 =-(1-L) File4 ) = -(1-20%) = -0.80;

[0302] When L File4 When = 10%, R File4 =-(1-L) File4 ) = -(1-10%) = -0.90.

[0303] In another example:

[0304] When L File4 When = 70%, according to formula 14 above, R File4 =-(1-L) File4 )-FIL=-(1-70%)-30%=-0.6;

[0305] When L File4When = 50%, according to formula 14 above, R File4 =-(1-L) File4 )-FIL=-(1-50%)-30%=-0.8;

[0306] When L File4 When = 30%, according to formula 14 above, R File4 =-(1-L) File4 )-FIL=-(1-30%)-30%=-1.0;

[0307] When L File4 When = 20%, according to formula 15 above, R File4 =-(1-L) File4 )-(FIL-L File4 ) = -(1-20%) - (30%-20%) = -0.9;

[0308] When L File4 When = 10%, according to formula 15 above, R File4 ==-(1-L) File4 )-(FIL-L File4 = -(1-10%)-(30%-10%)=-1.1.

[0309] After determining the reward value using any of the above methods, the Q-value function can be further updated based on the reward value and the updated state information corresponding to the first file group.

[0310] For example, before the interception threshold is updated, the state information of the first filegroup is S1 in Table 1. If the interception threshold is increased during adjustment, the state information of the first filegroup can be updated from S1 in Table 1 to S6 in Table 1. Then, the value of 'a' that maximizes Q(S6, a) is selected, and the corresponding Q value is substituted into maxa Q(S′, a) in Formula 2. The reward value determined above is substituted into R in Formula 2, and a new Q-value function is obtained according to Formula 2. Based on the new Q-value function and the ∈-greedy policy, the interception threshold is updated in the next round. When the termination condition of reinforcement learning is triggered, the final interception threshold is the second threshold.

[0311] based on Figure 6 In the described embodiment, the electronic device can perform FBO on the first file when the first proportion corresponding to the first file is greater than or equal to a second threshold, and the overall fragmentation rate of the first file is greater than or equal to a third threshold. This effectively avoids performing FBO on only a small portion of the first file, thereby saving computing resources of the electronic device and reducing wear and tear on storage devices. Furthermore, this embodiment also ensures that the reading performance of the first file is effectively improved after performing FBO.

[0312] against Figure 6 The described embodiment can learn the interception threshold during the learning phase, and then, during the working phase (i.e., the application phase of the scheme), determine whether to perform FBO on the first file based on the third threshold and the interception threshold when the termination condition of reinforcement learning is triggered (i.e., the second threshold mentioned above).

[0313] The working phase and the learning phase can be switched periodically. For example, the learning phase can be preset to one week, and the working phase to one month. First, the interception threshold is learned using the reinforcement learning method described above during the first week. Then, in the first month after the first week, the third threshold and the interception threshold at the time the reinforcement learning termination condition is triggered are used to determine whether to perform an FBO on the first file. After the first month ends, the interception threshold is relearned in a new week, and at the end of this new week, the third threshold and the interception threshold at the end of the relearning are applied to determine whether to perform an FBO on the first file, and so on. In this way, when the file's storage attributes or device status change, a more suitable second threshold can be learned through relearning. Optionally, the duration of the working phase and the learning phase can be set to different values ​​for different services.

[0314] For details, please refer to [the relevant documentation]. Figure 8 The process shown Figure 8 The illustrated process is executed by an electronic device and includes steps 801 to 810:

[0315] 801. Obtain the trigger command for the FBO subprocess in the defragmentation process.

[0316] In this embodiment, the defragmentation process includes one or more sub-processes, with FBO being one of these sub-processes. When the defragmentation process is triggered, these sub-processes are executed sequentially, i.e., sub-process 1, sub-process 2, sub-process 3, ... If an FBO is performed on only a small portion of the file within an FBO sub-process, it is equivalent to performing an invalid FBO on the file. When the invalid FBO on the file takes a long time in an FBO sub-process, the FBO sub-process will slow down the execution time of the remaining unexecuted sub-processes, thereby slowing down the overall processing efficiency and preventing the timely improvement of file reading performance in electronic devices.

[0317] Optionally, the defragmentation process can be triggered automatically or by the user. For example, the electronic device can receive a user-initiated command to improve device performance, which triggers the defragmentation process. Alternatively, the electronic device can detect whether it is in a screen-off charging state. If so, it automatically triggers the defragmentation process. Optionally, the electronic device can also detect the current screen-off charging duration and the interval between the current and previous screen-off charging sessions. If the current screen-off charging duration exceeds a screen-off duration threshold, and the interval between the current and previous screen-off charging sessions exceeds an interval duration threshold, the defragmentation process is automatically triggered.

[0318] Specifically, when the FBO sub-process is the first sub-process in the defragmentation process, the trigger instruction for the FBO sub-process is the same as the trigger instruction for the defragmentation process; when the FBO sub-process is not the first sub-process in the defragmentation process, the trigger instruction for the FBO sub-process is the instruction indicating that the previous sub-process has completed execution.

[0319] 802. Get the file collection.

[0320] For example, for a work phase, the file set may include multiple first files, the first files being those mentioned above. Figure 6 The first file in the embodiment; for the learning phase, the text set can be as described above. Figure 6 The embodiment shows the file set corresponding to the first service in "electronic device acquiring training data". The first service can be the service to which the first file belongs, or a service with similar storage attributes to the service to which the first file belongs; details can be found in [reference needed]. Figure 6 The relevant descriptions in the examples are as follows.

[0321] 803. Determine whether it is in the working stage.

[0322] If the process is in the working phase, proceed to step 810.

[0323] If not in the working phase, proceed to step 804.

[0324] 804. Determine whether the student is in the learning phase.

[0325] If it is in the learning phase, proceed to step 805.

[0326] If not in the learning phase, proceed to step 810.

[0327] Steps 805 to 809 are the specific implementation methods of reinforcement learning in the learning phase: After step 805 is completed, the electronic device needs to perform multiple rounds of reinforcement learning in the learning phase, and each round of reinforcement learning executes steps 806 to 809 in sequence.

[0328] 805. Select multiple files from the file set whose overall fragmentation rate is greater than or equal to the third threshold, and group the multiple files.

[0329] For example, selecting multiple files from the file set whose overall fragmentation rate is greater than or equal to the third threshold can yield the following results: Figure 6 The first file set in the embodiment; grouping multiple files yields the above-mentioned... Figure 6 In this embodiment, there are M file groups. The overall fragmentation rate of the files in each of the M file groups is greater than or equal to a third threshold, and the distribution of the first proportion of files in any two file groups is similar. Then, in each round of learning, one file group from the M file groups is used as the learning object, and steps 806 to 809 are executed below.

[0330] 806. Obtain current status information and update the interception threshold.

[0331] 807. Execute FBO on the file.

[0332] In the learning phase, step 807 is implemented by performing FBO on all files in a filegroup; in the working phase, step 807 is implemented by performing FBO on the files determined in step 810.

[0333] 808. After executing FBO, calculate whether the overall fragmentation rate of each file in a filegroup that is above / below the updated interception threshold has decreased.

[0334] Among them, whether the fragmentation rate of each file in a file group that is above / below the updated interception threshold has decreased can be used to determine the updated current status information and the reward value after the interception threshold is updated.

[0335] 809. Obtain the reward value after the interception threshold is updated.

[0336] It should be noted that in steps 805 to 809, only the interception threshold is updated, and the decision to execute FBO is not based on the interception threshold.

[0337] 810. Identify files in the file set whose first proportion is greater than or equal to the interception threshold and whose overall fragmentation rate is greater than or equal to the third threshold.

[0338] In this way, electronic devices can perform FBO on files only when the first proportion of the file is greater than or equal to the interception threshold and the overall fragmentation rate of the file is greater than or equal to the third threshold, thereby saving the computing resources of electronic devices, reducing the wear and tear on storage devices, and ensuring that file readability can be effectively improved.

[0339] The software architecture of the electronic device is described below, and the software interactions involved in the above embodiments are explained in conjunction with the software architecture:

[0340] Figure 9 A software architecture diagram of an electronic device according to an embodiment of this application is shown. The software structure adopts a layered architecture, dividing the software into several layers, each with a clear role and division of labor. Layers communicate with each other through software interfaces. Figure 9 As shown, taking the Android system, which runs on an application platform (AP), as an example, in some embodiments, the Android system is divided into five layers, from top to bottom: application (APP) layer, application framework (Framework) layer, native layer, kernel layer, and hardware layer.

[0341] It is understood that this software architecture is only an example. In actual implementation, electronic devices may include more functional modules in the above layers, which will not be elaborated in this application.

[0342] Application Layer: The application package can include a series of application packages, such as music, video, and text messaging applications. The application layer can also include the system UI, which is used to display the interface of the electronic device.

[0343] Application Framework Layer: The application framework layer provides application developers with an application programming interface (API) framework for accessing core functionalities, as well as various services and management tools. The application framework layer includes predefined functions and algorithms. For example... Figure 9As shown, the application framework layer may include a storage management service (StorageManager Service). The StorageManager Service can deploy file system and device system (garbage collection, GC) policies. These GC policies refer to the strategies related to the defragmentation process (including one or more sub-processes). Specifically, the StorageManager Service, based on the GC policy settings, monitors whether the electronic device is charging with the screen off. When it detects that the electronic device is charging with the screen off, it sets `mScreenOn` to `false` and simultaneously checks whether the electronic device meets other conditions. For example, the GC policy may also set a screen-off charging duration threshold and an interval threshold between two consecutive screen-off charging sessions. If the current screen-off charging duration exceeds the screen-off charging duration threshold, and the interval between the current screen-off charging session and the previous screen-off charging session exceeds the interval threshold, then the electronic device is determined to meet the other conditions. If the electronic device also meets the other conditions, the GC policy in the StorageManager Service calls the native layer's algorithm process module, which then executes the algorithm program to run one or more sub-processes (including the FBO sub-process) set in the GC policy.

[0344] Native Layer: The native layer mainly consists of code written in C and C++, used to provide low-level functional support for the application framework, such as libc (standard C library) and libm (mathematics library). Figure 9As shown, the native layer includes an algorithm process module, which deploys the algorithm programs and their corresponding interface functions. When the algorithm process module is called by the GC strategy to execute the FBO sub-process, it first calls the `runDevGc` function, which further calls the FBO interface function (`runIoctlGcFbo`). The `runIoctlGcFbo` function is used to obtain the file's LBA information and control whether to send relevant FBO instructions to the FBO driver in the kernel layer. For example, the `runIoctlGcFbo` function sends FBO-related instructions to the FBO driver in the kernel layer via an `ioctl` system call. These instructions include fragmentation rate analysis instructions. For instance, during the working and learning phases, `runIoctlGcFbo` sends fragmentation rate analysis instructions to the FBO driver in the kernel layer, carrying the file's LBA information to obtain the overall fragmentation rate of the file. FBO-related instructions also include FBO execution instructions. For example, during the working phase, `runIoctlGcFbo` can determine whether to send FBO execution instructions to the FBO driver in the kernel layer based on the file's first fragmentation ratio (determined based on the file's LBA information) and the file's overall fragmentation rate. During the learning phase, it directly sends FBO execution instructions to the FBO driver in the kernel layer. It should be noted that during the learning phase, the runDevGc function can also be used for file grouping, obtaining the status information of file groups, updating the interception threshold, updating the Q-value list of policies in reinforcement learning, etc. In addition, the runDevGc function can also be used to access the sysfs node defined in the FBO driver to query whether the UFS in the hardware layer supports FBO, query the completion status of fragmentation rate analysis, and query the execution status of FBO.

[0345] Kernel layer: The kernel layer is the layer between hardware and software, such as... Figure 9 As shown, the kernel layer includes a storage device driver (FBO driver). The FBO driver can respond to the FBO-related instructions sent by the algorithm process module and call the UFS in the hardware layer to perform corresponding operations.

[0346] Hardware Layer: The hardware layer includes storage devices such as Universal Flash Storage (UFS). Using UFS as an example, UFS responds to FBO driver calls, performing fragmentation rate analysis and executing FBO. For instance, during the working and learning phases, the overall fragmentation rate of the file is analyzed. During the working phase, if the first fragmentation ratio corresponding to the file is greater than or equal to a second threshold, and the overall fragmentation rate of the file is greater than or equal to a third threshold, an FBO is executed on the file; otherwise, an FBO is not executed. During the learning phase, an FBO is executed on the file.

[0347] It should be noted that the application layer, application framework layer, and native layer can correspond to... Figure 3 The software deployed in the host machine to control the storage devices to execute the FBO; the hardware layer corresponds to... Figure 3 The kernel layer is responsible for the interaction between the host software and the storage devices. Compared to the hardware-software interaction involved in the FBO in the JEDEC protocol, this application mainly involves modifications to the native layer (i.e., the algorithm process module of the native layer) in the host software. For details, please refer to the following... Figure 10 Corresponding implementation examples.

[0348] Based on the above software structure Figure 10 It shows Figure 8 The software interactions corresponding to steps 802 to 810 are as follows:

[0349] It should be noted that, Figure 8 The software interaction involved in step 801 is the interaction between the StorageManager Service in the application framework layer and the algorithm process module in the native layer. Specifically, when the StorageManagerService detects that the FBO sub-process has been triggered, it calls the RunIdleMaint interface in the algorithm process module through Binder communication. This causes the RunIdleMaint interface in the algorithm process module to call the runIoctlGcFbo function in the runDevGc function to execute... Figure 10 Corresponding implementation examples: It should be noted that, Figure 10 This explanation focuses solely on the interactions between the algorithm process module in the native layer, the FBO driver in the kernel layer, and the UFS in the hardware layer; other interactions will not be elaborated upon. Specifically:

[0350] 1001. The algorithm process module obtains the file set.

[0351] For example, for a work phase, the file set may include multiple first files, such as the first file mentioned above. Figure 6 The first file in the embodiment; for the learning phase, the text set can be as described above. Figure 6 The file set corresponding to the first service in "electronic device acquires training data" in the embodiment.

[0352] After obtaining the file set, the algorithm process module can determine whether it is currently in the working stage or the learning stage. If it is in the learning stage, it executes steps 1002 to 1011; if it is in the working stage, it executes steps 1002 to 1006 and steps 1012 to 1013.

[0353] 1002. The algorithm process module obtains that UFS has FBO capability.

[0354] Specifically, step 1002 is implemented by steps 1002-1 and 1002-2. Step 1002-1 involves the algorithm process module accessing the FBO descriptor sysfs node defined in the FBO driver to read the descriptor used to indicate that the UFS has FBO capability. Step 1002-2 involves the FBO driver reading the descriptor used to indicate that the UFS has FBO capability.

[0355] In other words, the algorithm process module accesses the FBO descriptor sysfs node defined in the FBO node to trigger the FBO driver to issue a read command to the UFS. This read command is used to read the descriptor that indicates that the UFS has FBO capability. After reading the descriptor that indicates that the UFS has FBO capability, the FBO driver returns the descriptor that indicates that the UFS has FBO capability to the algorithm process module through the FBO descriptor sysfs node, so that the algorithm process module determines that the UFS has FBO capability based on the descriptor.

[0356] 1003. Set the third threshold in the algorithm process module.

[0357] Specifically, step 1003 is implemented by steps 1003-1 and 1003-2. Step 1003-1 involves the algorithm process module accessing the FBO execution threshold sysfs node defined in the FBO driver to set the third threshold that the overall fragmentation rate must meet when the UFS executes FBO. Step 1003-2 involves the FBO driver setting the third threshold ("bFBOExecuteThreshold = third threshold") to the UFS.

[0358] According to the JEDEC protocol definition, "bFBOExecuteThreshold" is an attribute of the FBO execution threshold in UFS. In this step, the algorithm process module accesses the FBO execution threshold sysfs node defined in the FBO node to trigger the FBO driver to send a setting instruction to UFS. This setting instruction is used to set the value of "bFBOExecuteThreshold" in UFS to the third threshold (i.e., "bFBOExecuteThreshold = third threshold"). Optionally, the third threshold corresponding to different services can be different. Therefore, before step 1003-1, the algorithm process module can first query the configuration file to obtain the third threshold corresponding to the service to which the file set belongs, and then execute steps 1003-1 and 1003-2.

[0359] 1004. The algorithm process module uses the ioctl system call to access the file system and obtain the LBA information of each file in the file set.

[0360] The file system, also known as the file system layer described above, is located in the kernel layer. The algorithm process module can obtain the LBA information of each file by accessing the file system.

[0361] 1005. The algorithm process module determines the first proportion corresponding to each file based on the LBA information of each file.

[0362] Specifically, the algorithm process module determines the first total size and the second total size of each file based on the LBA information of each file, thereby determining the first ratio. The specific implementation method can be referred to the corresponding description of step 601.

[0363] 1006. The algorithm process module obtains the overall fragmentation rate of each file in the file set.

[0364] Specifically, step 1006 is implemented by steps 1006-1 to 1006-4. Step 1006-1 involves the algorithm process module sending a fragmentation rate analysis command to the FBO driver using an ioctl system call. Step 1006-2 involves the FBO driver setting the writebuffer and the FBO control attribute in UFS ("bFBOControl=0x1") so that UFS can analyze the overall fragmentation rate of each file. Step 1006-3 involves the algorithm process module accessing the FBO execution status sysfs node defined in the FBO driver to read the execution status of the fragmentation rate analysis. Step 1006-4 involves the FBO driver reading the writebuffer to obtain the overall fragmentation rate of each file when the fragmentation rate analysis is completed.

[0365] According to the JEDEC protocol definition, "bFBOExecuteThreshold" is the FBO control attribute in UFS, which controls the UFS to perform fragmentation rate analysis and execute FBO. In this step, the fragmentation rate analysis command carries the LBA information of each file. After receiving the fragmentation rate analysis command from the algorithm process module, the FBO driver can first check the format of the LBA information. If the LBA information is in the correct format, it is written to the writebuffer. At the same time, the FBO control attribute in UFS is set, such as setting the value of "bFBOControl" to 0x1 (i.e., "bFBOControl = 0x1"). This allows UFS to analyze the fragmentation rate of the data in the writebuffer, obtaining the fragmentation rate of each LBA of each file and the overall fragmentation rate of each file. Meanwhile, the algorithm process module can access the FBO execution status sysfs node defined in the FBO driver at any time to trigger the FBO driver to check whether the UFS has completed the fragmentation rate analysis. When the UFS has completed the fragmentation rate analysis, the FBO driver reads the writebuffer to obtain the fragmentation rate of each LBA and the overall fragmentation rate of each file, and then reports it to the algorithm process module through the FBO execution status sysfs node.

[0366] 1007. The algorithm process module selects multiple files from the file set whose overall fragmentation rate is greater than or equal to the third threshold, and groups the multiple files.

[0367] Specifically, the algorithm process module can group the file set according to the first ratio corresponding to each file in step 1005 and the overall fragmentation rate of each file determined in step 1006. For example, grouping the file set can yield the above... Figure 6 In this embodiment, there are M filegroups. Then, the algorithm process module uses one of these M filegroups as the learning target and executes steps 1008 to 1011. It should be noted that steps 1008 to 1011 need to be repeated multiple times until the termination condition of reinforcement learning is triggered.

[0368] 1008. The algorithm process module determines the status information of the file group.

[0369] Specifically, in the initial case, the status information of the file group can be the initial value; in the non-initial case, it is the value obtained when step 1012 was executed last time.

[0370] 1009. The algorithm process module updates the interception threshold based on the policy pair.

[0371] For the specific implementation of step 1011, please refer to... Figure 6 The relevant descriptions of reinforcement learning in China will not be elaborated here.

[0372] 1010. The algorithm process module controls the execution of FBO in UFS.

[0373] Specifically, step 1010 is implemented by steps 1010-1 to 1010-4. Step 1010-1 involves the algorithm process module sending the FBO execution instruction to the FBO driver via an ioctl system call. Step 1010-2 involves the FBO driver setting the writebuffer and the FBO control attribute ("bFBOControl=0x2") in the UFS to enable the UFS to perform FBO on each file in the filegroup. Step 1010-3 involves the algorithm process module accessing the FBO execution status sysfs node defined in the FBO driver to read the FBO execution status and the overall fragmentation rate change of each file in the filegroup. Step 1010-4 involves the FBO driver reading the FBO execution status attribute ("bFBOProgressState") in the UFS to obtain the FBO execution status and reading the writebuffer to obtain the overall fragmentation rate change of each file in the filegroup.

[0374] According to the JEDEC protocol definition, "bFBOProgressState" is an attribute in UFS that indicates the execution status (or execution condition) of an FBO.

[0375] The FBO execution instructions carry the threshold number of LBA segments in each file that are larger than or equal to the LBA segment size threshold (i.e., ... Figure 6 The FBO driver first checks the LBA information in the FBO execution instruction when it receives the instruction. If the LBA information is in the correct format, it writes it to the writebuffer and sets the FBO control attribute in the UFS, such as setting "bFBOControl" to 0x2 (i.e., "bFBOControl = 0x2"). This allows the UFS to perform FBO on the data in the writebuffer. Simultaneously, the algorithm process module can access the FBO execution status sysfs node at any time to trigger the FBO driver to read the FBO execution status attribute ("bFBOProgressState") in the UFS to determine if the UFS has completed the FBO. When the UFS has completed the FBO, the FBO driver reads the writebuffer to obtain the overall fragmentation rate change of each file in the filegroup and then reports it to the algorithm process module through the FBO execution status sysfs node. It should be noted that in this step, the UFS needs to perform FBO on each file in the filegroup to obtain the overall fragmentation rate change of each file and update the filegroup's status information.

[0376] 1011. The algorithm process module determines the updated status information of the file group and the updated reward value of the interception threshold based on the updated interception threshold and the change in the overall fragmentation rate of each file in the file group, and updates the strategy based on the reward value.

[0377] For the specific implementation of step 1011, please refer to... Figure 6 The implementation methods of reinforcement learning in China will not be elaborated here.

[0378] Optionally, after step 1011, the algorithm process module can also determine whether the termination condition of reinforcement learning has been triggered. If the termination condition of reinforcement learning has been triggered, steps 1008 to 1011 will not be repeated.

[0379] 1012. The algorithm process module determines whether the first proportion of files in the file set is greater than or equal to the interception threshold and whether the overall fragmentation rate of files in the file set is greater than or equal to the third threshold.

[0380] Optionally, the two judgments in step 1012 can be decoupled to determine whether the overall fragmentation rate or the first ratio meets the condition separately. This decoupling allows the electronic device to adjust the execution order of steps 1005 and 1006, and to selectively execute either step 1005 or step 1006. For example, step 1005 can be executed first, followed by the judgment of the first ratio in step 1012 (i.e., determining whether the first ratio is greater than or equal to the interception threshold). If the first ratio is greater than or equal to the interception threshold, then step 1005 and the judgment of the overall fragmentation rate in step 1012 (i.e., determining whether the overall fragmentation rate is greater than or equal to the third threshold) can be executed. Conversely, if the first ratio is less than the interception threshold, then step 1006 and the judgment of the overall fragmentation rate in step 1012 can be executed, and so on.

[0381] 1013. The algorithm process module controls UFS to perform FBO on the first file.

[0382] Specifically, step 1013 is implemented by steps 1013-1 and 1013-2. Step 1013-1 involves the algorithm process module sending an FBO execution instruction to the FBO driver via an ioctl system call when the first proportion of the first file in the file set is greater than or equal to the interception threshold and the overall fragmentation rate of the first file is greater than or equal to the third threshold. Step 1013-2 involves the FBO driver setting the writebuffer and the FBO control attribute in the UFS ("bFBOControl=0x2") so that the UFS can perform FBO on the first file.

[0383] It should be noted that the steps of the above learning phase are not performed when the work phase is in progress, and the steps of the above work phase are not performed when the learning phase is in progress, and the work phase is after the learning phase.

[0384] based on Figure 10 As can be seen from the described software interaction process, the algorithm process module in this application learns the interception threshold based on reinforcement learning during the learning phase, and determines whether the first ratio corresponding to the file meets the interception threshold triggered by the termination condition based on reinforcement learning during the working phase, and whether the overall fragmentation rate corresponding to the file meets the third threshold. In this way, the algorithm process module can ensure the effective issuance of FBO execution instructions, thereby saving the computing resources of electronic devices, reducing the wear and tear on storage devices, ensuring the improvement of file reading performance, and reducing the number of fragmentation rate judgments.

[0385] It should be noted that the above Figure 6 , Figure 8 , Figure 10 In the corresponding embodiment, the first ratio of the file can also be replaced by the file's read performance. That is, the decision to perform FBO on the file is based on the file's read performance and the overall fragmentation rate of the file. For example, if the read performance of the first file is less than the fifth threshold and the overall fragmentation rate of the first file is greater than or equal to the third threshold, then the electronic device performs FBO on the first file.

[0386] Optionally, the fifth threshold can be a fixed value or a non-fixed value. When the fifth threshold is non-fixed, it can be learned during the learning phase and applied during the working phase, according to the reinforcement learning approach. The specific implementation can be referred to the above. Figure 6 , Figure 8 , Figure 10 Corresponding implementation examples.

[0387] This application also provides a data processing apparatus, which includes functions / units for performing the electronic devices described above.

[0388] This application also provides a chip system, such as... Figure 11As shown, the chip system 1100 includes at least one processor 1101 and at least one interface circuit 1102. The processor 1101 and the interface circuit 1102 are interconnected via lines. For example, the interface circuit 1102 can be used to receive signals from other devices (e.g., the memory of an electronic device). As another example, the interface circuit 1102 can be used to send signals to other devices (e.g., the processor 1101). Exemplarily, the interface circuit 1102 can read instructions stored in memory and send those instructions to the processor 1101. When the instructions are executed by the processor 1101, the electronic device can perform the steps in the above embodiments. Of course, the chip system may also include other discrete devices, and this application embodiment does not specifically limit this.

[0389] This embodiment also provides a computer-readable storage medium storing a computer programmer / instructions. When the computer program / instructions are run on an electronic device, the electronic device performs various functions or steps performed by the electronic device in the above method embodiment.

[0390] This embodiment also provides a computer program product, which includes a computer program that, when run on a computer, causes the computer to perform various functions or steps performed by the electronic device in the above method embodiment.

[0391] In addition, embodiments of this application also provide an apparatus, which may specifically be a chip, component, or module. The apparatus may include a connected processor and a memory. The memory is used to store computer execution instructions. When the apparatus is running, the processor may execute the computer execution instructions stored in the memory to cause the chip to perform various functions or steps performed by the electronic device in the above method embodiments.

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

[0393] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0394] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0395] The unit described as a separate component may or may not be physically separate. The component shown as a unit can be one physical unit or multiple physical units, that is, it can be located in one place or distributed in multiple different places. Some or all of the units can be selected to achieve the purpose of the solution in this embodiment according to actual needs.

[0396] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0397] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially or in other words, the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0398] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application and are not intended to limit it. Although this application has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of this application without departing from the spirit and scope of the technical solutions of this application.

Claims

1. A data processing method, characterized in that, The method includes: Obtain a first file set, wherein the overall fragmentation rate of each file in the first file set is greater than or equal to a third threshold; The files in the first file set are grouped to obtain M file groups; M is a positive integer greater than or equal to 1; Based on the M file groups, a second threshold is determined through reinforcement learning. Determine the first proportion corresponding to the first file, the first proportion corresponding to the first file is the proportion of the first total size of the first file to the second total size of the first file, the first total size corresponding to the first file is the total size of the logical block address (LBA) segment whose size is greater than or equal to the first threshold, and the second total size corresponding to the first file is the total size of the LBA segment corresponding to the first file. If the first ratio corresponding to the first file is greater than or equal to the second threshold, and the overall fragmentation rate of the first file is greater than or equal to the third threshold, then file-level defragmentation (FBO) is performed on the first file.

2. The method according to claim 1, characterized in that, The process of grouping the files in the first file set to obtain M file groups includes: Determine the first proportion corresponding to each file in the first file set; Based on the first proportion corresponding to each file in the first file set, the files in the first file set are grouped to obtain M file groups.

3. The method according to claim 1 or 2, characterized in that, The step of determining the second threshold based on the M file groups through reinforcement learning includes: Select a first file group from the M file groups, and learn the interception threshold based on the first file group through reinforcement learning. The first file group can be any one of the M file groups. If the termination condition of reinforcement learning is not triggered, then a second file group is selected from the M file groups, and the interception threshold is learned through reinforcement learning based on the second file group; The second threshold is the interception threshold when the termination condition of the reinforcement learning is triggered.

4. The method according to claim 3, characterized in that, The step of learning the interception threshold based on the first file group through reinforcement learning includes: Based on the status information of the first file group and the first policy, the interception threshold is updated; The status information of the first file group is updated based on the updated interception threshold; Obtain the updated reward value of the interception threshold, and update the first policy based on the updated reward value of the interception threshold and the updated status information of the first file group.

5. The method according to claim 4, characterized in that, The status information of the first file group includes a first quantity, a second quantity, a third quantity, a fourth quantity, a fifth quantity, and a sixth quantity associated with the first file group; The first quantity is the number of files in the first file group whose first proportion is greater than or equal to the interception threshold; The second quantity is the number of files in the first file group whose first proportion is less than the interception threshold; The third quantity is the number of files in the first file group whose first proportion is greater than or equal to the interception threshold and whose overall fragmentation rate decreases after FBO is executed; The fourth quantity is the number of files in the first file group whose first proportion is greater than or equal to the interception threshold and whose overall fragmentation rate does not decrease after performing FBO; The fifth quantity is the number of files in the first file group whose first proportion is less than the interception threshold and whose overall fragmentation rate decreases after performing FBO; The sixth quantity is the number of files in the first file group whose first proportion is less than the interception threshold and whose overall fragmentation rate does not decrease after performing FBO.

6. The method according to claim 5, characterized in that, The step of obtaining the updated reward value after the interception threshold includes: Based on the updated interception threshold and whether the overall fragmentation rate of each file in the first file group decreased or did not decrease after FBO was executed, the status information of the updated first file group was determined. Based on the status information of the first file group and the updated status information of the first file group, the reward value after the interception threshold update is determined.

7. The method according to claim 6, characterized in that, The step of determining the updated reward value for the interception threshold based on the status information of the first file group and the updated status information of the first file group includes: Based on the status information of the first file group and the updated status information of the first file group, it is determined that the first file group is all positively improved, only positively improved and no deterioration, overall positively improved, overall no improvement, overall deterioration, only deterioration and no improvement, or all deterioration. The reward value after the interception threshold is updated is determined based on the following conditions: all files in the first file group show positive improvement, only positive improvement and no deterioration, overall positive improvement, no overall improvement, overall deterioration, only deterioration and no improvement, or all files show deterioration.

8. The method according to claim 7, characterized in that, The determination of the updated reward value for the interception threshold based on the following conditions: all positive improvements in the first file group, only positive improvements with no deterioration, overall positive improvements, no overall improvements, overall deterioration, only deterioration with no improvements, or all deterioration; includes: If, based on the status information of the first file group and the updated status information of the first file group, it is determined that the first file group has improved overall, has no improvement overall, or has deteriorated overall, then, based on the first proportion corresponding to each file in the first file group and whether the overall fragmentation rate decreases after each file performs FBO, the reward value corresponding to each file in the first file group is determined; based on the reward value corresponding to each file in the first file group, the reward value after the interception threshold is updated is determined.

9. The method according to claim 8, characterized in that, If the first file group shows all positive improvement, only positive improvement, only deterioration with no improvement, or all deterioration, then the reward value after the interception threshold is updated is a fixed value.

10. The method according to claim 5, characterized in that, The step of obtaining the updated reward value after the interception threshold includes: Based on the first ratio corresponding to each file in the first file group and whether the overall fragmentation rate decreases after each file performs FBO, the reward value corresponding to each file in the first file group is determined. Based on the reward value corresponding to each file in the first file group, the updated reward value of the interception threshold is determined.

11. The method according to claim 8 or 10, characterized in that, The second file is one of the files in the first file group and the first proportion corresponding to the second file is greater than or equal to the updated interception threshold; If the overall fragmentation rate of the second file decreases after performing FBO on the second file, then the reward value corresponding to the second file is positive. Alternatively, if the overall fragmentation rate of the second file does not decrease after performing FBO on the second file, then the reward value corresponding to the second file is negative or zero.

12. The method according to claim 8 or 10, characterized in that, The third file is a file in the first file group and the first proportion corresponding to the third file is less than the updated interception threshold; If the overall fragmentation rate of the third file does not decrease after performing FBO on the third file, then the reward value corresponding to the third file is positive. Alternatively, if the overall fragmentation rate of the third file decreases after performing FBO on the third file, then the reward value corresponding to the third file is negative or zero.

13. An electronic device, characterized in that, include: One or more processors, one or more memories; wherein the one or more memories are coupled to the one or more processors, the one or more memories being used to store computer program code, the computer program code including computer instructions, which, when the one or more processors execute the computer instructions, cause the electronic device to perform the method as described in any one of claims 1-12.

14. A chip system, characterized in that, The chip system, applied to an electronic device, includes at least one processor and an interface for receiving computer instructions and transmitting them to the at least one processor; the at least one processor executes the computer instructions to cause the electronic device to perform the method as described in any one of claims 1-12.

15. A computer-readable storage medium, characterized in that, Applied to an electronic device, wherein the computer-readable storage medium stores computer instructions that, when executed by a processor, cause the electronic device to perform the method as described in any one of claims 1-12.

16. A computer program product, characterized in that, Applied to an electronic device, the computer program product includes computer instructions that, when executed by a processor, cause the electronic device to perform the method as described in any one of claims 1-12.