Data storage method and device, electronic equipment and storage medium

By storing data blocks in different locations within electronic devices based on their update parameters, the problem of file system aging is solved, fragmentation is reduced, user experience is improved, and the lifespan of storage hardware is extended.

CN117472861BActive Publication Date: 2026-11-20BEIJING XIAOMI MOBILE SOFTWARE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210869180.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-22
Publication Date
2026-11-20
Estimated Expiration
2042-07-22

AI Technical Summary

Technical Problem

After prolonged use, electronic devices age due to increased storage fragmentation in the file system, affecting system performance and reducing user experience. Existing defragmentation methods increase data read/write frequency, impacting the lifespan of storage hardware.

Method used

By identifying the target data object to be processed in the file system and obtaining its update parameters, the data blocks are stored in different storage locations according to the update parameters, reducing fragmentation caused by differences in update parameters between adjacent data blocks, and classifying and storing data blocks as cold, hot, and warm.

Benefits of technology

Reduce the probability of storage fragmentation, avoid file system aging, improve user experience, and extend the lifespan of storage hardware.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117472861B_ABST
    Figure CN117472861B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a data storage method and device, electronic equipment and storage medium, and belongs to the technical field of software. First, a target data object to be processed in a file system is determined, and the target data object is stored in at least one data block. Then, one or more target data blocks that have been updated are determined from the at least one data block. Then, for each target data block, a current update parameter of the target data block is obtained according to an update mode of the target data block. Finally, a target storage location of the target data block in a storage area is determined according to the current update parameter, and the target data block is stored in the storage area according to the target storage location. In this way, the data blocks can be stored in different storage locations according to the update parameters, the storage fragmentation caused by the large difference between the update parameters of adjacent data blocks is reduced, the probability of storage fragmentation is reduced, the aging of the file system caused by the storage fragmentation is avoided, and the user experience is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of software, and more particularly to a data storage method, apparatus, electronic device, and storage medium. Background Technology

[0002] Electronic devices tend to become sluggish after prolonged use. One important reason for this is the aging of the file system due to increased storage fragmentation. File system aging leads to system performance degradation and seriously affects the user experience.

[0003] In related technologies, defragmentation is usually used to alleviate this problem. However, frequent defragmentation increases the frequency of data reading and writing, which affects the lifespan of electronic device storage hardware and the user experience. Summary of the Invention

[0004] To overcome the problems existing in related technologies, this disclosure provides a data storage method, apparatus, electronic device, and storage medium.

[0005] According to a first aspect of the present disclosure, a data storage method is provided, the method comprising:

[0006] Identify the target data object to be processed in the file system, wherein the target data object is stored in at least one data block;

[0007] From the at least one data block, determine one or more target data blocks that have been updated;

[0008] For each target data block, the current update parameters of the target data block are obtained according to the update method of the target data block. The update parameters are used to characterize the update frequency of the target data block.

[0009] The target storage location of the target data block in the storage area is determined based on the current update parameters, and the target data block is stored in the storage area according to the target storage location.

[0010] Optionally, the update method includes adding a data block or modifying a data block; obtaining the current update parameters of the target data block according to the update method of the target data block includes:

[0011] When the update method includes changing the data block, the historical update time of the target data block is determined, and the historical update time is the update time of the last update of the target data block;

[0012] The historical update parameters, the number of first data blocks, and the number of second data blocks at the historical update time are obtained. The number of first data blocks represents the sum of the number of data blocks allocated by the file system at the creation time of the target data block and the number of first updates. The number of first updates represents the number of times the file system updates the data blocks from the creation time to the historical update time. The number of second data blocks represents the sum of the number of data blocks allocated by the file system at the creation time and the number of second updates. The number of second updates represents the number of times the file system updates the data blocks from the creation time to the current time.

[0013] The current update parameters are determined based on the number of the first data blocks, the number of the second data blocks, and the historical update parameters.

[0014] Optionally, determining the current update parameter based on the number of the first data blocks, the number of the second data blocks, and the historical update parameters includes:

[0015] Obtain the difference between the number of the second data blocks and the number of the first data blocks;

[0016] The current update parameter is determined by weighting the historical update parameter and the difference according to a preset weight.

[0017] Optionally, the method further includes:

[0018] For each target data block, the current update parameter is used to replace the historical update parameter, and the second data block number is used to replace the first data block number.

[0019] Optionally, the method further includes:

[0020] When the update method includes the addition of new data blocks, the preset update parameters are used as the current update parameters.

[0021] Optionally, determining the target storage location of the target data block in the storage area based on the current update parameters includes:

[0022] Based on the current update parameters of the target data block, the data block type of the target data block is determined, and target data blocks of different data block types correspond to different storage locations;

[0023] The target storage location of the target data block in the storage area is determined based on the data block type.

[0024] Optionally, the data block type includes cold data blocks, hot data blocks, or warm data blocks, and determining the data block type of the target data block based on the current update parameters of the target data block includes:

[0025] If the current update parameter is less than or equal to a first preset parameter threshold, the data block type of the target data block is determined to be a hot data block; or,

[0026] If the current update parameter is greater than the first preset parameter threshold and less than or equal to the second preset parameter threshold, the data block type of the target data block is determined to be a warm data block; or,

[0027] If the current update parameter is greater than the second preset parameter threshold, the data block type of the target data block is determined to be a cold data block.

[0028] Optionally, determining the data block type of the target data block based on the current update parameters of the target data block includes:

[0029] By using the pre-defined correspondence between update parameters and data block types, the data block type of the target data block is determined from multiple pre-defined data block types based on the current update parameters of the target data block.

[0030] Optionally, the storage area includes multiple preset location areas, and determining the target storage location of the target data block in the storage area according to the data block type includes:

[0031] The target location region corresponding to the data block type is determined from the plurality of preset location regions, and different data block types correspond to different preset location regions;

