Skip to content

Commit 465f165

Browse files
robnixhamza
authored andcommitted
vdev_disk: move abd return and free off the interrupt handler
Freeing an ABD can take sleeping locks to update various stats. We aren't allowed to sleep on an interrupt handler. So, move the free off to the io_done callback. We should never have been freeing things in the interrupt handler, but we got away with it because we were usually freeing a linear ABD, which at most is returning two objects to a cache and never sleeping. Scatter ABDs can be used now, and those have more complex locking. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes openzfs#16687
1 parent 9886013 commit 465f165

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

module/os/linux/zfs/vdev_disk.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -831,21 +831,13 @@ BIO_END_IO_PROTO(vbio_completion, bio, error)
831831
bio_put(bio);
832832

833833
/*
834-
* If we copied the ABD before issuing it, clean up and return the copy
835-
* to the ADB, with changes if appropriate.
834+
* We're likely in an interrupt context so we can't do ABD/memory work
835+
* here; instead we stash vbio on the zio and take care of it in the
836+
* done callback.
836837
*/
837-
if (vbio->vbio_abd != NULL) {
838-
if (zio->io_type == ZIO_TYPE_READ)
839-
abd_copy(zio->io_abd, vbio->vbio_abd, zio->io_size);
838+
ASSERT3P(zio->io_bio, ==, NULL);
839+
zio->io_bio = vbio;
840840

841-
abd_free(vbio->vbio_abd);
842-
vbio->vbio_abd = NULL;
843-
}
844-
845-
/* Final cleanup */
846-
kmem_free(vbio, sizeof (vbio_t));
847-
848-
/* All done, submit for processing */
849841
zio_delay_interrupt(zio);
850842
}
851843

@@ -1492,6 +1484,28 @@ vdev_disk_io_start(zio_t *zio)
14921484
static void
14931485
vdev_disk_io_done(zio_t *zio)
14941486
{
1487+
/* If this was a read or write, we need to clean up the vbio */
1488+
if (zio->io_bio != NULL) {
1489+
vbio_t *vbio = zio->io_bio;
1490+
zio->io_bio = NULL;
1491+
1492+
/*
1493+
* If we copied the ABD before issuing it, clean up and return
1494+
* the copy to the ADB, with changes if appropriate.
1495+
*/
1496+
if (vbio->vbio_abd != NULL) {
1497+
if (zio->io_type == ZIO_TYPE_READ)
1498+
abd_copy(zio->io_abd, vbio->vbio_abd,
1499+
zio->io_size);
1500+
1501+
abd_free(vbio->vbio_abd);
1502+
vbio->vbio_abd = NULL;
1503+
}
1504+
1505+
/* Final cleanup */
1506+
kmem_free(vbio, sizeof (vbio_t));
1507+
}
1508+
14951509
/*
14961510
* If the device returned EIO, we revalidate the media. If it is
14971511
* determined the media has changed this triggers the asynchronous

0 commit comments

Comments
 (0)