Data processing method, electronic equipment and storage medium
By erasing invalid data blocks in the target data segment of the electronic device and writing new data, the data recycling problem caused by fixed data blocks is solved, and the I/O performance and storage space utilization of the electronic device are improved.
Patent Information
- Application Number
- CN202311321883.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-12
- Publication Date
- 2025-04-15
AI Technical Summary
Due to the existence of fixed data blocks in the memory of electronic devices, the data segments that cannot be recovered during data recovery will increase, affecting the input/output performance.
When the remaining storage space of the electronic device is smaller than the spatial threshold and new data is written, a target data segment is obtained, which includes at least a fixed data block and an invalid data block, erase the data in the invalid data block, and write the new data into the erased invalid data block.
It reduces the number of data recycles in electronic devices, improves I/O performance and user experience, and optimizes the utilization of storage space.
Smart Images

Figure CN119828951A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of electronic devices, and in particular to a data processing method, an electronic device, and a storage medium. Background Art
[0002] With the widespread use of electronic devices, data management and storage have become increasingly important. The memory of electronic devices is usually used to store user data, application data, etc. Over time, the memory may accumulate a large amount of data, including invalid data that is no longer needed. However, when there is a fixed data block in the data segment corresponding to the wireless data block, the data segment cannot be recycled, which will cause more and more data segments that cannot be recycled by the memory, thereby affecting the input / output (I / O) performance of the electronic device. Summary of the invention
[0003] In order to overcome the problems existing in the related art, the present disclosure provides a data processing method, an electronic device, and a storage medium, which can reduce the number of times the electronic device recovers data and improve the I / O performance and user experience of the electronic device.
[0004] According to a first aspect of an embodiment of the present disclosure, a data processing method is provided, comprising at least:
[0005] When the remaining storage space of the electronic device is less than the space threshold and new data is written to the remaining storage space, obtaining a target data segment determined by the electronic device from the data segment to be recovered during data recovery; wherein the target data segment includes at least a fixed data block and an invalid data block; the data in the fixed data block cannot be operated during the data recovery process;
[0006] Erasing data in the invalid data block in the target data segment;
[0007] The new data is written into the invalid data block after erasure.
[0008] In some embodiments, the method further comprises:
[0009] During the data recovery process, storing data segment information of the target data segment determined from the to-be-recovered data segment in a data list;
[0010] The obtaining of the target data segment determined by the electronic device from the to-be-recovered data segment during data recovery includes:
[0011] The target data segment is obtained by searching from the data list.
[0012] In some embodiments, erasing the data in the invalid data block in the target data segment includes:
[0013] In the case where there are multiple target data segments, selecting at least one target data segment from the multiple target data segments as the erased data segment;
[0014] The data in the invalid data block in the erased data segment is erased.
[0015] In some embodiments, selecting at least one target data segment from the plurality of target data segments as the erased data segment comprises:
[0016] Arrange the target data segments in ascending order based on the number of invalid data blocks in each target data segment to obtain an ascending queue;
[0017] Based on the number of invalid data blocks occupied by the new data, at least one target data segment located at the head of the queue is selected from the ascending queue as the erased data segment.
[0018] In some embodiments, selecting at least one target data segment located at the head of the queue as the erased data segment from the ascending queue based on the number of invalid data blocks occupied by the new data includes:
[0019] When the number of invalid data blocks occupied by the new data is greater than the number of invalid data blocks in the target data segment at the head of the queue, multiple target data segments are selected in sequence from the head of the ascending queue as the erased data segments.
[0020] In some embodiments, the method further comprises:
[0021] Obtaining the number of valid data blocks in each candidate data segment in the electronic device;
[0022] At least one of the candidate data segments having the smallest number of valid data blocks is used as the data segment to be recycled.
[0023] In some embodiments, the method further comprises:
[0024] Obtaining a recycling cost of each candidate data segment in the electronic device;
[0025] At least one of the candidate data segments with the smallest recycling overhead is used as the data segment to be recycled.
[0026] According to a second aspect of an embodiment of the present disclosure, there is provided an electronic device, including:
[0027] The acquisition module is configured to acquire a target data segment determined by the electronic device from the data segment to be recovered during data recovery when the remaining storage space of the electronic device is less than a space threshold and new data is written to the remaining storage space; wherein the target data segment includes at least a fixed data block and an invalid data block; and the data in the fixed data block cannot be operated during the data recovery process;
[0028] an erasing module, configured to erase data in the invalid data block in the target data segment;
[0029] The writing module is configured to write the new data into the invalid data block after erasure.
[0030] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, including:
[0031] processor;
[0032] a memory for storing processor-executable instructions;
[0033] Wherein, the processor is configured to execute the data processing method as described in the first aspect above.
[0034] According to a fourth aspect of an embodiment of the present disclosure, there is provided a storage medium, including:
[0035] When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the data processing method as described in the first aspect above.
[0036] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:
[0037] In the embodiment of the present disclosure, when the remaining storage space of the electronic device is less than the space threshold and new data is written to the remaining storage space, the electronic device determines the target data segment from the data segment to be recovered during data recovery, erases the data in the invalid data block in the target data segment, and writes the new data into the invalid data block after erasure. In other words, the embodiment of the present disclosure writes new data into the target data segment, so that the target data segment does not need to be recovered, thereby reducing the number of times the electronic device recovers data, improving the I / O performance and user experience of the electronic device; and, writing new data into the invalid data block after erasure in the target data segment can reduce the waste of storage space of the target data segment and improve the space utilization rate of the electronic device.
[0038] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0040] Figure 1 It is a flowchart of a data processing method according to an exemplary embodiment.
[0041] Figure 2 It is a schematic diagram of data processing according to an exemplary embodiment.
[0042] Figure 3 is a schematic diagram of data writing according to an exemplary embodiment.
[0043] Figure 4 The figure is a schematic diagram of existing data recovery according to an exemplary embodiment.
[0044] Figure 5 The figure is a schematic diagram of data recovery of the present application according to an exemplary embodiment.
[0045] Figure 6 An electronic device frame is shown according to an exemplary embodiment Figure 1 .
[0046] Figure 7 An electronic device frame is shown according to an exemplary embodiment Figure 2 . DETAILED DESCRIPTION
[0047] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present disclosure. Instead, they are merely examples of data processing methods and electronic devices consistent with some aspects of the present disclosure as detailed in the appended claims.
[0048] The present disclosure provides a data processing method. Figure 1 is a flowchart of a data processing method according to an exemplary embodiment. Figure 1 ,like Figure 1 As shown, the data processing method comprises the following steps:
[0049] S101, when the remaining storage space of the electronic device is less than a space threshold and new data is written to the remaining storage space, obtaining a target data segment determined by the electronic device from the data segment to be recovered during data recovery; wherein the target data segment includes at least a fixed data block and an invalid data block; the data in the fixed data block cannot be operated during the data recovery process;
[0050] S102, erasing data in the invalid data block in the target data segment;
[0051] S103: Write the new data into the invalid data block after erasure.
[0052] In the disclosed embodiment, the data processing method is applied to an application scenario in which the file system of an electronic device performs data recovery (Garbage Collection, GC) on a data segment to be recovered. Since fixed data blocks will not be recovered, and data recovery is usually performed in units of data segments, even if the target data segment where the fixed data block is located includes invalid data blocks, it will not be recovered by the electronic device. Exemplarily, when there are multiple target data segments in the electronic device, that is, when the electronic device has too many data fragments, the electronic device can erase the data in the invalid data block of the target data segment by executing the data processing method, and write new data in the invalid data block after erasure, thereby eliminating the need for data recovery of the target data segment, so as to reduce the number of times the electronic device performs data recovery.
[0053] Here, the file system of the electronic device includes a Flash Friendly File System (F2FS). The electronic device can recycle the to-be-recycled data in the memory through the F2FS.
[0054] It should be noted that the electronic device may be a mobile terminal device, a smart home device, etc. Among them, the mobile terminal device may include a mobile phone or a tablet computer; the smart home device may include a television or a speaker device. The embodiments of the present disclosure are not limited to this.
[0055] In step S101, the electronic device monitors the remaining storage space of the memory, compares the remaining storage space with the space threshold, and monitors whether new data needs to be written into the remaining storage space. When it is detected that the remaining storage space is less than the space threshold and new data is written into the remaining storage space, the target data segment determined by the electronic device from the data segments to be recycled is obtained.
[0056] Exemplarily, the space threshold may be set according to actual conditions, such as 10% or 20%, etc., and the embodiment of the present disclosure is not limited thereto.
[0057] The data recovery process of the electronic device may include: first selecting a data segment to be recovered from candidate data segments; then migrating data in valid data blocks in the data segment to be recovered other than the target data segment; and finally marking the data segment to be recovered after the migration as available.
[0058] The above-mentioned obtaining of the target data segment determined by the electronic device from the data segment to be recovered during data recovery may include: determining whether the data segment to be recovered contains both fixed data blocks and invalid data blocks, and if so, determining the data segment to be recovered as the target data segment.
[0059] It should be noted that obtaining a target data segment from at least one data segment to be recovered of an electronic device may include: scanning the data segment to be recovered, and screening out multiple target data segments by checking the marks of fixed data blocks and invalid data blocks; or, adding data block information (such as data block location information) of the fixed data blocks and invalid data blocks of the data segment to be recovered to a directory, and determining the target data segment by searching the directory; or, using an automated algorithm or machine learning technology to analyze the fixed data blocks and invalid data blocks in the data segment to be recovered, and automatically identifying multiple target data segments.
[0060] The target data segment determined by the electronic device from the data segments to be recovered during data recovery may be one target data segment or multiple target data segments.
[0061] In addition to fixed data blocks and invalid data blocks, the target data segment may also include valid data blocks or blank data blocks. Here, the number of fixed data blocks and invalid data blocks in the target data segment may be one or more, which is not limited in the embodiment of the present disclosure.
[0062] It should be noted that, under normal circumstances, the total number of fixed data blocks, invalid data blocks, valid data blocks, and blank data blocks in a target data segment is at most 512, and the size of a valid data block is 4 kilobytes, that is, the size of a target data segment is 2 megabytes. The fixed data blocks, invalid data blocks, valid data blocks, and blank data blocks in a target data segment can be arbitrarily combined, and the embodiments of the present disclosure do not limit this.
[0063] The data in the fixed data block cannot be operated during the data recovery process. That is to say, during the data recovery process, the data in the fixed data block will not be erased or migrated, and the corresponding target data segment with the fixed data block cannot be recovered. It should be noted that the fixed data block in the target data segment is marked as pinned. When the number of times the target data segment is recovered exceeds a preset number of thresholds, the pinned mark will be cancelled, and the target data segment after the pinned mark is cancelled can be recovered.
[0064] The data in the invalid data block is data that is no longer needed or has been damaged. That is to say, in the data recovery process, the data in the invalid data block can be recovered. It should be noted that the invalid data block is marked as invalid, and when the electronic device recovers data, the data in the invalid data block will be recovered.
[0065] The data in the valid data block is the data that needs to be used or is being used. That is to say, during the data recovery process, the data in the valid data block does not need to be recovered. It should be noted that the valid data block is marked as valid, and when the electronic device recovers data, the data in the valid data block needs to be migrated to the blank data block.
[0066] A blank data block is a data block without data. It is understandable that a blank data block is formed when data in an invalid data block is erased or recycled.
[0067] In step S102, erasing the data in the invalid data block in the target data segment includes: allocating resources for the erasing operation; searching for the invalid data block in the target data segment based on the allocated resources; and erasing the data in the invalid data block by using an erasing algorithm.
[0068] The electronic device needs to erase invalid data blocks in at least one target data segment.
[0069] It should be noted that when the electronic device performs an erasing operation, the electronic device will suspend the ongoing input / output operation to ensure data consistency; after all data in the invalid data block is erased, the invalid data block will be restored to its initial state; the electronic device will update the data block information of the invalid data block and mark the erased invalid data block as available; after the erasing is completed, the electronic device will resume the input / output operation and continue normal operation.
[0070] In step 103, writing new data into the invalid data block after erasure includes: writing the new data into any at least one invalid data block after erasure; or, obtaining a sorted queue by sorting the target data segments where the invalid data blocks are located, and writing the new data into the invalid data blocks after erasure contained in the target data segments located at the head, the tail or the middle of the queue in the sorted queue in sequence.
[0071] It should be noted that, in the process of writing new data into the invalid data block after erasure, the electronic device will suspend the ongoing input / output operation to ensure data consistency; and after the new data is successfully written into the invalid data block after erasure, the data block information of the invalid data block after erasure where the new data is written will be updated, and the electronic device will resume the input / output operation and continue normal operation. The data block information includes the location and status of the new data.
[0072] In the disclosed embodiment, in the disclosed embodiment, when the remaining storage space of the electronic device is less than the space threshold and new data is written to the remaining storage space, the electronic device determines the target data segment from the data segment to be recovered during data recovery, erases the data in the invalid data block in the target data segment, and writes the new data into the invalid data block after erasure. In other words, the disclosed embodiment writes new data into the target data segment, so that the target data segment does not need to be recovered, thereby reducing the number of times the electronic device recovers data, improving the I / O performance and user experience of the electronic device; and, writing new data into the invalid data block after erasure in the target data segment can reduce the waste of storage space of the target data segment and improve the space utilization rate of the electronic device.
[0073] In one embodiment, during the data recovery process, data segment information of the target data segment determined from the to-be-recovered data segment is stored in a data list;
[0074] The obtaining of the target data segment determined by the electronic device from the to-be-recovered data segment during data recovery includes:
[0075] The target data segment is obtained by searching from the data list.
[0076] In the embodiment of the present disclosure, a data list is set in the electronic device. The data list may be an array, a linked list, a hash table or other data lists, which is not limited in the embodiment of the present disclosure.
[0077] Storing the data segment information of the target data segment determined from the data segments to be recovered in the data list includes: storing the data segment information of multiple target data segments in the data list at the same time; or, each time a target data segment is obtained, storing the data segment information of the target data segment in the data list.
[0078] Exemplarily, the electronic device obtains the first target data segment and the second target data segment in the data segment to be recovered, and stores the data segment information of the first target data segment and the second target data segment in the data list; or, the electronic device obtains the first target data segment in the data segment to be recovered, stores the data segment information of the first target data segment in the data list, and then, the electronic device obtains the second target data segment in the data segment to be recovered, and stores the data segment information of the second target data segment in the data list.
[0079] In the embodiment of the present disclosure, the data segment information may include a unique identifier, location, size or other data information of the target data segment, and the embodiment of the present disclosure is not limited to this.
[0080] Each piece of data segment information corresponds to a target data segment, and the location of the target data segment in the electronic device can be obtained based on the data segment information.
[0081] The data list can also be updated in real time according to the status of the electronic device. When the electronic device reads and writes data or performs data recovery operations, the invalid data blocks and fixed data blocks in the target data segment are updated; or the data segment information of the target data segment in the data list is updated.
[0082] Searching for the target data segment from the data list may be that the electronic device locates the target data segment corresponding to the data segment information according to a one-to-one correspondence between the data segment information and the target data segment.
[0083] In the disclosed embodiment, during the recovery process, the data segment information of the target data segment determined from the data segment to be recovered is stored in the data list, and the target data segment is found from the data list. That is, multiple target data segments are managed through the data list, which lays the foundation for the subsequent erasure of the invalid data blocks in the target data segment and the writing of new data. In addition, the data list makes it more convenient and timely to obtain the target data segment, thereby improving the efficiency of data processing.
[0084] In one embodiment, erasing the data in the invalid data block in the target data segment includes:
[0085] In the case where there are multiple target data segments, selecting at least one target data segment from the multiple target data segments as the erased data segment;
[0086] The data in the invalid data block in the erased data segment is erased.
[0087] In the embodiment of the present disclosure, one or more target data segments may be selected as erased data segments based on the types of data blocks included in the target data segments.
[0088] Exemplarily, in one embodiment, multiple target data segments can be selected as erased data segments based on the number of invalid data blocks in the target data segment; in another embodiment, multiple target data segments can also be selected as erased data segments based on the number of invalid data blocks and the number of blank data blocks in the target data segment.
[0089] It should be noted that, in the process of erasing the data in the invalid data block in the erased data segment, it is necessary to traverse each invalid data block in the erased data segment to determine the position of each invalid data block in the erased data segment; or, according to the position information of the invalid data block contained in the erased data segment, determine the position of each invalid data block in the erased data segment. Here, after the invalid data block is erased, a new blank data block is formed.
[0090] It is necessary to erase the data in each invalid data block in the erased data segment, which can reduce the situation of performing multiple erase operations on the erased data segment and improve the efficiency of data processing.
[0091] In the embodiment of the present disclosure, when there are multiple target data segments, at least one target data segment is selected from the multiple target data segments as the erased data segment. That is to say, the embodiment of the present disclosure is applicable to the scenario of erasing one or more target data segments, which not only expands the use scenarios of data recovery, but also can minimize data fragmentation in electronic devices by erasing data of invalid data blocks in multiple target data segments and writing new data.
[0092] In one embodiment, selecting at least one target data segment from the plurality of target data segments as the erased data segment comprises:
[0093] Arrange the target data segments in ascending order based on the number of invalid data blocks in each target data segment to obtain an ascending queue;
[0094] Based on the number of invalid data blocks occupied by the new data, at least one target data segment located at the head of the queue is selected from the ascending queue as the erased data segment.
[0095] In an embodiment of the present disclosure, the electronic device can traverse each target data segment of a plurality of target data segments and record the number of invalid data blocks of each target data segment; sort the plurality of target data segments in ascending order based on the number of invalid data blocks in each recorded target data segment; and store the data information of the target data segments in the ascending queue in a data list in the order of the ascending sorting.
[0096] Exemplarily, the target data segment includes a first target data segment, a second target data segment and a third target data segment, the number of invalid data blocks in the first target data segment is a first number, the number of invalid data blocks in the second target data segment is a second number, and the number of invalid data blocks in the third target data segment is a third number. When the third number is less than the second number, and the second number is less than the first number, the third target data segment is arranged at the head position of the ascending queue, the second target data segment is arranged at the middle position of the ascending queue, and the first target data segment is arranged at the tail position of the ascending queue. Here, the third target data segment can be used as an erased data segment.
[0097] It should be noted that when there are multiple target data segments with the smallest number of invalid data blocks, at least one target data segment with the smallest number of invalid data blocks can be selected as the erased data segment based on the number of invalid data blocks occupied by new data.
[0098] In the disclosed embodiment, the number of invalid data blocks occupied by new data and the number of invalid data blocks of the target data segment at the head of the queue in the ascending queue can be compared, and based on the comparison result, one or more target data segments at the head of the queue in the ascending queue can be selected as erased data segments.
[0099] It should be noted that when the comparison result is that the number of invalid data blocks occupied by the new data is greater than the number of invalid data blocks of the target data segment located at the head end of the queue in the ascending queue, multiple target data segments located at the head end of the queue are selected as erased data segments; when the comparison result is that the number of invalid data blocks occupied by the new data is less than or equal to the number of invalid data blocks of the target data segment located at the head end of the queue in the ascending queue, a target data segment located at the head end of the queue is selected as the erased data segment.
[0100] In an embodiment of the present disclosure, multiple target data segments are sorted in ascending order based on the number of invalid data blocks in each target data segment, and a target data segment is selected from the ascending queue as an erased data segment, which can improve the efficiency of the electronic device in performing erase operations on the erased data segments; and based on the number of invalid data blocks occupied by new data, at least one target data segment is selected from the ascending queue as an erased data segment, which can also improve the writing efficiency of the electronic device when subsequently writing new data.
[0101] In one embodiment, the selecting at least one target data segment located at the head of the queue from the ascending queue as the erased data segment based on the number of invalid data blocks occupied by the new data includes:
[0102] When the number of invalid data blocks occupied by the new data is greater than the number of invalid data blocks in the target data segment at the head of the queue, multiple target data segments are selected in sequence from the head of the ascending queue as the erased data segments.
[0103] In the disclosed embodiment, by comparing the number of invalid data blocks occupied by new data and the number of invalid data blocks in the target data segment located at the head of the queue, if the number of invalid data blocks occupied by the new data is greater than the number of invalid data blocks in the target data segment located at the head of the queue, multiple target data segments are selected in sequence starting from the head of the ascending queue as erased data segments.
[0104] Exemplarily, when new data is written to the storage space, 100 invalid data blocks are required, and the first target data segment at the head of the queue has only 40 invalid data blocks, then it is necessary to determine the number of invalid data blocks in the second target data segment from the ascending queue in sequence; if the number of invalid data blocks in the second target data segment is greater than or equal to 60, then the first target data segment and the second target data segment are selected as erased data segments; if the number of invalid data blocks in the second target data segment is greater than 40 and less than 60, then it is also necessary to select the third target data segment from the ascending queue, that is, the first target data segment, the second target data segment and the third target data segment are all erased data segments.
[0105] In the disclosed embodiment, if the number of invalid data blocks occupied by the new data is less than or equal to the number of invalid data blocks in the target data segment at the head end of the queue in the ascending queue, a target data segment at the head end of the queue is selected from the ascending queue as an erased data segment, and each invalid data block in the erased data segment is erased, and then the new data is written into the erased invalid data blocks in the erased data segment.
[0106] In the disclosed embodiment, different numbers of target data segments can be selected as erased data segments based on the comparison results between the number of invalid data occupied by new data and the number of invalid data blocks in the target data segment located at the head of the queue. This can make the selection method of the erased data segments more flexible, enable the electronic device to process the erased data segments more accurately, and better write new data in the invalid data blocks after erasure.
[0107] In one embodiment, the method further comprises:
[0108] Obtaining the number of valid data blocks in each candidate data segment in the electronic device;
[0109] At least one of the candidate data segments having the smallest number of valid data blocks is used as the data segment to be recycled.
[0110] In an embodiment of the present disclosure, the step of obtaining the number of valid data blocks in each candidate data segment in the electronic device may include: the electronic device traverses each candidate data segment, checks each data block in the candidate data segment, and calculates the number of valid data blocks.
[0111] The number of valid data blocks in the candidate data segment may be determined based on the data segment information of the candidate data segment or the identification information of different data blocks in the candidate data segment.
[0112] One or more candidate data segments with the smallest number of valid data blocks are selected from the candidate data segments as the data segments to be recycled.
[0113] Exemplarily, the candidate data segment includes a first candidate data segment, a second candidate data segment, and a third candidate data segment, the number of valid data blocks in the first candidate data segment is a first number, the number of valid data blocks in the second candidate data segment is a second number, and the number of valid data blocks in the third candidate data segment is a third number. When the first number is less than the second number, and the second number is less than the third number, the first candidate data segment is selected as a data segment to be recycled.
[0114] When there are multiple candidate data segments whose numbers of valid data blocks are all minimum, at least one candidate data segment among the multiple candidate data segments is selected as the data segment to be recovered.
[0115] It can be understood that when the number of valid data blocks is the smallest, when data recovery is performed on the data segments to be recovered, the electronic device needs to recover the smallest number of valid data blocks, that is, when the first number is less than the second number, the efficiency of data recovery for the data segments to be recovered with the first number of valid data blocks is higher than the efficiency of data recovery for the data segments to be recovered with the second number of valid data blocks.
[0116] In the disclosed embodiment, by selecting at least one candidate data segment with the smallest number of valid data blocks as the data segment to be recovered, the efficiency of the electronic device in recovering data from the data segment to be recovered is improved.
[0117] In one embodiment, the method further comprises:
[0118] Obtaining a recycling cost of each candidate data segment in the electronic device;
[0119] At least one of the candidate data segments with the smallest recycling overhead is used as the data segment to be recycled.
[0120] In the embodiment of the present disclosure, obtaining the recycling overhead of each candidate data segment in the electronic device includes: calculating it according to the proportion of valid data blocks in a candidate data segment and the time from the candidate data segment to the most recent modification.
[0121] It should be noted that, in a candidate data segment, the smaller the proportion of valid data blocks is, the smaller the number of data blocks that the electronic device needs to recycle when recovering the data segment to be recovered, that is, the smaller the recovery overhead of the candidate data segment is; and the longer the time between the candidate data segment and the most recent modification is, the less likely it is that the candidate data segment will be modified when data is recovered.
[0122] In one embodiment, the calculation method of the input-output ratio is shown in formula (1):
[0123] cost = (1-u) / 2u*age (1)
[0124] Among them, cost represents the input-output ratio, u represents the ratio of the number of valid data blocks in the candidate data segment, and age represents the length of time from the candidate data segment to the most recent modification time.
[0125] It can be understood that when the proportion of valid data blocks is the smallest and when the candidate data segment is the longest from its last modification time, the input-output ratio of the candidate data segment is the largest, that is, the recovery overhead of the candidate data segment is the smallest.
[0126] Exemplarily, the candidate data segment includes a first candidate data segment and a second candidate data segment, the ratio of valid data blocks in the first candidate data segment is a first ratio, and the time from the last modification is a first duration, and a first input-output ratio is calculated based on the first ratio and the first duration; the ratio of valid data blocks in the second candidate data segment is a second ratio, and the time from the last modification is a second duration, and a second input-output ratio is calculated based on the second ratio and the second duration. The electronic device compares the size of the input-output ratio, and when the first number is less than the second number and the first duration is greater than the second duration, the first input-output ratio is greater than the second input-output ratio, then the recovery overhead of the first candidate data segment is less than that of the second candidate data segment, and the first candidate data segment is selected as the data segment to be recovered.
[0127] In the embodiment of the present disclosure, by selecting at least one candidate data segment with the smallest recovery overhead as the data segment to be recovered, the efficiency of the electronic device in performing data recovery on the data segment to be recovered is improved.
[0128] In order to better understand one or more of the above embodiments, an example of a data processing method according to an embodiment of the present disclosure is as follows:
[0129] like Figure 2As shown, before data recovery, the electronic device selects three data segments to be recovered for data recovery, wherein data segment 1 to be recovered includes valid data block A, valid data block B and two invalid data blocks; data segment 2 to be recovered includes fixed data block C, fixed data block D and two invalid data blocks; data segment 3 to be recovered includes valid data block E, valid data block F and two invalid data blocks.
[0130] The data segment 2 to be recovered includes fixed data blocks and invalid data blocks. Therefore, the data segment 2 to be recovered is determined as the target data segment 2, and the data segment information of the target data segment 2 is stored in the data list.
[0131] After a data recovery operation is performed on the file system of the electronic device, the valid data blocks A and B in the data segment 1 to be recovered are migrated into the blank data segment 4 by means of an off-site update, and the migrated data segment 1 to be recovered is subjected to data recovery to become a blank data segment 1; similarly, the valid data blocks E and F in the data segment 3 to be recovered are migrated into the blank data segment 4 by means of an off-site update, and the migrated data segment 3 to be recovered is subjected to data recovery to become a blank data segment 3; at this time, the blank data segment becomes the valid data segment 4, and the valid data segment 4 includes the valid data blocks A, B, E and F.
[0132] Since the target data segment 2 includes fixed data blocks, the data in the fixed data blocks cannot be operated during this data recovery process. Therefore, data recovery is not performed on the target data segment 2.
[0133] like Figure 3 As shown, when the remaining storage space of the electronic device is less than 10%, the target data segment 2 is selected from the data list, and the data in the two invalid data blocks in the target data segment 2 are erased, and the new data is written into the invalid data blocks after erasure. Then, the target data segment 2 becomes the valid data segment 2 after the new data is written, and the valid data segment 2 includes the fixed data block C, the fixed data block D, the valid data block K and the valid data block L.
[0134] like Figure 4As shown, before the optimization of the data processing method of the present application, when new data needs to be written, the new data will be written into the valid data segment 1, and the valid data segment 1 includes valid data block K, valid data block L, valid data block I and valid data block J; the data segment 2 to be recovered includes fixed data segment C, fixed data block D and two invalid data blocks; the data segment 3 to be recovered includes valid data block G, valid data block H and two invalid data blocks. At this time, after one data processing, the valid data block G and the valid data block H in the data segment 3 to be recovered will be migrated to the blank data segment 4, so that the blank data segment 4 becomes the valid data segment 4. The valid data segment 1 will not be data recovered, and the data segment 2 to be recovered will not be data recovered because it includes fixed data blocks.
[0135] Alternatively, after multiple data recycling processes, the fixed data block C and the fixed data block D cancel their fixed state. At this time, the data block C and the data block D can be recycled, that is, the data block C and the data block D in the data segment 2 to be recycled are migrated to the blank data segment 5 and form a valid data segment 5 with other valid data blocks.
[0136] like Figure 5 As shown, after the optimization of the data processing method of the present application, when data needs to be written, the data will be written into the target data segment 2, and the fixed data segment C, fixed data block D, valid data block K and valid data block L in the target data segment 2 constitute the valid data segment 2. At this time, only one data processing is needed, and the valid data block I and the valid data block J in the data segment 1 to be recovered will be migrated to the blank data segment 4, and the valid data block G and the valid data block H in the data segment 3 to be recovered will be migrated to the blank data segment 4, and the valid data block I, the valid data block J, the valid data block G and the valid data block H together constitute the valid data segment 4, the data segment 1 to be recovered will become the blank data segment 1, and the data segment 3 to be recovered will become the blank data segment 3.
[0137] It is understandable that after optimization of the data processing method of the present application, only one data recovery is required to obtain two blank data segments for writing new data, while the existing technology under the same conditions can only obtain one blank data segment, or the effect of the present application can only be achieved after multiple data recovery.
[0138] Therefore, through the data processing method of the embodiment of the present disclosure, the target data segment can be obtained from the data segment to be recovered, and when the remaining storage space of the electronic device is less than the space threshold and new data is written to the remaining storage space, the data in the invalid data block in the target data segment is erased, and the new data is written into the invalid data block after erasure. In other words, the embodiment of the present disclosure writes new data into the target data segment, so that the target data segment does not need to be data recovered, thereby reducing the number of data recovery of the electronic device and improving the I / O performance and user experience of the electronic device; and, writing new data into the invalid data block after erasure in the target data segment can reduce the waste of storage space of the target data segment and improve the space utilization rate of the electronic device.
[0139] The present disclosure provides an electronic device, Figure 6 An electronic device frame is shown according to an exemplary embodiment Figure 1 ,like Figure 6 As shown, the electronic device 1000 includes:
[0140] The first acquisition module 1001 is configured to acquire a target data segment determined by the electronic device from the to-be-reclaimed data segment during data recycling when the remaining storage space of the electronic device is less than a space threshold and new data is written to the remaining storage space; wherein the target data segment includes at least a fixed data block and an invalid data block; and the data in the fixed data block cannot be operated during the data recycling process;
[0141] An erasing module 1002 is configured to erase data in the invalid data block in the target data segment;
[0142] The writing module 1003 is configured to write the new data into the invalid data block after erasure.
[0143] In some embodiments, the electronic device further comprises:
[0144] A storage module is configured to store data segment information of the target data segment determined from the to-be-reclaimed data segments in a data list during the data recovery process;
[0145] The first acquisition module is further configured to search for the target data segment from the data list.
[0146] In some embodiments, the erasure module is further configured to select at least one target data segment from the multiple target data segments as an erased data segment when there are multiple target data segments; and erase the data in the invalid data block in the erased data segment.
[0147] In some embodiments, the erasure module is further configured to arrange the multiple target data segments in ascending order based on the number of invalid data blocks in each target data segment to obtain an ascending queue; and based on the number of data blocks occupied by the new data, select at least one target data segment located at the head of the queue from the ascending queue as the erased data segment.
[0148] In some embodiments, the erasure module is further configured to select multiple target data segments in sequence starting from the head position of the ascending queue as the erased data segments when the number of invalid data blocks occupied by the new data is greater than the number of invalid data blocks in the target data segment located at the head position of the queue.
[0149] In some embodiments, the electronic device further comprises:
[0150] A second acquisition module is configured to acquire the number of valid data blocks in each candidate data segment in the electronic device;
[0151] The first selection module is configured to select at least one of the candidate data segments with the smallest number of valid data blocks as the data segment to be recycled.
[0152] In some embodiments, the electronic device further comprises:
[0153] A third acquisition module is configured to acquire a recycling cost of each candidate data segment in the electronic device;
[0154] The second selection module is configured to select at least one of the candidate data segments with the smallest recovery overhead as the data segment to be recovered.
[0155] The specific manner in which each module in the electronic device in the above embodiment performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0156] Figure 7 An electronic device frame is shown according to an exemplary embodiment Figure 2 For example, the electronic device 1000 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, and the like.
[0157] Reference Figure 7 , the electronic device 1000 may include one or more of the following components: a processing component 802 , a memory 804 , a power component 806 , a multimedia component 808 , an audio component 810 , an input / output (I / O) interface 812 , a sensor component 814 , and a communication component 816 .
[0158] The processing component 802 generally controls the overall operation of the electronic device 1000, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 802 may include one or more modules to facilitate the interaction between the processing component 802 and other components. For example, the processing component 802 may include a multimedia module to facilitate the interaction between the multimedia component 808 and the processing component 802.
[0159] The memory 804 is configured to store various types of data to support operations on the electronic device 1000. Examples of such data include instructions for any application or method operating on the electronic device 1000, contact data, phone book data, messages, pictures, videos, etc. The memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0160] The power supply component 806 provides power to various components of the electronic device 1000. The power supply component 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 1000.
[0161] The multimedia component 808 includes a screen that provides an output interface between the electronic device 1000 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front camera and / or a rear camera. When the device 800 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0162] The audio component 810 is configured to output and / or input audio signals. For example, the audio component 810 includes a microphone (MIC), and when the electronic device 1000 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 804 or sent via the communication component 816. In some embodiments, the audio component 810 also includes a speaker for outputting audio signals.
[0163] I / O interface 812 provides an interface between processing component 802 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0164] The sensor assembly 814 includes one or more sensors for providing various aspects of status assessment for the electronic device 1000. For example, the sensor assembly 814 can detect the open / closed state of the device 800, the relative positioning of components, such as the display and keypad of the electronic device 1000, and the sensor assembly 814 can also detect the position change of the electronic device 1000 or a component of the electronic device 1000, the presence or absence of user contact with the electronic device 1000, the orientation or acceleration / deceleration of the electronic device 1000, and the temperature change of the electronic device 1000. The sensor assembly 814 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 814 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0165] The communication component 816 is configured to facilitate wired or wireless communication between the electronic device 1000 and other devices. The electronic device 1000 can access a wireless network based on a communication standard, such as WiFi, 3G or 5G, or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0166] In an exemplary embodiment, the electronic device 1000 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.
[0167] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 804 including instructions, and the instructions can be executed by the processor 820 of the electronic device 1000 to complete the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0168] A non-temporary computer-readable storage medium, when the instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to execute a data processing method, the method comprising: when the remaining storage space of the electronic device is less than a space threshold and new data is written to the remaining storage space, obtaining a target data segment determined by the electronic device from a data segment to be recovered during data recovery; wherein the target data segment includes at least a fixed data block and an invalid data block; the data in the fixed data block cannot be operated during the data recovery process; erasing the data in the invalid data block in the target data segment; and writing the new data into the invalid data block after erasure.
[0169] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0170] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A data processing method, characterized in that: include: When the remaining storage space of the electronic device is less than the space threshold and new data is written to the remaining storage space, obtaining a target data segment determined by the electronic device from the data segment to be recovered during data recovery; wherein the target data segment includes at least a fixed data block and an invalid data block; the data in the fixed data block cannot be operated during the data recovery process; Erasing data in the invalid data block in the target data segment; The new data is written into the invalid data block after erasure.
2. The method according to claim 1, characterized in that The method further comprises: During the data recovery process, storing data segment information of the target data segment determined from the to-be-recovered data segment in a data list; The obtaining of the target data segment determined by the electronic device from the to-be-recovered data segment during data recovery includes: The target data segment is obtained by searching from the data list.
3. The method according to claim 1 or 2, characterized in that: Erasing the data in the invalid data block in the target data segment includes: In the case where there are multiple target data segments, selecting at least one target data segment from the multiple target data segments as the erased data segment; The data in the invalid data block in the erased data segment is erased.
4. The method according to claim 3, characterized in that The selecting at least one target data segment from the plurality of target data segments as the erased data segment comprises: Arrange the target data segments in ascending order based on the number of invalid data blocks in each target data segment to obtain an ascending queue; Based on the number of invalid data blocks occupied by the new data, at least one target data segment located at the head of the queue is selected from the ascending queue as the erased data segment.
5. The method according to claim 4, characterized in that The selecting, based on the number of data blocks occupied by the new data, at least one target data segment located at the head end of the queue from the ascending queue as the erased data segment comprises: When the number of invalid data blocks occupied by the new data is greater than the number of invalid data blocks in the target data segment at the head position, multiple target data segments are selected in sequence from the head position of the ascending queue as the erased data segments.
6. The method according to claim 1 or 2, characterized in that: The method further comprises: Acquire the number of valid data blocks in each candidate data segment in the electronic device; At least one of the candidate data segments having the smallest number of valid data blocks is used as the data segment to be recycled.
7. The method according to claim 1 or 2, characterized in that: The method further comprises: Obtaining a recycling cost of each candidate data segment in the electronic device; At least one of the candidate data segments with the smallest recycling overhead is used as the data segment to be recycled.
8. An electronic device, characterized in that: include: The acquisition module is configured to acquire a target data segment determined by the electronic device from the to-be-reclaimed data segment during data recycling when the remaining storage space of the electronic device is less than a space threshold and new data is written to the remaining storage space; wherein the target data segment includes at least a fixed data block and an invalid data block; and the data in the fixed data block cannot be operated during the data recycling process; an erasing module, configured to erase data in the invalid data block in the target data segment; The writing module is configured to write the new data into the invalid data block after erasure.
9. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to execute the data processing method according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the data processing method as claimed in any one of claims 1 to 7.
Citation Information
Cited By
Data management method, electronic device, storage medium and computer program product
CN120891984A