[0032] The target storage location is determined from the target location region.

[0033] Optionally, the method further includes:

[0034] The target fragment processing strategy corresponding to the target location region is determined from multiple preset fragment processing strategies, and different preset location regions correspond to different preset fragment processing strategies.

[0035] The target location region is fragmented according to the target fragmentation processing strategy.

[0036] According to a second aspect of the present disclosure, a data storage apparatus is provided, the apparatus comprising:

[0037] The first determining module is configured to determine a target data object to be processed in the file system, the target data object being stored in at least one data block;

[0038] The second determining module is configured to determine one or more target data blocks that have been updated from the at least one data block;

[0039] The acquisition module is configured to acquire the current update parameters of each target data block according to the update method of the target data block. The update parameters are used to characterize the update frequency of the target data block.

[0040] The storage module is configured to determine the target storage location of the target data block in the storage area based on the current update parameters, and store the target data block in the storage area according to the target storage location.

[0041] Optionally, the update method includes adding a data block or changing a data block; the acquisition module is further configured to:

[0042] When the update method includes changing the data block, the historical update time of the target data block is determined, and the historical update time is the update time of the last update of the target data block;

[0043] The historical update parameters, the number of first data blocks, and the number of second data blocks at the historical update time are obtained. The number of first data blocks represents the sum of the number of data blocks allocated by the file system at the creation time of the target data block and the number of first updates. The number of first updates represents the number of times the file system updates the data blocks from the creation time to the historical update time. The number of second data blocks represents the sum of the number of data blocks allocated by the file system at the creation time and the number of second updates. The number of second updates represents the number of times the file system updates the data blocks from the creation time to the current time.

[0044] The current update parameters are determined based on the number of the first data blocks, the number of the second data blocks, and the historical update parameters.

[0045] Optionally, the acquisition module is further configured to:

[0046] Obtain the difference between the number of the second data blocks and the number of the first data blocks;

[0047] The current update parameter is determined by weighting the historical update parameter and the difference according to a preset weight.

[0048] The acquisition module is further configured to:

[0049] For each target data block, the current update parameter is used to replace the historical update parameter, and the second data block number is used to replace the first data block number.

[0050] The acquisition module is further configured to:

[0051] When the update method includes the addition of new data blocks, the preset update parameters are used as the current update parameters.

[0052] Optionally, the storage module is further configured to:

[0053] Based on the current update parameters of the target data block, the data block type of the target data block is determined, and target data blocks of different data block types correspond to different storage locations;

[0054] The target storage location of the target data block in the storage area is determined based on the data block type.

[0055] Optionally, the data block type includes cold data blocks, hot data blocks, or warm data blocks, and the storage module is further configured to:

[0056] If the current update parameter is less than or equal to a first preset parameter threshold, the data block type of the target data block is determined to be a hot data block; or,

[0057] If the current update parameter is greater than the first preset parameter threshold and less than or equal to the second preset parameter threshold, the data block type of the target data block is determined to be a warm data block; or,

[0058] If the current update parameter is greater than the second preset parameter threshold, the data block type of the target data block is determined to be a cold data block.

[0059] Optionally, the storage module is further configured to:

[0060] By using the pre-defined correspondence between update parameters and data block types, the data block type of the target data block is determined from multiple pre-defined data block types based on the current update parameters of the target data block.

[0061] Optionally, the storage module is further configured to:

[0062] The target location region corresponding to the data block type is determined from the plurality of preset location regions, and different data block types correspond to different preset location regions;

[0063] The target storage location is determined from the target location region.

[0064] Optionally, the storage module is further configured to:

[0065] The target fragment processing strategy corresponding to the target location region is determined from multiple preset fragment processing strategies, and different preset location regions correspond to different preset fragment processing strategies.

[0066] The target location region is fragmented according to the target fragmentation processing strategy.

[0067] According to a third aspect of the present disclosure, an electronic device is provided, the electronic device comprising:

[0068] A memory on which computer programs are stored;

[0069] A processor for executing the computer program in the memory to implement the steps of the method described in any of the embodiments of the first aspect above.

[0070] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps of the method described in the first aspect.

[0071] The technical solutions provided by the embodiments of this disclosure may include the following beneficial effects:

[0072] This disclosure first identifies target data objects to be processed in the file system, the target data objects being stored in at least one data block; secondly, it identifies one or more target data blocks that have been updated from the at least one data block; then, for each target data block, it obtains the current update parameters of the target data block according to the update method of the target data block; finally, it determines the target storage location of the target data block in the storage area according to the current update parameters, and stores the target data block in the storage area according to the target storage location. In this way, data blocks can be stored in different storage locations according to update parameters, reducing storage fragmentation caused by large differences in update parameters between adjacent data blocks, lowering the probability of storage fragmentation, avoiding file system aging caused by fragmentation, and improving the user experience.

[0073] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure.

[0074] Other features and advantages of this disclosure will be described in detail in the following detailed description section. Attached Figure Description

[0075] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, but do not constitute a limitation thereof.

[0076] Figure 1 This is a flowchart illustrating a data storage method according to an exemplary embodiment.

[0077] Figure 2This is a flowchart illustrating another data storage method according to an exemplary embodiment.

[0078] Figure 3 This is a schematic diagram illustrating the data block update of a data object according to an exemplary embodiment.

[0079] Figure 4 This is a flowchart illustrating yet another data storage method according to an exemplary embodiment.

[0080] Figure 5 This is a flowchart illustrating yet another data storage method according to an exemplary embodiment.

[0081] Figure 6 This is a block diagram illustrating another data storage device according to an exemplary embodiment.

[0082] Figure 7 This is a block diagram illustrating an electronic device according to an exemplary embodiment. Detailed Implementation

