Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 88 additions & 12 deletions src/bio/bio_buffer.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* (C) Copyright 2018-2024 Intel Corporation.
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP
* (C) Copyright 2025-2026 Hewlett Packard Enterprise Development LP
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand Down Expand Up @@ -1244,9 +1244,9 @@ iod_should_retry(struct bio_desc *biod, struct bio_dma_buffer *bdb)
* When there isn't any in-flight IODs, it means the whole DMA buffer
* isn't large enough to satisfy current huge IOD, don't retry.
*
* When current IOD is for copy target, take the source IOD into account.
* When current IOD is the source of a copy, take the destination IOD into account.
*/
if (biod->bd_copy_dst) {
if (biod->bd_copy_src) {
D_ASSERT(bdb->bdb_active_iods >= 1);
return bdb->bdb_active_iods > 1;
}
Expand Down Expand Up @@ -1279,8 +1279,11 @@ iod_fifo_in(struct bio_desc *biod, struct bio_dma_buffer *bdb)
/*
* Non-blocking prep request is usually from high priority job like checkpointing,
* so we allow it jump the queue.
*
* The source of a copy is prepared with the destination buffer held, it must not wait
* (see bio_copy_prep()).
*/
if (biod->bd_non_blocking)
if (biod->bd_non_blocking || biod->bd_copy_src)
return;

biod->bd_in_fifo = 1;
Expand Down Expand Up @@ -1390,7 +1393,11 @@ iod_map_iovs(struct bio_desc *biod, void *arg)
goto out;
}

