Overview of the Log File System in Linux System

  

As we all know, the file system is the most important part of the operating system
. Each operating system
has its own file system. The file system directly affects the stability and reliability of the operating system
. There are usually two file systems under Linux, the journal file system and the non-log file system. The following two types of file systems are briefly introduced.
1. Non-log file system Non-log file system does not log file system changes when it is working. The file system stores data on disk by allocating file blocks to files. Each file occupies more than one disk sector on the disk. The job of the file system is to maintain the file on the disk and record which sectors are occupied by the file. In addition, the use of the sector is also recorded on the disk. When the file system reads and writes a file, it first finds the sector number used by the file and then reads the file contents from it. If you want to write a file, the file system first finds the available sectors and appends the data. The file sector usage information is also updated at the same time. Different file systems allocate and read file blocks in different ways. For example, dos/windows uses the fat file system, while windows NT uses the NTFS file system. The non-log file system works very well, but it has a lot of problems. Please see, for an ordinary log file system, such as the Ext2 file system, if the system just writes the file's disk-partition information (meta-data) to the disk partition, it has not had time to write the file contents to disk. The accident happened: the system was powered off, and the result would be: the content of the file is still old content, and the meta-data information is new content, the two are inconsistent. Let's take a look at how fsck works on Linux systems: Normally, when the Linux system starts, first run fsck, which scans all local filesystems listed in the /etc/fstab file. The job of fsck is to ensure that the metadata of the file system to be mounted is in a usable state. When the system is shut down, fsck forwards all buffer data to disk and ensures that the file system is completely uninstalled to ensure normal use the next time the system boots. However, unexpected power failure or other failures will cause the system to freeze and restart. When this happens, the operating system does not have time to unmount the file system. After rebooting, fsck thoroughly scans the disk, thoroughly checks the metadata, and tries to correct any errors that can be found during the check. Thorough consistency checking of all metadata is extremely time consuming. The larger the file system, the longer it takes to complete a thorough scan. Fsck also encountered disk errors that it could not fix. In this case, simply delete or save the file as a file. In high-density access data centers, fsck can cause tremendous data file corruption. The Linux system can only be used after fsck has finished scanning, checking, and repairing. Of course, if there are serious files or data loss, the system may not be able to restart! Types of non-log file systems: Linux can support a wide variety of file systems, and almost all Linux distributions use ext2 as the default file system. The Ext2 file system is a non-log file system. In addition, other non-log file systems supported by Linux are: FAT, VFAT, HPFS (OS/2), NTFS (Windows
NT), Sun's UFS, and so on. Second, the log file system The log file system is based on the non-log file system, adding log records of file system changes. The design idea of ​​the log file is to keep track of changes in the file system and record the changes. The idea of ​​a journaled file system comes from a large database system. Database operations consist of multiple related, interdependent sub-operations. The failure of any sub-operation means the invalidity of the entire operation. Therefore, any modification to the data requires a return to the previous state of the operation. A similar technology is used in the journaled file system. The log file system saves the log records in the disk partition. The write operation firstly operates the log file. If the entire write operation is interrupted for some reason (such as system power failure), when the system restarts, the interrupt will be resumed according to the log record. The previous write operation. This process takes only a few seconds to a few minutes. How does the journal file system work? In the log file system, all file system changes, additions, and changes are recorded in "log" (that is, data for recording file metadata information). At regular intervals, the file system will write the updated file metadata and file contents to disk, and then delete this part of the log. Restart the new log record. Before making any changes to the metadata, the file system driver writes an entry to the log describing what it will do. Then it continues and modifies the metadata. In this way, the log file system has a history of recent metadata modifications. When it is checked that there is no consistency problem with the file system that has been completely uninstalled, it is only necessary to perform a corresponding check based on the data modification history. That is, in addition to storing data and metadata, the log file system also stores a log, which we can call meta-data (metadata about metadata). The log file system makes data and files safer, but the overhead is increased. Every update and most log operations require write synchronization, which requires more disk I/O operations. From the principle of log files, it is a good idea to use the journaling file system on partitions that require frequent write operations. A log file system or a non-log file system can be mixed in a Linux system. The log increases the time for file operations, but from the perspective of file security, the security of disk files has been greatly improved. The author has tested the log file system. The performance of the log file system is not much more than the performance of the ext2 file system. Some log file systems use the B+ tree algorithm. When operating some large files, the performance is negative. The performance of the log file system is even better. What are the benefits of using a journaling file system? The security of the file is improved, the chances of file corruption are reduced, the scan time for the disk is shortened, and the number of scans is reduced. When the system is unexpectedly down, there will be no loss of file content. At least the file should keep the content of the previous version. With the log file system, the disk will be scanned once every 20-30 times. , the number of scans is reduced

Copyright © Windows knowledge All Rights Reserved