[0083] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims. It should be understood that the specific embodiments described herein are for illustrative and explanatory purposes only and are not intended to limit the scope of this disclosure.

[0084] First, let's explain the application scenario of this disclosure. In the software of electronic devices, the file system manages multiple data objects, such as data files or directories that store data files. During the user's daily use of electronic devices (such as downloading movies, installing / uninstalling applications, browsing web pages, or instant messaging), the file system will correspondingly create, update, or delete data objects, which may lead to storage fragmentation.

[0085] The electronic devices involved in this disclosure may be smartphones, tablets, smartwatches, smart bracelets, PDAs (Personal Digital Assistants), or CPEs (Customer Premise Equipment), and this disclosure does not limit them.

[0086] The inventors noted that data storage methods in related file systems still suffer from significant storage fragmentation and file system aging issues. For example, in the F2FS (Flash Friendly File System) software system, data objects are categorized and stored in different locations based on their "hot" or "cold" classification. However, this coarse-grained approach still suffers from the aforementioned problems. For instance, F2FS marks directory data as "hot" types, but not all directory data should actually be classified as such. For example, directory files created during application installation rarely change after creation unless the application is uninstalled.

[0087] This disclosure provides a data storage method that can store data blocks in different storage locations according to update parameters, reducing storage fragmentation caused by large differences in update parameters between adjacent data blocks, lowering the probability of storage fragmentation, avoiding file system aging caused by fragmentation, and improving user experience.

[0088] The present disclosure will now be described in conjunction with specific embodiments.

[0089] Figure 1 This is a flowchart illustrating a data storage method according to an exemplary embodiment, such as... Figure 1 As shown, the method may include the following steps:

[0090] In step S101, the target data object to be processed in the file system is determined.

[0091] The target data object is stored in at least one data block.

[0092] The target data object can be a file or a directory containing files. Taking F2FS as an example, in the F2FS file system, the storage area consists of data blocks of a preset size. Each data block is allocated to store data (such as files or directories) and can also be allocated to store indexes. A certain number of contiguous blocks can form a storage segment, and can be further divided into storage sections. For details, please refer to the descriptions in related technologies, which will not be repeated here.

[0093] In step S102, one or more target data blocks that have been updated are determined from at least one data block.

[0094] A file system can update one or more data blocks of a target data object (file or directory). This update can include adding new data blocks, modifying existing data blocks (e.g., modifying data in data blocks using the out-of-place method in the F2FS file system), or deleting data in existing data blocks.

[0095] In some possible implementations, when storing data objects, the file system can save only the target data blocks that have been updated, while leaving the data blocks that have not been updated untouched (i.e., their storage location remains unchanged). Taking F2FS as an example, in the F2FS file system, when adding new data blocks or modifying existing data blocks (e.g., modifying data in data blocks using the out-of-place method in the F2FS file system), the newly added data block or the modified data block can be used as the target data block.

[0096] In step S103, for each target data block, the current update parameters of the target data block are obtained according to the update method of the target data block.

[0097] The update parameter is used to characterize the frequency of updates to the target data block.

[0098] For example, the smaller the update parameter, the higher the frequency of the target data block updates; conversely, the larger the update parameter, the lower the frequency of the target data block updates.

[0099] Taking F2FS as an example, in the F2FS file system, a storage segment is the smallest unit of storage allocation, and a storage segment consists of multiple data blocks. If data with significantly different update parameters are stored in the same storage segment, after a period of time, data in frequently updated blocks will become invalid, while data in infrequently updated blocks will remain valid. Thus, due to the large differences in update parameters between adjacent data blocks, storage fragmentation occurs in that storage segment. The F2FS file system must perform fragmentation processing on this storage segment to fully utilize it. Therefore, determining the update parameters of each data block of the target data object is crucial for reducing the probability of storage fragmentation and avoiding the resulting file system aging.

[0100] In step S104, the target storage location of the target data block in the storage area is determined according to the current update parameters, and the target data block is stored in the storage area according to the target storage location.

[0101] In some possible implementations, the target storage location of the target data block in the storage area can be determined by the following steps based on the current update parameters.

[0102] Step 1: Determine the data block type of the target data block based on the current update parameters of the target data block. Different data block types correspond to different storage locations.

[0103] In some embodiments, the data block type may include cold data block, hot data block, or warm data block. The data block type of the target data block can be determined based on the current update parameters of the target data block in the following manner.

[0104] Method 1: If the current update parameter is less than or equal to the first preset parameter threshold, determine the data block type of the target data block as a hot data block; or,

[0105] Method 2: If the current update parameter is greater than the first preset parameter threshold and less than or equal to the second preset parameter threshold, determine the target data block's data block type as a warm data block; or,

[0106] Method 3: If the current update parameter is greater than the second preset parameter threshold, determine the data block type of the target data block as a cold data block.

[0107] The second preset parameter threshold is greater than the first preset parameter threshold.

[0108] Step 2: Determine the target storage location of the target data block in the storage area based on the data block type.

[0109] In some possible implementations, after determining the data block type of the target data block, the corresponding storage location can be determined from multiple storage locations in the storage region based on the data block type. For example, in F2FS, the target storage segment corresponding to the target data block can be determined from multiple storage segments in the storage region based on the data block type (e.g., hot data block, warm data block, or cold data block). For example, target data blocks of the same data block type correspond to the same or similar target storage segments.

[0110] After determining the target storage location of the target data block in the storage area based on the data block type, the target data block can be stored in the storage area according to the target storage location.

[0111] By adopting the above scheme, data blocks can be stored in different storage locations according to update parameters, reducing storage fragmentation caused by large differences in update parameters between adjacent data blocks, lowering the probability of storage fragmentation, avoiding file system aging caused by it, and improving the user experience.

