Storage space management method and electronic equipment

By optimizing storage space management using predicted life indicators in electronic devices, the problem of low data block management efficiency in the prior art is solved, and the storage space management load is significantly reduced.

CN119847452AActive Publication Date: 2025-04-18HONOR DEVICE CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202510328524.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-19
Publication Date
2025-04-18
Estimated Expiration
2045-03-19

AI Technical Summary

Technical Problem

The prior art is difficult to efficiently manage data blocks, resulting in a large load on storage space management and affecting the performance of electronic devices.

Method used

By determining the predicted lifetime indicators of the data blocks based on the life cycle indicators of the file to which the data block belongs in the file system, the storage space management method is optimized, and the transfer frequency and recycling operations of the data blocks are reduced.

Benefits of technology

It effectively reduces the storage space management load of electronic devices, improves the efficiency of data block management, and reduces the overhead of storage space management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847452A_ABST
    Figure CN119847452A_ABST
Patent Text Reader

Abstract

The invention discloses a storage space management method and electronic equipment, and relates to the technical field of computers. And the electronic equipment determines a predicted life index of the data block according to the life cycle index of the file to which the file system data block belongs. And then, the electronic equipment manages the storage space of the file system according to the predicted life index of the data block. The predicted life index is used for indicating the predicted number of the data blocks distributed by the file system from writing to failure of the index data blocks. The life cycle index of the file is used for indicating the predicted number of data blocks distributed by the file system from creation to deletion of the file. The electronic equipment can know the predicted failure time of the data block in advance by predicting the service life of the data block, so that the storage space can be managed more efficiently, and the management load of the storage space is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a storage space management method and an electronic device. Background Art

[0002] The file system is a method used by the operating system to organize files on storage devices. Among them, the log file system is widely used in electronic devices. Data blocks in the file system may become invalid due to various reasons, resulting in a large number of invalid data blocks. In order to maintain the effective use of storage space, electronic devices need to frequently perform storage space management operations such as moving or recycling data blocks, resulting in a large storage space management load.

[0003] Therefore, how to efficiently manage data blocks and reduce the storage space management load is an important issue that needs to be solved. Summary of the invention

[0004] Embodiments of the present application provide a storage space management method and an electronic device, which are used to reduce the management load of the storage space of the electronic device.

[0005] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions: In a first aspect, a storage space management method is provided, the method comprising: determining a predicted life index for characterizing the life of a data block according to a life cycle index of a file to which a data block belongs in a file system; the predicted life index is used to indicate the estimated number of data blocks allocated by the file system from the time the data block is written to the time the data block is invalidated; the file life cycle index is used to indicate the estimated number of data blocks allocated by the file system from the time the file is created to the time the file is deleted. Thereafter, the storage space of the file system is managed according to the predicted life index of the data block.

[0006] It should be understood that the allocation of data blocks in the file system is a continuous process with an increasing number of allocations. The life cycle index and the predicted life index are both counts of data blocks allocated from the perspective of the file system. The electronic device can determine the predicted life index of the data block based on the life cycle index of the file to which the data block belongs in the file system, and then manage the storage space of the file system based on the life of the data block represented by the predicted life index.

[0007] In the above storage space management method, the electronic device obtains the required parameters and calculates the predicted life index of the data block. By predicting the life of the data block, the expected failure time of the data block is known in advance. The storage space management can be more efficiently performed according to the failure time, thereby effectively reducing the frequency of moving data blocks, efficiently performing management operations such as recycling data blocks, and reducing the storage space management load of the electronic device.

[0008] In a possible implementation manner of the first aspect, when the data block is an initial block, a predicted life index of the initial block is consistent with a life cycle index of a corresponding file; the initial block is a data block to which data is written for the first time.

[0009] It should be understood that the initial block is a data block to which data is written for the first time, and is not a data block to which data is written based on data update requirements. In the case where the data block is an initial block, the predicted life index of the initial block may inherit the life cycle index of the file to which it belongs.

[0010] The storage space management method adopts an inheritance method to predict the life index of the data block, which simplifies the prediction process and improves the prediction efficiency.

[0011] In another possible implementation of the first aspect, when the data block is an update block, the predicted life index of the update block is obtained based on an update cycle index; the update cycle index is used to indicate the number of data blocks allocated by the file system between the writing and failure of the updated block. Among them, the update block and the updated block are data blocks in different storage locations, and the data written in the update block is used to update the data content in the corresponding updated block. After the data is written in the update block, the corresponding updated block becomes invalid; or, the data written in the update block this time is used to update the data content in the data block in the same storage location, and the updated block is the original data block before this update.

[0012] It should be understood that after data is written to a data block, the data in the data block may be updated. Depending on the type of file system, the storage locations of the update block and the updated block may be different. In some embodiments, such as a log file system, the update block and the updated block are data blocks in different storage locations, and the data written to the update block is used to update the data content in the corresponding updated block. After the data is written to the update block, the corresponding updated block becomes invalid. In other embodiments, the data written to the update block this time is used to update the data content in the data block at the same storage location.

[0013] When the data block is an update block, the electronic device needs to consider the update interval, that is, the update cycle, when predicting the life index of the update block. The electronic device can directly use the update cycle as the predicted life index of the update block, or comprehensively consider the update cycle and the predicted life index of the updated block to obtain the predicted life index of the update block.

[0014] The storage space management method, by introducing the update cycle indicator, can more accurately reflect the state of the file system after the update, thereby improving the accuracy of the update block life prediction.

[0015] In another possible implementation of the first aspect, the predicted life index of the update block is a weighted sum of the update cycle index and the historical life index; the historical life index is the predicted life index of the updated block; wherein the updated block is an update block or an initial block. When the updated block is an initial block, the predicted life index of the updated block is consistent with the life cycle index of the file to which the updated block belongs.

[0016] It should be understood that the updated block itself can also be an update block or an initial block. In the case where the updated block is an initial block, the historical life index is the predicted life index of the initial block, that is, the historical life index is consistent with the life cycle index of the file to which the initial block belongs. The predicted life index of the update block is obtained based on the update cycle and the historical life index. In the case where the updated block is an update block, the historical life index can be iterated to the historical life index of the updated block corresponding to the previous update, and finally it can be iterated to the predicted life index of the corresponding initial block.

[0017] In the above storage space management method, the predicted life index of the update block is the weighted sum of the update cycle index and the historical life index. The update cycle index can reflect the current state of the file system. The historical life index represents the predicted life index of the updated block, which is calculated based on the previous update cycle index and predicted life index. The historical life index reflects the stability of the relevant data block in the past period of time and the comprehensive situation of the predicted life index. In this way, by comprehensively considering the update cycle index and the historical life index to predict the life of the update block, a more comprehensive and accurate life prediction result can be obtained.

[0018] In another possible implementation of the first aspect, the initial life cycle indicator of the file is consistent with the life cycle indicator of the directory where it is located, and the initial life cycle indicator of the directory is consistent with the life cycle indicator of the parent directory; the method also includes: when the target object is deleted, the life cycle indicator of the target object is updated according to the deletion timing indicator and creation timing indicator of the target object, and the object is a file or a directory; the deletion timing indicator is used to indicate the global cumulative number of blocks of the file system when the target object is deleted; the creation timing indicator is used to indicate the global cumulative number of blocks of the file system when the target object is created; the global cumulative number of blocks represents the total number of data blocks accumulated in the file system.

