File System space allocation test

Source: Internet
Author: User

Disk block size = 1024


  1. Create an empty directory

[[Email protected] A] # ll-d

Drwxr-XR-X. 2 root Root 4096 September 8 21:12.<-- Directory files occupy 40 96b of space

[[Email protected] A] # ll

Total usage 0<-- The space occupied by the listed items is 0.

[[Email protected] A] #

[[Email protected] A] # stat.

File :"."

Size: 4096 blocks: 8 Io block: 4096 directory

Device: 802 H/2050d inode: 21 links: 2

Access: (0755/drwxr-XR-x) uid: (0/root) gid: (0/root)

Access: 21:12:34. 795998334 + 0800

Modify: 21:12:34. 094994871 + 0800

Change: 21:12:34. 094994871 + 0800

[[Email protected] A] #

Here, blocks = 8 is calculated based on blocksize = 512.


2. Create a file in directory.

[[Email protected] A] # ll

Total usage 0

-RW-r --. 1 Root 0 September 8 21:17 File<-- The file is empty and no space is allocated.

[[Email protected] A] # stat File

File: "file"

Size: 0 blocks: 0 Io block: 4096 common Empty files

Device: 802 H/2050d inode: 487 links: 1

Access: (0644/-RW-r --) uid: (0/root) gid: (0/root)

Access: 21:17:19. 250004408 + 0800

Modify: 21:17:19. 250004408 + 0800

Change: 21:17:19. 250004408 + 0800

[[Email protected] A] #




3. Write a letter to the file

[[Email protected] A] # dd If =/dev/Zero of =./file BS = 1 COUNT = 1

1 + 0 read records

1 + 0 records

1 byte (1 B) Copied, 0.000194625 seconds, 5.1 kb/second

[[Email protected] A] # ll

Total usage 4<-- The disk space occupied by files in the directory is 4 K

-RW-r --. 1 Root 1 September 8 21:34 File



[[Email protected] A] # stat File

File: "file"

Size: 1 blocks: 8 Io block: 4096 common file

Device: 802 H/2050d inode: 487 links: 1

Access: (0644/-RW-r --) uid: (0/root) gid: (0/root)

Access: 21:33:37. 360998812 + 0800

Modify: 21:34:09. 183999027 + 0800

Change: 21:34:09. 183999027 + 0800

[[Email protected] A] #

The actual file size is 1B, and the actual allocated space is 8 blocks (???)




4. Write 4095 characters to the file

[[Email protected] A] # dd If =/dev/Zero of =./file BS = 4095 COUNT = 1

1 + 0 read records

1 + 0 records

4095 bytes (4.1 KB) Copied, 0.00023078 seconds, 17.7 MB/second

[[Email protected] A] # ll

Total usage 4<-- The disk space occupied by files in the directory is 4 K

-RW-r --. 1 Root 4095 September 8 21:22 File


[[Email protected] A] # stat File

File: "file"

Size: 4095 blocks: 8 Io block: 4096 common file

Device: 802 H/2050d inode: 487 links: 1

Access: (0644/-RW-r --) uid: (0/root) gid: (0/root)

Access: 21:19:00. 327004441 + 0800

Modify: 21:22:44. 025009619 + 0800

Change: 21:22:44. 025009619 + 0800

[[Email protected] A] #

The actual file size is 4095b, and the actual allocated space is 8 blocks (???)


5. Write 4096 characters to the file

[[Email protected] A] # dd If =/dev/Zero of =./file BS = 4096 COUNT = 1

1 + 0 read records

1 + 0 records

4096 bytes (4.1 KB) Copied, 0.000166902 seconds, 24.5 MB/second

[[Email protected] A] # ll

Total usage 4<-- The disk space occupied by files in the directory is 4 K

-RW-r --. 1 Root 4096 September 8 21:23 File


[[Email protected] A] # stat File

File: "file"

Size: 4096 blocks: 8 Io block: 4096 common file

Device: 802 H/2050d inode: 487 links: 1

Access: (0644/-RW-r --) uid: (0/root) gid: (0/root)

Access: 21:19:00. 327004441 + 0800

Modify: 21:23:46. 621008028 + 0800

Change: 21:23:46. 621008028 + 0800

[[Email protected] A] #

The actual file size is 4096b, and the actual allocated space is 8 blocks (???)


6. Write 4097 characters to the file