[0112] In some embodiments, the update method may include adding or modifying data blocks. It should be noted that the update method may also include deleting data blocks. When the update method includes deleting data blocks, the data block corresponding to the data object will be deleted, and the corresponding storage location can be reclaimed by the file system's recycling program. Since the data in the deleted data block becomes invalid, the update method of the target data block in the step of obtaining the current update parameters of the target data block according to the update method of the target data block in this disclosure may include adding or modifying data blocks (i.e., excluding deleting data blocks).

[0113] Figure 2 This is a flowchart illustrating another data storage method according to an exemplary embodiment, such as... Figure 2 As shown, step S103 may include the following steps:

[0114] In step S1031, if the update method includes changing the data block, the historical update time of the target data block is determined.

[0115] The historical update time refers to the last update time of the target data block. A modified data block indicates that the target data block of the data object was already stored in the storage area before the modification. The historical update time can be the historical addition time when the target data block was created, or the historical modification time when the target data block was modified. This disclosure does not impose any restrictions on this.

[0116] In step S1032, the historical update parameters, the number of first data blocks, and the number of second data blocks at the historical update time are obtained.

[0117] The first data block count represents the sum of the number of data blocks allocated by the file system at the creation time of the target data block and the first update count. The first update count represents the number of data block updates by the file system from the creation time to the historical update time. The second data block count represents the sum of the number of data blocks allocated by the file system at the creation time and the second update count. The second update count represents the number of data block updates by the file system from the creation time to the current time.

[0118] Figure 3 This is a schematic diagram illustrating a data block update of a data object according to an exemplary embodiment. For example... Figure 3 As shown.

[0119] At time t0, the file system creates two new data objects: Data Object 1 and Data Object 2. Data Object 1 has 6 data blocks, and Data Object 2 has 5 data blocks. At time t1, data blocks 4 and 5 are changed from 4a and 5a to 4b and 5b, respectively. At time t3, data blocks 11, 12, and 13 of Data Object 2 are changed from 11a, 12a, and 13a to 11b, 12b, and 13b, respectively. At time t3, data blocks 4 and 5 are changed from 4b and 5b to 4c and 5c, respectively, and data block 6 is changed from 6a to 6b. The file system creates a new data block 7 for Data Object 1.

[0120] In some possible implementations, at time t0, the update parameters for all data blocks of data object one and data object two are preset update parameters (i.e., 0xFFFFFFFF). Correspondingly, the number of data blocks allocated at the creation time of all data blocks is 11 (i.e., the total number of data blocks of all data objects updated by the file system at time t0). At time t1, the target data blocks are data blocks 4 and 5. The historical update time of the target data blocks is the last update time of the target data blocks (i.e., t0). At this time, the first update count is 0 (because the historical update time of data blocks 4 and 5 is the creation time). The file system updates data blocks 2 times from creation time t0 to the current time t1, so the second update count is 2. Therefore, the number of the first data blocks is 11, and the number of the second data blocks is 13. The methods for obtaining the number of data blocks allocated at creation time, the number of data block updates from creation time to the historical update time, and the number of data block updates from creation time to the current time can be found in the implementation of file systems in related technologies, and will not be elaborated here.

[0121] In some embodiments, for each data block of a data object, the historical update parameters and the number of the first data blocks can be stored in a preset object storage structure, and these parameters can be retrieved from the preset object storage structure. In some possible implementations, the data block's identification information (e.g., in an F2FS system, the data block's identification information is also called the Page index), the historical update parameters, and the number of the first data blocks can be stored in a red-black tree. For example, the data block's identification information can be used as the index of the red-black tree, and the historical update parameters and the number of the first data blocks can be used as the content of the red-black tree. Taking data block 4 as an example, at time t0, the data block's identification information (i.e., 4) is used as the index, and the historical update parameters and the number of the first data blocks (0xFFFFFFFF, 11) are used as the content to store the data in the red-black tree.

[0122] In some possible implementations, where the update method includes deleting data blocks, the historical update parameters of the data block, the number of the first data block, and the corresponding data block index can be deleted from the object storage structure.

[0123] The red-black tree described above is a self-balancing binary search tree. Red-black trees allow for the addition, modification, or deletion of elements with high performance. For specific implementation details regarding addition, modification, deletion, and retrieval in red-black trees, please refer to the descriptions of red-black trees in related technical documents; these details will not be elaborated upon here.

[0124] When the update method includes adding new data blocks, the preset update parameters will be used as the current update parameters.

[0125] For example, the preset update parameter can be 0xFFFFFFFF, which indicates that the newly added data block will be stored in a preset storage location within the storage area (e.g., the storage location corresponding to the data block with the lowest update frequency). After determining the current update parameter and adding the data block, the current update parameter can be used as the historical update parameter based on the identifier information of the target data block, and the total number of data blocks of all data objects updated by the file system at the current moment can be stored in the object storage structure as the first data block count.

[0126] The historical update parameters and the number of the first data block for multiple data objects in the file system can be stored in a preset system storage structure. In some possible implementations, this system storage structure can be a Radix Tree. The identification information of the data objects (e.g., in the F2FS system, the identification information of the data objects is also called inode) and the address of the corresponding object storage structure (e.g., the address of the object storage structure corresponding to the data object) can be stored in the radix tree. For example, the identification information of the data objects can be used as the index of the radix tree, and the address of the corresponding object storage structure (e.g., the address of the root node of the red-black tree corresponding to the data object) can be stored in the radix tree as the content.

[0127] The aforementioned radix tree is a binary tree that establishes a mapping between long integer keys and pointers. It is suitable for efficiently handling the correspondence between long integer keys (e.g., the identifier information of data objects in an F2FS system) and pointers (e.g., the address of the root node of a red-black tree). For specific implementations of adding, modifying, deleting, and retrieving data in a radix tree, please refer to the description of radix trees in related technologies; these details will not be elaborated upon here.