[0019] It should be understood that the initial life cycle indicator of a file can inherit the life cycle indicator of the directory where it is located, and the life cycle indicator of a directory can inherit the life cycle indicator of the parent directory. When a file (or directory) is deleted, the electronic device updates the previous life cycle indicator of the file (or directory) according to the actual life cycle indicator of the file (or directory). The actual life cycle indicator is calculated based on the creation timing indicator and deletion timing indicator of the file (or directory). The electronic device can obtain the creation timing indicator and the deletion timing indicator based on the global cumulative number of blocks of the file system.

[0020] In the above storage space management method, the electronic device records the creation timing index and the deletion timing index through the global block cumulative number, so as to clearly understand the relative position of the file (or directory) in the growth process of the file system storage space. It is helpful to analyze the storage space usage and update status of the file system, and to facilitate the prediction of future storage space requirements. The electronic device updates the previous life cycle index of the file (or directory) according to the actual life cycle index of the file (or directory), and then the predicted life cycle index of the initial block under the file inherits the life cycle index after the file is updated, which improves the accuracy of the predicted life cycle index.

[0021] In another possible implementation manner of the first aspect, after updating the lifecycle indicator of the target object, the method further includes: updating the lifecycle indicator of a parent directory of the target object according to the updated lifecycle indicator of the target object.

[0022] The above storage space management method can ensure that after the life cycle indicator of a file (or directory) is updated, the life cycle indicator of the parent directory can smoothly transition to a new value; timely updating the life cycle indicator of the parent directory improves the accuracy of the life cycle indicator of the parent directory.

[0023] In another possible implementation of the first aspect, the updated lifecycle indicator of the parent directory of the target object is obtained based on the updated lifecycle indicator of the target object, the lifecycle indicator of the parent directory of the target object, and the number of files under the parent directory of the target object.

[0024] It should be understood that comprehensively considering the updated life cycle index of the target object, the original life cycle index of the parent directory, and the number of files under the parent directory can more comprehensively reflect the actual state of the file system and improve the accuracy of the life cycle index of the parent directory.

[0025] In another possible implementation of the first aspect, updating the lifecycle indicator of the parent directory of the target object according to the lifecycle indicator of the target object after the update includes: calculating the product of the lifecycle indicator of the parent directory of the target object and the number of files in the parent directory of the target object after the update to obtain a first value. Adding the first value to the lifecycle indicator of the target object after the update to obtain a second value. Calculating the ratio of the second value to the number of files in the parent directory of the target object before the update to obtain the lifecycle indicator of the parent directory of the target object after the update.

[0026] In the above storage space management method, the electronic device calculates the average value of the life cycle indicators of all files in the parent directory within the update cycle. The average value can reflect the changes in the life cycle indicator of the parent directory. The electronic device updates the life cycle indicator of the parent directory in a timely manner to improve the accuracy of the life cycle indicator of the parent directory.

[0027] In another possible implementation of the first aspect, after the lifecycle indicator of the parent directory of the target object is updated, when a new object is created under the parent directory, the initial lifecycle indicator of the new object is consistent with the lifecycle indicator of the updated parent directory.

[0028] The storage space management method predicts the initial life cycle indicator of a newly created file under the parent directory based on a more accurate life cycle indicator of the parent directory, thereby improving the accuracy of the prediction of the life cycle of the data block under the newly created file.

[0029] In another possible implementation manner of the first aspect, the life cycle indicator of the root directory is set to a preset number of data blocks; the preset number of data blocks is a maximum number of data blocks that the file system allows to be allocated to the root directory.

[0030] In the above storage space management method, the life cycle indicator of the root directory is preset as the maximum number of data blocks allowed to be allocated to the root directory by the file system. The electronic device does not need to perform complex initialization evaluation and calculation, and directly uses the maximum value as the life cycle indicator of the root directory, thereby improving the prediction efficiency.

[0031] In another possible implementation of the first aspect, the index node structure of the object includes a newly added first parameter and a second parameter; the structure of the file system includes a third parameter; the object is a file or a directory; the first parameter is used to record the creation timing indicator of the object, and the second parameter is used to record the life cycle indicator of the object; the third parameter is used to record the total number of data blocks accumulated in the file system.

[0032] In the above storage space management method, the electronic device can record the creation time index and the predicted life cycle index of the file (or directory) by adding parameters. When calculating the predicted life index of the data block, the relevant parameters can be called at any time to provide accurate and real-time evaluation.

[0033] In another possible implementation of the first aspect, the index node structure of the file includes a data block life tree structure, the data block life tree structure includes M data block life nodes, the data block life node includes a fourth parameter and a fifth parameter; the fourth parameter is used to record a creation timing indicator of the data block, and the fifth parameter is used to record a predicted life indicator of the data block, and M is a positive integer.

[0034] In the above storage space management method, the electronic device can record the creation time index and the predicted life index of the data block by adding parameters. When calculating the predicted life index of the data block, the relevant parameters can be called at any time to provide accurate and real-time evaluation.

[0035] In another possible implementation of the first aspect, the storage space of the file system is managed according to the predicted life index of the data block, including: selecting a target data segment for garbage collection GC according to the predicted life index of each data block; a data segment includes N consecutive data blocks; N is an integer greater than 1.

[0036] In the above storage space management method, the electronic device uses the predicted life index of each data block to screen out more suitable data segments as target data segments, reducing the additional overhead caused by frequent movement of valid data blocks, improving the management efficiency of data blocks, and significantly reducing the storage space management load of the electronic device.

[0037] In another possible implementation of the first aspect, according to the predicted life index of each data block, a target data segment for garbage collection GC is selected, including: screening candidate data segments according to the moving cost; the moving cost represents the cost of moving valid data blocks in the candidate data segment. According to the predicted life index of each data block, the average remaining life index and the remaining life variance index of the data blocks in each candidate data segment are obtained. According to the average remaining life index and the remaining life variance index of the data blocks in each candidate data segment, the target data segment is determined.

[0038] In the above storage space management method, the electronic device comprehensively considers the migration overhead and the life of the data block, and selects a more suitable data segment as the target data segment, thereby reducing the GC overhead and reducing the storage space management load of the electronic device.

[0039] In another possible implementation of the first aspect, based on the predicted life of each data block, a target data segment for garbage collection GC is selected, including: if there are candidate data segments in the cache list, the target data segment is selected from the cache list; the average remaining life index of the candidate data segment is higher than the life index threshold, and the remaining life variance index is higher than the variance index threshold. If there are no candidate data segments in the cache list, the candidate data segments are screened based on the migration cost, the target data segment and the candidate data segment are determined based on the candidate data segments, and the candidate data segment is stored in the cache list; the average remaining life index of the target data segment is higher than the life index threshold, and the remaining life variance index is less than or equal to the variance index threshold.

[0040] In the above storage space management method, for candidate data segments with high average remaining life index but large remaining life variance index, the remaining life distribution of data blocks in the candidate data segments is relatively discrete, and may contain more data blocks with low remaining life. After these data blocks with low remaining life are marked as invalid, the moving cost drops rapidly in a short period of time. To improve efficiency, it is necessary to quickly select the target data segment for space recovery. To avoid the performance overhead caused by full disk traversal, select directly from the cache list. In this way, the candidate data segments with high average remaining life index but large remaining life variance index can be temporarily stored in the cache list as candidate data segments, and the next round of target data segment selection can be directly selected from the candidate data segments in the cache list, thereby improving the recovery efficiency of GC.

[0041] In another possible implementation of the first aspect, the storage space of the file system is managed according to the predicted life index of the data block, including: classifying each data block according to the predicted life of each data block to obtain a classification result; the classification result includes at least hot data blocks and cold data blocks, and the predicted life index of the hot data block is less than the predicted life index of the cold data block. According to the classification result, each data block is written into a corresponding different storage area; the storage area includes at least a hot data storage area and a cold data storage area, the hot data block is written into the hot data storage area, and the cold data block is written into the cold data storage area.

