CN113568868A - File system management method, system, electronic device and medium - Google Patents

File system management method, system, electronic device and medium Download PDF

Info

Publication number
CN113568868A
CN113568868A CN202110859193.6A CN202110859193A CN113568868A CN 113568868 A CN113568868 A CN 113568868A CN 202110859193 A CN202110859193 A CN 202110859193A CN 113568868 A CN113568868 A CN 113568868A
Authority
CN
China
Prior art keywords
idle
file
interval
space
size
Prior art date
Legal status (The legal status 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 status listed.)
Granted
Application number
CN202110859193.6A
Other languages
Chinese (zh)
Other versions
CN113568868B (en
Inventor
袁东平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chongqing Unisinsight Technology Co Ltd
Original Assignee
Chongqing Unisinsight Technology Co Ltd
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 Chongqing Unisinsight Technology Co Ltd filed Critical Chongqing Unisinsight Technology Co Ltd
Priority to CN202110859193.6A priority Critical patent/CN113568868B/en
Publication of CN113568868A publication Critical patent/CN113568868A/en
Application granted granted Critical
Publication of CN113568868B publication Critical patent/CN113568868B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • 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/11File system administration, e.g. details of archiving or snapshots
    • 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/13File access structures, e.g. distributed indices
    • G06F16/134Distributed indices
    • 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/1727Details of free space management performed by the file system
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The invention provides a file system management method, a file system management system, an electronic device and a medium, wherein the method comprises the steps of obtaining a file creation request of a file to be created, configuring the size of a pre-allocation required space for the file to be created, obtaining idle information of the file system, obtaining label information comprising an idle enlightenment position, and allocating a file space to be created for the file to be created according to the size of the pre-allocation required space from an idle initial position and the sequencing of each idle interval, so that file fragments can be reduced or avoided during writing, the continuous storage capacity of the same file is improved, and the read-write performance of the file system is improved.

Description

File system management method, system, electronic device and medium
Technical Field
The present invention relates to the field of image processing technology in the field of steel, and in particular, to a file system management method, system, electronic device, and medium.
Background
The Leveldb (multi-level key value database) is a very efficient open source key-value database realized by google, a data organization mode based on LSM (Log Structured Merge Trees) has very high writing efficiency when writing in sequence, merging operation becomes a writing bottleneck when writing in a large amount of random, and the quantity of level0 files expands seriously, which affects availability.
The file system is used for realizing the access function of binary data. The common file system EXT4 (Fourth-generation extended file system), XFS, etc. perform poorly in resource-constrained scenarios such as embedded scenarios, and file fragmentation easily occurs when multimedia files are written in parallel, so that the continuous storage capability of the same file is reduced, and then the read-write performance of the file system will be affected.
Disclosure of Invention
In view of the foregoing drawbacks of the prior art, an object of the present invention is to provide a file system management method, system, electronic device and medium, for solving the technical problem that file fragmentation easily occurs when multimedia files are written in parallel, so that the continuous storage capability of the same file is reduced, and then the read-write performance of the file system is affected.
In view of the above problem, the present invention provides a file system management method, including:
acquiring a file creating request of a file to be created, and configuring the size of a pre-allocated space for the file to be created;
acquiring idle information of a file system, wherein the idle information comprises idle position identifiers of a plurality of idle intervals;
acquiring label information, wherein the label information comprises the idle initial position of each idle interval left after space allocation is carried out on the file system for the last time, and the idle position identifier of one idle interval comprises the idle initial position;
and from the idle starting position, distributing the file space to be created for the file to be created according to the sorting of the idle intervals and the size of the space required by the pre-distribution.
Optionally, the identifier of the idle position includes an initial position of an idle interval and an end position of the idle interval, and allocating, from the initial position of the idle interval, a file space to be created for the file to be created according to the size of the space required for pre-allocation includes any one of:
and acquiring the size of the idle interval and the number of the idle position identifications in the idle information, allocating a file space to be created with the pre-allocated required space size for the file to be created according to one or more of the size of the idle interval, the size of the pre-allocated required space and the idle starting position, and determining the size of the idle interval according to the initial position of the idle interval and the ending position of the idle interval.
Optionally, the obtaining of the size of the free interval and the number of the free position identifiers in the free information, and allocating, according to one or more of the size of the free interval, the size of the space required for pre-allocation, and the free starting position, a space of the file to be created for allocating the size of the space required for pre-allocation to the file to be created includes any one of:
if the idle information only comprises an idle position identifier of the idle interval, the idle starting position is the same as the initial position of the idle interval, and if the size of the idle interval is larger than or equal to the size of the space required by pre-allocation, a file space to be created with the size of the space required by pre-allocation is allocated for the file to be created from the initial position of the idle interval;
if the idle information comprises idle position identifiers of a plurality of idle intervals, determining a target interval from each idle interval according to the idle initial position, determining the size of the target interval according to the size of each idle interval of the target interval, and if the size of the target interval is larger than or equal to the size of the required pre-allocation space, allocating a file space to be created with the size of the required pre-allocation space for the file to be created in the target interval from the idle initial position;
if the idle information comprises idle position identifications of a plurality of idle intervals, determining a target interval from each idle interval according to the idle starting position, determining the size of the target interval according to the size of each idle interval of the target interval, if the size of the target interval is smaller than the size of the space required for pre-allocation, obtaining the size of a difference space between the size of the target interval and the size of the space required for pre-allocation, determining a supplementary interval according to the difference space, wherein the supplementary interval comprises a plurality of idle intervals which are positioned behind the target interval and are selected according to a sorting sequence, and taking the target interval and the supplementary interval as the space of the file to be created.
Optionally, the determination manner of the supplemental interval includes at least one of:
acquiring the size of a first idle interval after the target interval, and if the size of the difference space is smaller than or equal to the size of the first idle interval, allocating the space with the size of the difference space in the first idle interval as a supplementary interval;
sequentially obtaining a first combination size of idle intervals of a first combination of idle intervals after a target interval, and if the difference space size is smaller than or equal to the first combination size of the idle intervals, allocating a space with the difference space size in the first combination of the idle intervals as a supplementary interval;
the method comprises the steps of sequentially obtaining a first combination size of idle intervals of a first combination of idle intervals after a target interval, sequentially obtaining a second combination size of idle intervals of a second combination of idle intervals before the target interval if the difference space size is larger than the first combination size of the idle intervals, and sequentially distributing space with the difference space size in the first combination of idle intervals and the second combination of idle intervals as supplementary intervals if the first combination size of idle intervals and the second combination size of idle intervals are larger than the difference space size.
Optionally, the method further includes:
acquiring deletion information of a deleted file, wherein the deletion information comprises an occupied position identifier of the deleted file;
and combining the occupied interval corresponding to the deleted file occupied position identification with the idle interval, and updating the idle information.
Optionally, the identifier of the occupied location of the deleted file includes an occupied initial location and an occupied end location, the identifier of the idle location includes an idle interval initial location and an idle interval end location, and updating the idle information includes:
if the initial position and the end position of each idle interval in the idle information are different from the initial position and the end position of the occupied interval, adding the initial position and the end position of the occupied interval to the idle information;
if the idle interval initial position of an idle interval in the idle information is the same as the occupation end position, replacing the idle interval initial position with the occupation end position;
and if the idle interval ending position of one idle interval in the idle information is the same as the occupied initial position, replacing the idle interval ending position with the occupied initial position.
Optionally, the method further includes:
opening the file to be created, and acquiring a file space to be created of the file to be created, wherein the file space to be created comprises a plurality of idle intervals;
and reading and writing data of the file to be created, and sequentially loading each idle interval into a cache according to the file offset of the file to be created.
Optionally, the method further includes:
and recording the modification time and the file size of the file to be created after data reading and writing.
Optionally, the cache module caches full path and all node information of the file system, and the metadata storage module stores metadata in the file system, where the method further includes at least one of:
when node information is inquired, the full path is matched in the cache module step by step, if the matching fails, the node information is searched in the metadata storage module, and the node information is cached in the cache module;
when updating the node information, updating the node information in the cache module, and then storing the node information into the metadata storage module;
and updating the metadata storage module through batch operation writing.
Optionally, the method further includes: and if the power failure restart happens, acquiring and analyzing a pre-written log, and performing data recovery on the file system according to the analyzed pre-written log.
The invention also provides a file system management system, which comprises a file system module and a metadata storage module for storing the metadata of the file system, wherein the file system module comprises an access interface of the metadata storage module, and the metadata storage module comprises an idle unit and a system recording unit, wherein:
the idle unit is used for recording idle information of an idle space which is not allocated to a file, and the idle information comprises idle position marks of a plurality of idle intervals;
the system recording unit is used for recording label information, including the idle starting position of each idle interval left after space allocation is carried out by the file system for the last time, wherein the idle position identifier of one idle interval includes the idle starting position;
and if a file creation request of a file to be created is received through the access interface, allocating a free space with the size of the space required by pre-allocation as a file space to be created according to the sequence of each free interval by taking the free starting position as a starting point.
Optionally, the metadata storage module includes at least one of:
the node unit comprises a file unit and a directory unit and is used for recording attribute information of files and directories, wherein the attribute information comprises at least one of node identity identification information, father identity identification information, creation time, modification time, used size, size of a file space to be created and name;
the index unit is used for searching files and scanning directories and comprises at least one of father identification information, names, identification information and types;
the active node unit is used for recording the modification time and the file size of the file to be created after data reading and writing;
and the allocation unit is used for recording the occupation information of the free space allocated to the file.
Optionally, the file system management system further includes a cache module, where the cache module is configured to cache path and node information of the file system;
when node information is inquired, the path is matched in the cache module step by step, if the matching fails, the node information is searched in the metadata storage module, and the node information is cached in the cache module;
when updating the node information, updating the node information in the cache module, and then storing the node information into the metadata storage module;
and updating the metadata storage module through batch operation writing.
Optionally, the file system management system further includes at least one of:
acquiring a father directory of a file to be created, if the file system comprises the father directory, distributing node identification information of the directory to be created for the directory to be created, and writing the node identification information of the directory to be created into the node unit, the index unit and the distribution unit respectively;
writing the occupation information of the file space to be created into the distribution unit;
updating the idle unit and/or the system recording unit according to the occupation information of the file space to be created;
acquiring a directory to be deleted, and if the directory to be deleted in the index unit is an empty directory, deleting the directory to be deleted in the node unit and the index unit;
acquiring deletion information of a deleted file, wherein the deletion information comprises an occupation position identifier of the deleted file, merging an occupation interval corresponding to the occupation position identifier of the deleted file with the idle interval, and updating the idle information in the idle unit and the occupation information in the allocation unit.
Optionally, the file system management system further includes an input/output module, where the input/output module is configured to manage a file handle of the opened file to be created, the file handle is associated with the node information, and obtains a file space to be created of the file to be created after the file to be created is opened, where the file space to be created includes a plurality of idle intervals, and performs data reading and writing on the file to be created, and loads each idle interval into the cache module in sequence according to a file offset of the file to be created.
Optionally, the metadata storage module includes a database, the idle unit includes an idle table, the system recording unit includes a system table, the node unit includes a node table, the index unit includes an index table, the active node unit includes an active node table, and the allocation unit includes an allocation table, where each table includes a table head identifier and a table tail identifier, and the prefix of the primary key between each table is different.
The invention also provides an electronic device, which comprises a processor, a memory and a communication bus;
the communication bus is used for connecting the processor and the memory;
the processor is configured to execute the computer program stored in the memory to implement the method according to any of the above embodiments.
The invention also provides a computer-readable storage medium having stored thereon a computer program for causing a computer to perform the method according to any one of the preceding embodiments.
As described above, the file system management method, system, electronic device and medium provided by the present invention have the following beneficial effects:
the file creating method comprises the steps of obtaining a file creating request of a file to be created, configuring the size of a pre-allocated required space for the file to be created, obtaining idle information of a file system, obtaining label information comprising an idle enlightenment position, and allocating the space of the file to be created for the file to be created according to the size of the pre-allocated required space according to the sequence of idle intervals from an idle initial position, so that file fragments can be reduced or avoided during writing, the continuous storage capacity of the same file is improved, and the read-write performance of the file system is improved.
Drawings
Fig. 1 is a schematic flowchart of a file system management method according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a file system management system according to a second embodiment of the present invention;
FIG. 3-1 is a diagram illustrating an Index table Index according to an embodiment;
fig. 3-2 is a schematic diagram of a Node table Node according to an embodiment;
fig. 3-3 is a schematic diagram of an Active node table Active according to an embodiment;
FIGS. 3-4 are diagrams of Free list Free provided by an embodiment;
FIGS. 3-5 are schematic diagrams of an allocation table Alloc according to an embodiment;
FIGS. 3-6 are schematic diagrams of a system record table SYS according to an embodiment;
fig. 4 is a schematic structural diagram of a cache module according to an embodiment;
5-1, 5-2, and 5-3 are example diagrams of allocation of file space to be created provided by an embodiment;
6-1, 6-2, and 6-3 are exemplary diagrams of spatial merging after deletion of a file according to an embodiment;
FIG. 7 is a block diagram of another exemplary file system management system;
FIG. 8 is a diagram illustrating an exemplary embedded file system scenario, according to an embodiment;
fig. 9 is a schematic structural diagram of a terminal according to an embodiment.
Detailed Description
The embodiments of the present invention are described below with reference to specific embodiments, and other advantages and effects of the present invention will be easily understood by those skilled in the art from the disclosure of the present specification. The invention is capable of other and different embodiments and of being practiced or of being carried out in various ways, and its several details are capable of modification in various respects, all without departing from the spirit and scope of the present invention. It is to be noted that the features in the following embodiments and examples may be combined with each other without conflict.
It should be noted that the drawings provided in the following embodiments are only for illustrating the basic idea of the present invention, and the components related to the present invention are only shown in the drawings rather than drawn according to the number, shape and size of the components in actual implementation, and the type, quantity and proportion of the components in actual implementation may be changed freely, and the layout of the components may be more complicated.
Example one
Referring to fig. 1, a file system management method according to an embodiment of the present invention includes:
s101: and acquiring a file creating request of the file to be created, and configuring the size of the pre-allocated space for the file to be created.
The file creation request may include, but is not limited to, at least one of a file type, a file format, a purpose, a request source (information of a requester), and the like, and the size of the space required for pre-allocation corresponding to the file to be created may be configured for the file to be created according to the file creation request, that is, the size of the reserved file of the file to be created is determined according to the file creation request. For example, when the file type in the file creation request is a video file, the size of the space required for pre-allocation is configured to be 1G, and when the file type in the file creation request is an audio file, the size of the space required for pre-allocation is configured to be 500M. The configuration rules for pre-allocating the required amount of space may also be set by those skilled in the art as desired.
Optionally, before step S101, the method further includes:
acquiring the father directory information of the file to be created, and if the father directory corresponding to the father directory information exists in the file system, allocating corresponding node identification information (node ID) for the file to be created.
Optionally, the file system in this embodiment includes an embedded virtual file system based on leveldb.
S102: and acquiring the idle information of the file system.
Wherein, the idle information includes, but is not limited to, idle position identifiers of a plurality of idle intervals.
Alternatively, the idle information may be location information of a blank block. For example, the data blocks capable of storing the virtual file are configured with corresponding data block sequence numbers in advance, the data block sequence number of each data block in the free interval of several data block runs is used as a free position identifier, for example, the data blocks 10 to 20 form a free interval, and the free position identifier of the free interval is (10, 20).
The situation of the available data blocks in the current file system can be known through the idle information.
S103: and acquiring label information.
The label information comprises idle starting positions of all idle intervals left after space allocation is carried out on the file system for the last time, and the idle position identifier of one idle interval comprises the idle starting position.
Optionally, each idle interval remaining after the file system performs space allocation last time may be understood as that one or more idle intervals (that is, a plurality of idle intervals in the idle information in step S102) remain after the file system receives a file creation request last time and completes space allocation for a last file to be created (after last space allocation). The idle starting position is also the idle interval starting position of one idle interval in the plurality of idle intervals. In other words, the idle starting position is the initial position of the idle interval of the currently most ordered idle interval in each idle interval.
Optionally, the idle starting position may be an idle interval starting position of a first idle interval after an occupied space ending position occupied by last space allocation. It should be noted that, the determining manner of the first idle interval after the occupied space end position includes, but is not limited to, the following manners:
if the occupied space end position is not the end position of the initial allocable space, the first idle interval is an idle interval sequenced after the occupied space end position;
if the occupied space end position is the end position of the initial allocable space, the first free interval is the free interval with the highest rank from the initial position of the initial allocable space.
In other words, the sequence of the empty intervals starts from the end position of the occupied space, passes through the end position of the initial allocable space, and circulates back to the start position of the initial allocable space to the end position of the occupied space.
Therefore, occupation can be performed in sequence according to the sequence of the idle intervals, metadata are stored based on the database sequence, the reading and writing efficiency is higher, the pressure of metadata operation on hard disk IO is small, and the metadata operation and the reading and writing of file data can be separated to different devices (such as different disks).
For example, the data block sequence number of the data block is 1-100, the last data block occupied by the last space allocation is 30, the current blank data block is 0-15, 31-50,75-100, the occupied space ending position is 30, the first idle interval after the occupied space ending position is 31-50, and the idle starting position is 31. For another example, the sequence number of the data block is 1-100, the last data block occupied by the last space allocation is 30, the current blank data block is 0-15, 45-50,75-100, the occupied space ending position is 30, the first idle interval after the occupied space ending position is 45-50, and the idle starting position is 45. For another example, the sequence number of the data block is 1-100, the last data block occupied by the last space allocation is 100, the current blank data block is 0-15, 45-50, the occupied space ending position is 100, the first idle interval after the occupied space ending position is 0-15, and the idle starting position is 0. For another example, the sequence number of the data block is 1-100, the last data block occupied by the last space allocation is 100, the current blank data block is 5-15, 45-50, the occupied space ending position is 100, the first idle interval after the occupied space ending position is 5-15, and the idle starting position is 5. For another example, the sequence number of the data block is 1-100, the last data block occupied by the last space allocation is 100, the current blank data block is 0, 5-15, 45-50, the occupied space ending position is 100, the first free interval after the occupied space ending position is 0, and the free starting position is 0.
Alternatively, the free starting position may be a free interval initial position of a first free interval from a starting position of the initial allocable space.
For example, the data block sequence number of the data block is 1-100, the data block of the current blank is 0-15, 31-50,75-100, and the idle start position is 0. For another example, the data block sequence number of the data block is 1-100, the data block of the current blank is 31-50,75-100, and the idle start position is 31.
For two situations that the idle starting position can be the initial position of the idle interval of the first idle interval from the starting position of the initial allocable space, and the idle starting position can be the initial position of the idle interval of the first idle interval after the ending position of the occupied space occupied by the last space allocation, the tag information can be recorded after the last space allocation is finished.
Optionally, the free starting position may be a free interval initial position of a free interval that best matches the size of the pre-allocated required space. At this time, after the size of the space required for pre-allocation is obtained, matching is performed according to the size of each current idle interval. The matching degree can be determined by calculating the relative error between the size of the space required by the pre-allocation and the size of each idle interval, and the smaller the relative error is, the better the matching degree is. If the matching degrees of at least two idle intervals are the same, the initial position of the idle interval of the first idle interval behind the end position of the occupied space in each idle interval with the same matching degree can be selected as the idle starting position. If there are at least two idle intervals with the same matching degree, the idle interval initial position of which idle interval is selected may be determined as the idle initial position according to other manners preset by those skilled in the art.
For example, the data block sequence number of the data block is 1-100, the current blank data block is 0-15, 31-50,75-100, and the size of the space required for pre-allocation is 15 data blocks, then the idle starting position is 0. For another example, the data block sequence number of the data block is 1-100, the current blank data block is 0-15, 31-50,75-100, the size of the space required for pre-allocation is 20 data blocks, and the idle starting position is 31. For another example, the data block sequence number of the data block is 1-100, the current blank data block is 0-15, 35-50,75-100, the size of the space required for pre-allocation is 15 data blocks, and the end position of the occupied space of the last space allocation is 34, then the idle start position is 35.
Therefore, a proper idle interval can be selected for the file to be created, the file to be created is arranged in the same continuous idle interval as much as possible in a 'blank filling' mode, and the generation of file fragments can be effectively avoided. Meanwhile, if the occupied space end position of the last space allocation can be considered, space allocation is performed after the occupied space end position, metadata can be stored sequentially based on a database, the reading and writing efficiency is higher, the pressure of metadata operation on hard disk IO is small, and the metadata operation and file data reading and writing can be separated to different devices (such as different disks).
S104: and from the idle starting position, distributing the space of the file to be created for the file to be created according to the size of the space required by the pre-distribution.
Optionally, the idle starting position is an idle interval initial position of one of the idle intervals a, that is, the file space to be created at least includes at least a part of the idle interval a.
Optionally, the idle interval includes one or more data blocks, and since the data blocks corresponding to the idle interval are pre-ordered, the file space to be created includes a plurality of data blocks selected according to the ordering of the data blocks from the data block where the idle start position is located. In other words, the file interval to be created may select the space with the size of the space required for pre-allocation according to the sequence of the free intervals from the free start position.
The file space to be created is configured according to the space size required by the pre-allocation, so that the phenomenon that a plurality of files are written in parallel is particularly large in file fragments can be effectively avoided, and the generation of fragments in a file system is effectively reduced.
Optionally, when the subsequent file to be created is read and written, only the space of the file to be created is occupied, and when the data of the file to be created exceeds the space of the file to be created, data overwriting (deleting the original data and writing in new data) may be started from the initial position of the space of the file to be created, or a new file to be created may be created again to record the exceeded data.
Optionally, from the idle starting position, allocating a file space to be created for the file to be created according to the size of the space required for pre-allocation includes:
and from the idle initial position, distributing the file space to be created for the file to be created according to the sorting of the idle intervals and the size of the space required by the pre-distribution.
Wherein the ordering of the idle intervals comprises at least one of:
the cyclic ordering of the idle intervals, for example, starts from the end position of the occupied space, circulates back to the start position of the initial allocable space through the end position of the initial allocable space, and ends at the end position of the occupied space.
Sorting the matching degrees of the idle intervals, for example, the idle starting position may be an initial idle interval position of an idle interval with the best matching degree with the size of the pre-allocated required space, the idle interval corresponding to the idle starting position is used as an idle interval for sorting the first name, the difference space is determined, the idle interval with the best matching degree with the difference space is used as an idle interval for sorting the second name, and so on, optionally, when a plurality of idle intervals have the same matching degree, a certain rule may be formulated by a person skilled in the art to select an idle interval (for example, natural sorting or circular sorting is combined);
the natural ordering of the idle interval, for example, the natural ordering of each data block in the idle interval, is from front to back.
In some embodiments, the free location identifier includes a free interval initial location and a free interval end location, and from the free initial location, allocating the file space to be created for the file to be created according to the size of the space required for pre-allocation includes any one of:
and acquiring the size of the idle interval and the number of the idle position identifications in the idle information, allocating a file space to be created with the pre-allocated required space size for the file to be created according to the size of one or more idle intervals, the pre-allocated required space size and the idle starting position, and determining the size of the idle interval according to the initial position of the idle interval and the ending position of the idle interval.
Optionally, the obtaining of the size of the free interval and the number of the free position identifiers in the free information, and allocating, for the file to be created, the file space to be created, which is the size of the space required by the pre-allocation, according to the size of one or more free intervals, the size of the space required by the pre-allocation, and the free starting position, includes any one of the following:
if the idle information only comprises an idle position identification of an idle interval, the idle initial position is the same as the initial position of the idle interval, the size of the idle interval is determined according to the initial position of the idle interval and the end position of the idle interval, and if the size of the idle interval is larger than or equal to the size of the required pre-allocation space, the file space to be created with the size of the required pre-allocation space is allocated for the file to be created from the initial position of the idle interval;
if the idle information comprises idle position identifications of a plurality of idle intervals, determining a target interval from each idle interval according to an idle initial position, determining the size of the target interval according to the size of each idle interval of the target interval, and if the size of the target interval is larger than or equal to the size of the required pre-allocation space, allocating the space of the file to be created with the size of the required pre-allocation space in the target interval from the idle initial position of the target interval;
if the idle information comprises idle position identifications of a plurality of idle intervals, determining a target interval from each idle interval according to an idle starting position, determining the size of the target interval according to the size of each idle interval of the target interval, if the size of the target interval is smaller than the size of a pre-distribution required space, acquiring the size of a difference space between the size of the target interval and the size of the pre-distribution required space, determining a supplement interval according to the difference space, wherein the supplement interval comprises a plurality of idle intervals which are positioned behind the target interval and select the size of the difference space according to a sorting sequence, and taking the target interval and the supplement interval as a file space to be created.
Optionally, since the target interval includes at least two idle intervals, the size of the idle interval of each idle interval may be accumulated to obtain the size of the target interval. Because each free interval has natural sequencing (from front to back, independent of the free starting position), if the size of the target interval obtained from the free starting position to the free interval ending position of the last free interval in each free interval is still smaller than the size of the space required by pre-allocation, the supplementary interval can be determined from the natural sequencing starting position of the free interval. Optionally, each idle interval further includes a current sequence, where the current sequence is from an idle starting position to an idle interval ending position of a last idle interval in the natural sequence, and the current sequence receives an idle interval initial position of a first idle interval in the natural sequence and reaches an idle interval ending position of an idle interval before the idle starting position in the natural sequence.
If the idle information only includes an idle position identifier of an idle interval, that is, there is only one idle interval in the current file system. If the idle information only includes the idle position identifiers of the idle intervals, that is, there are multiple idle intervals in the current file system.
If the idle information only comprises an idle position identification of an idle interval, the idle starting position is the same as the initial position of the idle interval, the size of the idle interval is determined according to the initial position of the idle interval and the end position of the idle interval, and if the size of the idle interval is smaller than the size of the space required by pre-allocation, the feedback establishment fails. And if the size of the idle interval is larger than or equal to the size of the space required by the pre-allocation, configuring continuous spaces with the size of the space required by the pre-allocation for the file to be created from the initial position of the idle interval as the space of the file to be created.
If the idle information comprises idle position identifications of a plurality of idle intervals, a target interval can be determined from each idle interval through the label information, and then space allocation is carried out according to the corresponding relation between the size of the target interval and the size of the space required by pre-allocation. Specifically, if the size of the target interval meets the size of the space required by pre-allocation, only the target interval is occupied, and from the initial position of the idle interval, a continuous space with the size of the space required by pre-allocation is configured for the file to be created in the target interval to serve as the space of the file to be created. And if the size of the target interval cannot meet the size of the space required by pre-allocation, determining a supplementary interval, and configuring the file space to be created in the target interval and the supplementary interval. Optionally, the sorting of the empty intervals includes starting from the end position of the occupied space, recycling to the start position of the initial allocable space through the end position of the initial allocable space, and ending at the end position of the occupied space.
The supplementary interval is determined in a manner including at least one of:
acquiring the size of a first idle interval after a target interval, and if the size of the difference space is smaller than or equal to the size of the first idle interval, allocating the space with the size of the difference space in the first idle interval as a supplementary interval;
acquiring a first combination size of idle intervals of a first combination of idle intervals after a target interval in sequence, and if the difference space size is smaller than or equal to the first combination size of the idle intervals, allocating space with the difference space size in the first combination of the idle intervals as a supplementary interval;
and if the size of the first combination of the idle intervals and the size of the second combination of the idle intervals are larger than the size of the margin space, allocating the space with the size of the margin space in the first combination of the idle intervals and the second combination of the idle intervals in sequence as a supplementary interval.
For convenience of understanding, the identifier of the free interval position is identified by the sequence number of the data block, and several examples of determining the file space to be created are as follows:
if the size of the space required for pre-allocation is 10 data blocks, the current free interval is (2,8), (11, 19), (50,100), the free starting position is 2, the difference space is 3, the size of the first free interval (11, 19) of the first free interval after the target interval is 9, the target interval is (2,8), the supplementary interval is (11,13), and the space of the file to be created is [ 2,8), (11,13 ].
If the size of the space required by the pre-allocation is 10 data blocks, the current free interval is (2,8), (11, 19), (98,100), and the free starting position is 97, the target interval is (98,100), the supplementary interval is (2,8), and the space of the file to be created is [ 2,8 ], (98,100) ], wherein the storage sequence of the file to be created is to store the file (98,100) first and then store the file (2, 8).
If the size of the space required for pre-allocation is 10 data blocks, the current free interval is (2,8), (11,12), (98,100), the free start position is 2, the first combination of the free intervals is (11,12), (98,100), and the first combination size of the free intervals is: 2+3 is 5, the size of the difference space is 3, the target interval is (2,8), the supplementary intervals are (11,12), (98), and the file space to be created is [ 2,8), (11,12), (98 ], wherein the storage sequence of the file to be created is that the file to be created is stored (2,8) first, then the file to be created is stored (11,12), and finally the file to be created is stored 98.
If the size of the space required by the pre-allocation is 10 data blocks, the current idle intervals are (2,8), (11,12), (98,100), the idle starting position is 11, the first combination of the idle intervals is (98,100), the first combination of the idle intervals is 3, the second combination of the idle intervals is (2,8), the first combination of the idle intervals is 7, and the difference space is: and when 10-2 is equal to 8, the target interval is (11,12), the supplementary interval is (98,100) and (2,6), and the file space to be created is [ 2,6), (11,12) and (98,100 ], wherein the storage sequence of the file to be created is that the file is stored first (11,12), then stored (98,100) and finally stored (2, 6).
It should be noted that the first combination of idle intervals and the second combination of idle intervals may include one or more idle intervals.
In the process of storing the metadata of the file to be created, the storage is started by taking the idle starting position as a starting point, so that the metadata can be stored in sequence, and then, for example, after the data is deleted, the idle spaces are merged.
In some embodiments, the file management method further comprises:
acquiring deletion information of a deleted file, wherein the deletion information comprises an occupied position identifier of the deleted file;
and combining the occupied interval corresponding to the deleted file occupied position identification with the idle interval, and updating the idle information.
Optionally, the occupied interval and the idle interval are merged, that is, if the occupied interval and the idle interval are continuous, the occupied interval and the idle interval are merged.
Optionally, the deleting the file occupation position identifier includes an occupation initial position and an occupation end position, the idle position identifier includes an idle interval initial position and an idle interval end position, and the updating the idle information includes:
if the initial position and the end position of each idle interval in the idle information are different from the initial position and the end position, the initial position and the end position are added to the idle information, namely one idle interval is added;
if the idle interval initial position of an idle interval in the idle information is the same as the occupation end position, replacing the idle interval initial position with the occupation end position, namely increasing an idle interval;
if the idle interval end position of an idle interval in the idle information is the same as the occupied initial position, the idle interval end position is replaced by the occupied initial position, and the idle interval is increased.
In some embodiments, the file management method further comprises:
acquiring deletion information of a deleted file, wherein the deletion information comprises an occupied position identifier of the deleted file;
combining the deleted file occupation position identification with the idle information, and updating the idle information;
and deleting the occupied position identifier of the deleted file in the file system.
By combining the idle intervals, updating the idle information of the combined idle intervals and deleting the marks of the occupied positions of the deleted files, the data volume of the stored data can be reduced.
In some embodiments, after completing the allocation of the file space to be created, the file management method further comprises:
the idle information and/or the tag information is updated.
Optionally, the idle interval includes a plurality of idle blocks (data blocks), and the manner of updating the tag information includes any one of the following:
if the idle information only comprises an idle position identifier of an idle interval, and the size of the idle interval is equal to the size of the space required by pre-allocation, the updated position identifier comprises a null value;
if the idle information only comprises an idle position identifier of an idle interval, and the size of the idle interval is larger than the size of the space required by pre-allocation, the update position identifier comprises an update initial position and an idle interval end position of the idle interval, and the update initial position comprises the position of the first idle block of the idle interval left after the last idle block in the file space to be created;
if the idle information only comprises idle position identifications of a plurality of idle intervals, and the size of the target interval is equal to the size of the space required by pre-allocation, the updated position identification comprises the idle position identifications of the rest idle intervals except the target interval;
if the idle information only comprises idle position identifications of a plurality of idle intervals, and the size of the target interval is larger than the size of the space required by pre-allocation, the update position identification comprises idle position identifications of other idle intervals except the target interval, the update position identification comprises an update initial position and an idle interval ending position of the idle interval, and the update initial position comprises the position of the first idle block of the idle interval after the last idle block in the file space to be created.
In some embodiments, after completing step S104, the file management method further comprises:
opening a file to be created, and acquiring a file space to be created of the file to be created, wherein the file space to be created comprises a plurality of idle intervals;
and reading and writing data of the file to be created, and respectively and sequentially loading each idle interval into the cache according to the file offset of the file to be created.
Optionally, the loading each idle interval into the cache in sequence includes:
and acquiring an idle initial position corresponding to the file space to be created, sequentially acquiring each idle interval from the idle initial position according to the sequence, and loading the idle intervals into a cache.
After the current idle interval is fully written, the next idle interval is acquired, so that the cache allocation record can be prevented from occupying too much memory.
For example, when a file (such as a file to be created after space allocation) in a file system is opened, an allocation record (information of the file space to be created) of the file is partially loaded into a memory, data reading and writing are performed by calculating a reading and writing position through the allocation record of a cache during reading and writing, and a relevant allocation record is reloaded from a database when the reading and writing offset exceeds the cache record, so that the cache allocation record is prevented from occupying too much memory.
In some embodiments, the file management method further comprises:
and recording the modification time and the file size of the file to be created after data reading and writing.
Optionally, the modification time and the file size of the file to be created are recorded in real time, so that the file size is ensured due to power failure, and meanwhile, the expansion of the database due to performance reduction after the IO model is degraded into random reading and writing due to frequent updating of file node information can be avoided.
In some embodiments, the cache module caches full path and all node information of the file system, and the metadata storage module stores metadata in the file system, and the file management method further includes at least one of:
when inquiring node information, the node information is firstly matched with the full path step by step in the cache module, if the matching fails, the node information is searched in the metadata storage module, and the node information is cached in the cache module, so that the inquiry times in the metadata storage module can be reduced;
when the node information is updated, the node information in the cache module is updated firstly, and then the node information is stored in the metadata storage module, so that the information in the cache module and the data in the metadata storage module can be kept consistent;
the metadata storage module is updated through batch operation writing, so that data inconsistency can be avoided.
In some embodiments, the file management method further comprises:
and if the power failure restart occurs, acquiring and analyzing the pre-written log, and performing data recovery on the file system according to the analyzed pre-written log.
The metadata storage module includes but is not limited to a database, such as a leveldb database.
The updating of the plurality of tables of the database in the data recovery can be performed through batch operation writing, so that data inconsistency caused by power failure can be avoided.
In some embodiments, the metadata is stored in the leveldb database in K-V (key-value) form.
Alternatively, the metadata may be stored in other relational databases.
In some embodiments, the cache module includes a red black tree for querying node information via a path and an LRU (Least Recently Used) linked list for aging the cache.
Optionally, when the cache is inserted, the cache node is added to the red-black tree and the LRU linked list at the same time. The LRU linked list is updated when the cache is accessed. And releasing the oldest buffer after the buffer number reaches the upper limit. When the cache is referenced by io, the cache is moved out of the LRU linked list, management is carried out by using reference counting, and when the reference counting is 0, the cache is added into the LRU linked list again.
The file system management method in this embodiment may be used to control a file system management system in any one of the following embodiments, and specific implementation manners may refer to the following embodiments, which are not described herein again.
The embodiment provides a file system management method, which includes acquiring a file creation request of a file to be created, configuring a pre-allocation required space size for the file to be created, acquiring idle information of a file system, acquiring tag information, and allocating a file space to be created for the file to be created according to the pre-allocation required space size from an idle starting position, so that file fragments during writing can be reduced or avoided, the continuous storage capacity of the same file is improved, and the read-write performance of the file system is improved.
Optionally, in this embodiment, metadata of the file system is stored in order based on leveldb, so that the read-write efficiency is high, the pressure of metadata operation on the hard disk IO is low, and the metadata operation and the file data read-write can be separated to different devices.
Optionally, the modification time and the file size of the file to be created after data reading and writing are recorded, so that the file size loss caused by power failure is avoided, and meanwhile, the phenomenon that the performance of an IO model is degraded into random reading and writing due to frequent updating of file node information to cause the expansion of the database caused by the occurrence of a large amount of repeated data in level0 in level db can be avoided.
Optionally, file spaces to be created are sequentially allocated from the free starting position and stored, so that the file spaces to be created are conveniently merged with adjacent data (free space) when the space is released (the occupied space of the deleted file when the file is deleted), and meanwhile, file spaces to be created are sequentially allocated by using a pre-allocation (the size of the space required by the pre-allocation) + circular allocation (the file spaces to be created are sequentially allocated from the free starting position), and particularly, when the ordering of the pre-space is from the end position of the occupied space, the file fragments can be effectively avoided through the end position of the initially allocable space and then being circulated back to the starting position of the initially allocable space to the end position of the occupied space).
Optionally, the operation of reading the disk when querying the file directory can be greatly reduced through node caching, the pressure of the hard disk is reduced, and the efficiency is improved.
Optionally, the embodiment provides a method for constructing a single-process file system based on a leveldb database and a block device, a fragment processing mechanism, and a high-efficiency power-fail protection mechanism, so that fragments are effectively prevented from being generated, and power-fail protection is effectively realized.
Example two
Referring to fig. 2, the embodiment provides a file system management system 200, the file system management system includes a file system module 201 and a metadata storage module 202 for storing file system metadata, the file system module 201 includes an access interface of the metadata storage module, the metadata storage module 202 includes an idle unit 2021 and a system recording unit 2022, where:
the idle unit 2021 is configured to record idle information of an idle space that is not allocated to a file, where the idle information includes idle position identifiers of a plurality of idle intervals;
the system recording unit 2022 is configured to record tag information, where the tag information includes an idle start position of each idle interval remaining after space allocation is performed by the file system for the last time, and an idle position identifier of one idle interval includes the idle start position;
and if a file creation request of the file to be created is received through the access interface, taking the idle initial position as a starting point, and allocating an idle space with the size of the required space to be pre-allocated to serve as the space of the file to be created according to the sequence of each idle interval.
In some embodiments, the idle position identifier includes an idle interval initial position and an idle interval end position, and allocating an idle space with a pre-allocated required space size as a file space to be created according to the sequence of each idle interval with the idle initial position as a starting point includes any one of:
and acquiring the size of the idle interval and the number of the idle position identifications in the idle information, allocating a file space to be created with the pre-allocated required space size for the file to be created according to the size of one or more idle intervals, the pre-allocated required space size and the idle starting position, and determining the size of the idle interval according to the initial position of the idle interval and the ending position of the idle interval.
Optionally, the obtaining of the size of the free interval and the number of the free position identifiers in the free information, and allocating, for the file to be created, the file space to be created, which is the size of the space required by the pre-allocation, according to the size of one or more free intervals, the size of the space required by the pre-allocation, and the free starting position, includes any one of the following:
if the idle information only comprises an idle position identification of an idle interval, the idle initial position is the same as the initial position of the idle interval, the size of the idle interval is determined according to the initial position of the idle interval and the end position of the idle interval, and if the size of the idle interval is larger than or equal to the size of the required pre-allocation space, the file space to be created with the size of the required pre-allocation space is allocated for the file to be created from the initial position of the idle interval;
if the idle information comprises idle position identifications of a plurality of idle intervals, determining a target interval from each idle interval according to an idle initial position, determining the size of the target interval according to the size of each idle interval of the target interval, and if the size of the target interval is larger than or equal to the size of the required pre-allocation space, allocating the space of the file to be created with the size of the required pre-allocation space in the target interval from the idle initial position of the target interval;
if the idle information comprises idle position identifications of a plurality of idle intervals, determining a target interval from each idle interval according to an idle starting position, determining the size of the target interval according to the size of each idle interval of the target interval, if the size of the target interval is smaller than the size of a pre-distribution required space, acquiring the size of a difference space between the size of the target interval and the size of the pre-distribution required space, determining a supplement interval according to the difference space, wherein the supplement interval comprises a plurality of idle intervals which are positioned behind the target interval and select the size of the difference space according to a sorting sequence, and taking the target interval and the supplement interval as a file space to be created.
Optionally, the determining manner of the supplemental interval includes at least one of:
acquiring the size of a first idle interval after a target interval, and if the size of the difference space is smaller than or equal to the size of the first idle interval, allocating the space with the size of the difference space in the first idle interval as a supplementary interval;
acquiring a first combination size of idle intervals of a first combination of idle intervals after a target interval in sequence, and if the difference space size is smaller than or equal to the first combination size of the idle intervals, allocating space with the difference space size in the first combination of the idle intervals as a supplementary interval;
and if the size of the first combination of the idle intervals and the size of the second combination of the idle intervals are larger than the size of the margin space, allocating the space with the size of the margin space in the first combination of the idle intervals and the second combination of the idle intervals in sequence as a supplementary interval.
In some embodiments, the metadata storage module comprises at least one of:
the node unit comprises a file unit and a directory unit and is used for recording attribute information of files and directories, wherein the attribute information comprises at least one of node identity identification information, father identity identification information, creation time, modification time, used size, size of a file space to be created and name, the node identity identification information is globally unique, and a current maximum value is loaded from the metadata storage module when reloading is carried out through accumulation distribution;
the index unit is used for searching files and scanning directories and comprises at least one of father identification information, names, identification information and types;
the active node unit is used for recording the modification time and the file size of the file to be created after data reading and writing;
and the allocation unit is used for recording the occupation information of the free space allocated to the file.
Optionally, the index unit records hierarchical management from top to bottom.
Optionally, the active node unit records real-time information of the first-layer directory and the opened file, including node identification information, modification time, file size, and size of space required for pre-allocation.
Optionally, the allocation unit is further configured to record an offset in the file; the system recording unit is also used for recording the configuration and status information of the file system module, such as information of the hard disk, partition information, allocated (occupied) condition, and the like.
Optionally, if the file system is restarted in case of power failure, the pre-written log is obtained and analyzed, and data recovery is performed on the file system according to the analyzed pre-written log. The pre-written log may be recorded and analyzed in a manner known to those skilled in the art, and is not limited herein. After the power failure is restarted, the modification time and the file size of the file to be created after data reading and writing can be read in the active node unit, and further the data inconsistency caused by power failure can be avoided.
Optionally, the metadata storage module includes a database, the idle unit includes an idle table, the system recording unit includes a system table, the node unit includes a node table, the index unit includes an index table, the active node unit includes an active node table, and the allocation unit includes an allocation table, where each table includes a table head identifier and a table tail identifier, and the prefixes of the primary keys between the tables are different.
Optionally, the metadata storage module includes, but is not limited to, a database, such as a leveldb database, and the like, and each unit may exist in the form of a data table, and each data table is distinguished by a KEY PREFIX, and PREFIX @ is additionally inserted as a header and a footer for fast positioning is inserted between the data tables.
Referring to fig. 3-1, fig. 3-1 is a schematic diagram of an Index table Index, which includes parent identification information pid, name, identification information id, and type; referring to fig. 3-2, fig. 3-2 is a schematic diagram of a Node table Node, which includes Node identification information id, parent identification information pid, creation time ctime, modification time mtiem, used size, to-be-created file space size allocsize, name; referring to fig. 3-3, fig. 3-3 is a schematic diagram of an Active node table Active, including node identification information id, modification time mtiem, used size, and file space size to be created allocsize; referring to fig. 3-4, fig. 3-4 are schematic diagrams of the Free table Free, including a Free interval initial position blkstart and a Free interval end position blkend; referring to fig. 3-5, fig. 3-5 are schematic diagrams of an allocation table Alloc, which includes node identification information id, offset in a file, initial occupancy position blkstart, and end occupancy position blkend; referring to fig. 3-6, fig. 3-6 are schematic diagrams of a system record table SYS, which includes a disk size disksize, an allocated (occupied) case unisize, tag information lastblk, and system information SYS;
in some embodiments, the file system management system further comprises a caching module, wherein the caching module is used for caching path and node information of the file system;
when node information is inquired, paths are matched in a cache module step by step, if matching fails, the node information is searched in a metadata storage module, and the node information is cached in the cache module;
when the node information is updated, the node information in the cache module is updated, and then the node information is stored in the metadata storage module;
and updating the metadata storage module through batch operation writing.
Fig. 4 is a schematic structural diagram of a cache module, as shown in fig. 4, the cache module includes a red-black Tree and an LRU linked list, the red-black Tree is used for querying node information through a path, and the LRU linked list is used for performing aging processing on the cache, where:
and when the cache is inserted, the cache node TreeNode is simultaneously added into the red-black tree and the LRU linked list, when the cache is accessed, the LRU linked list is updated, the oldest cache is released after the cache number reaches the upper limit, when the cache is invoked by io, the cache is moved out of the LRU linked list, the cache is managed by using the invocation count, and when the invocation count is 0, the LRU linked list is added again. FCache is file cache data, DCache is data cache data, IONode is a node for caching the IOs. The LRU linked list includes a number of ListNodes.
In some embodiments, the file system management system further comprises at least one of:
acquiring a father directory of a file to be created, if the file system comprises the father directory, distributing node identification information of the directory to be created for the directory to be created, and writing the node identification information of the directory to be created into a node unit, an index unit and a distribution unit respectively;
writing the occupation information of the file space to be created into the distribution unit;
updating an idle unit and/or a system recording unit according to the occupation information of the file space to be created;
acquiring a directory to be deleted, and if the directory to be deleted in the index unit is an empty directory, deleting the directory to be deleted in the node unit and the index unit;
acquiring deletion information of the deleted file, wherein the deletion information comprises an occupation position identifier of the deleted file, merging an occupation interval corresponding to the occupation position identifier of the deleted file with an idle interval, and updating the idle information in the idle unit and the occupation information in the distribution unit.
In some embodiments, the file system management system further includes an input/output module (io module), where the input/output module is configured to manage a file handle of an opened file to be created, the file handle is associated with node information, a file space to be created of the file to be created is obtained after the file to be created is opened, the file space to be created includes a plurality of idle intervals, the file to be created is subjected to data reading and writing, and the idle intervals are sequentially loaded into the cache module according to file offsets of the file to be created.
In some embodiments, the file offset may be derived in a manner known to those skilled in the art.
Optionally, the io module manages the file handle that has been opened. The handle is directly associated with the cache node to reduce memory usage and share file real-time status. When the file is opened, the distribution record part is loaded to the memory, when the file is read and written, the read-write position is calculated through the distribution record of the cache to carry out data read and write, when the read-write offset exceeds the cache record, the relevant distribution record is reloaded from the database, and the cache distribution record is prevented from occupying too much memory. And updating the modification time and size of the file after the data is written, and writing active records. The metadata is stored in the leveldb database in a K-V form. It can also be stored in other relational databases by overwriting the metadata in some way.
An example of allocation of a file space to be created is shown in fig. 5-1, 5-2, and 5-3, where only the idle information is deleted when the size of an idle interval in a scene shown in fig. 5-1 is equal to the size of the space required for pre-allocation, as can be seen from fig. 5-1, the occupied space ending position is 0, the size of the space required for pre-allocation is 50, the node ID is 2, the idle interval is (0,50), after space allocation, the idle information is deleted, at this time, the idle information Free is empty, the new occupied space ending position is 50, and the occupied space is (0, 50). After the sum of the sizes of the idle intervals of the scene two shown in fig. 5-2 exceeds the size of the pre-allocation required space, the old record is deleted and the remaining records are written in, as can be seen from fig. 5-2, the end position of the occupied space is 0, the size of the pre-allocation required space is 50, the node ID is 2, the idle intervals are (0,100), after the space allocation, the new idle information is (50,100), the end position of the new occupied space is 50, and the occupied space is (0, 50). The scenario three free record query shown in fig. 5-3 continues from the head of the table when the end of the table is reached. As can be seen from fig. 5-3, the occupied space ending position is 75, the size of the space required for pre-allocation is 50, the node ID is 2, the idle intervals are (0,50) and (75,100), after space allocation, the new idle information is (25,50), the new occupied space ending position is 25, and the occupied space is formed by two idle intervals of (75,100) and (0, 25).
Examples of space merging after file deletion are shown in fig. 6-1, 6-2 and 6-3, where the scene-occupied information shown in fig. 6-1 is not adjacent to the idle information and is directly inserted into the idle information, and as can be seen from fig. 6-1, when the idle information Free is empty, the occupied information Alloc is directly inserted into the idle information and the occupied information is deleted. The second and third allocation records of scenarios shown in fig. 6-2 and 6-3 are written into the merged record by deleting the adjacent record when the free information is adjacent. As can be seen from fig. 6-2, when "0" adjacent to the occupancy information Alloc exists in the Free information Free, the Free information is merged with the occupancy information, and then the Free information (0,100) is updated and the occupancy information is deleted. As can be seen from fig. 6-3, when the Free information Free has "25" adjacent to the partial occupancy information Alloc, the Free information and the occupancy information are merged, and then the Free information (0,50), (75,100) is updated, and the occupancy information is deleted.
In this embodiment, the system is substantially provided with a plurality of modules for executing the method in any of the embodiments, and specific functions and technical effects are only required by referring to the first embodiment, which is not described herein again.
Referring to fig. 7, fig. 7 is a schematic structural diagram of another file system management system, which includes a file system module fs, a database db, an input/output module io, and a cache module cache, where the database module is used to store metadata meta, and the io module processes data.
Referring to fig. 8, fig. 8 is a schematic view of a typical embedded file system scene, and as shown in fig. 8, the scene mainly includes a hard disk, a partition, data, a cache, an IO, and a file system interface fs, which are described as follows:
the hard disk is divided into an index partition, a data partition, and a backup partition. The data partition is divided in units of 1 MiB. The updates to db0 are asynchronously written to db1 for backup in the form of bulk operations, increasing database reliability. And after the loading is finished, checking the integrity of the main library and the back library, and preferentially using the main library synchronous standby library under the condition that the main library is complete, otherwise, using the standby library synchronous main library.
Referring to fig. 9, an embodiment of the present invention further provides an electronic device 600, which includes a processor 601, a memory 602, and a communication bus 603;
a communication bus 603 is used to connect the processor 601 and the memory 602;
the processor 601 is configured to execute a computer program stored in the memory 602 to implement the method according to one or more of the first embodiment.
An embodiment of the present invention also provides a computer-readable storage medium, characterized in that, a computer program is stored thereon,
the computer program is for causing a computer to perform the method as in any one of the above embodiments one.
Embodiments of the present application also provide a non-transitory readable storage medium, where one or more modules (programs) are stored in the storage medium, and when the one or more modules are applied to a device, the device may execute instructions (instructions) included in an embodiment of the present application.
It should be noted that the computer readable medium in the present disclosure can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
Computer program code for carrying out operations for aspects of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The foregoing embodiments are merely illustrative of the principles and utilities of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or change the above-mentioned embodiments without departing from the spirit and scope of the present invention. Accordingly, it is intended that all equivalent modifications or changes which can be made by those skilled in the art without departing from the spirit and technical spirit of the present invention be covered by the claims of the present invention.