[0128] It should be noted that the red-black tree is an example of a preset object storage structure in this disclosure, and the radix tree is an example of a preset system storage structure in this disclosure. This disclosure does not limit the choice of object storage structure and system storage structure.

[0129] In step S1033, the current update parameters are determined based on the number of first data blocks, the number of second data blocks, and the historical update parameters.

[0130] In some possible implementations, the current update parameters can be determined by the following steps based on the number of the first data block, the number of the second data block, and the historical update parameters.

[0131] Step 1: Obtain the difference between the number of the second data block and the number of the first data block.

[0132] For example, for Figure 3 In data block 4, at time t1, the difference between the number of the second data block and the number of the first data block is 2 (i.e., 13-11).

[0133] At time t3, the difference between the number of the second data block and the number of the first data block is 7 (at this time, the number of the second data block is 11+9=20, and the number of the first data block is 11+2=13).

[0134] Step 2: Determine the current update parameters by weighting the historical update parameters and differences according to the preset weights.

[0135] In some possible implementations, if the historical update parameter is equal to the preset update parameter (0xFFFFFFFF), the difference is used as the current update parameter.

[0136] Still with Figure 3 Taking data block 4 as an example, at the creation time of this data block (i.e., t0), the preset update parameter (0xFFFFFFFF) is stored as a historical update parameter in the object storage structure. At the current time (i.e., t1), the historical update parameter obtained from the object storage structure is the preset update parameter. Then, the difference between the number of the second data block and the number of the first data block is used as the current update parameter (i.e., 2). After determining that the current update parameter of data block 4 is 2 at time t1, this current update parameter can be stored as a historical update parameter in the object storage structure corresponding to the data object.

[0137] If the historical update parameter is not equal to the preset update parameter (0xFFFFFFFF), the update parameter can be determined according to the following formula 1.

[0138] A i =∝×A i-1 +(1-∝)×Δ i (Formula 1)

[0139] Among them, A i Let A be the current update parameter at time i, and ∝ be the preset weight of the historical update parameters, with a value range of 0 ≤ ∝ < 1. i-1For the historical update parameters at time i-1, Δ i It is the difference between the number of the second data block and the number of the first data block at time i.

[0140] For example, the preset weight value can be 0.3, for Figure 3 In data block 4, at time t3, the historical update parameter can be obtained from the object storage structure corresponding to data object 1. The difference between the number of the second data block and the number of the first data block is 7. Then, by formula 1, the current update parameter can be determined to be 0.3×2+(1-0.3)×7=5.5.

[0141] By adopting the above scheme, data blocks can be stored in different storage locations according to update parameters, reducing storage fragmentation caused by large differences in update parameters between adjacent data blocks, lowering the probability of storage fragmentation, avoiding file system aging caused by it, and improving the user experience.

[0142] Figure 4 This is a flowchart illustrating yet another data storage method according to an exemplary embodiment, such as... Figure 4 As shown, the method may further include the following steps:

[0143] In step S1034, for each target data block, the current update parameter is used to replace the historical update parameter, and the number of the second data block is used to replace the number of the first data block.

[0144] For example, after determining the current update parameter by weighting the historical update parameter and the difference according to the preset weight, the current update parameter can be used to replace the historical update parameter, the number of the second data block can be used to replace the number of the first data block, and the replaced data can be stored in the object storage structure corresponding to the data object.

[0145] Still with Figure 3 Taking data block 4 as an example, at time t1, after determining that the current update parameter is 2, the historical update parameter (0xFFFFFFFF) can be replaced with the current update parameter (i.e., 2), and the number of the first data block (i.e., 11) can be replaced with the number of the second data block (i.e., 13). The replaced data is then stored in the object storage structure corresponding to the data object. This allows the historical update parameter (i.e., 2) and the number of the first data block (i.e., 13) to be obtained at time t3, thus determining the current update parameter at time t3. Similarly, at time t3, after determining that the current update parameter is 5.5, the historical update parameter (i.e., 2) can be replaced with the current update parameter (i.e., 5.5), and the number of the first data block (i.e., 13) can be replaced with the number of the second data block (20), facilitating the determination of the new current update parameter at subsequent times.

[0146] By adopting the above scheme, data blocks can be stored in different storage locations according to update parameters, reducing storage fragmentation caused by large differences in update parameters between adjacent data blocks, lowering the probability of storage fragmentation, avoiding file system aging caused by it, and improving the user experience.

[0147] In another embodiment, when storing the historical update parameters of the target data block and the number of the first data blocks into a preset object storage structure, in order to reduce the amount of data stored, consecutive target data blocks with the same or similar historical update parameters (for example, grouping the target data blocks so that the difference between the update parameters of the target data blocks in the group and the average update parameters of the group is less than or equal to a preset difference threshold) can be stored as an element in the object storage structure to further improve performance. The specific storage structure can be (starting data block identification information, length, historical update parameters, number of first data blocks).

[0148] by Figure 3 Taking data object one as an example, at time t3, for each target data block, after replacing the historical update parameters with the current update parameters and replacing the number of the first data block with the number of the second data block, it can be determined that the historical update parameters of data blocks 1, 2, 3, and 7 are the preset update parameters (0xFFFFFFFF), the historical update parameters of data blocks 4 and 5 are 5.5, and the historical update parameter of data block 6 is 9. The seven data blocks of data object one can be stored in the manner shown in Table 1 below.

[0149]

[0150] Table 1

[0151] As shown in Table 1, data blocks 1, 2, and 3 have the same historical update parameters and are consecutive data blocks. When storing them on the object storage structure, the identifier information of the starting data block (i.e., 1) can be used as the index, the number of consecutive data blocks can be used as the length (i.e., 3), and the average update parameter of multiple data blocks (e.g., 0xFFFFFFFF) can be used as the historical update parameter. These parameters are stored together with the number of the first data blocks in the object storage structure. For data blocks 4 and 5, the identifier information of the corresponding starting data block, the length, the historical update parameter, and the number of the first data blocks are 4, 2, 5.5, and 20, respectively.