[0042] The above storage space management method can ensure that hot data and cold data are reasonably stored in corresponding storage areas through data diversion. In this way, the data blocks in each storage area expire at a similar time, thereby greatly reducing the GC frequency and overhead, and significantly reducing the storage space management load of the electronic device.

[0043] In another possible implementation of the first aspect, the storage space of the file system is managed according to the predicted life index of the data block, including: for the data blocks in the cache, according to the predicted life index of each data block and the set threshold, the data blocks having the predicted life index greater than or equal to the set threshold are preferentially written back to the main storage medium.

[0044] The above storage space management method, for data blocks in the cache, selects data blocks that are preferentially written back to the main storage medium according to the predicted life index. For data blocks with higher predicted life index, since it is expected that they will not change for a long time, the electronic device performs a write-back operation to synchronize the data to the main storage medium preferentially. For data blocks with lower predicted life index, considering that they may be updated and invalid soon, it is chosen not to write them back to the main storage medium (referred to as main memory) temporarily, so as to reduce the overhead of deleting the data blocks written back to the main memory and writing them back to the main memory again after they expire soon, thereby reducing the storage space management load of the electronic device, reducing unnecessary input / output bandwidth usage, and reducing the physical loss of the main storage medium, effectively extending the service life of the main storage medium.

[0045] In a second aspect, the present application provides an electronic device, comprising: one or more processors and a memory; the memory and the processor are coupled; the memory is used to store computer program code, the computer program code includes computer instructions, and when the computer instructions are executed by one or more processors, the electronic device executes the method described in the first aspect and any possible design method thereof.

[0046] In a third aspect, the present application provides a computer-readable storage medium, in which instructions are stored. When the instructions are executed on an electronic device, the electronic device executes the method described in the first aspect and any possible design thereof.

[0047] In a fourth aspect, the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the method described in the first aspect and any possible design thereof.

[0048] It can be understood that the beneficial effects that can be achieved by the electronic device described in the second aspect, the computer-readable storage medium described in the third aspect, and the computer program product described in the fourth aspect provided above can be referred to the beneficial effects in the first aspect and any possible design method thereof, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 A schematic diagram of a log file system remote update feature and data block validity provided by an embodiment of the present application; Figure 2 A flowchart of a storage space management method provided in an embodiment of the present application; Figure 3 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application; Figure 4 A schematic diagram of a software architecture of an electronic device provided in an embodiment of the present application; Figure 5A schematic diagram of a file system hierarchical structure and data structure expansion provided in an embodiment of the present application; Figure 6 A schematic diagram of data segment status before and after a data block is updated in a log file system provided by an embodiment of the present application; Figure 7 A schematic diagram of a garbage collection process provided in an embodiment of the present application; Figure 8 A schematic diagram of target data segment selection provided in an embodiment of the present application; Fig. 9 A schematic diagram of recording a creation timing indicator and a life cycle indicator when creating a file provided in an embodiment of the present application; Fig.10 A schematic diagram of updating file and parent directory life cycle indicators when a file is deleted provided in an embodiment of the present application; Fig.11 A schematic diagram of a life cycle indicator of a newly created file after a directory update provided in an embodiment of the present application; Fig.12 A schematic diagram of the structure of a chip system provided in an embodiment of the present application. DETAILED DESCRIPTION

[0050] The technical solutions in the embodiments of the present application are described below in conjunction with the drawings in the embodiments of the present application. Among them, in the description of the embodiments of the present application, the terms used in the following embodiments are only for the purpose of describing specific embodiments, and are not intended to be used as limitations on the present application. As used in the specification and the appended claims of the present application, the singular expressions "a", "said", "above", "the" and "this" are intended to also include expressions such as "one or more", unless there is a clear contrary indication in the context. It should also be understood that in the following embodiments of the present application, "at least one", "one or more" refer to one or more (including two). The term "and / or" is used to describe the association relationship of associated objects, indicating that three relationships can exist; for example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship.

[0051] References to "one embodiment" or "some embodiments" etc. described in this specification mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Thus, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways. The term "connection" includes direct connection and indirect connection, unless otherwise specified. "First" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated.

[0052] In the embodiments of the present application, the words "exemplarily" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplarily" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplarily" or "for example" is intended to present related concepts in a specific way.

[0053] The software organization in the operating system that is responsible for managing and storing file information is called a file management system, or file system for short. File systems can include different types, such as log file systems, virtual file systems (VFS), and file allocation table file systems (FAT).

[0054] Among them, the log file system has the feature of off-site update, that is, the updated data is not directly modified in the original data location, but the new data is written to the new storage space in sequence by appending. This off-site update method has good random write performance and flash memory-friendly characteristics, but has high requirements for storage space continuity.

[0055] For the file system, a large number of invalid data blocks will inevitably be generated during the continuous writing and updating process of users, and the feature of off-site updating aggravates the generation of invalid data blocks.

[0056] The storage space of the file system can include multiple data blocks. When writing data, the file system needs to apply for data blocks to store data. Data blocks that store valid data are called valid data blocks, and data blocks that do not store data or have been marked as invalid are called invalid data blocks. The reasons why data blocks are marked as invalid include: marking invalid due to data block deletion; marking invalid due to data block being updated remotely.

[0057] For example, Figure 1 The figure shows the feature of off-site update of log file system. Figure 1 As shown, if data block 12 and data block 13 need to be updated, the new data is written into the unused data block 18 and data block 19 in sequence in an appended manner, and data block 18a and data block 19a are obtained after the update. The original data block 12 and data block 13 are marked as invalid data block 12a and invalid data block 13a accordingly.

[0058] like Figure 1 As shown, if the data block 15 is not needed to be used subsequently, the data in the data block 15 is deleted, and the data block 15 is marked as an invalid data block 15a accordingly. Figure 1 In the example, data blocks storing valid data are valid data blocks. Taking the updated data blocks as an example, data blocks 11, 14, 16, 17, 18a and 19a are all valid data blocks. Updated, deleted and unused data blocks are invalid data blocks. Taking the data blocks before updating as an example, data blocks 18 and 19 are both invalid data blocks.

[0059] Invalid data blocks not only occupy storage space, but also affect the storage space continuity of the log file system. Therefore, in order to improve the continuity and utilization of storage space, storage space management methods such as garbage collection (GC) and data diversion are proposed. However, in the process of GC and data diversion, for a large number of invalid data blocks, electronic devices need to frequently perform data block movement and recycling operations, resulting in a large storage space management load.

[0060] In addition, in the process of saving the data in the cache back to the persistent main storage medium (hereinafter referred to as cache write-back), some short-lived data is unnecessarily written to the persistent storage medium (for example, a disk or solid-state drive), and then the data quickly becomes invalid. This process not only increases the storage space management load and causes input / output (IO) bandwidth waste, but also aggravates the physical wear of the storage medium and shortens the service life of the storage medium.

[0061] In some related technologies, the file system can allow users to set the file storage timeliness level according to their own needs through the input / output control (ioctl) interface provided by the virtual file system (VFS). However, the storage timeliness level is a preset fixed level. For example, it only distinguishes between temporary files and long-term files, and does not provide a clear and quantitative time definition standard. Users need to manually set the life span of each file, which is not only cumbersome to operate, but also limited in application scenarios. To this end, an embodiment of the present application provides a storage space management method, which is applied to electronic devices. Figure 2 As shown, the electronic device determines the predicted life index of the data block based on the life cycle index of the file to which the data block belongs in the file system. The predicted life index is used to characterize the life of the data block. Afterwards, the electronic device manages the storage space of the file system based on the predicted life index of the data block. The predicted life index is used to indicate the estimated number of data blocks allocated by the file system from the time the data block is written to the time it expires. The life cycle index of a file is used to indicate the estimated number of data blocks allocated by the file system from the time the file is created to the time it is deleted.

