WO2018032743A1 - Method for evaluating file fragments, and terminal - Google Patents

Method for evaluating file fragments, and terminal Download PDF

Info

Publication number
WO2018032743A1
WO2018032743A1 PCT/CN2017/075178 CN2017075178W WO2018032743A1 WO 2018032743 A1 WO2018032743 A1 WO 2018032743A1 CN 2017075178 W CN2017075178 W CN 2017075178W WO 2018032743 A1 WO2018032743 A1 WO 2018032743A1
Authority
WO
WIPO (PCT)
Prior art keywords
information
file
storage area
terminal
file size
Prior art date
Application number
PCT/CN2017/075178
Other languages
French (fr)
Chinese (zh)
Inventor
王一静
翟奇
方炜
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2018032743A1 publication Critical patent/WO2018032743A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/1724Details of de-fragmentation performed by the file system

Definitions

  • the present invention relates to the field of computer technologies, and in particular, to a file fragment evaluation method and a terminal.
  • Files are scattered in many different areas on storage media such as disk and flash. File fragments are usually used. After a file system runs for a period of time, files in the file system are repeatedly added and deleted on the storage medium, resulting in storage. The free storage area on the media is no longer continuous. If the file is stored on the storage medium, the file may be scattered over multiple non-contiguous storage areas to form file fragments. File fragmentation is more serious, which leads to a decrease in file read and write performance. Therefore, the file system needs to be defragmented to improve file read and write performance.
  • the terminal traverses all the files in the file system. Reading the metadata of each file in all the files to obtain the file size of each file and the number of storage areas of each file, and the more the number of storage areas, the storage area where the files on the storage medium are located The more dispersed. You can find each file (each file corresponds to a logical address) by issuing the FS_IOC_FIEMAP command, and read the metadata of each file to obtain the logical address of each file. The number of logical addresses is the number of storage areas of the file. As shown in the address map of FIG.
  • each file has at least one storage area on a disk.
  • the terminal evaluates the fragmentation degree of the file system based on the file size of each file and the number of storage areas of each file. It takes more than one hour to evaluate the degree of fragmentation of a storage medium with a storage medium of 128G.
  • a disadvantage of the prior art is that the terminal needs to read the metadata of each file one by one in the process of fragment evaluation, and the number of times of reading the metadata is longer and longer, resulting in lower efficiency of fragment evaluation.
  • the embodiment of the invention discloses a file fragment evaluation method and a terminal, which can improve the efficiency of file fragment evaluation.
  • an embodiment of the present invention provides a file fragment evaluation method, which includes: when the terminal evaluates a fragmentation degree of a file system, directly reading pre-stored fragment information, where the fragment information includes the terminal pre-passing
  • the storage area quantity information evaluates the degree of fragmentation of the K files.
  • the terminal may read the fragmentation information when receiving a trigger instruction input by the user, or may periodically read the fragmentation information, and is not limited to the two methods.
  • the terminal reads the metadata of each file before receiving the fragment evaluation instruction to obtain the file size information and the storage area quantity information of each file, and saves the information in a specific file for reading; the terminal receives the The fragment evaluation instruction directly reads the file size information and the storage area quantity information in the specific file, and evaluates the fragmentation degree of the file system based on the file size information and the storage area quantity information. That is to say, the terminal does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to evaluate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system.
  • the method before the terminal reads the pre-stored fragment information, the method further includes: obtaining, by the terminal, the metadata of each file The file size information of each file and the number of storage areas.
  • the terminal reads the file size information and the storage area quantity information of each file, so that the file size information and the storage area quantity information are used later. It can be used directly without having to read it, making it easier to use the file size information and the number of storage areas.
  • the method further includes: determining, by the terminal, that a write operation is performed for the target file, and Determining the result, reading the metadata of the target file after the end of the writing operation, obtaining the file size information of the target file and the quantity of the storage area, the target file being any one of the K files; the terminal Updating the first file size information and the first storage area quantity information into the fragmentation information, the first file size information being the file size information of the target file read after the end of the writing operation, the first storage area
  • the quantity information is the number of pieces of the storage area of the target file read after the end of the write operation. Determining if there is a write operation to the target file can occur before the fragmentation information is read, or after the fragmentation information is read.
  • the terminal After the terminal acquires the file size information and the storage area number information of each file, if the user subsequently writes to one of the files, the terminal reads the metadata of the certain file again to restart Obtaining the file size information and the storage area quantity information of the certain file and updating it into the fragmentation information, so that the correlation result calculated based on the fragmentation information is more accurate.
  • the terminal, the first file size information and the first storage area quantity information are updated to the fragment information, including Determining that the first file size information is different from the second file size information, and the first storage area quantity information is different from the second storage area quantity information, and replacing the first file size information with the second file according to the determined result.
  • the size information, and the first storage area quantity information is replaced by the second storage area quantity information;
  • the second file size information is the file size information of the target file in the fragmentation information, and the second storage area quantity information is The storage area quantity information of the target file in the fragmentation information.
  • the file size information and the storage area number information of the re-reading of the certain file are not immediately updated to the fragmentation information, but the judgment is first Obtaining the file size information and the storage area quantity information of the certain file and whether the file size information and the storage area quantity information of the certain file in the fragmentation information are the same, and if not, the file of the certain file to be reacquired
  • the size information and the storage area quantity information are updated into the fragmentation information, avoiding unnecessary updates.
  • the fragmentation information is stored on the same storage area of the terminal's external storage.
  • the terminal when the fragment information is stored in the same storage area, the terminal only needs to perform a read operation when reading the fragment information, thereby improving the input/output performance of the fragment information.
  • an embodiment of the present invention provides a terminal, where the terminal includes a processor, a memory, and a user interface, where the memory is used to store data and a program; the processor calls a program in the memory to perform the following operations:
  • To evaluate the fragmentation degree of the file system directly read the pre-stored fragment information, which includes the terminal in advance.
  • the file size information and the storage area number information of each file obtained by reading the metadata of each of the K files of the own file system, K is an integer greater than 0; according to the file size information and the storage
  • the area quantity information evaluates the degree of fragmentation of the K files.
  • the terminal may read the fragmentation information when receiving a trigger instruction input by the user, or may periodically read the fragmentation information, and is not limited to the two methods.
  • the terminal reads the metadata of each file before receiving the fragment evaluation instruction to obtain the file size information and the storage area quantity information of each file, and saves the information in a specific file for reading; the terminal receives The fragment evaluation instruction directly reads the file size information and the storage area quantity information in the specific file, and evaluates the fragmentation degree of the file system based on the file size information and the storage area quantity information. That is to say, the terminal does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to evaluate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system.
  • the processor is further configured to: before reading the pre-stored fragment information, by reading the metadata of each file The file size information of the file and the number of storage areas.
  • the terminal reads the file size information and the storage area quantity information of each file, so that the file size information and the storage area quantity information are used later. It can be used directly without having to read it, making it easier to use the file size information and the number of storage areas.
  • the processor is further configured to: determine that there is a write operation for the target file, and Determining the result, reading the metadata of the target file after the end of the writing operation, obtaining the file size information of the target file and the quantity of the storage area, the target file being any one of the K files; Updating the file size information and the first storage area quantity information to the fragmentation information, the first file size information being the file size information of the target file read after the end of the writing operation, the first storage area quantity information The amount of storage area information of the target file read after the end of the write operation. Determining if there is a write operation to the target file can occur before the fragmentation information is read, or after the fragmentation information is read.
  • the terminal After the terminal acquires the file size information and the storage area number information of each file, if the user subsequently writes to one of the files, the terminal reads the metadata of the certain file again to restart Obtaining the file size information and the storage area quantity information of the certain file and updating it into the fragmentation information, so that the correlation result calculated based on the fragmentation information is more accurate.
  • the processor updates the first file size information and the first storage area quantity information to the fragment information, Specifically, the first file size information is different from the second file size information, and the first storage area quantity information is different from the second storage area quantity information, and the first file size information is replaced by the first result according to the determined result.
  • the second file size information, and the first storage area quantity information is replaced by the second storage area quantity information;
  • the second file size information is the file size information of the target file in the fragmentation information, and the second storage area number
  • the information is the storage area quantity information of the target file in the fragmentation information.
  • the file size information and the storage area number information of the re-reading of the certain file are not immediately updated to the fragmentation information, but the judgment is first Obtaining file size information and storage area quantity information of the file and file size information of the certain file in the fragmentation information Whether the storage area quantity information is the same, if not the same, the file size information and the storage area quantity information of the re-acquired file are updated to the fragmentation information, thereby avoiding unnecessary updates.
  • the fragmentation information is stored on the same storage area of the terminal's external storage.
  • the terminal when the fragment information is stored in the same storage area, the terminal only needs to perform a read operation when reading the fragment information, thereby improving the input/output performance of the fragment information.
  • an embodiment of the present invention provides a terminal, where the terminal includes: a first reading unit, configured to directly read pre-stored fragment information, where the fragment information includes the terminal, when the degree of fragmentation of the file system is to be evaluated.
  • the file size information and the storage area number information of each file obtained by reading the metadata of each of the K files of the own file system, K is an integer greater than 0;
  • the evaluation unit is configured to The file size information and the storage area quantity information evaluate the degree of fragmentation of the K files.
  • the terminal may read the fragmentation information when receiving a trigger instruction input by the user, or may periodically read the fragmentation information, and is not limited to the two methods.
  • the terminal reads the metadata of each file before receiving the fragment evaluation instruction to obtain the file size information and the storage area quantity information of each file, and saves the information in a specific file for reading; the terminal receives the The fragment evaluation instruction directly reads the file size information and the storage area quantity information in the specific file, and evaluates the fragmentation degree of the file system based on the file size information and the storage area quantity information. That is to say, the terminal does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to evaluate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system.
  • the terminal further includes: a second reading unit, configured to read the pre-stored fragment information before the first reading unit reads the pre-stored fragment information
  • the file size information of the each file obtained by the metadata of each file and the quantity information of the storage area.
  • the terminal reads the file size information and the storage area quantity information of each file, so that the file size information and the storage area quantity information are used later. It can be used directly without having to read it, making it easier to use the file size information and the number of storage areas.
  • the terminal further includes: a third reading unit, configured to determine that the target file exists a write operation, and reading the metadata of the target file after the end of the write operation according to the determined result, obtaining the file size information of the target file and the quantity of the storage area, where the target file is in the K files Any one of the files; an update unit, configured to update the first file size information and the first storage area quantity information into the fragmentation information, the first file size information being the target file read after the end of the write operation File size information, the first storage area quantity information is the storage area quantity information of the target file read after the end of the write operation. Determining if there is a write operation to the target file can occur before the fragmentation information is read, or after the fragmentation information is read.
  • the terminal After the terminal acquires the file size information and the storage area number information of each file, if the user subsequently writes to one of the files, the terminal reads the metadata of the certain file again to restart Obtaining the file size information and the storage area quantity information of the certain file and updating it into the fragmentation information, so that the correlation result calculated based on the fragmentation information is more accurate.
  • the updating unit is configured to: determine that the first file size information is different from the second file size information, and the first storage area quantity information is different from the second storage area quantity information, and the first file size information is determined according to the determined result. Substituting the second file size information, and replacing the first storage area quantity information with the second storage area quantity information; the second file size information is the file size information of the target file in the fragmentation information, the second The storage area quantity information is the storage area quantity information of the target file in the fragmentation information.
  • the file size information and the storage area number information of the re-reading of the certain file are not immediately updated to the fragmentation information, but the judgment is first Obtaining the file size information and the storage area quantity information of the certain file and whether the file size information and the storage area quantity information of the certain file in the fragmentation information are the same, and if not, the file of the certain file to be reacquired
  • the size information and the storage area quantity information are updated into the fragmentation information, avoiding unnecessary updates.
  • the fragmentation information is stored on the same storage area of the terminal's external storage.
  • the embodiment of the present invention further provides a computer storage medium, which may be non-volatile, that is, the content is not lost after power off.
  • the storage medium stores a software program that, when read and executed by one or more processors, implements the method provided by the first aspect or any one of the foregoing first aspects.
  • the terminal reads metadata of each file before receiving the fragment evaluation instruction to obtain file size information and storage area quantity information of each file, and saves the information in a specific file for reading;
  • the file size information and the storage area quantity information in the specific file are directly read, and the fragmentation degree of the file system is evaluated based on the file size information and the storage area quantity information. That is to say, the terminal does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to evaluate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system.
  • FIG. 1 is a schematic diagram of a scenario corresponding to a file storage area according to an embodiment of the present disclosure
  • FIG. 2 is a schematic structural diagram of a terminal according to an embodiment of the present invention.
  • FIG. 3 is a schematic flowchart of a file fragment evaluation method according to an embodiment of the present invention.
  • FIG. 4 is a schematic diagram of a format of fragmentation information according to an embodiment of the present invention.
  • FIG. 5 is a schematic diagram of a scenario for updating fragment information according to an embodiment of the present disclosure
  • FIG. 6 is a schematic structural diagram of a computer system according to an embodiment of the present invention.
  • FIG. 7 is a schematic structural diagram of still another terminal according to an embodiment of the present invention.
  • the file fragment evaluation method provided by the embodiment of the present invention is mainly applied to a terminal, and the terminal may also be called a user equipment (English: User Equipment, abbreviated as: UE), a mobile station (English: Mobile Station, abbreviated as: MS), and a mobile terminal. (English: Mobile Terminal), etc., optional, the terminal can have a wireless access network (English: Radio Access Network, referred to as: RAN)
  • RAN Radio Access Network
  • the terminal may be a mobile phone (or "cellular" phone), or a computer with mobile nature, for example, the terminal may also be portable , pocket, handheld, computer built-in or in-vehicle mobile devices. It should be understood that the file fragment evaluation method provided by the embodiment of the present invention can be applied to other types of computer systems in addition to the terminal.
  • FIG. 2 is a schematic structural diagram of a terminal 200 according to an embodiment of the present invention.
  • the terminal 200 includes a memory 280, a processor 250, and a display device 240.
  • the memory 280 stores a computer program including an operating system program 282, an application program 281, and the like.
  • the processor 250 is configured to read a computer program in the memory 280 and then execute a computer program defined method, for example, the processor 250 reads the operating system program 282 to run an operating system on the terminal 200 and implement various functions of the operating system. Or one or more applications 281 are read to run the application on the terminal.
  • Processor 250 may include one or more processors, for example, processor 250 may include one or more central processors. When the processor 250 includes a plurality of processors, the plurality of processors may be integrated on the same chip, or may each be a separate chip. A processor may include one or more processing cores. The following embodiments are all described by taking multiple cores as an example. However, the file fragment evaluation method provided by the embodiments of the present invention may also be applied to a single core processor.
  • the memory 280 also stores other data 283 in addition to the computer program.
  • the other data 283 may include data generated by the operating system 282 or the application 281 after being run, the data including system data (eg, operating system configuration parameters) and User data, such as fragmentation information generated by the terminal reading metadata, can be regarded as user data.
  • Memory 280 typically includes memory and external memory.
  • the memory can be random access memory (RAM), read only memory (ROM), and cache (CACHE).
  • the external storage can be a hard disk, a CD, a USB disk, a floppy disk, or a tape drive.
  • Computer programs are typically stored on external storage, and the processor loads the computer program from external memory into memory before processing.
  • the fragmentation information in the embodiment of the present invention may be stored in the external storage. When the fragmentation information needs to be used or updated, the fragmentation information that needs to be used or updated may be first loaded into the memory.
  • the operating system program 282 includes a computer program that can implement the file fragment evaluation method provided by the embodiment of the present invention, so that after the processor 250 reads the operating system program 282 and runs the operating system, the operating system can have the present invention.
  • the evaluation file fragmentation feature provided by the embodiment.
  • the operating system can open the calling interface of the fragment evaluation function to the upper layer application, and after the processor 250 reads the application 281 from the memory 280 and runs the application, the application can invoke the operating system through the calling interface.
  • a fragment evaluation function is provided to enable fragmentation assessment of the file system.
  • the terminal 200 may further include an input device 230 for receiving input digital information, character information or contact touch/contactless gestures, and generating signal inputs related to user settings and function control of the terminal 200, and the like.
  • the input device 230 may include a touch panel 231.
  • the touch panel 231 also referred to as a touch screen, can collect touch operations on or near the user (such as the user's operation on the touch panel 231 or on the touch panel 231 using any suitable object or accessory such as a finger, a stylus, or the like. ), and drive the corresponding connection device according to a preset program.
  • the touch panel 231 can include two parts: a touch detection device and a touch controller.
  • the touch detection device detects the touch orientation of the user, and detects a signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts the touch information into contact coordinates, and sends the touch information.
  • the processor 250 is provided and can receive commands from the processor 250 and execute them. For example, the user clicks a virtual button on the touch panel 231 with a finger, and the touch detection device detects the signal brought by the click, and then transmits the signal to the touch control. The controller then converts the signal into coordinates and sends it to the processor 250.
  • the processor 250 performs the file fragment evaluation operation according to the coordinates and the type of the signal (click or double click), and finally displays the evaluation result on the display. On the panel 241.
  • the touch panel 231 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves.
  • the input device 230 may further include other input devices 232, which may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, switch buttons, etc.), trackballs, mice, joysticks, and the like. One or more of them.
  • the terminal 200 may further include a display device 240, including a display panel 241, for displaying information input by the user or information provided to the user, and various menu interfaces of the terminal 200, etc., which are mainly used in the embodiment of the present invention. Display the results of the fragment evaluation.
  • the display device 240 can include a display panel 241, which can be configured in the form of a liquid crystal display (LCD) or an organic light-emitting diode (English: Organic Light-Emitting Diode, OLED for short).
  • the touch panel 231 can cover the display panel 241 to form a touch display screen.
  • the terminal 200 may further include a power source 290 for supplying power to other modules and a camera 260 for taking a photo or video.
  • Terminal 200 may also include one or more sensors 220, such as acceleration sensors, light sensors, and the like.
  • the terminal 200 may further include a radio frequency (RF) circuit 210 for performing network communication with the wireless network device, and may further include a WiFi module 270 for performing WiFi communication with other devices.
  • RF radio frequency
  • FIG. 3 is a schematic flowchart of a method for evaluating a file fragment according to an embodiment of the present invention.
  • the method may be implemented by the terminal 20, and the processor 210 of the terminal 20 calls a program in the memory 220 to perform the following operations:
  • Terminal step S301 The file size information and the storage area number information of the each file obtained by the terminal by reading the metadata of each of the K files of the own file system.
  • the file system of the terminal has K files and each of the files has its own metadata, and the metadata of each file describes the file size of the file, the physical address of the storage area on the storage medium, and the like.
  • the K files are specifically file A, file B, and file C
  • the terminal needs to read the metadata of the file A to obtain the file size and the storage area of the file A, and the file B needs to be read.
  • the metadata obtains the file size and the number of storage areas of the file B, and the metadata of the file C needs to be read to obtain the file size and the storage area number of the file C.
  • the K files may be partial files or all files in the file system, and K is an integer greater than 0.
  • fragmentation information the collection of file size information and storage area number information of the K files may be referred to as fragmentation information; further, the fragmentation information may be stored in a specific file for subsequent use.
  • FIG. 4 is an optional format of the fragmentation information, where the fragmentation information is composed of a plurality of indexes (fraginfo), and each fragmentinfo corresponds to a file size information and an exten count information of a file.
  • the file size information and the data size of the storage area number information are not limited herein, and may be set to, for example, 4 bytes.
  • the specific files are distributed on a storage medium on a continuous storage area, that is, the “fraginfo” is continuous on the storage medium, and can improve input/output (English: Input/Output, IO for short) performance.
  • the user may have one of the K files.
  • Write operations for example, add, modify, etc.; after a write operation, the file size and number of storage areas of a certain file may change. In this case, the file size information and storage area after the change of the file is also required.
  • the quantity information is updated to this specific file for subsequent use.
  • the process of updating the fragmentation information in this particular file is as follows:
  • the terminal determines whether there is a write operation for the target file, and the target file is any one of the K files. If it is determined that there is a write operation for the target file, the terminal reads the metadata of the target file after the end of the write operation, and obtains the file size information and the storage area quantity information of the target file. The terminal updates the first file size information and the first storage area quantity information into the fragmentation information, where the first file size information is the target file obtained by reading the metadata of the target file after the end of the writing operation The file size information, the first storage area quantity information is the storage area quantity information of the target file obtained by reading the metadata of the target file after the end of the write operation. If there is no write operation for the target file, no update is performed.
  • the terminal After the terminal acquires the file size information and the storage area number information of each file, if the user subsequently writes to one of the files, the terminal reads the metadata of the certain file again to restart Obtaining the file size information and the storage area quantity information of the certain file and updating it into the fragmentation information, so that the correlation result calculated based on the fragmentation information is more accurate.
  • the terminal may read the metadata of the target file from the memory, and may also read the metadata of the target file from the storage medium; the embodiment of the present invention preferably is from the memory. Read the metadata of the target file, which can improve the efficiency of reading the metadata.
  • the terminal updates the first file size information and the first storage area quantity information to the fragment information, specifically: determining whether the first file size information and the second file size information are the same. And determining whether the first storage area quantity information is the same as the second storage area quantity information, the second file size information is the file size information of the target file in the fragmentation information, and the second storage area quantity information is the fragment The number of storage areas of the target file in the information.
  • the first file size information is different from the second file size information, and the first storage area quantity information is different from the second storage area quantity information, the first file size information is replaced by the second file size information, And replacing the first storage area quantity information with the second storage area quantity information.
  • the file size information and the storage area number information of the re-reading of the certain file are not immediately updated into the fragmentation information, but the judgment is first Obtaining the file size information and the storage area quantity information of the certain file and whether the file size information and the storage area quantity information of the certain file in the fragmentation information are the same, and if not, the file of the certain file to be reacquired
  • the size information and the storage area quantity information are updated into the fragmentation information, avoiding unnecessary updates.
  • FIG. 5 is a schematic diagram of a scenario for updating fragmentation information according to an embodiment of the present invention.
  • the process of updating fragmentation information is as follows:
  • Step A The user writes data to the target file in the file system by operating the terminal, for example, adding data to the target file.
  • Step B The terminal writes the changed data in the process of writing data to the disk.
  • Step C The terminal reads the metadata of the target file after the data is written, obtains the latest file size information and the storage area quantity information of the target file, and determines that the latest file size information and the storage area quantity information of the target file are compared with the already Whether the file size information and the storage area number information of the target file are changed; if there is a change, the latest file size information and the storage area quantity information are updated into the buffer area.
  • Step D The terminal periodically writes the file size information and the storage area quantity information of the target file in the buffer area to the specific file periodically (the period is usually several seconds). It can be understood that if the fragment information is refreshed at the end of each IO, the IO speed will be affected. Therefore, the fragment information is updated to the cache only at the end of the IO, and the background thread periodically drops the disk, which is reduced. Negative impact on IO speed. In addition, the terminal operating system may have a situation in which the information in the cache is lost due to abnormal power-off, but because the information cached in the cache is only changed within a few seconds, the information lost in the cache does not cause too much information in the specific file. Great negative impact. And the file size information and the storage area quantity information of the target file are generated again when the user performs a write operation on the target file next time, so the negative influence caused by the loss of information in the cache does not gradually expand.
  • Step E The terminal writes the file size information and the storage area quantity information of the target file in the specific file back to the disk.
  • Step S302 The terminal receives the input fragment evaluation instruction.
  • the user may input the fragment evaluation instruction by touching the touch display screen, pressing the physical button, voice control, gesture control, etc., and correspondingly, the terminal receives the input fragment evaluation instruction.
  • the fragment evaluation instruction is used to instruct the terminal to perform fragmentation evaluation on the files in the file system.
  • Step S303 The terminal reads the fragmentation information according to the fragment evaluation instruction.
  • the terminal reads the fragment information stored in the specific file according to the fragment evaluation instruction, and obtains file size information and storage area number information of each file. Since the fragmentation information has been generated before the terminal receives the fragment evaluation instruction, it is not necessary to read the metadata of each file to generate the fragmentation information.
  • the terminal can also periodically read the fragmentation information without receiving the fragmentation evaluation instruction input by the user and then reading the fragmentation information.
  • Step S304 The terminal evaluates the degree of fragmentation of the K files according to the file size information and the storage area quantity information.
  • the terminal may calculate a total fragmentation score based on the file size information and the storage area quantity information by using a preset algorithm, and measure the fragmentation degree of the K files by using the total size of the fragment, the K files.
  • the degree of fragmentation can be seen as the degree of fragmentation of the file system.
  • Step 1 Calculate the best storage area number best_extent_count for the target file by the following formula.
  • file_size is the file size of the target file
  • the size of BEST_EXTENT_LEN is related to the file system and the storage medium, that is, the BEST_EXTENT_LEN is a fixed value after the file system and the storage medium are determined.
  • the target file has the best read/write performance when the average storage area length (file_size)/(extent_count) of the target file is greater than or equal to BEST_EXTENT_LEN.
  • Step 2 Calculate the Fragment Score Score.
  • extent_count is the number of storage areas of the target file.
  • the meaning of the formula is: when the extent_count is less than or equal to best_extent_count, the fragment score of the target file is 0. When the extent_count is greater than best_extent_count, the fragment score of the target file is (extent_count-best_extent_count)*100/(extent_count).
  • related information generated during the evaluation process may be cached in memory, so that when an evaluation process is interrupted, the next evaluation may continue to be evaluated based on the cached information from where the evaluation was interrupted.
  • the terminal reads metadata of each file before receiving the fragment evaluation instruction to obtain file size information and storage area quantity information of each file, and saves the information in a specific file for reading;
  • the terminal directly reads the file size information and the storage area quantity information in the specific file, and evaluates the fragmentation degree of the file system based on the file size information and the storage area quantity information. That is to say, the terminal does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to evaluate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system.
  • FIG. 6 is a schematic structural diagram of a computer system 600 according to an embodiment of the present invention.
  • the computer system 600 can be applied to the above terminal.
  • the computer system includes an application layer 610, an operating system layer 620, and a hardware layer 630, which may be an Android operating system.
  • the application layer 610 in FIG. 6 can be considered as a specific implementation of the application 281 in FIG. 2.
  • the application layer 610 can include a fragment evaluation tool, an application market, a camera, a file manager, and the like.
  • the operating system layer 620 in FIG. 6 can be considered as a specific implementation of the operating system 282 in FIG. 2, and the operating system layer 620 includes a kernel layer, and further includes other layers such as a frame layer, since the embodiment of the present invention mainly relates to a file system. Change, so the kernel layer associated with the file system is mainly illustrated in Figure 6.
  • the kernel layer includes a file system abstraction layer (English: Virtual Filesystem, VFS) 621, a file system layer 622, a block device layer (English: BLOCK Layer) 623, and a driver layer 624. All file system commands are first passed through FVS 621. Sent to the corresponding file system in the file system layer 622, the mainstream file system has a flash file system (English: Flash Friendly File System, referred to as: F2FS), the fourth generation of extended file system (English: Fourth extended file system, referred to as: EXT4
  • the file device layer (623) is configured to receive an input/output IO command issued by the file system and submit it to the driver layer 624.
  • the driver layer 624 includes a disk drive, an embedded multimedia media card (Embedded Multi Media Card, eMMC for short), a solid state hard disk (English: Non-Volatile Memory, NVMe for short), and a central processing unit (English: Central Processing) Unit, referred to as: CPU) driver.
  • eMMC embedded Multi Media Card
  • NVMe Non-Volatile Memory
  • CPU Central Processing
  • the hardware layer 630 of the computer system 600 can include a magnetic disk, an eMMC, an NVMe, and a central processing unit. It may also include a memory (corresponding to the memory 280 in FIG. 2), including memory and external memory, and may also include a display device (corresponding to the display device 240 in FIG. 2), such as a liquid crystal display (English: Liquid Crystal Display, referred to as: LCD), Holographic, Projector, etc., may also include one or more sensors (equivalent to Sensor 220 in 2).
  • the hardware layer 630 may also include the power source, camera, RF circuit, and WiFi module shown in FIG. 2, and may also include other hardware modules not shown in FIG. 2, such as a memory controller and display control. And so on.
  • FIG. 7 is a schematic structural diagram of still another terminal 70 according to an embodiment of the present invention.
  • the terminal 70 may include a first reading unit 701 and an evaluation unit 702, wherein detailed descriptions of the respective units are as follows.
  • the first reading unit 701 is configured to read pre-stored fragment information according to the fragment evaluation instruction, where the fragment information includes the terminal obtained by reading metadata of each of the K files of the file system in advance.
  • File size information and storage area number information of each of the files, K is an integer greater than 0;
  • the evaluation unit 702 is configured to evaluate the degree of fragmentation of the K files according to the file size information and the storage area quantity information.
  • the terminal 70 reads the metadata of each file before receiving the fragment evaluation instruction to obtain file size information and storage area number information of each file, and saves the information in a specific file for reading; the terminal 70 is When receiving the fragment evaluation instruction, the file size information and the storage area quantity information in the specific file are directly read, and the fragmentation degree of the file system is evaluated based on the file size information and the storage area quantity information. That is to say, the terminal 70 does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to estimate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system. .
  • the terminal 70 further includes:
  • a second reading unit configured to: before the first reading unit reads the pre-stored fragment information, the file size information of each file obtained by reading the metadata of each file and The storage area quantity information.
  • the terminal 70 reads the file size information and the storage area number information of each file before the user inputs the fragment evaluation instruction to the terminal 70, so that when the file size information and the storage area quantity information are subsequently used, It can be used directly without having to read it, making it easier to use the file size information and the number of storage areas.
  • the terminal 70 further includes:
  • a third reading unit configured to determine that there is a write operation for the target file, and read metadata of the target file after the end of the writing operation according to the determined result, to obtain the file size information of the target file And the storage area quantity information, the target file is any one of the K files;
  • an updating unit configured to update the first file size information and the first storage area quantity information into the fragmentation information, where the first file size information is the target file read after the end of the writing operation
  • the file size information, the first storage area quantity information is the storage area quantity information of the target file read after the end of the write operation.
  • the terminal 70 obtains the file size information and the storage area number information of each file, if the user subsequently writes to one of the files, the terminal 70 reads the metadata of the certain file again. To re-acquire the file size information and the storage area quantity information of the certain file and update it into the fragmentation information, so that the correlation result calculated based on the fragmentation information is more accurate.
  • the updating unit is specifically configured to:
  • the file size information and the storage area number information of the re-reading of the certain file are not immediately updated to the fragmentation information, but the judgment is first Obtaining the file size information and the storage area quantity information of the certain file and whether the file size information and the storage area quantity information of the certain file in the fragmentation information are the same, and if not, the file of the certain file to be reacquired
  • the size information and the storage area quantity information are updated into the fragmentation information, avoiding unnecessary updates.
  • the fragmentation information is stored on the same storage area of the external storage of the terminal 70.
  • the terminal 70 when the fragment information is stored on the same storage area, the terminal 70 only needs to perform a read operation when reading the fragment information, thereby improving the input/output performance of the fragment information.
  • the specific implementation of the terminal 70 may also correspond to the corresponding description of the method embodiment shown in FIG. 3.
  • the terminal 70 reads the metadata of each file before receiving the fragment evaluation instruction to obtain file size information and storage area number information of each file, and saves the information in a specific file for reading.
  • the terminal 70 directly reads the file size information and the storage area quantity information in the specific file when receiving the fragment evaluation instruction, and evaluates the fragmentation degree of the file system based on the file size information and the storage area quantity information. That is to say, the terminal 70 does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to estimate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system. .
  • the terminal reads the metadata of each file before receiving the fragment evaluation instruction to obtain the file size information and the storage area quantity information of each file, and save the information in a specific file. Reading; when receiving the fragment evaluation instruction, the terminal directly reads the file size information and the storage area quantity information in the specific file, and evaluates the fragmentation degree of the file system based on the file size information and the storage area quantity information. That is to say, the terminal does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to evaluate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system.
  • the foregoing storage medium includes various media that can store program codes, such as a ROM, a RAM, a magnetic disk, or an optical disk.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A method for evaluating file fragments, and a terminal, the method comprising: the terminal acquires pre-stored fragment information, the fragment information comprising file size information and storage area quantity information of each file obtained by the terminal pre-reading the metadata of each file amongst K files in the file system of the terminal, K being an integer greater than 0; and, on the basis of the file size information and the storage area quantity information, the terminal evaluates the degree of fragmentation of the K files. The present method can improve the efficiency of evaluating the degree of fragmentation of the file system.

