Storage space management method and electronic device
By predicting the life cycle and life index of data blocks in the file system and optimizing storage space management, the storage space management load problem caused by data block failure is solved, and management efficiency and the service life of storage media are improved.
Patent Information
- Application Number
- CN202510328524.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-19
- Publication Date
- 2025-09-02
- Estimated Expiration
- 2045-03-19
AI Technical Summary
In the prior art, invalid data blocks are generated in large quantities due to data block failure in the file system, resulting in frequent storage space management operations, and increasing the storage space management load.
By predicting the life of data blocks based on the life cycle indicators and predicting life indicators of data blocks in the file system, understanding their failure timing in advance, optimizing storage space management, and reducing the frequency of data block transfer and recycling operations.
Effectively reduces the storage space management load, improves the storage space management efficiency, and reduces input/output bandwidth usage and physical wear of storage media.
Smart Images

Figure CN119847452B_ABST
Abstract
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] A file system is an operating system's method for organizing files on storage devices. Journaling file systems are widely used in electronic devices. Data blocks in a file system can become invalid for various reasons, resulting in a large number of invalid data blocks. To maintain efficient storage space utilization, electronic devices frequently perform storage management operations such as moving or recycling data blocks, resulting in a significant storage 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, for reducing 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:
[0006] In a first aspect, a storage space management method is provided. The method includes: determining a predicted lifespan indicator for characterizing the lifespan of a data block in a file system based on a lifespan indicator of a file to which the data block belongs; the predicted lifespan indicator indicating the estimated number of data blocks allocated by the file system between the time the data block is written and the time it expires; and the file lifespan indicator indicating the estimated number of data blocks allocated by the file system between the time the file is created and the time it is deleted. Subsequently, the storage space of the file system is managed based on the predicted lifespan indicator of the data block.
[0007] It should be understood that data block allocation in a file system is an ongoing, incremental process. Both the lifecycle indicator and the predicted lifespan indicator are counts of allocated data blocks from the file system's perspective. Electronic devices can determine the predicted lifespan indicator for a data block based on the lifespan indicator of the file to which the data block belongs in the file system. They can then manage the file system's storage space based on the data block's lifespan as indicated by the predicted lifespan indicator.
[0008] In the above-mentioned 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 understood in advance. The storage space management can be performed more efficiently 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.
[0009] In a possible implementation of the first aspect, when 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.
[0010] 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 lifespan index of the initial block may inherit the lifespan index of the file to which it belongs.
[0011] The above 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.
[0012] 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 the 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 fails.
[0013] 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 update block writes the data, 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.
[0014] It should be understood that after data is written to a data block, the data within the data block may be updated. Depending on the file system type, the storage locations of the updating block and the updated block may be different. In some embodiments, such as a journaling file system, the updating block and the updated block are data blocks in different storage locations. The data written to the updating block is used to update the data content in the corresponding updated block. After the data is written to the updating block, the corresponding updated block becomes invalid. In other embodiments, the data written to the updating block is used to update the data content in the data block at the same storage location.
[0015] When the data block is an update block, the electronic device needs to consider the update interval, or update period, when predicting the lifespan of the update block. The electronic device can directly use the update period as the predicted lifespan of the update block, or it can combine the update period and the predicted lifespan of the updated block to obtain the predicted lifespan of the update block.
[0016] The above storage space management method, by introducing the update cycle indicator, can more accurately reflect the status of the file system after the update, thereby improving the accuracy of the update block life prediction.
[0017] In another possible implementation of the first aspect, the predicted lifespan indicator of the updated block is a weighted sum of the update cycle indicator and the historical lifespan indicator; the historical lifespan indicator is the predicted lifespan indicator of the updated block; the updated block is either an updated block or an initial block. If the updated block is an initial block, the predicted lifespan indicator of the updated block is consistent with the lifecycle indicator of the file to which the updated block belongs.
[0018] 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 lifespan index is the predicted lifespan index of the initial block, that is, the historical lifespan index is consistent with the life cycle index of the file to which the initial block belongs. The predicted lifespan index of the update block is derived based on the update cycle and the historical lifespan index. In the case where the updated block is an update block, the historical lifespan index can be iterated to the historical lifespan index of the updated block corresponding to the previous update, and ultimately to the predicted lifespan index of the corresponding initial block.
[0019] In the above storage space management method, the predicted lifespan of an updated block is a weighted sum of the update cycle index and the historical lifespan index. The update cycle index reflects the current state of the file system. The historical lifespan index represents the predicted lifespan of the updated block and is calculated based on the previous update cycle index and predicted lifespan index. The historical lifespan index reflects the stability and predicted lifespan of the relevant data block over a period of time. This combined consideration of the update cycle index and historical lifespan index in predicting the lifespan of an updated block provides a more comprehensive and accurate lifespan prediction.
[0020] In another possible implementation of the first aspect, the initial life cycle indicator of a file is consistent with the life cycle indicator of the directory in which it is located, and the initial life cycle indicator of a directory is consistent with the life cycle indicator of the parent directory; the method also includes: when a target object is deleted, updating the life cycle indicator of the target object according to the deletion timing indicator and creation timing indicator of the target object, where 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 and allocated in the file system.
[0021] It should be understood that a file's initial lifecycle indicator can inherit the lifecycle indicator of the directory in which it resides, and a directory's lifecycle indicator can inherit the lifecycle indicator of its parent directory. When a file (or directory) is deleted, the electronic device updates the file's (or directory's) previous lifecycle indicator based on the file's (or directory's) actual lifecycle indicator. The actual lifecycle indicator is calculated based on the file's (or directory's) creation timing indicator and deletion timing indicator. The electronic device can obtain the creation timing indicator and deletion timing indicator based on the file system's global cumulative block count.
[0022] In the above storage space management method, electronic devices record creation and deletion timing indicators using global block accumulation, providing a clear understanding of the relative position of files (or directories) within the file system's storage space growth. This facilitates analysis of file system storage space usage and updates, facilitating prediction of future storage space requirements. The electronic device updates the previous lifecycle indicator of a file (or directory) based on its actual lifecycle indicator. Subsequently, the predicted lifecycle indicator of the initial block associated with the file inherits the updated lifecycle indicator, improving the accuracy of the predicted lifecycle indicator.
[0023] In another possible implementation of the first aspect, after updating the lifecycle indicator of the target object, the method further includes: updating the lifecycle indicator of the parent directory of the target object according to the updated lifecycle indicator of the target object.
[0024] 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 the new value; timely updating the life cycle indicator of the parent directory improves the accuracy of the parent directory life cycle indicator.
[0025] In another possible implementation of the first aspect, the updated lifecycle indicator of the target object's parent directory is obtained based on the updated lifecycle indicator of the target object, the lifecycle indicator of the target object's parent directory, and the number of files under the target object's parent directory.
[0026] It should be understood that comprehensively considering the updated lifecycle indicator of the target object, the original lifecycle indicator of the parent directory, and the number of files under the parent directory can more comprehensively reflect the actual status of the file system and improve the accuracy of the lifecycle indicator of the parent directory.
[0027] In another possible implementation of the first aspect, updating the lifecycle indicator of the target object's parent directory based on the target object's updated lifecycle indicator includes: calculating the product of the target object's parent directory's lifecycle indicator and the number of files in the target object's parent directory after the update to obtain a first value; adding the first value to the target object's updated lifecycle indicator to obtain a second value; and calculating the ratio of the second value to the number of files in the target object's parent directory before the update to obtain the target object's parent directory's updated lifecycle indicator.
[0028] In the above storage space management method, the electronic device calculates the average lifecycle index of all files in the parent directory during an update cycle. This average value reflects changes in the parent directory's lifecycle index. The electronic device promptly updates the parent directory's lifecycle index, improving its accuracy.
[0029] 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.
[0030] The above storage space management method predicts the initial life cycle indicator of a newly created file under the parent directory based on a more accurate parent directory life cycle indicator, thereby improving the accuracy of the prediction of the data block life cycle of the newly created file.
[0031] In another possible implementation of the first aspect, the lifecycle 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.
[0032] In the above storage space management method, the root directory lifecycle indicator is preset to the maximum number of data blocks allowed by the file system to be allocated to the root directory. This eliminates the need for complex initialization evaluation and calculations, allowing the electronic device to directly use the maximum value as the root directory lifecycle indicator, improving prediction efficiency.
[0033] In another possible implementation of the first aspect, the index node structure of the object includes a newly added first parameter and 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 object's creation timing indicator, and the second parameter is used to record the object's life cycle indicator; the third parameter is used to record the total number of data blocks accumulated in the file system.
[0034] With the aforementioned storage space management method, electronic devices can record file (or directory) creation timing indicators and predicted lifecycle indicators through newly added parameters. When calculating the predicted lifespan indicators of data blocks, relevant parameters can be used at any time to provide accurate and real-time assessments.
[0035] 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, and the data block life node includes 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.
[0036] In the above storage space management method, the electronic device can record the creation timing index and predicted life index of the data block by adding new 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.
[0037] 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.
[0038] 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.
[0039] In another possible implementation of the first aspect, selecting a target data segment for garbage collection (GC) based on a predicted lifespan indicator for each data block includes: screening candidate data segments based on a move cost, where the move cost represents the cost of moving valid data blocks in the candidate data segment; obtaining an average remaining lifespan indicator and a remaining lifespan variance indicator for the data blocks within each candidate data segment based on the predicted lifespan indicator for each data block; and determining a target data segment based on the average remaining lifespan indicator and the remaining lifespan variance indicator for the data blocks within each candidate data segment.
[0040] 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.
[0041] In another possible implementation of the first aspect, target data segments for garbage collection (GC) are selected based on the predicted lifespan of each data block, including: if a cache list contains candidate data segments, selecting the target data segments from the cache list; the average remaining lifespan index of the candidate data segments is higher than a lifetime index threshold, and the remaining lifespan variance index is higher than a variance index threshold. If the cache list contains no candidate data segments, screening candidate data segments based on migration overhead, determining the target data segments and candidate data segments based on the candidate data segments, and storing the candidate data segments in the cache list; the average remaining lifespan index of the target data segments is higher than the lifetime index threshold, and the remaining lifespan variance index is less than or equal to the variance index threshold.
[0042] In the above storage space management method, for candidate data segments with a high average remaining life index but a 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 overhead drops rapidly in a short period of time. In order to improve efficiency, it is necessary to quickly select the target data segment for space recovery. In order to avoid the performance overhead caused by full disk traversal, the selection is made directly in the cache list. In this way, the candidate data segments with a high average remaining life index but a large remaining life variance index can be temporarily stored in the cache list as candidate data segments. The target data segments selected in the next round can be directly selected from the candidate data segments in the cache list, thereby improving the recovery efficiency of GC.
[0043] In another possible implementation of the first aspect, managing storage space of a file system based on a predicted lifespan index of a data block includes: classifying each data block based on its predicted lifespan to obtain a classification result; the classification result includes at least hot data blocks and cold data blocks, the predicted lifespan index of the hot data block being smaller than the predicted lifespan index of the cold data block; and writing each data block to a corresponding different storage area based on the classification result; the storage area includes at least a hot data storage area and a cold data storage area, with the hot data blocks being written to the hot data storage area and the cold data blocks being written to the cold data storage area.
[0044] The above storage space management method ensures that hot and cold data are properly stored in corresponding storage areas through data diversion. This ensures that data blocks within each storage area expire at similar times, significantly reducing GC frequency and overhead, and significantly alleviating the storage space management load on electronic devices.
[0045] In another possible implementation of the first aspect, the storage space of the file system is managed based on the predicted life index of the data block, including: for the data blocks in the cache, based on the predicted life index of each data block and the 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.
[0046] The above-mentioned storage space management method, for data blocks in the cache, selects data blocks to be written back to the main storage medium first based on the predicted life index. For data blocks with higher predicted life indexes, since they are not expected to change for a long time, the electronic device performs a write-back operation to synchronize the data to the main storage medium first. For data blocks with lower predicted life indexes, considering that they may be updated and become invalid soon, it is chosen not to write them back to the main storage medium (referred to as the main memory) temporarily, thereby reducing the overhead of deleting the data blocks written back to the main memory and writing them back to the main memory again after they become invalid 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.
[0047] 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 comprising computer instructions, which, when executed by one or more processors, enables the electronic device to execute the method described in the first aspect and any possible design thereof.
[0048] In a third aspect, the present application provides a computer-readable storage medium, which stores instructions. 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.
[0049] 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.
[0050] 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
[0051] Figure 1 A schematic diagram of the remote update characteristics and data block validity of a log file system provided in an embodiment of the present application;
[0052] Figure 2 A flowchart of a storage space management method provided in an embodiment of the present application;
[0053] Figure 3 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application;
[0054] Figure 4A schematic diagram of the software architecture of an electronic device provided in an embodiment of the present application;
[0055] Figure 5 A schematic diagram of a file system hierarchical structure and data structure extension provided in an embodiment of the present application;
[0056] 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;
[0057] Figure 7 A schematic diagram of a garbage collection process provided in an embodiment of the present application;
[0058] Figure 8 A schematic diagram of target data segment selection provided in an embodiment of the present application;
[0059] Figure 9 A schematic diagram of recording the creation timing indicator and life cycle indicator when creating a file provided in an embodiment of the present application;
[0060] Figure 10 A schematic diagram of updating file and parent directory lifecycle indicators when a file is deleted, provided in an embodiment of the present application;
[0061] Figure 11 A schematic diagram of life cycle indicators for newly created files after a directory update provided in an embodiment of the present application;
[0062] Figure 12 A schematic structural diagram of a chip system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0063] The technical solutions in the embodiments of the present application are described below in conjunction with the accompanying drawings. The terms used in the following embodiments are for the purpose of describing specific embodiments only and are not intended to limit the present application. As used in the specification and appended claims of this application, the singular expressions "a," "the," "the," "the," and "the" are intended to include expressions such as "one or more," unless the context clearly indicates otherwise. It should also be understood that in the following embodiments of this application, "at least one" and "one or more" refer to one or more (including two). The term "and / or" is used to describe an association relationship between associated objects, indicating that three possible relationships can exist. For example, "A and / or B" can mean: A exists alone, A and B exist simultaneously, or B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the associated objects are in an "or" relationship.
[0064] References to "one embodiment" or "some embodiments" etc. described in this specification mean that the specific features, structures or characteristics described in conjunction with the embodiment are included in one or more embodiments of the present application. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. appearing 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 another way. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in another way. The term "connected" includes direct and indirect connections, unless otherwise stated. "First" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated.
[0065] In the embodiments of this application, words such as "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 this application should not be interpreted as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplarily" or "for example" is intended to present the relevant concepts in a concrete manner.
[0066] The software component of an operating system 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 journaling file systems, virtual file systems (VFS), and file allocation table file systems (FAT).
[0067] The journaling file system features off-site updates, meaning updated data isn't modified directly in the original location. Instead, it appends the new data sequentially to a new storage space. This off-site update approach offers good random write performance and is flash-friendly, but it places high demands on storage space continuity.
[0068] 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.
[0069] The file system's storage space can include multiple data blocks. When writing data, the file system requests a data block to store it. Data blocks that store valid data are called valid data blocks, while data blocks that do not store data or have been marked invalid are called invalid data blocks. Data blocks may be marked invalid due to deletion or due to remote updates.
[0070] For example, Figure 1 This shows the characteristics of the log file system out-of-place update. Figure 1 As shown, if data blocks 12 and 13 need to be updated, the new data is written sequentially into unused data blocks 18 and 19 in an appended manner, resulting in data blocks 18a and 19a. The original data blocks 12 and 13 are marked as invalid data blocks 12a and 13a respectively.
[0071] 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. Data blocks that have been updated, deleted, or unused are invalid data blocks. Taking the data blocks before the update as an example, data blocks 18 and 19 are both invalid data blocks.
[0072] Invalid data blocks not only occupy storage space but also affect the storage space continuity of log file systems. Therefore, to improve storage space continuity and utilization, storage space management methods such as garbage collection (GC) and data diversion have been proposed. However, during GC and data diversion, electronic devices must frequently perform data block movement and recycling operations for a large number of invalid data blocks, resulting in a significant storage space management load.
[0073] Furthermore, when saving cached data back to persistent primary storage (hereinafter referred to as cache writeback), some short-lived data is unnecessarily written to persistent storage media (such as magnetic disks or solid-state drives), where it quickly becomes ineffective. This process not only increases the storage management load and wastes input / output (IO) bandwidth, but also increases physical wear on the storage media, shortening its lifespan.
[0074] In some related technologies, file systems allow users to set file storage ageing levels based on their needs through the Input / Output Control (ioctl) interface provided by Virtual File Systems (VFS). However, these storage ageing levels are fixed and preset, for example, only distinguishing between temporary and long-term files, without providing clear and quantitative time-based demarcation standards. Users must manually set the ageing range for each file, which is not only cumbersome but also limits application scenarios.
[0075] 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 a predicted lifespan indicator for a data block based on the lifespan indicator of the file to which the data block belongs in the file system. The predicted lifespan indicator is used to characterize the lifespan of the data block. The electronic device then manages the storage space of the file system based on the predicted lifespan indicator of the data block. The predicted lifespan indicator indicates the estimated number of data blocks allocated by the file system between the time the data block is written and the time it expires. The file lifespan indicator indicates the estimated number of data blocks allocated by the file system between the time the file is created and the time it is deleted.
[0076] The file system's data block allocation is an ongoing, incremental process, similar to the accumulation of time. For any data block, the predicted lifespan index reflects the number of additional data blocks the file system may need to allocate to store related data between the time the block is written and its failure. Specifically, the higher the predicted lifespan index, the more additional data blocks the file system will need to allocate between the time the block is written and its failure, indicating a longer predicted lifespan for the data block.
[0077] In some embodiments, the electronic device can accumulate the total number of data blocks allocated by the file system, a behavior similar to recording a time series. The cycle indicator and lifespan indicator correspond to specific "time span" statistics in the time series. This allows for predicting the lifespan of data blocks. 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 lifespan indicator of the data block is b. In this case, the electronic device predicts that the data block will become invalid when the total number of data blocks allocated by the file system reaches a + b.
[0078] In the above-mentioned 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 understood in advance. The storage space management can be performed more efficiently 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.
[0079] For example, the above-mentioned electronic devices can be mobile phones, tablet computers, televisions (also known as smart TVs, smart screens or large-screen devices), laptops, ultra-mobile personal computers (UMPCs), handheld computers, cameras (such as digital cameras), video cameras (such as digital video cameras), netbooks, personal digital assistants (PDAs), wearable electronic devices (such as smart watches, smart bracelets, smart glasses), vehicle-mounted devices, virtual reality devices, and other electronic devices with file systems. The embodiments of the present application do not impose any restrictions on this.
[0080] For ease of understanding, a mobile phone is taken as an example to schematically illustrate the hardware structure and software system of the electronic device to which the method in the embodiments of the present application is applied.
[0081] Figure 3 A schematic structural diagram of a mobile phone is shown.
[0082] 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 194, and a subscriber identification module (SIM) card interface 195, etc.
[0083] It should be understood that the structures illustrated in the embodiments of the present invention do not constitute a specific limitation on mobile phones. In other embodiments of the present application, the mobile phone may include more or fewer components than shown in the figure, or some components may be combined or separated, or the components may be arranged differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0084] 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 processing unit (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). The different processing units may be independent devices or integrated into one or more processors.
[0085] Processor 110 can be used to read and execute computer-readable instructions. Optionally, processor 110 may also include a controller, an arithmetic unit (ALU), and registers. The controller is primarily responsible for decoding instructions and issuing control signals for operations corresponding to the instructions. The ALU is primarily responsible for temporarily storing register operands and intermediate operation results during instruction execution. Registers are high-speed storage components with limited storage capacity that can be used to temporarily store instructions, data, and addresses.
[0086] 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.
[0087] 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.
[0088] 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 can 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 can 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.
[0089] 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.
[0090] The mobile communication module 150 can provide solutions for wireless communications, including 2G / 3G / 4G / 5G, used on mobile phones. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.
[0091] 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.
[0092] The mobile phone can implement audio functions such as music playback and recording through the audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, and application processor.
[0093] Keys 190 include a power button, a volume button, and the like. Keys 190 may be mechanical keys or touch-sensitive keys. The mobile phone may receive key inputs and generate key signal inputs related to user settings and function control of the mobile phone.
[0094] 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.
[0095] The indicator 192 may be an indicator light, which may be used to indicate the charging status, power level changes, messages, missed calls, notifications, etc.
[0096] Camera 193 is a physical camera that actually exists. In some embodiments of the present application, the mobile phone may have multiple cameras 193. For example, the multiple cameras 193 may include a front camera and a rear camera. The front camera may be one or more, and the rear camera may also be one or more.
[0097] The mobile phone can implement a shooting function through the ISP, camera 193, video codec, GPU, display 194 and application processor, etc. For example, an application in the mobile phone can access the camera 193 and control the camera 193 to capture images.
[0098] The mobile phone implements its display functionality through a GPU, display 194, and an application processor. The GPU is a microprocessor for image processing that connects display 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or modify display information.
[0099] The display screen 194 is used to display images, videos, etc.
[0100] 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 or removing the SIM card into or from the SIM card interface 195.
[0101] 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 with a layered architecture as an example to illustrate the software structure of the mobile phone.
[0102] Figure 4 It is a software structure diagram of the mobile phone according to an embodiment of the present invention.
[0103] A layered architecture divides software into several layers, each with distinct roles and responsibilities. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers: application layer, application framework layer, system library layer, and kernel layer, from top to bottom.
[0104] The application layer can include a series of application packages.
[0105] like Figure 4 As shown, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc.
[0106] The application framework layer provides an application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0107] 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.
[0108] The window manager is used to manage window programs. The window manager can obtain the display size, determine whether there is a status bar, lock the screen, take screenshots, etc.
[0109] 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.
[0110] The view system includes visual controls, such as those for displaying text and images. The view system is used to build applications. A display interface can consist of one or more views. For example, a display interface containing a text notification icon might include a view for displaying text and a view for displaying images.
[0111] 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.).
[0112] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0113] The Notification Manager allows applications to display notifications in the status bar. These messages can be displayed briefly and then disappear automatically without user interaction. For example, the Notification Manager is used to notify users of completed downloads and message reminders. The Notification Manager can also display notifications in the top status bar of the system as icons or scrolling text, such as notifications from background applications, or as dialog windows on the screen. Examples include text messages in the status bar, beeps, vibrations on electronic devices, and flashing indicator lights.
[0114] The system library can 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.
[0115] The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications.
[0116] The media library supports playback and recording of a variety of common audio and video formats, as well as static image files. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0117] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0118] A 2D graphics engine is a drawing engine for 2D drawings.
[0119] like Figure 4 As shown in Figure 1, the kernel layer is the layer between hardware and software. The kernel layer includes at least 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.
[0120] Figure 5 、 Figure 9 and Figure 10The following shows a hierarchical file system structure. 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 directories 1 and 2, directory 1 contains directories 3 and 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 directory above a file (or directory) is called the parent directory of that file (or directory). The files (or directories) below a directory are called child files (or subdirectories) of that directory. For example, directory 1 is the parent directory of directory 3, directory 3 is a subdirectory of directory 1, directory 5 is the parent directory of file 4, and file 4 is a child file of directory 5.
[0121] In this application, the internal data structure of the file system at the kernel layer is expanded.
[0122] In some embodiments, a first parameter and a second parameter are added to the file (or directory) inode structure. A third parameter is added to the file system structure. The first parameter is used to record the file (or directory) creation timing indicator, and the second parameter is used to record the file (or directory) lifecycle indicator. The third parameter is used to record the total number of data blocks allocated in the file system.
[0123] In some embodiments, a data block lifespan tree structure is added to the file's index node structure. The data block lifespan tree structure includes multiple data block lifespan nodes. Each data block lifespan node includes a fourth parameter and a fifth parameter. The fourth parameter is used to record the creation timing indicator of the data block, and the fifth parameter is used to record the predicted lifespan indicator of the data block.
[0124] The electronic device can match different fourth parameters to different data blocks and / or different fifth parameters to different data blocks. Alternatively, based on actual needs, the electronic device can allow multiple data blocks to share the same fourth parameter and / or the same fifth parameter. As long as a clear correspondence between data blocks and parameters is established, the electronic device can trace the corresponding parameters to the data blocks when calculating the data block lifespan indicator.
[0125] Specifically, a new parameter can be added to the file system's superblock structure: the global block cumulative number (total_ count). The total_ count is used to accumulate the total number of data blocks allocated by the file system.
[0126] like Figure 5As shown in the figure, the directory creation timing indicator (c_num) and directory life cycle indicator (lifetime) are added to the directory index node (dir inode) structure, and the file creation timing indicator (c_num) and file life cycle indicator (lifetime) are added to the file index node (file inode) structure.
[0127] like Figure 5 As shown in the figure, a new structure is added to the file index node structure: the blocks lifetime tree. The blocks lifetime tree includes a series of block lifetime nodes, and new parameters are added to the block lifetime nodes: the block creation timing parameter (w_num) and the block predicted lifetime parameter (node_lifetime).
[0128] Specifically, a data block lifespan tree is added to the extent tree structure. 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 a data segment). Thus, in the newly added data block creation timing parameters and data block predicted lifespan parameters, the data block creation timing parameter structure can be used to record the earliest creation timing indicator of a data block within the aforementioned data segment, and the data block predicted lifespan parameter structure can be used to record the average predicted lifespan indicator of the data blocks within the aforementioned data segment.
[0129] The following combination Figure 4 , exemplarily illustrating the processing flow of a mobile phone executing the method in the embodiment of the present application.
[0130] 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.
[0131] The kernel-level file system records the creation timing and lifecycle indicators of files in the corresponding structure. The lifecycle indicator can inherit the lifecycle indicator of the parent directory. Furthermore, the file system records information about data blocks within the file in the corresponding data block lifecycle tree. For each data block lifecycle node, the corresponding structure records the earliest creation timing indicator of the data block within the data segment and the data block's predicted lifespan indicator. The data block's predicted lifespan indicator can inherit the lifecycle indicator of the file to which it belongs.
[0132] For another example, when an application in the application layer updates a data block during execution, this status message is passed to the kernel layer through the application framework layer and the system library.
[0133] For the update block, the kernel layer file system 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. The predicted life index of the update block is calculated based on the update cycle index, and the predicted life index of the update block is written in the corresponding structure.
[0134] In some embodiments, the update block and the updated block are data blocks in different storage locations. 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 characteristic of remote 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.
[0135] 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 the update.
[0136] 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.
[0137] For ease of understanding, the following embodiments describe in detail application scenario 1: GC scenario.
[0138] In a file system, a certain number of data blocks are organized into data segments, which are the basic units of storage space management. Based on the validity of the data blocks within a segment, a data segment is classified into three states: empty, full, and dirty. If a segment contains only invalid data blocks, it is considered an empty segment. If a segment contains only valid data blocks, it is considered a full segment. If a segment contains both valid and invalid data blocks, it is considered a dirty segment.
[0139] 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 full data segment, and data segment 204 is still empty data segment.
[0140] As users use the system, valid data blocks gradually become invalid, dirty data segments increase, and empty data segments decrease. An insufficient number of empty data segments significantly impacts the performance and stability of the log file system. To ensure a sufficient number of empty data segments, electronic devices regularly clean up dirty data segments, moving valid data within them to other locations. This frees up the storage space occupied by the dirty data segments, thereby creating contiguous storage space (i.e., empty data segments). This process is called garbage collection (GC).
[0141] During the garbage collection process, because moving valid data blocks incurs a certain amount of overhead, electronic devices must select appropriate data segments for cleanup. These segments are called target segments. Currently, target segments are selected only based on the migration overhead, not the lifespan of the data blocks. This can cause valid data blocks to become invalid shortly after being moved. This not only increases garbage collection overhead but also makes it difficult to effectively manage data blocks, resulting in a significant storage management load.
[0142] 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.
[0143] The electronic device can first screen the candidate data segments based on 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.
[0144] In some embodiments, the electronic device can calculate a remaining lifespan indicator based on the current total_count, the data block's creation timing indicator, and the predicted lifespan indicator. For example, assuming the total number of data blocks allocated by the file system at the time of data block creation (the creation timing indicator) is a, and the data block's predicted lifespan indicator is b, the electronic device predicts that the data block will become invalid when the total number of data blocks allocated by the file system reaches a + b. Assuming the current total number of data blocks allocated by the file system (the current total_count) is c, the electronic device calculates the remaining lifespan indicator for the data block as a + bc.
[0145] 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 remaining life variance index of the candidate data segment.
[0146] 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, candidate data segments are screened according to the migration overhead, and the predicted life index of each data block is calculated, thereby obtaining the average remaining life index and the remaining life variance index of each data block in each candidate data segment. The electronic device uses 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 uses 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 candidate data segment and stores it in the cache list.
[0147] In some embodiments, as Figure 7 As shown, the electronic device first selects candidate data segments based on the migration cost. Then, based on the predicted lifespan of each data block, it calculates the average remaining lifespan and remaining lifespan variance of the data blocks within the candidate data segments. Taking into account the average remaining lifespan and remaining lifespan variance of the candidate data segments, the candidate data segments with high average remaining lifespan and low remaining lifespan variance are selected as the target data segments for this round. The candidate data segments with high average remaining lifespan and high remaining lifespan variance are added to the cache list as candidate data segments. These candidate data segments serve as target data segments for the next round of garbage collection (GC).
[0148] The remaining life variance index is a key metric for measuring the degree of dispersion in the remaining life of data blocks within a candidate data segment. To mitigate the impact of extreme values on the average remaining life index calculation, candidate data segments with smaller remaining life variances are selected. This allows the average remaining life index of the candidate data segments to more accurately reflect the overall expected life of the data blocks. Furthermore, candidate data segments with smaller remaining life variances have more similar remaining lifespans within them, helping to reduce the occurrence of scattered data block failures at different points in time. Furthermore, candidate data segments with smaller remaining life variances are more likely to fail en masse at similar times, indirectly reducing the generation of dirty data segments.
[0149] For candidate data segments with a high average remaining life index but a 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 overhead 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, selection is made directly in the cache list. In this way, the candidate data segments with a high average remaining life index but a large remaining life variance index can be temporarily stored in the cache list as candidate data segments. The target data segments can be directly selected from the candidate data segments in the cache list in the next round of selection, thereby improving the GC recovery efficiency.
[0150] In some embodiments, the electronic device may determine the migration cost based on the number of valid data blocks in the data segment. A migration cost threshold may be set, and data segments below the migration cost threshold are candidate data segments.
[0151] The target data segments are selected by comprehensively considering the average remaining life indicator and the remaining life variance indicator of the candidate data segments. In some embodiments, a lifetime indicator threshold and a variance indicator threshold can be set respectively. Candidate data segments whose average remaining life indicator exceeds the lifetime indicator threshold and whose remaining life variance indicator does not exceed the variance indicator threshold are selected as target data segments for this round. Candidate data segments whose average remaining life indicator exceeds the lifetime indicator threshold and whose remaining life variance indicator exceeds the variance indicator threshold are selected as candidate data segments.
[0152] For example, Figure 8 As shown, the number of valid data blocks of data segments A to C is 5, which is less than the migration overhead threshold. Data segments A to C are all candidate data segments. Figure 8 In the example, the numbers within the valid data blocks represent the remaining lifespan of the corresponding data blocks. The average remaining lifespan index of candidate data segment A is 11, and the average remaining lifespan index of candidate data segment C is 11.2. The average remaining lifespan indexes of candidate data segments A and C exceed the lifespan index threshold. The average remaining lifespan index of candidate data segment B is 8, which is below the lifespan index threshold, so candidate data segment B is excluded. Furthermore, the remaining lifespan variance index of candidate data segment A is 0, which is below the variance index threshold; whereas the remaining lifespan variance index of candidate data segment C is 33.76, which is above the variance index threshold.
[0153] 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 of 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 soon become invalid. After the invalidation, the migration overhead is significantly reduced, and the candidate data segment C is selected as the candidate data segment.
[0154] In other embodiments, the electronic device may determine the target data segment from the candidate data segments based on a weighted sum evaluation method. For example, first, the weighted sum of the average remaining life index and the remaining life variance index of the candidate data segments 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 blocks. A first weighted sum threshold and a second weighted sum threshold may 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.
[0155] For ease of understanding, the following embodiment introduces application scenario 2 in detail: data diversion scenario.
[0156] Data distribution aims to allocate data to different storage areas by differentiating its access and update frequencies. During data distribution, data is classified 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 is data with an access and update frequency between hot and cold data. Cold data is data with a low access and update frequency.
[0157] Data diversion ensures that hot, warm, and cold data are appropriately stored in corresponding storage areas. This ensures that data blocks within each storage area expire at similar times, significantly reducing GC frequency and overhead, and significantly alleviating the storage space management load on electronic devices.
[0158] In some embodiments, the lifespan prediction method of the present application is applied to a data offload scenario to further reduce the storage space management load of the electronic device.
[0159] First, the method of this application is used to obtain a predicted lifespan index for each data block. Data is then divided based on the predicted lifespan index of each data block, resulting in a classification result. The classification result includes at least hot data blocks and cold data blocks. For example, data blocks with low predicted lifespan indexes and expected to be updated soon are classified as hot data blocks, while data blocks with high predicted lifespan indexes and expected to be inactive for a long time are classified as cold data blocks. The hot and cold data blocks are then written to their corresponding storage areas.
[0160] For ease of understanding, the following embodiments describe in detail application scenario three: cache write-back scenario.
[0161] Cache write-back synchronizes cache data back to persistent primary storage. As a high-speed data storage area, cache temporarily stores frequently accessed data to improve data access speed. However, to ensure data persistence and consistency, when cache data changes, the updated data must be written back to the primary storage. Cache write-back timing refers to the conditions under which updated cache data is synchronized back to the primary storage.
[0162] 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 to be written back to the main storage medium are selected first 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 first. 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.
[0163] For example, a write-back threshold may be set, and the electronic device preferentially writes back data blocks whose predicted lifespan indicators are greater than or equal to the write-back threshold to the primary storage medium.
[0164] In each of the above application scenarios, it is necessary to manage the file system's storage space based on the predicted lifespan of the data blocks. It should be understood that the storage space management method of this application is not limited to the application scenarios listed above. The method is also applicable to other scenarios that also use data block predicted lifespan information for file system storage management, and is not limited here.
[0165] For ease of understanding, the storage space management method of the present application is described in detail in the following embodiments.
[0166] In some embodiments, a lifespan prediction system based on a directory tree is established, whereby the electronic device determines a predicted lifespan indicator for a data block based on the lifecycle indicator of the file to which the data block belongs in the file system, and manages storage space based on the predicted lifespan indicator for each data block.
[0167] For an initial block, the predicted lifespan can inherit the lifespan of the file to which it belongs, and the initial lifespan of a file can inherit the lifespan of its parent directory. An initial block is a data block where data is first written, and is not written based on data update requirements.
[0168] 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 (i.e., 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.
[0169] 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 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, Figure 9 As shown, when file 3 is created, the electronic device records the creation timing indicator of file 3 based on the global block cumulative number at that time. Directory 4 is the parent directory of file 3, and the life cycle indicator of file 3 is recorded based on the life cycle indicator of directory 4. It can be expressed as:
[0170] ;
[0171] ;
[0172] 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 count when file 3 was created; Indicates the life cycle indicator of file 3; Indicates the life cycle indicator of directory 4.
[0173] 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:
[0174] ;
[0175] in, represents the predicted life index of the initial block, Indicates the lifecycle indicator of file 3.
[0176] For the update block, the electronic device obtains a predicted life indicator based on the update cycle indicator.
[0177] In some embodiments, the electronic device may calculate a weighted sum of the update cycle indicator and the historical lifespan indicator to obtain a predicted lifespan indicator for the update block. Alternatively, the electronic device may calculate an average of the update cycle indicator and the historical lifespan indicator to obtain a predicted lifespan indicator for the update block. Alternatively, the electronic device may directly use the update cycle indicator as the predicted lifespan indicator for the update block.
[0178] 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 based on 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 between the time data block 12 is written and the time it is marked as invalid.
[0179] For example, the predicted lifespan indicator of an update block can be expressed as:
[0180] ;
[0181] in, represents the predicted lifespan indicator of the update block; Indicates the total number of data blocks allocated by the file system as recorded by the global block cumulative count 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 lifespan indicator; represents the weight coefficient, The value range is [0, 1].
[0182] The update cycle metric represents the number of data blocks allocated by the file system between the time the updated block is written and its expiration. This metric reflects the current state of the file system. The historical lifespan metric represents the predicted lifespan of the updated block. It is calculated based on the previous update cycle metric and the predicted lifespan metric. The historical lifespan metric reflects the stability and predicted lifespan of the corresponding data block over a period of time. By combining the update cycle metric and the historical lifespan metric to predict the lifespan of updated blocks, a more comprehensive and accurate prediction can be obtained.
[0183] In some embodiments, when a file (or directory) is deleted, the electronic device updates the file's life cycle indicator based on the file's (or directory's) deletion timing indicator and creation timing indicator to obtain the file's actual life cycle indicator.
[0184] For example, Figure 10As 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:
[0185] ;
[0186] 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.
[0187] In some embodiments, after the electronic device updates the lifecycle indicator of a deleted file, it updates the lifecycle indicator of the corresponding parent directory. The updated lifecycle indicator of the parent directory can be obtained based on the updated lifecycle indicator of the deleted file, the lifecycle indicator of the parent directory before the update, and the number of files in the parent directory. This method can ensure that after a file is deleted, the lifecycle indicator of the directory can smoothly transition to the new value; timely updating of the lifecycle indicator of the parent directory improves the accuracy of the parent directory lifecycle indicator.
[0188] For example, Figure 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:
[0189] ;
[0190] in, Represents the new lifecycle indicator for 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 under directory 3. Figure 10 In the embodiment described, the number of files under directory 3 is 2.
[0191] After the life cycle indicator of the parent directory is updated, if a new file is created under the corresponding parent directory, the life cycle indicator of the new file will inherit the new life cycle indicator of the parent directory. Figure 11 As shown in the figure, after the lifecycle indicator of directory 3 is updated, file 6 is created under directory 3. The lifecycle indicator of the newly created file 6 inherits the new lifecycle indicator of directory 3. File 5 was created before the lifecycle indicator of directory 3 was updated, so the lifecycle indicator of file 5 remains unchanged.
[0192] By promptly updating the lifecycle indicator of a file (or directory) and feeding it back to the parent directory, the parent directory's lifecycle indicator is dynamically updated. This not only improves the accuracy of the parent directory's lifecycle indicator, but also allows the initial lifecycle indicator of newly created files in the parent directory to be predicted based on the more accurate parent directory lifecycle indicator, thereby improving the accuracy of data block lifecycle prediction.
[0193] 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. They 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. Here, UNIX time refers to the total number of seconds from the Coordinated Universal Time to the present (excluding leap seconds). It is also necessary to record the frequency information of the file system allocating data blocks, 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 facilitates the subsequent calculation of the number of data blocks allocated by the file system from creation to deletion, and also facilitates the calculation of the actual life cycle indicator and the update cycle indicator, thereby facilitating the calculation of the predicted life cycle indicator.
[0194] The above-mentioned data block life prediction method enables electronic devices to predict the life of data blocks and understand the expected failure time of data blocks in advance, so as to plan the data block migration and recycling strategies in advance, realize forward-looking data block management, and significantly reduce the storage space management load of electronic devices.
[0195] 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, and the computer program code includes computer instructions. 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.
[0196] The present application also provides a chip system. Figure 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 via lines. For example, the interface circuit 1702 can be used to receive signals from other devices (such as the memory of an 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 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 components, which is not specifically limited in the embodiments of the present application.
[0197] 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-mentioned electronic device, the electronic device executes each step of the above-mentioned method embodiment.
[0198] The embodiment of the present application further provides a computer program product, which, when executed on a computer, enables the computer to execute each step of the above method embodiment.
[0199] 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.
[0200] In the several embodiments provided in this 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 merely schematic. For example, the division of the modules or units is merely a logical function division. In actual implementation, there may be other division methods, 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.
[0201] The units described as separate components may or may not be physically separate, 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 places. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0202] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0203] 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, 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 and includes several instructions for enabling a device (which can be a single-chip microcomputer, chip, etc.) or a 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.
[0204] The above content is only a specific embodiment of this application, but the scope of protection of this application is not limited to this. Any changes or replacements within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A storage space management method, characterized in that: include: Determining, based on a lifecycle indicator of a file to which a data block belongs in a file system, a predicted lifespan indicator for characterizing the lifespan of the data block; the predicted lifespan indicator is used to indicate an estimated number of data blocks allocated by the file system from the time the data block is written to the time it becomes invalid; and the file lifecycle indicator is used to indicate an estimated number of data blocks allocated by the file system from the time the file is created to the time it is deleted; Managing the storage space of the file system according to the predicted lifespan indicator of the data block; When a target object is deleted, the lifecycle indicator of the target object is updated according to the deletion timing indicator and creation timing indicator of the target object; wherein the target object is a file to which a data block belongs or a directory where the file is located; the deletion timing indicator is used to indicate the global cumulative number of blocks of the file system when the target object is deleted; and 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 allocated in the file system.
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 updated block, the predicted life index of the updated 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 of the updated block and its failure; The updating block and the updated block are data blocks in different storage locations, the data written by 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 by the updating block; or The data written into 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 the 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. In the case where 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 lifecycle indicator of a file is consistent with the lifecycle indicator of the directory where it resides, and the initial lifecycle indicator of a directory is consistent with the lifecycle indicator of the parent directory.
6. The storage space management method according to claim 5, characterized in that: After updating the lifecycle indicator of the target object, the method further includes: According to the updated lifecycle indicator of the target object, the lifecycle 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 lifecycle indicator of the parent directory of the target object according to the updated lifecycle indicator of the target object includes: Calculating the product of the lifecycle index of the parent directory of the target object and the number of files in the parent directory of the target object after being updated 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 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 updated lifecycle indicator of the parent directory.
10. The storage space management method according to claim 1, wherein: 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, and the data block life node includes 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, wherein: Managing the storage space of the file system according to the predicted lifespan indicator of the data block includes: A target data segment for garbage collection (GC) is selected based on the predicted lifespan index of each data block; 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) based on the predicted lifespan indicator 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; Obtaining an average remaining life indicator and a remaining life variance indicator of the data blocks in each candidate data segment according to the predicted life indicator of each data block; 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 candidate data segment.
15. The storage space management method according to claim 13, wherein: The step of selecting a target data segment for garbage collection (GC) based on the predicted lifespan indicator of each data block 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, wherein: Managing the storage space of the file system according to the predicted lifespan indicator of the data block includes: Classifying each of the data blocks 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, and the predicted life index of the hot data block is smaller 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.
17. The storage space management method according to claim 1, wherein: Managing the storage space of the file system according to the predicted lifespan indicator of the data block includes: For the data blocks in the cache, based on 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 primary storage medium.
18. An electronic device, characterized in that: The electronic device includes: one or more processors and a memory; the memory is coupled to the processor; the memory is used to store computer program code, and the computer program code includes computer instructions. 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 storing instructions, characterized in that: When the instructions are executed on an electronic device, the electronic device is caused to execute the method according to 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 perform the method according to any one of claims 1 to 17.
Citation Information
Patent Citations
Data storage method and device
CN115480707A