Skip to content

Commit ea97f8c

Browse files
ahrensbehlendorf
authored andcommitted
Illumos #3834
3834 incremental replication of 'holey' file systems is slow Reviewed by: Adam Leventhal <ahl@delphix.com> Reviewed by: George Wilson <george.wilson@delphix.com> Approved by: Richard Lowe <richlowe@richlowe.net> References: https://www.illumos.org/issues/3834 illumos/illumos-gate@ca48f36 Ported-by: Richard Yao <ryao@gentoo.org> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Issue #1775
1 parent 2883cad commit ea97f8c

File tree

5 files changed

+110
-21
lines changed

5 files changed

+110
-21
lines changed

include/sys/dmu_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
/*
2222
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
2323
* Use is subject to license terms.
24+
*/
25+
/*
2426
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
27+
* Copyright (c) 2013 by Delphix. All rights reserved.
2528
*/
2629

2730
#ifndef _SYS_DMU_IMPL_H
@@ -265,6 +268,9 @@ typedef struct dmu_sendarg {
265268
uint64_t dsa_toguid;
266269
int dsa_err;
267270
dmu_pendop_t dsa_pending_op;
271+
boolean_t dsa_incremental;
272+
uint64_t dsa_last_data_object;
273+
uint64_t dsa_last_data_offset;
268274
} dmu_sendarg_t;
269275

270276
#ifdef __cplusplus

