Linux---10-20

Source: Internet
Author: User
Tags inode usage

A detailed description of Linux file attributes:

[Email protected] robin]# Ls-ihl/home/robin/test.txt
398606-rw-r--r--. 1 root root 2315 Mar 21:00/home/test.txt

The columns correspond to the following explanations:

Inode node Number file type permissions hard links number of main genus group file/directory size last Modified Date File/directory name

398606-rw-r--r--. 1 root root 4M Mar 21:00/home/test.txt

Inode node Number: the equivalent of a book directory, we want to read this book, first read the directory of the book, to the computer, read the file when the Inode node number

File type permissions:-/d//l/s/c/b represents the file type, and the following 9 bits represent the basic permissions for the file. There is no point in CentOS 5. Centos 6 is a bit, and this point is related to SELinux. If you turn SELinux off, then the newly created file will not have a point behind the permission bit. ??

Hard Links: Note Not the number of soft connections

Master: File Owner

Genus Group: Filegroups

Size: The default size of the directory is 4K, (because in Linux, when the file system is formatted, CENTOS6 is not a system partition, its block size is 4K)

Time: Mtime Modify Time (not atime, CTime)

########### #分隔符 ############

Inode Overview:

The hard disk is partitioned and then formatted to create the file system.

Inode, Chinese means that the index node, after each Linux storage device or storage device partition is formatted as EXT3, Ext4 file system, generally have two parts: the first part is the Inode (many), The second part is the block (many)---formatting is the essence of: Create a file can be stored in the format (ext3, EXT4).

Block is used to store the actual data.

The inode is used to store these data attribute information (that is, the result of Ls-l), the inode contains the attribute information including file size, owner, attribution user group, read and Write permissions, file type, modification time, It also includes the ability to pointer to a file entity (inode node--block), etc., but does not include the file name. In addition to logging information about the properties of a file, the Inode also indexes the information for each file, so there is a value for the inode. According to the instructions, the system can find the corresponding file entity as quickly as possible through the Inode value. The relationship between file name and Inodeblock is as follows;

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/5B/3C/wKioL1UC7jeArOFWAACBftqE3Lg991.jpg "title=" 33333333.png "alt=" Wkiol1uc7jearofwaacbftqe3lg991.jpg "/>

This diagram is a Linux ext4 file system, different file systems, this relationship is different. Oldboyfile is the file name ls-l see, this file in the disk or partition corresponding to a unique inode,inode in the Ls-l display property information, but does not include the file name, the file name is stored in the file name of the parent directory block, The inode also contains a pointer to a block that holds the specific data . So read the file, first find the filename, and then find the file name corresponding to the inode, in this according to the permissions of the file (rw-r--r--) to determine whether you allow access, if allowed, then the inode will take you to locate the file corresponding to the block of data. A file will only correspond to an inode, but the inode below the corresponding block more than one, because the size of the block, in the CENTOS6 default is 4K, but put a video 4K obviously not fit, so there will be a lot of block.

For example, the whole book is a disk or partition, the index of the home page is equivalent to the inode, each page is equivalent to a block (this page holds the specific text content).

So when viewing a file, the inode is found by file name, and then the block that holds the file data is found based on the inode information.

Because the inode is to hold the file's attribute information, the inode is of a size, the default size of the Centos5 inode is 128K, and the default size of the CENTOS6 Inode is 256 bytes (the non-/boot/partition is the 256k,/boot partition is 128K), The size of the inode cannot be changed after the file system has been formatted, and the inode size can be specified before formatting, but the general working environment does not have this requirement.

Commands to view inode size

[Email protected]C6]# Dumpe2fs/dev/sda3 | Grep-i "Inode Size"----/dev/sda3 non-boot partition
DUMPE2FS 1.41.12 (17-may-2010)
Inode size:256

[Email protected]C6]# dumpe2fs/dev/sda1 | Grep-i "Inode size" ----/dev/sda1 is/boot partition
DUMPE2FS 1.41.12 (17-may-2010)
Inode size:128

Note the inode size and block size may be different for the/boot partition and the non/boot partition

To view the Inode usage of a disk

[Email protected] ~]# df-i
Filesystem inodes iused IFree iuse% mounted on
/dev/xvda2 1687552 81114 1606438 5%/
TMPFS 480300 1 480299 1%/DEV/SHM
/DEV/XVDA1 76912 76874 1%/boot

View disk space usage

[Email protected] ~]# df-th
Filesystem Type Size used Avail use% mounted on
/dev/xvda2 ext4 26G 3.1G 21G 13%/
Tmpfs tmpfs 1.9G 0 1.9G 0%/dev/shm
/DEV/XVDA1 ext4 291M 34M 243M 13%/boot

Summary:

1), the disk partition after the format becomes EXT3/EXT4 will generate a certain number of inode and block,

2), Inode is an index node, the function is to store the properties of the file and as a file index (the entity block pointing to the file)

3), Inode is a piece of storage space, Centos 6 non/boot partition size default is 256k,centos 5 non-boot default is 128K

4), Inode is a series of numbers, corresponding to different files, the inode in the file system is the only difference (file system * * *)

In the file system also has the inode number is the same, then the timely hard link file, such a file can be considered a file because the inode is the same, so can say inode the same file as a file, or each other as a hard-link file

eg

[[email protected] robin]# touch a
[[Email protected] robin]# LN a b

[Email protected] robin]# LL-IHL *
398607 -rw-r--r--. 2 root root 0 Mar 23:07 a
398607 -rw-r--r--. 2 root root 0 Mar 23:07 b

