Monday, June 6, 2011

Why does du(1) report different file sizes for ZFS and UFS? Why doesn't the space consumption that is reported by the df command and the zfs list command match?

SkyHi @ Monday, June 06, 2011



ZFS Frequently Asked Questions (FAQ)


For information about dedup, see the ZFS Dedup FAQ. 
  1. ZFS Product Release Questions
  2. ZFS Technical Questions
  3. ZFS/UFS Comparison Questions
  4. ZFS Administration Questions
  5. ZFS and Other Product Interaction Questions

ZFS Product Release Questions

  1. How can I get ZFS?
  2. When will ZFS be available for
  3. What does ZFS stand for?

How can I get ZFS?

ZFS is available in the following releases:

When will ZFS be available for

Projects are under way to port ZFS to FreeBSD and to Linux (using FUSE). For more information on CDDL, see the licensing FAQ.

What does ZFS stand for?

Originally, ZFS was an acronym for "Zettabyte File System." The largest SI prefix we liked was 'zetta' ('yotta' was out of the question). Since ZFS is a 128-bit file system, the name was a reference to the fact that ZFS can store 256 quadrillion zettabytes (where each ZB is 270 bytes). Over time, ZFS gained a lot more features besides 128-bit capacity, such as rock-solid data integrity, easy administration, and a simplified model for managing your data.

ZFS Technical Questions

  1. Why does ZFS have 128-bit capacity?
  2. What limits does ZFS have?

Why does ZFS have 128-bit capacity?

File systems have proven to have a much longer lifetime than most traditional pieces of software, due in part to the fact that the on-disk format is extremely difficult to change. Given the fact that UFS has lasted in its current form (mostly) for nearly 20 years, it's not unreasonable to expect ZFS to last at least 30 years into the future. At this point, Moore's law starts to kick in for storage, and we start to predict that we'll be storing more than 64 bits of data in a single filesystem. For a more thorough description of this topic, and why 128 bits is enough, see Jeff's blog entry.

What limits does ZFS have?

The limitations of ZFS are designed to be so large that they will never be encountered in any practical operation. ZFS can store 16 Exabytes in each storage pool, file system, file, or file attribute. ZFS can store billions of names: files or directories in a directory, file systems in a file system, or snapshots of a file system. ZFS can store trillions of items: files in a file system, file systems, volumes, or snapshots in a pool.

ZFS/UFS Comparison Questions

  1. Why doesn't ZFS have an fsck-like utility?
  2. Why does du(1) report different file sizes for ZFS and UFS? Why doesn't the space consumption that is reported by the df command and the zfs list command match?
  3. Can I set quotas on ZFS file systems? 

Why doesn't ZFS have an fsck-like utility?

There are two basic reasons to have an fsck-like utility:
  • Verify file system integrity - Many times, administrators simply want to make sure that there is no on-disk corruption within their file systems. With most file systems, this involves running fsck while the file system is offline. This can be time consuming and expensive. Instead, ZFS provides the ability to 'scrub' all data within a pool while the system is live, finding and repairing any bad data in the process. There are future plans to enhance this to enable background scrubbing.
  • Repair on-disk state - If a machine crashes, the on-disk state of some file systems will be inconsistent. The addition of journalling has solved some of these problems, but failure to roll the log may still result in a file system that needs to be repaired. In this case, there are well known pathologies of errors, such as creating a directory entry before updating the parent link, which can be reliably repaired. ZFS does not suffer from this problem because data is always consistent on disk.
    A more insidious problem occurs with faulty hardware or software. Even file systems or volume managers that have per-block checksums are vulnerable to a variety of other pathologies that result in valid but corrupt data. In this case, the failure mode is essentially random, and most file systems will panic (if it was metadata) or silently return bad data to the application. In either case, an fsck utility will be of little benefit. Since the corruption matches no known pathology, it will be likely be unrepairable. With ZFS, these errors will be (statistically) nonexistent in a redundant configuration. In an non-redundant config, these errors are correctly detected, but will result in an I/O error when trying to read the block. It is theoretically possible to write a tool to repair such corruption, though any such attempt would likely be a one-off special tool. Of course, ZFS is equally vulnerable to software bugs, but the bugs would have to result in a consistent pattern of corruption to be repaired by a generic tool. During the 5 years of ZFS development, no such pattern has been seen.