include/sys/dmu_send.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/*
2323
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24-
* Copyright (c) 2012 by Delphix. All rights reserved.
24+
* Copyright (c) 2013 by Delphix. All rights reserved.
2525
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
2626
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
2727
*/
@@ -63,5 +63,6 @@ int dmu_recv_begin(char *tofs, char *tosnap, struct drr_begin *drrb,
6363
int dmu_recv_stream(dmu_recv_cookie_t *drc, struct vnode *vp, offset_t *voffp,
6464
int cleanup_fd, uint64_t *action_handlep);
6565
int dmu_recv_end(dmu_recv_cookie_t *drc, void *owner);
66+
boolean_t dmu_objset_is_receiving(objset_t *os);
6667

6768
#endif /* _DMU_SEND_H */

module/zfs/dbuf.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <sys/zfs_context.h>
2929
#include <sys/arc.h>
3030
#include <sys/dmu.h>
31+
#include <sys/dmu_send.h>
3132
#include <sys/dmu_impl.h>
3233
#include <sys/dbuf.h>
3334
#include <sys/dmu_objset.h>
@@ -846,9 +847,12 @@ dbuf_unoverride(dbuf_dirty_record_t *dr)
846847
/*
847848
* Evict (if its unreferenced) or clear (if its referenced) any level-0
848849
* data blocks in the free range, so that any future readers will find
849-
* empty blocks. Also, if we happen accross any level-1 dbufs in the
850+
* empty blocks. Also, if we happen across any level-1 dbufs in the
850851
* range that have not already been marked dirty, mark them dirty so
851852
* they stay in memory.
853+
*
854+
* This is a no-op if the dataset is in the middle of an incremental
855+
* receive; see comment below for details.
852856
*/
853857
void
854858
dbuf_free_range(dnode_t *dn, uint64_t start, uint64_t end, dmu_tx_t *tx)
@@ -864,6 +868,20 @@ dbuf_free_range(dnode_t *dn, uint64_t start, uint64_t end, dmu_tx_t *tx)
864868
last_l1 = end >> epbs;
865869
}
866870
dprintf_dnode(dn, "start=%llu end=%llu\n", start, end);
871+
872+
if (dmu_objset_is_receiving(dn->dn_objset)) {
873+
/*
874+
* When processing a free record from a zfs receive,
875+
* there should have been no previous modifications to the
876+
* data in this range. Therefore there should be no dbufs
877+
* in the range. Searching dn_dbufs for these non-existent
878+
* dbufs can be very expensive, so simply ignore this.
879+
*/
880+
VERIFY3P(dbuf_find(dn, 0, start), ==, NULL);
881+
VERIFY3P(dbuf_find(dn, 0, end), ==, NULL);
882+
return;
883+
}
884+
867885
mutex_enter(&dn->dn_dbufs_mtx);
868886
for (db = list_head(&dn->dn_dbufs); db; db = db_next) {
869887
db_next = list_next(&dn->dn_dbufs, db);

module/zfs/dmu_send.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,32 @@ dump_free(dmu_sendarg_t *dsp, uint64_t object, uint64_t offset,
109109
{
110110
struct drr_free *drrf = &(dsp->dsa_drr->drr_u.drr_free);
111111

112+
/*
113+
* When we receive a free record, dbuf_free_range() assumes
114+
* that the receiving system doesn't have any dbufs in the range
115+
* being freed. This is always true because there is a one-record
116+
* constraint: we only send one WRITE record for any given
117+
* object+offset. We know that the one-record constraint is
118+
* true because we always send data in increasing order by
119+
* object,offset.
120+
*
121+
* If the increasing-order constraint ever changes, we should find
122+
* another way to assert that the one-record constraint is still
123+
* satisfied.
124+
*/
125+
ASSERT(object > dsp->dsa_last_data_object ||
126+
(object == dsp->dsa_last_data_object &&
127+
offset > dsp->dsa_last_data_offset));
128+
129+
/*
130+
* If we are doing a non-incremental send, then there can't
131+
* be any data in the dataset we're receiving into. Therefore
132+
* a free record would simply be a no-op. Save space by not
133+
* sending it to begin with.
134+
*/
135+
if (!dsp->dsa_incremental)
136+
return (0);
137+
112138
if (length != -1ULL && offset + length < offset)
113139
length = -1ULL;
114140

@@ -175,6 +201,15 @@ dump_data(dmu_sendarg_t *dsp, dmu_object_type_t type,
175201
{
176202
struct drr_write *drrw = &(dsp->dsa_drr->drr_u.drr_write);
177203

204+
/*
205+
* We send data in increasing object, offset order.
206+
* See comment in dump_free() for details.
207+
*/
208+
ASSERT(object > dsp->dsa_last_data_object ||
209+
(object == dsp->dsa_last_data_object &&
210+
offset > dsp->dsa_last_data_offset));
211+
dsp->dsa_last_data_object = object;
212+
dsp->dsa_last_data_offset = offset + blksz - 1;
178213

179214
/*
180215
* If there is any kind of pending aggregation (currently either
@@ -242,6 +277,10 @@ dump_freeobjects(dmu_sendarg_t *dsp, uint64_t firstobj, uint64_t numobjs)
242277
{
243278
struct drr_freeobjects *drrfo = &(dsp->dsa_drr->drr_u.drr_freeobjects);
244279

280+
/* See comment in dump_free(). */
281+
if (!dsp->dsa_incremental)
282+
return (0);
283+
245284
/*
246285
* If there is a pending op, but it's not PENDING_FREEOBJECTS,
247286
* push it out, since free block aggregation can only be done for
@@ -318,9 +357,9 @@ dump_dnode(dmu_sendarg_t *dsp, uint64_t object, dnode_phys_t *dnp)
318357
if (dump_bytes(dsp, DN_BONUS(dnp), P2ROUNDUP(dnp->dn_bonuslen, 8)) != 0)
319358
return (SET_ERROR(EINTR));
320359

321-
/* free anything past the end of the file */
360+
/* Free anything past the end of the file. */
322361
if (dump_free(dsp, object, (dnp->dn_maxblkid + 1) *
323-
(dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT), -1ULL))
362+
(dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT), -1ULL) != 0)
324363
return (SET_ERROR(EINTR));
325364
if (dsp->dsa_err != 0)
326365
return (SET_ERROR(EINTR));
@@ -503,6 +542,7 @@ dmu_send_impl(void *tag, dsl_pool_t *dp, dsl_dataset_t *ds,
503542
dsp->dsa_toguid = ds->ds_phys->ds_guid;
504543
ZIO_SET_CHECKSUM(&dsp->dsa_zc, 0, 0, 0, 0);
505544
dsp->dsa_pending_op = PENDING_NONE;
545+
dsp->dsa_incremental = (fromtxg != 0);
506546

507547
mutex_enter(&ds->ds_sendstream_lock);
508548
list_insert_head(&ds->ds_sendstreams, dsp);
@@ -1799,3 +1839,13 @@ dmu_recv_end(dmu_recv_cookie_t *drc, void *owner)
17991839
else
18001840
return (dmu_recv_existing_end(drc));
18011841
}
1842+
1843+
/*
1844+
* Return TRUE if this objset is currently being received into.
1845+
*/
1846+
boolean_t
1847+
dmu_objset_is_receiving(objset_t *os)
1848+
{
1849+
return (os->os_dsl_dataset != NULL &&
1850+
os->os_dsl_dataset->ds_owner == dmu_recv_tag);
1851+
}

module/zfs/dmu_tx.c

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,7 @@ dmu_tx_hold_free(dmu_tx_t *tx, uint64_t object, uint64_t off, uint64_t len)
604604
{
605605
dmu_tx_hold_t *txh;
606606
dnode_t *dn;
607-
uint64_t start, end, i;
608-
int err, shift;
607+
int err;
609608
zio_t *zio;
610609

611610
ASSERT(tx->tx_txg == 0);
@@ -616,30 +615,45 @@ dmu_tx_hold_free(dmu_tx_t *tx, uint64_t object, uint64_t off, uint64_t len)
616615
return;
617616
dn = txh->txh_dnode;
618617

619-
/* first block */
620-
if (off != 0)
621-
dmu_tx_count_write(txh, off, 1);
622-
/* last block */
623-
if (len != DMU_OBJECT_END)
624-
dmu_tx_count_write(txh, off+len, 1);
625-
626-
dmu_tx_count_dnode(txh);
627-
628618
if (off >= (dn->dn_maxblkid+1) * dn->dn_datablksz)
629619
return;
630620
if (len == DMU_OBJECT_END)
631621
len = (dn->dn_maxblkid+1) * dn->dn_datablksz - off;
632622

623+
dmu_tx_count_dnode(txh);
624+
633625
/*
634-
* For i/o error checking, read the first and last level-0
635-
* blocks, and all the level-1 blocks. The above count_write's
636-
* have already taken care of the level-0 blocks.
626+
* For i/o error checking, we read the first and last level-0
627+
* blocks if they are not aligned, and all the level-1 blocks.
628+
*
629+
* Note: dbuf_free_range() assumes that we have not instantiated
630+
* any level-0 dbufs that will be completely freed. Therefore we must
631+
* exercise care to not read or count the first and last blocks
632+
* if they are blocksize-aligned.
633+
*/
634+
if (dn->dn_datablkshift == 0) {
635+
dmu_tx_count_write(txh, off, len);
636+
} else {
637+
/* first block will be modified if it is not aligned */
638+
if (!IS_P2ALIGNED(off, 1 << dn->dn_datablkshift))
639+
dmu_tx_count_write(txh, off, 1);
640+
/* last block will be modified if it is not aligned */
641+
if (!IS_P2ALIGNED(off + len, 1 << dn->dn_datablkshift))
642+
dmu_tx_count_write(txh, off+len, 1);
643+
}
644+
645+
/*
646+
* Check level-1 blocks.
637647
*/
638648
if (dn->dn_nlevels > 1) {
639-
shift = dn->dn_datablkshift + dn->dn_indblkshift -
649+
int shift = dn->dn_datablkshift + dn->dn_indblkshift -
640650
SPA_BLKPTRSHIFT;
641-
start = off >> shift;
642-
end = dn->dn_datablkshift ? ((off+len) >> shift) : 0;
651+
uint64_t start = off >> shift;
652+
uint64_t end = (off + len) >> shift;
653+
uint64_t i;
654+
655+
ASSERT(dn->dn_datablkshift != 0);
656+
ASSERT(dn->dn_indblkshift != 0);
643657

644658
zio = zio_root(tx->tx_pool->dp_spa,
645659
NULL, NULL, ZIO_FLAG_CANFAIL);

0 commit comments

Comments
 (0)