Physical block recovery method, device and equipment and computer readable storage medium
By obtaining the status information of the F2FS file system and the information of the physical blocks to be recycled, the virtual physical blocks in the file system are recycled, which solves the problem of file system performance degradation caused by virtual occupation and ensures the stability and performance of the system.
Patent Information
- Application Number
- CN202411563247.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-04
- Publication Date
- 2025-03-14
AI Technical Summary
The F2FS file system will cause a large number of physical blocks to be occupied when the user writes/deletes. If it is not recycled in time, it will cause the file system performance to become worse.
By obtaining the status information of the target file system, it is determined whether physical block recycling is needed. If necessary, the number and location information of the physical blocks to be recycled are obtained, and the physical block to be recycled is erased based on this information for recycling.
It realizes automatic recycling of virtual physical blocks in the F2FS file system, ensures the write and deletion performance of the file system, avoids performance deterioration, and ensures that users do not lag when using the device for a long time.
Smart Images

Figure CN119621601A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a physical block recovery method, device, equipment and computer-readable storage medium. Background Art
[0002] F2FS (Flash Friendly File System) is a new open source flash file system designed specifically for NAND-based storage devices. With the popularity of mobile phones, TVs and other terminal devices, more and more devices are equipped with F2FS file system. When users write / delete the F2FS file system of terminal devices, a large number of physical blocks will be virtual occupied. If these physical blocks virtual occupied by invalid data are not recovered in time, the performance of F2FS file system will deteriorate. Summary of the invention
[0003] The embodiments of the present application provide a physical block recovery method, apparatus, device and computer-readable storage medium, which can automatically recover virtual occupied physical blocks in a target file system to ensure the write and delete performance of the target file system.
[0004] The technical solution adopted by the present invention to solve the problem is as follows:
[0005] On the one hand, the present application provides a physical block recovery method, comprising:
[0006] Get the status information of the target file system;
[0007] Based on the status information, determine whether the target file system needs to reclaim physical blocks;
[0008] If the target file system needs to recycle physical blocks, obtain a first number of physical blocks to be reclaimed and position information of the physical blocks to be reclaimed in the target file system;
[0009] The physical block to be reclaimed is erased based on the first quantity and the position information to reclaim the physical block to be reclaimed.
[0010] In some embodiments of the present application, the state information includes a second number of input / output operations and / or storage capacity, and determining whether the target file system needs to reclaim physical blocks based on the state information includes:
[0011] comparing the second quantity to a quantity threshold;
[0012] If the second number is greater than or equal to the number threshold, obtaining type information of the input and output operations;
[0013] Based on the type information, determine whether the target file system needs to reclaim physical blocks.
[0014] In some embodiments of the present application, determining whether the target file system needs to reclaim physical blocks based on the type information includes:
[0015] Based on the type information of the input / output operation, determining whether the input / output operation is of a preset type;
[0016] If the input / output operation is not of the preset type, it is determined that the target file system needs to reclaim physical blocks.
[0017] In some embodiments of the present application, after comparing the second quantity with the quantity threshold, the method further comprises:
[0018] If the second quantity is less than the quantity threshold, comparing the storage capacity with the capacity threshold;
[0019] If the storage capacity is less than the capacity threshold, it is determined that the target file system needs to reclaim physical blocks.
[0020] In some embodiments of the present application, the physical blocks to be reclaimed include multiple physical blocks, and the multiple physical blocks to be reclaimed are erased by the recovery thread. The physical blocks to be reclaimed are erased based on the first quantity and position information, including:
[0021] Based on the first number, determining an operation cycle of the recycling thread;
[0022] Determine the recycling priorities of multiple physical blocks to be recycled based on the location information;
[0023] The control recovery thread performs erasing processing on a plurality of physical blocks to be recovered based on an operation cycle and a recovery priority.
[0024] In some embodiments of the present application, determining the operation cycle of the recycling thread based on the first quantity includes:
[0025] Obtaining a third number and a preset time; the third number is the number of physical blocks that do not need to be recycled in the target file system;
[0026] Adding the first quantity and the third quantity to obtain a fourth quantity;
[0027] Dividing the first quantity and the fourth quantity to obtain a quantity ratio value;
[0028] The preset time and the quantity ratio value are divided to obtain the operation cycle of the recycling thread.
[0029] In some embodiments of the present application, based on the location information, determining the recycling priorities of multiple physical blocks to be recycled includes:
[0030] Based on the location information, determine distance information between multiple physical blocks to be recycled;
[0031] Based on the distance information and the block sizes of the multiple physical blocks to be reclaimed, the reclaiming priorities of the multiple physical blocks to be reclaimed are determined.
[0032] In a second aspect, an embodiment of the present invention further provides a physical block recovery device, comprising:
[0033] A first acquisition module, used to acquire status information of a target file system;
[0034] An information determination module, used to determine whether the target file system needs to reclaim physical blocks based on the status information;
[0035] A second acquisition module is used to acquire a first number of physical blocks to be reclaimed and position information of the physical blocks to be reclaimed in the target file system if the target file system needs to reclaim physical blocks;
[0036] The erasing processing module is used to perform an erasing process on the physical block to be reclaimed based on the first quantity and position information, so as to reclaim the physical block to be reclaimed.
[0037] In a third aspect, the present application further provides a computer device, the computer device comprising:
[0038] one or more processors;
[0039] Memory; and
[0040] One or more application programs, wherein the one or more application programs are stored in a memory and configured to be executed by a processor to implement any one of the physical block reclaiming methods in the first aspect.
[0041] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, and the computer program is loaded by a processor to execute the steps in any one of the physical block recycling methods in the first aspect.
[0042] The beneficial effects of the present invention include determining whether a target file system needs to recycle physical blocks based on status information; if the target file system needs to recycle physical blocks, erasing the physical blocks to be reclaimed based on the first number of physical blocks to be reclaimed and position information of the physical blocks to be reclaimed in the target file system; automatically reclaiming the virtually occupied physical blocks in the target file system based on the status information of the target file system and the number and position distribution of the virtually occupied physical blocks, thereby ensuring the write and delete performance of the target file system, and further ensuring that users can use the device for a long time without lag. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0044] Figure 1 is a schematic diagram of a scenario of a physical block recycling system provided by an embodiment of the present invention;
[0045] Figure 2 is a flow chart of a physical block recovery method provided by an embodiment of the present invention;
[0046] Figure 3 It is a flowchart of a specific embodiment of determining whether a target file system needs to reclaim physical blocks provided by an embodiment of the present invention;
[0047] Figure 4 It is a schematic diagram of a specific embodiment flow of erasing a physical block to be recovered provided by an embodiment of the present invention;
[0048] Figure 5 is a principle block diagram of a physical block recovery device provided by an embodiment of the present invention;
[0049] Figure 6 It is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0050] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0051] In the description of the present application, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present application. In addition, the terms "first", "second", "third" and the like are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, features defined as "first", "second", "third" and the like may explicitly or implicitly include one or more of the said features.
[0052] In this application, the word "exemplary" is used to mean "used as an example, illustration, or description." Any embodiment described in this application as "exemplary" is not necessarily to be construed as being preferred or advantageous over other embodiments. The following description is given to enable any technician in the field to implement and use the present application. In the following description, details are listed for the purpose of explanation. It should be understood that a person of ordinary skill in the art can recognize that the present application can be implemented without using these specific details. In other instances, well-known structures and processes will not be elaborated in detail to avoid obscuring the description of the present application with unnecessary details. Therefore, the present application is not intended to be limited to the embodiments shown, but is consistent with the widest scope consistent with the principles and features disclosed in the present application.
[0053] It should be noted that since the method of the embodiment of the present application is executed in a computer device, the processing objects of each computer device exist in the form of data or information. For example, time is actually time information. It can be understood that if size, quantity, position, etc. are mentioned in subsequent embodiments, they are all corresponding data for processing by the computer device. The details will not be repeated here.
[0054] The embodiments of the present application provide a physical block recovery method, apparatus, device, and computer-readable storage medium, which are described in detail below.
[0055] See also Figure 1 , Figure 1 Schematic diagram of a scenario of a physical block recycling system provided in an embodiment of the present application. The physical block recycling system may include a computer device 100, in which a physical block recycling device is integrated. Figure 1 Computer equipment in.
[0056] In the embodiment of the present application, the computer device 100 is mainly used to obtain the status information of the target file system; based on the status information, determine whether the target file system needs to recycle physical blocks; if the target file system needs to recycle physical blocks, obtain the first number of physical blocks to be recycled and the position information of the physical blocks to be recycled in the target file system; based on the first number and the position information, erase the physical blocks to be recycled, and automatically recycle the virtually occupied physical blocks in the target file system based on the status information of the target file system and the number and position distribution of the virtually occupied physical blocks, so as to ensure the write and delete performance of the target file system, thereby ensuring that the user can use the device for a long time without lag.
[0057] In the embodiment of the present application, the computer device 100 may be an independent server, or a server network or server cluster composed of servers. For example, the computer device 100 described in the embodiment of the present application includes but is not limited to a computer, a network host, a single network server, a plurality of network server sets or a cloud server composed of a plurality of servers. The cloud server is composed of a large number of computers or network servers based on cloud computing.
[0058] It is understandable that the computer device 100 used in the embodiments of the present application may be a device including both receiving and transmitting hardware, that is, a device having receiving and transmitting hardware capable of performing two-way communication on a two-way communication link. Such a device may include: a cellular or other communication device having a single-line display or a multi-line display or a cellular or other communication device without a multi-line display. The specific computer device 100 may be a desktop terminal or a mobile terminal, and the computer device 100 may also be one of a smart TV, a mobile phone, a tablet computer, a laptop computer, etc.
[0059] Those skilled in the art will understand that Figure 1 The application environment shown in the figure is only one application scenario of the present application solution and does not constitute a limitation on the application scenario of the present application solution. Other application environments may also include Figure 1 More or less computer equipment as shown in Figure 1 Only one computer device is shown in the figure. It can be understood that the physical block recycling system can also include one or more other services, which are not limited here.
[0060] In addition, if Figure 1 As shown, the physical block recycling system may further include a memory 200 for storing data, such as status information, such as a second quantity, storage capacity, etc., such as threshold information, such as a quantity threshold, a capacity threshold, etc.
[0061] It should be noted that Figure 1The scenario diagram of the physical block recovery system shown is only an example. The physical block recovery system and scenario described in the embodiment of the present application are intended to more clearly illustrate the technical solution of the embodiment of the present application, and do not constitute a limitation on the technical solution provided in the embodiment of the present application. Ordinary technicians in this field can know that with the evolution of the physical block recovery system and the emergence of new business scenarios, the technical solution provided in the embodiment of the present application is also applicable to similar technical problems.
[0062] First, a physical block recovery method is provided in an embodiment of the present application. The execution subject of the physical block recovery method is a physical block recovery device. The physical block recovery device is applied to a computer device. The physical block recovery method includes: obtaining status information of a target file system; based on the status information, determining whether the target file system needs to perform physical block recovery; if the target file system needs to perform physical block recovery, obtaining a first number of physical blocks to be recovered and position information of the physical blocks to be recovered in the target file system; and erasing the physical blocks to be recovered based on the first number and the position information to recover the physical blocks to be recovered.
[0063] like Figure 2 FIG. 2 is a flow chart of an embodiment of a physical block recycling method in an embodiment of the present application. The physical block recycling method may include the following steps S201 to S204, which are as follows:
[0064] Step S201: Obtain status information of the target file system.
[0065] In this embodiment, the target file system is a system that needs to recycle physical blocks. The target file system may be an F2FS file system. The F2FS file system is a new open source flash file system designed based on a storage device. Writing / deleting operations on the F2FS file system may cause a large number of virtual physical block occupation problems. If these virtual physical blocks are not recycled in time, the performance of the F2FS file system may deteriorate as users use it for a long time.
[0066] In a specific embodiment, the status information of the target file system may include a second number of input / output (IO) operations of the target file system, and / or the storage capacity of the target file system. The second number may indicate whether the target file system is busy. If the second number is greater than or equal to a number threshold, it indicates that the target file system is busy; conversely, if the second number is less than the number threshold, it indicates that the target file system is not busy. The storage capacity is the read-only memory (ROM) capacity of the target file system. The storage capacity indicates the available storage space of the read-only memory of the target file system. If the storage capacity is greater than or equal to the capacity threshold, it indicates that the ROM capacity of the target file system is sufficient; conversely, if the storage capacity is less than the capacity threshold, it indicates that the ROM capacity of the target file system is insufficient.
[0067] Step S202: Based on the status information, determine whether the target file system needs to reclaim physical blocks.
[0068] In a specific embodiment, a physical block represents a physical area for storing data on a target file system. By obtaining status information of the target file system and determining whether the target file system needs to recycle physical blocks based on the status information, when it is determined that the target file system needs to recycle physical blocks, the physical blocks to be reclaimed in the target file system are reclaimed. Automatic recycling of virtual occupied physical blocks in the target file system can be achieved based on the status information, thereby ensuring the write and delete performance of the target file system.
[0069] Step S203: If the target file system needs to reclaim physical blocks, obtain the first number of physical blocks to be reclaimed and the location information of the physical blocks to be reclaimed in the target file system.
[0070] In a specific embodiment, the write / delete operation on the target file system will cause the target file system to generate a large number of virtual occupied physical blocks, which means that the physical blocks that should have been used to store valid data are occupied by invalid data. The physical blocks to be recovered are the physical blocks occupied by invalid data in the target file system. Recycling the physical blocks to be recovered can avoid the performance degradation of the target file system caused by virtual occupation of physical blocks, and improve the performance stability of the target file system.
[0071] Further, the first number is the number of physical blocks to be reclaimed in the target file system, the location information is the block address of the physical block to be reclaimed in the target file system, and the location information of each physical block to be reclaimed directly corresponds to a specific storage location in the physical memory. In a specific embodiment, the target file system is an F2FS file system, and the F2FS file system maintains an important structure discard_cmd_control. The location information of the physical blocks to be reclaimed can be obtained through the start and len member variables of the discard_cmd_control structure, and the first number of physical blocks to be reclaimed can be obtained through the undiscard_blks field of the discard_cmd_control structure.
[0072] Step S204: Erasing the physical block to be reclaimed based on the first quantity and position information to reclaim the physical block to be reclaimed.
[0073] In this embodiment, erasing the physical blocks to be reclaimed refers to clearing the data of the physical blocks to be reclaimed. By erasing the physical blocks to be reclaimed based on the first quantity and position information, the physical blocks to be reclaimed can be reclaimed based on the impact and urgency of the physical blocks to be reclaimed on the target file system, thereby improving the performance stability of the target file system.
[0074] In addition, when writing data to a physical block in the target file system, it is usually necessary to first erase the physical block and then write the data into the physical block. This embodiment determines whether the target file system needs to recycle the physical block based on the status information. When the target file system needs to recycle the physical block, the physical block to be reclaimed is erased based on the first number of physical blocks to be reclaimed and the position information of the physical blocks to be reclaimed in the target file system. The physical block can be erased in advance, thereby improving the data writing speed.
[0075] In a specific implementation, the state information includes a second number of input / output operations and / or storage capacity, referring to Figure 3 As shown, in the above step S202, determining whether the target file system needs to reclaim physical blocks based on the status information may include steps S301-S305, which are specifically as follows:
[0076] S301: Compare the second quantity with a quantity threshold.
[0077] In a specific embodiment, the quantity threshold is a preset threshold used to measure whether the target file system is busy. If the second quantity is greater than or equal to the quantity threshold, it indicates that the target file system is busy; conversely, if the second quantity is less than the quantity threshold, it indicates that the target file system is not busy.
[0078] S302: If the second number is greater than or equal to the number threshold, obtain type information of the input and output operations.
[0079] In a specific embodiment, the type information of the input / output operation can characterize the operation type of the input / output operation. If the second number is greater than or equal to the number threshold, the type information of the input / output operation is further obtained to determine whether the target file system needs to perform physical block recovery based on the operation type of the input / output operation.
[0080] S303: Determine whether the target file system needs to reclaim physical blocks based on the type information.
[0081] In a specific embodiment, the above-mentioned step of determining whether the target file system needs to reclaim physical blocks based on the type information specifically includes: determining whether the input / output operation is of a preset type based on the type information of the input / output operation; if the input / output operation is not of the preset type, determining that the target file system needs to reclaim physical blocks.
[0082] In some embodiments, the preset type is a user interaction type. When the input / output operation is not of the preset type, that is, the input / output operation is not of the user interaction type, it is determined that the target file system needs to perform physical block recovery. Conversely, when the input / output operation is of the preset type, that is, the input / output operation is of the user interaction type, in order to avoid physical block recovery affecting user use of the device, it is determined that the target file system does not need to perform physical block recovery.
[0083] S304: If the second quantity is less than the quantity threshold, compare the storage capacity with the capacity threshold.
[0084] In some embodiments, the capacity threshold is a pre-set threshold used to measure whether the ROM capacity of the target file system is sufficient. If the storage capacity is greater than or equal to the capacity threshold, it indicates that the ROM capacity of the target file system is sufficient; conversely, if the storage capacity is less than the capacity threshold, it indicates that the ROM capacity of the target file system is insufficient.
[0085] In a specific embodiment, if the second number is less than the number threshold, indicating that the target file system is not busy, the storage capacity is further compared with the capacity threshold to determine whether the ROM capacity of the target file system is sufficient.
[0086] S305: If the storage capacity is less than the capacity threshold, determine that the target file system needs to reclaim physical blocks.
[0087] In a specific embodiment, if the storage capacity is less than the capacity threshold, that is, the ROM capacity of the target file system is insufficient, it is determined that the target file system needs to recycle physical blocks to avoid the performance degradation of the target file system caused by virtual occupation of physical blocks, and improve the performance stability of the target file system. On the contrary, if the storage capacity is greater than or equal to the capacity threshold, that is, the ROM capacity of the target file system is sufficient, it is determined that the target file system does not need to recycle physical blocks.
[0088] In a specific implementation, the physical blocks to be recycled include multiple physical blocks, and the multiple physical blocks to be recycled are erased by the recycling thread. Figure 4 As shown, the above step S204 performs erasing processing on the physical block to be recovered based on the first quantity and position information, which may include steps S401-S403, which are specifically as follows:
[0089] S401. Determine an operation cycle of a recovery thread based on a first quantity.
[0090] In a specific embodiment, based on the first quantity, the step of determining the operating cycle of the recovery thread specifically includes: obtaining a third quantity and a preset time; adding the first quantity and the third quantity to obtain a fourth quantity; dividing the first quantity and the fourth quantity to obtain a quantity ratio value; dividing the preset time and the quantity ratio value to obtain the operating cycle of the recovery thread.
[0091] In some embodiments, the third number is the number of physical blocks that do not need to be reclaimed in the target file system. The process of determining the operation cycle can be expressed as: T = t / (S 1 / (S1+S2) ), wherein T represents the operation cycle, S1 represents the first quantity, S2 represents the third quantity, and t represents the preset time, which can be set according to actual needs.
[0092] S402: Determine the recycling priorities of multiple physical blocks to be recycled based on the location information.
[0093] In a specific embodiment, the recycling priorities of the multiple physical blocks to be recycled represent the recycling order of the multiple physical blocks to be recycled, and the higher the priority of the physical blocks to be recycled, the earlier they are recycled, and the lower the priority of the physical blocks to be recycled, the later they are recycled. The above-mentioned step of determining the recycling priorities of the multiple physical blocks to be recycled based on the position information may include: determining the distance information between the multiple physical blocks to be recycled based on the position information; determining the recycling priorities of the multiple physical blocks to be recycled based on the distance information and the block sizes of the multiple physical blocks to be recycled.
[0094] In this embodiment, the distance information represents the position offset between any two physical blocks to be reclaimed among multiple physical blocks to be reclaimed. For example, if the address of physical block A to be reclaimed is a and the address of physical block B to be reclaimed is a, then the distance information between physical block A to be reclaimed and physical block B to be reclaimed is ba.
[0095] In a specific embodiment, the step of determining the recovery priority of multiple physical blocks to be recovered based on the distance information and the block size of the multiple physical blocks to be recovered specifically includes: determining the first priority of the multiple physical blocks to be recovered based on the distance information; adjusting the first priority based on the block size of the physical blocks to be recovered to obtain the recovery priority of the multiple physical blocks to be recovered.
[0096] In this embodiment, when determining the first priority of multiple physical blocks to be recycled based on the distance information, the multiple physical blocks to be recycled can be sorted in ascending order based on the distance information, and the priorities of the sorted multiple physical blocks to be recycled can be set in descending order of priority, so that adjacent or close physical blocks to be recycled can be recycled first. When adjusting the first priority based on the block size of the physical blocks to be recycled, the priority of the physical blocks to be recycled with a larger block size can be set higher.
[0097] In another specific embodiment, the step of determining the recovery priority of multiple physical blocks to be recovered based on the distance information and the block sizes of the multiple physical blocks to be recovered specifically includes: determining the second priority of the multiple physical blocks to be recovered based on the block sizes of the multiple physical blocks to be recovered; and adjusting the second priority based on the distance information to obtain the recovery priority of the multiple physical blocks to be recovered.
[0098] In this embodiment, when determining the second priority of multiple physical blocks to be recycled based on the block sizes of multiple physical blocks to be recycled, the multiple physical blocks to be recycled can be sorted in descending order based on the block sizes, and the priorities of the sorted multiple physical blocks to be recycled can be set in descending order of priority, so that larger physical blocks to be recycled can be recycled first. When adjusting the second priority based on the distance information, the priorities of adjacent or close physical blocks to be recycled among the multiple physical blocks to be recycled can be set higher than the priorities of other physical blocks among the physical blocks to be recycled.
[0099] S403: Control the recovery thread to perform erasure processing on multiple physical blocks to be recovered based on the operation cycle and the recovery priority.
[0100] The recycling thread of this embodiment performs erasure processing on multiple physical blocks to be recycled based on the operation cycle and recycling priority, and can adjust the recycling times and intensity of the physical blocks per unit time according to the number and location information of the physical blocks to be recycled. Without affecting the user's use of the device, the physical blocks occupied by invalid data in the target file system can be recycled to the maximum extent.
[0101] In summary, the physical block recovery method provided by the present implementation scheme obtains the status information of the target file system, and determines whether the target file system needs to recover the physical blocks based on the status information. If the target file system needs to recover the physical blocks, the first number of physical blocks to be recovered and the position information of the physical blocks to be recovered in the target file system are obtained, and the physical blocks to be recovered are erased based on the first number and the position information to recover the physical blocks to be recovered. In this solution, it is determined whether the target file system needs to recycle physical blocks based on the status information. If the target file system needs to recycle physical blocks, the physical blocks to be recycled are erased based on the first number of physical blocks to be recycled and the position information of the physical blocks to be recycled in the target file system. The virtual occupied physical blocks in the target file system can be automatically recycled based on the status information of the target file system and the number and position distribution of the virtual occupied physical blocks, so as to ensure the write and delete performance of the target file system, thereby ensuring that the user can use the device for a long time without lag; further, the second number is compared with the number threshold, and if the second number is greater than or equal to the number threshold, the type information of the input and output operation is obtained, and based on the type information, it is determined whether the target file system needs to recycle physical blocks, so as to ensure that the automatic recycling of the virtual occupied physical blocks does not affect the user's use of the device; further, the recycling thread is controlled to erase multiple physical blocks to be recycled based on the operation cycle and the recycling priority, and the number and strength of the recycling of physical blocks per unit time can be adjusted according to the number and position information of the physical blocks to be recycled, so as to maximize the recovery of physical blocks that are virtual occupied by invalid data in the target file system.
[0102] In order to better implement the physical block recovery method in the embodiment of the present application, based on the physical block recovery method, the embodiment of the present application also provides a physical block recovery device, such as Figure 5 As shown, the physical block recovery device 600 includes:
[0103] A first acquisition module 610 is used to acquire status information of a target file system;
[0104] An information determination module 620, used to determine whether the target file system needs to reclaim physical blocks based on the status information;
[0105] A second acquisition module 630 is used to acquire a first number of physical blocks to be reclaimed and location information of the physical blocks to be reclaimed in the target file system if the target file system needs to reclaim physical blocks;
[0106] The erasure processing module 640 is used to perform an erasure process on the physical blocks to be reclaimed based on the first quantity and position information, so as to reclaim the physical blocks to be reclaimed.
[0107] In the embodiment of the present application, whether the target file system needs to recycle physical blocks is determined based on the status information. If the target file system needs to recycle physical blocks, the physical blocks to be reclaimed are erased based on the first number of physical blocks to be reclaimed and the position information of the physical blocks to be reclaimed in the target file system. The virtually occupied physical blocks in the target file system can be automatically reclaimed based on the status information of the target file system and the number and position distribution of the virtually occupied physical blocks, thereby ensuring the write and delete performance of the target file system, thereby ensuring that the user can use the device for a long time without lag.
[0108] In some embodiments of the present application, the state information includes the second number of input / output operations and / or storage capacity, and the information determination module 620 is specifically used to:
[0109] comparing the second quantity to a quantity threshold;
[0110] If the second number is greater than or equal to the number threshold, obtaining type information of the input and output operations;
[0111] Based on the type information, determine whether the target file system needs to reclaim physical blocks.
[0112] In some embodiments of the present application, the information determination module 620 is further configured to:
[0113] Based on the type information of the input / output operation, determining whether the input / output operation is of a preset type;
[0114] If the input / output operation is not of a preset type, it is determined that the target file system needs to reclaim physical blocks.
[0115] In some embodiments of the present application, the information determination module 620 is further configured to:
[0116] If the second quantity is less than the quantity threshold, comparing the storage capacity with the capacity threshold;
[0117] If the storage capacity is less than the capacity threshold, it is determined that the target file system needs to reclaim physical blocks.
[0118] In some embodiments of the present application, the physical blocks to be reclaimed include multiple physical blocks, and the multiple physical blocks to be reclaimed are erased by the recovery thread. The erasure processing module 640 is specifically used for:
[0119] Based on the first number, determining an operation cycle of the recycling thread;
[0120] Determine the recycling priorities of multiple physical blocks to be recycled based on the location information;
[0121] The control recovery thread performs erasing processing on a plurality of physical blocks to be recovered based on an operation cycle and a recovery priority.
[0122] In some embodiments of the present application, the erasure processing module 640 is further used to:
[0123] Obtaining a third number and a preset time; the third number is the number of physical blocks that do not need to be recycled in the target file system;
[0124] Adding the first quantity and the third quantity to obtain a fourth quantity;
[0125] Dividing the first quantity and the fourth quantity to obtain a quantity ratio value;
[0126] The preset time and the quantity ratio value are divided to obtain the operation cycle of the recycling thread.
[0127] In some embodiments of the present application, the erasure processing module 640 is further used to:
[0128] Based on the location information, determine distance information between multiple physical blocks to be recycled;
[0129] Based on the distance information and the block sizes of the multiple physical blocks to be reclaimed, the reclaiming priorities of the multiple physical blocks to be reclaimed are determined.
[0130] An embodiment of the present application also provides a computer device, which integrates any one of the physical block recovery devices provided in the embodiments of the present application, and the computer device includes: one or more processors, a memory, and one or more applications, wherein the one or more applications are stored in the memory and are configured to execute the steps of the physical block recovery method in any one of the above-mentioned physical block recovery method embodiments by the processor.
[0131] The present application also provides a computer device that integrates any physical block recovery device provided in the present application. Figure 6 As shown, it shows a schematic diagram of the structure of the computer device involved in the embodiment of the present application, specifically:
[0132] The computer device may include one or more processing core processors 801, one or more computer-readable storage media memories 802, a power supply 803, an input unit 804 and other components. Those skilled in the art will appreciate that Figure 6 The computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. Among them:
[0133] The processor 801 is the control center of the computer device. It uses various interfaces and lines to connect various parts of the entire computer device. By running or executing software programs and / or modules stored in the memory 802 and calling data stored in the memory 802, it executes various functions of the computer device and processes data, thereby monitoring the computer device as a whole. Optionally, the processor 801 may include one or more processing cores; preferably, the processor 801 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 801.
[0134] The memory 802 can be used to store software programs and modules. The processor 801 executes various functional applications and data processing by running the software programs and modules stored in the memory 802. The memory 802 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 802 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, or other volatile solid-state storage device. Accordingly, the memory 802 may also include a memory controller to provide the processor 801 with access to the memory 802.
[0135] The computer device also includes a power supply 803 for supplying power to each component. Preferably, the power supply 803 can be logically connected to the processor 801 through a power management system, so that the power management system can manage charging, discharging, power consumption and other functions. The power supply 803 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators and other arbitrary components.
[0136] The computer device may further include an input unit 804, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0137] Although not shown, the computer device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 801 in the computer device will load the executable files corresponding to the processes of one or more application programs into the memory 802 according to the following instructions, and the processor 801 will run the application programs stored in the memory 802, thereby realizing various functions, as follows:
[0138] Get the status information of the target file system;
[0139] Based on the status information, determine whether the target file system needs to reclaim physical blocks;
[0140] If the target file system needs to recycle physical blocks, obtain a first number of physical blocks to be reclaimed and position information of the physical blocks to be reclaimed in the target file system;
[0141] The physical block to be reclaimed is erased based on the first quantity and the position information to reclaim the physical block to be reclaimed.
[0142] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0143] To this end, an embodiment of the present application provides a computer-readable storage medium, which may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc. A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in any physical block recovery method provided in the embodiment of the present application. For example, the computer program is loaded by the processor to execute the following steps:
[0144] Get the status information of the target file system;
[0145] Based on the status information, determine whether the target file system needs to reclaim physical blocks;
[0146] If the target file system needs to recycle physical blocks, obtain a first number of physical blocks to be reclaimed and position information of the physical blocks to be reclaimed in the target file system;
[0147] The physical block to be reclaimed is erased based on the first quantity and the position information to reclaim the physical block to be reclaimed.
[0148] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of other embodiments above, and will not be repeated here.
[0149] In specific implementation, the above units or structures can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units or structures can refer to the previous method embodiments, which will not be repeated here.
[0150] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0151] The above is a detailed introduction to a physical block recovery method, device, equipment and computer-readable storage medium provided in an embodiment of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A physical block recovery method, characterized in that: include: Get the status information of the target file system; Based on the status information, determining whether the target file system needs to reclaim physical blocks; If the target file system needs to reclaim physical blocks, obtaining a first number of physical blocks to be reclaimed in the target file system and location information of the physical blocks to be reclaimed; The physical block to be reclaimed is erased based on the first number and the position information to reclaim the physical block to be reclaimed.
2. The physical block recycling method according to claim 1, characterized in that: The state information includes a second number of input / output operations, and / or storage capacity; The determining, based on the status information, whether the target file system needs to reclaim physical blocks includes: comparing the second amount to an amount threshold; If the second number is greater than or equal to the number threshold, obtaining type information of the input / output operation; Based on the type information, it is determined whether the target file system needs to reclaim physical blocks.
3. The physical block recycling method according to claim 2, characterized in that: The determining, based on the type information, whether the target file system needs to reclaim physical blocks includes: Based on the type information of the input / output operation, determining whether the input / output operation is of a preset type; If the input / output operation is not of the preset type, it is determined that the target file system needs to reclaim physical blocks.
4. The physical block recycling method according to claim 2, characterized in that: After comparing the second quantity with the quantity threshold, the method further comprises: If the second quantity is less than the quantity threshold, comparing the storage capacity with a capacity threshold; If the storage capacity is less than the capacity threshold, it is determined that the target file system needs to reclaim physical blocks.
5. The physical block recycling method according to claim 1, characterized in that: The physical blocks to be reclaimed include a plurality of physical blocks to be reclaimed, and the plurality of physical blocks to be reclaimed are erased by a reclaiming thread; The erasing process of the physical block to be recycled based on the first quantity and the position information includes: Based on the first number, determining an operation cycle of the recycling thread; Determining the recycling priorities of the plurality of physical blocks to be recycled based on the location information; The recycling thread is controlled to perform erasing processing on the plurality of physical blocks to be recycled based on the operation cycle and the recycling priority.
6. The physical block recycling method according to claim 5, characterized in that: The determining, based on the first quantity, the operating cycle of the recycling thread includes: Acquire a third number and a preset time; the third number is the number of physical blocks that do not need to be recycled in the target file system; Adding the first number and the third number to obtain a fourth number; Dividing the first quantity and the fourth quantity to obtain a quantity ratio value; The preset time and the quantity ratio value are divided to obtain the operation cycle of the recycling thread.
7. The physical block recycling method according to claim 5, characterized in that: The determining, based on the location information, the recycling priorities of the plurality of physical blocks to be recycled comprises: Based on the location information, determining distance information between the plurality of physical blocks to be recycled; Based on the distance information and the block sizes of the multiple physical blocks to be reclaimed, the reclaiming priorities of the multiple physical blocks to be reclaimed are determined.
8. A physical block recovery device, characterized in that: include: A first acquisition module, used to acquire status information of a target file system; An information determination module, used to determine whether the target file system needs to reclaim physical blocks based on the status information; A second acquisition module is used to acquire a first number of physical blocks to be reclaimed and position information of the physical blocks to be reclaimed in the target file system if the target file system needs to reclaim physical blocks; An erasing processing module is used to perform an erasing process on the physical block to be reclaimed based on the first number and the position information, so as to reclaim the physical block to be reclaimed.
9. A computer device, characterized in that: The computer device comprises: one or more processors, a memory, and one or more application programs, wherein the one or more application programs are stored in the memory and are configured to be executed by the processor to implement the physical block recycling method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in the physical block recycling method according to any one of claims 1 to 7.