Why does du(1) report different file sizes for ZFS and UFS? Why doesn't the space consumption that is reported by the df command and the zfs list command match?

On UFS, the du command reports the size of the data blocks within the file. On ZFS, du reports the actual size of the file as stored on disk. This size includes metadata as well as compression. This reporting really helps answer the question of "how much more space will I get if I remove this file?" So, even when compression is off, you will still see different results between ZFS and UFS.
When you compare the space consumption that is reported by the df command with the zfs list command, consider that df is reporting the pool size and not just file system sizes. In addition, df doesn't understand descendent datasets or whether snapshots exist. If any ZFS properties, such as compression and quotas, are set on file systems, reconciling the space consumption that is reported by df might be difficult.
Consider the following scenarios that might also impact reported space consumption:
  • For files that are larger than recordsize, the last block of the file is generally about 1/2 full. With the default recordsize set to 128 KB, approximately 64 KB is wasted per file, which might be a large impact. The integration of RFE 6812608 would resolve this scenario. You can work around this by enabling compression. Even if your data is already compressed, the unused portion of the last block will be zero-filled, and compresses very well.
  • On a RAIDZ-2 pool, every block consumes at least 2 sectors (512-byte chunks) of parity information. The space consumed by the parity information is not reported, but because it can vary, and be a much larger percentage for small blocks, an impact to space reporting might be seen. The impact is more extreme for a recordsize set to 512 bytes, where each 512-byte logical block consumes 1.5 KB (3 times the space).
    Regardless of the data being stored, if space efficiency is your primary concern, you should leave the recordsize at the default (128 KB), and enable compression (to the default of lzjb).
  • The df command is not aware of deduplicated file data.

Can I set quotas on ZFS file systems? 

Yes, ZFS provides several different quota features:
  • File system quotas (quota property) - ZFS file systems can be used as logical administrative control points, which allow you to view usage, manage properties, perform backups, take snapshots, and so on. For home directory servers, the ZFS model enables you to easily set up one file system per user. ZFS quotas are intentionally not associated with a particular user because file systems are points of administrative control. ZFS quotas can be set on file systems that could represent users, projects, groups, and so on, as well as on entire portions of a file system hierarchy. This allows quotas to be combined in ways that traditional per-user quotas cannot. Per-user quotas were introduced because multiple users had to share the same file system. ZFS file system quotas are flexible and easy to set up. A quota can be applied when the file system is created. For example:
# zfs create -o quota=20g tank/home/users
User file systems created in this file system automatically inherit the 20-Gbyte quota set on the parent file system. For example: 
# zfs create tank/home/users/user1
# zfs create tank/home/users/user2
# zfs list -r tank/home/users
NAME                   USED  AVAIL  REFER  MOUNTPOINT
tank/home/users        76.5K  20.0G  27.5K  /tank/home/users
tank/home/users/user1  24.5K  20.0G  24.5K  /tank/home/users/user1
tank/home/users/user2  24.5K  20.0G  24.5K  /tank/home/users/user2
ZFS quotas can be increased when the disk space in the ZFS storage pools is increased while the file systems are active, without having any down time.
  • Reference file system quotas (refquota property) - File system quota that does not limit space used by descendents, including file systems and snapshots
  • User and group quotas (userquota and groupquota properties) - Limits the amount of space that is consumed by the specified user or group. The userquota or groupquota space calculation does not include space that is used by descendent datasets, such as snapshots and clones, similar to the refquota property.
In general, file system quotas are appropriate for most environments, but user/group quotas are needed in some environments, such as universities that must manage many student user accounts. RFE 6501037 has integrated into Nevada build 114 and the Solaris 10 10/09 release.
An alternative to user-based quotas for containing disk space used for mail, is using mail server software that includes a quota feature, such as the Sun Java System Messaging Server. This software provides user mail quotas, quota warning messages, and expiration and purge features.