Description

一种文件碎片评估方法及终端File fragment evaluation method and terminal 技术领域Technical field
本发明涉及计算机技术领域,尤其涉及一种文件碎片评估方法及终端。The present invention relates to the field of computer technologies, and in particular, to a file fragment evaluation method and a terminal.
背景技术Background technique
文件在磁盘、Flash等存储介质中分散在众多不同的区域即为文件碎片,通常情况下,文件系统运行一段时间之后,文件系统中的文件在存储介质上被反复地添加和删除,从而导致存储介质上空闲的存储区域不再连续,如果再在该存储介质上存储文件,则该文件可能会分散在多个不连续的存储区域上,形成文件碎片。文件碎片化程度较严重时会导致文件读写性能下降,因此需要对该文件系统进行碎片整理从而改善文件读写性能。Files are scattered in many different areas on storage media such as disk and flash. File fragments are usually used. After a file system runs for a period of time, files in the file system are repeatedly added and deleted on the storage medium, resulting in storage. The free storage area on the media is no longer continuous. If the file is stored on the storage medium, the file may be scattered over multiple non-contiguous storage areas to form file fragments. File fragmentation is more serious, which leads to a decrease in file read and write performance. Therefore, the file system needs to be defragmented to improve file read and write performance.
在进行碎片整理之前需要先评估该文件系统的碎片化程度是否严重,若碎片化程度严重则执行碎片整理操作,评估碎片化程度是否严重的方式具体如下:该终端遍历该文件系统中的所有文件,读取该所有文件中每个文件的元数据以获得每个文件的文件大小和每个文件的存储区域的数量,该存储区域的数量越多则表明该存储介质上的文件所在的存储区域越分散。可以通过下发FS_IOC_FIEMAP命令来找到各个文件(每一个文件对应一个逻辑地址),并读取各个文件的元数据来获得每个文件的逻辑地址,逻辑地址的数量即为文件的存储区域的数量,如图1所示的地址地图(address map),每个文件在硬盘(disk)上都对应有至少一个存储区域。最后该终端基于每个文件的文件大小和每个文件的存储区域的数量来评估该文件系统的碎片化程度。一个存储介质为128G的存储介质进行一次碎片化程度的评估耗时1个多小时。Before defragmentation, you need to evaluate whether the fragmentation degree of the file system is serious. If the fragmentation degree is serious, perform the defragmentation operation to evaluate whether the fragmentation degree is serious. The terminal traverses all the files in the file system. Reading the metadata of each file in all the files to obtain the file size of each file and the number of storage areas of each file, and the more the number of storage areas, the storage area where the files on the storage medium are located The more dispersed. You can find each file (each file corresponds to a logical address) by issuing the FS_IOC_FIEMAP command, and read the metadata of each file to obtain the logical address of each file. The number of logical addresses is the number of storage areas of the file. As shown in the address map of FIG. 1, each file has at least one storage area on a disk. Finally, the terminal evaluates the fragmentation degree of the file system based on the file size of each file and the number of storage areas of each file. It takes more than one hour to evaluate the degree of fragmentation of a storage medium with a storage medium of 128G.
现有技术的缺陷在于,该终端在碎片评估过程中需要一一读取每个文件的元数据,读取元数据的次数较多耗时较长,导致碎片评估的效率较低。A disadvantage of the prior art is that the terminal needs to read the metadata of each file one by one in the process of fragment evaluation, and the number of times of reading the metadata is longer and longer, resulting in lower efficiency of fragment evaluation.
发明内容Summary of the invention
本发明实施例公开了一种文件碎片评估方法及终端,能够提高文件碎片评估的效率。The embodiment of the invention discloses a file fragment evaluation method and a terminal, which can improve the efficiency of file fragment evaluation.
第一方面,本发明实施例提供了一种文件碎片评估方法,该方法包括:当该终端要评估文件系统的碎片化程度时,直接读取预存的碎片信息,该碎片信息包括该终端预先通过读取自身文件系统的K个文件中的每个文件的元数据所得到的该每个文件的文件大小信息和存储区域数量信息,K为大于0的整数;然后,该终端根据该文件大小信息和该存储区域数量信息评估该K个文件的碎片化程度。该终端可以在接收到用户输入的触发指令时读取该碎片信息,也可以周期性地读取该碎片信息,当然,也不限于这两种方式。In a first aspect, an embodiment of the present invention provides a file fragment evaluation method, which includes: when the terminal evaluates a fragmentation degree of a file system, directly reading pre-stored fragment information, where the fragment information includes the terminal pre-passing The file size information and the storage area number information of each file obtained by reading the metadata of each of the K files of the own file system, K is an integer greater than 0; then, the terminal according to the file size information And the storage area quantity information evaluates the degree of fragmentation of the K files. The terminal may read the fragmentation information when receiving a trigger instruction input by the user, or may periodically read the fragmentation information, and is not limited to the two methods.
通过执行上述步骤,终端在接收碎片评估指令之前读取各个文件的元数据以得到各个文件的文件大小信息和存储区域数量信息,并将这些信息保存在特定文件中供读取;终端在接收到该碎片评估指令时直接读取该特定文件中的文件大小信息和存储区域数量信息,并基于该文件大小信息和存储区域数量信息评估文件系统的碎片化程度。也即是说,该终端从接收到该碎片评估指令到评估出文件系统的碎片化程度的过程中,无需一一读取各个文件的元数据,提高了评估文件系统的碎片化程度的效率。 By performing the above steps, the terminal reads the metadata of each file before receiving the fragment evaluation instruction to obtain the file size information and the storage area quantity information of each file, and saves the information in a specific file for reading; the terminal receives the The fragment evaluation instruction directly reads the file size information and the storage area quantity information in the specific file, and evaluates the fragmentation degree of the file system based on the file size information and the storage area quantity information. That is to say, the terminal does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to evaluate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system.
结合第一方面,在第一方面的第一种可能的实现方式中,该终端读取预存的碎片信息之前,该方法还包括:该终端通过读取该每个文件的元数据所得到的该每个文件的该文件大小信息和该存储区域数量信息。In conjunction with the first aspect, in a first possible implementation manner of the first aspect, before the terminal reads the pre-stored fragment information, the method further includes: obtaining, by the terminal, the metadata of each file The file size information of each file and the number of storage areas.
也即是说,在用户向终端输入碎片评估指令之前该终端读取每个文件的文件大小信息和存储区域数量信息,这样一来,后续要用该文件大小信息和存储区域数量信息时就可以直接用而无需再去读取,使得使用该文件大小信息和存储区域数量信息更加方便。That is to say, before the user inputs the fragment evaluation instruction to the terminal, the terminal reads the file size information and the storage area quantity information of each file, so that the file size information and the storage area quantity information are used later. It can be used directly without having to read it, making it easier to use the file size information and the number of storage areas.
结合第一方面,或者第一方面的第一种可能的实现方式,在第一方面的第二种可能的实现方式中,该方法还包括:该终端确定存在针对目标文件的写操作,并根据确定的结果在该写操作结束后读取该目标文件的元数据,得到该目标文件的该文件大小信息和该存储区域数量信息,该目标文件为该K个文件中的任意一个文件;该终端将第一文件大小信息和第一存储区域数量信息更新到该碎片信息中,该第一文件大小信息为在该写操作结束后读取的该目标文件的该文件大小信息,该第一存储区域数量信息为在该写操作结束后读取的该目标文件的该存储区域数量信息。确定是否有针对目标文件的写操作,可以发生在读取碎片信息之前,也可以发生在读取碎片信息之后。With reference to the first aspect, or the first possible implementation manner of the first aspect, in a second possible implementation manner of the first aspect, the method further includes: determining, by the terminal, that a write operation is performed for the target file, and Determining the result, reading the metadata of the target file after the end of the writing operation, obtaining the file size information of the target file and the quantity of the storage area, the target file being any one of the K files; the terminal Updating the first file size information and the first storage area quantity information into the fragmentation information, the first file size information being the file size information of the target file read after the end of the writing operation, the first storage area The quantity information is the number of pieces of the storage area of the target file read after the end of the write operation. Determining if there is a write operation to the target file can occur before the fragmentation information is read, or after the fragmentation information is read.
也即是说,终端获取每个文件的文件大小信息和存储区域数量信息之后,如果用户后续对其中某个文件进行了写操作,则该终端会再次读取该某个文件的元数据来重新获取该某个文件的文件大小信息和存储区域数量信息,并将其更新到该碎片信息中,使得基于该碎片信息计算的相关结果更加精确。That is to say, after the terminal acquires the file size information and the storage area number information of each file, if the user subsequently writes to one of the files, the terminal reads the metadata of the certain file again to restart Obtaining the file size information and the storage area quantity information of the certain file and updating it into the fragmentation information, so that the correlation result calculated based on the fragmentation information is more accurate.
结合第一方面的第二种可能的实现方式,在第一方面的第三种可能的实现方式中,该终端将第一文件大小信息和第一存储区域数量信息更新到该碎片信息中,包括:确定该第一文件大小信息与第二文件大小信息不同,且该第一存储区域数量信息与第二存储区域数量信息不同,并根据确定的结果将该第一文件大小信息替换该第二文件大小信息,以及将该第一存储区域数量信息替换该第二存储区域数量信息;该第二文件大小信息为该碎片信息中的该目标文件的该文件大小信息,该第二存储区域数量信息为该碎片信息中的该目标文件的该存储区域数量信息。In conjunction with the second possible implementation of the first aspect, in a third possible implementation manner of the first aspect, the terminal, the first file size information and the first storage area quantity information are updated to the fragment information, including Determining that the first file size information is different from the second file size information, and the first storage area quantity information is different from the second storage area quantity information, and replacing the first file size information with the second file according to the determined result. The size information, and the first storage area quantity information is replaced by the second storage area quantity information; the second file size information is the file size information of the target file in the fragmentation information, and the second storage area quantity information is The storage area quantity information of the target file in the fragmentation information.
也即是说,当判断出存在针对某个文件的写操作时,不是立即将重新读取的该某个文件的文件大小信息和存储区域数量信息更新到该碎片信息中,而是先判断重新获取该某个文件的文件大小信息和存储区域数量信息与该碎片信息中的该某个文件的文件大小信息和存储区域数量信息是否相同,若不相同才将重新获取的该某个文件的文件大小信息和存储区域数量信息更新到该碎片信息中,避免了不必要的更新。That is to say, when it is judged that there is a write operation for a certain file, the file size information and the storage area number information of the re-reading of the certain file are not immediately updated to the fragmentation information, but the judgment is first Obtaining the file size information and the storage area quantity information of the certain file and whether the file size information and the storage area quantity information of the certain file in the fragmentation information are the same, and if not, the file of the certain file to be reacquired The size information and the storage area quantity information are updated into the fragmentation information, avoiding unnecessary updates.
结合第一方面,或者第一方面的第一种可能的实现方式,或者第一方面的第二种可能的实现方式,或者第一方面的第三种可能的实现方式,在第一方面的第四种可能的实现方式中,该碎片信息存储在该终端的外存的同一个存储区域上。With reference to the first aspect, or the first possible implementation of the first aspect, or the second possible implementation of the first aspect, or the third possible implementation of the first aspect, in the first aspect In four possible implementations, the fragmentation information is stored on the same storage area of the terminal's external storage.
可以理解的是,当碎片信息存储在同一个存储区域上时,该终端在读取碎片信息时只需要做一次读操作即可,提高了该碎片信息的输入/输出性能。It can be understood that when the fragment information is stored in the same storage area, the terminal only needs to perform a read operation when reading the fragment information, thereby improving the input/output performance of the fragment information.
第二方面,本发明实施例提供一种终端,该终端包括处理器、存储器和用户接口,该存储器用于存储数据和程序;该处理器调用该存储器中的程序,用于执行如下操作:在要评估文件系统的碎片化程度时,直接读取预存的碎片信息,该碎片信息包括该终端预先通 过读取自身文件系统的K个文件中的每个文件的元数据所得到的该每个文件的文件大小信息和存储区域数量信息,K为大于0的整数;根据该文件大小信息和该存储区域数量信息评估该K个文件的碎片化程度。该终端可以在接收到用户输入的触发指令时读取该碎片信息,也可以周期性地读取该碎片信息,当然,也不限于这两种方式。In a second aspect, an embodiment of the present invention provides a terminal, where the terminal includes a processor, a memory, and a user interface, where the memory is used to store data and a program; the processor calls a program in the memory to perform the following operations: To evaluate the fragmentation degree of the file system, directly read the pre-stored fragment information, which includes the terminal in advance. The file size information and the storage area number information of each file obtained by reading the metadata of each of the K files of the own file system, K is an integer greater than 0; according to the file size information and the storage The area quantity information evaluates the degree of fragmentation of the K files. The terminal may read the fragmentation information when receiving a trigger instruction input by the user, or may periodically read the fragmentation information, and is not limited to the two methods.
通过执行上述操作,终端在接收碎片评估指令之前读取各个文件的元数据以得到各个文件的文件大小信息和存储区域数量信息,并将这些信息保存在特定文件中供读取;终端在接收到该碎片评估指令时直接读取该特定文件中的文件大小信息和存储区域数量信息,并基于该文件大小信息和存储区域数量信息评估文件系统的碎片化程度。也即是说,该终端从接收到该碎片评估指令到评估出文件系统的碎片化程度的过程中,无需一一读取各个文件的元数据,提高了评估文件系统的碎片化程度的效率。By performing the above operation, the terminal reads the metadata of each file before receiving the fragment evaluation instruction to obtain the file size information and the storage area quantity information of each file, and saves the information in a specific file for reading; the terminal receives The fragment evaluation instruction directly reads the file size information and the storage area quantity information in the specific file, and evaluates the fragmentation degree of the file system based on the file size information and the storage area quantity information. That is to say, the terminal does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to evaluate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system.
结合第二方面,在第二方面的第一种可能的实现方式中,该处理器还用于:在读取预存的碎片信息之前,通过读取该每个文件的元数据所得到的该每个文件的该文件大小信息和该存储区域数量信息。With reference to the second aspect, in a first possible implementation manner of the second aspect, the processor is further configured to: before reading the pre-stored fragment information, by reading the metadata of each file The file size information of the file and the number of storage areas.
也即是说,在用户向终端输入碎片评估指令之前该终端读取每个文件的文件大小信息和存储区域数量信息,这样一来,后续要用该文件大小信息和存储区域数量信息时就可以直接用而无需再去读取,使得使用该文件大小信息和存储区域数量信息更加方便。That is to say, before the user inputs the fragment evaluation instruction to the terminal, the terminal reads the file size information and the storage area quantity information of each file, so that the file size information and the storage area quantity information are used later. It can be used directly without having to read it, making it easier to use the file size information and the number of storage areas.
结合第二方面,或者第二方面的第一种可能的实现方式,在第二方面的第二种可能的实现方式中,该处理器还用于:确定存在针对目标文件的写操作,并根据确定的结果在该写操作结束后读取该目标文件的元数据,得到该目标文件的该文件大小信息和该存储区域数量信息,该目标文件为该K个文件中的任意一个文件;将第一文件大小信息和第一存储区域数量信息更新到该碎片信息中,该第一文件大小信息为在该写操作结束后读取的该目标文件的该文件大小信息,该第一存储区域数量信息为在该写操作结束后读取的该目标文件的该存储区域数量信息。确定是否有针对目标文件的写操作,可以发生在读取碎片信息之前,也可以发生在读取碎片信息之后。With reference to the second aspect, or the first possible implementation manner of the second aspect, in a second possible implementation manner of the second aspect, the processor is further configured to: determine that there is a write operation for the target file, and Determining the result, reading the metadata of the target file after the end of the writing operation, obtaining the file size information of the target file and the quantity of the storage area, the target file being any one of the K files; Updating the file size information and the first storage area quantity information to the fragmentation information, the first file size information being the file size information of the target file read after the end of the writing operation, the first storage area quantity information The amount of storage area information of the target file read after the end of the write operation. Determining if there is a write operation to the target file can occur before the fragmentation information is read, or after the fragmentation information is read.
也即是说,终端获取每个文件的文件大小信息和存储区域数量信息之后,如果用户后续对其中某个文件进行了写操作,则该终端会再次读取该某个文件的元数据来重新获取该某个文件的文件大小信息和存储区域数量信息,并将其更新到该碎片信息中,使得基于该碎片信息计算的相关结果更加精确。That is to say, after the terminal acquires the file size information and the storage area number information of each file, if the user subsequently writes to one of the files, the terminal reads the metadata of the certain file again to restart Obtaining the file size information and the storage area quantity information of the certain file and updating it into the fragmentation information, so that the correlation result calculated based on the fragmentation information is more accurate.
结合第二方面的第二种可能的实现方式,在第二方面的第三种可能的实现方式中,该处理器将第一文件大小信息和第一存储区域数量信息更新到该碎片信息中,具体为:确定该第一文件大小信息与第二文件大小信息不同,且该第一存储区域数量信息与第二存储区域数量信息不同,并根据确定的结果将该第一文件大小信息替换该第二文件大小信息,以及将该第一存储区域数量信息替换该第二存储区域数量信息;该第二文件大小信息为该碎片信息中的该目标文件的该文件大小信息,该第二存储区域数量信息为该碎片信息中的该目标文件的该存储区域数量信息。In conjunction with the second possible implementation of the second aspect, in a third possible implementation manner of the second aspect, the processor updates the first file size information and the first storage area quantity information to the fragment information, Specifically, the first file size information is different from the second file size information, and the first storage area quantity information is different from the second storage area quantity information, and the first file size information is replaced by the first result according to the determined result. The second file size information, and the first storage area quantity information is replaced by the second storage area quantity information; the second file size information is the file size information of the target file in the fragmentation information, and the second storage area number The information is the storage area quantity information of the target file in the fragmentation information.
也即是说,当判断出存在针对某个文件的写操作时,不是立即将重新读取的该某个文件的文件大小信息和存储区域数量信息更新到该碎片信息中,而是先判断重新获取该某个文件的文件大小信息和存储区域数量信息与该碎片信息中的该某个文件的文件大小信息和 存储区域数量信息是否相同,若不相同才将重新获取的该某个文件的文件大小信息和存储区域数量信息更新到该碎片信息中,避免了不必要的更新。That is to say, when it is judged that there is a write operation for a certain file, the file size information and the storage area number information of the re-reading of the certain file are not immediately updated to the fragmentation information, but the judgment is first Obtaining file size information and storage area quantity information of the file and file size information of the certain file in the fragmentation information Whether the storage area quantity information is the same, if not the same, the file size information and the storage area quantity information of the re-acquired file are updated to the fragmentation information, thereby avoiding unnecessary updates.
结合第二方面,或者第二方面的第一种可能的实现方式,或者第二方面的第二种可能的实现方式,或者第二方面的第三种可能的实现方式,在第二方面的第四种可能的实现方式中,该碎片信息存储在该终端的外存的同一个存储区域上。With reference to the second aspect, or the first possible implementation of the second aspect, or the second possible implementation of the second aspect, or the third possible implementation of the second aspect, in the second aspect In four possible implementations, the fragmentation information is stored on the same storage area of the terminal's external storage.
可以理解的是,当碎片信息存储在同一个存储区域上时,该终端在读取碎片信息时只需要做一次读操作即可,提高了该碎片信息的输入/输出性能。It can be understood that when the fragment information is stored in the same storage area, the terminal only needs to perform a read operation when reading the fragment information, thereby improving the input/output performance of the fragment information.
第三方面,本发明实施例提供一种终端,该终端包括:第一读取单元,用于在要评估文件系统的碎片化程度时,直接读取预存的碎片信息,该碎片信息包括该终端预先通过读取自身文件系统的K个文件中的每个文件的元数据所得到的该每个文件的文件大小信息和存储区域数量信息,K为大于0的整数;评估单元,用于根据该文件大小信息和该存储区域数量信息评估该K个文件的碎片化程度。该终端可以在接收到用户输入的触发指令时读取该碎片信息,也可以周期性地读取该碎片信息,当然,也不限于这两种方式。In a third aspect, an embodiment of the present invention provides a terminal, where the terminal includes: a first reading unit, configured to directly read pre-stored fragment information, where the fragment information includes the terminal, when the degree of fragmentation of the file system is to be evaluated. The file size information and the storage area number information of each file obtained by reading the metadata of each of the K files of the own file system, K is an integer greater than 0; the evaluation unit is configured to The file size information and the storage area quantity information evaluate the degree of fragmentation of the K files. The terminal may read the fragmentation information when receiving a trigger instruction input by the user, or may periodically read the fragmentation information, and is not limited to the two methods.
通过运行上述单元,终端在接收碎片评估指令之前读取各个文件的元数据以得到各个文件的文件大小信息和存储区域数量信息,并将这些信息保存在特定文件中供读取;终端在接收到该碎片评估指令时直接读取该特定文件中的文件大小信息和存储区域数量信息,并基于该文件大小信息和存储区域数量信息评估文件系统的碎片化程度。也即是说,该终端从接收到该碎片评估指令到评估出文件系统的碎片化程度的过程中,无需一一读取各个文件的元数据,提高了评估文件系统的碎片化程度的效率。By running the above unit, the terminal reads the metadata of each file before receiving the fragment evaluation instruction to obtain the file size information and the storage area quantity information of each file, and saves the information in a specific file for reading; the terminal receives the The fragment evaluation instruction directly reads the file size information and the storage area quantity information in the specific file, and evaluates the fragmentation degree of the file system based on the file size information and the storage area quantity information. That is to say, the terminal does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to evaluate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system.
结合第三方面,在第三方面的第一种可能的实现方式中,该终端还包括:第二读取单元,用于在该第一读取单元读取预存的碎片信息之前,通过读取该每个文件的元数据所得到的该每个文件的该文件大小信息和该存储区域数量信息。In conjunction with the third aspect, in a first possible implementation manner of the third aspect, the terminal further includes: a second reading unit, configured to read the pre-stored fragment information before the first reading unit reads the pre-stored fragment information The file size information of the each file obtained by the metadata of each file and the quantity information of the storage area.
也即是说,在用户向终端输入碎片评估指令之前该终端读取每个文件的文件大小信息和存储区域数量信息,这样一来,后续要用该文件大小信息和存储区域数量信息时就可以直接用而无需再去读取,使得使用该文件大小信息和存储区域数量信息更加方便。That is to say, before the user inputs the fragment evaluation instruction to the terminal, the terminal reads the file size information and the storage area quantity information of each file, so that the file size information and the storage area quantity information are used later. It can be used directly without having to read it, making it easier to use the file size information and the number of storage areas.
结合第三方面,或者第三方面的第一种可能的实现方式,在第三方面的第二种可能的实现方式中,该终端还包括:第三读取单元,用于确定存在针对目标文件的写操作,并根据确定的结果在该写操作结束后读取该目标文件的元数据,得到该目标文件的该文件大小信息和该存储区域数量信息,该目标文件为该K个文件中的任意一个文件;更新单元,用于将第一文件大小信息和第一存储区域数量信息更新到该碎片信息中,该第一文件大小信息为在该写操作结束后读取的该目标文件的该文件大小信息,该第一存储区域数量信息为在该写操作结束后读取的该目标文件的该存储区域数量信息。确定是否有针对目标文件的写操作,可以发生在读取碎片信息之前,也可以发生在读取碎片信息之后。With reference to the third aspect, or the first possible implementation manner of the third aspect, in a second possible implementation manner of the third aspect, the terminal further includes: a third reading unit, configured to determine that the target file exists a write operation, and reading the metadata of the target file after the end of the write operation according to the determined result, obtaining the file size information of the target file and the quantity of the storage area, where the target file is in the K files Any one of the files; an update unit, configured to update the first file size information and the first storage area quantity information into the fragmentation information, the first file size information being the target file read after the end of the write operation File size information, the first storage area quantity information is the storage area quantity information of the target file read after the end of the write operation. Determining if there is a write operation to the target file can occur before the fragmentation information is read, or after the fragmentation information is read.
也即是说,终端获取每个文件的文件大小信息和存储区域数量信息之后,如果用户后续对其中某个文件进行了写操作,则该终端会再次读取该某个文件的元数据来重新获取该某个文件的文件大小信息和存储区域数量信息,并将其更新到该碎片信息中,使得基于该碎片信息计算的相关结果更加精确。That is to say, after the terminal acquires the file size information and the storage area number information of each file, if the user subsequently writes to one of the files, the terminal reads the metadata of the certain file again to restart Obtaining the file size information and the storage area quantity information of the certain file and updating it into the fragmentation information, so that the correlation result calculated based on the fragmentation information is more accurate.
结合第三方面的第二种可能的实现方式,在第三方面的第三种可能的实现方式中,该 更新单元具体用于:确定该第一文件大小信息与第二文件大小信息不同,且该第一存储区域数量信息与第二存储区域数量信息不同,并根据确定的结果将该第一文件大小信息替换该第二文件大小信息,以及将该第一存储区域数量信息替换该第二存储区域数量信息;该第二文件大小信息为该碎片信息中的该目标文件的该文件大小信息,该第二存储区域数量信息为该碎片信息中的该目标文件的该存储区域数量信息。In conjunction with the second possible implementation of the third aspect, in a third possible implementation of the third aspect, The updating unit is configured to: determine that the first file size information is different from the second file size information, and the first storage area quantity information is different from the second storage area quantity information, and the first file size information is determined according to the determined result. Substituting the second file size information, and replacing the first storage area quantity information with the second storage area quantity information; the second file size information is the file size information of the target file in the fragmentation information, the second The storage area quantity information is the storage area quantity information of the target file in the fragmentation information.
也即是说,当判断出存在针对某个文件的写操作时,不是立即将重新读取的该某个文件的文件大小信息和存储区域数量信息更新到该碎片信息中,而是先判断重新获取该某个文件的文件大小信息和存储区域数量信息与该碎片信息中的该某个文件的文件大小信息和存储区域数量信息是否相同,若不相同才将重新获取的该某个文件的文件大小信息和存储区域数量信息更新到该碎片信息中,避免了不必要的更新。That is to say, when it is judged that there is a write operation for a certain file, the file size information and the storage area number information of the re-reading of the certain file are not immediately updated to the fragmentation information, but the judgment is first Obtaining the file size information and the storage area quantity information of the certain file and whether the file size information and the storage area quantity information of the certain file in the fragmentation information are the same, and if not, the file of the certain file to be reacquired The size information and the storage area quantity information are updated into the fragmentation information, avoiding unnecessary updates.
结合第三方面,或者第三方面的第一种可能的实现方式,或者第三方面的第二种可能的实现方式,或者第三方面的第三种可能的实现方式,在第三方面的第四种可能的实现方式中,该碎片信息存储在该终端的外存的同一个存储区域上。With reference to the third aspect, or the first possible implementation of the third aspect, or the second possible implementation of the third aspect, or the third possible implementation of the third aspect, in the third aspect In four possible implementations, the fragmentation information is stored on the same storage area of the terminal's external storage.
第四方面,本发明实施例中还提供一种计算机存储介质,该存储介质可以是非易失性的,即断电后内容不丢失。该存储介质中存储软件程序,该软件程序在被一个或多个处理器读取并执行时可实现第一方面或上述第一方面的任意一种实现方式提供的方法。In a fourth aspect, the embodiment of the present invention further provides a computer storage medium, which may be non-volatile, that is, the content is not lost after power off. The storage medium stores a software program that, when read and executed by one or more processors, implements the method provided by the first aspect or any one of the foregoing first aspects.
通过实施本发明实施例,终端在接收碎片评估指令之前读取各个文件的元数据以得到各个文件的文件大小信息和存储区域数量信息,并将这些信息保存在特定文件中供读取;终端在接收到该碎片评估指令时直接读取该特定文件中的文件大小信息和存储区域数量信息,并基于该文件大小信息和存储区域数量信息评估文件系统的碎片化程度。也即是说,该终端从接收到该碎片评估指令到评估出文件系统的碎片化程度的过程中,无需一一读取各个文件的元数据,提高了评估文件系统的碎片化程度的效率。By implementing the embodiment of the present invention, the terminal reads metadata of each file before receiving the fragment evaluation instruction to obtain file size information and storage area quantity information of each file, and saves the information in a specific file for reading; When receiving the fragment evaluation instruction, the file size information and the storage area quantity information in the specific file are directly read, and the fragmentation degree of the file system is evaluated based on the file size information and the storage area quantity information. That is to say, the terminal does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to evaluate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system.
附图说明DRAWINGS
下面将对背景技术或者实施例所需要使用的附图作简单地介绍。The drawings to be used in the background art or the embodiments will be briefly described below.
图1是本发明实施例提供的一种文件对应存储区域的场景示意图;FIG. 1 is a schematic diagram of a scenario corresponding to a file storage area according to an embodiment of the present disclosure;
图2是本发明实施例提供的一种终端的结构示意图;2 is a schematic structural diagram of a terminal according to an embodiment of the present invention;
图3是本发明实施例提供的一种文件碎片评估方法的流程示意图;3 is a schematic flowchart of a file fragment evaluation method according to an embodiment of the present invention;
图4是本发明实施例提供的一种碎片信息的格式示意图;4 is a schematic diagram of a format of fragmentation information according to an embodiment of the present invention;
图5是本发明实施例提供的一种更新碎片信息的场景示意图;FIG. 5 is a schematic diagram of a scenario for updating fragment information according to an embodiment of the present disclosure;
图6是本发明实施例提供的一种计算机系统的结构示意图;FIG. 6 is a schematic structural diagram of a computer system according to an embodiment of the present invention;
图7是本发明实施例提供的又一种终端的结构示意图。FIG. 7 is a schematic structural diagram of still another terminal according to an embodiment of the present invention.
具体实施方式detailed description
下面将结合本发明实施例中的附图对本发明实施例中的技术方案进行描述。The technical solutions in the embodiments of the present invention will be described below with reference to the accompanying drawings in the embodiments of the present invention.
本发明实施例提供的文件碎片评估方法主要应用于终端,该终端也可称之为用户设备(英文:User Equipment,简称:UE)、移动台(英文:Mobile Station,简称:MS)、移动终端(英文:Mobile Terminal)等,可选的,该终端可以具备经无线接入网(英文:Radio Access  Network,简称:RAN)与一个或多个核心网进行通信的能力,例如,终端可以是移动电话(或称为“蜂窝”电话)、或具有移动性质的计算机等,例如,终端还可以是便携式、袖珍式、手持式、计算机内置的或者车载的移动装置。应理解的是,除了终端以外,本发明实施例提供的文件碎片评估方法也可以应用于其他类型的计算机系统。The file fragment evaluation method provided by the embodiment of the present invention is mainly applied to a terminal, and the terminal may also be called a user equipment (English: User Equipment, abbreviated as: UE), a mobile station (English: Mobile Station, abbreviated as: MS), and a mobile terminal. (English: Mobile Terminal), etc., optional, the terminal can have a wireless access network (English: Radio Access Network, referred to as: RAN) The ability to communicate with one or more core networks, for example, the terminal may be a mobile phone (or "cellular" phone), or a computer with mobile nature, for example, the terminal may also be portable , pocket, handheld, computer built-in or in-vehicle mobile devices. It should be understood that the file fragment evaluation method provided by the embodiment of the present invention can be applied to other types of computer systems in addition to the terminal.
请参考图2,为本发明实施例应用的终端200的结构示意图。该终端200包括存储器280、处理器250以及显示设备240。存储器280存储计算机程序,该计算机程序包括操作系统程序282和应用程序281等。处理器250用于读取存储器280中的计算机程序,然后执行计算机程序定义的方法,例如处理器250读取操作系统程序282从而在该终端200上运行操作系统以及实现操作系统的各种功能,或读取一种或多种应用程序281,从而在该终端上运行应用。Please refer to FIG. 2 , which is a schematic structural diagram of a terminal 200 according to an embodiment of the present invention. The terminal 200 includes a memory 280, a processor 250, and a display device 240. The memory 280 stores a computer program including an operating system program 282, an application program 281, and the like. The processor 250 is configured to read a computer program in the memory 280 and then execute a computer program defined method, for example, the processor 250 reads the operating system program 282 to run an operating system on the terminal 200 and implement various functions of the operating system. Or one or more applications 281 are read to run the application on the terminal.
处理器250可以包括一个或多个处理器,例如,处理器250可以包括一个或多个中央处理器。当处理器250包括多个处理器时,这多个处理器可以集成在同一块芯片上,也可以各自为独立的芯片。一个处理器可以包括一个或多个处理核,以下实施例均以多核为例来介绍,但是本发明实施例提供的文件碎片评估方法也可以应用于单核处理器。 Processor 250 may include one or more processors, for example, processor 250 may include one or more central processors. When the processor 250 includes a plurality of processors, the plurality of processors may be integrated on the same chip, or may each be a separate chip. A processor may include one or more processing cores. The following embodiments are all described by taking multiple cores as an example. However, the file fragment evaluation method provided by the embodiments of the present invention may also be applied to a single core processor.
另外,存储器280还存储有除计算机程序之外的其他数据283,其他数据283可包括操作系统282或应用程序281被运行后产生的数据,该数据包括系统数据(例如操作系统的配置参数)和用户数据,例如终端读取元数据所生成的碎片信息可看作是用户数据。In addition, the memory 280 also stores other data 283 in addition to the computer program. The other data 283 may include data generated by the operating system 282 or the application 281 after being run, the data including system data (eg, operating system configuration parameters) and User data, such as fragmentation information generated by the terminal reading metadata, can be regarded as user data.
存储器280一般包括内存和外存。内存可以为随机存储器(RAM),只读存储器(ROM),以及高速缓存(CACHE)等。外存可以为硬盘、光盘、USB盘、软盘或磁带机等。计算机程序通常被存储在外存上,处理器在执行处理前会将计算机程序从外存加载到内存。本发明实施例中的碎片信息可以存储在外存上,当需要使用或者更新该碎片信息时,可以将该需要使用或者更新的那部分碎片信息先加载到内存。 Memory 280 typically includes memory and external memory. The memory can be random access memory (RAM), read only memory (ROM), and cache (CACHE). The external storage can be a hard disk, a CD, a USB disk, a floppy disk, or a tape drive. Computer programs are typically stored on external storage, and the processor loads the computer program from external memory into memory before processing. The fragmentation information in the embodiment of the present invention may be stored in the external storage. When the fragmentation information needs to be used or updated, the fragmentation information that needs to be used or updated may be first loaded into the memory.
操作系统程序282中包含了可实现本发明实施例提供的文件碎片评估方法的计算机程序,从而使得处理器250读取到该操作系统程序282并运行该操作系统后,该操作系统可具备本发明实施例提供的评估文件碎片功能。进一步的,该操作系统可以向上层的应用开放该碎片评估功能的调用接口,处理器250从存储器中280中读取应用程序281并运行该应用后,该应用就可以通过该调用接口调用操作系统中提供的碎片评估功能,从而实现对文件系统的碎片评估。The operating system program 282 includes a computer program that can implement the file fragment evaluation method provided by the embodiment of the present invention, so that after the processor 250 reads the operating system program 282 and runs the operating system, the operating system can have the present invention. The evaluation file fragmentation feature provided by the embodiment. Further, the operating system can open the calling interface of the fragment evaluation function to the upper layer application, and after the processor 250 reads the application 281 from the memory 280 and runs the application, the application can invoke the operating system through the calling interface. A fragment evaluation function is provided to enable fragmentation assessment of the file system.
终端200还可以包括输入设备230,用于接收输入的数字信息、字符信息或接触式触摸操作/非接触式手势,以及产生与终端200的用户设置以及功能控制有关的信号输入等。具体地,本发明实施例中,该输入设备230可以包括触控面板231。触控面板231,也称为触摸屏,可收集用户在其上或附近的触摸操作(比如用户使用手指、触笔等任何适合的物体或附件在触控面板231上或在触控面板231的操作),并根据预先设定的程式驱动相应的连接装置。可选的,触控面板231可包括触摸检测装置和触摸控制器两个部分。其中,触摸检测装置检测用户的触摸方位,并检测触摸操作带来的信号,将信号传送给触摸控制器;触摸控制器从触摸检测装置上接收触摸信息,并将它转换成触点坐标,再送给该处理器250,并能接收处理器250发来的命令并加以执行。例如,用户在触控面板231上用手指单击某个虚拟按钮,触摸检测装置检测到此次单击带来的这个信号,然后将该信号传送给触摸控 制器,触摸控制器再将这个信号转换成坐标发送给处理器250,处理器250根据该坐标和该信号的类型(单击或双击)执行文件碎片评估的操作,最后将评估结果显示在显示面板241上。The terminal 200 may further include an input device 230 for receiving input digital information, character information or contact touch/contactless gestures, and generating signal inputs related to user settings and function control of the terminal 200, and the like. Specifically, in the embodiment of the present invention, the input device 230 may include a touch panel 231. The touch panel 231, also referred to as a touch screen, can collect touch operations on or near the user (such as the user's operation on the touch panel 231 or on the touch panel 231 using any suitable object or accessory such as a finger, a stylus, or the like. ), and drive the corresponding connection device according to a preset program. Optionally, the touch panel 231 can include two parts: a touch detection device and a touch controller. Wherein, the touch detection device detects the touch orientation of the user, and detects a signal brought by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device, converts the touch information into contact coordinates, and sends the touch information. The processor 250 is provided and can receive commands from the processor 250 and execute them. For example, the user clicks a virtual button on the touch panel 231 with a finger, and the touch detection device detects the signal brought by the click, and then transmits the signal to the touch control. The controller then converts the signal into coordinates and sends it to the processor 250. The processor 250 performs the file fragment evaluation operation according to the coordinates and the type of the signal (click or double click), and finally displays the evaluation result on the display. On the panel 241.
触控面板231可以采用电阻式、电容式、红外线以及表面声波等多种类型实现。除了触控面板231,输入设备230还可以包括其他输入设备232,其他输入设备232可以包括但不限于物理键盘、功能键(比如音量控制按键、开关按键等)、轨迹球、鼠标、操作杆等中的一种或多种。The touch panel 231 can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic waves. In addition to the touch panel 231, the input device 230 may further include other input devices 232, which may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, switch buttons, etc.), trackballs, mice, joysticks, and the like. One or more of them.
终端200还可以包括显示设备240,显示设备240,包括显示面板241,用于显示由用户输入的信息或提供给用户的信息以及终端200的各种菜单界面等,在本发明实施例中主要用于显示碎片评估结果。该显示设备240可包括显示面板241,可选的,可以采用液晶显示器(英文:Liquid Crystal Display,简称:LCD)或有机发光二极管(英文:Organic Light-Emitting Diode,简称:OLED)等形式来配置显示面板241。在其他一些实施例中,触控面板231可覆盖显示面板241上,形成触摸显示屏。The terminal 200 may further include a display device 240, including a display panel 241, for displaying information input by the user or information provided to the user, and various menu interfaces of the terminal 200, etc., which are mainly used in the embodiment of the present invention. Display the results of the fragment evaluation. The display device 240 can include a display panel 241, which can be configured in the form of a liquid crystal display (LCD) or an organic light-emitting diode (English: Organic Light-Emitting Diode, OLED for short). The display panel 241. In some other embodiments, the touch panel 231 can cover the display panel 241 to form a touch display screen.
除以上之外,终端200还可以包括用于给其他模块供电的电源290以及用于拍摄照片或视频的摄像头260。终端200还可以包括一个或多个传感器220,例如加速度传感器、光传感器等。终端200还可以包括无线射频(Radio Frequency,RF)电路210,用于与无线网络设备进行网络通信,还可以包括WiFi模块270,用于与其他设备进行WiFi通信。In addition to the above, the terminal 200 may further include a power source 290 for supplying power to other modules and a camera 260 for taking a photo or video. Terminal 200 may also include one or more sensors 220, such as acceleration sensors, light sensors, and the like. The terminal 200 may further include a radio frequency (RF) circuit 210 for performing network communication with the wireless network device, and may further include a WiFi module 270 for performing WiFi communication with other devices.
图3是本发明实施例提供的一种文件碎片评估方法的流程示意图,该方法可以由上述终端20来实现,该终端20的处理器210调用存储器220中的程序,执行如下操作:FIG. 3 is a schematic flowchart of a method for evaluating a file fragment according to an embodiment of the present invention. The method may be implemented by the terminal 20, and the processor 210 of the terminal 20 calls a program in the memory 220 to perform the following operations:
终端步骤S301:终端通过读取自身文件系统的K个文件中的每个文件的元数据所得到的该每个文件的文件大小信息和存储区域数量信息。Terminal step S301: The file size information and the storage area number information of the each file obtained by the terminal by reading the metadata of each of the K files of the own file system.
具体地,该终端的文件系统中有K个文件且其中每个文件都有自己的元数据,每个文件的元数据描述了该文件的文件大小、在存储介质上的存储区域的物理地址等信息,通过该物理地址信息即可获知该文件在该存储介质上分散在几个存储区域上,也即是说,通过读取每个文件的元数据可以获得每个文件各自的文件大小信息和存储区域数量信息。举例来说,假设这K个文件具体为文件A、文件B和文件C,那么该终端需要读取该文件A的元数据得到该文件A的文件大小和存储区域数量,需要读取该文件B的元数据得到该文件B的文件大小和存储区域数量,需要读取该文件C的元数据得到该文件C的文件大小和存储区域数量。另外,该K个文件可以为该文件系统中的部分文件或全部文件,K为大于0的整数。Specifically, the file system of the terminal has K files and each of the files has its own metadata, and the metadata of each file describes the file size of the file, the physical address of the storage area on the storage medium, and the like. Information, through the physical address information, that the file is distributed on several storage areas on the storage medium, that is, by reading the metadata of each file, the file size information of each file can be obtained and Storage area quantity information. For example, if the K files are specifically file A, file B, and file C, the terminal needs to read the metadata of the file A to obtain the file size and the storage area of the file A, and the file B needs to be read. The metadata obtains the file size and the number of storage areas of the file B, and the metadata of the file C needs to be read to obtain the file size and the storage area number of the file C. In addition, the K files may be partial files or all files in the file system, and K is an integer greater than 0.
为了方便描述,可以称这K个文件的文件大小信息和存储区域数量信息的集合为碎片信息;进一步地,可以将该碎片信息存放到一个特定文件中以供后续使用。图4为该碎片信息的一种可选的格式,该碎片信息由多个索引(fraginfo)组成,每个fraginfo对应封装一个文件的文件大小(file size)信息和存储区域数量(exten count)信息,该文件大小信息和该存储区域数量信息的数据大小此处不作限定,例如,可以设定为4个字节(byte)。可选的,该特定文件在存储介质上分布于一块连续的存储区域上,即这些“fraginfo”在存储介质上连续,能够提升输入/输出(英文:Input/Output,简称:IO)性能。For convenience of description, the collection of file size information and storage area number information of the K files may be referred to as fragmentation information; further, the fragmentation information may be stored in a specific file for subsequent use. FIG. 4 is an optional format of the fragmentation information, where the fragmentation information is composed of a plurality of indexes (fraginfo), and each fragmentinfo corresponds to a file size information and an exten count information of a file. The file size information and the data size of the storage area number information are not limited herein, and may be set to, for example, 4 bytes. Optionally, the specific files are distributed on a storage medium on a continuous storage area, that is, the “fraginfo” is continuous on the storage medium, and can improve input/output (English: Input/Output, IO for short) performance.
可选的,该碎片信息存储在该特定文件中后,用户可能对上述K个文件中的某个文件 做写操作,例如,添加、修改等;在做写操作之后该某个文件的文件大小、存储区域数量等信息可能发生变,此时也需要将该某文件变化后的文件大小信息和存储区域数量信息更新到该特定文件中供后续使用。对该特定文件中的碎片信息进行更新的过程如下:Optionally, after the fragment information is stored in the specific file, the user may have one of the K files. Write operations, for example, add, modify, etc.; after a write operation, the file size and number of storage areas of a certain file may change. In this case, the file size information and storage area after the change of the file is also required. The quantity information is updated to this specific file for subsequent use. The process of updating the fragmentation information in this particular file is as follows:
该终端判断是否存在针对目标文件的写操作,该目标文件为该K个文件中的任意一个文件。若确定存在针对该目标文件的写操作,则该终端在该写操作结束后读取该目标文件的元数据,得到该目标文件的该文件大小信息和该存储区域数量信息。该终端将第一文件大小信息和第一存储区域数量信息更新到该碎片信息中,该第一文件大小信息为在该写操作结束后通过读取该目标文件的元数据得到的该目标文件的该文件大小信息,该第一存储区域数量信息为在该写操作结束后通过读取该目标文件的元数据得到的该目标文件的该存储区域数量信息。若不存在针对该目标文件的写操作,则不进行更新。也即是说,终端获取每个文件的文件大小信息和存储区域数量信息之后,如果用户后续对其中某个文件进行了写操作,则该终端会再次读取该某个文件的元数据来重新获取该某个文件的文件大小信息和存储区域数量信息,并将其更新到该碎片信息中,使得基于该碎片信息计算的相关结果更加精确。The terminal determines whether there is a write operation for the target file, and the target file is any one of the K files. If it is determined that there is a write operation for the target file, the terminal reads the metadata of the target file after the end of the write operation, and obtains the file size information and the storage area quantity information of the target file. The terminal updates the first file size information and the first storage area quantity information into the fragmentation information, where the first file size information is the target file obtained by reading the metadata of the target file after the end of the writing operation The file size information, the first storage area quantity information is the storage area quantity information of the target file obtained by reading the metadata of the target file after the end of the write operation. If there is no write operation for the target file, no update is performed. That is to say, after the terminal acquires the file size information and the storage area number information of each file, if the user subsequently writes to one of the files, the terminal reads the metadata of the certain file again to restart Obtaining the file size information and the storage area quantity information of the certain file and updating it into the fragmentation information, so that the correlation result calculated based on the fragmentation information is more accurate.
需要说明的是,该终端在该写操作结束后可以从内存中读取该目标文件的元数据,也可以从该存储介质中读取该目标文件的元数据;本发明实施例优选从内存中读取该目标文件的元数据,这样可以提高读取该元数据的效率。It should be noted that, after the end of the write operation, the terminal may read the metadata of the target file from the memory, and may also read the metadata of the target file from the storage medium; the embodiment of the present invention preferably is from the memory. Read the metadata of the target file, which can improve the efficiency of reading the metadata.
在一种可选的方案中,该终端将第一文件大小信息和第一存储区域数量信息更新到该碎片信息中,具体为:判断该第一文件大小信息与第二文件大小信息是否相同,以及判断该第一存储区域数量信息与第二存储区域数量信息是否相同,该第二文件大小信息为该碎片信息中的该目标文件的该文件大小信息,该第二存储区域数量信息为该碎片信息中的该目标文件的该存储区域数量信息。当该第一文件大小信息与该第二文件大小信息不同,且该第一存储区域数量信息与该第二存储区域数量信息不同时,将该第一文件大小信息替换该第二文件大小信息,以及将该第一存储区域数量信息替换该第二存储区域数量信息。也即是说,当确定出存在针对某个文件的写操作时,不是立即将重新读取的该某个文件的文件大小信息和存储区域数量信息更新到该碎片信息中,而是先判断重新获取该某个文件的文件大小信息和存储区域数量信息与该碎片信息中的该某个文件的文件大小信息和存储区域数量信息是否相同,若不相同才将重新获取的该某个文件的文件大小信息和存储区域数量信息更新到该碎片信息中,避免了不必要的更新。In an optional solution, the terminal updates the first file size information and the first storage area quantity information to the fragment information, specifically: determining whether the first file size information and the second file size information are the same. And determining whether the first storage area quantity information is the same as the second storage area quantity information, the second file size information is the file size information of the target file in the fragmentation information, and the second storage area quantity information is the fragment The number of storage areas of the target file in the information. When the first file size information is different from the second file size information, and the first storage area quantity information is different from the second storage area quantity information, the first file size information is replaced by the second file size information, And replacing the first storage area quantity information with the second storage area quantity information. That is to say, when it is determined that there is a write operation for a certain file, the file size information and the storage area number information of the re-reading of the certain file are not immediately updated into the fragmentation information, but the judgment is first Obtaining the file size information and the storage area quantity information of the certain file and whether the file size information and the storage area quantity information of the certain file in the fragmentation information are the same, and if not, the file of the certain file to be reacquired The size information and the storage area quantity information are updated into the fragmentation information, avoiding unnecessary updates.
图5是本发明实施例提供的一种更新碎片信息的场景示意图,更新碎片信息的过程如下:FIG. 5 is a schematic diagram of a scenario for updating fragmentation information according to an embodiment of the present invention. The process of updating fragmentation information is as follows:
步骤A:用户通过操作该终端来对文件系统中的目标文件写数据,例如,向该目标文件中添加数据。Step A: The user writes data to the target file in the file system by operating the terminal, for example, adding data to the target file.
步骤B:该终端将写数据过程中变化的数据回写到磁盘上。Step B: The terminal writes the changed data in the process of writing data to the disk.
步骤C:该终端读取写数据后的目标文件的元数据,获得该目标文件最新的文件大小信息和存储区域数量信息;判断该目标文件最新的文件大小信息和存储区域数量信息相较于已经记录的该目标文件的文件大小信息和存储区域数量信息是否有变化;若有变化,则将该最新的文件大小信息和存储区域数量信息更新到缓存区中。 Step C: The terminal reads the metadata of the target file after the data is written, obtains the latest file size information and the storage area quantity information of the target file, and determines that the latest file size information and the storage area quantity information of the target file are compared with the already Whether the file size information and the storage area number information of the target file are changed; if there is a change, the latest file size information and the storage area quantity information are updated into the buffer area.
步骤D:该终端周期性地(周期通常为几秒)将缓存区中目标文件的文件大小信息和存储区域数量信息回写到该特定文件中。可以理解的是,若在每次IO结束的时候都对碎片信息刷新则会影响到IO速度,因此只在IO结束时将碎片信息更新到缓存中,由后台线程周期性下盘,减小了对IO速度的负面影响。另外,终端操作系统可能存在异常下电导致缓存中的信息丢失的情况,但因缓存数据缓存的只是几秒内的信息变化,因此缓存中的信息丢失不会对该特定文件中的信息造成太大负面影响。并且该目标文件的的文件大小信息和存储区域数量信息会在用户下次对该目标文件执行写操作时再次生成,因此缓存中的信息丢失造成的负面影响不会逐渐扩大。Step D: The terminal periodically writes the file size information and the storage area quantity information of the target file in the buffer area to the specific file periodically (the period is usually several seconds). It can be understood that if the fragment information is refreshed at the end of each IO, the IO speed will be affected. Therefore, the fragment information is updated to the cache only at the end of the IO, and the background thread periodically drops the disk, which is reduced. Negative impact on IO speed. In addition, the terminal operating system may have a situation in which the information in the cache is lost due to abnormal power-off, but because the information cached in the cache is only changed within a few seconds, the information lost in the cache does not cause too much information in the specific file. Great negative impact. And the file size information and the storage area quantity information of the target file are generated again when the user performs a write operation on the target file next time, so the negative influence caused by the loss of information in the cache does not gradually expand.
步骤E:该终端将该特定文件中的该目标文件的文件大小信息和存储区域数量信息回写到磁盘上。Step E: The terminal writes the file size information and the storage area quantity information of the target file in the specific file back to the disk.
步骤S302:终端接收输入的碎片评估指令。Step S302: The terminal receives the input fragment evaluation instruction.
具体地,用户可以通过触控触摸显示屏、按压物理按键、声控、手势控制等方式来输入该碎片评估指令,相应地,该终端接收输入的该碎片评估指令。该碎片评估指令用于指示该终端对该文件系统中的文件进行碎片评估。Specifically, the user may input the fragment evaluation instruction by touching the touch display screen, pressing the physical button, voice control, gesture control, etc., and correspondingly, the terminal receives the input fragment evaluation instruction. The fragment evaluation instruction is used to instruct the terminal to perform fragmentation evaluation on the files in the file system.
步骤S303:该终端根据该碎片评估指令读取碎片信息。Step S303: The terminal reads the fragmentation information according to the fragment evaluation instruction.
具体地,该终端根据该碎片评估指令读取存储在特定文件中的碎片信息,获得每个文件的文件大小信息和存储区域数量信息。由于该碎片信息在该终端接收到该碎片评估指令之前就已经生成了,因此不需要再去读取各个文件的元数据来生成该碎片信息。该终端还可以周期性地读取该碎片信息,而不需要在接收到用户输入的碎片评估指令再读取该碎片信息。Specifically, the terminal reads the fragment information stored in the specific file according to the fragment evaluation instruction, and obtains file size information and storage area number information of each file. Since the fragmentation information has been generated before the terminal receives the fragment evaluation instruction, it is not necessary to read the metadata of each file to generate the fragmentation information. The terminal can also periodically read the fragmentation information without receiving the fragmentation evaluation instruction input by the user and then reading the fragmentation information.
步骤S304:该终端根据该文件大小信息和该存储区域数量信息评估该K个文件的碎片化程度。Step S304: The terminal evaluates the degree of fragmentation of the K files according to the file size information and the storage area quantity information.
具体地,该终端可以通过预设算法基于该文件大小信息和该存储区域数量信息计算出一个碎片总分,并用该碎片总分的大小来衡量该K个文件的碎片化程度,该K个文件的碎片化程度即可看作该文件系统的碎片化程度。Specifically, the terminal may calculate a total fragmentation score based on the file size information and the storage area quantity information by using a preset algorithm, and measure the fragmentation degree of the K files by using the total size of the fragment, the K files. The degree of fragmentation can be seen as the degree of fragmentation of the file system.
为了方便理解,以下提供计算该碎片分数的一种可选的方式,先计算该K个文件中每个文件的碎片分数,再结合每个文件的碎片分数计算该碎片总分,计算单个文件(目标文件)的碎片分数的过程如下:For ease of understanding, the following provides an alternative way of calculating the fragment score. First, calculate the fragment score of each of the K files, and then calculate the total score of the fragment by combining the fragment score of each file to calculate a single file ( The process of fragmentation scores for the target file is as follows:
第一步:通过以下公式计算目标文件的最佳存储区域数量best_extent_count。Step 1: Calculate the best storage area number best_extent_count for the target file by the following formula.
Figure PCTCN2017075178-appb-000001
Figure PCTCN2017075178-appb-000001
在公式1-1中,file_size为该目标文件的文件大小,BEST_EXTENT_LEN的大小与该文件系统和存储介质有关,即该文件系统和存储介质确定后该BEST_EXTENT_LEN就为定值。目标文件的平均存储区域长度(file_size)/(extent_count)大于等于BEST_EXTENT_LEN时,该目标文件的读写性能最佳。In Equation 1-1, file_size is the file size of the target file, and the size of BEST_EXTENT_LEN is related to the file system and the storage medium, that is, the BEST_EXTENT_LEN is a fixed value after the file system and the storage medium are determined. The target file has the best read/write performance when the average storage area length (file_size)/(extent_count) of the target file is greater than or equal to BEST_EXTENT_LEN.
第二步:计算碎片分数Score。 Step 2: Calculate the Fragment Score Score.
Figure PCTCN2017075178-appb-000002
Figure PCTCN2017075178-appb-000002
在公式1-2中,extent_count为目标文件的存储区域数量,该公式的含义为:当extent_count小于或等于best_extent_count时该目标文件的碎片分数为0,当extent_count大于best_extent_count时该目标文件的碎片分数为(extent_count-best_extent_count)*100/(extent_count)。In Equation 1-2, extent_count is the number of storage areas of the target file. The meaning of the formula is: when the extent_count is less than or equal to best_extent_count, the fragment score of the target file is 0. When the extent_count is greater than best_extent_count, the fragment score of the target file is (extent_count-best_extent_count)*100/(extent_count).
可选的,评估过程中产生的相关信息可以缓存在内存中,因此某次评估过程被打断时,下次评估可以基于缓存的信息从评估被打断的位置继续往下评估。Optionally, related information generated during the evaluation process may be cached in memory, so that when an evaluation process is interrupted, the next evaluation may continue to be evaluated based on the cached information from where the evaluation was interrupted.
在图3所描述的方法中,终端在接收碎片评估指令之前读取各个文件的元数据以得到各个文件的文件大小信息和存储区域数量信息,并将这些信息保存在特定文件中供读取;终端在接收到该碎片评估指令时直接读取该特定文件中的文件大小信息和存储区域数量信息,并基于该文件大小信息和存储区域数量信息评估文件系统的碎片化程度。也即是说,该终端从接收到该碎片评估指令到评估出文件系统的碎片化程度的过程中,无需一一读取各个文件的元数据,提高了评估文件系统的碎片化程度的效率。In the method described in FIG. 3, the terminal reads metadata of each file before receiving the fragment evaluation instruction to obtain file size information and storage area quantity information of each file, and saves the information in a specific file for reading; When receiving the fragment evaluation instruction, the terminal directly reads the file size information and the storage area quantity information in the specific file, and evaluates the fragmentation degree of the file system based on the file size information and the storage area quantity information. That is to say, the terminal does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to evaluate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system.
以上主要介绍了本发明实施例提供的方法的具体流程,下面结合图6以Android操作系统为例,介绍本发明实施例提供的方法的实现位置和运行时状态,更具体的方法流程可参考前述实施例所述。The foregoing is a description of the specific process of the method provided by the embodiment of the present invention. The implementation of the method and the runtime state of the method provided by the embodiment of the present invention are described below with reference to FIG. As described in the examples.
请参阅图6,为本发明实施例提供的计算机系统600的结构示意图。该计算机系统600可以应用于上述终端。该计算机系统包括应用层610、操作系统层620和硬件层630,该操作系统可以为安卓(Android)操作系统。图6中的应用层610可以认为是图2中应用程序281的一种具体实现,应用层610可包括碎片评估工具、应用市场、相机以及文件管理器等。图6中的操作系统层620可以认为是图2中操作系统282的一种具体实现,操作系统层620包括内核层,还包括框架层等其他层,由于本发明实施例主要涉及到文件系统的改变,因此图6中主要示意了与文件系统相关的内核层。FIG. 6 is a schematic structural diagram of a computer system 600 according to an embodiment of the present invention. The computer system 600 can be applied to the above terminal. The computer system includes an application layer 610, an operating system layer 620, and a hardware layer 630, which may be an Android operating system. The application layer 610 in FIG. 6 can be considered as a specific implementation of the application 281 in FIG. 2. The application layer 610 can include a fragment evaluation tool, an application market, a camera, a file manager, and the like. The operating system layer 620 in FIG. 6 can be considered as a specific implementation of the operating system 282 in FIG. 2, and the operating system layer 620 includes a kernel layer, and further includes other layers such as a frame layer, since the embodiment of the present invention mainly relates to a file system. Change, so the kernel layer associated with the file system is mainly illustrated in Figure 6.
内核层包括文件系统抽象层(英文:Virtual Filesystem,简称:VFS)621、文件系统层622、块设备层(英文:BLOCK Layer)623和驱动层624,所有的文件系统命令都会先经过FVS 621再发送到该文件系统层622中相应的文件系统,主流的文件系统有flash文件系统(英文:Flash Friendly File System,简称:F2FS)、第四代扩展文件系统(英文:Fourth extended filesystem,简称:EXT4)、日志文件系统(XFS)等,块设备层623用于接收文件系统下发的输入/输出IO命令并提交给到驱动层624。驱动层624包括磁盘驱动、嵌入式多媒体存储卡(英文:Embedded Multi Media Card,简称:eMMC)驱动、固态硬盘(英文:Non-Volatile Memory,简称:NVMe)驱动以及中央处理器(英文:Central Processing Unit,简称:CPU)驱动等。The kernel layer includes a file system abstraction layer (English: Virtual Filesystem, VFS) 621, a file system layer 622, a block device layer (English: BLOCK Layer) 623, and a driver layer 624. All file system commands are first passed through FVS 621. Sent to the corresponding file system in the file system layer 622, the mainstream file system has a flash file system (English: Flash Friendly File System, referred to as: F2FS), the fourth generation of extended file system (English: Fourth extended file system, referred to as: EXT4 The file device layer (623) is configured to receive an input/output IO command issued by the file system and submit it to the driver layer 624. The driver layer 624 includes a disk drive, an embedded multimedia media card (Embedded Multi Media Card, eMMC for short), a solid state hard disk (English: Non-Volatile Memory, NVMe for short), and a central processing unit (English: Central Processing) Unit, referred to as: CPU) driver.
该计算机系统600的硬件层630可以包括磁盘、eMMC、NVMe以及中央处理器。还可以包括存储器(相当于图2中的存储器280),包括内存和外存,还可以包括显示设备(相当于图2中的显示设备240),例如液晶显示器(英文:Liquid Crystal Display,简称:LCD)、全息成像(Holographic)、投影(Projector)等,还可以包括一个或多个传感器(相当于图 2中的传感器220)。当然除此之外,硬件层630还可以包括图2中示出的电源、摄像头、RF电路和WiFi模块,还可以包括图2中也没有示出的其他硬件模块,如内存控制器和显示控制器等。The hardware layer 630 of the computer system 600 can include a magnetic disk, an eMMC, an NVMe, and a central processing unit. It may also include a memory (corresponding to the memory 280 in FIG. 2), including memory and external memory, and may also include a display device (corresponding to the display device 240 in FIG. 2), such as a liquid crystal display (English: Liquid Crystal Display, referred to as: LCD), Holographic, Projector, etc., may also include one or more sensors (equivalent to Sensor 220 in 2). Of course, in addition, the hardware layer 630 may also include the power source, camera, RF circuit, and WiFi module shown in FIG. 2, and may also include other hardware modules not shown in FIG. 2, such as a memory controller and display control. And so on.
上述详细阐述了本发明实施例的方法,为了便于更好地实施本发明实施例的上述方案,相应地,下面提供了本发明实施例的虚拟装置。The foregoing describes the method of the embodiment of the present invention in detail. In order to facilitate the implementation of the above solution of the embodiment of the present invention, the virtual device of the embodiment of the present invention is provided below.
请参见图7,图7是本发明实施例提供的又一种终端70的结构示意图,该终端70可以包括第一读取单元701和评估单元702,其中,各个单元的详细描述如下。Referring to FIG. 7, FIG. 7 is a schematic structural diagram of still another terminal 70 according to an embodiment of the present invention. The terminal 70 may include a first reading unit 701 and an evaluation unit 702, wherein detailed descriptions of the respective units are as follows.
第一读取单元701用于根据所述碎片评估指令读取预存的碎片信息,所述碎片信息包括所述终端预先通过读取自身文件系统的K个文件中的每个文件的元数据所得到的所述每个文件的文件大小信息和存储区域数量信息,K为大于0的整数;The first reading unit 701 is configured to read pre-stored fragment information according to the fragment evaluation instruction, where the fragment information includes the terminal obtained by reading metadata of each of the K files of the file system in advance. File size information and storage area number information of each of the files, K is an integer greater than 0;
评估单元702用于根据所述文件大小信息和所述存储区域数量信息评估所述K个文件的碎片化程度。The evaluation unit 702 is configured to evaluate the degree of fragmentation of the K files according to the file size information and the storage area quantity information.
通过运行上述单元,终端70在接收碎片评估指令之前读取各个文件的元数据以得到各个文件的文件大小信息和存储区域数量信息,并将这些信息保存在特定文件中供读取;终端70在接收到该碎片评估指令时直接读取该特定文件中的文件大小信息和存储区域数量信息,并基于该文件大小信息和存储区域数量信息评估文件系统的碎片化程度。也即是说,该终端70从接收到该碎片评估指令到评估出文件系统的碎片化程度的过程中,无需一一读取各个文件的元数据,提高了评估文件系统的碎片化程度的效率。By running the above unit, the terminal 70 reads the metadata of each file before receiving the fragment evaluation instruction to obtain file size information and storage area number information of each file, and saves the information in a specific file for reading; the terminal 70 is When receiving the fragment evaluation instruction, the file size information and the storage area quantity information in the specific file are directly read, and the fragmentation degree of the file system is evaluated based on the file size information and the storage area quantity information. That is to say, the terminal 70 does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to estimate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system. .
在一种可选的方案中,所述终端70还包括:In an optional solution, the terminal 70 further includes:
第二读取单元,用于在所述第一读取单元读取预存的碎片信息之前,通过读取所述每个文件的元数据所得到的所述每个文件的所述文件大小信息和所述存储区域数量信息。a second reading unit, configured to: before the first reading unit reads the pre-stored fragment information, the file size information of each file obtained by reading the metadata of each file and The storage area quantity information.
也即是说,在用户向终端70输入碎片评估指令之前该终端70读取每个文件的文件大小信息和存储区域数量信息,这样一来,后续要用该文件大小信息和存储区域数量信息时就可以直接用而无需再去读取,使得使用该文件大小信息和存储区域数量信息更加方便。That is, the terminal 70 reads the file size information and the storage area number information of each file before the user inputs the fragment evaluation instruction to the terminal 70, so that when the file size information and the storage area quantity information are subsequently used, It can be used directly without having to read it, making it easier to use the file size information and the number of storage areas.
在又一种可选的方案中,所述终端70还包括:In still another optional solution, the terminal 70 further includes:
第三读取单元,用于确定存在针对目标文件的写操作,并根据确定的结果在所述写操作结束后读取所述目标文件的元数据,得到所述目标文件的所述文件大小信息和所述存储区域数量信息,所述目标文件为所述K个文件中的任意一个文件;a third reading unit, configured to determine that there is a write operation for the target file, and read metadata of the target file after the end of the writing operation according to the determined result, to obtain the file size information of the target file And the storage area quantity information, the target file is any one of the K files;
更新单元,用于将第一文件大小信息和第一存储区域数量信息更新到所述碎片信息中,所述第一文件大小信息为在所述写操作结束后读取的所述目标文件的所述文件大小信息,所述第一存储区域数量信息为在所述写操作结束后读取的所述目标文件的所述存储区域数量信息。And an updating unit, configured to update the first file size information and the first storage area quantity information into the fragmentation information, where the first file size information is the target file read after the end of the writing operation The file size information, the first storage area quantity information is the storage area quantity information of the target file read after the end of the write operation.
也即是说,终端70获取每个文件的文件大小信息和存储区域数量信息之后,如果用户后续对其中某个文件进行了写操作,则该终端70会再次读取该某个文件的元数据来重新获取该某个文件的文件大小信息和存储区域数量信息,并将其更新到该碎片信息中,使得基于该碎片信息计算的相关结果更加精确。That is to say, after the terminal 70 obtains the file size information and the storage area number information of each file, if the user subsequently writes to one of the files, the terminal 70 reads the metadata of the certain file again. To re-acquire the file size information and the storage area quantity information of the certain file and update it into the fragmentation information, so that the correlation result calculated based on the fragmentation information is more accurate.
在又一种可选的方案中,所述更新单元具体用于: In still another optional solution, the updating unit is specifically configured to:
确定所述第一文件大小信息与第二文件大小信息不同,且所述第一存储区域数量信息与第二存储区域数量信息不同,并根据确定的结果将所述第一文件大小信息替换所述第二文件大小信息,以及将所述第一存储区域数量信息替换所述第二存储区域数量信息。Determining that the first file size information is different from the second file size information, and the first storage area quantity information is different from the second storage area quantity information, and replacing the first file size information with the determined result Second file size information, and replacing the first storage area quantity information with the second storage area quantity information.
也即是说,当判断出存在针对某个文件的写操作时,不是立即将重新读取的该某个文件的文件大小信息和存储区域数量信息更新到该碎片信息中,而是先判断重新获取该某个文件的文件大小信息和存储区域数量信息与该碎片信息中的该某个文件的文件大小信息和存储区域数量信息是否相同,若不相同才将重新获取的该某个文件的文件大小信息和存储区域数量信息更新到该碎片信息中,避免了不必要的更新。That is to say, when it is judged that there is a write operation for a certain file, the file size information and the storage area number information of the re-reading of the certain file are not immediately updated to the fragmentation information, but the judgment is first Obtaining the file size information and the storage area quantity information of the certain file and whether the file size information and the storage area quantity information of the certain file in the fragmentation information are the same, and if not, the file of the certain file to be reacquired The size information and the storage area quantity information are updated into the fragmentation information, avoiding unnecessary updates.
在又一种可选的方案中,该碎片信息存储在所述终端70的外存的同一个存储区域上。In still another alternative, the fragmentation information is stored on the same storage area of the external storage of the terminal 70.
可以理解的是,当碎片信息存储在同一个存储区域上时,该终端70在读取碎片信息时只需要做一次读操作即可,提高了该碎片信息的输入/输出性能。It can be understood that when the fragment information is stored on the same storage area, the terminal 70 only needs to perform a read operation when reading the fragment information, thereby improving the input/output performance of the fragment information.
该终端70的具体实现还可以对应参照图3所示的方法实施例的相应描述。The specific implementation of the terminal 70 may also correspond to the corresponding description of the method embodiment shown in FIG. 3.
在图7所描述的终端70中,终端70在接收碎片评估指令之前读取各个文件的元数据以得到各个文件的文件大小信息和存储区域数量信息,并将这些信息保存在特定文件中供读取;终端70在接收到该碎片评估指令时直接读取该特定文件中的文件大小信息和存储区域数量信息,并基于该文件大小信息和存储区域数量信息评估文件系统的碎片化程度。也即是说,该终端70从接收到该碎片评估指令到评估出文件系统的碎片化程度的过程中,无需一一读取各个文件的元数据,提高了评估文件系统的碎片化程度的效率。In the terminal 70 described in FIG. 7, the terminal 70 reads the metadata of each file before receiving the fragment evaluation instruction to obtain file size information and storage area number information of each file, and saves the information in a specific file for reading. The terminal 70 directly reads the file size information and the storage area quantity information in the specific file when receiving the fragment evaluation instruction, and evaluates the fragmentation degree of the file system based on the file size information and the storage area quantity information. That is to say, the terminal 70 does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to estimate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system. .
综上所述,通过实施本发明实施例,终端在接收碎片评估指令之前读取各个文件的元数据以得到各个文件的文件大小信息和存储区域数量信息,并将这些信息保存在特定文件中供读取;终端在接收到该碎片评估指令时直接读取该特定文件中的文件大小信息和存储区域数量信息,并基于该文件大小信息和存储区域数量信息评估文件系统的碎片化程度。也即是说,该终端从接收到该碎片评估指令到评估出文件系统的碎片化程度的过程中,无需一一读取各个文件的元数据,提高了评估文件系统的碎片化程度的效率。In summary, by implementing the embodiment of the present invention, the terminal reads the metadata of each file before receiving the fragment evaluation instruction to obtain the file size information and the storage area quantity information of each file, and save the information in a specific file. Reading; when receiving the fragment evaluation instruction, the terminal directly reads the file size information and the storage area quantity information in the specific file, and evaluates the fragmentation degree of the file system based on the file size information and the storage area quantity information. That is to say, the terminal does not need to read the metadata of each file one by one in the process of receiving the fragment evaluation instruction to evaluate the fragmentation degree of the file system, thereby improving the efficiency of evaluating the fragmentation degree of the file system.
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,可通过计算机程序来指令相关的硬件来完成,该的程序可存储于计算机可读取存储介质中,该程序在执行时,可包括如上述各方法的实施例的流程。而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可存储程序代码的介质。 A person skilled in the art can understand that all or part of the process of implementing the above embodiment method can be completed by a computer program to instruct related hardware, and the program can be stored in a computer readable storage medium. The flow of an embodiment of the methods as described above may be included. The foregoing storage medium includes various media that can store program codes, such as a ROM, a RAM, a magnetic disk, or an optical disk.

Claims (10)

  1. 一种文件碎片评估方法,其特征在于,包括:A method for evaluating a document fragment, comprising:
    终端读取预存的碎片信息,所述碎片信息包括所述终端预先通过读取自身文件系统的K个文件中的每个文件的元数据所得到的所述每个文件的文件大小信息和存储区域数量信息,K为大于0的整数;The terminal reads pre-stored fragment information, where the fragment information includes file size information and a storage area of each file obtained by the terminal in advance by reading metadata of each of the K files of the own file system. Quantity information, K is an integer greater than 0;
    所述终端根据所述文件大小信息和所述存储区域数量信息评估所述K个文件的碎片化程度。The terminal evaluates the degree of fragmentation of the K files according to the file size information and the storage area quantity information.
  2. 根据权利要求1所述的方法,其特征在于,所述终端读取预存的碎片信息之前,所述方法还包括:The method according to claim 1, wherein before the terminal reads the pre-stored fragment information, the method further includes:
    所述终端通过读取所述每个文件的元数据所得到的所述每个文件的所述文件大小信息和所述存储区域数量信息。The file size information and the storage area quantity information of each file obtained by the terminal by reading the metadata of each file.
  3. 根据权利要求1或2所述的方法,其特征在于,所述方法还包括:The method according to claim 1 or 2, wherein the method further comprises:
    所述终端确定存在针对目标文件的写操作,并根据确定的结果在所述写操作结束后读取所述目标文件的元数据,得到所述目标文件的所述文件大小信息和所述存储区域数量信息,所述目标文件为所述K个文件中的任意一个文件;Determining that there is a write operation for the target file, and reading metadata of the target file after the end of the write operation according to the determined result, obtaining the file size information of the target file and the storage area Quantity information, the target file is any one of the K files;
    所述终端将第一文件大小信息和第一存储区域数量信息更新到所述碎片信息中,所述第一文件大小信息为在所述写操作结束后读取的所述目标文件的所述文件大小信息,所述第一存储区域数量信息为在所述写操作结束后读取的所述目标文件的所述存储区域数量信息。The terminal updates the first file size information and the first storage area quantity information into the fragmentation information, where the first file size information is the file of the target file read after the end of the writing operation The size information, the first storage area quantity information is the storage area quantity information of the target file read after the end of the write operation.
  4. 根据权利要求3所述的方法,其特征在于,所述终端将第一文件大小信息和第一存储区域数量信息更新到所述碎片信息中,包括:The method according to claim 3, wherein the terminal updates the first file size information and the first storage area quantity information to the fragmentation information, including:
    确定所述第一文件大小信息与第二文件大小信息不同,且所述第一存储区域数量信息与第二存储区域数量信息不同,并根据确定的结果将所述第一文件大小信息替换所述第二文件大小信息,以及将所述第一存储区域数量信息替换所述第二存储区域数量信息;所述第二文件大小信息为所述碎片信息中的所述目标文件的所述文件大小信息,所述第二存储区域数量信息为所述碎片信息中的所述目标文件的所述存储区域数量信息。Determining that the first file size information is different from the second file size information, and the first storage area quantity information is different from the second storage area quantity information, and replacing the first file size information with the determined result Second file size information, and replacing the first storage area quantity information with the second storage area quantity information; the second file size information is the file size information of the target file in the fragmentation information The second storage area quantity information is the storage area quantity information of the target file in the fragmentation information.
  5. 根据权利要求1~4任一项所述的方法,其特征在于,所述碎片信息存储在所述终端的外存的同一个存储区域上。The method according to any one of claims 1 to 4, characterized in that the fragmentation information is stored on the same storage area of the external storage of the terminal.
  6. 一种终端,其特征在于,所述终端包括处理器、存储器和用户接口:A terminal, characterized in that the terminal comprises a processor, a memory and a user interface:
    所述存储器用于存储数据和程序;The memory is for storing data and programs;
    所述处理器调用所述存储器中的程序,用于执行如下操作:The processor invokes a program in the memory to perform the following operations:
    读取预存的碎片信息,所述碎片信息包括所述终端预先通过读取自身文件系统的K个文件中的每个文件的元数据所得到的所述每个文件的文件大小信息和存储区域数量信息, K为大于0的整数;Reading the pre-stored fragment information, where the fragment information includes the file size information and the number of storage areas of each file obtained by the terminal in advance by reading metadata of each of the K files of the own file system. Information, K is an integer greater than 0;
    根据所述文件大小信息和所述存储区域数量信息评估所述K个文件的碎片化程度。And estimating a degree of fragmentation of the K files according to the file size information and the storage area quantity information.
  7. 根据权利要求6所述的终端,其特征在于,所述处理器还用于:The terminal according to claim 6, wherein the processor is further configured to:
    在读取预存的碎片信息之前,通过读取所述每个文件的元数据所得到的所述每个文件的所述文件大小信息和所述存储区域数量信息。The file size information and the storage area number information of each of the files obtained by reading the metadata of each of the files before reading the pre-stored pieces of information.
  8. 根据权利要求6或7所述的终端,其特征在于,所述处理器还用于:The terminal according to claim 6 or 7, wherein the processor is further configured to:
    确定存在针对目标文件的写操作,并根据确定的结果在所述写操作结束后读取所述目标文件的元数据,得到所述目标文件的所述文件大小信息和所述存储区域数量信息,所述目标文件为所述K个文件中的任意一个文件;Determining that there is a write operation for the target file, and reading the metadata of the target file after the end of the write operation according to the determined result, obtaining the file size information of the target file and the storage area quantity information, The target file is any one of the K files;
    将第一文件大小信息和第一存储区域数量信息更新到所述碎片信息中,所述第一文件大小信息为在所述写操作结束后读取的所述目标文件的所述文件大小信息,所述第一存储区域数量信息为在所述写操作结束后读取的所述目标文件的所述存储区域数量信息。Updating the first file size information and the first storage area quantity information into the fragmentation information, where the first file size information is the file size information of the target file read after the end of the writing operation, The first storage area quantity information is the storage area quantity information of the target file read after the end of the write operation.
  9. 根据权利要求8所述的终端,其特征在于,所述处理器将第一文件大小信息和第一存储区域数量信息更新到所述碎片信息中,具体为:The terminal according to claim 8, wherein the processor updates the first file size information and the first storage area quantity information to the fragmentation information, specifically:
    确定所述第一文件大小信息与第二文件大小信息不同,且所述第一存储区域数量信息与第二存储区域数量信息不同,并根据确定的结果将所述第一文件大小信息替换所述第二文件大小信息,以及将所述第一存储区域数量信息替换所述第二存储区域数量信息;所述第二文件大小信息为所述碎片信息中的所述目标文件的所述文件大小信息,所述第二存储区域数量信息为所述碎片信息中的所述目标文件的所述存储区域数量信息。Determining that the first file size information is different from the second file size information, and the first storage area quantity information is different from the second storage area quantity information, and replacing the first file size information with the determined result Second file size information, and replacing the first storage area quantity information with the second storage area quantity information; the second file size information is the file size information of the target file in the fragmentation information The second storage area quantity information is the storage area quantity information of the target file in the fragmentation information.
  10. 根据权利要求6~9任一项所述的终端,其特征在于,所述碎片信息存储在所述终端的外存的同一个存储区域上。 The terminal according to any one of claims 6 to 9, wherein the fragmentation information is stored on a same storage area of the external storage of the terminal.
PCT/CN2017/075178 2016-08-19 2017-02-28 Method for evaluating file fragments, and terminal WO2018032743A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610692345.7 2016-08-19
CN201610692345.7A CN107766370A (en) 2016-08-19 2016-08-19 A kind of file fragmentation appraisal procedure and terminal

Publications (1)

Publication Number Publication Date
WO2018032743A1 true WO2018032743A1 (en) 2018-02-22

Family

ID=61196305

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/075178 WO2018032743A1 (en) 2016-08-19 2017-02-28 Method for evaluating file fragments, and terminal

Country Status (2)

Country Link
CN (1) CN107766370A (en)
WO (1) WO2018032743A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114461588A (en) * 2021-08-20 2022-05-10 荣耀终端有限公司 Method for adjusting pre-reading window and electronic equipment
WO2024020707A1 (en) * 2022-07-25 2024-02-01 Micron Technology, Inc. Memory performance evaluation using address mapping information

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111459848B (en) * 2020-03-31 2023-10-31 Oppo广东移动通信有限公司 File fragment sorting method and device, storage medium and electronic equipment
CN112905499B (en) * 2021-02-26 2022-10-04 四川泽字节网络科技有限责任公司 Fragmented content similar storage method

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1423271A (en) * 2001-12-03 2003-06-11 英业达股份有限公司 Method and system for computing fragment rate of magnetic disc
CN102760168A (en) * 2012-06-13 2012-10-31 腾讯科技(深圳)有限公司 Method and device for scanning fragmented files
CN102945275A (en) * 2012-11-08 2013-02-27 华为技术有限公司 File defragmentation method, file defragmentation unit and file defragmentation device
US8909887B1 (en) * 2012-09-25 2014-12-09 Emc Corporation Selective defragmentation based on IO hot spots
CN104933169A (en) * 2015-06-29 2015-09-23 南开大学 File system defragmentation method based on hotspot file priority

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101576890B (en) * 2008-05-08 2015-06-17 深圳市朗科科技股份有限公司 Novel method and system for sorting fragment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1423271A (en) * 2001-12-03 2003-06-11 英业达股份有限公司 Method and system for computing fragment rate of magnetic disc
CN102760168A (en) * 2012-06-13 2012-10-31 腾讯科技(深圳)有限公司 Method and device for scanning fragmented files
US8909887B1 (en) * 2012-09-25 2014-12-09 Emc Corporation Selective defragmentation based on IO hot spots
CN102945275A (en) * 2012-11-08 2013-02-27 华为技术有限公司 File defragmentation method, file defragmentation unit and file defragmentation device
CN104933169A (en) * 2015-06-29 2015-09-23 南开大学 File system defragmentation method based on hotspot file priority

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114461588A (en) * 2021-08-20 2022-05-10 荣耀终端有限公司 Method for adjusting pre-reading window and electronic equipment
CN114461588B (en) * 2021-08-20 2023-01-24 荣耀终端有限公司 Method for adjusting pre-reading window and electronic equipment
WO2024020707A1 (en) * 2022-07-25 2024-02-01 Micron Technology, Inc. Memory performance evaluation using address mapping information

Also Published As

Publication number Publication date
CN107766370A (en) 2018-03-06

Similar Documents

Publication Publication Date Title
US10558835B2 (en) Electronic device and method for acquiring fingerprint information
US10908789B2 (en) Application switching method and apparatus and graphical user interface
EP3335214B1 (en) Method and electronic device for playing a virtual musical instrument
US9904409B2 (en) Touch input processing method that adjusts touch sensitivity based on the state of a touch object and electronic device for supporting the same
US11093069B2 (en) Method and apparatus for performing a function based on a touch event and a relationship to edge and non-edge regions
US10802622B2 (en) Electronic device and method for controlling same
US20230129384A1 (en) Method for Browsing Application Folder and Electronic Device
US20150177903A1 (en) Method and apparatus for controlling scale resolution in electronic device
WO2018032743A1 (en) Method for evaluating file fragments, and terminal
US9189152B2 (en) Touch device and method for dynamically setting touch inactive area, and non-transitory recording medium
US9874957B2 (en) Deformable wearable electronic device
JP2014135053A (en) Method for displaying scrolling information in electronic device, and device therefor
KR20180074983A (en) Method for obtaining bio data and an electronic device thereof
US11704240B2 (en) Garbage data scrubbing method, and device
KR20140110452A (en) Control method and apparatus for user interface using proximity touch in electronic device
WO2018082616A1 (en) Dram-based storage cache method and intelligent terminal
KR102536148B1 (en) Method and apparatus for operation of an electronic device
CN112445766A (en) Terminal fragment sorting method and device and terminal
JP2013232044A (en) Electronic apparatus, control method, and program
US20150331600A1 (en) Operating method using an input control object and electronic device supporting the same
CN115543221B (en) Data migration method and device for solid state disk, electronic equipment and storage medium
JP5479876B2 (en) Device having touch sensor, data storage method, and data storage program

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17840721

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 17840721

Country of ref document: EP

Kind code of ref document: A1