Linux File System Beginner

Source: Internet
Author: User

Linux disk partitions and directories

The difference between Linux distributions is very small, the difference is mainly in the system management of the characteristics of the tool and the software package management method is different.

The file structure of Windows is a multi-side tree structure, with different disks (partitions) at the top, such as C,d,e. and the Linux file structure is a tree-like structure.

Partitioning and Directory relationships:

1. Any partition must be mounted on a directory.

2. A directory is a logical distinction, and partitioning is a physical distinction.

3. root directory is all Linux files and directories

Here is the relationship of one of our possible directories and partitions:

Use DF to view the usage of each partition.

Mount Mount and NFS

When you want to use a device, such as to read a well-formatted partition, CD-ROM or software and other devices, you must first put these devices to a directory, and this directory is called "mount point", so that you can read these devices, so that the action is "mount." Mount is the mount instruction, and NFS is implemented by Mount.

LInux Space Management

L Inux is relatively simple for space management:

It divides the disk into the following three parts:

1) The Super block, the first block in the file system, is called the Super block. This block is called the Super block. This block holds information about the file system itself. For example, the Super Block records the size of each region, and the Super Block also stores information about unused disk blocks.

2) inode table, a part of the Super block is the Inode table. Each inode node is the structure of the corresponding file/directory. This organization contains information about the length of a file, the creation and modification times, the location of the disk, and so on.

3) data area, the third part of the file system is the data area. The contents of the file are saved in this area. A large file can easily be stored in thousands of separate disk blocks.

A file mainly contains the file name, attributes, data three items. The kernel stores the contents of the file in the data area, the file attributes are stored in the inode, and the filename is stored in the directory. Shows an example of creating a new file:

file File Type

There are several main file types for Linux:

1. Common Files: C language source code, shell script, binary executable, etc., divided into text files and binary files.

2. Catalog Files: directories, the only place where files are stored.

3. Link File: A file that points to the same directory or file.

4. Special files: equipment files, etc.

file storage Structure

Linux Orthodox file Systems (EXT2,EXT3, etc.) a file consists of directory entries, Inode, and data blocks.

Catalog entry: Include file name and inode node number

Inode: Also known as the file Index node, is the location of the basic information of the file and the data block pointer to the storage place.

Data BLOCK: The specific contents of the file to be stored.

The following is the overall structure:

The contents of the catalog entries are as follows:

Information in the Inode:

soft links, hard links:

Hard Links : is to give a copy of the file, while establishing a connection between the two, modify one, and its linked files are also modified. If you delete one of them, the remaining files will not be affected.

Soft Links : Also called symbolic link, when the source file is deleted, the symbolic link becomes water without, and the link is deleted, and the source file is not affected. However, the use and references to the linked files are directly called from the source file.

VFS

Virtual file system:

In addition to the Linux file system itself, in order to solve the problem of allowing Linux to support different file systems, it is necessary to incorporate the operation and management of various file systems into a unified framework, allowing the user program to operate on a variety of different file systems using the same set of system calls. In this way, the user program has hidden a variety of different file system implementation details, to provide users with a unified, abstract, virtual file system interface. This is known as the "virtual file system (VFS)".

problem

http://djt.qq.com/article/view/620

1. Mechanical disk Random read and write speed is very slow, what is the operating system used to improve the random read and write performance?

A picture of the drawings:

Disk polygons: Disks are made up of disk faces

Head: Each head corresponds to a disk face, which is responsible for reading and writing data on the plane.

Track: Each disc will be divided around the center of the Circle of Communication Circle, responsible for the disk surface of the data read and write

Cylinder: The three-dimensional track consisting of the same position on all platters is called a cylindrical surface.

Sector: The management units in the track are still too large, so the computer predecessors have divided each track into sectors.

Disk IO process: The first step is to move the head radially to find the track where the data is located. This part is called seek time.

Second, locate the target track and rotate it through the disk face, moving the target sector directly below the head.

Part Three: Write data to the target sector.

So the single disk IO time = seek time + rotation delay + access time.

So the answer is: because the data of a partition is usually read together, the operating system divides the partition by the cylinder corresponding to the track to reduce the seek time spent on disk IO, thus improving the read and write performance of the disk.


2. Does touch a new empty file occupy disk space? How much does it take to occupy?

Under Linux, create a new empty file will also occupy space, the actual occupation of 256Byte, the exact amount of an inode size, the specific inode size is based on the specific platform.


3. Do you want to create a new empty directory that consumes disk space? How much do you occupy? Which occupies a larger size than a new file?

Occupies 1 blocks size+1 inode size, a block size is typically 4KB
4. Do you know where the file name is recorded on the disk?

The file name is recorded in the directory of the block.
5. How long is the filename? Under what constraints?

The Linux limit file name length must not exceed 255byte.
6, the file name is too long will affect system performance? Why does it have an impact?

A long file name can have an impact on the system, as this may result in more disk IO, for example, because the file name is too long, causing the directory block to become large, then Linux looks for the specified file extreme conditions may need to traverse all blocks, generating a lot of overhead. 、。

The above question is why sometimes LS is fast, sometimes LS slow, is because the block too much, produced multiple IO.


7. How many files can be built in a directory?

This problem is limited to the number of inode in your directory, such as if there are 100w inode, you can create 100w files, but because of the problem mentioned above, a single directory under the file is best not to million, or LS and other commands or the first time the system operation will have a poor performance situation.


8, create a new content size of 1k files, how much disk space will actually occupy?

Will actually occupy a block plus the size of an inode:
9, to the operating system to initiate the Read File 2Byte command, the actual operating system will read how much?

The block device, of course, is read in block units.
10. How can we improve disk IO speed When we use files?

If you know how much space your new file will occupy, such as 1M, then create a new file with the operating system to say, let it help you to set the size of the file, so that the operating system will try to allocate a continuous block, when you read this file, the disk saves a lot of seek time, The IO speed appears much faster.

Note:

Use Df-i to see the number of inode per partition.

Use Du-h to view the actual hard disk space size of each file in the current directory.

If the files are larger than 4KB, even a few m. A few grams of files, then it is recommended block or as large as possible, so that the inode can be less than a few addresses.

If the file is mostly 1K or less, then using 4K as the block size can be a waste.



From for notes (Wiz)

Linux File System Beginner

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.