[0152] By adopting the above solution, the amount of data stored in the data storage method, such as historical update parameters, can be further reduced, thereby further improving performance.

[0153] In another embodiment, the data block type of the target data block can also be determined based on the current update parameters of the target data block in the following manner.

[0154] By establishing a predefined correspondence between update parameters and data block types, the target data block type is determined from multiple predefined data block types based on the current update parameters of the target data block.

[0155] Different data block types can correspond to different storage locations. This disclosure does not limit the number of preset data block types.

[0156] For example, the data block type of the target data block can be determined using Table 2 below.

[0157] Current update parameters Data block type <![CDATA[A i <a1]]> Data block type 1 <![CDATA[a1≤A i <a2]]> Data block type two <![CDATA[a2≤A i <a3]]> Data block type three <![CDATA[a3≤A i <a4]]> Data block type four <![CDATA[a4≤A i ]]> Data block type five

[0158] Table 2

[0159] As shown in Table 2, when the current update parameters are in different ranges, the corresponding data block type can be determined based on the current update parameters. Data block type one to data block type five represent multiple data block types with different update hotness. After determining the corresponding data block type based on the current update parameters, the target storage location of the target data block in the storage area can be determined based on the data block type, and the target data block can be stored in the storage area according to the target storage location.

[0160] It should be noted that the multiple rows in Table 2 above are listed in the same table as an example, but this does not mean that all rows in the table must exist simultaneously as shown in the table, nor does it mean that the table imposes a restriction on the correspondence between data block types.

[0161] In another embodiment, the data block type of the target data block can be further determined from multiple preset data block types based on the attributes of the data object and the current update parameters.

[0162] For example, the data block type of the target data block can be determined using Table 3 below, based on the file extension of the data object (e.g., db for database files, MP4 for multimedia files) and the current update parameters.

[0163] file extensions for data objects Current update parameters Data block type db <![CDATA[A i <a1]]> Data block type 1 db <![CDATA[a1≤A i <a2]]> Data block type two db <![CDATA[a2≤A i ]]> Data block type three MP4 <![CDATA[A i <a1]]> Data block type two MP4 <![CDATA[a1≤A i <a2]]> Data block type three MP4 <![CDATA[a2≤A i <a3]]> Data block type four MP4 <![CDATA[a3≤A i <a4]]> Data block type five MP4 <![CDATA[a4≤A i ]]> Data block type six

[0164] Table 3

[0165] As shown in Table 3, in A iIn the case of a1, if the suffix name of the data object indicates that the data object is a database file, it may be determined that the data block type corresponding to the target data block is the first data block type; if the suffix name of the data object indicates that the data object is a multimedia file, it may be determined that the data block type corresponding to the target data block is the second data block type. Correspondingly, when the current update parameter is in different intervals and the suffix name of the data object is different, the data block type corresponding to the target data block may be determined according to the interval where the current update parameter is located and the suffix name of the data object. After the corresponding data block type is determined according to the current update parameter, the target storage position of the target data block in the storage area may be determined according to the data block type, and the target data block is stored in the storage area according to the target storage position.

[0166] It should be particularly noted that the data block types corresponding to each row in the above Table 3 may be the same or different. The multiple rows in the above Table 3 are exemplarily listed in the same table, but this does not mean that all rows in the table must exist simultaneously as shown in the table, nor does it mean that the table constitutes a limitation on the correspondence of the data block types.

[0167] By adopting the above solution, data blocks can be stored in different storage positions according to the update parameters, which reduces storage fragments formed due to large differences in update parameters between adjacent data blocks, lowers the occurrence probability of storage fragments, avoids the resulting aging of the file system, and improves user experience.

[0168] In some embodiments, the storage area includes a plurality of preset position regions, and the target storage position of the target data block in the storage area may be determined according to the data block type through the following steps.

[0169] Step 1: Determine the target position region corresponding to the data block type from the plurality of preset position regions.

[0170] Still taking the F2FS file system as an example, the storage area may be divided into a plurality of preset position regions according to different data block types, where different data block types correspond to different preset position regions. For example, each preset position region may include one or more storage Segments, or may be one or more storage Sections, which is not limited in the present disclosure.

[0171] Step 2: Determine the target storage position from the target position region.

[0172] Still taking the F2FS file system as an example, the target storage segment may be determined from a plurality of storage segments of the target position region, and the target storage segment is used as the target storage position.

[0173] Figure 5This is a flowchart illustrating yet another data storage method according to an exemplary embodiment, such as... Figure 5 As shown, the method may further include the following steps:

[0174] In step S105, the target fragment processing strategy corresponding to the target location region is determined from multiple preset fragment processing strategies.

[0175] Different preset location areas correspond to different preset fragment processing strategies.

[0176] The storage area can be fragmented using the file system's fragmentation mechanism. For example, in the F2FS system, a garbage collection mechanism can be used to fragment the storage area. The triggering conditions for this fragmentation can include conditionally triggered foreground garbage collection and periodically triggered background garbage collection. The triggering condition for foreground garbage collection can be that the proportion of free data segments is less than or equal to a preset proportion threshold. In some possible implementations, multiple preset fragmentation strategies can include different fragmentation triggering conditions, such as different preset proportion thresholds and / or different processing cycles.

[0177] For example, the preset location area may include a hot data block area corresponding to a hot data block, a warm data block area corresponding to a warm data block, and a cold data block area corresponding to a cold data block. The fragmentation processing strategy corresponding to the hot data block area may have a fragmentation processing cycle of T, the fragmentation processing strategy corresponding to the warm data block area may have a fragmentation processing cycle of 4T, and the fragmentation processing strategy corresponding to the cold data block area may have a fragmentation processing cycle of 32T.