Claims (18)

1. A file system management method, the method comprising:
acquiring a file creating request of a file to be created, and configuring the size of a pre-allocated space for the file to be created;
acquiring idle information of a file system, wherein the idle information comprises idle position identifiers of a plurality of idle intervals;
acquiring label information, wherein the label information comprises the idle initial position of each idle interval left after space allocation is carried out on the file system for the last time, and the idle position identifier of one idle interval comprises the idle initial position;
and from the idle starting position, distributing the file space to be created for the file to be created according to the sorting of the idle intervals and the size of the space required by the pre-distribution.
2. The file system management method according to claim 1, wherein said free location identifier comprises a free interval initial location and a free interval end location, and said allocating a file space to be created for said file to be created according to said pre-allocation required space size from said free initial location comprises:
and acquiring the size of the idle interval and the number of the idle position identifications in the idle information, allocating a file space to be created with the pre-allocated required space size for the file to be created according to one or more of the size of the idle interval, the size of the pre-allocated required space and the idle starting position, and determining the size of the idle interval according to the initial position of the idle interval and the ending position of the idle interval.
3. The file system management method according to claim 2, wherein said obtaining the size of the free space and the number of the free location identifiers in the free information, and allocating the file space to be created with the size of the space required for pre-allocation to the file to be created according to one or more of the size of the free space, the size of the space required for pre-allocation, and the free start location comprises any one of:
if the idle information only comprises an idle position identifier of the idle interval, the idle starting position is the same as the initial position of the idle interval, and if the size of the idle interval is larger than or equal to the size of the space required by pre-allocation, a file space to be created with the size of the space required by pre-allocation is allocated for the file to be created from the initial position of the idle interval;
if the idle information comprises idle position identifiers of a plurality of idle intervals, determining a target interval from each idle interval according to the idle initial position, determining the size of the target interval according to the size of each idle interval of the target interval, and if the size of the target interval is larger than or equal to the size of the required pre-allocation space, allocating a file space to be created with the size of the required pre-allocation space for the file to be created in the target interval from the idle initial position;
if the idle information comprises idle position identifications of a plurality of idle intervals, determining a target interval from each idle interval according to the idle starting position, determining the size of the target interval according to the size of each idle interval of the target interval, if the size of the target interval is smaller than the size of the space required for pre-allocation, obtaining the size of a difference space between the size of the target interval and the size of the space required for pre-allocation, determining a supplementary interval according to the difference space, wherein the supplementary interval comprises a plurality of idle intervals which are positioned behind the target interval and are selected according to a sorting sequence, and taking the target interval and the supplementary interval as the space of the file to be created.
4. The file system management method according to claim 3, wherein the supplemental interval is determined in a manner including at least one of:
acquiring the size of a first idle interval after the target interval, and if the size of the difference space is smaller than or equal to the size of the first idle interval, allocating the space with the size of the difference space in the first idle interval as a supplementary interval;
sequentially obtaining a first combination size of idle intervals of a first combination of idle intervals after a target interval, and if the difference space size is smaller than or equal to the first combination size of the idle intervals, allocating a space with the difference space size in the first combination of the idle intervals as a supplementary interval;
the method comprises the steps of sequentially obtaining a first combination size of idle intervals of a first combination of idle intervals after a target interval, sequentially obtaining a second combination size of idle intervals of a second combination of idle intervals before the target interval if the difference space size is larger than the first combination size of the idle intervals, and sequentially distributing space with the difference space size in the first combination of idle intervals and the second combination of idle intervals as supplementary intervals if the first combination size of idle intervals and the second combination size of idle intervals are larger than the difference space size.
5. The file system management method according to any one of claims 1 to 4, wherein the method further comprises:
acquiring deletion information of a deleted file, wherein the deletion information comprises an occupied position identifier of the deleted file;
and combining the occupied interval corresponding to the deleted file occupied position identification with the idle interval, and updating the idle information.
6. The file system management method according to claim 5, wherein said delete file occupying location identification includes an occupying initial location and an occupying end location, said free location identification includes a free interval initial location and a free interval end location, and updating said free information includes:
if the initial position and the end position of each idle interval in the idle information are different from the initial position and the end position of the occupied interval, adding the initial position and the end position of the occupied interval to the idle information;
if the idle interval initial position of an idle interval in the idle information is the same as the occupation end position, replacing the idle interval initial position with the occupation end position;
and if the idle interval ending position of one idle interval in the idle information is the same as the occupied initial position, replacing the idle interval ending position with the occupied initial position.
7. The file system management method according to any one of claims 1 to 4, wherein the method further comprises:
opening the file to be created, and acquiring a file space to be created of the file to be created, wherein the file space to be created comprises a plurality of idle intervals;
and reading and writing data of the file to be created, and sequentially loading each idle interval into a cache according to the file offset of the file to be created.
8. The file system management method according to claim 7, wherein said method further comprises:
and recording the modification time and the file size of the file to be created after data reading and writing.
9. The file system management method according to any one of claims 1 to 4, wherein full path and all node information of the file system are cached by a caching module, and metadata in the file system is stored by a metadata storage module, the method further comprising at least one of:
when node information is inquired, the full path is matched in the cache module step by step, if the matching fails, the node information is searched in the metadata storage module, and the node information is cached in the cache module;
when updating the node information, updating the node information in the cache module, and then storing the node information into the metadata storage module;
and updating the metadata storage module through batch operation writing.
10. The file system management method according to any one of claims 1 to 4, further comprising: and if the power failure restart happens, acquiring and analyzing a pre-written log, and performing data recovery on the file system according to the analyzed pre-written log.
11. A file system management system, comprising a file system module and a metadata storage module for storing file system metadata, the file system module comprising an access interface of the metadata storage module, the metadata storage module comprising a free unit and a system recording unit, wherein:
the idle unit is used for recording idle information of an idle space which is not allocated to a file, and the idle information comprises idle position marks of a plurality of idle intervals;
the system recording unit is used for recording label information, including the idle starting position of each idle interval left after space allocation is carried out by the file system for the last time, wherein the idle position identifier of one idle interval includes the idle starting position;
and if a file creation request of a file to be created is received through the access interface, allocating a free space with a pre-allocated required space size as a file space to be created according to the sequence of each free interval by taking the free starting position as a starting point.
12. The file system management system of claim 11, wherein the metadata storage module comprises at least one of:
the node unit comprises a file unit and a directory unit and is used for recording attribute information of files and directories, wherein the attribute information comprises at least one of node identity identification information, father identity identification information, creation time, modification time, used size, size of a file space to be created and name;
the index unit is used for searching files and scanning directories and comprises at least one of father identification information, names, identification information and types;
the active node unit is used for recording the modification time and the file size of the file to be created after data reading and writing;
and the allocation unit is used for recording the occupation information of the free space allocated to the file.
13. The file system management system according to claim 11, wherein the file system management system further comprises a caching module for caching path and node information of the file system;
when node information is inquired, the path is matched in the cache module step by step, if the matching fails, the node information is searched in the metadata storage module, and the node information is cached in the cache module;
when updating the node information, updating the node information in the cache module, and then storing the node information into the metadata storage module;
and updating the metadata storage module through batch operation writing.
14. The file system management system of claim 12, wherein the file system management system further comprises at least one of:
acquiring a father directory of a file to be created, if the file system comprises the father directory, distributing node identification information of the directory to be created for the directory to be created, and writing the node identification information of the directory to be created into the node unit, the index unit and the distribution unit respectively;
writing the occupation information of the file space to be created into the distribution unit;
updating the idle unit and/or the system recording unit according to the occupation information of the file space to be created;
acquiring a directory to be deleted, and if the directory to be deleted in the index unit is an empty directory, deleting the directory to be deleted in the node unit and the index unit;
acquiring deletion information of a deleted file, wherein the deletion information comprises an occupation position identifier of the deleted file, merging an occupation interval corresponding to the occupation position identifier of the deleted file with the idle interval, and updating the idle information in the idle unit and the occupation information in the allocation unit.
15. The file system management system according to claim 13, wherein the file system management system further includes an input/output module, the input/output module is configured to manage a file handle of the opened file to be created, the file handle is associated with the node information, a file space to be created of the file to be created is obtained after the file to be created is opened, the file space to be created includes a plurality of free intervals, data reading and writing are performed on the file to be created, and the free intervals are sequentially loaded into the cache module according to a file offset of the file to be created.
16. The file system management system according to any one of claims 12 or 14, wherein the metadata storage module includes a database, the free unit includes a free table, the system recording unit includes a system table, the node unit includes a node table, the index unit includes an index table, the active node unit includes an active node table, and the allocation unit includes an allocation table, wherein each table includes a head identifier and a tail identifier, respectively, and a primary key prefix is different between each table.
17. An electronic device comprising a processor, a memory, and a communication bus;
the communication bus is used for connecting the processor and the memory;
the processor is configured to execute a computer program stored in the memory to implement the method of any one of claims 1-10.
18. A computer-readable storage medium, having stored thereon a computer program,
the computer program is for causing the computer to perform the method of any one of claims 1-10.
CN202110859193.6A 2021-07-28 2021-07-28 File system management method, system, electronic equipment and medium Active CN113568868B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110859193.6A CN113568868B (en) 2021-07-28 2021-07-28 File system management method, system, electronic equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110859193.6A CN113568868B (en) 2021-07-28 2021-07-28 File system management method, system, electronic equipment and medium