[0062] The data block allocation of the file system is an ongoing process with an increasing number of allocations, similar to the accumulation of time. For any data block, the predicted life index reflects the number of other data blocks that the file system may need to allocate in order to store related data from the time the data block is written to the time it fails. Specifically, the higher the predicted life index, the more other data blocks the file system needs to allocate from the time the data block is written to the time it fails, and the longer the predicted life of the data block.

[0063] In some embodiments, the electronic device can accumulate the total number of data blocks allocated by the file system, which is similar to recording a time series. The cycle index and the life index correspond to specific "time span" statistics in the time series. In this way, the life prediction of the data block can be achieved. For example, assume that the total number of data blocks allocated by the file system when writing data to the data block is a, and the predicted life index of the data block is b. In this case, the electronic device predicts that when the total number of data blocks allocated by the file system reaches a+b, the data block will fail.

[0064] In the above storage space management method, the electronic device obtains the required parameters and calculates the predicted life index of the data block. By predicting the life of the data block, the expected failure time of the data block is known in advance. The storage space management can be more efficiently performed according to the failure time, thereby effectively reducing the frequency of moving data blocks, efficiently performing management operations such as recycling data blocks, and reducing the storage space management load of the electronic device.

[0065] By way of example, the above-mentioned electronic devices may specifically be mobile phones, tablet computers, televisions (also referred to as smart TVs, smart screens or large-screen devices), laptop computers, ultra-mobile personal computers (UMPCs), handheld computers, cameras (such as digital cameras), camcorders (such as digital video cameras), netbooks, personal digital assistants (PDAs), wearable electronic devices (for example: smart watches, smart bracelets, smart glasses), vehicle-mounted devices, virtual reality devices, and other electronic devices with file systems, and the embodiments of the present application do not impose any restrictions on this.

[0066] For ease of understanding, a mobile phone is taken as an example to illustrate the hardware structure and software system of the electronic device to which the method in the embodiment of the present application is applied.

[0067] Figure 3 A schematic diagram of the structure of a mobile phone is shown.

[0068] The mobile phone may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc.

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

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

[0071] The processor 110 can be used to read and execute computer-readable instructions. Optionally, the processor 110 can also include a controller, an arithmetic unit, and a register. Among them, the controller is mainly responsible for decoding instructions and issuing control signals for operations corresponding to the instructions. The arithmetic unit is mainly responsible for saving register operands and intermediate operation results temporarily stored during the execution of instructions. Registers are high-speed storage components with limited storage capacity, which can be used to temporarily store instructions, data, and addresses.

[0072] In a specific implementation, the hardware architecture of the processor 110 can be an application specific integrated circuit (ASIC) architecture, a microprocessor without interlocked piped stages (MIPS) architecture, an ARM (advanced RISC machines) architecture, or a network processor (NP) architecture, etc.

[0073] In some embodiments, the mobile phone may execute a storage space management method through the processor 110 to improve the accuracy of data life prediction.

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

[0075] The wireless communication function of the mobile phone can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor.

[0076] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied on mobile phones. In some embodiments, at least some functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 150 can be set in the same device as at least some modules of the processor 110.

[0077] The wireless communication module 160 can provide wireless communication solutions for use on mobile phones, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication technology (NFC), infrared technology (IR), etc.

[0078] The mobile phone can realize audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor.

[0079] The key 190 includes a power button, a volume button, etc. The key 190 can be a mechanical key or a touch key. The mobile phone can receive key input and generate key signal input related to the user settings and function control of the mobile phone.

[0080] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback.

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

[0082] The camera 193 is a physical camera that actually exists. In some embodiments of the present application, the camera 193 of the mobile phone can be multiple, for example, the multiple cameras 193 can include a front camera and a rear camera. The front camera can be one or more, and the rear camera can also be one or more.

[0083] The mobile phone can realize the shooting function through the ISP, the camera 193, the video codec, the GPU, the display screen 194 and the application processor, etc. For example, the application in the mobile phone can access the camera 193 and control the camera 193 to collect images.

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

[0085] Display screen 194 is used to display images, videos, etc.

[0086] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to or disconnected from the mobile phone by inserting the SIM card interface 195 or pulling the SIM card out of the SIM card interface 195.

[0087] The software system of the mobile phone can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present invention takes a software system of a layered architecture as an example to exemplify the software structure of the mobile phone.

[0088] Figure 4 It is a software structure block diagram of the mobile phone according to an embodiment of the present invention.

[0089] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the system library, and the kernel layer.

[0090] The application layer can include a series of application packages.

[0091] like Figure 4 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.

[0092] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.

[0093] like Figure 4 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.

[0094] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.

[0095] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0096] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.

[0097] The phone manager is used to provide the communication functions of the mobile phone, such as the management of call status (including answering, hanging up, etc.).

[0098] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0099] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.

[0100] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0101] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.

[0102] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

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

[0104] A 2D graphics engine is a drawing engine for 2D drawings.

[0105] like Figure 4 As shown in Figure 1, the kernel layer is the layer between hardware and software. The kernel layer at least includes a file system, which is used to calculate and record the life information of data blocks. In addition, the kernel layer may also include Figure 4 Drivers not shown, such as display driver, camera driver, audio driver, sensor driver, etc.

[0106] Figure 5 , Fig. 9 and Fig.10A file system hierarchical structure is shown, where the root directory contains multiple directories, which are further nested with subdirectories, and files are stored in the subdirectories. For example, the root directory contains directory 1 and directory 2, directory 1 contains directory 3 and directory 4, and directory 2 contains directory 5. Directory 3 contains files 1 and 5, directory 4 contains files 2 and 3, and directory 5 contains file 4. In the hierarchical structure, the parent directory of a file (or directory) is called the parent directory of the file (or directory). The next level file (or directory) of a directory is called the child file (or subdirectory) of the directory. For example, directory 1 is the parent directory of directory 3, directory 3 is the subdirectory of directory 1, directory 5 is the parent directory of file 4, and file 4 is the child file of directory 5.

[0107] In this application, the internal data structure of the file system at the kernel layer is expanded.

[0108] In some embodiments, a first parameter and a second parameter are added to the index node structure of a file (or directory). A third parameter is added to the structure of the file system. The first parameter is used to record the creation timing index of the file (or directory), and the second parameter is used to record the life cycle index of the file (or directory). The third parameter is used to record the total number of data blocks accumulated and allocated in the file system.

[0109] In some embodiments, the index node structure of the file is newly added with a data block life tree structure, and the data block life tree structure includes a plurality of data block life nodes. Each data block life node includes a fourth parameter and a fifth parameter. The fourth parameter is used to record the creation time index of the data block, and the fifth parameter is used to record the predicted life index of the data block.

[0110] The electronic device may match different fourth parameters for different data blocks, and / or match different fifth parameters for different data blocks. The electronic device may also allow multiple data blocks to share the same fourth parameter, and / or multiple data blocks to share the same fifth parameter according to actual needs. As long as a clear correspondence between data blocks and parameters is established, the electronic device can trace back to the parameters corresponding to the data blocks when calculating the data block life index.

[0111] Specifically, a new parameter can be added to the superblock structure of the file system: global block cumulative number (total_ count). Total_ count is used to accumulate the total number of data blocks allocated by the file system.