[0178] In step S106, the target location area is processed for fragmentation according to the target fragmentation processing strategy.

[0179] After determining the target fragmentation processing strategy for the target location area, fragmentation processing can be performed on the target location area. For specific technical solutions for processing the target location area, please refer to the descriptions in relevant technologies, which will not be repeated here.

[0180] By adopting the above scheme, fragmentation of the target location area can be processed in a timely manner according to different fragmentation processing strategies, thereby further improving data storage performance and enhancing user experience.

[0181] Figure 6 This is a block diagram illustrating a data storage device 600 according to an exemplary embodiment, such as... Figure 6 As shown, the data storage device 600 includes:

[0182] The first determining module 601 is configured to determine the target data object to be processed in the file system, the target data object being stored in at least one data block;

[0183] The second determining module 602 is configured to determine one or more target data blocks from at least one data block that have been updated;

[0184] The acquisition module 603 is configured to acquire the current update parameters of each target data block according to the update method of the target data block. The update parameters are used to characterize the update frequency of the target data block.

[0185] Storage module 604 is configured to determine the target storage location of the target data block in the storage area based on the current update parameters, and store the target data block in the storage area according to the target storage location.

[0186] Optionally, the update method includes adding a data block or changing a data block; the acquisition module 603 is also configured to determine the historical update time of the target data block when the update method includes changing a data block, wherein the historical update time is the update time of the last update of the target data block;

[0187] Obtain the historical update parameters, the number of first data blocks, and the number of second data blocks at the historical update time. The number of first data blocks represents the sum of the number of data blocks allocated by the file system at the creation time of the target data block and the number of first updates. The number of first updates represents the number of data block updates from the creation time to the historical update time. The number of second data blocks represents the sum of the number of data blocks allocated by the file system at the creation time and the number of second updates. The number of second updates represents the number of data block updates from the creation time to the current time.

[0188] The current update parameters are determined based on the number of the first data block, the number of the second data block, and the historical update parameters.

[0189] Optionally, module 603 is also configured to:

[0190] Get the difference between the number of the second data block and the number of the first data block;

[0191] The current update parameters are determined by weighting the historical update parameters and differences according to preset weights.

[0192] Optionally, module 603 is also configured to:

[0193] For each target data block, the current update parameters are used to replace the historical update parameters, and the number of the second data block is used to replace the number of the first data block.

[0194] Optionally, module 603 is also configured to:

[0195] When the update method includes adding new data blocks, the preset update parameters will be used as the current update parameters.

[0196] Optionally, the storage module 604 is also configured to: determine the data block type of the target data block based on the current update parameters of the target data block, with different data block types corresponding to different storage locations;

[0197] Determine the target storage location of the target data block in the storage area based on the data block type.

[0198] Optionally, the data block type includes cold data blocks, hot data blocks, or warm data blocks, and storage module 604 is also configured as follows:

[0199] If the current update parameter is less than or equal to the first preset parameter threshold, the data block type of the target data block is determined to be a hot data block; or,

[0200] If the current update parameter is greater than the first preset parameter threshold and less than or equal to the second preset parameter threshold, the data block type of the target data block is determined to be a warm data block; or,

[0201] If the current update parameter is greater than the second preset parameter threshold, the data block type of the target data block is determined to be a cold data block.

[0202] Optionally, storage module 604 is also configured as follows:

[0203] By establishing a predefined correspondence between update parameters and data block types, the target data block type is determined from multiple predefined data block types based on the current update parameters of the target data block.

[0204] Optionally, the storage area includes multiple preset location areas, and the storage module 604 is further configured as follows:

[0205] The target location area corresponding to the data block type is determined from multiple preset location areas, and different data block types correspond to different preset location areas;

[0206] Determine the target storage location from the target location area.

[0207] Optionally, storage module 604 is also configured as follows:

[0208] The target fragmentation processing strategy corresponding to the target location region is determined from multiple preset fragmentation processing strategies, and different preset location regions correspond to different preset fragmentation processing strategies.

[0209] Fragmentation is performed on the target location area according to the target fragmentation processing strategy.

[0210] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.

[0211] By adopting the above technical solution, data blocks can be stored in different storage locations according to update parameters, reducing storage fragmentation caused by large differences in update parameters between adjacent data blocks, lowering the probability of storage fragmentation, avoiding file system aging caused by it, and improving the user experience.

[0212] Figure 7 This is a block diagram illustrating an electronic device 700 according to an exemplary embodiment. Figure 7 As shown, the electronic device 700 may include a processor 701 and a memory 702. The electronic device 700 may also include one or more of a multimedia component 703, an input / output interface 704, and a communication component 705.

[0213] The processor 701 controls the overall operation of the electronic device 700 to complete all or part of the steps in the data storage method described above. The memory 702 stores various types of data to support the operation of the electronic device 700. This data may include, for example, instructions for any application or method operating on the electronic device 700, and application-related data such as contact data, sent and received messages, pictures, audio, video, etc. The memory 702 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The multimedia component 703 may include a screen and audio components. The screen may be, for example, a touchscreen, and the audio component is used for outputting and / or inputting audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signals may be further stored in memory 702 or transmitted via communication component 705. The audio component also includes at least one speaker for outputting audio signals. Input / output interface 704 provides an interface between processor 701 and other interface modules, such as a keyboard, mouse, buttons, etc. These buttons may be virtual or physical buttons. Communication component 705 is used for wired or wireless communication between the electronic device 700 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G, 4G, NB-IoT, eMTC, or other 5G technologies, or combinations thereof, is not limited here. Therefore, the corresponding communication component 705 may include: a Wi-Fi module, a Bluetooth module, an NFC module, etc.

