2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
2022-07-12 00:16:13 +03:00
|
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
2008-11-20 23:01:55 +03:00
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
2017-02-03 01:13:41 +03:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
2010-05-29 00:45:14 +04:00
|
|
|
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
2019-06-12 23:13:09 +03:00
|
|
|
* Copyright (c) 2011, 2018 by Delphix. All rights reserved.
|
2015-04-02 06:44:32 +03:00
|
|
|
* Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
|
2017-02-03 01:13:41 +03:00
|
|
|
* Copyright 2017 Nexenta Systems, Inc.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
#include <sys/zio.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
#include <sys/spa.h>
|
|
|
|
#include <sys/dmu.h>
|
|
|
|
#include <sys/zfs_context.h>
|
|
|
|
#include <sys/zap.h>
|
|
|
|
#include <sys/zap_impl.h>
|
|
|
|
#include <sys/zap_leaf.h>
|
2022-10-20 21:57:15 +03:00
|
|
|
#include <sys/btree.h>
|
2010-05-29 00:45:14 +04:00
|
|
|
#include <sys/arc.h>
|
2014-11-03 23:15:08 +03:00
|
|
|
#include <sys/dmu_objset.h>
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
#include <sys/sunddi.h>
|
|
|
|
#endif
|
|
|
|
|
2023-01-11 00:41:54 +03:00
|
|
|
int zap_micro_max_size = MZAP_MAX_BLKSZ;
|
|
|
|
|
2016-07-21 01:39:55 +03:00
|
|
|
static int mzap_upgrade(zap_t **zapp,
|
2022-04-19 21:49:30 +03:00
|
|
|
const void *tag, dmu_tx_t *tx, zap_flags_t flags);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
uint64_t
|
|
|
|
zap_getflags(zap_t *zap)
|
|
|
|
{
|
|
|
|
if (zap->zap_ismicro)
|
|
|
|
return (0);
|
2015-04-01 18:14:34 +03:00
|
|
|
return (zap_f_phys(zap)->zap_flags);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
int
|
|
|
|
zap_hashbits(zap_t *zap)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2010-05-29 00:45:14 +04:00
|
|
|
if (zap_getflags(zap) & ZAP_FLAG_HASH64)
|
|
|
|
return (48);
|
|
|
|
else
|
|
|
|
return (28);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
uint32_t
|
|
|
|
zap_maxcd(zap_t *zap)
|
|
|
|
{
|
|
|
|
if (zap_getflags(zap) & ZAP_FLAG_HASH64)
|
|
|
|
return ((1<<16)-1);
|
|
|
|
else
|
|
|
|
return (-1U);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
static uint64_t
|
|
|
|
zap_hash(zap_name_t *zn)
|
|
|
|
{
|
|
|
|
zap_t *zap = zn->zn_zap;
|
|
|
|
uint64_t h = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
if (zap_getflags(zap) & ZAP_FLAG_PRE_HASHED_KEY) {
|
|
|
|
ASSERT(zap_getflags(zap) & ZAP_FLAG_UINT64_KEY);
|
|
|
|
h = *(uint64_t *)zn->zn_key_orig;
|
|
|
|
} else {
|
|
|
|
h = zap->zap_salt;
|
|
|
|
ASSERT(h != 0);
|
|
|
|
ASSERT(zfs_crc64_table[128] == ZFS_CRC64_POLY);
|
|
|
|
|
|
|
|
if (zap_getflags(zap) & ZAP_FLAG_UINT64_KEY) {
|
|
|
|
const uint64_t *wp = zn->zn_key_norm;
|
|
|
|
|
|
|
|
ASSERT(zn->zn_key_intlen == 8);
|
2018-05-30 21:16:54 +03:00
|
|
|
for (int i = 0; i < zn->zn_key_norm_numints;
|
|
|
|
wp++, i++) {
|
2010-05-29 00:45:14 +04:00
|
|
|
uint64_t word = *wp;
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
for (int j = 0; j < 8; j++) {
|
2010-05-29 00:45:14 +04:00
|
|
|
h = (h >> 8) ^
|
|
|
|
zfs_crc64_table[(h ^ word) & 0xFF];
|
|
|
|
word >>= NBBY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const uint8_t *cp = zn->zn_key_norm;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We previously stored the terminating null on
|
|
|
|
* disk, but didn't hash it, so we need to
|
|
|
|
* continue to not hash it. (The
|
|
|
|
* zn_key_*_numints includes the terminating
|
|
|
|
* null for non-binary keys.)
|
|
|
|
*/
|
2018-05-30 21:16:54 +03:00
|
|
|
int len = zn->zn_key_norm_numints - 1;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
ASSERT(zn->zn_key_intlen == 1);
|
2018-05-30 21:16:54 +03:00
|
|
|
for (int i = 0; i < len; cp++, i++) {
|
2010-05-29 00:45:14 +04:00
|
|
|
h = (h >> 8) ^
|
|
|
|
zfs_crc64_table[(h ^ *cp) & 0xFF];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
2010-05-29 00:45:14 +04:00
|
|
|
* Don't use all 64 bits, since we need some in the cookie for
|
|
|
|
* the collision differentiator. We MUST use the high bits,
|
|
|
|
* since those are the ones that we first pay attention to when
|
2017-01-03 20:31:18 +03:00
|
|
|
* choosing the bucket.
|
2008-11-20 23:01:55 +03:00
|
|
|
*/
|
2010-05-29 00:45:14 +04:00
|
|
|
h &= ~((1ULL << (64 - zap_hashbits(zap))) - 1);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
return (h);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-02-03 01:13:41 +03:00
|
|
|
zap_normalize(zap_t *zap, const char *name, char *namenorm, int normflags)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2010-05-29 00:45:14 +04:00
|
|
|
ASSERT(!(zap_getflags(zap) & ZAP_FLAG_UINT64_KEY));
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
size_t inlen = strlen(name) + 1;
|
|
|
|
size_t outlen = ZAP_MAXNAMELEN;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int err = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
(void) u8_textprep_str((char *)name, &inlen, namenorm, &outlen,
|
2017-02-03 01:13:41 +03:00
|
|
|
normflags | U8_TEXTPREP_IGNORE_NULL | U8_TEXTPREP_IGNORE_INVALID,
|
|
|
|
U8_UNICODE_LATEST, &err);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean_t
|
|
|
|
zap_match(zap_name_t *zn, const char *matchname)
|
|
|
|
{
|
2010-05-29 00:45:14 +04:00
|
|
|
ASSERT(!(zap_getflags(zn->zn_zap) & ZAP_FLAG_UINT64_KEY));
|
|
|
|
|
2017-02-03 01:13:41 +03:00
|
|
|
if (zn->zn_matchtype & MT_NORMALIZE) {
|
2008-11-20 23:01:55 +03:00
|
|
|
char norm[ZAP_MAXNAMELEN];
|
|
|
|
|
2017-02-03 01:13:41 +03:00
|
|
|
if (zap_normalize(zn->zn_zap, matchname, norm,
|
|
|
|
zn->zn_normflags) != 0)
|
2008-11-20 23:01:55 +03:00
|
|
|
return (B_FALSE);
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
return (strcmp(zn->zn_key_norm, norm) == 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
2010-05-29 00:45:14 +04:00
|
|
|
return (strcmp(zn->zn_key_orig, matchname) == 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
static zap_name_t *
|
|
|
|
zap_name_alloc(zap_t *zap)
|
|
|
|
{
|
|
|
|
zap_name_t *zn = kmem_alloc(sizeof (zap_name_t), KM_SLEEP);
|
|
|
|
zn->zn_zap = zap;
|
|
|
|
return (zn);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
void
|
|
|
|
zap_name_free(zap_name_t *zn)
|
|
|
|
{
|
|
|
|
kmem_free(zn, sizeof (zap_name_t));
|
|
|
|
}
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
static int
|
|
|
|
zap_name_init_str(zap_name_t *zn, const char *key, matchtype_t mt)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2022-10-20 21:57:15 +03:00
|
|
|
zap_t *zap = zn->zn_zap;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
zn->zn_key_intlen = sizeof (*key);
|
|
|
|
zn->zn_key_orig = key;
|
|
|
|
zn->zn_key_orig_numints = strlen(zn->zn_key_orig) + 1;
|
2008-11-20 23:01:55 +03:00
|
|
|
zn->zn_matchtype = mt;
|
2017-02-03 01:13:41 +03:00
|
|
|
zn->zn_normflags = zap->zap_normflags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're dealing with a case sensitive lookup on a mixed or
|
|
|
|
* insensitive fs, remove U8_TEXTPREP_TOUPPER or the lookup
|
|
|
|
* will fold case to all caps overriding the lookup request.
|
|
|
|
*/
|
|
|
|
if (mt & MT_MATCH_CASE)
|
|
|
|
zn->zn_normflags &= ~U8_TEXTPREP_TOUPPER;
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
if (zap->zap_normflags) {
|
2017-02-03 01:13:41 +03:00
|
|
|
/*
|
|
|
|
* We *must* use zap_normflags because this normalization is
|
|
|
|
* what the hash is computed from.
|
|
|
|
*/
|
|
|
|
if (zap_normalize(zap, key, zn->zn_normbuf,
|
2022-10-20 21:57:15 +03:00
|
|
|
zap->zap_normflags) != 0)
|
|
|
|
return (SET_ERROR(ENOTSUP));
|
2010-05-29 00:45:14 +04:00
|
|
|
zn->zn_key_norm = zn->zn_normbuf;
|
|
|
|
zn->zn_key_norm_numints = strlen(zn->zn_key_norm) + 1;
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
2022-10-20 21:57:15 +03:00
|
|
|
if (mt != 0)
|
|
|
|
return (SET_ERROR(ENOTSUP));
|
2010-05-29 00:45:14 +04:00
|
|
|
zn->zn_key_norm = zn->zn_key_orig;
|
|
|
|
zn->zn_key_norm_numints = zn->zn_key_orig_numints;
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
zn->zn_hash = zap_hash(zn);
|
2017-02-03 01:13:41 +03:00
|
|
|
|
|
|
|
if (zap->zap_normflags != zn->zn_normflags) {
|
|
|
|
/*
|
|
|
|
* We *must* use zn_normflags because this normalization is
|
|
|
|
* what the matching is based on. (Not the hash!)
|
|
|
|
*/
|
|
|
|
if (zap_normalize(zap, key, zn->zn_normbuf,
|
2022-10-20 21:57:15 +03:00
|
|
|
zn->zn_normflags) != 0)
|
|
|
|
return (SET_ERROR(ENOTSUP));
|
2017-02-03 01:13:41 +03:00
|
|
|
zn->zn_key_norm_numints = strlen(zn->zn_key_norm) + 1;
|
|
|
|
}
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
zap_name_t *
|
|
|
|
zap_name_alloc_str(zap_t *zap, const char *key, matchtype_t mt)
|
|
|
|
{
|
|
|
|
zap_name_t *zn = zap_name_alloc(zap);
|
|
|
|
if (zap_name_init_str(zn, key, mt) != 0) {
|
|
|
|
zap_name_free(zn);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2010-05-29 00:45:14 +04:00
|
|
|
return (zn);
|
|
|
|
}
|
|
|
|
|
2020-06-15 21:30:37 +03:00
|
|
|
static zap_name_t *
|
2010-05-29 00:45:14 +04:00
|
|
|
zap_name_alloc_uint64(zap_t *zap, const uint64_t *key, int numints)
|
|
|
|
{
|
2014-11-21 03:09:39 +03:00
|
|
|
zap_name_t *zn = kmem_alloc(sizeof (zap_name_t), KM_SLEEP);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
ASSERT(zap->zap_normflags == 0);
|
|
|
|
zn->zn_zap = zap;
|
|
|
|
zn->zn_key_intlen = sizeof (*key);
|
|
|
|
zn->zn_key_orig = zn->zn_key_norm = key;
|
|
|
|
zn->zn_key_orig_numints = zn->zn_key_norm_numints = numints;
|
2017-02-03 01:13:41 +03:00
|
|
|
zn->zn_matchtype = 0;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
zn->zn_hash = zap_hash(zn);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (zn);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mzap_byteswap(mzap_phys_t *buf, size_t size)
|
|
|
|
{
|
|
|
|
buf->mz_block_type = BSWAP_64(buf->mz_block_type);
|
|
|
|
buf->mz_salt = BSWAP_64(buf->mz_salt);
|
|
|
|
buf->mz_normflags = BSWAP_64(buf->mz_normflags);
|
2018-05-30 21:16:54 +03:00
|
|
|
int max = (size / MZAP_ENT_LEN) - 1;
|
|
|
|
for (int i = 0; i < max; i++) {
|
2008-11-20 23:01:55 +03:00
|
|
|
buf->mz_chunk[i].mze_value =
|
|
|
|
BSWAP_64(buf->mz_chunk[i].mze_value);
|
|
|
|
buf->mz_chunk[i].mze_cd =
|
|
|
|
BSWAP_32(buf->mz_chunk[i].mze_cd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zap_byteswap(void *buf, size_t size)
|
|
|
|
{
|
2018-05-30 21:16:54 +03:00
|
|
|
uint64_t block_type = *(uint64_t *)buf;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (block_type == ZBT_MICRO || block_type == BSWAP_64(ZBT_MICRO)) {
|
|
|
|
/* ASSERT(magic == ZAP_LEAF_MAGIC); */
|
|
|
|
mzap_byteswap(buf, size);
|
|
|
|
} else {
|
|
|
|
fzap_byteswap(buf, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-26 20:03:12 +03:00
|
|
|
__attribute__((always_inline)) inline
|
2008-11-20 23:01:55 +03:00
|
|
|
static int
|
|
|
|
mze_compare(const void *arg1, const void *arg2)
|
|
|
|
{
|
|
|
|
const mzap_ent_t *mze1 = arg1;
|
|
|
|
const mzap_ent_t *mze2 = arg2;
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
return (TREE_CMP((uint64_t)(mze1->mze_hash) << 32 | mze1->mze_cd,
|
|
|
|
(uint64_t)(mze2->mze_hash) << 32 | mze2->mze_cd));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2023-05-26 20:03:12 +03:00
|
|
|
ZFS_BTREE_FIND_IN_BUF_FUNC(mze_find_in_buf, mzap_ent_t,
|
|
|
|
mze_compare)
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
static void
|
2022-10-20 21:57:15 +03:00
|
|
|
mze_insert(zap_t *zap, uint16_t chunkid, uint64_t hash)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2022-10-20 21:57:15 +03:00
|
|
|
mzap_ent_t mze;
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
ASSERT(zap->zap_ismicro);
|
|
|
|
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
mze.mze_chunkid = chunkid;
|
|
|
|
ASSERT0(hash & 0xffffffff);
|
|
|
|
mze.mze_hash = hash >> 32;
|
|
|
|
ASSERT3U(MZE_PHYS(zap, &mze)->mze_cd, <=, 0xffff);
|
|
|
|
mze.mze_cd = (uint16_t)MZE_PHYS(zap, &mze)->mze_cd;
|
|
|
|
ASSERT(MZE_PHYS(zap, &mze)->mze_name[0] != 0);
|
|
|
|
zfs_btree_add(&zap->zap_m.zap_tree, &mze);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static mzap_ent_t *
|
2022-10-20 21:57:15 +03:00
|
|
|
mze_find(zap_name_t *zn, zfs_btree_index_t *idx)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
mzap_ent_t mze_tofind;
|
|
|
|
mzap_ent_t *mze;
|
2022-10-20 21:57:15 +03:00
|
|
|
zfs_btree_t *tree = &zn->zn_zap->zap_m.zap_tree;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
ASSERT(zn->zn_zap->zap_ismicro);
|
|
|
|
ASSERT(RW_LOCK_HELD(&zn->zn_zap->zap_rwlock));
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
ASSERT0(zn->zn_hash & 0xffffffff);
|
|
|
|
mze_tofind.mze_hash = zn->zn_hash >> 32;
|
2010-05-29 00:45:14 +04:00
|
|
|
mze_tofind.mze_cd = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
mze = zfs_btree_find(tree, &mze_tofind, idx);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (mze == NULL)
|
2022-10-20 21:57:15 +03:00
|
|
|
mze = zfs_btree_next(tree, idx, idx);
|
|
|
|
for (; mze && mze->mze_hash == mze_tofind.mze_hash;
|
|
|
|
mze = zfs_btree_next(tree, idx, idx)) {
|
2010-05-29 00:45:14 +04:00
|
|
|
ASSERT3U(mze->mze_cd, ==, MZE_PHYS(zn->zn_zap, mze)->mze_cd);
|
|
|
|
if (zap_match(zn, MZE_PHYS(zn->zn_zap, mze)->mze_name))
|
2008-11-20 23:01:55 +03:00
|
|
|
return (mze);
|
|
|
|
}
|
2017-02-03 01:13:41 +03:00
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
mze_find_unused_cd(zap_t *zap, uint64_t hash)
|
|
|
|
{
|
|
|
|
mzap_ent_t mze_tofind;
|
2022-10-20 21:57:15 +03:00
|
|
|
zfs_btree_index_t idx;
|
|
|
|
zfs_btree_t *tree = &zap->zap_m.zap_tree;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
ASSERT(zap->zap_ismicro);
|
|
|
|
ASSERT(RW_LOCK_HELD(&zap->zap_rwlock));
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
ASSERT0(hash & 0xffffffff);
|
|
|
|
hash >>= 32;
|
2008-11-20 23:01:55 +03:00
|
|
|
mze_tofind.mze_hash = hash;
|
2010-05-29 00:45:14 +04:00
|
|
|
mze_tofind.mze_cd = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
uint32_t cd = 0;
|
2022-10-20 21:57:15 +03:00
|
|
|
for (mzap_ent_t *mze = zfs_btree_find(tree, &mze_tofind, &idx);
|
|
|
|
mze && mze->mze_hash == hash;
|
|
|
|
mze = zfs_btree_next(tree, &idx, &idx)) {
|
2010-05-29 00:45:14 +04:00
|
|
|
if (mze->mze_cd != cd)
|
2008-11-20 23:01:55 +03:00
|
|
|
break;
|
|
|
|
cd++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (cd);
|
|
|
|
}
|
|
|
|
|
Fix ENOSPC in "Handle zap_add() failures in ..."
Commit cc63068 caused ENOSPC error when copy a large amount of files
between two directories. The reason is that the patch limits zap leaf
expansion to 2 retries, and return ENOSPC when failed.
The intent for limiting retries is to prevent pointlessly growing table
to max size when adding a block full of entries with same name in
different case in mixed mode. However, it turns out we cannot use any
limit on the retry. When we copy files from one directory in readdir
order, we are copying in hash order, one leaf block at a time. Which
means that if the leaf block in source directory has expanded 6 times,
and you copy those entries in that block, by the time you need to expand
the leaf in destination directory, you need to expand it 6 times in one
go. So any limit on the retry will result in error where it shouldn't.
Note that while we do use different salt for different directories, it
seems that the salt/hash function doesn't provide enough randomization
to the hash distance to prevent this from happening.
Since cc63068 has already been reverted. This patch adds it back and
removes the retry limit.
Also, as it turn out, failing on zap_add() has a serious side effect for
mzap_upgrade(). When upgrading from micro zap to fat zap, it will
call zap_add() to transfer entries one at a time. If it hit any error
halfway through, the remaining entries will be lost, causing those files
to become orphan. This patch add a VERIFY to catch it.
Reviewed-by: Sanjeev Bagewadi <sanjeev.bagewadi@gmail.com>
Reviewed-by: Richard Yao <ryao@gentoo.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Albert Lee <trisk@forkgnu.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Closes #7401
Closes #7421
2018-04-19 00:19:50 +03:00
|
|
|
/*
|
|
|
|
* Each mzap entry requires at max : 4 chunks
|
|
|
|
* 3 chunks for names + 1 chunk for value.
|
|
|
|
*/
|
|
|
|
#define MZAP_ENT_CHUNKS (1 + ZAP_LEAF_ARRAY_NCHUNKS(MZAP_NAME_LEN) + \
|
|
|
|
ZAP_LEAF_ARRAY_NCHUNKS(sizeof (uint64_t)))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the current entry keeps the colliding entries under the fatzap leaf
|
|
|
|
* size.
|
|
|
|
*/
|
|
|
|
static boolean_t
|
|
|
|
mze_canfit_fzap_leaf(zap_name_t *zn, uint64_t hash)
|
|
|
|
{
|
|
|
|
zap_t *zap = zn->zn_zap;
|
|
|
|
mzap_ent_t mze_tofind;
|
2022-10-20 21:57:15 +03:00
|
|
|
zfs_btree_index_t idx;
|
|
|
|
zfs_btree_t *tree = &zap->zap_m.zap_tree;
|
Fix ENOSPC in "Handle zap_add() failures in ..."
Commit cc63068 caused ENOSPC error when copy a large amount of files
between two directories. The reason is that the patch limits zap leaf
expansion to 2 retries, and return ENOSPC when failed.
The intent for limiting retries is to prevent pointlessly growing table
to max size when adding a block full of entries with same name in
different case in mixed mode. However, it turns out we cannot use any
limit on the retry. When we copy files from one directory in readdir
order, we are copying in hash order, one leaf block at a time. Which
means that if the leaf block in source directory has expanded 6 times,
and you copy those entries in that block, by the time you need to expand
the leaf in destination directory, you need to expand it 6 times in one
go. So any limit on the retry will result in error where it shouldn't.
Note that while we do use different salt for different directories, it
seems that the salt/hash function doesn't provide enough randomization
to the hash distance to prevent this from happening.
Since cc63068 has already been reverted. This patch adds it back and
removes the retry limit.
Also, as it turn out, failing on zap_add() has a serious side effect for
mzap_upgrade(). When upgrading from micro zap to fat zap, it will
call zap_add() to transfer entries one at a time. If it hit any error
halfway through, the remaining entries will be lost, causing those files
to become orphan. This patch add a VERIFY to catch it.
Reviewed-by: Sanjeev Bagewadi <sanjeev.bagewadi@gmail.com>
Reviewed-by: Richard Yao <ryao@gentoo.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Albert Lee <trisk@forkgnu.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Closes #7401
Closes #7421
2018-04-19 00:19:50 +03:00
|
|
|
uint32_t mzap_ents = 0;
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
ASSERT0(hash & 0xffffffff);
|
|
|
|
hash >>= 32;
|
Fix ENOSPC in "Handle zap_add() failures in ..."
Commit cc63068 caused ENOSPC error when copy a large amount of files
between two directories. The reason is that the patch limits zap leaf
expansion to 2 retries, and return ENOSPC when failed.
The intent for limiting retries is to prevent pointlessly growing table
to max size when adding a block full of entries with same name in
different case in mixed mode. However, it turns out we cannot use any
limit on the retry. When we copy files from one directory in readdir
order, we are copying in hash order, one leaf block at a time. Which
means that if the leaf block in source directory has expanded 6 times,
and you copy those entries in that block, by the time you need to expand
the leaf in destination directory, you need to expand it 6 times in one
go. So any limit on the retry will result in error where it shouldn't.
Note that while we do use different salt for different directories, it
seems that the salt/hash function doesn't provide enough randomization
to the hash distance to prevent this from happening.
Since cc63068 has already been reverted. This patch adds it back and
removes the retry limit.
Also, as it turn out, failing on zap_add() has a serious side effect for
mzap_upgrade(). When upgrading from micro zap to fat zap, it will
call zap_add() to transfer entries one at a time. If it hit any error
halfway through, the remaining entries will be lost, causing those files
to become orphan. This patch add a VERIFY to catch it.
Reviewed-by: Sanjeev Bagewadi <sanjeev.bagewadi@gmail.com>
Reviewed-by: Richard Yao <ryao@gentoo.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Albert Lee <trisk@forkgnu.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Closes #7401
Closes #7421
2018-04-19 00:19:50 +03:00
|
|
|
mze_tofind.mze_hash = hash;
|
|
|
|
mze_tofind.mze_cd = 0;
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
for (mzap_ent_t *mze = zfs_btree_find(tree, &mze_tofind, &idx);
|
|
|
|
mze && mze->mze_hash == hash;
|
|
|
|
mze = zfs_btree_next(tree, &idx, &idx)) {
|
Fix ENOSPC in "Handle zap_add() failures in ..."
Commit cc63068 caused ENOSPC error when copy a large amount of files
between two directories. The reason is that the patch limits zap leaf
expansion to 2 retries, and return ENOSPC when failed.
The intent for limiting retries is to prevent pointlessly growing table
to max size when adding a block full of entries with same name in
different case in mixed mode. However, it turns out we cannot use any
limit on the retry. When we copy files from one directory in readdir
order, we are copying in hash order, one leaf block at a time. Which
means that if the leaf block in source directory has expanded 6 times,
and you copy those entries in that block, by the time you need to expand
the leaf in destination directory, you need to expand it 6 times in one
go. So any limit on the retry will result in error where it shouldn't.
Note that while we do use different salt for different directories, it
seems that the salt/hash function doesn't provide enough randomization
to the hash distance to prevent this from happening.
Since cc63068 has already been reverted. This patch adds it back and
removes the retry limit.
Also, as it turn out, failing on zap_add() has a serious side effect for
mzap_upgrade(). When upgrading from micro zap to fat zap, it will
call zap_add() to transfer entries one at a time. If it hit any error
halfway through, the remaining entries will be lost, causing those files
to become orphan. This patch add a VERIFY to catch it.
Reviewed-by: Sanjeev Bagewadi <sanjeev.bagewadi@gmail.com>
Reviewed-by: Richard Yao <ryao@gentoo.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Albert Lee <trisk@forkgnu.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Closes #7401
Closes #7421
2018-04-19 00:19:50 +03:00
|
|
|
mzap_ents++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Include the new entry being added */
|
|
|
|
mzap_ents++;
|
|
|
|
|
|
|
|
return (ZAP_LEAF_NUMCHUNKS_DEF > (mzap_ents * MZAP_ENT_CHUNKS));
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
static void
|
|
|
|
mze_destroy(zap_t *zap)
|
|
|
|
{
|
2022-10-20 21:57:15 +03:00
|
|
|
zfs_btree_clear(&zap->zap_m.zap_tree);
|
|
|
|
zfs_btree_destroy(&zap->zap_m.zap_tree);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static zap_t *
|
2024-03-26 00:58:50 +03:00
|
|
|
mzap_open(dmu_buf_t *db)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
zap_t *winner;
|
2016-03-25 22:21:56 +03:00
|
|
|
uint64_t *zap_hdr = (uint64_t *)db->db_data;
|
|
|
|
uint64_t zap_block_type = zap_hdr[0];
|
|
|
|
uint64_t zap_magic = zap_hdr[1];
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
ASSERT3U(MZAP_ENT_LEN, ==, sizeof (mzap_ent_phys_t));
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
zap_t *zap = kmem_zalloc(sizeof (zap_t), KM_SLEEP);
|
2010-08-26 21:30:13 +04:00
|
|
|
rw_init(&zap->zap_rwlock, NULL, RW_DEFAULT, NULL);
|
2008-11-20 23:01:55 +03:00
|
|
|
rw_enter(&zap->zap_rwlock, RW_WRITER);
|
2024-03-26 00:58:50 +03:00
|
|
|
zap->zap_objset = dmu_buf_get_objset(db);
|
|
|
|
zap->zap_object = db->db_object;
|
2008-11-20 23:01:55 +03:00
|
|
|
zap->zap_dbuf = db;
|
|
|
|
|
2016-03-25 22:21:56 +03:00
|
|
|
if (zap_block_type != ZBT_MICRO) {
|
2016-11-26 23:30:44 +03:00
|
|
|
mutex_init(&zap->zap_f.zap_num_entries_mtx, 0, MUTEX_DEFAULT,
|
|
|
|
0);
|
2014-04-16 07:40:22 +04:00
|
|
|
zap->zap_f.zap_block_shift = highbit64(db->db_size) - 1;
|
2016-03-25 22:21:56 +03:00
|
|
|
if (zap_block_type != ZBT_HEADER || zap_magic != ZAP_MAGIC) {
|
|
|
|
winner = NULL; /* No actual winner here... */
|
|
|
|
goto handle_winner;
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
|
|
|
zap->zap_ismicro = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that zap_ismicro is set before we let others see
|
|
|
|
* it, because zap_lockdir() checks zap_ismicro without the lock
|
|
|
|
* held.
|
|
|
|
*/
|
2017-01-27 01:43:28 +03:00
|
|
|
dmu_buf_init_user(&zap->zap_dbu, zap_evict_sync, NULL, &zap->zap_dbuf);
|
2015-04-02 06:44:32 +03:00
|
|
|
winner = dmu_buf_set_user(db, &zap->zap_dbu);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2016-03-25 22:21:56 +03:00
|
|
|
if (winner != NULL)
|
|
|
|
goto handle_winner;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (zap->zap_ismicro) {
|
2015-04-01 18:14:34 +03:00
|
|
|
zap->zap_salt = zap_m_phys(zap)->mz_salt;
|
|
|
|
zap->zap_normflags = zap_m_phys(zap)->mz_normflags;
|
2008-11-20 23:01:55 +03:00
|
|
|
zap->zap_m.zap_num_chunks = db->db_size / MZAP_ENT_LEN - 1;
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
/*
|
|
|
|
* Reduce B-tree leaf from 4KB to 512 bytes to reduce memmove()
|
|
|
|
* overhead on massive inserts below. It still allows to store
|
|
|
|
* 62 entries before we have to add 2KB B-tree core node.
|
|
|
|
*/
|
|
|
|
zfs_btree_create_custom(&zap->zap_m.zap_tree, mze_compare,
|
2023-05-26 20:03:12 +03:00
|
|
|
mze_find_in_buf, sizeof (mzap_ent_t), 512);
|
2022-10-20 21:57:15 +03:00
|
|
|
|
|
|
|
zap_name_t *zn = zap_name_alloc(zap);
|
|
|
|
for (uint16_t i = 0; i < zap->zap_m.zap_num_chunks; i++) {
|
2008-11-20 23:01:55 +03:00
|
|
|
mzap_ent_phys_t *mze =
|
2015-04-01 18:14:34 +03:00
|
|
|
&zap_m_phys(zap)->mz_chunk[i];
|
2008-11-20 23:01:55 +03:00
|
|
|
if (mze->mze_name[0]) {
|
|
|
|
zap->zap_m.zap_num_entries++;
|
2022-10-20 21:57:15 +03:00
|
|
|
zap_name_init_str(zn, mze->mze_name, 0);
|
2010-05-29 00:45:14 +04:00
|
|
|
mze_insert(zap, i, zn->zn_hash);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
2022-10-20 21:57:15 +03:00
|
|
|
zap_name_free(zn);
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
2015-04-01 18:14:34 +03:00
|
|
|
zap->zap_salt = zap_f_phys(zap)->zap_salt;
|
|
|
|
zap->zap_normflags = zap_f_phys(zap)->zap_normflags;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
ASSERT3U(sizeof (struct zap_leaf_header), ==,
|
|
|
|
2*ZAP_LEAF_CHUNKSIZE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The embedded pointer table should not overlap the
|
|
|
|
* other members.
|
|
|
|
*/
|
|
|
|
ASSERT3P(&ZAP_EMBEDDED_PTRTBL_ENT(zap, 0), >,
|
2015-04-01 18:14:34 +03:00
|
|
|
&zap_f_phys(zap)->zap_salt);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The embedded pointer table should end at the end of
|
|
|
|
* the block
|
|
|
|
*/
|
|
|
|
ASSERT3U((uintptr_t)&ZAP_EMBEDDED_PTRTBL_ENT(zap,
|
|
|
|
1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)) -
|
2015-04-01 18:14:34 +03:00
|
|
|
(uintptr_t)zap_f_phys(zap), ==,
|
2008-11-20 23:01:55 +03:00
|
|
|
zap->zap_dbuf->db_size);
|
|
|
|
}
|
|
|
|
rw_exit(&zap->zap_rwlock);
|
|
|
|
return (zap);
|
2016-03-25 22:21:56 +03:00
|
|
|
|
|
|
|
handle_winner:
|
|
|
|
rw_exit(&zap->zap_rwlock);
|
|
|
|
rw_destroy(&zap->zap_rwlock);
|
|
|
|
if (!zap->zap_ismicro)
|
|
|
|
mutex_destroy(&zap->zap_f.zap_num_entries_mtx);
|
|
|
|
kmem_free(zap, sizeof (zap_t));
|
|
|
|
return (winner);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2018-05-30 21:27:40 +03:00
|
|
|
/*
|
|
|
|
* This routine "consumes" the caller's hold on the dbuf, which must
|
|
|
|
* have the specified tag.
|
|
|
|
*/
|
2016-07-21 01:39:55 +03:00
|
|
|
static int
|
2024-03-26 00:58:50 +03:00
|
|
|
zap_lockdir_impl(dnode_t *dn, dmu_buf_t *db, const void *tag, dmu_tx_t *tx,
|
2008-11-20 23:01:55 +03:00
|
|
|
krw_t lti, boolean_t fatreader, boolean_t adding, zap_t **zapp)
|
|
|
|
{
|
2018-05-30 21:16:54 +03:00
|
|
|
ASSERT0(db->db_offset);
|
2016-07-21 01:39:55 +03:00
|
|
|
objset_t *os = dmu_buf_get_objset(db);
|
|
|
|
uint64_t obj = db->db_object;
|
2018-05-30 21:16:54 +03:00
|
|
|
dmu_object_info_t doi;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2016-07-21 01:39:55 +03:00
|
|
|
*zapp = NULL;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2024-03-26 00:58:50 +03:00
|
|
|
dmu_object_info_from_dnode(dn, &doi);
|
2014-08-29 23:24:26 +04:00
|
|
|
if (DMU_OT_BYTESWAP(doi.doi_type) != DMU_BSWAP_ZAP)
|
|
|
|
return (SET_ERROR(EINVAL));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
zap_t *zap = dmu_buf_get_user(db);
|
2016-03-25 22:21:56 +03:00
|
|
|
if (zap == NULL) {
|
2024-03-26 00:58:50 +03:00
|
|
|
zap = mzap_open(db);
|
2016-03-25 22:21:56 +03:00
|
|
|
if (zap == NULL) {
|
|
|
|
/*
|
|
|
|
* mzap_open() didn't like what it saw on-disk.
|
|
|
|
* Check for corruption!
|
|
|
|
*/
|
|
|
|
return (SET_ERROR(EIO));
|
|
|
|
}
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We're checking zap_ismicro without the lock held, in order to
|
|
|
|
* tell what type of lock we want. Once we have some sort of
|
|
|
|
* lock, see if it really is the right type. In practice this
|
|
|
|
* can only be different if it was upgraded from micro to fat,
|
|
|
|
* and micro wanted WRITER but fat only needs READER.
|
|
|
|
*/
|
2018-05-30 21:16:54 +03:00
|
|
|
krw_t lt = (!zap->zap_ismicro && fatreader) ? RW_READER : lti;
|
2008-11-20 23:01:55 +03:00
|
|
|
rw_enter(&zap->zap_rwlock, lt);
|
|
|
|
if (lt != ((!zap->zap_ismicro && fatreader) ? RW_READER : lti)) {
|
|
|
|
/* it was upgraded, now we only need reader */
|
|
|
|
ASSERT(lt == RW_WRITER);
|
|
|
|
ASSERT(RW_READER ==
|
2015-08-17 09:55:52 +03:00
|
|
|
((!zap->zap_ismicro && fatreader) ? RW_READER : lti));
|
2008-11-20 23:01:55 +03:00
|
|
|
rw_downgrade(&zap->zap_rwlock);
|
|
|
|
lt = RW_READER;
|
|
|
|
}
|
|
|
|
|
|
|
|
zap->zap_objset = os;
|
2024-03-26 00:58:50 +03:00
|
|
|
zap->zap_dnode = dn;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (lt == RW_WRITER)
|
|
|
|
dmu_buf_will_dirty(db, tx);
|
|
|
|
|
|
|
|
ASSERT3P(zap->zap_dbuf, ==, db);
|
|
|
|
|
|
|
|
ASSERT(!zap->zap_ismicro ||
|
|
|
|
zap->zap_m.zap_num_entries <= zap->zap_m.zap_num_chunks);
|
|
|
|
if (zap->zap_ismicro && tx && adding &&
|
|
|
|
zap->zap_m.zap_num_entries == zap->zap_m.zap_num_chunks) {
|
|
|
|
uint64_t newsz = db->db_size + SPA_MINBLOCKSIZE;
|
2023-01-11 00:41:54 +03:00
|
|
|
if (newsz > zap_micro_max_size) {
|
2008-11-20 23:01:55 +03:00
|
|
|
dprintf("upgrading obj %llu: num_entries=%u\n",
|
2021-06-23 07:53:45 +03:00
|
|
|
(u_longlong_t)obj, zap->zap_m.zap_num_entries);
|
2008-11-20 23:01:55 +03:00
|
|
|
*zapp = zap;
|
2017-11-04 23:25:13 +03:00
|
|
|
int err = mzap_upgrade(zapp, tag, tx, 0);
|
2016-07-21 01:39:55 +03:00
|
|
|
if (err != 0)
|
|
|
|
rw_exit(&zap->zap_rwlock);
|
|
|
|
return (err);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
2016-07-21 01:39:55 +03:00
|
|
|
VERIFY0(dmu_object_set_blocksize(os, obj, newsz, 0, tx));
|
2008-11-20 23:01:55 +03:00
|
|
|
zap->zap_m.zap_num_chunks =
|
|
|
|
db->db_size / MZAP_ENT_LEN - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*zapp = zap;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
OpenZFS 7004 - dmu_tx_hold_zap() does dnode_hold() 7x on same object
Using a benchmark which has 32 threads creating 2 million files in the
same directory, on a machine with 16 CPU cores, I observed poor
performance. I noticed that dmu_tx_hold_zap() was using about 30% of
all CPU, and doing dnode_hold() 7 times on the same object (the ZAP
object that is being held).
dmu_tx_hold_zap() keeps a hold on the dnode_t the entire time it is
running, in dmu_tx_hold_t:txh_dnode, so it would be nice to use the
dnode_t that we already have in hand, rather than repeatedly calling
dnode_hold(). To do this, we need to pass the dnode_t down through
all the intermediate calls that dmu_tx_hold_zap() makes, making these
routines take the dnode_t* rather than an objset_t* and a uint64_t
object number. In particular, the following routines will need to have
analogous *_by_dnode() variants created:
dmu_buf_hold_noread()
dmu_buf_hold()
zap_lookup()
zap_lookup_norm()
zap_count_write()
zap_lockdir()
zap_count_write()
This can improve performance on the benchmark described above by 100%,
from 30,000 file creations per second to 60,000. (This improvement is on
top of that provided by working around the object allocation issue. Peak
performance of ~90,000 creations per second was observed with 8 CPUs;
adding CPUs past that decreased performance due to lock contention.) The
CPU used by dmu_tx_hold_zap() was reduced by 88%, from 340 CPU-seconds
to 40 CPU-seconds.
Sponsored by: Intel Corp.
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/7004
OpenZFS-commit: https://github.com/openzfs/openzfs/pull/109
Closes #4641
Closes #4972
2016-07-21 01:42:13 +03:00
|
|
|
static int
|
|
|
|
zap_lockdir_by_dnode(dnode_t *dn, dmu_tx_t *tx,
|
2022-04-19 21:49:30 +03:00
|
|
|
krw_t lti, boolean_t fatreader, boolean_t adding, const void *tag,
|
|
|
|
zap_t **zapp)
|
OpenZFS 7004 - dmu_tx_hold_zap() does dnode_hold() 7x on same object
Using a benchmark which has 32 threads creating 2 million files in the
same directory, on a machine with 16 CPU cores, I observed poor
performance. I noticed that dmu_tx_hold_zap() was using about 30% of
all CPU, and doing dnode_hold() 7 times on the same object (the ZAP
object that is being held).
dmu_tx_hold_zap() keeps a hold on the dnode_t the entire time it is
running, in dmu_tx_hold_t:txh_dnode, so it would be nice to use the
dnode_t that we already have in hand, rather than repeatedly calling
dnode_hold(). To do this, we need to pass the dnode_t down through
all the intermediate calls that dmu_tx_hold_zap() makes, making these
routines take the dnode_t* rather than an objset_t* and a uint64_t
object number. In particular, the following routines will need to have
analogous *_by_dnode() variants created:
dmu_buf_hold_noread()
dmu_buf_hold()
zap_lookup()
zap_lookup_norm()
zap_count_write()
zap_lockdir()
zap_count_write()
This can improve performance on the benchmark described above by 100%,
from 30,000 file creations per second to 60,000. (This improvement is on
top of that provided by working around the object allocation issue. Peak
performance of ~90,000 creations per second was observed with 8 CPUs;
adding CPUs past that decreased performance due to lock contention.) The
CPU used by dmu_tx_hold_zap() was reduced by 88%, from 340 CPU-seconds
to 40 CPU-seconds.
Sponsored by: Intel Corp.
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/7004
OpenZFS-commit: https://github.com/openzfs/openzfs/pull/109
Closes #4641
Closes #4972
2016-07-21 01:42:13 +03:00
|
|
|
{
|
|
|
|
dmu_buf_t *db;
|
2024-03-26 00:58:50 +03:00
|
|
|
int err;
|
OpenZFS 7004 - dmu_tx_hold_zap() does dnode_hold() 7x on same object
Using a benchmark which has 32 threads creating 2 million files in the
same directory, on a machine with 16 CPU cores, I observed poor
performance. I noticed that dmu_tx_hold_zap() was using about 30% of
all CPU, and doing dnode_hold() 7 times on the same object (the ZAP
object that is being held).
dmu_tx_hold_zap() keeps a hold on the dnode_t the entire time it is
running, in dmu_tx_hold_t:txh_dnode, so it would be nice to use the
dnode_t that we already have in hand, rather than repeatedly calling
dnode_hold(). To do this, we need to pass the dnode_t down through
all the intermediate calls that dmu_tx_hold_zap() makes, making these
routines take the dnode_t* rather than an objset_t* and a uint64_t
object number. In particular, the following routines will need to have
analogous *_by_dnode() variants created:
dmu_buf_hold_noread()
dmu_buf_hold()
zap_lookup()
zap_lookup_norm()
zap_count_write()
zap_lockdir()
zap_count_write()
This can improve performance on the benchmark described above by 100%,
from 30,000 file creations per second to 60,000. (This improvement is on
top of that provided by working around the object allocation issue. Peak
performance of ~90,000 creations per second was observed with 8 CPUs;
adding CPUs past that decreased performance due to lock contention.) The
CPU used by dmu_tx_hold_zap() was reduced by 88%, from 340 CPU-seconds
to 40 CPU-seconds.
Sponsored by: Intel Corp.
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/7004
OpenZFS-commit: https://github.com/openzfs/openzfs/pull/109
Closes #4641
Closes #4972
2016-07-21 01:42:13 +03:00
|
|
|
|
2024-03-26 00:58:50 +03:00
|
|
|
err = dmu_buf_hold_by_dnode(dn, 0, tag, &db, DMU_READ_NO_PREFETCH);
|
|
|
|
if (err != 0)
|
OpenZFS 7004 - dmu_tx_hold_zap() does dnode_hold() 7x on same object
Using a benchmark which has 32 threads creating 2 million files in the
same directory, on a machine with 16 CPU cores, I observed poor
performance. I noticed that dmu_tx_hold_zap() was using about 30% of
all CPU, and doing dnode_hold() 7 times on the same object (the ZAP
object that is being held).
dmu_tx_hold_zap() keeps a hold on the dnode_t the entire time it is
running, in dmu_tx_hold_t:txh_dnode, so it would be nice to use the
dnode_t that we already have in hand, rather than repeatedly calling
dnode_hold(). To do this, we need to pass the dnode_t down through
all the intermediate calls that dmu_tx_hold_zap() makes, making these
routines take the dnode_t* rather than an objset_t* and a uint64_t
object number. In particular, the following routines will need to have
analogous *_by_dnode() variants created:
dmu_buf_hold_noread()
dmu_buf_hold()
zap_lookup()
zap_lookup_norm()
zap_count_write()
zap_lockdir()
zap_count_write()
This can improve performance on the benchmark described above by 100%,
from 30,000 file creations per second to 60,000. (This improvement is on
top of that provided by working around the object allocation issue. Peak
performance of ~90,000 creations per second was observed with 8 CPUs;
adding CPUs past that decreased performance due to lock contention.) The
CPU used by dmu_tx_hold_zap() was reduced by 88%, from 340 CPU-seconds
to 40 CPU-seconds.
Sponsored by: Intel Corp.
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/7004
OpenZFS-commit: https://github.com/openzfs/openzfs/pull/109
Closes #4641
Closes #4972
2016-07-21 01:42:13 +03:00
|
|
|
return (err);
|
2024-03-26 00:58:50 +03:00
|
|
|
err = zap_lockdir_impl(dn, db, tag, tx, lti, fatreader, adding, zapp);
|
|
|
|
if (err != 0)
|
OpenZFS 7004 - dmu_tx_hold_zap() does dnode_hold() 7x on same object
Using a benchmark which has 32 threads creating 2 million files in the
same directory, on a machine with 16 CPU cores, I observed poor
performance. I noticed that dmu_tx_hold_zap() was using about 30% of
all CPU, and doing dnode_hold() 7 times on the same object (the ZAP
object that is being held).
dmu_tx_hold_zap() keeps a hold on the dnode_t the entire time it is
running, in dmu_tx_hold_t:txh_dnode, so it would be nice to use the
dnode_t that we already have in hand, rather than repeatedly calling
dnode_hold(). To do this, we need to pass the dnode_t down through
all the intermediate calls that dmu_tx_hold_zap() makes, making these
routines take the dnode_t* rather than an objset_t* and a uint64_t
object number. In particular, the following routines will need to have
analogous *_by_dnode() variants created:
dmu_buf_hold_noread()
dmu_buf_hold()
zap_lookup()
zap_lookup_norm()
zap_count_write()
zap_lockdir()
zap_count_write()
This can improve performance on the benchmark described above by 100%,
from 30,000 file creations per second to 60,000. (This improvement is on
top of that provided by working around the object allocation issue. Peak
performance of ~90,000 creations per second was observed with 8 CPUs;
adding CPUs past that decreased performance due to lock contention.) The
CPU used by dmu_tx_hold_zap() was reduced by 88%, from 340 CPU-seconds
to 40 CPU-seconds.
Sponsored by: Intel Corp.
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/7004
OpenZFS-commit: https://github.com/openzfs/openzfs/pull/109
Closes #4641
Closes #4972
2016-07-21 01:42:13 +03:00
|
|
|
dmu_buf_rele(db, tag);
|
2024-03-26 00:58:50 +03:00
|
|
|
else
|
|
|
|
VERIFY(dnode_add_ref(dn, tag));
|
OpenZFS 7004 - dmu_tx_hold_zap() does dnode_hold() 7x on same object
Using a benchmark which has 32 threads creating 2 million files in the
same directory, on a machine with 16 CPU cores, I observed poor
performance. I noticed that dmu_tx_hold_zap() was using about 30% of
all CPU, and doing dnode_hold() 7 times on the same object (the ZAP
object that is being held).
dmu_tx_hold_zap() keeps a hold on the dnode_t the entire time it is
running, in dmu_tx_hold_t:txh_dnode, so it would be nice to use the
dnode_t that we already have in hand, rather than repeatedly calling
dnode_hold(). To do this, we need to pass the dnode_t down through
all the intermediate calls that dmu_tx_hold_zap() makes, making these
routines take the dnode_t* rather than an objset_t* and a uint64_t
object number. In particular, the following routines will need to have
analogous *_by_dnode() variants created:
dmu_buf_hold_noread()
dmu_buf_hold()
zap_lookup()
zap_lookup_norm()
zap_count_write()
zap_lockdir()
zap_count_write()
This can improve performance on the benchmark described above by 100%,
from 30,000 file creations per second to 60,000. (This improvement is on
top of that provided by working around the object allocation issue. Peak
performance of ~90,000 creations per second was observed with 8 CPUs;
adding CPUs past that decreased performance due to lock contention.) The
CPU used by dmu_tx_hold_zap() was reduced by 88%, from 340 CPU-seconds
to 40 CPU-seconds.
Sponsored by: Intel Corp.
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/7004
OpenZFS-commit: https://github.com/openzfs/openzfs/pull/109
Closes #4641
Closes #4972
2016-07-21 01:42:13 +03:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2016-07-21 01:39:55 +03:00
|
|
|
int
|
|
|
|
zap_lockdir(objset_t *os, uint64_t obj, dmu_tx_t *tx,
|
2022-04-19 21:49:30 +03:00
|
|
|
krw_t lti, boolean_t fatreader, boolean_t adding, const void *tag,
|
|
|
|
zap_t **zapp)
|
2016-07-21 01:39:55 +03:00
|
|
|
{
|
2024-03-26 00:58:50 +03:00
|
|
|
dnode_t *dn;
|
2016-07-21 01:39:55 +03:00
|
|
|
dmu_buf_t *db;
|
2024-03-26 00:58:50 +03:00
|
|
|
int err;
|
2016-07-21 01:39:55 +03:00
|
|
|
|
2024-03-26 00:58:50 +03:00
|
|
|
err = dnode_hold(os, obj, tag, &dn);
|
2016-07-21 01:39:55 +03:00
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
2024-03-26 00:58:50 +03:00
|
|
|
err = dmu_buf_hold_by_dnode(dn, 0, tag, &db, DMU_READ_NO_PREFETCH);
|
|
|
|
if (err != 0) {
|
|
|
|
dnode_rele(dn, tag);
|
|
|
|
return (err);
|
2018-05-30 21:27:40 +03:00
|
|
|
}
|
2024-03-26 00:58:50 +03:00
|
|
|
err = zap_lockdir_impl(dn, db, tag, tx, lti, fatreader, adding, zapp);
|
|
|
|
if (err != 0) {
|
2016-07-21 01:39:55 +03:00
|
|
|
dmu_buf_rele(db, tag);
|
2024-03-26 00:58:50 +03:00
|
|
|
dnode_rele(dn, tag);
|
|
|
|
}
|
2016-07-21 01:39:55 +03:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
void
|
2022-04-19 21:49:30 +03:00
|
|
|
zap_unlockdir(zap_t *zap, const void *tag)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
rw_exit(&zap->zap_rwlock);
|
2024-03-26 00:58:50 +03:00
|
|
|
dnode_rele(zap->zap_dnode, tag);
|
2016-07-21 01:39:55 +03:00
|
|
|
dmu_buf_rele(zap->zap_dbuf, tag);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2022-04-19 21:49:30 +03:00
|
|
|
mzap_upgrade(zap_t **zapp, const void *tag, dmu_tx_t *tx, zap_flags_t flags)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2010-05-29 00:45:14 +04:00
|
|
|
int err = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
zap_t *zap = *zapp;
|
|
|
|
|
|
|
|
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int sz = zap->zap_dbuf->db_size;
|
|
|
|
mzap_phys_t *mzp = vmem_alloc(sz, KM_SLEEP);
|
2022-02-25 16:26:54 +03:00
|
|
|
memcpy(mzp, zap->zap_dbuf->db_data, sz);
|
2018-05-30 21:16:54 +03:00
|
|
|
int nchunks = zap->zap_m.zap_num_chunks;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
if (!flags) {
|
|
|
|
err = dmu_object_set_blocksize(zap->zap_objset, zap->zap_object,
|
|
|
|
1ULL << fzap_default_block_shift, 0, tx);
|
2018-05-30 21:16:54 +03:00
|
|
|
if (err != 0) {
|
2016-12-01 02:18:20 +03:00
|
|
|
vmem_free(mzp, sz);
|
2010-05-29 00:45:14 +04:00
|
|
|
return (err);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dprintf("upgrading obj=%llu with %u chunks\n",
|
2021-06-23 07:53:45 +03:00
|
|
|
(u_longlong_t)zap->zap_object, nchunks);
|
2022-10-20 21:57:15 +03:00
|
|
|
/* XXX destroy the tree later, so we can use the stored hash value */
|
2008-11-20 23:01:55 +03:00
|
|
|
mze_destroy(zap);
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
fzap_upgrade(zap, tx, flags);
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
zap_name_t *zn = zap_name_alloc(zap);
|
2018-05-30 21:16:54 +03:00
|
|
|
for (int i = 0; i < nchunks; i++) {
|
2008-11-20 23:01:55 +03:00
|
|
|
mzap_ent_phys_t *mze = &mzp->mz_chunk[i];
|
|
|
|
if (mze->mze_name[0] == 0)
|
|
|
|
continue;
|
|
|
|
dprintf("adding %s=%llu\n",
|
2021-06-23 07:53:45 +03:00
|
|
|
mze->mze_name, (u_longlong_t)mze->mze_value);
|
2022-10-20 21:57:15 +03:00
|
|
|
zap_name_init_str(zn, mze->mze_name, 0);
|
Fix ENOSPC in "Handle zap_add() failures in ..."
Commit cc63068 caused ENOSPC error when copy a large amount of files
between two directories. The reason is that the patch limits zap leaf
expansion to 2 retries, and return ENOSPC when failed.
The intent for limiting retries is to prevent pointlessly growing table
to max size when adding a block full of entries with same name in
different case in mixed mode. However, it turns out we cannot use any
limit on the retry. When we copy files from one directory in readdir
order, we are copying in hash order, one leaf block at a time. Which
means that if the leaf block in source directory has expanded 6 times,
and you copy those entries in that block, by the time you need to expand
the leaf in destination directory, you need to expand it 6 times in one
go. So any limit on the retry will result in error where it shouldn't.
Note that while we do use different salt for different directories, it
seems that the salt/hash function doesn't provide enough randomization
to the hash distance to prevent this from happening.
Since cc63068 has already been reverted. This patch adds it back and
removes the retry limit.
Also, as it turn out, failing on zap_add() has a serious side effect for
mzap_upgrade(). When upgrading from micro zap to fat zap, it will
call zap_add() to transfer entries one at a time. If it hit any error
halfway through, the remaining entries will be lost, causing those files
to become orphan. This patch add a VERIFY to catch it.
Reviewed-by: Sanjeev Bagewadi <sanjeev.bagewadi@gmail.com>
Reviewed-by: Richard Yao <ryao@gentoo.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Albert Lee <trisk@forkgnu.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Closes #7401
Closes #7421
2018-04-19 00:19:50 +03:00
|
|
|
/* If we fail here, we would end up losing entries */
|
|
|
|
VERIFY0(fzap_add_cd(zn, 8, 1, &mze->mze_value, mze->mze_cd,
|
|
|
|
tag, tx));
|
2008-11-20 23:01:55 +03:00
|
|
|
zap = zn->zn_zap; /* fzap_add_cd() may change zap */
|
|
|
|
}
|
2022-10-20 21:57:15 +03:00
|
|
|
zap_name_free(zn);
|
2016-12-01 02:18:20 +03:00
|
|
|
vmem_free(mzp, sz);
|
2008-11-20 23:01:55 +03:00
|
|
|
*zapp = zap;
|
Fix ENOSPC in "Handle zap_add() failures in ..."
Commit cc63068 caused ENOSPC error when copy a large amount of files
between two directories. The reason is that the patch limits zap leaf
expansion to 2 retries, and return ENOSPC when failed.
The intent for limiting retries is to prevent pointlessly growing table
to max size when adding a block full of entries with same name in
different case in mixed mode. However, it turns out we cannot use any
limit on the retry. When we copy files from one directory in readdir
order, we are copying in hash order, one leaf block at a time. Which
means that if the leaf block in source directory has expanded 6 times,
and you copy those entries in that block, by the time you need to expand
the leaf in destination directory, you need to expand it 6 times in one
go. So any limit on the retry will result in error where it shouldn't.
Note that while we do use different salt for different directories, it
seems that the salt/hash function doesn't provide enough randomization
to the hash distance to prevent this from happening.
Since cc63068 has already been reverted. This patch adds it back and
removes the retry limit.
Also, as it turn out, failing on zap_add() has a serious side effect for
mzap_upgrade(). When upgrading from micro zap to fat zap, it will
call zap_add() to transfer entries one at a time. If it hit any error
halfway through, the remaining entries will be lost, causing those files
to become orphan. This patch add a VERIFY to catch it.
Reviewed-by: Sanjeev Bagewadi <sanjeev.bagewadi@gmail.com>
Reviewed-by: Richard Yao <ryao@gentoo.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Albert Lee <trisk@forkgnu.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Closes #7401
Closes #7421
2018-04-19 00:19:50 +03:00
|
|
|
return (0);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2017-02-03 01:13:41 +03:00
|
|
|
/*
|
|
|
|
* The "normflags" determine the behavior of the matchtype_t which is
|
|
|
|
* passed to zap_lookup_norm(). Names which have the same normalized
|
|
|
|
* version will be stored with the same hash value, and therefore we can
|
|
|
|
* perform normalization-insensitive lookups. We can be Unicode form-
|
|
|
|
* insensitive and/or case-insensitive. The following flags are valid for
|
|
|
|
* "normflags":
|
|
|
|
*
|
|
|
|
* U8_TEXTPREP_NFC
|
|
|
|
* U8_TEXTPREP_NFD
|
|
|
|
* U8_TEXTPREP_NFKC
|
|
|
|
* U8_TEXTPREP_NFKD
|
|
|
|
* U8_TEXTPREP_TOUPPER
|
|
|
|
*
|
|
|
|
* The *_NF* (Normalization Form) flags are mutually exclusive; at most one
|
|
|
|
* of them may be supplied.
|
|
|
|
*/
|
2013-10-08 21:13:05 +04:00
|
|
|
void
|
2019-01-11 01:37:43 +03:00
|
|
|
mzap_create_impl(dnode_t *dn, int normflags, zap_flags_t flags, dmu_tx_t *tx)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
dmu_buf_t *db;
|
|
|
|
|
2019-01-11 01:37:43 +03:00
|
|
|
VERIFY0(dmu_buf_hold_by_dnode(dn, 0, FTAG, &db, DMU_READ_NO_PREFETCH));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
dmu_buf_will_dirty(db, tx);
|
2018-05-30 21:16:54 +03:00
|
|
|
mzap_phys_t *zp = db->db_data;
|
2008-11-20 23:01:55 +03:00
|
|
|
zp->mz_block_type = ZBT_MICRO;
|
2019-01-11 01:37:43 +03:00
|
|
|
zp->mz_salt =
|
|
|
|
((uintptr_t)db ^ (uintptr_t)tx ^ (dn->dn_object << 1)) | 1ULL;
|
2008-11-20 23:01:55 +03:00
|
|
|
zp->mz_normflags = normflags;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
if (flags != 0) {
|
|
|
|
zap_t *zap;
|
|
|
|
/* Only fat zap supports flags; upgrade immediately. */
|
2024-03-26 00:58:50 +03:00
|
|
|
VERIFY(dnode_add_ref(dn, FTAG));
|
|
|
|
VERIFY0(zap_lockdir_impl(dn, db, FTAG, tx, RW_WRITER,
|
2018-05-30 21:27:40 +03:00
|
|
|
B_FALSE, B_FALSE, &zap));
|
2018-05-30 21:16:54 +03:00
|
|
|
VERIFY0(mzap_upgrade(&zap, FTAG, tx, flags));
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2018-05-30 21:27:40 +03:00
|
|
|
} else {
|
|
|
|
dmu_buf_rele(db, FTAG);
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2019-01-11 01:37:43 +03:00
|
|
|
static uint64_t
|
|
|
|
zap_create_impl(objset_t *os, int normflags, zap_flags_t flags,
|
|
|
|
dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
|
|
|
|
dmu_object_type_t bonustype, int bonuslen, int dnodesize,
|
2022-04-19 21:49:30 +03:00
|
|
|
dnode_t **allocated_dnode, const void *tag, dmu_tx_t *tx)
|
2019-01-11 01:37:43 +03:00
|
|
|
{
|
|
|
|
uint64_t obj;
|
|
|
|
|
|
|
|
ASSERT3U(DMU_OT_BYTESWAP(ot), ==, DMU_BSWAP_ZAP);
|
|
|
|
|
|
|
|
if (allocated_dnode == NULL) {
|
|
|
|
dnode_t *dn;
|
|
|
|
obj = dmu_object_alloc_hold(os, ot, 1ULL << leaf_blockshift,
|
|
|
|
indirect_blockshift, bonustype, bonuslen, dnodesize,
|
|
|
|
&dn, FTAG, tx);
|
|
|
|
mzap_create_impl(dn, normflags, flags, tx);
|
|
|
|
dnode_rele(dn, FTAG);
|
|
|
|
} else {
|
|
|
|
obj = dmu_object_alloc_hold(os, ot, 1ULL << leaf_blockshift,
|
|
|
|
indirect_blockshift, bonustype, bonuslen, dnodesize,
|
|
|
|
allocated_dnode, tag, tx);
|
|
|
|
mzap_create_impl(*allocated_dnode, normflags, flags, tx);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (obj);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
int
|
|
|
|
zap_create_claim(objset_t *os, uint64_t obj, dmu_object_type_t ot,
|
|
|
|
dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
|
|
|
|
{
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 04:25:34 +03:00
|
|
|
return (zap_create_claim_dnsize(os, obj, ot, bonustype, bonuslen,
|
|
|
|
0, tx));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_create_claim_dnsize(objset_t *os, uint64_t obj, dmu_object_type_t ot,
|
|
|
|
dmu_object_type_t bonustype, int bonuslen, int dnodesize, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
return (zap_create_claim_norm_dnsize(os, obj,
|
|
|
|
0, ot, bonustype, bonuslen, dnodesize, tx));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_create_claim_norm(objset_t *os, uint64_t obj, int normflags,
|
|
|
|
dmu_object_type_t ot,
|
|
|
|
dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 04:25:34 +03:00
|
|
|
{
|
|
|
|
return (zap_create_claim_norm_dnsize(os, obj, normflags, ot, bonustype,
|
|
|
|
bonuslen, 0, tx));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_create_claim_norm_dnsize(objset_t *os, uint64_t obj, int normflags,
|
|
|
|
dmu_object_type_t ot, dmu_object_type_t bonustype, int bonuslen,
|
|
|
|
int dnodesize, dmu_tx_t *tx)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2019-01-11 01:37:43 +03:00
|
|
|
dnode_t *dn;
|
|
|
|
int error;
|
|
|
|
|
2018-05-30 21:27:40 +03:00
|
|
|
ASSERT3U(DMU_OT_BYTESWAP(ot), ==, DMU_BSWAP_ZAP);
|
2019-01-11 01:37:43 +03:00
|
|
|
error = dmu_object_claim_dnsize(os, obj, ot, 0, bonustype, bonuslen,
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 04:25:34 +03:00
|
|
|
dnodesize, tx);
|
2019-01-11 01:37:43 +03:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
error = dnode_hold(os, obj, FTAG, &dn);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
mzap_create_impl(dn, normflags, 0, tx);
|
|
|
|
|
|
|
|
dnode_rele(dn, FTAG);
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
zap_create(objset_t *os, dmu_object_type_t ot,
|
|
|
|
dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
return (zap_create_norm(os, 0, ot, bonustype, bonuslen, tx));
|
|
|
|
}
|
|
|
|
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 04:25:34 +03:00
|
|
|
uint64_t
|
|
|
|
zap_create_dnsize(objset_t *os, dmu_object_type_t ot,
|
|
|
|
dmu_object_type_t bonustype, int bonuslen, int dnodesize, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
return (zap_create_norm_dnsize(os, 0, ot, bonustype, bonuslen,
|
|
|
|
dnodesize, tx));
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
uint64_t
|
|
|
|
zap_create_norm(objset_t *os, int normflags, dmu_object_type_t ot,
|
|
|
|
dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
|
|
|
|
{
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 04:25:34 +03:00
|
|
|
return (zap_create_norm_dnsize(os, normflags, ot, bonustype, bonuslen,
|
|
|
|
0, tx));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
zap_create_norm_dnsize(objset_t *os, int normflags, dmu_object_type_t ot,
|
|
|
|
dmu_object_type_t bonustype, int bonuslen, int dnodesize, dmu_tx_t *tx)
|
|
|
|
{
|
2019-01-11 01:37:43 +03:00
|
|
|
return (zap_create_impl(os, normflags, 0, ot, 0, 0,
|
|
|
|
bonustype, bonuslen, dnodesize, NULL, NULL, tx));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
zap_create_flags(objset_t *os, int normflags, zap_flags_t flags,
|
|
|
|
dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
|
|
|
|
dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
|
|
|
|
{
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 04:25:34 +03:00
|
|
|
return (zap_create_flags_dnsize(os, normflags, flags, ot,
|
|
|
|
leaf_blockshift, indirect_blockshift, bonustype, bonuslen, 0, tx));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
zap_create_flags_dnsize(objset_t *os, int normflags, zap_flags_t flags,
|
|
|
|
dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
|
|
|
|
dmu_object_type_t bonustype, int bonuslen, int dnodesize, dmu_tx_t *tx)
|
|
|
|
{
|
2019-01-11 01:37:43 +03:00
|
|
|
return (zap_create_impl(os, normflags, flags, ot, leaf_blockshift,
|
|
|
|
indirect_blockshift, bonustype, bonuslen, dnodesize, NULL, NULL,
|
|
|
|
tx));
|
|
|
|
}
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2019-01-11 01:37:43 +03:00
|
|
|
/*
|
|
|
|
* Create a zap object and return a pointer to the newly allocated dnode via
|
|
|
|
* the allocated_dnode argument. The returned dnode will be held and the
|
|
|
|
* caller is responsible for releasing the hold by calling dnode_rele().
|
|
|
|
*/
|
|
|
|
uint64_t
|
|
|
|
zap_create_hold(objset_t *os, int normflags, zap_flags_t flags,
|
|
|
|
dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
|
|
|
|
dmu_object_type_t bonustype, int bonuslen, int dnodesize,
|
2022-04-19 21:49:30 +03:00
|
|
|
dnode_t **allocated_dnode, const void *tag, dmu_tx_t *tx)
|
2019-01-11 01:37:43 +03:00
|
|
|
{
|
|
|
|
return (zap_create_impl(os, normflags, flags, ot, leaf_blockshift,
|
|
|
|
indirect_blockshift, bonustype, bonuslen, dnodesize,
|
|
|
|
allocated_dnode, tag, tx));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_destroy(objset_t *os, uint64_t zapobj, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* dmu_object_free will free the object number and free the
|
|
|
|
* data. Freeing the data will cause our pageout function to be
|
|
|
|
* called, which will destroy our data (zap_leaf_t's and zap_t).
|
|
|
|
*/
|
|
|
|
|
|
|
|
return (dmu_object_free(os, zapobj, tx));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-27 01:43:28 +03:00
|
|
|
zap_evict_sync(void *dbu)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
2015-04-02 06:44:32 +03:00
|
|
|
zap_t *zap = dbu;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
rw_destroy(&zap->zap_rwlock);
|
|
|
|
|
|
|
|
if (zap->zap_ismicro)
|
|
|
|
mze_destroy(zap);
|
|
|
|
else
|
|
|
|
mutex_destroy(&zap->zap_f.zap_num_entries_mtx);
|
|
|
|
|
|
|
|
kmem_free(zap, sizeof (zap_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_count(objset_t *os, uint64_t zapobj, uint64_t *count)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int err =
|
|
|
|
zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
2008-11-20 23:01:55 +03:00
|
|
|
return (err);
|
|
|
|
if (!zap->zap_ismicro) {
|
|
|
|
err = fzap_count(zap, count);
|
|
|
|
} else {
|
|
|
|
*count = zap->zap_m.zap_num_entries;
|
|
|
|
}
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* zn may be NULL; if not specified, it will be computed if needed.
|
|
|
|
* See also the comment above zap_entry_normalization_conflict().
|
|
|
|
*/
|
|
|
|
static boolean_t
|
2022-10-20 21:57:15 +03:00
|
|
|
mzap_normalization_conflict(zap_t *zap, zap_name_t *zn, mzap_ent_t *mze,
|
|
|
|
zfs_btree_index_t *idx)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
boolean_t allocdzn = B_FALSE;
|
2022-10-20 21:57:15 +03:00
|
|
|
mzap_ent_t *other;
|
|
|
|
zfs_btree_index_t oidx;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (zap->zap_normflags == 0)
|
|
|
|
return (B_FALSE);
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
for (other = zfs_btree_prev(&zap->zap_m.zap_tree, idx, &oidx);
|
2008-11-20 23:01:55 +03:00
|
|
|
other && other->mze_hash == mze->mze_hash;
|
2022-10-20 21:57:15 +03:00
|
|
|
other = zfs_btree_prev(&zap->zap_m.zap_tree, &oidx, &oidx)) {
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (zn == NULL) {
|
2022-10-20 21:57:15 +03:00
|
|
|
zn = zap_name_alloc_str(zap,
|
|
|
|
MZE_PHYS(zap, mze)->mze_name, MT_NORMALIZE);
|
2008-11-20 23:01:55 +03:00
|
|
|
allocdzn = B_TRUE;
|
|
|
|
}
|
2010-05-29 00:45:14 +04:00
|
|
|
if (zap_match(zn, MZE_PHYS(zap, other)->mze_name)) {
|
2008-11-20 23:01:55 +03:00
|
|
|
if (allocdzn)
|
|
|
|
zap_name_free(zn);
|
|
|
|
return (B_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
for (other = zfs_btree_next(&zap->zap_m.zap_tree, idx, &oidx);
|
|
|
|
other && other->mze_hash == mze->mze_hash;
|
|
|
|
other = zfs_btree_next(&zap->zap_m.zap_tree, &oidx, &oidx)) {
|
|
|
|
|
|
|
|
if (zn == NULL) {
|
|
|
|
zn = zap_name_alloc_str(zap,
|
|
|
|
MZE_PHYS(zap, mze)->mze_name, MT_NORMALIZE);
|
|
|
|
allocdzn = B_TRUE;
|
|
|
|
}
|
|
|
|
if (zap_match(zn, MZE_PHYS(zap, other)->mze_name)) {
|
|
|
|
if (allocdzn)
|
|
|
|
zap_name_free(zn);
|
|
|
|
return (B_TRUE);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (allocdzn)
|
|
|
|
zap_name_free(zn);
|
|
|
|
return (B_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routines for manipulating attributes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_lookup(objset_t *os, uint64_t zapobj, const char *name,
|
|
|
|
uint64_t integer_size, uint64_t num_integers, void *buf)
|
|
|
|
{
|
|
|
|
return (zap_lookup_norm(os, zapobj, name, integer_size,
|
2017-02-03 01:13:41 +03:00
|
|
|
num_integers, buf, 0, NULL, 0, NULL));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2016-07-21 01:39:55 +03:00
|
|
|
static int
|
|
|
|
zap_lookup_impl(zap_t *zap, const char *name,
|
2008-11-20 23:01:55 +03:00
|
|
|
uint64_t integer_size, uint64_t num_integers, void *buf,
|
|
|
|
matchtype_t mt, char *realname, int rn_len,
|
|
|
|
boolean_t *ncp)
|
|
|
|
{
|
2016-07-21 01:39:55 +03:00
|
|
|
int err = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
zap_name_t *zn = zap_name_alloc_str(zap, name, mt);
|
2016-07-21 01:39:55 +03:00
|
|
|
if (zn == NULL)
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (!zap->zap_ismicro) {
|
|
|
|
err = fzap_lookup(zn, integer_size, num_integers, buf,
|
|
|
|
realname, rn_len, ncp);
|
|
|
|
} else {
|
2022-10-20 21:57:15 +03:00
|
|
|
zfs_btree_index_t idx;
|
|
|
|
mzap_ent_t *mze = mze_find(zn, &idx);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (mze == NULL) {
|
2013-03-08 22:41:28 +04:00
|
|
|
err = SET_ERROR(ENOENT);
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
|
|
|
if (num_integers < 1) {
|
2013-03-08 22:41:28 +04:00
|
|
|
err = SET_ERROR(EOVERFLOW);
|
2008-11-20 23:01:55 +03:00
|
|
|
} else if (integer_size != 8) {
|
2013-03-08 22:41:28 +04:00
|
|
|
err = SET_ERROR(EINVAL);
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
2010-05-29 00:45:14 +04:00
|
|
|
*(uint64_t *)buf =
|
|
|
|
MZE_PHYS(zap, mze)->mze_value;
|
2022-10-15 05:55:48 +03:00
|
|
|
if (realname != NULL)
|
|
|
|
(void) strlcpy(realname,
|
|
|
|
MZE_PHYS(zap, mze)->mze_name,
|
|
|
|
rn_len);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (ncp) {
|
|
|
|
*ncp = mzap_normalization_conflict(zap,
|
2022-10-20 21:57:15 +03:00
|
|
|
zn, mze, &idx);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zap_name_free(zn);
|
2016-07-21 01:39:55 +03:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_lookup_norm(objset_t *os, uint64_t zapobj, const char *name,
|
|
|
|
uint64_t integer_size, uint64_t num_integers, void *buf,
|
|
|
|
matchtype_t mt, char *realname, int rn_len,
|
|
|
|
boolean_t *ncp)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int err =
|
|
|
|
zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
|
2016-07-21 01:39:55 +03:00
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
err = zap_lookup_impl(zap, name, integer_size,
|
|
|
|
num_integers, buf, mt, realname, rn_len, ncp);
|
|
|
|
zap_unlockdir(zap, FTAG);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2014-05-10 01:51:20 +04:00
|
|
|
int
|
|
|
|
zap_prefetch(objset_t *os, uint64_t zapobj, const char *name)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
int err;
|
|
|
|
zap_name_t *zn;
|
|
|
|
|
2016-07-21 01:39:55 +03:00
|
|
|
err = zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
|
2014-05-10 01:51:20 +04:00
|
|
|
if (err)
|
|
|
|
return (err);
|
2022-10-20 21:57:15 +03:00
|
|
|
zn = zap_name_alloc_str(zap, name, 0);
|
2014-05-10 01:51:20 +04:00
|
|
|
if (zn == NULL) {
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2014-05-10 01:51:20 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
|
|
|
}
|
|
|
|
|
|
|
|
fzap_prefetch(zn);
|
|
|
|
zap_name_free(zn);
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2014-05-10 01:51:20 +04:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2024-07-26 19:16:18 +03:00
|
|
|
int
|
|
|
|
zap_prefetch_object(objset_t *os, uint64_t zapobj)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
dmu_object_info_t doi;
|
|
|
|
|
|
|
|
error = dmu_object_info(os, zapobj, &doi);
|
|
|
|
if (error == 0 && DMU_OT_BYTESWAP(doi.doi_type) != DMU_BSWAP_ZAP)
|
|
|
|
error = SET_ERROR(EINVAL);
|
|
|
|
if (error == 0)
|
|
|
|
dmu_prefetch_wait(os, zapobj, 0, doi.doi_max_offset);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
OpenZFS 7004 - dmu_tx_hold_zap() does dnode_hold() 7x on same object
Using a benchmark which has 32 threads creating 2 million files in the
same directory, on a machine with 16 CPU cores, I observed poor
performance. I noticed that dmu_tx_hold_zap() was using about 30% of
all CPU, and doing dnode_hold() 7 times on the same object (the ZAP
object that is being held).
dmu_tx_hold_zap() keeps a hold on the dnode_t the entire time it is
running, in dmu_tx_hold_t:txh_dnode, so it would be nice to use the
dnode_t that we already have in hand, rather than repeatedly calling
dnode_hold(). To do this, we need to pass the dnode_t down through
all the intermediate calls that dmu_tx_hold_zap() makes, making these
routines take the dnode_t* rather than an objset_t* and a uint64_t
object number. In particular, the following routines will need to have
analogous *_by_dnode() variants created:
dmu_buf_hold_noread()
dmu_buf_hold()
zap_lookup()
zap_lookup_norm()
zap_count_write()
zap_lockdir()
zap_count_write()
This can improve performance on the benchmark described above by 100%,
from 30,000 file creations per second to 60,000. (This improvement is on
top of that provided by working around the object allocation issue. Peak
performance of ~90,000 creations per second was observed with 8 CPUs;
adding CPUs past that decreased performance due to lock contention.) The
CPU used by dmu_tx_hold_zap() was reduced by 88%, from 340 CPU-seconds
to 40 CPU-seconds.
Sponsored by: Intel Corp.
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/7004
OpenZFS-commit: https://github.com/openzfs/openzfs/pull/109
Closes #4641
Closes #4972
2016-07-21 01:42:13 +03:00
|
|
|
int
|
|
|
|
zap_lookup_by_dnode(dnode_t *dn, const char *name,
|
|
|
|
uint64_t integer_size, uint64_t num_integers, void *buf)
|
|
|
|
{
|
|
|
|
return (zap_lookup_norm_by_dnode(dn, name, integer_size,
|
2017-02-03 01:13:41 +03:00
|
|
|
num_integers, buf, 0, NULL, 0, NULL));
|
OpenZFS 7004 - dmu_tx_hold_zap() does dnode_hold() 7x on same object
Using a benchmark which has 32 threads creating 2 million files in the
same directory, on a machine with 16 CPU cores, I observed poor
performance. I noticed that dmu_tx_hold_zap() was using about 30% of
all CPU, and doing dnode_hold() 7 times on the same object (the ZAP
object that is being held).
dmu_tx_hold_zap() keeps a hold on the dnode_t the entire time it is
running, in dmu_tx_hold_t:txh_dnode, so it would be nice to use the
dnode_t that we already have in hand, rather than repeatedly calling
dnode_hold(). To do this, we need to pass the dnode_t down through
all the intermediate calls that dmu_tx_hold_zap() makes, making these
routines take the dnode_t* rather than an objset_t* and a uint64_t
object number. In particular, the following routines will need to have
analogous *_by_dnode() variants created:
dmu_buf_hold_noread()
dmu_buf_hold()
zap_lookup()
zap_lookup_norm()
zap_count_write()
zap_lockdir()
zap_count_write()
This can improve performance on the benchmark described above by 100%,
from 30,000 file creations per second to 60,000. (This improvement is on
top of that provided by working around the object allocation issue. Peak
performance of ~90,000 creations per second was observed with 8 CPUs;
adding CPUs past that decreased performance due to lock contention.) The
CPU used by dmu_tx_hold_zap() was reduced by 88%, from 340 CPU-seconds
to 40 CPU-seconds.
Sponsored by: Intel Corp.
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/7004
OpenZFS-commit: https://github.com/openzfs/openzfs/pull/109
Closes #4641
Closes #4972
2016-07-21 01:42:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_lookup_norm_by_dnode(dnode_t *dn, const char *name,
|
|
|
|
uint64_t integer_size, uint64_t num_integers, void *buf,
|
|
|
|
matchtype_t mt, char *realname, int rn_len,
|
|
|
|
boolean_t *ncp)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int err = zap_lockdir_by_dnode(dn, NULL, RW_READER, TRUE, FALSE,
|
OpenZFS 7004 - dmu_tx_hold_zap() does dnode_hold() 7x on same object
Using a benchmark which has 32 threads creating 2 million files in the
same directory, on a machine with 16 CPU cores, I observed poor
performance. I noticed that dmu_tx_hold_zap() was using about 30% of
all CPU, and doing dnode_hold() 7 times on the same object (the ZAP
object that is being held).
dmu_tx_hold_zap() keeps a hold on the dnode_t the entire time it is
running, in dmu_tx_hold_t:txh_dnode, so it would be nice to use the
dnode_t that we already have in hand, rather than repeatedly calling
dnode_hold(). To do this, we need to pass the dnode_t down through
all the intermediate calls that dmu_tx_hold_zap() makes, making these
routines take the dnode_t* rather than an objset_t* and a uint64_t
object number. In particular, the following routines will need to have
analogous *_by_dnode() variants created:
dmu_buf_hold_noread()
dmu_buf_hold()
zap_lookup()
zap_lookup_norm()
zap_count_write()
zap_lockdir()
zap_count_write()
This can improve performance on the benchmark described above by 100%,
from 30,000 file creations per second to 60,000. (This improvement is on
top of that provided by working around the object allocation issue. Peak
performance of ~90,000 creations per second was observed with 8 CPUs;
adding CPUs past that decreased performance due to lock contention.) The
CPU used by dmu_tx_hold_zap() was reduced by 88%, from 340 CPU-seconds
to 40 CPU-seconds.
Sponsored by: Intel Corp.
Signed-off-by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/7004
OpenZFS-commit: https://github.com/openzfs/openzfs/pull/109
Closes #4641
Closes #4972
2016-07-21 01:42:13 +03:00
|
|
|
FTAG, &zap);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
err = zap_lookup_impl(zap, name, integer_size,
|
|
|
|
num_integers, buf, mt, realname, rn_len, ncp);
|
|
|
|
zap_unlockdir(zap, FTAG);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
int
|
|
|
|
zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
|
|
|
|
int key_numints)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int err =
|
|
|
|
zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
2010-05-29 00:45:14 +04:00
|
|
|
return (err);
|
2018-05-30 21:16:54 +03:00
|
|
|
zap_name_t *zn = zap_name_alloc_uint64(zap, key, key_numints);
|
2010-05-29 00:45:14 +04:00
|
|
|
if (zn == NULL) {
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
fzap_prefetch(zn);
|
|
|
|
zap_name_free(zn);
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2010-05-29 00:45:14 +04:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
|
|
|
|
int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int err =
|
|
|
|
zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
2010-05-29 00:45:14 +04:00
|
|
|
return (err);
|
2018-05-30 21:16:54 +03:00
|
|
|
zap_name_t *zn = zap_name_alloc_uint64(zap, key, key_numints);
|
2010-05-29 00:45:14 +04:00
|
|
|
if (zn == NULL) {
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
err = fzap_lookup(zn, integer_size, num_integers, buf,
|
|
|
|
NULL, 0, NULL);
|
|
|
|
zap_name_free(zn);
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2010-05-29 00:45:14 +04:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_contains(objset_t *os, uint64_t zapobj, const char *name)
|
|
|
|
{
|
2013-10-08 21:13:05 +04:00
|
|
|
int err = zap_lookup_norm(os, zapobj, name, 0,
|
2017-02-03 01:13:41 +03:00
|
|
|
0, NULL, 0, NULL, 0, NULL);
|
2010-05-29 00:45:14 +04:00
|
|
|
if (err == EOVERFLOW || err == EINVAL)
|
|
|
|
err = 0; /* found, but skipped reading the value */
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
int
|
|
|
|
zap_length(objset_t *os, uint64_t zapobj, const char *name,
|
|
|
|
uint64_t *integer_size, uint64_t *num_integers)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int err =
|
|
|
|
zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
2008-11-20 23:01:55 +03:00
|
|
|
return (err);
|
2022-10-20 21:57:15 +03:00
|
|
|
zap_name_t *zn = zap_name_alloc_str(zap, name, 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (zn == NULL) {
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
if (!zap->zap_ismicro) {
|
|
|
|
err = fzap_length(zn, integer_size, num_integers);
|
|
|
|
} else {
|
2022-10-20 21:57:15 +03:00
|
|
|
zfs_btree_index_t idx;
|
|
|
|
mzap_ent_t *mze = mze_find(zn, &idx);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (mze == NULL) {
|
2013-03-08 22:41:28 +04:00
|
|
|
err = SET_ERROR(ENOENT);
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
|
|
|
if (integer_size)
|
|
|
|
*integer_size = 8;
|
|
|
|
if (num_integers)
|
|
|
|
*num_integers = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
zap_name_free(zn);
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
int
|
|
|
|
zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
|
|
|
|
int key_numints, uint64_t *integer_size, uint64_t *num_integers)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int err =
|
|
|
|
zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
2010-05-29 00:45:14 +04:00
|
|
|
return (err);
|
2018-05-30 21:16:54 +03:00
|
|
|
zap_name_t *zn = zap_name_alloc_uint64(zap, key, key_numints);
|
2010-05-29 00:45:14 +04:00
|
|
|
if (zn == NULL) {
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
err = fzap_length(zn, integer_size, num_integers);
|
|
|
|
zap_name_free(zn);
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2010-05-29 00:45:14 +04:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
static void
|
|
|
|
mzap_addent(zap_name_t *zn, uint64_t value)
|
|
|
|
{
|
|
|
|
zap_t *zap = zn->zn_zap;
|
2022-10-20 21:57:15 +03:00
|
|
|
uint16_t start = zap->zap_m.zap_alloc_next;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
|
|
|
|
|
|
|
|
#ifdef ZFS_DEBUG
|
2018-05-30 21:16:54 +03:00
|
|
|
for (int i = 0; i < zap->zap_m.zap_num_chunks; i++) {
|
|
|
|
mzap_ent_phys_t *mze = &zap_m_phys(zap)->mz_chunk[i];
|
2010-05-29 00:45:14 +04:00
|
|
|
ASSERT(strcmp(zn->zn_key_orig, mze->mze_name) != 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
uint32_t cd = mze_find_unused_cd(zap, zn->zn_hash);
|
2008-11-20 23:01:55 +03:00
|
|
|
/* given the limited size of the microzap, this can't happen */
|
2010-05-29 00:45:14 +04:00
|
|
|
ASSERT(cd < zap_maxcd(zap));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
again:
|
2022-10-20 21:57:15 +03:00
|
|
|
for (uint16_t i = start; i < zap->zap_m.zap_num_chunks; i++) {
|
2015-04-01 18:14:34 +03:00
|
|
|
mzap_ent_phys_t *mze = &zap_m_phys(zap)->mz_chunk[i];
|
2008-11-20 23:01:55 +03:00
|
|
|
if (mze->mze_name[0] == 0) {
|
|
|
|
mze->mze_value = value;
|
|
|
|
mze->mze_cd = cd;
|
2016-09-26 01:08:28 +03:00
|
|
|
(void) strlcpy(mze->mze_name, zn->zn_key_orig,
|
|
|
|
sizeof (mze->mze_name));
|
2008-11-20 23:01:55 +03:00
|
|
|
zap->zap_m.zap_num_entries++;
|
|
|
|
zap->zap_m.zap_alloc_next = i+1;
|
|
|
|
if (zap->zap_m.zap_alloc_next ==
|
|
|
|
zap->zap_m.zap_num_chunks)
|
|
|
|
zap->zap_m.zap_alloc_next = 0;
|
2010-05-29 00:45:14 +04:00
|
|
|
mze_insert(zap, i, zn->zn_hash);
|
2008-11-20 23:01:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (start != 0) {
|
|
|
|
start = 0;
|
|
|
|
goto again;
|
|
|
|
}
|
2015-02-27 23:53:35 +03:00
|
|
|
cmn_err(CE_PANIC, "out of entries!");
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2017-01-14 01:58:41 +03:00
|
|
|
static int
|
|
|
|
zap_add_impl(zap_t *zap, const char *key,
|
2008-11-20 23:01:55 +03:00
|
|
|
int integer_size, uint64_t num_integers,
|
2022-04-19 21:49:30 +03:00
|
|
|
const void *val, dmu_tx_t *tx, const void *tag)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
const uint64_t *intval = val;
|
2018-05-30 21:16:54 +03:00
|
|
|
int err = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
zap_name_t *zn = zap_name_alloc_str(zap, key, 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (zn == NULL) {
|
2017-01-14 01:58:41 +03:00
|
|
|
zap_unlockdir(zap, tag);
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
if (!zap->zap_ismicro) {
|
2017-01-14 01:58:41 +03:00
|
|
|
err = fzap_add(zn, integer_size, num_integers, val, tag, tx);
|
2008-11-20 23:01:55 +03:00
|
|
|
zap = zn->zn_zap; /* fzap_add() may change zap */
|
|
|
|
} else if (integer_size != 8 || num_integers != 1 ||
|
Fix ENOSPC in "Handle zap_add() failures in ..."
Commit cc63068 caused ENOSPC error when copy a large amount of files
between two directories. The reason is that the patch limits zap leaf
expansion to 2 retries, and return ENOSPC when failed.
The intent for limiting retries is to prevent pointlessly growing table
to max size when adding a block full of entries with same name in
different case in mixed mode. However, it turns out we cannot use any
limit on the retry. When we copy files from one directory in readdir
order, we are copying in hash order, one leaf block at a time. Which
means that if the leaf block in source directory has expanded 6 times,
and you copy those entries in that block, by the time you need to expand
the leaf in destination directory, you need to expand it 6 times in one
go. So any limit on the retry will result in error where it shouldn't.
Note that while we do use different salt for different directories, it
seems that the salt/hash function doesn't provide enough randomization
to the hash distance to prevent this from happening.
Since cc63068 has already been reverted. This patch adds it back and
removes the retry limit.
Also, as it turn out, failing on zap_add() has a serious side effect for
mzap_upgrade(). When upgrading from micro zap to fat zap, it will
call zap_add() to transfer entries one at a time. If it hit any error
halfway through, the remaining entries will be lost, causing those files
to become orphan. This patch add a VERIFY to catch it.
Reviewed-by: Sanjeev Bagewadi <sanjeev.bagewadi@gmail.com>
Reviewed-by: Richard Yao <ryao@gentoo.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Albert Lee <trisk@forkgnu.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Closes #7401
Closes #7421
2018-04-19 00:19:50 +03:00
|
|
|
strlen(key) >= MZAP_NAME_LEN ||
|
|
|
|
!mze_canfit_fzap_leaf(zn, zn->zn_hash)) {
|
2017-01-14 01:58:41 +03:00
|
|
|
err = mzap_upgrade(&zn->zn_zap, tag, tx, 0);
|
2016-07-21 01:39:55 +03:00
|
|
|
if (err == 0) {
|
|
|
|
err = fzap_add(zn, integer_size, num_integers, val,
|
2017-01-14 01:58:41 +03:00
|
|
|
tag, tx);
|
2016-07-21 01:39:55 +03:00
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
zap = zn->zn_zap; /* fzap_add() may change zap */
|
|
|
|
} else {
|
2022-10-20 21:57:15 +03:00
|
|
|
zfs_btree_index_t idx;
|
|
|
|
if (mze_find(zn, &idx) != NULL) {
|
2013-03-08 22:41:28 +04:00
|
|
|
err = SET_ERROR(EEXIST);
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
|
|
|
mzap_addent(zn, *intval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT(zap == zn->zn_zap);
|
|
|
|
zap_name_free(zn);
|
2017-02-25 00:34:26 +03:00
|
|
|
if (zap != NULL) /* may be NULL if fzap_add() failed */
|
|
|
|
zap_unlockdir(zap, tag);
|
2017-01-14 01:58:41 +03:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_add(objset_t *os, uint64_t zapobj, const char *key,
|
|
|
|
int integer_size, uint64_t num_integers,
|
|
|
|
const void *val, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
err = zap_add_impl(zap, key, integer_size, num_integers, val, tx, FTAG);
|
|
|
|
/* zap_add_impl() calls zap_unlockdir() */
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_add_by_dnode(dnode_t *dn, const char *key,
|
|
|
|
int integer_size, uint64_t num_integers,
|
|
|
|
const void *val, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = zap_lockdir_by_dnode(dn, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
err = zap_add_impl(zap, key, integer_size, num_integers, val, tx, FTAG);
|
|
|
|
/* zap_add_impl() calls zap_unlockdir() */
|
2008-11-20 23:01:55 +03:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2024-03-26 00:58:50 +03:00
|
|
|
static int
|
|
|
|
zap_add_uint64_impl(zap_t *zap, const uint64_t *key,
|
|
|
|
int key_numints, int integer_size, uint64_t num_integers,
|
|
|
|
const void *val, dmu_tx_t *tx, const void *tag)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
zap_name_t *zn = zap_name_alloc_uint64(zap, key, key_numints);
|
|
|
|
if (zn == NULL) {
|
|
|
|
zap_unlockdir(zap, tag);
|
|
|
|
return (SET_ERROR(ENOTSUP));
|
|
|
|
}
|
|
|
|
err = fzap_add(zn, integer_size, num_integers, val, tag, tx);
|
|
|
|
zap = zn->zn_zap; /* fzap_add() may change zap */
|
|
|
|
zap_name_free(zn);
|
|
|
|
if (zap != NULL) /* may be NULL if fzap_add() failed */
|
|
|
|
zap_unlockdir(zap, tag);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
int
|
|
|
|
zap_add_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
|
|
|
|
int key_numints, int integer_size, uint64_t num_integers,
|
|
|
|
const void *val, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int err =
|
|
|
|
zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
2010-05-29 00:45:14 +04:00
|
|
|
return (err);
|
2024-03-26 00:58:50 +03:00
|
|
|
err = zap_add_uint64_impl(zap, key, key_numints,
|
|
|
|
integer_size, num_integers, val, tx, FTAG);
|
|
|
|
/* zap_add_uint64_impl() calls zap_unlockdir() */
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_add_uint64_by_dnode(dnode_t *dn, const uint64_t *key,
|
|
|
|
int key_numints, int integer_size, uint64_t num_integers,
|
|
|
|
const void *val, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
|
|
|
int err =
|
|
|
|
zap_lockdir_by_dnode(dn, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
err = zap_add_uint64_impl(zap, key, key_numints,
|
|
|
|
integer_size, num_integers, val, tx, FTAG);
|
|
|
|
/* zap_add_uint64_impl() calls zap_unlockdir() */
|
2010-05-29 00:45:14 +04:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
int
|
|
|
|
zap_update(objset_t *os, uint64_t zapobj, const char *name,
|
|
|
|
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
const uint64_t *intval = val;
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int err =
|
|
|
|
zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
2008-11-20 23:01:55 +03:00
|
|
|
return (err);
|
2022-10-20 21:57:15 +03:00
|
|
|
zap_name_t *zn = zap_name_alloc_str(zap, name, 0);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (zn == NULL) {
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
if (!zap->zap_ismicro) {
|
2016-07-21 01:39:55 +03:00
|
|
|
err = fzap_update(zn, integer_size, num_integers, val,
|
|
|
|
FTAG, tx);
|
2008-11-20 23:01:55 +03:00
|
|
|
zap = zn->zn_zap; /* fzap_update() may change zap */
|
|
|
|
} else if (integer_size != 8 || num_integers != 1 ||
|
|
|
|
strlen(name) >= MZAP_NAME_LEN) {
|
|
|
|
dprintf("upgrading obj %llu: intsz=%u numint=%llu name=%s\n",
|
2021-06-23 07:53:45 +03:00
|
|
|
(u_longlong_t)zapobj, integer_size,
|
|
|
|
(u_longlong_t)num_integers, name);
|
2016-07-21 01:39:55 +03:00
|
|
|
err = mzap_upgrade(&zn->zn_zap, FTAG, tx, 0);
|
|
|
|
if (err == 0) {
|
2008-11-20 23:01:55 +03:00
|
|
|
err = fzap_update(zn, integer_size, num_integers,
|
2016-07-21 01:39:55 +03:00
|
|
|
val, FTAG, tx);
|
|
|
|
}
|
2008-11-20 23:01:55 +03:00
|
|
|
zap = zn->zn_zap; /* fzap_update() may change zap */
|
|
|
|
} else {
|
2022-10-20 21:57:15 +03:00
|
|
|
zfs_btree_index_t idx;
|
|
|
|
mzap_ent_t *mze = mze_find(zn, &idx);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (mze != NULL) {
|
2010-05-29 00:45:14 +04:00
|
|
|
MZE_PHYS(zap, mze)->mze_value = *intval;
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
|
|
|
mzap_addent(zn, *intval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT(zap == zn->zn_zap);
|
|
|
|
zap_name_free(zn);
|
|
|
|
if (zap != NULL) /* may be NULL if fzap_upgrade() failed */
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2024-03-26 00:58:50 +03:00
|
|
|
static int
|
|
|
|
zap_update_uint64_impl(zap_t *zap, const uint64_t *key, int key_numints,
|
|
|
|
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx,
|
|
|
|
const void *tag)
|
2010-05-29 00:45:14 +04:00
|
|
|
{
|
2024-03-26 00:58:50 +03:00
|
|
|
int err;
|
2010-05-29 00:45:14 +04:00
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
zap_name_t *zn = zap_name_alloc_uint64(zap, key, key_numints);
|
2010-05-29 00:45:14 +04:00
|
|
|
if (zn == NULL) {
|
2024-03-26 00:58:50 +03:00
|
|
|
zap_unlockdir(zap, tag);
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
2024-03-26 00:58:50 +03:00
|
|
|
err = fzap_update(zn, integer_size, num_integers, val, tag, tx);
|
2010-05-29 00:45:14 +04:00
|
|
|
zap = zn->zn_zap; /* fzap_update() may change zap */
|
|
|
|
zap_name_free(zn);
|
|
|
|
if (zap != NULL) /* may be NULL if fzap_upgrade() failed */
|
2024-03-26 00:58:50 +03:00
|
|
|
zap_unlockdir(zap, tag);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
|
|
|
|
int key_numints, int integer_size, uint64_t num_integers, const void *val,
|
|
|
|
dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
|
|
|
int err =
|
|
|
|
zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
err = zap_update_uint64_impl(zap, key, key_numints,
|
|
|
|
integer_size, num_integers, val, tx, FTAG);
|
|
|
|
/* zap_update_uint64_impl() calls zap_unlockdir() */
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_update_uint64_by_dnode(dnode_t *dn, const uint64_t *key, int key_numints,
|
|
|
|
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
|
|
|
int err =
|
|
|
|
zap_lockdir_by_dnode(dn, tx, RW_WRITER, TRUE, TRUE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
err = zap_update_uint64_impl(zap, key, key_numints,
|
|
|
|
integer_size, num_integers, val, tx, FTAG);
|
|
|
|
/* zap_update_uint64_impl() calls zap_unlockdir() */
|
2010-05-29 00:45:14 +04:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
int
|
|
|
|
zap_remove(objset_t *os, uint64_t zapobj, const char *name, dmu_tx_t *tx)
|
|
|
|
{
|
2017-02-03 01:13:41 +03:00
|
|
|
return (zap_remove_norm(os, zapobj, name, 0, tx));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2017-01-14 01:58:41 +03:00
|
|
|
static int
|
|
|
|
zap_remove_impl(zap_t *zap, const char *name,
|
2008-11-20 23:01:55 +03:00
|
|
|
matchtype_t mt, dmu_tx_t *tx)
|
|
|
|
{
|
2017-01-14 01:58:41 +03:00
|
|
|
int err = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
zap_name_t *zn = zap_name_alloc_str(zap, name, mt);
|
2017-01-14 01:58:41 +03:00
|
|
|
if (zn == NULL)
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOTSUP));
|
2008-11-20 23:01:55 +03:00
|
|
|
if (!zap->zap_ismicro) {
|
|
|
|
err = fzap_remove(zn, tx);
|
|
|
|
} else {
|
2022-10-20 21:57:15 +03:00
|
|
|
zfs_btree_index_t idx;
|
|
|
|
mzap_ent_t *mze = mze_find(zn, &idx);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (mze == NULL) {
|
2013-03-08 22:41:28 +04:00
|
|
|
err = SET_ERROR(ENOENT);
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
|
|
|
zap->zap_m.zap_num_entries--;
|
2022-10-20 21:57:15 +03:00
|
|
|
memset(MZE_PHYS(zap, mze), 0, sizeof (mzap_ent_phys_t));
|
|
|
|
zfs_btree_remove_idx(&zap->zap_m.zap_tree, &idx);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
zap_name_free(zn);
|
2017-01-14 01:58:41 +03:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_remove_norm(objset_t *os, uint64_t zapobj, const char *name,
|
|
|
|
matchtype_t mt, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, FALSE, FTAG, &zap);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
err = zap_remove_impl(zap, name, mt, tx);
|
|
|
|
zap_unlockdir(zap, FTAG);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_remove_by_dnode(dnode_t *dn, const char *name, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = zap_lockdir_by_dnode(dn, tx, RW_WRITER, TRUE, FALSE, FTAG, &zap);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
2017-02-03 01:13:41 +03:00
|
|
|
err = zap_remove_impl(zap, name, 0, tx);
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2024-03-26 00:58:50 +03:00
|
|
|
static int
|
|
|
|
zap_remove_uint64_impl(zap_t *zap, const uint64_t *key, int key_numints,
|
|
|
|
dmu_tx_t *tx, const void *tag)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
zap_name_t *zn = zap_name_alloc_uint64(zap, key, key_numints);
|
|
|
|
if (zn == NULL) {
|
|
|
|
zap_unlockdir(zap, tag);
|
|
|
|
return (SET_ERROR(ENOTSUP));
|
|
|
|
}
|
|
|
|
err = fzap_remove(zn, tx);
|
|
|
|
zap_name_free(zn);
|
|
|
|
zap_unlockdir(zap, tag);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2010-05-29 00:45:14 +04:00
|
|
|
int
|
|
|
|
zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
|
|
|
|
int key_numints, dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int err =
|
|
|
|
zap_lockdir(os, zapobj, tx, RW_WRITER, TRUE, FALSE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
2010-05-29 00:45:14 +04:00
|
|
|
return (err);
|
2024-03-26 00:58:50 +03:00
|
|
|
err = zap_remove_uint64_impl(zap, key, key_numints, tx, FTAG);
|
|
|
|
/* zap_remove_uint64_impl() calls zap_unlockdir() */
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_remove_uint64_by_dnode(dnode_t *dn, const uint64_t *key, int key_numints,
|
|
|
|
dmu_tx_t *tx)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
|
|
|
int err =
|
|
|
|
zap_lockdir_by_dnode(dn, tx, RW_WRITER, TRUE, FALSE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
|
|
|
err = zap_remove_uint64_impl(zap, key, key_numints, tx, FTAG);
|
|
|
|
/* zap_remove_uint64_impl() calls zap_unlockdir() */
|
2010-05-29 00:45:14 +04:00
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
/*
|
|
|
|
* Routines for iterating over the attributes.
|
|
|
|
*/
|
|
|
|
|
2019-06-12 23:13:09 +03:00
|
|
|
static void
|
|
|
|
zap_cursor_init_impl(zap_cursor_t *zc, objset_t *os, uint64_t zapobj,
|
|
|
|
uint64_t serialized, boolean_t prefetch)
|
2008-11-20 23:01:55 +03:00
|
|
|
{
|
|
|
|
zc->zc_objset = os;
|
|
|
|
zc->zc_zap = NULL;
|
|
|
|
zc->zc_leaf = NULL;
|
|
|
|
zc->zc_zapobj = zapobj;
|
2010-05-29 00:45:14 +04:00
|
|
|
zc->zc_serialized = serialized;
|
|
|
|
zc->zc_hash = 0;
|
|
|
|
zc->zc_cd = 0;
|
2019-06-12 23:13:09 +03:00
|
|
|
zc->zc_prefetch = prefetch;
|
|
|
|
}
|
|
|
|
void
|
|
|
|
zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *os, uint64_t zapobj,
|
|
|
|
uint64_t serialized)
|
|
|
|
{
|
|
|
|
zap_cursor_init_impl(zc, os, zapobj, serialized, B_TRUE);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
2019-06-12 23:13:09 +03:00
|
|
|
/*
|
|
|
|
* Initialize a cursor at the beginning of the ZAP object. The entire
|
|
|
|
* ZAP object will be prefetched.
|
|
|
|
*/
|
2008-11-20 23:01:55 +03:00
|
|
|
void
|
|
|
|
zap_cursor_init(zap_cursor_t *zc, objset_t *os, uint64_t zapobj)
|
|
|
|
{
|
2019-06-12 23:13:09 +03:00
|
|
|
zap_cursor_init_impl(zc, os, zapobj, 0, B_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize a cursor at the beginning, but request that we not prefetch
|
|
|
|
* the entire ZAP object.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
zap_cursor_init_noprefetch(zap_cursor_t *zc, objset_t *os, uint64_t zapobj)
|
|
|
|
{
|
|
|
|
zap_cursor_init_impl(zc, os, zapobj, 0, B_FALSE);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zap_cursor_fini(zap_cursor_t *zc)
|
|
|
|
{
|
|
|
|
if (zc->zc_zap) {
|
|
|
|
rw_enter(&zc->zc_zap->zap_rwlock, RW_READER);
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zc->zc_zap, NULL);
|
2008-11-20 23:01:55 +03:00
|
|
|
zc->zc_zap = NULL;
|
|
|
|
}
|
|
|
|
if (zc->zc_leaf) {
|
|
|
|
rw_enter(&zc->zc_leaf->l_rwlock, RW_READER);
|
|
|
|
zap_put_leaf(zc->zc_leaf);
|
|
|
|
zc->zc_leaf = NULL;
|
|
|
|
}
|
|
|
|
zc->zc_objset = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
zap_cursor_serialize(zap_cursor_t *zc)
|
|
|
|
{
|
|
|
|
if (zc->zc_hash == -1ULL)
|
|
|
|
return (-1ULL);
|
2010-05-29 00:45:14 +04:00
|
|
|
if (zc->zc_zap == NULL)
|
|
|
|
return (zc->zc_serialized);
|
|
|
|
ASSERT((zc->zc_hash & zap_maxcd(zc->zc_zap)) == 0);
|
|
|
|
ASSERT(zc->zc_cd < zap_maxcd(zc->zc_zap));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We want to keep the high 32 bits of the cursor zero if we can, so
|
|
|
|
* that 32-bit programs can access this. So usually use a small
|
|
|
|
* (28-bit) hash value so we can fit 4 bits of cd into the low 32-bits
|
|
|
|
* of the cursor.
|
|
|
|
*
|
|
|
|
* [ collision differentiator | zap_hashbits()-bit hash value ]
|
|
|
|
*/
|
|
|
|
return ((zc->zc_hash >> (64 - zap_hashbits(zc->zc_zap))) |
|
|
|
|
((uint64_t)zc->zc_cd << zap_hashbits(zc->zc_zap)));
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (zc->zc_hash == -1ULL)
|
2013-03-08 22:41:28 +04:00
|
|
|
return (SET_ERROR(ENOENT));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (zc->zc_zap == NULL) {
|
2010-05-29 00:45:14 +04:00
|
|
|
int hb;
|
2008-11-20 23:01:55 +03:00
|
|
|
err = zap_lockdir(zc->zc_objset, zc->zc_zapobj, NULL,
|
2016-07-21 01:39:55 +03:00
|
|
|
RW_READER, TRUE, FALSE, NULL, &zc->zc_zap);
|
2018-05-30 21:16:54 +03:00
|
|
|
if (err != 0)
|
2008-11-20 23:01:55 +03:00
|
|
|
return (err);
|
2010-05-29 00:45:14 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To support zap_cursor_init_serialized, advance, retrieve,
|
|
|
|
* we must add to the existing zc_cd, which may already
|
|
|
|
* be 1 due to the zap_cursor_advance.
|
|
|
|
*/
|
|
|
|
ASSERT(zc->zc_hash == 0);
|
|
|
|
hb = zap_hashbits(zc->zc_zap);
|
|
|
|
zc->zc_hash = zc->zc_serialized << (64 - hb);
|
|
|
|
zc->zc_cd += zc->zc_serialized >> hb;
|
|
|
|
if (zc->zc_cd >= zap_maxcd(zc->zc_zap)) /* corrupt serialized */
|
|
|
|
zc->zc_cd = 0;
|
2008-11-20 23:01:55 +03:00
|
|
|
} else {
|
|
|
|
rw_enter(&zc->zc_zap->zap_rwlock, RW_READER);
|
|
|
|
}
|
|
|
|
if (!zc->zc_zap->zap_ismicro) {
|
|
|
|
err = fzap_cursor_retrieve(zc->zc_zap, zc, za);
|
|
|
|
} else {
|
2022-10-20 21:57:15 +03:00
|
|
|
zfs_btree_index_t idx;
|
2018-05-30 21:16:54 +03:00
|
|
|
mzap_ent_t mze_tofind;
|
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
mze_tofind.mze_hash = zc->zc_hash >> 32;
|
2010-05-29 00:45:14 +04:00
|
|
|
mze_tofind.mze_cd = zc->zc_cd;
|
2008-11-20 23:01:55 +03:00
|
|
|
|
2022-10-20 21:57:15 +03:00
|
|
|
mzap_ent_t *mze = zfs_btree_find(&zc->zc_zap->zap_m.zap_tree,
|
|
|
|
&mze_tofind, &idx);
|
2008-11-20 23:01:55 +03:00
|
|
|
if (mze == NULL) {
|
2022-10-20 21:57:15 +03:00
|
|
|
mze = zfs_btree_next(&zc->zc_zap->zap_m.zap_tree,
|
|
|
|
&idx, &idx);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
if (mze) {
|
2010-05-29 00:45:14 +04:00
|
|
|
mzap_ent_phys_t *mzep = MZE_PHYS(zc->zc_zap, mze);
|
|
|
|
ASSERT3U(mze->mze_cd, ==, mzep->mze_cd);
|
2008-11-20 23:01:55 +03:00
|
|
|
za->za_normalization_conflict =
|
2022-10-20 21:57:15 +03:00
|
|
|
mzap_normalization_conflict(zc->zc_zap, NULL,
|
|
|
|
mze, &idx);
|
2008-11-20 23:01:55 +03:00
|
|
|
za->za_integer_length = 8;
|
|
|
|
za->za_num_integers = 1;
|
2010-05-29 00:45:14 +04:00
|
|
|
za->za_first_integer = mzep->mze_value;
|
2020-06-07 21:42:12 +03:00
|
|
|
(void) strlcpy(za->za_name, mzep->mze_name,
|
|
|
|
sizeof (za->za_name));
|
2022-10-20 21:57:15 +03:00
|
|
|
zc->zc_hash = (uint64_t)mze->mze_hash << 32;
|
2010-05-29 00:45:14 +04:00
|
|
|
zc->zc_cd = mze->mze_cd;
|
2008-11-20 23:01:55 +03:00
|
|
|
err = 0;
|
|
|
|
} else {
|
|
|
|
zc->zc_hash = -1ULL;
|
2013-03-08 22:41:28 +04:00
|
|
|
err = SET_ERROR(ENOENT);
|
2008-11-20 23:01:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rw_exit(&zc->zc_zap->zap_rwlock);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zap_cursor_advance(zap_cursor_t *zc)
|
|
|
|
{
|
|
|
|
if (zc->zc_hash == -1ULL)
|
|
|
|
return;
|
|
|
|
zc->zc_cd++;
|
2010-05-29 00:45:14 +04:00
|
|
|
}
|
|
|
|
|
2008-11-20 23:01:55 +03:00
|
|
|
int
|
|
|
|
zap_get_stats(objset_t *os, uint64_t zapobj, zap_stats_t *zs)
|
|
|
|
{
|
|
|
|
zap_t *zap;
|
|
|
|
|
2018-05-30 21:16:54 +03:00
|
|
|
int err =
|
|
|
|
zap_lockdir(os, zapobj, NULL, RW_READER, TRUE, FALSE, FTAG, &zap);
|
|
|
|
if (err != 0)
|
2008-11-20 23:01:55 +03:00
|
|
|
return (err);
|
|
|
|
|
2022-02-25 16:26:54 +03:00
|
|
|
memset(zs, 0, sizeof (zap_stats_t));
|
2008-11-20 23:01:55 +03:00
|
|
|
|
|
|
|
if (zap->zap_ismicro) {
|
|
|
|
zs->zs_blocksize = zap->zap_dbuf->db_size;
|
|
|
|
zs->zs_num_entries = zap->zap_m.zap_num_entries;
|
|
|
|
zs->zs_num_blocks = 1;
|
|
|
|
} else {
|
|
|
|
fzap_get_stats(zap, zs);
|
|
|
|
}
|
2016-07-21 01:39:55 +03:00
|
|
|
zap_unlockdir(zap, FTAG);
|
2008-11-20 23:01:55 +03:00
|
|
|
return (0);
|
|
|
|
}
|
2009-07-03 02:44:48 +04:00
|
|
|
|
2018-02-16 04:53:18 +03:00
|
|
|
#if defined(_KERNEL)
|
2010-08-26 22:49:16 +04:00
|
|
|
EXPORT_SYMBOL(zap_create);
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 04:25:34 +03:00
|
|
|
EXPORT_SYMBOL(zap_create_dnsize);
|
2011-09-28 03:07:35 +04:00
|
|
|
EXPORT_SYMBOL(zap_create_norm);
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 04:25:34 +03:00
|
|
|
EXPORT_SYMBOL(zap_create_norm_dnsize);
|
2011-09-28 03:07:35 +04:00
|
|
|
EXPORT_SYMBOL(zap_create_flags);
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 04:25:34 +03:00
|
|
|
EXPORT_SYMBOL(zap_create_flags_dnsize);
|
2011-09-28 03:07:35 +04:00
|
|
|
EXPORT_SYMBOL(zap_create_claim);
|
|
|
|
EXPORT_SYMBOL(zap_create_claim_norm);
|
Implement large_dnode pool feature
Justification
-------------
This feature adds support for variable length dnodes. Our motivation is
to eliminate the overhead associated with using spill blocks. Spill
blocks are used to store system attribute data (i.e. file metadata) that
does not fit in the dnode's bonus buffer. By allowing a larger bonus
buffer area the use of a spill block can be avoided. Spill blocks
potentially incur an additional read I/O for every dnode in a dnode
block. As a worst case example, reading 32 dnodes from a 16k dnode block
and all of the spill blocks could issue 33 separate reads. Now suppose
those dnodes have size 1024 and therefore don't need spill blocks. Then
the worst case number of blocks read is reduced to from 33 to two--one
per dnode block. In practice spill blocks may tend to be co-located on
disk with the dnode blocks so the reduction in I/O would not be this
drastic. In a badly fragmented pool, however, the improvement could be
significant.
ZFS-on-Linux systems that make heavy use of extended attributes would
benefit from this feature. In particular, ZFS-on-Linux supports the
xattr=sa dataset property which allows file extended attribute data
to be stored in the dnode bonus buffer as an alternative to the
traditional directory-based format. Workloads such as SELinux and the
Lustre distributed filesystem often store enough xattr data to force
spill bocks when xattr=sa is in effect. Large dnodes may therefore
provide a performance benefit to such systems.
Other use cases that may benefit from this feature include files with
large ACLs and symbolic links with long target names. Furthermore,
this feature may be desirable on other platforms in case future
applications or features are developed that could make use of a
larger bonus buffer area.
Implementation
--------------
The size of a dnode may be a multiple of 512 bytes up to the size of
a dnode block (currently 16384 bytes). A dn_extra_slots field was
added to the current on-disk dnode_phys_t structure to describe the
size of the physical dnode on disk. The 8 bits for this field were
taken from the zero filled dn_pad2 field. The field represents how
many "extra" dnode_phys_t slots a dnode consumes in its dnode block.
This convention results in a value of 0 for 512 byte dnodes which
preserves on-disk format compatibility with older software.
Similarly, the in-memory dnode_t structure has a new dn_num_slots field
to represent the total number of dnode_phys_t slots consumed on disk.
Thus dn->dn_num_slots is 1 greater than the corresponding
dnp->dn_extra_slots. This difference in convention was adopted
because, unlike on-disk structures, backward compatibility is not a
concern for in-memory objects, so we used a more natural way to
represent size for a dnode_t.
The default size for newly created dnodes is determined by the value of
a new "dnodesize" dataset property. By default the property is set to
"legacy" which is compatible with older software. Setting the property
to "auto" will allow the filesystem to choose the most suitable dnode
size. Currently this just sets the default dnode size to 1k, but future
code improvements could dynamically choose a size based on observed
workload patterns. Dnodes of varying sizes can coexist within the same
dataset and even within the same dnode block. For example, to enable
automatically-sized dnodes, run
# zfs set dnodesize=auto tank/fish
The user can also specify literal values for the dnodesize property.
These are currently limited to powers of two from 1k to 16k. The
power-of-2 limitation is only for simplicity of the user interface.
Internally the implementation can handle any multiple of 512 up to 16k,
and consumers of the DMU API can specify any legal dnode value.
The size of a new dnode is determined at object allocation time and
stored as a new field in the znode in-memory structure. New DMU
interfaces are added to allow the consumer to specify the dnode size
that a newly allocated object should use. Existing interfaces are
unchanged to avoid having to update every call site and to preserve
compatibility with external consumers such as Lustre. The new
interfaces names are given below. The versions of these functions that
don't take a dnodesize parameter now just call the _dnsize() versions
with a dnodesize of 0, which means use the legacy dnode size.
New DMU interfaces:
dmu_object_alloc_dnsize()
dmu_object_claim_dnsize()
dmu_object_reclaim_dnsize()
New ZAP interfaces:
zap_create_dnsize()
zap_create_norm_dnsize()
zap_create_flags_dnsize()
zap_create_claim_norm_dnsize()
zap_create_link_dnsize()
The constant DN_MAX_BONUSLEN is renamed to DN_OLD_MAX_BONUSLEN. The
spa_maxdnodesize() function should be used to determine the maximum
bonus length for a pool.
These are a few noteworthy changes to key functions:
* The prototype for dnode_hold_impl() now takes a "slots" parameter.
When the DNODE_MUST_BE_FREE flag is set, this parameter is used to
ensure the hole at the specified object offset is large enough to
hold the dnode being created. The slots parameter is also used
to ensure a dnode does not span multiple dnode blocks. In both of
these cases, if a failure occurs, ENOSPC is returned. Keep in mind,
these failure cases are only possible when using DNODE_MUST_BE_FREE.
If the DNODE_MUST_BE_ALLOCATED flag is set, "slots" must be 0.
dnode_hold_impl() will check if the requested dnode is already
consumed as an extra dnode slot by an large dnode, in which case
it returns ENOENT.
* The function dmu_object_alloc() advances to the next dnode block
if dnode_hold_impl() returns an error for a requested object.
This is because the beginning of the next dnode block is the only
location it can safely assume to either be a hole or a valid
starting point for a dnode.
* dnode_next_offset_level() and other functions that iterate
through dnode blocks may no longer use a simple array indexing
scheme. These now use the current dnode's dn_num_slots field to
advance to the next dnode in the block. This is to ensure we
properly skip the current dnode's bonus area and don't interpret it
as a valid dnode.
zdb
---
The zdb command was updated to display a dnode's size under the
"dnsize" column when the object is dumped.
For ZIL create log records, zdb will now display the slot count for
the object.
ztest
-----
Ztest chooses a random dnodesize for every newly created object. The
random distribution is more heavily weighted toward small dnodes to
better simulate real-world datasets.
Unused bonus buffer space is filled with non-zero values computed from
the object number, dataset id, offset, and generation number. This
helps ensure that the dnode traversal code properly skips the interior
regions of large dnodes, and that these interior regions are not
overwritten by data belonging to other dnodes. A new test visits each
object in a dataset. It verifies that the actual dnode size matches what
was stored in the ztest block tag when it was created. It also verifies
that the unused bonus buffer space is filled with the expected data
patterns.
ZFS Test Suite
--------------
Added six new large dnode-specific tests, and integrated the dnodesize
property into existing tests for zfs allow and send/recv.
Send/Receive
------------
ZFS send streams for datasets containing large dnodes cannot be received
on pools that don't support the large_dnode feature. A send stream with
large dnodes sets a DMU_BACKUP_FEATURE_LARGE_DNODE flag which will be
unrecognized by an incompatible receiving pool so that the zfs receive
will fail gracefully.
While not implemented here, it may be possible to generate a
backward-compatible send stream from a dataset containing large
dnodes. The implementation may be tricky, however, because the send
object record for a large dnode would need to be resized to a 512
byte dnode, possibly kicking in a spill block in the process. This
means we would need to construct a new SA layout and possibly
register it in the SA layout object. The SA layout is normally just
sent as an ordinary object record. But if we are constructing new
layouts while generating the send stream we'd have to build the SA
layout object dynamically and send it at the end of the stream.
For sending and receiving between pools that do support large dnodes,
the drr_object send record type is extended with a new field to store
the dnode slot count. This field was repurposed from unused padding
in the structure.
ZIL Replay
----------
The dnode slot count is stored in the uppermost 8 bits of the lr_foid
field. The bits were unused as the object id is currently capped at
48 bits.
Resizing Dnodes
---------------
It should be possible to resize a dnode when it is dirtied if the
current dnodesize dataset property differs from the dnode's size, but
this functionality is not currently implemented. Clearly a dnode can
only grow if there are sufficient contiguous unused slots in the
dnode block, but it should always be possible to shrink a dnode.
Growing dnodes may be useful to reduce fragmentation in a pool with
many spill blocks in use. Shrinking dnodes may be useful to allow
sending a dataset to a pool that doesn't support the large_dnode
feature.
Feature Reference Counting
--------------------------
The reference count for the large_dnode pool feature tracks the
number of datasets that have ever contained a dnode of size larger
than 512 bytes. The first time a large dnode is created in a dataset
the dataset is converted to an extensible dataset. This is a one-way
operation and the only way to decrement the feature count is to
destroy the dataset, even if the dataset no longer contains any large
dnodes. The complexity of reference counting on a per-dnode basis was
too high, so we chose to track it on a per-dataset basis similarly to
the large_block feature.
Signed-off-by: Ned Bass <bass6@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #3542
2016-03-17 04:25:34 +03:00
|
|
|
EXPORT_SYMBOL(zap_create_claim_norm_dnsize);
|
2019-01-11 01:37:43 +03:00
|
|
|
EXPORT_SYMBOL(zap_create_hold);
|
2011-09-28 03:07:35 +04:00
|
|
|
EXPORT_SYMBOL(zap_destroy);
|
2010-08-26 22:49:16 +04:00
|
|
|
EXPORT_SYMBOL(zap_lookup);
|
2017-01-14 01:58:41 +03:00
|
|
|
EXPORT_SYMBOL(zap_lookup_by_dnode);
|
2010-08-26 22:49:16 +04:00
|
|
|
EXPORT_SYMBOL(zap_lookup_norm);
|
2011-09-28 03:07:35 +04:00
|
|
|
EXPORT_SYMBOL(zap_lookup_uint64);
|
|
|
|
EXPORT_SYMBOL(zap_contains);
|
2014-05-10 01:51:20 +04:00
|
|
|
EXPORT_SYMBOL(zap_prefetch);
|
2011-09-28 03:07:35 +04:00
|
|
|
EXPORT_SYMBOL(zap_prefetch_uint64);
|
2024-07-26 19:16:18 +03:00
|
|
|
EXPORT_SYMBOL(zap_prefetch_object);
|
2011-09-28 03:07:35 +04:00
|
|
|
EXPORT_SYMBOL(zap_add);
|
2017-01-14 01:58:41 +03:00
|
|
|
EXPORT_SYMBOL(zap_add_by_dnode);
|
2011-09-28 03:07:35 +04:00
|
|
|
EXPORT_SYMBOL(zap_add_uint64);
|
2024-03-26 00:58:50 +03:00
|
|
|
EXPORT_SYMBOL(zap_add_uint64_by_dnode);
|
2010-08-26 22:49:16 +04:00
|
|
|
EXPORT_SYMBOL(zap_update);
|
2011-09-28 03:07:35 +04:00
|
|
|
EXPORT_SYMBOL(zap_update_uint64);
|
2024-03-26 00:58:50 +03:00
|
|
|
EXPORT_SYMBOL(zap_update_uint64_by_dnode);
|
2011-09-28 03:07:35 +04:00
|
|
|
EXPORT_SYMBOL(zap_length);
|
|
|
|
EXPORT_SYMBOL(zap_length_uint64);
|
|
|
|
EXPORT_SYMBOL(zap_remove);
|
2017-01-14 01:58:41 +03:00
|
|
|
EXPORT_SYMBOL(zap_remove_by_dnode);
|
2011-09-28 03:07:35 +04:00
|
|
|
EXPORT_SYMBOL(zap_remove_norm);
|
|
|
|
EXPORT_SYMBOL(zap_remove_uint64);
|
2024-03-26 00:58:50 +03:00
|
|
|
EXPORT_SYMBOL(zap_remove_uint64_by_dnode);
|
2011-09-28 03:07:35 +04:00
|
|
|
EXPORT_SYMBOL(zap_count);
|
|
|
|
EXPORT_SYMBOL(zap_value_search);
|
|
|
|
EXPORT_SYMBOL(zap_join);
|
|
|
|
EXPORT_SYMBOL(zap_join_increment);
|
|
|
|
EXPORT_SYMBOL(zap_add_int);
|
|
|
|
EXPORT_SYMBOL(zap_remove_int);
|
|
|
|
EXPORT_SYMBOL(zap_lookup_int);
|
|
|
|
EXPORT_SYMBOL(zap_increment_int);
|
|
|
|
EXPORT_SYMBOL(zap_add_int_key);
|
|
|
|
EXPORT_SYMBOL(zap_lookup_int_key);
|
|
|
|
EXPORT_SYMBOL(zap_increment);
|
|
|
|
EXPORT_SYMBOL(zap_cursor_init);
|
|
|
|
EXPORT_SYMBOL(zap_cursor_fini);
|
|
|
|
EXPORT_SYMBOL(zap_cursor_retrieve);
|
|
|
|
EXPORT_SYMBOL(zap_cursor_advance);
|
|
|
|
EXPORT_SYMBOL(zap_cursor_serialize);
|
|
|
|
EXPORT_SYMBOL(zap_cursor_init_serialized);
|
|
|
|
EXPORT_SYMBOL(zap_get_stats);
|
2023-01-11 00:41:54 +03:00
|
|
|
|
|
|
|
/* CSTYLED */
|
|
|
|
ZFS_MODULE_PARAM(zfs, , zap_micro_max_size, INT, ZMOD_RW,
|
|
|
|
"Maximum micro ZAP size, before converting to a fat ZAP, in bytes");
|
2010-08-26 22:49:16 +04:00
|
|
|
#endif
|