[0112] like Figure 5As shown, a directory creation timing indicator (c_num) and a directory life cycle indicator (lifetime) are added to the directory index node (dir inode) structure, and a file creation timing indicator (c_num) and a file life cycle indicator (lifetime) are added to the file index node (file inode) structure.

[0113] like Figure 5 As shown, a new structure is added to the file index node structure: blocks lifetime tree. The blocks lifetime tree includes a series of block lifetime nodes, and new parameters are added to the block lifetime nodes: block creation timing parameter (w_num) and block predicted lifetime parameter (node_lifetime).

[0114] Specifically, a data block life tree is added to the structure of the extent tree, and the extent tree includes a series of extent tree nodes, each of which records the length and starting address of a continuous data block (hereinafter referred to as the data segment). Thus, in the data block creation timing parameter and data block predicted life parameter newly added in the present application, the data block creation timing parameter structure can be used to record the earliest creation timing indicator of the data block in the above data segment, and the data block predicted life parameter structure can be used to record the average predicted life indicator of the data block in the above data segment.

[0115] Combine the following Figure 4 , exemplarily illustrating the processing flow of a mobile phone executing the method in the embodiment of the present application.

[0116] For example, when an application in the application layer creates a file during execution, this status message is passed to the kernel layer through the application framework layer and the system library.

[0117] The file system at the kernel layer records the creation timing index and life cycle index of the file in the corresponding structure, where the life cycle index can inherit the life cycle index of the parent directory. In addition, the file system records the information of the data blocks in the file in the corresponding data block life tree. For each data block life node, the earliest creation timing index of the data block in the data segment and the predicted life index of the data block are recorded in the corresponding structure, where the predicted life index of the data block can inherit the life cycle index of the file to which it belongs.

[0118] For another example, when an application in the application layer updates a data block during execution, the status message is passed to the kernel layer through the application framework layer and the system library.

[0119] For the update block, the file system at the kernel layer records the write time in the data block creation timing parameter structure. The update cycle index can be calculated based on the write time of the update block and the creation timing index of the updated block, and the predicted life index of the update block can be calculated based on the update cycle index, and the predicted life index of the update block can be written into the corresponding structure.

[0120] In some embodiments, the update block and the updated block are data blocks in different storage locations, and the data written in the update block is used to update the data content in the corresponding updated block. After the corresponding update block writes the data, the updated block becomes invalid. For example, in the case where the file system is a log file system, since the log file system has the feature of off-site update, the updated block and the update block are data blocks in different storage locations. Figure 1 As shown, data block 18a is an update block, and data block 12 is an updated block corresponding to data block 18a.

[0121] In other embodiments, the data written in the update block this time is used to update the data content in the data block at the same storage location, and the updated block is the original data block before this update.

[0122] The above storage space management method can be applied to various scenarios, including but not limited to GC scenarios, data diversion scenarios and cache write-back scenarios.

[0123] For ease of understanding, the following embodiment introduces application scenario 1 in detail: GC scenario.

[0124] In the file system, a certain number of data blocks are organized into data segments, which are the basic units of storage space management. According to the validity of the data blocks in the data segment, the data segment is divided into three states: empty data segment, full data segment, and dirty data segment. If the data segment is full of invalid data blocks, the data segment is an empty data segment. If the data segment is full of valid data blocks, the data segment is a full data segment. If the data segment contains both valid data blocks and invalid data blocks, the data segment is a dirty data segment.

[0125] Figure 6 The following figure shows the data segment status before and after the data block is updated in the log file system. Figure 6 As shown, taking the data segments before the update as an example, data segments 201 and 202 are full data segments, and data segments 203 and 204 are empty data segments. Taking the data segments after the update as an example, data segments 201a and 202a are dirty data segments, data segment 203a is a full data segment, and data segment 204 is still an empty data segment.

[0126] As users use the data, valid data blocks gradually become invalid data blocks, dirty data segments increase, and empty data segments decrease. Insufficient empty data segments have a significant impact on the performance and stability of the log file system. To ensure the number of empty data segments, electronic devices regularly clean up dirty data segments, move valid data in dirty data segments to other locations, and release the storage space occupied by the entire dirty data segment, thereby obtaining continuous storage space (that is, obtaining empty data segments). This process is called GC.

[0127] During the GC process, since the movement of valid data blocks brings a certain amount of overhead, the electronic device needs to select the appropriate data segment for cleaning. The data segment selected to be cleaned is called the target data segment. The current selection of the target data segment only considers the movement overhead, but does not consider the life of the data block. It is possible that the valid data block becomes invalid shortly after being moved, which not only increases the GC overhead, but also makes it difficult to effectively manage the data block, resulting in a large storage space management load.

[0128] By applying the storage space management method of the present application to the GC scenario, the migration overhead and data block life are comprehensively considered, and more suitable data segments are screened out as target data segments, thereby reducing GC overhead and reducing the storage space management load of electronic devices.

[0129] The electronic device can first screen the candidate data segments according to the migration overhead, and then use the storage space management method of the present application to calculate the predicted life index of each data block, and then obtain the average remaining life index and remaining life variance index of each data block in each candidate data segment. After that, the candidate data segments whose average remaining life index and remaining life variance index meet the requirements can be selected as the target data segments.

[0130] In some embodiments, the electronic device can calculate the remaining life index based on the current total_ count, the creation timing index of the data block, and the predicted life index. For example, assuming that the total number of data blocks allocated by the file system when the data block is created (creation timing index) is a, and the predicted life index of the data block is b, the electronic device predicts that when the total number of data blocks allocated by the file system reaches a+b, the data block will become invalid. Assuming that the total number of data blocks currently allocated by the file system (current total_ count) is c, in this case, the electronic device calculates the remaining life index of the data block as a+bc.

[0131] After obtaining the remaining life index of each data block in the candidate data segment, the electronic device calculates the arithmetic mean and variance of the remaining life index of each data block, thereby obtaining the average remaining life index and the remaining life variance index of the candidate data segment.

[0132] In some modes of GC, the electronic device can select a target data segment from the cache list. When there are no data segments to be selected in the cache list, the data blocks are traversed again, the candidate data segments are screened according to the migration overhead, and the predicted life index of each data block is calculated, so as to obtain the average remaining life index and the remaining life variance index of each data block in each candidate data segment. The electronic device takes the data segment whose average remaining life index is higher than the life index threshold and whose remaining life variance index is less than or equal to (not exceeding) the variance index threshold as the target data segment. The electronic device takes the data segment whose average remaining life index is higher than the life index threshold and whose remaining life variance index is higher than the variance index threshold as the data segment to be selected, and stores it in the cache list.

[0133] In some embodiments, Figure 7 As shown, the electronic device first screens the candidate data segments according to the moving overhead. Afterwards, the average remaining life index and the remaining life variance index of the data blocks in the candidate data segments are calculated according to the predicted life index of each data block. Taking into account the average remaining life index and the remaining life variance index of the candidate data segments, the candidate data segments with high average remaining life index and small remaining life variance index are selected as the target data segments of this round. The candidate data segments with high average remaining life index but large remaining life variance index are added to the cache list as the candidate data segments. The candidate data segments are used as the target data segments to be selected in the next round of garbage collection GC.

[0134] Among them, the remaining life variance index is an important index to measure the degree of dispersion of the remaining life of data blocks in the candidate data segment. In order to weaken the interference of extreme values ​​on the calculation results of the average remaining life index, the candidate data segment with a smaller remaining life variance index is selected. In this way, the average remaining life index of the candidate data segment can more accurately reflect the overall expected life of the data block. In addition, the candidate data segment with a smaller remaining life variance index means that the remaining life of the data blocks inside it is closer, which helps to reduce the situation where the data blocks fail at different time points. In addition, the candidate data segments with a smaller remaining life variance index are more likely to fail as a whole at a similar time, which indirectly reduces the generation of dirty data segments.

