diff mbox series

[kvmtool,6/9] disk/aio: Fix AIO thread

Message ID 20190218130702.32575-7-jean-philippe.brucker@arm.com (mailing list archive)
State New, archived
Headers show
Series Disk fixes and AIO reset | expand

Commit Message

Jean-Philippe Brucker Feb. 18, 2019, 1:06 p.m. UTC
Currently when the kernel completes a batch of AIO requests and signals it
via eventfd, we retrieve at most AIO_MAX events (256), and ignore the
rest. Call io_getevents() again in case more events are pending.

Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
---
 disk/aio.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

Comments

Andre Przywara Feb. 22, 2019, 4:38 p.m. UTC | #1
On Mon, 18 Feb 2019 13:06:59 +0000
Jean-Philippe Brucker <jean-philippe.brucker@arm.com> wrote:

> Currently when the kernel completes a batch of AIO requests and signals it
> via eventfd, we retrieve at most AIO_MAX events (256), and ignore the
> rest. Call io_getevents() again in case more events are pending.

Did you encounter this case in a test or is this just theoretical?

But I am just curious, the patch looks alright:

> Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre.

> ---
>  disk/aio.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
> 
> diff --git a/disk/aio.c b/disk/aio.c
> index 007415c69..1fcf36857 100644
> --- a/disk/aio.c
> +++ b/disk/aio.c
> @@ -66,20 +66,31 @@ ssize_t raw_image__write_async(struct disk_image *disk, u64 sector,
>  			   offset, disk->evt, param);
>  }
>  
> -static void *disk_aio_thread(void *param)
> +static int disk_aio_get_events(struct disk_image *disk)
>  {
> -	struct disk_image *disk = param;
>  	struct io_event event[AIO_MAX];
>  	struct timespec notime = {0};
>  	int nr, i;
> +
> +	do {
> +		nr = io_getevents(disk->ctx, 1, ARRAY_SIZE(event), event, &notime);
> +		for (i = 0; i < nr; i++)
> +			disk->disk_req_cb(event[i].data, event[i].res);
> +	} while (nr > 0);
> +
> +	return 0;
> +}
> +
> +static void *disk_aio_thread(void *param)
> +{
> +	struct disk_image *disk = param;
>  	u64 dummy;
>  
>  	kvm__set_thread_name("disk-image-io");
>  
>  	while (read(disk->evt, &dummy, sizeof(dummy)) > 0) {
> -		nr = io_getevents(disk->ctx, 1, ARRAY_SIZE(event), event, &notime);
> -		for (i = 0; i < nr; i++)
> -			disk->disk_req_cb(event[i].data, event[i].res);
> +		if (disk_aio_get_events(disk))
> +			break;
>  	}
>  
>  	return NULL;
Jean-Philippe Brucker Feb. 22, 2019, 6:28 p.m. UTC | #2
On 22/02/2019 16:38, Andre Przywara wrote:
> On Mon, 18 Feb 2019 13:06:59 +0000
> Jean-Philippe Brucker <jean-philippe.brucker@arm.com> wrote:
> 
>> Currently when the kernel completes a batch of AIO requests and signals it
>> via eventfd, we retrieve at most AIO_MAX events (256), and ignore the
>> rest. Call io_getevents() again in case more events are pending.
> 
> Did you encounter this case in a test or is this just theoretical?

Only with a standalone test that exercised disk/aio.c. Through a guest
it doesn't seems possible, since the virtio-blk queue currently has 256
slots (VIRTIO_BLK_QUEUE_SIZE), meaning at most 256 in-flight requests.
That's currently equal to AIO_MAX, but it can easily be overlooked by
someone changing one of the constants.

> But I am just curious, the patch looks alright:
> 
>> Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
> 
> Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Thanks!
Jean
diff mbox series

Patch

diff --git a/disk/aio.c b/disk/aio.c
index 007415c69..1fcf36857 100644
--- a/disk/aio.c
+++ b/disk/aio.c
@@ -66,20 +66,31 @@  ssize_t raw_image__write_async(struct disk_image *disk, u64 sector,
 			   offset, disk->evt, param);
 }
 
-static void *disk_aio_thread(void *param)
+static int disk_aio_get_events(struct disk_image *disk)
 {
-	struct disk_image *disk = param;
 	struct io_event event[AIO_MAX];
 	struct timespec notime = {0};
 	int nr, i;
+
+	do {
+		nr = io_getevents(disk->ctx, 1, ARRAY_SIZE(event), event, &notime);
+		for (i = 0; i < nr; i++)
+			disk->disk_req_cb(event[i].data, event[i].res);
+	} while (nr > 0);
+
+	return 0;
+}
+
+static void *disk_aio_thread(void *param)
+{
+	struct disk_image *disk = param;
 	u64 dummy;
 
 	kvm__set_thread_name("disk-image-io");
 
 	while (read(disk->evt, &dummy, sizeof(dummy)) > 0) {
-		nr = io_getevents(disk->ctx, 1, ARRAY_SIZE(event), event, &notime);
-		for (i = 0; i < nr; i++)
-			disk->disk_req_cb(event[i].data, event[i].res);
+		if (disk_aio_get_events(disk))
+			break;
 	}
 
 	return NULL;