Skip to content

Commit 35dd024

Browse files
committed
ZAP: Massively switch to _by_dnode() interfaces
Before this change ZAP called dnode_hold() for almost every block access, that was clearly visible in profiler under heavy load, such as BRT. This patch makes it always hold the dnode reference between zap_lockdir() and zap_unlockdir(). It allows to avoid most of dnode operations between those. It also adds several new _by_dnode() APIs to ZAP and uses them in BRT code. Also adds dmu_prefetch_by_dnode() variant and uses it in the ZAP code. After this there remains only one call to dmu_buf_dnode_enter(), which seems to be unneeded. So remove the call and the functions. Signed-off-by: Alexander Motin <[email protected]> Sponsored by: iXsystems, Inc.
1 parent c28f94f commit 35dd024

File tree

9 files changed

+202
-172
lines changed

9 files changed

+202
-172
lines changed

include/sys/dmu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,6 @@ void dmu_buf_sub_user_size(dmu_buf_t *db, uint64_t nsub);
752752
void *dmu_buf_get_user(dmu_buf_t *db);
753753

754754
objset_t *dmu_buf_get_objset(dmu_buf_t *db);
755-
dnode_t *dmu_buf_dnode_enter(dmu_buf_t *db);
756-
void dmu_buf_dnode_exit(dmu_buf_t *db);
757755

758756
/* Block until any in-progress dmu buf user evictions complete. */
759757
void dmu_buf_user_evict_wait(void);
@@ -902,6 +900,8 @@ extern uint_t zfs_max_recordsize;
902900
*/
903901
void dmu_prefetch(objset_t *os, uint64_t object, int64_t level, uint64_t offset,
904902
uint64_t len, enum zio_priority pri);
903+
void dmu_prefetch_by_dnode(dnode_t *dn, int64_t level, uint64_t offset,
904+
uint64_t len, enum zio_priority pri);
905905
void dmu_prefetch_dnode(objset_t *os, uint64_t object, enum zio_priority pri);
906906