[0135] For candidate data segments with high average remaining life index but large remaining life variance index, the remaining life distribution of data blocks in the candidate data segments is relatively discrete, and may contain more data blocks with low remaining life. After these data blocks with low remaining life are marked as invalid, the moving cost drops rapidly in a short period of time. To improve efficiency, it is necessary to quickly select the target data segment for space recovery. To avoid the performance overhead caused by full disk traversal, select directly in the cache list. In this way, the candidate data segments with high average remaining life index but large remaining life variance index can be temporarily stored in the cache list as candidate data segments. The next round of selecting target data segments can be directly selected from the candidate data segments in the cache list, thereby improving the recovery efficiency of GC.

[0136] In some embodiments, the electronic device may determine the migration cost according to the number of valid data blocks in the data segment. A migration cost threshold may be set, and data segments with a value lower than the migration cost threshold are candidate data segments.

[0137] The target data segment is selected by comprehensively considering the average remaining life index and the remaining life variance index of the candidate data segment. In some embodiments, a life index threshold and a variance index threshold can be set respectively, and the candidate data segment whose average remaining life index is higher than the life index threshold and whose remaining life variance index does not exceed the variance index threshold is used as the target data segment of this round. The candidate data segment whose average remaining life index is higher than the life index threshold and whose remaining life variance index is higher than the variance index threshold is used as the candidate data segment.

[0138] For example, Figure 8 As shown, the number of valid data blocks from data segment A to data segment C is 5, which is less than the migration overhead threshold, and data segment A to data segment C are all candidate data segments. Figure 8 In the example, the numbers in the valid data blocks represent the remaining life of the corresponding data blocks. The average remaining life index of candidate data segment A is 11, and the average remaining life index of candidate data segment C is 11.2. The average remaining life index of candidate data segments A and C is higher than the life index threshold. The average remaining life index of candidate data segment B is 8, which is lower than the life index threshold, so candidate data segment B is excluded. In addition, the remaining life variance index of candidate data segment A is 0, which is lower than the variance index threshold; while the remaining life variance index of candidate data segment C is 33.76, which is higher than the variance index threshold.

[0139] Therefore, the average remaining life index of candidate data segment A is higher than the life index threshold, and the remaining life variance index is lower than the variance index threshold, so candidate data segment A is used as the target data segment for this round. The average remaining life index of candidate data segment C is higher than the life index threshold, and the remaining life variance index is higher than the variance index threshold. Figure 8 As shown, there are two data blocks that will fail soon. After the failure, the migration overhead is significantly reduced, and the candidate data segment C is selected as the candidate data segment.

[0140] In other embodiments, the electronic device can determine the target data segment from the candidate data segments based on a weighted and evaluated method. For example, first, the weighted sum of the average remaining life index and the remaining life variance index of the candidate data segment is calculated, wherein the weight of the average remaining life index is positive to reflect the preference for data blocks with high remaining life, and the weight of the remaining life variance index can be set to negative to consider the degree of discreteness of the remaining life distribution of the data block. A first weighted sum threshold and a second weighted sum threshold can be set as needed, and the first weighted sum threshold is higher than the second weighted sum threshold. The candidate data segment corresponding to the weighted sum higher than the first weighted sum threshold is used as the target data segment of this round, and the candidate data segment whose weighted sum is higher than the second weighted sum threshold but not exceeding the first weighted sum threshold is used as the selected data segment.

[0141] For ease of understanding, the following embodiment introduces application scenario 2 in detail: data diversion scenario.

[0142] Data diversion aims to distribute data to different storage areas by distinguishing the access frequency and update frequency of data. In the process of data diversion, data is divided into different categories, such as hot data, warm data, and cold data. Hot data refers to data that is frequently accessed and updated. Warm data refers to data with an access frequency and update frequency between hot data and cold data. Cold data refers to data with a low access frequency and update frequency.

[0143] By data diversion, it is possible to ensure that hot data, warm data, and cold data are reasonably stored in corresponding storage areas. In this way, the data blocks in each storage area expire at a similar time, which greatly reduces the frequency and overhead of GC and significantly reduces the storage space management load of electronic devices.

[0144] In some embodiments, the life prediction method of the present application is applied to a data diversion scenario to further reduce the storage space management load of the electronic device.

[0145] First, the predicted life index of each data block is obtained by the method of the present application. Data diversion is guided according to the predicted life index of each data block to obtain a classification result. The classification result includes at least hot data blocks and cold data blocks. For example, data blocks with low predicted life index and about to be updated are classified as hot data blocks; data blocks with high predicted life index and not expected to be updated for a long time are classified as cold data blocks. Afterwards, the hot data blocks and cold data blocks are written into corresponding storage areas respectively.

[0146] For ease of understanding, the following embodiment introduces application scenario three in detail: cache write-back scenario.

[0147] Cache write-back is used to synchronize data in the cache back to the persistent main storage medium. As a high-speed data storage area, the cache can temporarily store frequently accessed data to increase data access speed. However, to ensure data persistence and consistency, when the data in the cache changes, the updated data needs to be written back to the main storage medium. The cache write-back timing refers to the conditions for synchronizing the updated data in the cache back to the main storage medium.

[0148] In some embodiments, the life prediction method of the present application is applied to the scenario of selecting the timing of cache write back. For the data blocks in the cache, the data blocks that are preferentially written back to the main storage medium are selected according to the predicted life index. For the data blocks with higher predicted life index, since it is expected that they will not change for a long time, the electronic device performs the write-back operation to synchronize the data to the main storage medium preferentially. For the data blocks with lower predicted life index, considering that they may be updated and invalid soon, it is chosen not to write them back to the main storage medium temporarily, so as to reduce the overhead of deleting the data blocks in the main memory after they are written back to the main memory and need to be written back to the main memory again after they expire soon, thereby reducing the storage space management load, reducing unnecessary input / output bandwidth usage, and reducing the physical loss of the main storage medium, effectively extending the service life of the main storage medium.

[0149] For example, a write-back threshold may be set, and the electronic device preferentially writes back data blocks whose predicted life indicators are greater than or equal to the write-back threshold to the primary storage medium.

[0150] In each of the above application scenarios, it is necessary to manage the storage space of the file system based on the predicted life index of the data block. It should be understood that the storage space management method of the present application is not limited to the application scenarios listed above, and is also applicable to other scenarios that also use data block predicted life information for file system storage management, and is not limited here.

[0151] For ease of understanding, the storage space management method of the present application is described in detail in the following embodiments.

[0152] In some embodiments, a life prediction system based on a directory tree is established, and the electronic device determines the predicted life index of the data block according to the life cycle index of the file to which the data block belongs in the file system, and manages the storage space according to the predicted life index of each data block.

[0153] For the initial block, the predicted life index can inherit the life cycle index of the file to which it belongs, and the initial life cycle index of the file can inherit the life cycle index of the parent directory. Among them, the initial block is the data block where data is written for the first time, and the data block where data is written is not based on data update requirements.

[0154] When a file is created, the electronic device records the file's creation timing indicator and life cycle indicator, where the life cycle indicator inherits the life cycle indicator of the parent directory. When a directory is created, the electronic device records the directory's creation timing indicator and life cycle indicator, where the life cycle indicator inherits the life cycle indicator of the parent directory (that is, the upper-level directory). The initial life cycle indicator of the root directory can be set to a preset number of data blocks. For example, the preset number of data blocks can be the maximum number of data blocks that the file system allows to be allocated for the root directory.

