[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 81/93] block: Generalise and optimise COR serialisati
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 81/93] block: Generalise and optimise COR serialisation |
Date: |
Fri, 24 Jan 2014 18:22:04 +0100 |
Change the API so that specific requests can be marked serialising. Only
these requests are checked for overlaps then.
This means that during a Copy on Read operation, not all requests
overlapping other requests are serialised any more, but only those that
actually overlap with the specific COR request.
Also remove COR from function and variable names because this
functionality can be useful in other contexts.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Reviewed-by: Benoit Canet <address@hidden>
---
block.c | 48 ++++++++++++++++++++++++++++-------------------
include/block/block_int.h | 5 +++--
2 files changed, 32 insertions(+), 21 deletions(-)
diff --git a/block.c b/block.c
index 0a391bd..493c75f 100644
--- a/block.c
+++ b/block.c
@@ -2208,6 +2208,10 @@ int bdrv_commit_all(void)
*/
static void tracked_request_end(BdrvTrackedRequest *req)
{
+ if (req->serialising) {
+ req->bs->serialising_in_flight--;
+ }
+
QLIST_REMOVE(req, list);
qemu_co_queue_restart_all(&req->wait_queue);
}
@@ -2222,10 +2226,11 @@ static void tracked_request_begin(BdrvTrackedRequest
*req,
{
*req = (BdrvTrackedRequest){
.bs = bs,
- .offset = offset,
- .bytes = bytes,
- .is_write = is_write,
- .co = qemu_coroutine_self(),
+ .offset = offset,
+ .bytes = bytes,
+ .is_write = is_write,
+ .co = qemu_coroutine_self(),
+ .serialising = false,
};
qemu_co_queue_init(&req->wait_queue);
@@ -2233,6 +2238,14 @@ static void tracked_request_begin(BdrvTrackedRequest
*req,
QLIST_INSERT_HEAD(&bs->tracked_requests, req, list);
}
+static void mark_request_serialising(BdrvTrackedRequest *req)
+{
+ if (!req->serialising) {
+ req->bs->serialising_in_flight++;
+ req->serialising = true;
+ }
+}
+
/**
* Round a region to cluster boundaries
*/
@@ -2285,26 +2298,31 @@ static bool tracked_request_overlaps(BdrvTrackedRequest
*req,
return true;
}
-static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs,
- BdrvTrackedRequest *self, int64_t offset, unsigned int bytes)
+static void coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self)
{
+ BlockDriverState *bs = self->bs;
BdrvTrackedRequest *req;
int64_t cluster_offset;
unsigned int cluster_bytes;
bool retry;
+ if (!bs->serialising_in_flight) {
+ return;
+ }
+
/* If we touch the same cluster it counts as an overlap. This guarantees
* that allocating writes will be serialized and not race with each other
* for the same cluster. For example, in copy-on-read it ensures that the
* CoR read and write operations are atomic and guest writes cannot
* interleave between them.
*/
- round_bytes_to_clusters(bs, offset, bytes, &cluster_offset,
&cluster_bytes);
+ round_bytes_to_clusters(bs, self->offset, self->bytes,
+ &cluster_offset, &cluster_bytes);
do {
retry = false;
QLIST_FOREACH(req, &bs->tracked_requests, list) {
- if (req == self) {
+ if (req == self || (!req->serialising && !self->serialising)) {
continue;
}
if (tracked_request_overlaps(req, cluster_offset, cluster_bytes)) {
@@ -2923,12 +2941,10 @@ static int coroutine_fn
bdrv_aligned_preadv(BlockDriverState *bs,
/* Handle Copy on Read and associated serialisation */
if (flags & BDRV_REQ_COPY_ON_READ) {
- bs->copy_on_read_in_flight++;
+ mark_request_serialising(req);
}
- if (bs->copy_on_read_in_flight) {
- wait_for_overlapping_requests(bs, req, offset, bytes);
- }
+ wait_serialising_requests(req);
if (flags & BDRV_REQ_COPY_ON_READ) {
int pnum;
@@ -2977,10 +2993,6 @@ static int coroutine_fn
bdrv_aligned_preadv(BlockDriverState *bs,
}
out:
- if (flags & BDRV_REQ_COPY_ON_READ) {
- bs->copy_on_read_in_flight--;
- }
-
return ret;
}
@@ -3179,9 +3191,7 @@ static int coroutine_fn
bdrv_aligned_pwritev(BlockDriverState *bs,
assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
- if (bs->copy_on_read_in_flight) {
- wait_for_overlapping_requests(bs, req, offset, bytes);
- }
+ wait_serialising_requests(req);
ret = notifier_with_return_list_notify(&bs->before_write_notifiers, req);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index bcdd98c..c1153cb 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -60,6 +60,7 @@ typedef struct BdrvTrackedRequest {
int64_t offset;
unsigned int bytes;
bool is_write;
+ bool serialising;
QLIST_ENTRY(BdrvTrackedRequest) list;
Coroutine *co; /* owner, used for deadlock detection */
CoQueue wait_queue; /* coroutines blocked on this request */
@@ -302,8 +303,8 @@ struct BlockDriverState {
/* Callback before write request is processed */
NotifierWithReturnList before_write_notifiers;
- /* number of in-flight copy-on-read requests */
- unsigned int copy_on_read_in_flight;
+ /* number of in-flight serialising requests */
+ unsigned int serialising_in_flight;
/* I/O throttling */
ThrottleState throttle_state;
--
1.8.1.4
- [Qemu-devel] [PULL 66/93] block: Inherit opt_transfer_length, (continued)
- [Qemu-devel] [PULL 66/93] block: Inherit opt_transfer_length, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 68/93] qemu_memalign: Allow small alignments, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 67/93] block: Update BlockLimits when they might have changed, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 69/93] block: Detect unaligned length in bdrv_qiov_is_aligned(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 70/93] block: Don't use guest sector size for qemu_blockalign(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 76/93] block: write: Handle COR dependency after I/O throttling, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 77/93] block: Introduce bdrv_co_do_pwritev(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 78/93] block: Switch BdrvTrackedRequest to byte granularity, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 79/93] block: Allow waiting for overlapping requests between begin/end, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 80/93] block: Make zero-after-EOF work with larger alignment, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 81/93] block: Generalise and optimise COR serialisation,
Kevin Wolf <=
- [Qemu-devel] [PULL 82/93] block: Make overlap range for serialisation dynamic, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 83/93] block: Allow wait_serialising_requests() at any point, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 84/93] block: Align requests in bdrv_co_do_pwritev(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 85/93] block: Assert serialisation assumptions in pwritev, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 86/93] block: Change coroutine wrapper to byte granularity, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 87/93] block: Make bdrv_pread() a bdrv_prwv_co() wrapper, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 88/93] block: Make bdrv_pwrite() a bdrv_prwv_co() wrapper, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 89/93] iscsi: Set bs->request_alignment, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 90/93] blkdebug: Make required alignment configurable, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 92/93] qemu-iotests: Test pwritev RMW logic, Kevin Wolf, 2014/01/24