907907
typedef struct dmu_object_info {

include/sys/zap.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ int zap_add_by_dnode(dnode_t *dn, const char *key,
253253
int zap_add_uint64(objset_t *ds, uint64_t zapobj, const uint64_t *key,
254254
int key_numints, int integer_size, uint64_t num_integers,
255255
const void *val, dmu_tx_t *tx);
256+
int zap_add_uint64_by_dnode(dnode_t *dn, const uint64_t *key,
257+
int key_numints, int integer_size, uint64_t num_integers,
258+
const void *val, dmu_tx_t *tx);
256259

257260
/*
258261
* Set the attribute with the given name to the given value. If an
@@ -267,6 +270,9 @@ int zap_update(objset_t *ds, uint64_t zapobj, const char *name,
267270
int zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
268271
int key_numints,
269272
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
273+
int zap_update_uint64_by_dnode(dnode_t *dn, const uint64_t *key,
274+
int key_numints,
275+
int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
270276

271277
/*
272278
* Get the length (in integers) and the integer size of the specified
@@ -292,6 +298,8 @@ int zap_remove_norm(objset_t *ds, uint64_t zapobj, const char *name,
292298
int zap_remove_by_dnode(dnode_t *dn, const char *name, dmu_tx_t *tx);
293299
int zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
294300
int key_numints, dmu_tx_t *tx);
301+
int zap_remove_uint64_by_dnode(dnode_t *dn, const uint64_t *key,
302+
int key_numints, dmu_tx_t *tx);
295303

296304
/*
297305
* Returns (in *count) the number of attributes in the specified zap

include/sys/zap_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ typedef struct zap {
145145
dmu_buf_user_t zap_dbu;
146146
objset_t *zap_objset;
147147
uint64_t zap_object;
148+
dnode_t *zap_dnode;
148149
struct dmu_buf *zap_dbuf;
149150
krwlock_t zap_rwlock;
150151
boolean_t zap_ismicro;

module/zfs/brt.c

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -955,52 +955,10 @@ brt_entry_prefetch(brt_t *brt, uint64_t vdevid, brt_entry_t *bre)
955955
if (mos_entries == 0)
956956
return;
957957

958-
BRT_DEBUG("ZAP prefetch: object=%llu vdev=%llu offset=%llu",
959-
(u_longlong_t)mos_entries, (u_longlong_t)vdevid,
960-
(u_longlong_t)bre->bre_offset);
961958
(void) zap_prefetch_uint64(brt->brt_mos, mos_entries,
962959
(uint64_t *)&bre->bre_offset, BRT_KEY_WORDS);
963960
}
964961

965-
static int
966-
brt_entry_update(brt_t *brt, brt_vdev_t *brtvd, brt_entry_t *bre, dmu_tx_t *tx)
967-
{
968-
int error;
969-
970-
ASSERT(RW_LOCK_HELD(&brt->brt_lock));
971-
ASSERT(brtvd->bv_mos_entries != 0);
972-
ASSERT(bre->bre_refcount > 0);
973-
974-
error = zap_update_uint64(brt->brt_mos, brtvd->bv_mos_entries,
975-
(uint64_t *)&bre->bre_offset, BRT_KEY_WORDS, 1,
976-
sizeof (bre->bre_refcount), &bre->bre_refcount, tx);
977-
BRT_DEBUG("ZAP update: object=%llu vdev=%llu offset=%llu count=%llu "
978-
"error=%d", (u_longlong_t)brtvd->bv_mos_entries,
979-
(u_longlong_t)brtvd->bv_vdevid, (u_longlong_t)bre->bre_offset,
980-
(u_longlong_t)bre->bre_refcount, error);
981-
982-
return (error);
983-
}
984-
985-
static int
986-
brt_entry_remove(brt_t *brt, brt_vdev_t *brtvd, brt_entry_t *bre, dmu_tx_t *tx)
987-
{
988-
int error;
989-
990-
ASSERT(RW_LOCK_HELD(&brt->brt_lock));
991-
ASSERT(brtvd->bv_mos_entries != 0);
992-
ASSERT0(bre->bre_refcount);
993-
994-
error = zap_remove_uint64(brt->brt_mos, brtvd->bv_mos_entries,
995-
(uint64_t *)&bre->bre_offset, BRT_KEY_WORDS, tx);
996-
BRT_DEBUG("ZAP remove: object=%llu vdev=%llu offset=%llu count=%llu "
997-
"error=%d", (u_longlong_t)brtvd->bv_mos_entries,
998-
(u_longlong_t)brtvd->bv_vdevid, (u_longlong_t)bre->bre_offset,
999-
(u_longlong_t)bre->bre_refcount, error);
1000-
1001-
return (error);
1002-
}
1003-
1004962
/*
1005963
* Return TRUE if we _can_ have BRT entry for this bp. It might be false
1006964
* positive, but gives us quick answer if we should look into BRT, which
@@ -1559,24 +1517,16 @@ brt_pending_apply(spa_t *spa, uint64_t txg)
15591517
}
15601518

15611519
static void
1562-
brt_sync_entry(brt_t *brt, brt_vdev_t *brtvd, brt_entry_t *bre, dmu_tx_t *tx)
1520+
brt_sync_entry(dnode_t *dn, brt_entry_t *bre, dmu_tx_t *tx)
15631521
{
1564-
1565-
ASSERT(RW_WRITE_HELD(&brt->brt_lock));
1566-
ASSERT(brtvd->bv_mos_entries != 0);
1567-
15681522
if (bre->bre_refcount == 0) {
1569-
int error;
1570-
1571-
error = brt_entry_remove(brt, brtvd, bre, tx);
1572-
ASSERT(error == 0 || error == ENOENT);
1573-
/*
1574-
* If error == ENOENT then zfs_clone_range() was done from a
1575-
* removed (but opened) file (open(), unlink()).
1576-
*/
1577-
ASSERT(brt_entry_lookup(brt, brtvd, bre) == ENOENT);
1523+
int error = zap_remove_uint64_by_dnode(dn, &bre->bre_offset,
1524+
BRT_KEY_WORDS, tx);
1525+
VERIFY(error == 0 || error == ENOENT);
15781526
} else {
1579-
VERIFY0(brt_entry_update(brt, brtvd, bre, tx));
1527+
VERIFY0(zap_update_uint64_by_dnode(dn, &bre->bre_offset,
1528+
BRT_KEY_WORDS, 1, sizeof (bre->bre_refcount),
1529+
&bre->bre_refcount, tx));
15801530
}
15811531
}
15821532

@@ -1585,6 +1535,7 @@ brt_sync_table(brt_t *brt, dmu_tx_t *tx)
15851535
{
15861536
brt_vdev_t *brtvd;
15871537
brt_entry_t *bre;
1538+
dnode_t *dn;
15881539
uint64_t vdevid;
15891540
void *c;
15901541

@@ -1608,14 +1559,19 @@ brt_sync_table(brt_t *brt, dmu_tx_t *tx)
16081559
if (brtvd->bv_mos_brtvdev == 0)
16091560
brt_vdev_create(brt, brtvd, tx);
16101561

1562+
VERIFY0(dnode_hold(brt->brt_mos, brtvd->bv_mos_entries,
1563+
FTAG, &dn));
1564+
16111565
c = NULL;
16121566
while ((bre = avl_destroy_nodes(&brtvd->bv_tree, &c)) != NULL) {
1613-
brt_sync_entry(brt, brtvd, bre, tx);
1567+
brt_sync_entry(dn, bre, tx);
16141568
brt_entry_free(bre);
16151569
ASSERT(brt->brt_nentries > 0);
16161570
brt->brt_nentries--;
16171571
}
16181572

1573+
dnode_rele(dn, FTAG);
1574+
16191575
brt_vdev_sync(brt, brtvd, tx);
16201576

16211577
if (brtvd->bv_totalcount == 0)

module/zfs/dbuf.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4174,21 +4174,6 @@ dmu_buf_get_objset(dmu_buf_t *db)
41744174
return (dbi->db_objset);
41754175
}
41764176