[0155] In some embodiments, the creation timing indicator is the total number of global blocks (total_ count) of the file system when the file or directory is created. The total_ count is directly related to the storage space usage of the file system. By recording the total_ count at the time of creation, the relative position of the file or directory in the growth process of the file system storage space can be clearly understood. This helps to analyze the storage space usage and update status of the file system and facilitates the prediction of future storage space requirements. For example, Fig. 9 As shown, when file 3 is created, the electronic device records the creation timing index of file 3 according to the global block cumulative number at this time, directory 4 is the parent directory of file 3, and the life cycle index of file 3 is recorded according to the life cycle index of directory 4. It can be expressed as: ; ; in, Indicates the creation timing indicator of file 3; Indicates the total number of data blocks allocated by the file system as recorded by the global block cumulative number when file 3 is created; Indicates the life cycle indicator of file 3; Indicates the life cycle indicator of directory 4.

[0156] For the initial block in file 3, the electronic device records the predicted life index of the initial block according to the life cycle index of file 3. It can be expressed as: ; in, represents the predicted life index of the initial block, Indicates the life cycle indicator of file 3.

[0157] For the update block, the electronic device obtains a predicted life indicator based on the update cycle indicator.

[0158] In some embodiments, the electronic device may calculate the weighted sum of the update cycle index and the historical life index to obtain the predicted life index of the update block. The electronic device may also calculate the average value of the update cycle index and the historical life index to obtain the predicted life index of the update block. The electronic device may also directly use the update cycle index as the predicted life index of the update block.

[0159] Specifically, the historical life index refers to the predicted life index of the updated block. For example, in a log file system, Figure 1 As shown, data block 18a is an update block, and the updated block corresponding to data block 18a is data block 12. For data block 18a, the electronic device obtains the predicted life index of data block 18a according to the weighted sum of the update cycle index and the predicted life index of data block 12. The update cycle index is the number of data blocks allocated by the log file system from the time when data block 12 is written to the time when it is marked as invalid.

[0160] For example, the predicted life index of the update block can be expressed as: ; in, represents the predicted life indicator of the update block; Indicates the total number of data blocks allocated by the file system recorded by the global block cumulative number when the update block is created; Indicates the number of data blocks allocated by the file system when the updated block is created; represents the historical life indicator; represents the weight coefficient, The value range is [0, 1].

[0161] The update cycle indicator indicates the number of data blocks allocated by the file system from the time the updated block is written to the time it becomes invalid. The update cycle indicator can reflect the current state of the file system. The historical life indicator indicates the predicted life indicator of the updated block, which is calculated based on the previous update cycle indicator and predicted life indicator. The historical life indicator reflects the stability of the relevant data block in the past period of time and the comprehensive situation of the predicted life indicator. In this way, by comprehensively considering the update cycle indicator and the historical life indicator to predict the life of the updated block, a more comprehensive and accurate prediction result can be obtained.

[0162] In some embodiments, when a file (or directory) is deleted, the electronic device updates the life cycle indicator of the file according to the deletion timing indicator and creation timing indicator of the file (or directory) to obtain the actual life cycle indicator of the file.

[0163] For example, Fig.10 As shown, file 1 is deleted, and the electronic device updates the life cycle indicator of file 1 to obtain the actual life cycle indicator of file 1. The actual life cycle indicator of file 1 can be expressed as: ; in, Indicates the actual life cycle indicator of file 1; Indicates the total number of data blocks allocated by the file system as recorded by the global block cumulative count when file 1 is deleted; Indicates the creation timing indicator of file 1.

[0164] In some embodiments, after the electronic device updates the life cycle indicator of the deleted file, it updates the life cycle indicator of the corresponding parent directory. The life cycle indicator of the parent directory after the update can be obtained based on the life cycle indicator of the deleted file after the update, the life cycle indicator of the parent directory before the update, and the number of files under the parent directory. This method can ensure that after the file is deleted, the life cycle indicator of the directory can smoothly transition to the new value; timely update the life cycle indicator of the parent directory, and improve the accuracy of the life cycle indicator of the parent directory.

[0165] For example, Fig.10 As shown, file 1 is deleted, and after the electronic device updates the life cycle indicator of file 1, it updates the life cycle indicator of directory 3. The new life cycle indicator of directory 3 can be expressed as: ; in, Represents the new life cycle indicator of directory 3, Indicates the actual life cycle indicator of file 1, Indicates the life cycle indicator before directory 3 is updated. Indicates the number of files in directory 3. Fig.10 In the described embodiment, the number of files under directory 3 is 2.

[0166] After the life cycle indicator of the parent directory is updated, a new file is created in the corresponding parent directory, and the life cycle indicator of the new file inherits the new life cycle indicator of the parent directory. Fig.11 As shown, after the life cycle indicator of directory 3 is updated, a new file 6 is created under directory 3, and the life cycle indicator of the new file 6 inherits the new life cycle indicator of directory 3. File 5 is a file created before the life cycle indicator of directory 3 is updated, so the life cycle indicator of file 5 remains unchanged.

[0167] By timely updating the life cycle indicator of the file (or directory) and feeding it back to the parent directory, the life cycle indicator of the parent directory is dynamically updated. This not only improves the accuracy of the life cycle indicator of the parent directory, but also predicts the initial life cycle indicator of the newly created file under the parent directory based on the more accurate life cycle indicator of the parent directory, thereby improving the accuracy of data block life prediction.

[0168] In other embodiments, the creation timing indicator is the specific moment when the file or directory is created, and the deletion timing indicator is the specific moment when the file or directory is deleted, which can be expressed in a standard date and time format, such as "year-month-day hour: minute: second". The creation timing indicator and the deletion timing indicator can also be expressed in UNIX time. Among them, UNIX time refers to the total number of seconds from the Coordinated Universal Time to the present (leap seconds are not considered). And the frequency information of the file system allocating data blocks needs to be recorded, such as how many minutes ( / second) it takes to allocate a data block or how many minutes ( / second) it takes to allocate a data block. This is convenient for subsequent calculations of the number of data blocks allocated by the file system from creation to deletion, and also for calculating the actual life cycle indicator and the update cycle indicator, thereby facilitating the calculation of the predicted life index.

[0169] With the above data block life prediction method, electronic devices predict the life of data blocks and know the expected failure time of data blocks in advance, so as to plan the migration and recycling strategies of data blocks in advance, realize forward-looking data block management, and significantly reduce the storage space management load of electronic devices.

[0170] An embodiment of the present application also provides an electronic device, which may include: one or more processors and a memory; the memory and the processor are coupled; the memory is used to store computer program code, the computer program code includes computer instructions, and when the computer instructions are executed by one or more processors, the electronic device can perform the various functions or steps performed in the above method embodiment.

[0171] The present application also provides a chip system, such as Fig.12 As shown, the chip system 1700 includes at least one processor 1701 and at least one interface circuit 1702. The processor 1701 and the interface circuit 1702 can be interconnected through lines. For example, the interface circuit 1702 can be used to receive signals from other devices (such as the memory of the electronic device). For another example, the interface circuit 1702 can be used to send signals to other devices (such as the processor 1701). Exemplarily, the interface circuit 1702 can read the instructions stored in the memory and send the instructions to the processor 1701. When the instruction is executed by the processor 1701, the electronic device can execute the various steps in the above embodiments. Of course, the chip system can also include other discrete devices, which are not specifically limited in the embodiments of the present application.

[0172] An embodiment of the present application further provides a computer storage medium, which includes computer instructions. When the computer instructions are executed on the above electronic device, the electronic device executes each step in the above method embodiment.

[0173] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute each step in the above method embodiment.

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

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

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

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

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

[0179] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application shall be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims

1. A storage space management method, characterized in that: include: Determine a predicted life index for characterizing the life of a data block according to a life index of a file to which the data block belongs in the file system; the predicted life index is used to indicate the estimated number of data blocks allocated by the file system from the time the data block is written to the time the data block is invalidated; the life index of a file is used to indicate the estimated number of data blocks allocated by the file system from the time the file is created to the time the file is deleted; The storage space of the file system is managed according to the predicted life indicator of the data block.

2. The storage space management method according to claim 1, characterized in that: In the case where the data block is an initial block, the predicted life index of the initial block is consistent with the life cycle index of the file to which it belongs; the initial block is a data block to which data is written for the first time.

3. The storage space management method according to claim 2, characterized in that: In the case where the data block is an update block, the predicted life index of the update block is obtained based on an update cycle index; the update cycle index is used to indicate the number of data blocks allocated by the file system from the time the updated block is written to the time it becomes invalid; The updating block and the updated block are data blocks at different storage locations, the data written in the updating block is used to update the data content in the corresponding updated block, and the corresponding updated block becomes invalid after the data is written in the updating block; or The data written in the update block this time is used to update the data content in the data block at the same storage location, and the updated block is the original data block before this update.

4. The storage space management method according to claim 3, characterized in that: The predicted life index of the update block is the weighted sum of the update cycle index and the historical life index; the historical life index is the predicted life index of the updated block; The updated block is an update block or an initial block. When the updated block is an initial block, the predicted life index of the updated block is consistent with the life cycle index of the file to which the updated block belongs.

5. The storage space management method according to any one of claims 1 to 4, characterized in that: The initial life cycle index of the file is consistent with the life cycle index of the directory in which it is located, and the initial life cycle index of the directory is consistent with the life cycle index of the parent directory; the method also includes: When a target object is deleted, the life cycle indicator of the target object is updated according to the deletion timing indicator and creation timing indicator of the target object; wherein the object is a file or a directory; the deletion timing indicator is used to indicate the cumulative number of global blocks of the file system when the target object is deleted; the creation timing indicator is used to indicate the cumulative number of global blocks of the file system when the target object is created; the cumulative number of global blocks represents the total number of data blocks cumulatively allocated in the file system.

6. The storage space management method according to claim 5, characterized in that: After updating the life cycle indicator of the target object, the method further includes: According to the updated life cycle indicator of the target object, the life cycle indicator of the parent directory of the target object is updated.

7. The storage space management method according to claim 6, characterized in that: The updated lifecycle indicator of the parent directory of the target object is obtained based on the updated lifecycle indicator of the target object, the lifecycle indicator of the parent directory of the target object, and the number of files under the parent directory of the target object.

8. The storage space management method according to claim 7, characterized in that: The updating of the life cycle indicator of the parent directory of the target object according to the updated life cycle indicator of the target object includes: Calculate the product of the life cycle index of the parent directory of the target object and the number of files in the parent directory of the target object after update to obtain a first value; Adding the first value to the updated lifecycle indicator of the target object to obtain a second value; The ratio of the second value to the number of files in the parent directory of the target object before the update is calculated to obtain a life cycle indicator of the parent directory of the target object after the update.

9. The storage space management method according to claim 8, characterized in that: After the life cycle indicator of the parent directory of the target object is updated, when a new object is created under the parent directory, the initial life cycle indicator of the new object is consistent with the updated life cycle indicator of the parent directory.

10. The storage space management method according to claim 1, characterized in that: The life cycle indicator of the root directory is set to a preset number of data blocks; the preset number of data blocks is the maximum number of data blocks that the file system allows to be allocated to the root directory.

11. The storage space management method according to claim 5, characterized in that: The index node structure of the object includes a first parameter and a second parameter; the structure of the file system includes a third parameter; the first parameter is used to record the creation timing indicator of the object, and the second parameter is used to record the life cycle indicator of the object; the third parameter is used to record the total number of data blocks accumulated in the file system.

12. The storage space management method according to claim 11, characterized in that: The index node structure of the file includes a data block life tree structure, the data block life tree structure includes M data block life nodes, the data block life nodes include a fourth parameter and a fifth parameter; the fourth parameter is used to record the creation timing index of the data block, and the fifth parameter is used to record the predicted life index of the data block, and M is a positive integer.

13. The storage space management method according to claim 1, characterized in that: The managing the storage space of the file system according to the predicted life indicator of the data block includes: According to the predicted life index of each of the data blocks, a target data segment for garbage collection GC is selected; a data segment includes N consecutive data blocks; N is an integer greater than 1.

14. The storage space management method according to claim 13, characterized in that: The step of selecting a target data segment for garbage collection (GC) according to the predicted lifespan index of each data block includes: Filter candidate data segments according to a transfer overhead; the transfer overhead represents the overhead of transferring valid data blocks in the candidate data segments; According to the predicted life index of each of the data blocks, obtaining an average remaining life index and a remaining life variance index of the data blocks in each of the candidate data segments; The target data segment is determined according to the average remaining life indicator and the remaining life variance indicator of the data blocks in each of the candidate data segments.

15. The storage space management method according to claim 13, characterized in that: The step of selecting a target data segment for garbage collection (GC) according to the predicted lifespan of each of the data blocks includes: In the case where there are data segments to be selected in the cache list, the target data segment is selected from the cache list; the average remaining life index of the data segments to be selected is higher than the life index threshold, and the remaining life variance index is higher than the variance index threshold; In the case that the cache list does not have the candidate data segment, the candidate data segments are screened according to the migration cost, the target data segment and the candidate data segment are determined according to the candidate data segments, and the candidate data segment is stored in the cache list; the average remaining life index of the target data segment is higher than the life index threshold, and the remaining life variance index is less than or equal to the variance index threshold.

16. The storage space management method according to claim 1, characterized in that: The managing the storage space of the file system according to the predicted life indicator of the data block includes: According to the predicted lifespan of each data block, each data block is classified to obtain a classification result; the classification result includes at least a hot data block and a cold data block, and the predicted lifespan index of the hot data block is smaller than the predicted lifespan index of the cold data block; According to the classification result, each data block is written into a corresponding different storage area respectively; the storage area includes at least a hot data storage area and a cold data storage area, the hot data block is written into the hot data storage area, and the cold data block is written into the cold data storage area.

17. The storage space management method according to claim 1, characterized in that: The managing the storage space of the file system according to the predicted life indicator of the data block includes: For the data blocks in the cache, according to the predicted life index of each data block and a set threshold, the data blocks whose predicted life index is greater than or equal to the set threshold are preferentially written back to the main storage medium.

18. An electronic device, characterized in that: The electronic device comprises: one or more processors and a memory; the memory is coupled to the processor; the memory is used to store computer program code, the computer program code comprises computer instructions, and when the computer instructions are executed by the one or more processors, the electronic device executes the method as described in any one of claims 1-17.

19. A computer-readable storage medium, wherein instructions are stored in the computer-readable storage medium, characterized in that: When the instructions are executed on an electronic device, the electronic device is caused to execute the method as claimed in any one of claims 1 to 17.

20. A computer program product, characterized in that When the computer program product is run on a computer, the computer is caused to execute the method according to any one of claims 1 to 17.

Citation Information

Patent Citations

  • Wear leveling technique for storage devices

    CN102037520A

  • Wear management for flash memory devices

    CN106502917A

  • Data storage method and device

    CN115480707A

  • Solid state storage system and controlling method thereof

    KR1020090097050A

  • Method and device for data storage

    US11921629B1