[0214] In another exemplary embodiment, a non-transitory computer-readable storage medium including program instructions is also provided, which, when executed by a processor, implement the steps of the data storage method described above. For example, the computer-readable storage medium may be the memory 702 including the program instructions described above, which may be executed by the processor 701 of the electronic device 700 to complete the data storage method described above.

[0215] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of this disclosure. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.

[0216] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.

Claims

1. A data storage method, characterized in that, The method includes: Identify the target data object to be processed in the file system, wherein the target data object is stored in at least one data block; From the at least one data block, determine one or more target data blocks that have been updated; For each target data block, the current update parameters of the target data block are obtained according to the update method of the target data block. The update parameters are used to characterize the update frequency of the target data block. Determine the target storage location of the target data block in the storage area based on the current update parameters, and store the target data block in the storage area according to the target storage location; The update method includes adding a data block or modifying a data block; obtaining the current update parameters of the target data block according to the update method of the target data block includes: When the update method includes changing the data block, the historical update time of the target data block is determined, and the historical update time is the update time of the last update of the target data block; Obtain the historical update parameters, the number of first data blocks, and the number of second data blocks at the historical update time. The number of first data blocks represents the sum of the number of data blocks allocated by the file system at the creation time of the target data block and the number of first updates. The number of first updates represents the number of times the file system updates the data blocks from the creation time to the historical update time. The number of second data blocks represents the sum of the number of data blocks allocated by the file system at the creation time and the number of second updates. The number of second updates represents the number of times the file system updates the data blocks from the creation time to the current time. Obtain the difference between the number of the second data blocks and the number of the first data blocks; The current update parameter is determined by weighting the historical update parameter and the difference according to a preset weight. When the update method includes the addition of new data blocks, the preset update parameters are used as the current update parameters.

2. The method according to claim 1, characterized in that, The method further includes: For each target data block, the current update parameter is used to replace the historical update parameter, and the second data block number is used to replace the first data block number.

3. The method according to any one of claims 1 to 2, characterized in that, Determining the target storage location of the target data block in the storage area based on the current update parameters includes: Based on the current update parameters of the target data block, the data block type of the target data block is determined, and target data blocks of different data block types correspond to different storage locations; The target storage location of the target data block in the storage area is determined based on the data block type.

4. The method according to claim 3, characterized in that, The data block type includes cold data blocks, hot data blocks, or warm data blocks. Determining the data block type of the target data block based on its current update parameters includes: If the current update parameter is less than or equal to a first preset parameter threshold, the data block type of the target data block is determined to be a hot data block; or, If the current update parameter is greater than the first preset parameter threshold and less than or equal to the second preset parameter threshold, the data block type of the target data block is determined to be a warm data block; or, If the current update parameter is greater than the second preset parameter threshold, the data block type of the target data block is determined to be a cold data block.

5. The method according to claim 3, characterized in that, The step of determining the data block type of the target data block based on the current update parameters of the target data block includes: By using the pre-defined correspondence between update parameters and data block types, the data block type of the target data block is determined from multiple pre-defined data block types based on the current update parameters of the target data block.

6. The method according to claim 3, characterized in that, The storage area includes multiple preset location areas, and determining the target storage location of the target data block in the storage area according to the data block type includes: The target location region corresponding to the data block type is determined from the plurality of preset location regions, and different data block types correspond to different preset location regions; The target storage location is determined from the target location region.

7. The method according to claim 6, characterized in that, The method further includes: The target fragment processing strategy corresponding to the target location region is determined from multiple preset fragment processing strategies, and different preset location regions correspond to different preset fragment processing strategies. The target location region is fragmented according to the target fragmentation processing strategy.

8. A data storage device, characterized in that, The device includes: The first determining module is configured to determine a target data object to be processed in the file system, the target data object being stored in at least one data block; The second determining module is configured to determine one or more target data blocks that have been updated from the at least one data block; The acquisition module is configured to acquire the current update parameters of each target data block according to the update method of the target data block. The update parameters are used to characterize the update frequency of the target data block. The storage module is configured to determine the target storage location of the target data block in the storage area based on the current update parameters, and store the target data block in the storage area according to the target storage location; The update method includes adding or modifying data blocks; the acquisition module is configured as follows: When the update method includes changing the data block, the historical update time of the target data block is determined, and the historical update time is the update time of the last update of the target data block; Obtain the historical update parameters, the number of first data blocks, and the number of second data blocks at the historical update time. The number of first data blocks represents the sum of the number of data blocks allocated by the file system at the creation time of the target data block and the number of first updates. The number of first updates represents the number of times the file system updates the data blocks from the creation time to the historical update time. The number of second data blocks represents the sum of the number of data blocks allocated by the file system at the creation time and the number of second updates. The number of second updates represents the number of times the file system updates the data blocks from the creation time to the current time. Obtain the difference between the number of the second data blocks and the number of the first data blocks; The current update parameter is determined by weighting the historical update parameter and the difference according to a preset weight. When the update method includes the addition of new data blocks, the preset update parameters are used as the current update parameters.

9. The apparatus according to claim 8, characterized in that, The acquisition module is further configured to: For each target data block, the current update parameter is used to replace the historical update parameter, and the second data block number is used to replace the first data block number.

10. An electronic device, characterized in that, include: A memory on which computer programs are stored; A processor for executing the computer program in the memory to implement the steps of the method according to any one of claims 1-7.

11. A non-transitory computer-readable storage medium having computer program instructions stored thereon, characterized in that, When executed by a processor, the program instructions implement the steps of the method described in any one of claims 1-7.

Citation Information

Patent Citations

  • Multi-time-window hybrid fault-tolerant cloud storage method and device and medium

    CN112445653A

  • Solid state disk, wear balancing method thereof and terminal equipment

    CN112817880A