Publications (2)

Publication Number Publication Date
CN113568868A true CN113568868A (en) 2021-10-29
CN113568868B CN113568868B (en) 2024-02-06

Family

ID=78168580

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110859193.6A Active CN113568868B (en) 2021-07-28 2021-07-28 File system management method, system, electronic equipment and medium

Country Status (1)

Country Link
CN (1) CN113568868B (en)

Citations (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1632765A (en) * 2004-12-31 2005-06-29 大唐微电子技术有限公司 A flash memory file system management method
CN101556557A (en) * 2009-05-14 2009-10-14 浙江大学 Object file organization method based on object storage device
CN101692252A (en) * 2009-08-31 2010-04-07 上海宝信软件股份有限公司 Method for distributing and reclaiming idle blocks of file
US20100185690A1 (en) * 2009-01-20 2010-07-22 Autodesk, Inc. Dynamic manipulation of archive files
CN104933169A (en) * 2015-06-29 2015-09-23 南开大学 File system defragmentation method based on hotspot file priority
CN105262697A (en) * 2015-11-24 2016-01-20 浪潮(北京)电子信息产业有限公司 Network traffic shunting method and system
CN105389376A (en) * 2015-11-18 2016-03-09 武汉微创光电股份有限公司 Contiguous block based non-fragmentation multimedia data storage method and system
CN105589812A (en) * 2015-12-16 2016-05-18 成都华为技术有限公司 Disk defragmentation method, disk defragmentation device and host
CN105740334A (en) * 2016-01-22 2016-07-06 中国科学院计算技术研究所 System and method for asynchronous and batched file creation in file system
US20170017413A1 (en) * 2014-03-11 2017-01-19 Hitachi Data Systems Engineering UK Limited Computer program product, method, apparatus and data storage system for controlling write operations in the data storage system
CN110149803A (en) * 2018-08-27 2019-08-20 深圳市锐明技术股份有限公司 Date storage method, system and terminal device
CN110221782A (en) * 2019-06-06 2019-09-10 重庆紫光华山智安科技有限公司 Video file processing method and processing device
CN111240599A (en) * 2020-01-17 2020-06-05 北京马赫谷科技有限公司 Data stream storage method and device
CN111309267A (en) * 2020-02-26 2020-06-19 Oppo广东移动通信有限公司 Storage space allocation method and device, storage equipment and storage medium
CN111522507A (en) * 2020-04-14 2020-08-11 中山大学 Low-delay file system address space management method, system and medium

Patent Citations (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1632765A (en) * 2004-12-31 2005-06-29 大唐微电子技术有限公司 A flash memory file system management method
US20100185690A1 (en) * 2009-01-20 2010-07-22 Autodesk, Inc. Dynamic manipulation of archive files
CN101556557A (en) * 2009-05-14 2009-10-14 浙江大学 Object file organization method based on object storage device
CN101692252A (en) * 2009-08-31 2010-04-07 上海宝信软件股份有限公司 Method for distributing and reclaiming idle blocks of file
US20170017413A1 (en) * 2014-03-11 2017-01-19 Hitachi Data Systems Engineering UK Limited Computer program product, method, apparatus and data storage system for controlling write operations in the data storage system
CN104933169A (en) * 2015-06-29 2015-09-23 南开大学 File system defragmentation method based on hotspot file priority
CN105389376A (en) * 2015-11-18 2016-03-09 武汉微创光电股份有限公司 Contiguous block based non-fragmentation multimedia data storage method and system
CN105262697A (en) * 2015-11-24 2016-01-20 浪潮(北京)电子信息产业有限公司 Network traffic shunting method and system
CN105589812A (en) * 2015-12-16 2016-05-18 成都华为技术有限公司 Disk defragmentation method, disk defragmentation device and host
CN105740334A (en) * 2016-01-22 2016-07-06 中国科学院计算技术研究所 System and method for asynchronous and batched file creation in file system
CN110149803A (en) * 2018-08-27 2019-08-20 深圳市锐明技术股份有限公司 Date storage method, system and terminal device
CN110221782A (en) * 2019-06-06 2019-09-10 重庆紫光华山智安科技有限公司 Video file processing method and processing device
CN111240599A (en) * 2020-01-17 2020-06-05 北京马赫谷科技有限公司 Data stream storage method and device
CN111309267A (en) * 2020-02-26 2020-06-19 Oppo广东移动通信有限公司 Storage space allocation method and device, storage equipment and storage medium
CN111522507A (en) * 2020-04-14 2020-08-11 中山大学 Low-delay file system address space management method, system and medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
罗凡等: "MySQL中InnoDB引擎的动态存储管理", 《东北师大学报(自然科学版)》, pages 22 - 26 *

Also Published As

Publication number Publication date
CN113568868B (en) 2024-02-06

Similar Documents

Publication Publication Date Title
US7349927B2 (en) Transactional file system for realizing atomic update of plural files by transactions
JP7410181B2 (en) Hybrid indexing methods, systems, and programs
US8423733B1 (en) Single-copy implicit sharing among clones
CN102629247B (en) Method, device and system for data processing
US20050234867A1 (en) Method and apparatus for managing file, computer product, and file system
CN113515487B (en) Directory query method, computing device and distributed file system
CN111459884B (en) Data processing method and device, computer equipment and storage medium
CN103106286A (en) Method and device for managing metadata
US11853566B2 (en) Management method and system for address space of low delay file system and medium
CN113568582B (en) Data management method, device and storage equipment
CN113377292B (en) Single machine storage engine
US8612717B2 (en) Storage system
CN112306957A (en) Method and device for acquiring index node number, computing equipment and storage medium
KR20090007926A (en) Apparatus and method for managing index of data stored in flash memory
CN113568868B (en) File system management method, system, electronic equipment and medium
CN116226232A (en) Persistent memory data storage method and system for distributed database
CN115964350A (en) File system management model and system
CN112860628A (en) File system scale management method and system
CN111984598A (en) High-performance metadata log file management method, system, medium and terminal
CN113204520B (en) Remote sensing data rapid concurrent read-write method based on distributed file system
CN115905259B (en) Pure column type updating method and device supporting row-level concurrency control
CN115827653B (en) Pure column type updating method and device for HTAP and mass data
CN114356232B (en) Data reading and writing method and device
US20050044090A1 (en) Computer system and program
CN116266100A (en) Distributed object storage management method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant