Introducing the reasons why Linux does not require defragmentation

巴扎黑
Release: 2017-08-23 15:31:16
Original
1373 people have browsed it

If you are a Linux user, you may have heard that Linux file systems do not require defragmentation. You may also notice that Linux distributions do not have disk defragmentation capabilities. Why is this?

To understand why the Linux file system will not be fragmented like the Windows file system, you must first understand how fragmentation is generated and how the file systems of these two major operating systems work. What a difference.

What is disk fragmentation?

Many Windows users, even some inexperienced users, believe that regularly defragmenting the file system will make their computers run faster. But none of them know why.

Simply put, a hard drive contains many sectors, and each sector can store a small piece of data. For files, especially larger files, they must be stored in many different sectors. Suppose you have many different files in your file system, and each file is stored in a contiguous group of sectors. Then, you increase the size of one of the files. The file system will first try to store the newly added portion of the file in a sector adjacent to the original sector group. But if there are not enough contiguous sectors in it, the file must be broken into multiple small pieces, and these operations are visible to you. When your hard drive reads these files, its heads have to jump between different physical locations to read consecutive groups of sectors, which slows it down.

Defragmentation is a sophisticated process of reducing fragmentation by moving files bit by bit (bit is the smallest unit of file storage on the disk) to ensure that each file is stored continuously on the hard disk. .

Of course, this is a little different for solid-state drives. Solid-state drives do not require moving files or defragmenting. Because defragmenting an SSD (Solid State Drive) will reduce its lifespan. Moreover, in the latest version of Windows system, you no longer need to worry about defragmentation, because Windows will automatically complete it for you.

How Windows file systems work

The FAT file system formerly used by Microsoft - was last seen as the default system in Windows 98 and ME, although this system is still on USB drives Using -- does not arrange the files very well. When you save a file in the FAT file system, it tries to arrange the file at the beginning of the disk as much as possible. When you store the next file, it will store it directly after the first file, and so on. So when the file gets larger, there will always be fragmentation, because there is no room next to the file to store the added parts.

Microsoft’s newer NTFS file system used in Windows XP and 2000 is trying to be a little smarter. This file system puts more free space called "buffers" around the files, but as any Windows user can tell you, the NTFS file system will one day become fragmented.

Because file systems behave like this, they require defragmentation to maintain performance. Microsoft can only mitigate this problem in the latest versions of Windows by automatically running defragmentation in the background.

How does the Linux file system work?

Linux's ext2, ext3, and ext4 file systems - ext4 is the file system used by Ubuntu and most current distributions - will be used in a more intelligent way way to place files. Linux's file system spreads files across the disk, leaving a lot of free space between files, rather than placing files one after another like Windows. When a file is edited and becomes larger, there is usually enough free space to save the file. If fragmentation does occur, the file system will attempt to reduce fragmentation by moving files around during daily use, so a specialized defragmentation program is not needed.

Because of the way this works, you may see fragmentation after your file system fills up. If 95% (or even 80%) of the file system is occupied, you'll start to see some fragmentation. However, such file systems are designed to reduce fragmentation in ordinary use.

If you really have problems with fragmentation on Linux, you may need a larger hard drive. If you really need to defragment a file system, the simplest and probably most reliable method is to copy all the files out, then clear the original partition, and then copy the files back. The file system will intelligently place the files as you copy them back.

You can use the fsck command to detect the degree of fragmentation of a Linux file system. Just check the number of non-contiguous inodes in the output.

The above is the detailed content of Introducing the reasons why Linux does not require defragmentation. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template