About to install Ubuntu 16.04 on a M.2 harddrive. Which file system should I use for speed? [closed]
About to install Ubuntu 16.04 on a Samsung M.2 harddrive. (using a USB-drive)
Which file system should I use?
- Fat32
- ext4
- ext3
- ext2
- NTFS
- another one I haven't mentioned?
My harddrive is:
1TB SAMSUNG SM961 M.2, PCIe NVMe (up to 3200MB/R, 1800MB/W)
If they all work, which one is the fastest?
Any tips/pitfalls for a frightened noob :)
Solution 1:
Quite simple. You use the filesystem which is best suited for your OS. For most Linux Distributions, Ubuntu included, this is:
ext4
NTFS and fat32 are not suited for Unix/Linux systems, since they are lacking features Linux needs. They might be a good choice for data partitions that need to be accessible from Windows systems. Be aware that fat32 cannot store files larger than 4GB, but it is the most compatible choice. Even old DOS can read/write fat32.
ext2 and ext3 are basically predecessors of ext4.
By the way, speed is not really a matter of filesystem. Harddrive and Bus (Connection, USB-Port) determine the speed of your file operations.
Solution 2:
Quite complex. There are significant differences between the filesystems you mention, and determining the impact of these differences on speed is, IMHO, non-trivial and depends on what operations will be done.
First, let's discard the possibility of installing your root filesystem on a FAT or NTFS partition. These filesystems aren't properly compatible with the Linux kernel and Linux filesystem permissions don't work properly on them, so you would have a lot of interesting problems.
Note: FAT32 is a good choice for USB installation media, and NTFS is a good choice in a dual boot (with Windows) scenario for partitions where you want to use to store personal stuff (like your media library for example) that should be accessible to both Ubuntu (or any other Linux system) and Windows. Linux systems can read (and write to) NTFS partitions as long as they have been mounted correctly, but ext* partitions aren't easily readable to Windows (as far as I know).
The ext* systems were designed to be used with the Linux kernel. Using ext2,3 or 4 for your Ubuntu installation would be perfectly sane. Probably the biggest differences between them are
- ext2 is non-journalling
- ext3 is journalling, but otherwise has similar data structures and features to ext2
- ext4 is journalling and has some performance-enhancing features including a faster algorithm for block allocation compared to earlier ext* systems, although it has similar data structures.
It's important to note, I think, that speed isn't the only consideration when choosing a filesystem. Ext4 has fewer limitations than earlier versions, allowing a larger filesystem, unlimited subdirectories etc. Ext3 is regarded by some as more tried-and-tested, safer and slightly less likely to lose data. I'll try to focus on speed here, while mentioning only the most salient things besides performance.
Wait what? Journalling?1
A journalling filesystem, in short, keeps a log of changes that have not yet been written to the main part of the filesystem. This is done so that in the event of a crash, it's easy to check the consistency of the filesystem by comparing the journal to what has been written to the main filesystem area. This means the speed of checking the filesystem is much faster with ext3 and ext4. Also, because ext4 allows unallocated blocks to be marked, checking them can be skipped, making fsck
even faster.
Ext4 also checksums the journal (allowing less I/O waits when writing) which gives a slight overall increase in speed compared to ext3.
Checking filesystem consistency might not be needed very often, and journalling comes at a price - more disk writes. Not only is this bad for a speedy SSD's lifespan, it can slow down performance (writing takes time). The general consensus seems to be that journalling is worth the cost, though.
Performance-enhancing features of ext4
Ext4 supports the fallocate()
system call to pre-allocate space for a file. The kernel allocates some blocks and marks them as initialised without writing to them, which is much faster than writing zeroes to the space as was done in older filesystems.
It also uses delayed allocation (or allocate-on-flush) which batches allocations (rather than performing many small ones), thus tending to reduce CPU usage and avoid fragmentation.
Ext4 is backwards compatible with ext2 and ext3, meaning that ext2 and 3 filesystems can be mounted as ext4 and enjoy a modest performance benefit since some features like the new block allocation algorithm can be used.
Other filesystems
Ext* are not the only fully Linux-compatible filesystems, though they are the best-known and most tested. Other filesystems use alternatives to journalling and have innovative features that may impact performance. Btrfs, for example, uses a copy-on-write method of preserving filesystem integrity instead of a journal. It has different data structures to ext* systems. As far as I know, Btrfs is not known to provide faster general performance than ext4, but is regarded as particularly good for archival storage of photo video files, as they are less likely to suffer degradation. It allows filesystem consistency to be checked and cleaned while in use, which might save time depending on your use case. In future, Btrfs or another innovative filesystem may be developed further to outperform ext4 convincingly on general speed.
Conclusion
Most Ubuntu users looking for good performance will want to stick with ext4 for now...
1This and other Linux filesystem concepts are explained really well in Understanding the Linux Kernel.