Skip to content

Commit 4dd1893

Browse files
committed
Avoid 128K kmem allocations in mzap_upgrade()
As originally implemented the mzap_upgrade() function will perform up to SPA_MAXBLOCKSIZE allocations using kmem_alloc(). These large allocations can potentially block indefinitely if contiguous memory is not available. Since this allocation is done under the zap->zap_rwlock it can appear as if there is a deadlock in zap_lockdir(). This is shown below. The optimal fix for this would be to rework mzap_upgrade() such that no large allocations are required. This could be done but it would result in us diverging further from the other implementations. Therefore I've opted against doing this unless it becomes absolutely necessary. Instead mzap_upgrade() has been updated to use zio_buf_alloc() which can reliably provide buffers of up to SPA_MAXBLOCKSIZE. Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Richard Yao <ryao@gentoo.org> Close #2580
1 parent 50b25b2 commit 4dd1893

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

module/zfs/zap_micro.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,15 @@ mzap_upgrade(zap_t **zapp, dmu_tx_t *tx, zap_flags_t flags)
533533
ASSERT(RW_WRITE_HELD(&zap->zap_rwlock));
534534

535535
sz = zap->zap_dbuf->db_size;
536-
mzp = kmem_alloc(sz, KM_PUSHPAGE | KM_NODEBUG);
536+
mzp = zio_buf_alloc(sz);
537537
bcopy(zap->zap_dbuf->db_data, mzp, sz);
538538
nchunks = zap->zap_m.zap_num_chunks;
539539

540540
if (!flags) {
541541
err = dmu_object_set_blocksize(zap->zap_objset, zap->zap_object,
542542
1ULL << fzap_default_block_shift, 0, tx);
543543
if (err) {
544-
kmem_free(mzp, sz);
544+
zio_buf_free(mzp, sz);
545545
return (err);
546546
}
547547
}
@@ -567,7 +567,7 @@ mzap_upgrade(zap_t **zapp, dmu_tx_t *tx, zap_flags_t flags)
567567
if (err)
568568
break;
569569
}
570-
kmem_free(mzp, sz);
570+
zio_buf_free(mzp, sz);
571571
*zapp = zap;
572572
return (err);
573573
}

0 commit comments

Comments
 (0)