Skip to content

Commit dd54ec7

Browse files
committed
metaslab: don't pass a whole zio to the reserve APIs
They only need a couple of fields, and passing the whole thing just invites fiddling around inside it, like modifying flags, which then makes it much harder to understand the zio state from inside zio.c. We move the flag update to just after a successful throttle in zio.c. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Signed-off-by: Rob Norris <[email protected]>
1 parent ee0cb4c commit dd54ec7

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

include/sys/metaslab.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ void metaslab_class_balance(metaslab_class_t *mc, boolean_t onsync);
110110
void metaslab_class_histogram_verify(metaslab_class_t *);
111111
uint64_t metaslab_class_fragmentation(metaslab_class_t *);
112112
uint64_t metaslab_class_expandable_space(metaslab_class_t *);
113-
boolean_t metaslab_class_throttle_reserve(metaslab_class_t *, int, zio_t *,
114-
boolean_t, boolean_t *);
115-
boolean_t metaslab_class_throttle_unreserve(metaslab_class_t *, int, zio_t *);
113+
boolean_t metaslab_class_throttle_reserve(metaslab_class_t *, int, int,
114+
uint64_t, boolean_t, boolean_t *);
115+
boolean_t metaslab_class_throttle_unreserve(metaslab_class_t *, int, int,
116+
uint64_t);
116117
void metaslab_class_evict_old(metaslab_class_t *, uint64_t);
117118
const char *metaslab_class_get_name(metaslab_class_t *);
118119
uint64_t metaslab_class_get_alloc(metaslab_class_t *);

module/zfs/metaslab.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5757,21 +5757,21 @@ metaslab_free_dva(spa_t *spa, const dva_t *dva, boolean_t checkpoint)
57575757
}
57585758

