Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

6.3 File system and data


May 23, 2021 That's what Linux should learn



The file establishment, writing, reading, modification, transfer and control performed by the user in the hardware storage device are all done by the file system. T he role of the file system is to plan the hard disk reasonably to ensure the normal use of the user's needs. Linux systems support dozens of file systems, and the most common file systems are shown below.

Ext3: is a log file system that avoids file system data loss in the event of system outages and automatically fixes data insopties and errors. H owever, when the hard drive is large, the repair time required can be long and there is no 100 percent guarantee that the data will not be lost. It pre-records the details of each write action on the entire disk so that it can be traced back to the interrupted part after an unusual outage and then attempted to fix it.

An improved version of Ext4:Ext3, as the default file management system in the RHEL 6 system, supports up to 1EB (1EB x 1,073,741,824GB) and an unlimited number of subdirecttors. In addition, the Ext4 file system is able to allocate block blocks in bulk, which greatly improves read and write efficiency.

XFS: Is a high-performance log file system, and the default file management system in RHEL 7, the advantages of which are particularly evident in unexpected downtime, i.e. the ability to quickly recover potentially compromised files, and the powerful log functionality with minimal computing and storage performance. And it has a maximum supportable storage capacity of 18EB, which meets almost all requirements.

One of the big changes in the RHEL 7 system is the use of XFS as a file system, unlike the Ext4 used by RHEL 6. A ccording to Red Hat's official statement, this is indeed a significant step forward, but Mr. Liu's test found that it is not entirely true. B ecause simply to test the "read" performance of a file system, in the end how many files to read, what is the size of each file, read the CPU, memory and other system resources, and different hardware configuration will have different effects, so after taking full account of these uncertainties, really dare not copy the official red hat introduction. Personally, I think the XFS is better than the Ext4 in terms of performance, but it's by no means overwhelming, so the highlight of the XFS file system should be the storage capacity that can support up to 18 EXB.

Just like getting an unchepped piece of complete paper, we first cut it for ease of use, and then draw a grid on the cropped paper so that we can write the whole work. O nce you have a new hard disk storage device, you also need to partition and then format the file system before you can mount it and use it properly. T he partitioning of your hard drive depends on your needs and the size of your hard drive; N ext, Mr. Liu Wei will brief you on what happened to the hard drive after it was formatted. Again, don't remember deliberately, as long as you can understand it.

There's so much data to save on your hard drive every day that you have a "hard drive map" called super block in your Linux system. L inux does not write the contents of the file directly to this "hard disk map", but records the information of the entire file system. B ecause if you write all the contents of the file here, it will become very large, and the contents of the file will become very slow to query and write. Linux simply records the permissions and properties of each file in inode, and each file occupies a separate inode table, which defaults to 128 bytes in size and records the following information:

Access to the file (read, write, execute);

The owner and group of the file (owner, group);

The size of the file (size);

The time at which the file was created or the contents were modified (ctime);

The last time the file was accessed (atime);

The time at which the file was modified (mtime);

Special permissions for files (SUID, SGID, SBIT);

The real data address (point) of the file.

The actual contents of the file are stored in a block block (which can be 1KB, 2KB, or 4KB), the default size of one inode is only 128B (Ext3), and the record of a block consumes 4B. W hen the file's inode is full, the Linux system automatically assigns a block block dedicated to recording information about other block blocks like inode, so that the contents of each block can be stringed together to allow the user to read the full file content. For block blocks that store file content, there are two common scenarios (illustrate by the block size of 4KB).

Scenario 1: The file is small (1KB), but still takes up a block, potentially wasting 3KB.

Scenario 2: If the file is large (5KB), it will take up two block (the remaining 1KB after 5KB-4KB will also occupy one block).

Computer system in the process of development has produced a large number of file systems, in order to enable users to read or write files without concern about the underlying hard disk structure, linux kernel software layer for the user program to provide a VFS (Virtual File System, virtual file system) interface, so that users actually when operating files is unified operation of this virtual file system. F igure 6-5 shows the schematic schematic of VFS. It can be seen that the actual file system under the VFS hides its own features and details, so that users in the daily use of the "file system is the same", but also can use a variety of commands in any file system to carry out various operations (such as the use of cp command to copy files).

6.3 File system and data

Schematic diagram of Figure 6-5 VFS