ZFS Administration Questions

  1. Why doesn't the space that is reported by the zpool list command and the zfs list command match?
  2. What can I do if ZFS file system panics on every boot?
  3. Does ZFS support hot spares?
  4. Can devices be removed from a ZFS pool?
  5. Can I use ZFS as my root file system? What about for zones?
  6. Can I split a mirrored ZFS configuration?
  7. Why has the zpool command changed?

Why doesn't the space that is reported by the zpool list command and the zfs list command match?

The SIZE value that is reported by the zpool list command is generally the amount of physical disk space in the pool, but varies depending on the pool's redundancy level. See the examples below. The zfs list command lists the usable space that is available to file systems, which is disk space minus ZFS pool redundancy metadata overhead, if any.
  • A non-redundant storage pool created with one 136-GB disk reports SIZE and initial FREE values as 136 GB. The initial AVAIL space reported by the zfs list command is 134 GB, due to a small amount pool metadata overhead.
# zpool create tank c0t6d0
# zpool list tank
NAME   SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
tank   136G  95.5K   136G     0%  1.00x  ONLINE  -
# zfs list tank
NAME   USED  AVAIL  REFER  MOUNTPOINT
tank    72K   134G    21K  /tank
  • A mirrored storage pool created with two 136-GB disks reports SIZE as 136 GB and initial FREE values as 136 GB. This reporting is referred to as the deflated space value. The initial AVAIL space reported by the zfs list command is 134 GB, due to a small amount of pool metadata overhead.
# zpool create tank mirror c0t6d0 c0t7d0   
# zpool list tank
NAME   SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
tank   136G  95.5K   136G     0%  1.00x  ONLINE  -
# zfs list tank
NAME   USED  AVAIL  REFER  MOUNTPOINT
tank    72K   134G    21K  /tank
  • A RAIDZ-2 storage pool created with three 136-GB disks reports SIZE as 408 GB and initial FREE values as 408 GB. This reporting is referred to as the inflated disk space value, which includes redundancy overhead, such as parity information. The initial AVAIL space reported by the zfs list command is 133 GB, due to the pool redundancy overhead.
# zpool create tank raidz2 c0t6d0 c0t7d0 c0t8d0
# zpool list tank
NAME   SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
tank   408G   286K   408G     0%  1.00x  ONLINE  -
# zfs list tank
NAME   USED  AVAIL  REFER  MOUNTPOINT
tank  73.2K   133G  20.9K  /tank

What can I do if ZFS file system panics on every boot?

ZFS is designed to survive arbitrary hardware failures through the use of redundancy (mirroring or RAID-Z). Unfortunately, certain failures in non-replicated configurations can cause ZFS to panic when trying to load the pool. This is a bug, and will be fixed in the near future (along with several other nifty features, such as background scrubbing). In the meantime, if you find yourself in the situation where you cannot boot due to a corrupt pool, do the following:

# mount -o remount /
# rm /etc/zfs/zpool.cache
# reboot
This will remove all knowledge of pools from your system. You will have to re-create your pool and restore from backup.
If a ZFS root file system panics, then you must boot from alternate media, import the root pool, resolve the issue that is causing the failure, export the root pool, and reboot the system. For more information, see the ZFS Troubleshooting Guide.

Does ZFS support hot spares?

Yes, the ZFS hot spares feature is available in the Solaris Express Community Release, build 42, the Solaris Express July 2006 release, and the Solaris 10 11/06 release. For more information about hot spares, see the ZFS Administration Guide.

Can devices be removed from a ZFS pool?

Removal of a top-level vdev, such as an entire RAID-Z group or a disk in an unmirrored configuration, is not currently supported. This feature is planned for a future release and can be tracked with CR 4852783.
You can remove a device from a mirrored ZFS configuration by using the zpool detach command.
You can replace a device with a device of equivalent size in both a mirrored or RAID-Z configuration by using the zpool replace command.

