To "discuss" the size of the file and the size of the block

Source: Internet
Author: User
Tags syslog
Dumpe2fs/dev/sda3|head-n 30
DUMPE2FS 1.39 (29-may-2006)
FileSystem volume Name:/
Block size:4096

It says that my/file system block is 4k.

8.0K-RW-------1 root 3.9K Dec 22:08 anaconda-ks.cfg
4.0K-RW-------1 root 8 12:02 dead.letter
4.0K drwxr-xr-x 7 Root 4.0K may one 16:38 demo
16k-rw-r--r--1 root 12K Dec 22:08 Install.log
8.0k-rw-r--r--1 root 1.2K Dec 22:08 install.log.syslog

[Root@xxx ~]# Ll-s
Total 40
8-RW-------1 root 3981 Dec 22:08 anaconda-ks.cfg
4-RW-------1 root 8 12:02 dead.letter
4 drwxr-xr-x 7 root root 4096 May 16:38 demo
16-rw-r--r--1 root 11568 Dec 22:08 Install.log
8-rw-r--r--1 root 1191 Dec 22:08 Install.log.syslog

As shown above: The catalog file occupies the same size as the block size, such as demo this directory occupies 4K, a block
Why the size of the file, but far less than block size, such as the figure blue two lines, Install.log.syslog only 1.2K, and a Bock is 4K, but used 2 blok size 8K
According to information, it has been found that a few bytes of the file, why the new time when the two data block.

You should know that the size of the space used to create a new file is mainly to see block size. If the size of a file does not exceed the block size, it will theoretically occupy only 1 blocks.

When I use du-a in the main post, I see a small file that occupies 2 blocks, one of which is the data block of the file, and the other is the extra block that is enabled by the system by default on the SELinux.

I have done a few tests, one of which is when the inode size is 128, du-a see the small file occupies two blocks; When the inode size is 256, Du-a sees only one block and no matter how large the block size is. (Think about it, if a data block size is 4096, a few bytes of file is not occupied by 8192 of the space.) Oh, waste AH)

The data found also tells me that this is because when the system is enabled SELinux, the 128 bytes Inode is not enough to store the SELinux xattr, so a separate data block is needed to store the SELinux xattr. Of course the information is about XFS, but it's also the same in ext3 and EXT4, which explains why EXT4 the default recommendation for 256 bytes inode (because of the selinux, samba, beagle, and other software that might be added to future systems, You need to use your own extended properties).

I have also done another test to prove the correctness of the information stated:
The selinux shut down after restart, and then in the Inode for 128 bytes filesystem on the establishment of small files, du-a after the discovery that this file occupies only 1 blocks, the folder is also.

So far, the problem is solved.

conclusion, it is better to use MKFS.EXT4 to create file system in the future, efficient and convenient

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.