4177-
dnode_t *
4178-
dmu_buf_dnode_enter(dmu_buf_t *db)
4179-
{
4180-
dmu_buf_impl_t *dbi = (dmu_buf_impl_t *)db;
4181-
DB_DNODE_ENTER(dbi);
4182-
return (DB_DNODE(dbi));
4183-
}
4184-
4185-
void
4186-
dmu_buf_dnode_exit(dmu_buf_t *db)
4187-
{
4188-
dmu_buf_impl_t *dbi = (dmu_buf_impl_t *)db;
4189-
DB_DNODE_EXIT(dbi);
4190-
}
4191-
41924177
static void
41934178
dbuf_check_blkptr(dnode_t *dn, dmu_buf_impl_t *db)
41944179
{

module/zfs/dmu.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,6 @@ dmu_prefetch(objset_t *os, uint64_t object, int64_t level, uint64_t offset,
712712
uint64_t len, zio_priority_t pri)
713713
{
714714
dnode_t *dn;
715-
int64_t level2 = level;
716-
uint64_t start, end, start2, end2;
717715

718716
if (dmu_prefetch_max == 0 || len == 0) {
719717
dmu_prefetch_dnode(os, object, pri);
@@ -723,6 +721,18 @@ dmu_prefetch(objset_t *os, uint64_t object, int64_t level, uint64_t offset,
723721
if (dnode_hold(os, object, FTAG, &dn) != 0)
724722
return;
725723

724+
dmu_prefetch_by_dnode(dn, level, offset, len, pri);
725+
726+
dnode_rele(dn, FTAG);
727+
}
728+
729+
void
730+
dmu_prefetch_by_dnode(dnode_t *dn, int64_t level, uint64_t offset,
731+
uint64_t len, zio_priority_t pri)
732+
{
733+
int64_t level2 = level;
734+
uint64_t start, end, start2, end2;
735+
726736
/*
727737
* Depending on len we may do two prefetches: blocks [start, end) at
728738
* level, and following blocks [start2, end2) at higher level2.
@@ -762,8 +772,6 @@ dmu_prefetch(objset_t *os, uint64_t object, int64_t level, uint64_t offset,
762772
for (uint64_t i = start2; i < end2; i++)
763773
dbuf_prefetch(dn, level2, i, pri, 0);
764774
rw_exit(&dn->dn_struct_rwlock);
765-
766-
dnode_rele(dn, FTAG);
767775
}
768776

769777
/*
@@ -2563,6 +2571,8 @@ EXPORT_SYMBOL(dmu_bonus_hold_by_dnode);
25632571
EXPORT_SYMBOL(dmu_buf_hold_array_by_bonus);
25642572
EXPORT_SYMBOL(dmu_buf_rele_array);
25652573
EXPORT_SYMBOL(dmu_prefetch);
2574+
EXPORT_SYMBOL(dmu_prefetch_by_dnode);
2575+
EXPORT_SYMBOL(dmu_prefetch_dnode);
25662576
EXPORT_SYMBOL(dmu_free_range);
25672577
EXPORT_SYMBOL(dmu_free_long_range);
25682578
EXPORT_SYMBOL(dmu_free_long_object);

module/zfs/dmu_recv.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,6 @@ receive_process_write_record(struct receive_writer_arg *rwa,
23532353
if (rwa->heal) {
23542354
blkptr_t *bp;
23552355
dmu_buf_t *dbp;
2356-
dnode_t *dn;
23572356
int flags = DB_RF_CANFAIL;
23582357

23592358
if (rwa->raw)
@@ -2385,19 +2384,15 @@ receive_process_write_record(struct receive_writer_arg *rwa,
23852384
dmu_buf_rele(dbp, FTAG);
23862385
return (err);
23872386
}
2388-
dn = dmu_buf_dnode_enter(dbp);
23892387
/* Make sure the on-disk block and recv record sizes match */
2390-
if (drrw->drr_logical_size !=
2391-
dn->dn_datablkszsec << SPA_MINBLOCKSHIFT) {
2388+
if (drrw->drr_logical_size != dbp->db_size) {
23922389
err = ENOTSUP;
2393-
dmu_buf_dnode_exit(dbp);
23942390
dmu_buf_rele(dbp, FTAG);
23952391
return (err);
23962392
}
23972393
/* Get the block pointer for the corrupted block */
23982394
bp = dmu_buf_get_blkptr(dbp);
23992395
err = do_corrective_recv(rwa, drrw, rrd, bp);
2400-
dmu_buf_dnode_exit(dbp);
24012396
dmu_buf_rele(dbp, FTAG);
24022397
return (err);
24032398
}

0 commit comments

Comments
 (0)