Can I use ZFS as my root file system? What about for zones?

You can install and boot a ZFS root file system starting in the SXCE build 90 release and starting in the Solaris 10 10/08 release. For more information, see ZFS Boot.
ZFS can be used as a zone root path in the Solaris 10 10/08 release, but configurations that can be patched and upgraded are limited. Additional ZFS zone root configurations that can be patched and upgraded are supported starting in the Solaris 10 5/09 release.
For more information, see the ZFS Admin Guide.
In addition, you cannot create a cachefs cache on a ZFS file system.

Can I split a mirrored ZFS configuration?

Yes, you can split a mirrored ZFS configuration for cloning or backup purposes in the SXCE, build 131 release. The best method for cloning and backups is to use ZFS clone and snapshot features. For information about using ZFS clone and snapshot features, see the ZFS Admin Guide. See RFE 6421958 to recursively send snapshots that will improve the replication process across systems.
In addition to ZFS clone and snapshot features, remote replication of ZFS file systems is provided by the Sun StorageTek Availability Suite product. AVS/ZFS demonstrations are available here.
Keep the following cautions in mind if you attempt to split a mirrored ZFS configuration for cloning or backup purposes:
  • Support for splitting a mirrored ZFS configuration integrated with RFE 5097228.
  • You cannot remove a disk from a mirrored ZFS configuration, back up the data on the disk, and then use this data to create a cloned pool.
  • If you want to use a hardware-level backup or snapshot feature instead of the ZFS snapshot feature, then you will need to do the following steps:
    • zpool export pool-name
    • Hardware-level snapshot steps
    • zpool import pool-name
  • Any attempt to split a mirrored ZFS storage pool by removing disks or changing the hardware that is part of a live pool could cause data corruption.

Why has the zpool command changed?