57595759
/*
5760-
* Reserve some allocation slots. The reservation system must be called
5761-
* before we call into the allocator. If there aren't any available slots
5762-
* then the I/O will be throttled until an I/O completes and its slots are
5763-
* freed up. The function returns true if it was successful in placing
5764-
* the reservation.
5760+
* Reserve some space for a future allocation. The reservation system must be
5761+
* called before we call into the allocator. If there aren't enough space
5762+
* available, the calling I/O will be throttled until another I/O completes and
5763+
* its reservation is released. The function returns true if it was successful
5764+
* in placing the reservation.
57655765
*/
57665766
boolean_t
5767-
metaslab_class_throttle_reserve(metaslab_class_t *mc, int slots, zio_t *zio,
5768-
boolean_t must, boolean_t *more)
5767+
metaslab_class_throttle_reserve(metaslab_class_t *mc, int allocator,
5768+
int copies, uint64_t io_size, boolean_t must, boolean_t *more)
57695769
{
5770-
metaslab_class_allocator_t *mca = &mc->mc_allocator[zio->io_allocator];
5770+
metaslab_class_allocator_t *mca = &mc->mc_allocator[allocator];
57715771

57725772
ASSERT(mc->mc_alloc_throttle_enabled);
5773-
if (mc->mc_alloc_io_size < zio->io_size) {
5774-
mc->mc_alloc_io_size = zio->io_size;
5773+
if (mc->mc_alloc_io_size < io_size) {
5774+
mc->mc_alloc_io_size = io_size;
57755775
metaslab_class_balance(mc, B_FALSE);
57765776
}
57775777
if (must || mca->mca_reserved <= mc->mc_alloc_max) {
@@ -5782,24 +5782,23 @@ metaslab_class_throttle_reserve(metaslab_class_t *mc, int slots, zio_t *zio,
57825782
* worst that can happen is few more I/Os get to allocation
57835783
* earlier, that is not a problem.
57845784
*/
5785-
int64_t delta = slots * zio->io_size;
5785+
int64_t delta = copies * io_size;
57865786
*more = (atomic_add_64_nv(&mca->mca_reserved, delta) <=
57875787
mc->mc_alloc_max);
5788-
zio->io_flags |= ZIO_FLAG_IO_ALLOCATING;
57895788
return (B_TRUE);
57905789
}
57915790
*more = B_FALSE;
57925791
return (B_FALSE);
57935792
}
57945793

57955794
boolean_t
5796-
metaslab_class_throttle_unreserve(metaslab_class_t *mc, int slots,
5797-
zio_t *zio)
5795+
metaslab_class_throttle_unreserve(metaslab_class_t *mc, int allocator,
5796+
int copies, uint64_t io_size)
57985797
{
5799-
metaslab_class_allocator_t *mca = &mc->mc_allocator[zio->io_allocator];
5798+
metaslab_class_allocator_t *mca = &mc->mc_allocator[allocator];
58005799

58015800
ASSERT(mc->mc_alloc_throttle_enabled);
5802-
int64_t delta = slots * zio->io_size;
5801+
int64_t delta = copies * io_size;
58035802
return (atomic_add_64_nv(&mca->mca_reserved, -delta) <=
58045803
mc->mc_alloc_max);
58055804
}

module/zfs/zio.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,8 +3194,9 @@ zio_write_gang_block(zio_t *pio, metaslab_class_t *mc)
31943194
zio_gang_inherit_allocator(pio, zio);
31953195
if (pio->io_flags & ZIO_FLAG_IO_ALLOCATING) {
31963196
boolean_t more;
3197-
VERIFY(metaslab_class_throttle_reserve(mc, gbh_copies,
3198-
zio, B_TRUE, &more));
3197+
VERIFY(metaslab_class_throttle_reserve(mc, zio->io_allocator,
3198+
gbh_copies, zio->io_size, B_TRUE, &more));
3199+
zio->io_flags |= ZIO_FLAG_IO_ALLOCATING;
31993200
}
32003201

32013202
/*
@@ -4078,9 +4079,11 @@ zio_io_to_allocate(metaslab_class_allocator_t *mca, boolean_t *more)
40784079
* reserve then we throttle.
40794080
*/
40804081
if (!metaslab_class_throttle_reserve(zio->io_metaslab_class,
4081-
zio->io_prop.zp_copies, zio, B_FALSE, more)) {
4082+
zio->io_allocator, zio->io_prop.zp_copies, zio->io_size,
4083+
B_FALSE, more)) {
40824084
return (NULL);
40834085
}
4086+
zio->io_flags |= ZIO_FLAG_IO_ALLOCATING;
40844087

40854088
avl_remove(&mca->mca_tree, zio);
40864089
ASSERT3U(zio->io_stage, <, ZIO_STAGE_DVA_ALLOCATE);
@@ -4238,7 +4241,8 @@ zio_dva_allocate(zio_t *zio)
42384241
*/
42394242
if (zio->io_flags & ZIO_FLAG_IO_ALLOCATING) {
42404243
if (metaslab_class_throttle_unreserve(mc,
4241-
zio->io_prop.zp_copies, zio)) {
4244+
zio->io_allocator, zio->io_prop.zp_copies,
4245+
zio->io_size)) {
42424246
zio_allocate_dispatch(zio->io_metaslab_class,
42434247
zio->io_allocator);
42444248
}
@@ -5213,8 +5217,8 @@ zio_ready(zio_t *zio)
52135217
* issue the next I/O to allocate.
52145218
*/
52155219
if (metaslab_class_throttle_unreserve(
5216-
zio->io_metaslab_class, zio->io_prop.zp_copies,
5217-
zio)) {
5220+
zio->io_metaslab_class, zio->io_allocator,
5221+
zio->io_prop.zp_copies, zio->io_size)) {
52185222
zio_allocate_dispatch(zio->io_metaslab_class,
52195223
zio->io_allocator);
52205224
}
@@ -5297,7 +5301,8 @@ zio_dva_throttle_done(zio_t *zio)
52975301
metaslab_group_alloc_decrement(zio->io_spa, vd->vdev_id,
52985302
pio->io_allocator, flags, pio->io_size, tag);
52995303

5300-
if (metaslab_class_throttle_unreserve(zio->io_metaslab_class, 1, pio)) {
5304+
if (metaslab_class_throttle_unreserve(pio->io_metaslab_class,
5305+
pio->io_allocator, 1, pio->io_size)) {
53015306
zio_allocate_dispatch(zio->io_metaslab_class,
53025307
pio->io_allocator);
53035308
}

0 commit comments

Comments
 (0)