if (biod->bd_non_blocking) {
/*
* The source of a copy can't wait here, the destination buffer is held:
* bio_copy_prep() releases it, waits and prepares both IODs again.
*/
if (biod->bd_non_blocking || biod->bd_copy_src) {
rc = -DER_AGAIN;
goto out;
}
Expand Down Expand Up @@ -1450,7 +1457,11 @@ iod_prep_internal(struct bio_desc *biod, unsigned int type, void *bulk_ctxt,
d_tm_set_gauge(bdb->bdb_stats.bds_active_iods, bdb->bdb_active_iods);

if (biod->bd_type < BIO_IOD_TYPE_GETBUF) {
rc = ABT_eventual_create(0, &biod->bd_dma_done);
/* An IOD of a copy is prepared again when bio_copy_prep() retries */
if (biod->bd_dma_done != ABT_EVENTUAL_NULL)
rc = ABT_eventual_reset(biod->bd_dma_done);
else
rc = ABT_eventual_create(0, &biod->bd_dma_done);
if (rc != ABT_SUCCESS) {
rc = -DER_NOMEM;
goto failed;
Expand Down Expand Up @@ -1867,32 +1878,97 @@ alloc_copy_desc(struct bio_io_context *ioctxt, struct umem_instance *umem,
return NULL;
}

/*
* The copy can't get the buffer of its source while other IODs are active: wait for one of them
* to complete. Called without any buffer held, see bio_copy_prep().
*/
static void
copy_wait_iods(struct bio_desc *biod, struct bio_dma_buffer *bdb)
{
/* The caller made sure of it: an active IOD is going to wake us up */
D_ASSERT(bdb->bdb_active_iods > 0);

/* Other waiters are queued, the destination IOD is going to join the FIFO queue on retry */
if (bdb->bdb_queued_iods != 0)
return;

/* Wait as the first waiter, it's woken up when an active IOD is completed */
iod_fifo_wait(biod, bdb);
iod_fifo_out(biod, bdb);
}

/*
* A copy needs DMA buffer for both the destination and the source, and copies run concurrently
* on an xstream (VOS aggregation, one per container). A copy must not yield while it holds only
* one of the two buffers: when the DMA buffer is short and can't grow, concurrent copies holding
* one buffer each would wait for each other forever, or keep taking the buffer another copy
* just gave up.
*
* So the destination IOD is prepared first: it waits for buffer as any IOD, with nothing held,
* and loads nothing from media. Then the source IOD is prepared without waiting nor yielding in
* between: either the copy gets both buffers, and only then yields to load the source, or it
* releases the destination buffer, waits for an active IOD to complete and starts over.
*/
int
bio_copy_prep(struct bio_io_context *ioctxt, struct umem_instance *umem,
struct bio_sglist *bsgl_src, struct bio_sglist *bsgl_dst,
struct bio_copy_desc **desc)
{
struct bio_copy_desc *copy_desc;
struct bio_desc *biod_src, *biod_dst;
struct bio_dma_buffer *bdb;
int rc, ret;

copy_desc = alloc_copy_desc(ioctxt, umem, bsgl_src, bsgl_dst);
if (copy_desc == NULL) {
*desc = NULL;
return -DER_NOMEM;
}

rc = bio_iod_prep(copy_desc->bcd_iod_src, BIO_CHK_TYPE_LOCAL, NULL, 0);
biod_src = copy_desc->bcd_iod_src;
biod_dst = copy_desc->bcd_iod_dst;
retry:
rc = bio_iod_prep(biod_dst, BIO_CHK_TYPE_LOCAL, NULL, 0);
if (rc)
goto free;

copy_desc->bcd_iod_dst->bd_copy_dst = 1;
rc = bio_iod_prep(copy_desc->bcd_iod_dst, BIO_CHK_TYPE_LOCAL, NULL, 0);
/*
* The source IOD must not wait if the destination IOD holds DMA buffer. A destination
* accessing SCM directly holds none, the source is then prepared as any IOD.
*/
biod_src->bd_copy_src = (biod_dst->bd_rsrvd.brd_rg_cnt != 0);

rc = bio_iod_prep(biod_src, BIO_CHK_TYPE_LOCAL, NULL, 0);
if (rc) {
ret = bio_iod_post(copy_desc->bcd_iod_src, 0);
D_ASSERT(ret == 0);
bdb = biod_src->bd_copy_src ? iod_dma_buf(biod_src) : NULL;

/* Release the destination buffer, nothing is written on error */
ret = bio_iod_post(biod_dst, rc);
D_ASSERT(ret == rc);
/*
* No DMA buffer for the source while other IODs are active: wait for one of
* them to complete and start over. If none is active, the DMA buffer isn't
* large enough for this copy and the error is returned.
*/
if (rc == -DER_AGAIN && bdb != NULL && bdb->bdb_active_iods > 0) {
copy_wait_iods(biod_dst, bdb);
goto retry;
}
goto free;
}

/*
* For unit test only. In a server the copy yields while the source is loaded from NVMe,
* a unit test polls the completion itself: yield here for the time of the load (fail
* value, in microseconds) so that copies interleave as in a server.
*/
if (DAOS_FAIL_CHECK(DAOS_NVME_COPY_YIELD)) {
uint64_t start = daos_getutime();

do {
ABT_thread_yield();
} while (daos_getutime() < start + daos_fail_value_get());
}

*desc = copy_desc;
return 0;
free:
Expand Down
13 changes: 10 additions & 3 deletions src/bio/bio_internal.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* (C) Copyright 2018-2024 Intel Corporation.
* (C) Copyright 2025 Hewlett Packard Enterprise Development LP
* (C) Copyright 2025-2026 Hewlett Packard Enterprise Development LP
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand Down Expand Up @@ -493,6 +493,7 @@ struct bio_rsrvd_dma {
unsigned int brd_chk_cnt;
};

/* clang-format off */
/* I/O descriptor */
struct bio_desc {
struct bio_io_lug bd_io_lug;
Expand All @@ -509,12 +510,17 @@ struct bio_desc {
unsigned int bd_type;
/* Total bytes landed to data blob */
unsigned int bd_nvme_bytes;
/* Flags */
/*
* Flags
*
* bd_copy_src: source IOD of a copy, prepared after the destination IOD with the
* destination buffer held, so it never waits for DMA buffer, see bio_copy_prep().
*/
unsigned int bd_buffer_prep:1,
bd_dma_issued:1,
bd_retry:1,
bd_rdma:1,
bd_copy_dst:1,
bd_copy_src:1,
bd_in_fifo:1,
bd_async_post:1,
bd_non_blocking:1;
Expand All @@ -529,6 +535,7 @@ struct bio_desc {
unsigned int bd_sgl_cnt;
struct bio_sglist bd_sgls[0];
};
/* clang-format on */

static inline struct spdk_thread *
owner_thread(struct bio_blobstore *bbs)
Expand Down
2 changes: 2 additions & 0 deletions src/include/daos/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,8 @@ enum {
#define DAOS_NVME_READ_ERR (DAOS_FAIL_UNIT_TEST_GROUP_LOC | 0x52)
#define DAOS_NVME_ALLOCBUF_ERR (DAOS_FAIL_UNIT_TEST_GROUP_LOC | 0x53)
#define DAOS_NVME_WAL_TX_LOST (DAOS_FAIL_UNIT_TEST_GROUP_LOC | 0x54)
/* bio_copy_prep() yields with both buffers held, fail value: for how long, in microseconds */
#define DAOS_NVME_COPY_YIELD (DAOS_FAIL_UNIT_TEST_GROUP_LOC | 0x55)

#define DAOS_POOL_CREATE_FAIL_CORPC (DAOS_FAIL_UNIT_TEST_GROUP_LOC | 0x60)
#define DAOS_POOL_DESTROY_FAIL_CORPC (DAOS_FAIL_UNIT_TEST_GROUP_LOC | 0x61)
Expand Down
Loading
Loading