Changes to the zpool command in Nevada, builds 125-129, are as follows:
  1. Device name changes due to integration of 6574286 (removing a slog doesn't work) - This change adds a top-level virtual device name to support device removal operations. The top-level device name is constructed by using the logical name (mirror, raidz2, and so on) and appends a unique numeric number. The zpool status and zpool import commands now display configuration information using this new naming convention. For example, the following configuration contains two top-level virtual devices named mirror-0 and mirror-1.
# zpool status
   pool: export
 state: ONLINE
 scrub: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        export      ONLINE       0     0     0
          mirror-0  ONLINE       0     0     0
            c1t3d0  ONLINE       0     0     0
            c1t4d0  ONLINE       0     0     0
        logs
          mirror-1  ONLINE       0     0     0
            c1t5d0  ONLINE       0     0     0
            c1t6d0  ONLINE       0     0     0
In this release, you could potentially remove the mirrored log device (mirror-1) as follows:
# zpool remove export mirror-1
# zpool status export
  pool: export
 state: ONLINE
 scrub: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        export      ONLINE       0     0     0
          mirror-0  ONLINE       0     0     0
            c1t3d0  ONLINE       0     0     0
            c1t4d0  ONLINE       0     0     0
Currently, only cache, log, and spare devices can be removed from a pool.
2. New dedup ratio property due to integration of 6677093 (zfs should have dedup capability) - The zpool list command includes dedupratio for each pool. You can also display the value of this read-only property by using the zpool get command. For example:
# zpool list
NAME     SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
export   928G  47.5G   881G     5%  1.77x  ONLINE  -
rpool    928G  25.7G   902G     2%  1.40x  ONLINE  -
# zpool get dedup rpool
NAME   PROPERTY    VALUE  SOURCE
rpool  dedupratio  1.40x  - 
3. The zpool list output has changed due to integration of 6897693 (deduplication can only go so far) - In previous releases, thezpool list command reported used and available physical block space and zfs list reports used and available space to the file system. The previous zpool list used and available columns have changed to report allocated and free physical blocks. These changes should help clarify the accounting difference reported by the zpool list and zfs list commands.
# zpool list
NAME     SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
export   928G  47.5G   881G     5%  1.77x  ONLINE  -
rpool    928G  25.7G   902G     2%  1.40x  ONLINE  - 
Any scripts that utilized the old used and available properties of the zpool command should be updated to use the new naming conventions.

ZFS and Other Product Interaction Questions

  1. Is ZFS supported in a clustered environment?
  2. Which third party backup products support ZFS?
  3. Does ZFS work with SAN-attached devices?

Is ZFS supported in a clustered environment?

Solaris Cluster 3.2 supports a local ZFS file system as highly available (HA) in the Solaris 10 11/06 release. This support allows for live failover between systems, with automatic import of pools between systems.
If you use Solaris Cluster 3.2 to configure a local ZFS file system as highly available, review the following caution:
Do not add a configured quorum device to a ZFS storage pool. When a configured quorum device is added to a storage pool, the disk is relabeled and the quorum configuration information is lost. This means the disk no longer provides a quorum vote to the cluster. After a disk is added to a storage pool, you can configure that disk as a quorum device. Or, you can unconfigure the disk, add it to the storage pool, then reconfigure the disk as a quorum device.
Solaris Cluster 3.2 is not supported on the OpenSolaris or Nevada releases. For information about using the open-source Solaris Cluster version, go to the Open High-Availability Cluster community page.
ZFS is not a native cluster, distributed, or parallel file system and cannot provide concurrent access from multiple, different hosts. ZFS works great when shared in a distributed NFS environment.
In the long term, we plan on investigating ZFS as a native cluster file system to allow concurrent access. This work has not yet been scoped.

Which third party backup products support ZFS?

  • EMC Networker 7.3.2. backs up and restores ZFS file systems, including ZFS ACLs.
  • Veritas Netbackup 6.5 backs up and restores ZFS file systems, including ZFS ACLs.
  • IBM Tivoli Storage Manager client software (5.4.1.2) backs up and restores ZFS file systems with both the CLI and the GUI. ZFS ACLs are also preserved.
  • Computer Associates' BrightStor ARCserve product backs up and restores ZFS file systems, but ZFS ACLs are not preserved.

Does ZFS work with SAN-attached devices?

Yes, ZFS works with either direct-attached devices or SAN-attached devices. However, if your storage pool contains no mirror or RAID-Z top-level devices, ZFS can only report checksum errors but cannot correct them. If your storage pool consists of mirror or RAID-Z devices built using storage from SAN-attached devices, ZFS can report and correct checksum errors.
For example, consider a SAN-attached hardware-RAID array, set up to present LUNs to the SAN fabric that are based on its internally mirrored disks. If you use a single LUN from this array to build a single-disk pool, the pool contains no duplicate data that ZFS needs to correct detected errors. In this case, ZFS could not correct an error introduced by the array.
If you use two LUNs from this array to construct a mirrored storage pool, or three LUNs to create a RAID-Z storage pool, ZFS then would have duplicate data available to correct detected errors. In this case, ZFS could typically correct errors introduced by the array.
In all cases where ZFS storage pools lack mirror or RAID-Z top-level virtual devices, pool viability depends entirely on the reliability of the underlying storage devices.
If your ZFS storage pool only contains a single device, whether from SAN-attached or direct-attached storage, you cannot take advantage of features such as RAID-Z, dynamic striping, I/O load balancing, and so on.
ZFS always detects silent data corruption. Some storage arrays can detect checksum errors, but might not be able to detect the following class of errors:
  • Accidental overwrites or phantom writes
  • Mis-directed reads and writes
  • Data path errors
Keep the following points in mind when using ZFS with SAN devices:
  • Overall, ZFS functions as designed with SAN-attached devices, as long as all the drives are only accessed from a single host at any given time. You cannot share SAN disks between pools on the same system or different systems. This limitation includes sharing SAN disks as shared hot spares between pools on different systems.
  • If you expose simpler devices to ZFS, you can better leverage all available features.
    In summary, if you use ZFS with SAN-attached devices, you can take advantage of the self-healing features of ZFS by configuring redundancy in your ZFS storage pools even though redundancy is available at a lower hardware level.
REFERENCES