Method for defragmenting a disk and related device
By uploading disk fragments to a server and storing them contiguously on the server, the reliance of disk defragmentation on large contiguous free spaces is resolved, enabling a more flexible defragmentation method.
Patent Information
- Application Number
- CN202210907020.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-29
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2042-07-29
AI Technical Summary
Existing disk defragmentation methods require a contiguous block of free space on the disk with a size no smaller than the file size, which has significant limitations.
Each fragment of the target file is uploaded to the server, and the disk space it occupies is cleared. After obtaining a sufficiently large contiguous free space, the fragments are stored contiguously in the server's free space, reducing the dependence on local disk space.
Defragmentation can be completed without requiring contiguous free space on the local disk larger than the file size, reducing the limitations of disk defragmentation.
Smart Images

Figure CN115269449B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of computer, and particularly, to a disk defragmentation method and related device. BACKGROUND
[0002] After a disk is used for a period of time, due to repeated writing and deleting files, the free sectors in the disk are scattered to non-continuous physical locations in the whole disk, so that the files cannot be stored in continuous sectors. When reading and writing files, different fragments of the file need to be read from different locations in the disk, and the head needs to move back and forth frequently, which reduces the access efficiency of the disk.
[0003] Now, the defragmentation is usually performed by means of a locally continuous free space of the disk. The defragmentation of a file is realized by migrating all fragments of the file to a continuous free space, i.e., storing each fragment of the file in a continuous free space and clearing the disk space originally occupied by each fragment of the file, so that the multiple fragments of the file are continuously saved in the disk.
[0004] However, this defragmentation method requires that there is a continuous free space locally existing in the disk, and the size of the free space should not be smaller than the size of the file, which has great limitations. SUMMARY
[0005] Embodiments of the present application provide a disk defragmentation method and related device, which are used to reduce the limitations of defragmentation.
[0006] In a first aspect, the present application provides a disk defragmentation method, comprising:
[0007] In response to a defragmentation request for a target file, uploading each target fragment corresponding to the target file to a server, and clearing the disk space occupied by each target fragment;
[0008] Obtaining first free continuous space information of the disk;
[0009] If there is at least one target first free continuous space in the first free continuous space information, the size of which is greater than or equal to the file size of the target file, obtaining each target fragment from the server, and continuously storing multiple target fragments in any target first free continuous space.
[0010] In a specific implementation, before the response to the defragmentation request for the target file, the method further comprises:
[0011] determining, in response to a defragmentation request for the disk, a plurality of files to be defragmented in the disk whose defragmentation degrees are greater than a preset defragmentation threshold, the plurality of files to be defragmented including the target file;
[0012] initiating a defragmentation request for each file to be processed in turn.
[0013] In an implementation mode, after the first free contiguous space information of the disk is acquired, the method further comprises:
[0014] If the size of each first free contiguous space included in the first free contiguous space information is smaller than the file size of the target file, a defragmentation request is initiated for any unprocessed file to be defragmented in the plurality of files to be defragmented except the target file until there is a free contiguous space in the disk which is greater than or equal to the file size of the target file.
[0015] In an implementation mode, before the defragmentation request for the disk is initiated in response to the defragmentation request for the disk, the method further comprises:
[0016] If the disk satisfies a preset first defragmentation condition, second free contiguous space information of the disk is acquired;
[0017] If the number of contiguous spaces or the size of contiguous spaces included in the second free contiguous space information satisfies a preset second defragmentation condition, a defragmentation request for the disk is initiated.
[0018] In an implementation mode, the defragmentation request for each file to be processed in turn comprises:
[0019] According to the file size of each file to be processed, a defragmentation request is initiated for each file to be processed in turn from the file to be processed with the largest file size to the file to be processed with the smallest file size.
[0020] In an implementation mode, the uploading of each target fragment corresponding to the target file to a server and the emptying of the disk space occupied by each target fragment comprise:
[0021] At least part of the target fragments corresponding to the target file whose total size is not greater than the size of the reserved memory are acquired, and an uploading operation is performed on the at least part of the target fragments acquired from the plurality of target fragments corresponding to the target file;
[0022] The at least part of the target fragments acquired from the plurality of target fragments corresponding to the target file are stored in the reserved memory;
[0023] uploading at least part of the target fragments obtained from the plurality of target fragments corresponding to the target file to the server, and deleting the at least part of the target fragments obtained from the plurality of target fragments corresponding to the target file in the reserved memory;
[0024] if there is an un-uploaded target fragment in the plurality of target fragments corresponding to the target file except the first target fragment, obtaining at least part of the target fragments with a total size of fragments not greater than a space size of the reserved memory from the un-uploaded target fragments, and performing an uploading operation on the at least part of the target fragments with the total size of fragments not greater than the space size of the reserved memory from the un-uploaded target fragments until each target fragment corresponding to the target file is completed uploading;
[0025] if each target fragment corresponding to the target file is completed uploading, clearing a disk space occupied by the each target fragment.
[0026] In a specific implementation manner, the obtaining, by the server, of the each target fragment and the continuous storage, by the server, of the plurality of target fragments in any of the target first idle continuous spaces include:
[0027] the continuous storage, by the server, of the plurality of target fragments in the target first idle continuous space with the smallest space size.
[0028] In a specific implementation manner, the method further includes:
[0029] if the battery power of the disk corresponding terminal is lower than a preset minimum power, stopping the fragment arrangement and obtaining, by the server, all uploaded fragments.
[0030] The second aspect of the embodiment of the application provides a disk fragment arrangement device, including
[0031] an uploading unit configured to, in response to a fragment arrangement request for a target file, upload each target fragment corresponding to the target file to a server and clear a disk space occupied by the each target fragment;
[0032] an obtaining unit configured to obtain first idle continuous space information of a disk;
[0033] a storage unit configured to, if there is at least one target first idle continuous space with a continuous space size greater than or equal to a file size of the target file in the first idle continuous space information, obtain, by the server, the each target fragment and continuously store the plurality of target fragments in any of the target first idle continuous spaces.
[0034] In a specific implementation manner, the device further includes a determining unit and an initiating unit.
[0035] The determining unit is configured to determine, in response to a defragmentation request for the disk, a plurality of files to be defragmented in the disk whose fragmentation degrees are greater than a preset fragmentation threshold, the plurality of files to be defragmented including the target file.
[0036] The initiating unit is configured to initiate the defragmentation request for each file to be processed in turn.
[0037] In an implementation manner, the initiating unit is further configured to initiate a defragmentation request for any unprocessed file to be defragmented in the plurality of files to be defragmented except the target file, until there is a free contiguous space in the disk which is greater than or equal to the file size of the target file, if the space size of each first free contiguous space included in the first free contiguous space information is less than the file size of the target file.
[0038] In an implementation manner, the obtaining unit is further configured to obtain second free contiguous space information of the disk if the disk satisfies a preset first defragmentation condition.
[0039] The initiating unit is further configured to initiate the defragmentation request for the disk if the number of contiguous spaces or the space size of contiguous spaces included in the second free contiguous space information satisfies a preset second defragmentation condition.
[0040] In an implementation manner, the initiating unit is specifically configured to initiate the defragmentation request for each file to be processed in turn from the file to be processed with the largest file size to the file to be processed with the smallest file size according to the file size of each file to be processed.
[0041] In an implementation manner, the uploading unit is specifically configured to obtain at least part of target fragments corresponding to the target file whose total fragment size is not greater than the space size of the reserved memory, and perform an uploading operation on the at least part of target fragments obtained from the plurality of target fragments corresponding to the target file.
[0042] The at least part of target fragments obtained from the plurality of target fragments corresponding to the target file are stored in the reserved memory.
[0043] The at least part of target fragments obtained from the plurality of target fragments corresponding to the target file are uploaded to a server, and the at least part of target fragments obtained from the plurality of target fragments corresponding to the target file in the reserved memory are deleted.
[0044] If there is an un-uploaded target fragment in the target fragments corresponding to the target file except the first target fragment, at least part of the target fragments with a total size of fragments not greater than the space size of the reserved memory are obtained from the un-uploaded target fragments, and an uploading operation is performed on the at least part of the target fragments with a total size of fragments not greater than the space size of the reserved memory obtained from the un-uploaded target fragments until each target fragment corresponding to the target file is completed uploading.
[0045] If each target fragment corresponding to the target file is completed uploading, the disk space occupied by each target fragment is emptied.
[0046] In a specific implementation manner, the storage unit is specifically configured to store the target fragments in the target first idle continuous spaces in a continuous manner from the target first idle continuous space with the smallest space size.
[0047] In a specific implementation manner, the device further includes a termination unit.
[0048] The termination unit is configured to stop the fragment consolidation and obtain all uploaded fragments from the server if the battery power of the corresponding terminal of the disk is lower than a preset minimum power.
[0049] The third aspect of the embodiment of the present application provides a disk fragment consolidation device, including:
[0050] a central processing unit, a memory and an input and output interface;
[0051] The memory is a transitory storage memory or a persistent storage memory.
[0052] The central processing unit is configured to communicate with the memory and perform instruction operation in the memory to execute the method of the first aspect.
[0053] The fourth aspect of the embodiment of the present application provides a computer program product containing instructions, when the computer program product runs on a computer, so that the computer executes the method of the first aspect.
[0054] The fifth aspect of the embodiment of the present application provides a computer storage medium, the computer storage medium stores instructions, when the instructions are executed on a computer, so that the computer executes the method of the first aspect.
[0055] From the above technical solution can be seen, the application embodiment has the following advantages: when the target file corresponding to the target file is uploaded to the server, and the disk space occupied by each target fragment is emptied to release the disk space to obtain a large enough free continuous space. Then, the target file is obtained from the server and the target file is stored in the continuous space determined from the first free continuous space information of the disk. The size of the free continuous space is not less than the size of the target file. Without the need for a local space of a file size, the limitation of disk defragmentation is greatly reduced. BRIEF DESCRIPTION OF DRAWINGS
[0056] Figure 1 A system architecture diagram of the disk defragmentation method disclosed by the embodiment of the application;
[0057] Figure 2 A flowchart of the disk defragmentation method disclosed by the embodiment of the application;
[0058] Figure 3 Another flowchart of the disk defragmentation method disclosed by the embodiment of the application;
[0059] Figure 4 A flowchart of the upload operation disclosed by the embodiment of the application;
[0060] Figure 5 A structural diagram of the disk defragmentation device disclosed by the embodiment of the application;
[0061] Figure 6 Another structural diagram of the disk defragmentation device disclosed by the embodiment of the application. DETAILED DESCRIPTION
[0062] The technical solutions in the embodiments of the application will be described clearly and completely below with reference to the drawings in the embodiments of the application. Obviously, the described embodiments are only part of the embodiments of the application, not all the embodiments. Based on the embodiments in the application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the application.
[0063] The embodiments of the application provide a disk defragmentation method and related devices to reduce the limitations of disk defragmentation.
[0064] Please refer to Figure 1In order to better realize the disk defragmentation method of the present application, the embodiments of the present application provide a disk defragmentation system, which can include at least one terminal 101 and at least one server 102. The terminal is integrated with an operating system, which includes at least a local file system and a server system. The local file system is used to manage the disk space of the terminal, and the server system is used to upload the file fragments required by the local file system to the server and obtain the file fragments from the server for storage by the local file system.
[0065] The terminal 101 can be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers and portable wearable devices. The portable wearable device can be a smart watch, a smart bracelet, a head-mounted device, etc. The server 102 can be implemented by an independent server or a server cluster composed of multiple servers, and can be a cloud server or a network server.
[0066] Referring to Figure 2 Based on the foregoing disk defragmentation system, the embodiments of the present application further provide a disk defragmentation method. The disk defragmentation method of the embodiments of the present application can be executed by the terminal 101 and / or the server 102, and includes the following steps:
[0067] 201. In response to a defragmentation request for a target file, each target fragment corresponding to the target file is uploaded to the server, and the disk space occupied by each target fragment is emptied.
[0068] In response to a defragmentation request for a target file, each target fragment corresponding to the target file is uploaded to the server, and the disk space occupied by each target fragment is emptied.
[0069] 202. Obtain first free contiguous space information of the disk.
[0070] After the uploading operation on the target file in step 201, the number of free contiguous spaces and the size of each free contiguous space in the disk are obtained, and the obtained information is taken as the first free contiguous space information.
[0071] Further, the free contiguous space in the first free contiguous space information can be a free contiguous space with a size greater than a preset size threshold, or all free contiguous spaces contained in the disk, which is not limited here.
[0072] 203、if there is at least one target first free continuous space in the first free continuous space information, whose size is greater than or equal to the file size of the target file, then the server is queried for each target fragment, and the plurality of target fragments are stored in any target first free continuous space.
[0073] After the first free continuous space information of the disk is obtained in step 202, if it is determined that there is at least one free continuous space, and the size of the free continuous space is not less than the file size of the target file, then the server can be queried for each target fragment and stored in any target first free continuous space. Among them, the target first free continuous space is any free continuous space in the first free continuous space information whose size is not less than the file size of the target file. In addition, the file size of the target file refers to the sum of the fragment sizes of all target fragments corresponding to the target file.
[0074] In the embodiments of the present application, when the fragment arrangement request for the target file is obtained, all target fragments corresponding to the target file are uploaded to the server, and the disk space occupied by each target fragment is emptied to release the disk space and obtain a large enough free continuous space. Then, the server is queried for each target fragment of the target file, and each target fragment of the target file is stored in any free continuous space whose size is not less than the size of the target file determined from the continuous free space contained in the first free continuous space information of the disk. There is no need for a free continuous space with a size not less than the file size to exist locally on the disk, greatly reducing the limitations of disk defragmentation.
[0075] Please refer to Figure 3 The embodiments of the present application also provide a disk defragmentation method, comprising the following steps:
[0076] 301、in response to a fragment arrangement request for a disk, a plurality of to-be-arranged files in the disk whose fragmentation degree is greater than a preset fragmentation threshold are determined based on the preset fragmentation threshold, and the plurality of to-be-arranged files include a target file.
[0077] In response to a fragment arrangement request for a disk, the file whose fragmentation degree is greater than a preset fragmentation threshold is determined from the disk indicated by the fragment arrangement request as a to-be-arranged file.
[0078] In some specific embodiments, the to-be-arranged file determined from the disk whose fragmentation degree is greater than a preset fragmentation threshold is only one, and the determined unique to-be-arranged file is taken as a target file, and the method described in the foregoing steps 201 to 203 is executed on the to-be-arranged file to complete the fragment arrangement of the to-be-arranged file.
[0079] It can be known that if the plurality of files to be arranged determined from the degree of fragmentation of the disk is greater than the preset fragmentation threshold, step 302 is executed. Among them, the plurality of files to be arranged contains the target file.
[0080] Specifically, the selection of the file to be arranged depends on the number of file fragments and the average size of the file fragments. Generally, the more the number of file fragments of the file, the larger the average size of the file fragments, the greater the value of the file defragmentation, and therefore such files are preferentially selected. In some specific implementations, the file fragment size of the file and the number of file fragments of the file can be obtained through a local file system interface (fiemap ioctl). This interface can be a Linux operating system interface, which is applicable to file systems including but not limited to EXT4 and F2FS file systems. Among them, Linux, EXT4, F2FS are widely used on Android devices.
[0081] Further, the defragmentation request for the disk in response to this step can be triggered by the terminal corresponding to the disk at a regular time, or triggered when the terminal corresponding to the disk meets the first arrangement condition and the second arrangement condition. If the storage space of terminal A is disk B, the terminal corresponding to disk B is terminal A. Specifically, the defragmentation request for the disk can be triggered in the early morning. Before the defragmentation request for the disk is triggered, it can also be determined whether the terminal corresponding to the disk is in a charging state and / or is being used (i.e. the first arrangement condition). If the terminal corresponding to the disk is in a charging state and is not currently being used, it is considered that the defragmentation request can be initiated for the disk, and the second free contiguous space information of the disk is obtained. If the number of contiguous spaces contained in the second free contiguous space information is greater than or equal to a preset number threshold (i.e. the second arrangement condition) or the size of the contiguous space is less than a preset space size threshold (i.e. the second arrangement condition), the defragmentation request for the disk is initiated, and then the file in the disk that needs to be defragmented is determined as the file to be arranged.
[0082] Among them, the first arrangement condition can be any condition for judging whether the current environment (use case and device condition) of the terminal allows defragmentation, and the second arrangement condition can be any condition for judging whether the degree of fragmentation of the disk (i.e. whether the size of the free contiguous space in the disk is small or the number of free contiguous spaces in the disk is small) is suitable or should be defragmented, which is not limited here.
[0083] 302, initiate a defragmentation request for each file to be processed in turn.
[0084] The defragmentation request is initiated for each file to be processed in turn until each file to be processed is defragmented. The defragmentation includes uploading each target fragment of the target file to the server and storing each target fragment of the target file in the continuous space.
[0085] 303. In response to the defragmentation request for the target file, each target fragment corresponding to the target file is uploaded to the server, and the disk space occupied by each target fragment is emptied.
[0086] Step 302 initiates a defragmentation request for file A to be defragmented, so the target file in this step 303 is file A to be defragmented. Specifically, after receiving the defragmentation request for the target file, an upload operation is performed on each target fragment of the target file, i.e., each target fragment corresponding to the target file is uploaded to the server, and the disk space occupied by each target fragment is emptied to obtain more free continuous spaces of larger size.
[0087] 304. Obtain first free continuous space information of the disk.
[0088] This step is similar to step 202 in the foregoing embodiments, which will not be described here.
[0089] 305. If there is at least one target first free continuous space in the first free continuous space information whose size is greater than or equal to the file size of the target file, each target fragment is obtained from the server, and the target fragments are stored continuously in any target first free continuous space.
[0090] This step is similar to step 203 in the foregoing embodiments, which will not be described here.
[0091] 304. If the size of each first free continuous space included in the first free continuous space information is less than the file size of the target file, a defragmentation request is initiated for any unprocessed file to be defragmented in the plurality of files to be defragmented except the target file until there is a free continuous space in the disk that is greater than or equal to the file size of the target file.
[0092] After obtaining the first free continuous space information of the disk after uploading the target file in step 304, if it is determined that there is no free continuous space whose size is not less than the file size of the target file, a defragmentation request is initiated for any unprocessed file to be defragmented. The unprocessed file to be defragmented refers to a file to be defragmented for which a defragmentation request has not been initiated. In addition, the response after initiating the defragmentation request for any unprocessed file to be defragmented is similar to the response to the defragmentation request for the target file, which will not be described here.
[0093] Specifically, a defragmentation request is initiated for each file to be arranged. If there is a sufficient free contiguous space, the defragmentation request for the file to be arranged is processed (i.e., the uploading operation and the storage operation are completed), and a new defragmentation request is initiated for any file to be arranged from the unprocessed files to be arranged. If there is no sufficient free contiguous space, a new defragmentation request is initiated for any file to be arranged from the unprocessed files to be arranged, and after the defragmentation request for the new file to be arranged is processed, it is determined whether the defragmentation request for the previous unprocessed file to be arranged can be completed (whether the file can be stored in the sufficient free contiguous space). If there is no sufficient free contiguous space, a new defragmentation request is initiated for any file to be arranged from the unprocessed files to be arranged until all the files to be arranged are processed.
[0094] In the embodiments of the present application, if there is no contiguous free space with a size not less than the size of the target file in the first free contiguous space information, a defragmentation request can also be initiated for any unprocessed file to be arranged to solve the problem of insufficient free contiguous space, thereby improving the realizability of the scheme.
[0095] Further, in some specific implementation manners, when the free contiguous space meeting the condition (the size of the space is greater than the file to be stored) is selected from the first free contiguous space information in the foregoing and subsequent embodiments, if there are multiple free contiguous spaces meeting the condition, the free contiguous space with the smallest size can be selected from the multiple free contiguous spaces meeting the condition. Specifically, the multiple free contiguous spaces meeting the condition can be sorted according to the size of the space, and the free contiguous space with the smallest size is selected from the multiple free contiguous spaces meeting the condition as the storage space of the file to be stored, so as to maximize the utilization of the free contiguous space of the disk.
[0096] Further, in some specific implementation manners, whether the target file is selected from the multiple files to be arranged and the defragmentation request is initiated for the target file or a file to be arranged is selected from the unprocessed files to be arranged and the defragmentation request is initiated for the file to be arranged, in the step of selecting a file from the multiple files and initiating the defragmentation request for the file, the selected file can also be the free contiguous space with the largest size in the multiple files, which is not limited here.
[0097] In consideration of the limited battery power of the terminal, a preset minimum power can be set in advance, and when the disk corresponding terminal is lower than or equal to the preset minimum power, all operations related to the defragmentation (including but not limited to uploading operations, storage operations and operations of initiating defragmentation requests) are stopped, and if there are files or file fragments that have been uploaded, all the uploaded files or file fragments that have not completed the storage operation are downloaded to the disk corresponding terminal to ensure the normal operation of the terminal.
[0098] Please refer to Figure 4 In a specific implementation, taking the uploading operation on the target file as an example, the uploading step (including but not limited to uploading the file fragments to the server and emptying the disk space occupied by the file fragments) of the embodiment of the application can include the following steps:
[0099] 401、Obtain at least part of the target fragments corresponding to the target file whose total size is not greater than the size of the reserved memory, and perform an uploading operation on the at least part of the target fragments obtained from the plurality of target fragments corresponding to the target file.
[0100] Before performing the uploading operation, a part of the memory is pre-divided as a reserved memory to implement the uploading operation of the target fragments (i.e. file fragments) corresponding to the target file, so if the target file has a plurality of target fragments and the size of the target fragments is greater than the reserved memory, the uploading operation needs to be performed on the plurality of target fragments in batches, as long as the size of the fragments performing the uploading operation each time is not greater than the reserved memory; if the target file has a plurality of target fragments and the size of the target fragments is less than the reserved memory, the uploading operation can be performed on all the target fragments once, which is not limited here.
[0101] Specifically, the reserved memory can be determined according to the size of the file fragments, which is not limited here.
[0102] 402、This step is the step of performing the uploading operation, including step 4021 and step 4022.
[0103] 4021、Store at least part of the target fragments obtained from the plurality of target fragments corresponding to the target file in the reserved memory.
[0104] First, store all the target fragments performing the uploading operation in the reserved memory.
[0105] 4022、Upload at least part of the target fragments obtained from the plurality of target fragments corresponding to the target file to the server, and delete at least part of the target fragments obtained from the plurality of target fragments corresponding to the target file in the reserved memory.
[0106] Then, the target fragments stored in the reserved memory and currently performing the uploading operation are all uploaded to the server, and the memory is emptied, and thus the uploading operation for the batch is completed.
[0107] 403. Determine whether there is a target fragment that has not been uploaded.
[0108] If there is a target fragment that has not been uploaded in the target fragments corresponding to the target file except the first target fragment, at least part of the target fragments with a total size not greater than the space size of the reserved memory are obtained from the target fragments that have not been uploaded, and the uploading operation is performed on the at least part of the target fragments with a total size not greater than the space size of the reserved memory obtained from the target fragments that have not been uploaded, until each target fragment corresponding to the target file is completed uploading (different from the uploading operation).
[0109] Specifically, if there is a target fragment that has not been uploaded in the target fragments corresponding to the target file, the target fragments are selected according to the target fragment selection criteria (i.e., the total size of the selected target fragments cannot exceed the reserved memory) described in step 401 of the foregoing embodiment, and after the selection, the uploading operation is performed on the selected target fragments, until each target fragment corresponding to the target file is completed uploading.
[0110] In some specific implementations, if each target fragment corresponding to the target file is completed uploading, step 404 is performed.
[0111] 404. If each target fragment corresponding to the target file is completed uploading, the disk space occupied by each target fragment is emptied.
[0112] After it is determined that each target fragment corresponding to the target file is completed uploading, step 404 can empty the disk space occupied by each target fragment, and thus the uploading operation is completed.
[0113] In the embodiments of the present application, a specific implementation of the uploading operation is provided, and the realizability of the scheme is improved.
[0114] Please refer to Figure 5 The embodiments of the present application provide a disk fragment arrangement device, which comprises:
[0115] The uploading unit 501 is configured to, in response to a fragment arrangement request for a target file, upload each target fragment corresponding to the target file to a server, and empty the disk space occupied by each target fragment;
[0116] The obtaining unit 502 is configured to obtain first free continuous space information of a disk.
[0117] The storage unit 503 is configured to acquire each target fragment from the server if there is at least one target first free continuous space in the first free continuous space information, and store the plurality of target fragments in any target first free continuous space.
[0118] In an implementation, the device further comprises a determination unit and an initiation unit;
[0119] The determination unit is configured to determine, in response to a defragmentation request for the disk, a plurality of to-be-defragmented files in the disk whose defragmentation degrees are greater than a preset defragmentation threshold, and the plurality of to-be-defragmented files include the target file;
[0120] The initiation unit is configured to initiate the defragmentation request for each to-be-processed file in turn.
[0121] In an implementation, the initiation unit is further configured to initiate the defragmentation request for any unprocessed to-be-defragmented file in the plurality of to-be-defragmented files except the target file until there is a free continuous space in the disk that is greater than or equal to the file size of the target file, if the space size of each first free continuous space included in the first free continuous space information is less than the file size of the target file.
[0122] In an implementation, the acquisition unit 502 is further configured to acquire second free continuous space information of the disk if the disk satisfies a preset first defragmentation condition.
[0123] The initiation unit is further configured to initiate the defragmentation request for the disk if the number of continuous spaces or the space size of the continuous spaces included in the second free continuous space information satisfies a preset second defragmentation condition.
[0124] In an implementation, the initiation unit is specifically configured to initiate the defragmentation request for each to-be-processed file in turn from the to-be-processed file with the largest file size to the to-be-processed file with the smallest file size according to the file size of each to-be-processed file.
[0125] In an implementation, the acquisition unit 501 is specifically configured to acquire at least part of the target fragments corresponding to the target file whose total fragment size is not greater than the space size of the reserved memory, and perform an uploading operation on the at least part of the target fragments acquired from the plurality of target fragments corresponding to the target file.
[0126] The at least part of the target fragments acquired from the plurality of target fragments corresponding to the target file are stored in the reserved memory.
[0127] upload at least part of the target fragments obtained from the plurality of target fragments corresponding to the target file to the server, and delete at least part of the target fragments obtained from the plurality of target fragments corresponding to the target file in the reserved memory;
[0128] If there is an un-uploaded target fragment in the plurality of target fragments corresponding to the target file except the first target fragment, obtain at least part of the target fragments with a total size of the fragments not greater than the space size of the reserved memory from the un-uploaded target fragments, and perform an uploading operation on at least part of the target fragments with a total size of the fragments not greater than the space size of the reserved memory obtained from the un-uploaded target fragments until each target fragment corresponding to the target file is completed uploading;
[0129] If each target fragment corresponding to the target file is completed uploading, clear the disk space occupied by each target fragment.
[0130] In a specific implementation manner, the storage unit 503 is specifically configured to store the plurality of target fragments in the target first idle continuous space with the smallest space size in the target first idle continuous space.
[0131] In a specific implementation manner, the device further includes a termination unit.
[0132] The termination unit is configured to stop the fragment arrangement and obtain all the uploaded fragments from the server if the battery power of the corresponding terminal of the disk is lower than the preset minimum power.
[0133] Figure 6 FIG. 1 is a structural schematic diagram of a disk fragment arrangement device provided by an embodiment of the present application. The disk fragment arrangement device 600 can include one or more central processing units (CPUs) 601 and a memory 605, and the memory 605 stores one or more application programs or data.
[0134] The memory 605 can be volatile storage or persistent storage. The program stored in the memory 605 can include one or more modules, and each module can include a series of instruction operations in the disk fragment arrangement device. Further, the central processing unit 601 can be configured to communicate with the memory 605 and execute the series of instruction operations in the memory 605 on the disk fragment arrangement device 600.
[0135] The disk defragmentation device 600 can further include one or more power supplies 602, one or more wired or wireless network interfaces 603, one or more input / output interfaces 604, and / or one or more operating systems, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0136] The central processor 601 can perform the operations of the disk defragmentation device in the embodiments described above, which will not be repeated here. Figures 1 to 5 The disk defragmentation device can be the terminal 101 and / or the server 102 in the embodiments described above.
[0137] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the system, device and unit described above can refer to the corresponding processes in the method embodiments described above, which will not be repeated here.
[0138] In several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.
[0139] The units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, i.e. can be located in one place, or can be distributed on a plurality of network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.
[0140] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0141] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such an understanding, the technical solutions of the present application, essentially or in other words, the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the method described in various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, read-only memory), a random access memory (RAM, random access memory), a magnetic disk or an optical disk, and various media that can store program codes.
[0142] The embodiments of the present application also provide a computer program product containing instructions, which, when the computer program product is executed on a computer, causes the computer to execute the disk defragmentation method as described above.
Claims
1. A method of defragmenting a magnetic disk, characterized by, The method comprises: in response to a defragmentation request for a target file, uploading each target fragment corresponding to the target file to a server and clearing the disk space occupied by the each target fragment; the target file is a file in a plurality of files to be defragmented determined based on a preset fragmentation threshold; obtaining first free contiguous space information of the disk; if there is at least one target first free contiguous space in the first free contiguous space information, the size of which is greater than or equal to the file size of the target file, obtaining the each target fragment from the server and storing the plurality of target fragments in any target first free contiguous space; if the size of each first free contiguous space included in the first free contiguous space information is less than the file size of the target file, initiating a defragmentation request for any unprocessed file to be defragmented in the plurality of files to be defragmented except the target file until there is the target first free contiguous space in the disk, the size of which is greater than or equal to the file size of the target file.
2. The method of claim 1, wherein, Before the response to the defragmentation request for the target file, the method further comprises: in response to a defragmentation request for the disk, determining a plurality of files to be defragmented in the disk based on a preset fragmentation threshold, the fragmentation degree of the plurality of files to be defragmented being greater than the fragmentation threshold, the target file being included in the plurality of files to be defragmented; initiating a defragmentation request for each file to be processed in turn.
3. The method of claim 2, wherein, Before the response to the defragmentation request for the disk, the method further comprises: if the disk meets a preset first defragmentation condition, obtaining second free contiguous space information of the disk; if the number of contiguous spaces or the size of contiguous spaces included in the second free contiguous space information meets a preset second defragmentation condition, initiating a defragmentation request for the disk.
4. The method of claim 2, wherein, The initiation of the defragmentation request for each file to be processed in turn comprises: initiating the defragmentation request for each file to be processed in turn from the file to be processed with the largest file size to the file to be processed with the smallest file size according to the file size of each file to be processed.
5. The method of claim 1, wherein, The uploading of the each target fragment corresponding to the target file to the server and the clearing of the disk space occupied by the each target fragment comprise: obtaining at least part of the target fragments corresponding to the target file, the total size of which is not greater than the size of the reserved memory, and performing an uploading operation on the at least part of the target fragments obtained from the plurality of target fragments corresponding to the target file; storing the at least part of the target fragments obtained from the plurality of target fragments corresponding to the target file in the reserved memory; uploading the at least part of the target fragments obtained from the plurality of target fragments corresponding to the target file to the server and deleting the at least part of the target fragments obtained from the plurality of target fragments corresponding to the target file in the reserved memory; If there is an un-uploaded target fragment in the target fragments corresponding to the target file except the uploaded target fragment, at least part of the target fragments with a total size of fragments not greater than the space size of the reserved memory are obtained from the un-uploaded target fragments, and an uploading operation is performed on the at least part of the target fragments with a total size of fragments not greater than the space size of the reserved memory obtained from the un-uploaded target fragments until each target fragment corresponding to the target file is completed uploading; If each target fragment corresponding to the target file is completed uploading, the disk space occupied by each target fragment is emptied.
6. The method of claim 1, wherein, The obtaining, from the server, each target fragment and continuously storing a plurality of the target fragments in any target first idle continuous space includes: Continuously storing a plurality of the target fragments in a target first idle continuous space with the smallest space size.
7. The method of claim 1, wherein, The method further includes: If the battery power of the corresponding terminal of the disk is lower than the preset minimum power, stopping the fragment arrangement and obtaining, from the server, all the uploaded fragments.
8. A disk defragmentation apparatus characterized by comprising: It includes: An uploading unit configured to, in response to a fragment arrangement request for a target file, upload each target fragment corresponding to the target file to a server and empty the disk space occupied by each target fragment; The target file is a file in a plurality of to-be-arranged files determined based on a preset fragmentation threshold; An obtaining unit configured to obtain first idle continuous space information of a disk; A storing unit configured to, if there is at least one target first idle continuous space with a space size greater than or equal to the file size of the target file in the first idle continuous space information, obtain, from the server, each target fragment and continuously store a plurality of the target fragments in any target first idle continuous space; An initiating unit configured to, if the space size of each first idle continuous space included in the first idle continuous space information is smaller than the file size of the target file, initiate a fragment arrangement request for any unprocessed to-be-arranged file in the plurality of to-be-arranged files except the target file until there is the target first idle continuous space with a space size greater than or equal to the file size of the target file in the disk.
9. A disk defragmentation apparatus characterized by comprising: It includes: A central processing unit, a memory and an input-output interface; The memory is a transitory storage memory or a persistent storage memory; The central processing unit is configured to communicate with the memory and execute instruction operations in the memory to perform the method in any one of claims 1 to 7.
10. A computer storage medium, characterized in that, The computer storage medium stores instructions, and the instructions, when executed on a computer, cause the computer to perform the method in any one of claims 1 to 7. The computer storage medium stores instructions, and the instructions, when executed on a computer, cause the computer to perform the method in any one of claims 1 to 7.
Citation Information
Patent Citations
Fragmented-file storage method based on distributed storage system
CN103488685A
Intelligent disk defragmentation method and device and electronic equipment
CN114238161A