[[Email protected] A] # dd If =/dev/Zero of =./file BS = 4097 COUNT = 1

1 + 0 read records

1 + 0 records

4097 bytes (4.1 KB) Copied, 0.000319839 seconds, 12.8 MB/second

[[Email protected] A] # ll

Total usage 8<-- The disk space occupied by files in the directory is 8 KB.

-RW-r --. 1 Root 4097 September 8 21:24 File

[[Email protected] A] # stat File

File: "file"

Size: 4097 blocks: 16 Io block: 4096 common file

Device: 802 H/2050d inode: 487 links: 1

Access: (0644/-RW-r --) uid: (0/root) gid: (0/root)

Access: 21:19:00. 327004441 + 0800

Modify: 21:24:33. 548004283 + 0800

Change: 21:24:33. 548004283 + 0800

[[Email protected] A] #

The actual file size is 4097b, and the actual allocated space is 16 blocks (???)


7. Write 1024*4*2-1 = 8191 characters to the file

[[Email protected] A] # dd If =/dev/Zero of =./file BS = 8191 COUNT = 1

1 + 0 read records

1 + 0 records

8191 bytes (8.2 KB) Copied, 0.00019196 seconds, 42.7 MB/second

[[Email protected] A] # ll

Total usage 8<-- The disk space occupied by files in the directory is 8 KB.

-RW-r --. 1 Root 8191 September 8 21:54 File

[[Email protected] A] # stat File

File: "file"

Size: 8191 blocks: 16 Io block: 4096 common file

Device: 802 H/2050d inode: 487 links: 1

Access: (0644/-RW-r --) uid: (0/root) gid: (0/root)

Access: 21:33:37. 360998812 + 0800

Modify: 21:54:23. 152997510 + 0800

Change: 21:54:23. 152997510 + 0800

[[Email protected] A] #

The actual file size is 8191b, and the actual allocated space is 16 blocks (???)



8. Write 1024*4*2 = 8192 characters to the file

[[Email protected] A] # dd If =/dev/Zero of =./file BS = 8192 COUNT = 1

1 + 0 read records

1 + 0 records

8192 bytes (8.2 KB) Copied, 0.000289364 seconds, 28.3 MB/second

[[Email protected] A] # ll

Total usage 8<-- The disk space occupied by files in the directory is 8 KB.

-RW-r --. 1 Root 8192 September 8 21:55 File

[[Email protected] A] # stat File

File: "file"

Size: 8192 blocks: 16 Io block: 4096 common file

Device: 802 H/2050d inode: 487 links: 1

Access: (0644/-RW-r --) uid: (0/root) gid: (0/root)

Access: 21:33:37. 360998812 + 0800

Modify: 21:55:07. 207994349 + 0800

Change: 21:55:07. 207994349 + 0800

[[Email protected] A] #

The actual file size is 8192b, and the actual allocated space is 16 blocks (???)


9. Write 1024*4*2 + 1 = 8193 characters to the file

[[Email protected] A] # dd If =/dev/Zero of =./file BS = 8193 COUNT = 1

1 + 0 read records

1 + 0 records

8193 bytes (8.2 KB) Copied, 0.000344005 seconds, 23.8 MB/second

[[Email protected] A] # ll

Total usage 12<-- The disk space occupied by files in the directory is 8 KB.

-RW-r --. 1 Root 8193 September 8 21:56 File

[[Email protected] A] # stat File

File: "file"

Size: 8193 blocks: 24 Io block: 4096 common files

Device: 802 H/2050d inode: 487 links: 1

Access: (0644/-RW-r --) uid: (0/root) gid: (0/root)

Access: 21:33:37. 360998812 + 0800

Modify: 21:56:24. 473997824 + 0800

Change: 21:56:24. 473997824 + 0800

[[Email protected] A] #

The actual file size is 8193b, and the actual allocated space is 24 blocks (???)



Summary:

1. Empty files do not occupy disk data blocks. They should occupy some space of directory files (keep metadata of this empty file) and inode records.

2. The system allocates disk space, 4 k = 1024*4 each time.

3. Total in ll shows the data block space occupied by the file, not the actual size of the file.

4. The number of blocks listed in stat is calculated based on blocksize = 512, that is, the number of slices occupied by the file.


What determines the amount of space allocated each time? Can it be changed? Is it related to io-block?

File System space allocation test

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.