5),inode the same file as a file, or each other as a hard-link file

6), a file must occupy at least one inode and one block

7), ext3 and Ext4 file system blocks are stored in the actual contents of the file,

8), the size of the block generally has 1k,2k,4k which the boot partition, such as 1K, other ordinary partition 4K (C6),

9), if a file is large, can occupy multiple blocks, if a file is small, at least one block, and the remaining space wasted.

10), Inode size view: Dumpe2fs/dev/sda3 | Grep-i "Inode Size"

Inode totals view: dumpe2fs/dev/sda1 | Grep-i "Inode Count"

Inode Totals and Usage views: df-i

11), how to survive and how to make the inode size

Mkfs.ext4-b block-size-i Inode-size/dev/sdb

Mkfs.ext4-b 2048-i 256/DEV/SD

Knowledge of block

1, the disk read data is read in block units, one-time to read the contents of a block.

2, a file may occupy multiple blocks, and each block read will consume disk IO once

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5B/3D/wKioL1UDDgXALfTgAAFrvAku6qI867.jpg "title=" Aaaaaaaaaa.jpg "alt=" Wkiol1uddgxalftgaafrvaku6qi867.jpg "/>

The latency of the ordinary hard disk is very large, so we should try not to access disk IO, or to read as much as possible at once. This will make the disk IO less. Blocks are larger and more data can be read at once.



3, if you want to increase the disk IO, then try to read as much as possible at once.

4, a block can only hold a file content, no matter how small, if the block 4K storage 1K files, then the remaining 3K is wasted.

5, so block is not the bigger the better, block too big, for small files will waste disk space, such as: 1000K files, 4Kblock occupies 250, 1Kblock occupies 1000, access efficiency who is higher? Consumption of Io is 250 and 1000 respectively ( disk read data is read in block, one time to read the contents of a block ).

6, large file (larger than 16K) general settings block larger, small files (less than 1K) general settings block smaller.

7,block too big for example 4 K, files are 0.1K, a lot of wasted disk space.

8,block settings are also set when the partition is formatted.

Mkfs.ext4-b block-size-i Inode-size/dev/sdb

Mkfs.ext4-b 2048-i 256/DEV/SD

9, when the file is large, the block setting will increase the disk access efficiency, EXT3/EXT4 is generally set to 4K

10. View the size of block size

Dumpe2fs/dev/sda3 | Grep-i "Block Size"


Block blocks larger for a single small file (0.5K) more business, will be very wasteful disk space, because a file no matter how large will have to occupy at least one inode and a block, the disk read data is in block units read, but for large files, can improve the efficiency of reading, because if the block is too small, To read more than one block, this consumes disk IO, and if the block is large, it will read the data by reading fewer blocks, thus reducing disk IO.

The current production environment is generally set to 4K, special business (such as video), can increase the block (#注: EXT4 does not support too large block)

Block large, wasted space, small, affecting disk read performance.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5B/3D/wKioL1UDEWyBpJtrAAE_SLtO4C4318.jpg "title=" Kkkkkkkk.png "alt=" Wkiol1udewybpjtraae_slto4c4318.jpg "/>

Files are 1M, if the block is 4K, need 250, if the block is 1K, then 1000, from the reading speed, read a block is an IO, the IO consumption is 250 and 1000 respectively. So it can be concluded that: when the file itself is relatively large, the block is set to a good size, will improve the efficiency of disk access. Ext3, EXT4 is generally set to 4K.

Production environment: How is the size of the block configured?

If it is a large file business, block as much as possible to set a larger

If it is a small file business, block try to set a smaller

Actual: Ext2, ext3, Ext4 maximum can only 4 K, and the work of almost no less than 4K files, so ext2, ext3, Ext4 file system, block are assigned to 4K.

Summary of the total:

1), disk partition format file system, will be divided into inode and block two parts of the content

2), the inode holds the attributes of the file and pointers to the file entity, the filename is not in the inode, but in the upper directory block.

3), access to files, through file files--->inode---->blocks

4), Inode in general, the default size is 256b,block size 1K, 2K, 4K, the default is 4K, note, boot partition, such as special partitions except.

5), through Df-i view the number of inode and usage, Dumpe2fs/dev/sda3 view the inode and block size and quantity.

6), a file must occupy at least one inode and a block, multiple files can occupy the same inode (hard link), the same file

7), a block can only be used by a file, if the file is very small, block is large, the remaining space is wasted, can not continue to be used by other files.

Example Demo:

Add a new hard drive

Fdisk-l #查看磁盘的情况, found a new plate/DEV/SDB

Fdisk/dev/sdb #进行分区

N: Increase partition P-primary partition; e-logical partition P: Print W: Write to partition Table Partprobe: Does not restart the partition table directly in effect

Mkfs.ext4-b 8192/DEV/SDB1 # # # #因为大于4K, there will be warnings, whether the actual use of the process support unknown (so not recommended)

Mkfs.ext4-b 1024-i 512/DEV/SDB1

mount/dev/sdb1/mnt/

Touch/mnt/aaa.txt

Df-th

umount/mnt/

Interview questions:

A 100M (100000K) disk partition, write 1K files, or write 1M files, how many can be written separately?

Error Answer:

The number of 1K is 100m*1000/1k=100000

The number of 1M is 100m/1m=100

The answer to this question is actually to answer the INODE and block related knowledge point is good. Refer to the following:





















Linux---10-20

Related Article

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.