diff options
author | Brian Behlendorf <[email protected]> | 2011-10-24 16:55:20 -0700 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2011-11-28 15:45:51 -0800 |
commit | 82a37189aac955c81a59a5ecc3400475adb56355 (patch) | |
tree | f67d24ae075a3e97bcc3000c7da2e1abd9c6258f /include/sys | |
parent | e89236fd28cbe8585146b8b5d0ced1f8d4aa8431 (diff) |
Implement SA based xattrs
The current ZFS implementation stores xattrs on disk using a hidden
directory. In this directory a file name represents the xattr name
and the file contexts are the xattr binary data. This approach is
very flexible and allows for arbitrarily large xattrs. However,
it also suffers from a significant performance penalty. Accessing
a single xattr can requires up to three disk seeks.
1) Lookup the dnode object.
2) Lookup the dnodes's xattr directory object.
3) Lookup the xattr object in the directory.
To avoid this performance penalty Linux filesystems such as ext3
and xfs try to store the xattr as part of the inode on disk. When
the xattr is to large to store in the inode then a single external
block is allocated for them. In practice most xattrs are small
and this approach works well.
The addition of System Attributes (SA) to zfs provides us a clean
way to make this optimization. When the dataset property 'xattr=sa'
is set then xattrs will be preferentially stored as System Attributes.
This allows tiny xattrs (~100 bytes) to be stored with the dnode and
up to 64k of xattrs to be stored in the spill block. If additional
xattr space is required, which is unlikely under Linux, they will be
stored using the traditional directory approach.
This optimization results in roughly a 3x performance improvement
when accessing xattrs which brings zfs roughly to parity with ext4
and xfs (see table below). When multiple xattrs are stored per-file
the performance improvements are even greater because all of the
xattrs stored in the spill block will be cached.
However, by default SA based xattrs are disabled in the Linux port
to maximize compatibility with other implementations. If you do
enable SA based xattrs then they will not be visible on platforms
which do not support this feature.
----------------------------------------------------------------------
Time in seconds to get/set one xattr of N bytes on 100,000 files
------+--------------------------------+------------------------------
| setxattr | getxattr
bytes | ext4 xfs zfs-dir zfs-sa | ext4 xfs zfs-dir zfs-sa
------+--------------------------------+------------------------------
1 | 2.33 31.88 21.50 4.57 | 2.35 2.64 6.29 2.43
32 | 2.79 30.68 21.98 4.60 | 2.44 2.59 6.78 2.48
256 | 3.25 31.99 21.36 5.92 | 2.32 2.71 6.22 3.14
1024 | 3.30 32.61 22.83 8.45 | 2.40 2.79 6.24 3.27
4096 | 3.57 317.46 22.52 10.73 | 2.78 28.62 6.90 3.94
16384 | n/a 2342.39 34.30 19.20 | n/a 45.44 145.90 7.55
65536 | n/a 2941.39 128.15 131.32* | n/a 141.92 256.85 262.12*
Legend:
* ext4 - Stock RHEL6.1 ext4 mounted with '-o user_xattr'.
* xfs - Stock RHEL6.1 xfs mounted with default options.
* zfs-dir - Directory based xattrs only.
* zfs-sa - Prefer SAs but spill in to directories as needed, a
trailing * indicates overflow in to directories occured.
NOTE: Ext4 supports 4096 bytes of xattr name/value pairs per file.
NOTE: XFS and ZFS have no limit on xattr name/value pairs per file.
NOTE: Linux limits individual name/value pairs to 65536 bytes.
NOTE: All setattr/getattr's were done after dropping the cache.
NOTE: All tests were run against a single hard drive.
Signed-off-by: Brian Behlendorf <[email protected]>
Issue #443
Diffstat (limited to 'include/sys')
-rw-r--r-- | include/sys/fs/zfs.h | 5 | ||||
-rw-r--r-- | include/sys/sa.h | 2 | ||||
-rw-r--r-- | include/sys/zfs_sa.h | 9 | ||||
-rw-r--r-- | include/sys/zfs_vfsops.h | 1 | ||||
-rw-r--r-- | include/sys/zfs_znode.h | 3 |
5 files changed, 20 insertions, 0 deletions
diff --git a/include/sys/fs/zfs.h b/include/sys/fs/zfs.h index 2ac84f645..2b6abbf1b 100644 --- a/include/sys/fs/zfs.h +++ b/include/sys/fs/zfs.h @@ -309,6 +309,11 @@ typedef enum { ZFS_SYNC_DISABLED = 2 } zfs_sync_type_t; +typedef enum { + ZFS_XATTR_OFF = 0, + ZFS_XATTR_DIR = 1, + ZFS_XATTR_SA = 2 +} zfs_xattr_type_t; /* * On-disk version number. diff --git a/include/sys/sa.h b/include/sys/sa.h index c8b924771..718cbfbd5 100644 --- a/include/sys/sa.h +++ b/include/sys/sa.h @@ -149,6 +149,8 @@ int sa_replace_all_by_template_locked(sa_handle_t *, sa_bulk_attr_t *, boolean_t sa_enabled(objset_t *); void sa_cache_init(void); void sa_cache_fini(void); +void *sa_spill_alloc(int); +void sa_spill_free(void *); int sa_set_sa_object(objset_t *, uint64_t); int sa_hdrsize(void *); void sa_handle_lock(sa_handle_t *); diff --git a/include/sys/zfs_sa.h b/include/sys/zfs_sa.h index 90bb9972b..0bac7808a 100644 --- a/include/sys/zfs_sa.h +++ b/include/sys/zfs_sa.h @@ -73,6 +73,7 @@ typedef enum zpl_attr { ZPL_SYMLINK, ZPL_SCANSTAMP, ZPL_DACL_ACES, + ZPL_DXATTR, ZPL_END } zpl_attr_t; @@ -126,12 +127,20 @@ typedef struct znode_phys { } znode_phys_t; #ifdef _KERNEL + +#define DXATTR_MAX_ENTRY_SIZE (32768) +#define DXATTR_MAX_SA_SIZE (SPA_MAXBLOCKSIZE >> 1) + int zfs_sa_readlink(struct znode *, uio_t *); void zfs_sa_symlink(struct znode *, char *link, int len, dmu_tx_t *); void zfs_sa_get_scanstamp(struct znode *, xvattr_t *); void zfs_sa_set_scanstamp(struct znode *, xvattr_t *, dmu_tx_t *); +int zfs_sa_get_xattr(struct znode *); +int zfs_sa_set_xattr(struct znode *); void zfs_sa_upgrade(struct sa_handle *, dmu_tx_t *); void zfs_sa_upgrade_txholds(dmu_tx_t *, struct znode *); +void zfs_sa_init(void); +void zfs_sa_fini(void); #endif #ifdef __cplusplus diff --git a/include/sys/zfs_vfsops.h b/include/sys/zfs_vfsops.h index fc8be58bc..6d4d713ce 100644 --- a/include/sys/zfs_vfsops.h +++ b/include/sys/zfs_vfsops.h @@ -76,6 +76,7 @@ typedef struct zfs_sb { boolean_t z_use_fuids; /* version allows fuids */ boolean_t z_replay; /* set during ZIL replay */ boolean_t z_use_sa; /* version allow system attributes */ + boolean_t z_xattr_sa; /* allow xattrs to be stores as SA */ uint64_t z_version; /* ZPL version */ uint64_t z_shares_dir; /* hidden shares dir */ kmutex_t z_lock; diff --git a/include/sys/zfs_znode.h b/include/sys/zfs_znode.h index 6a0c6a4df..6903ad4cc 100644 --- a/include/sys/zfs_znode.h +++ b/include/sys/zfs_znode.h @@ -105,6 +105,7 @@ extern "C" { #define SA_ZPL_FLAGS(z) z->z_attr_table[ZPL_FLAGS] #define SA_ZPL_SIZE(z) z->z_attr_table[ZPL_SIZE] #define SA_ZPL_ZNODE_ACL(z) z->z_attr_table[ZPL_ZNODE_ACL] +#define SA_ZPL_DXATTR(z) z->z_attr_table[ZPL_DXATTR] #define SA_ZPL_PAD(z) z->z_attr_table[ZPL_PAD] /* @@ -206,6 +207,8 @@ typedef struct znode { uint32_t z_sync_cnt; /* synchronous open count */ kmutex_t z_acl_lock; /* acl data lock */ zfs_acl_t *z_acl_cached; /* cached acl */ + krwlock_t z_xattr_lock; /* xattr data lock */ + nvlist_t *z_xattr_cached;/* cached xattrs */ list_node_t z_link_node; /* all znodes in fs link */ sa_handle_t *z_sa_hdl; /* handle to sa data */ boolean_t z_is_sa; /* are we native sa? */ |