sel4vmmplatsupport: increase buffer in load_image Larger sized calls to read can lead to better loading performance if the underlying read implementation has high overhead for each call performed.
diff --git a/libsel4vmmplatsupport/src/arch/arm/guest_image.c b/libsel4vmmplatsupport/src/arch/arm/guest_image.c index 3ee8d0e..cfb8547 100644 --- a/libsel4vmmplatsupport/src/arch/arm/guest_image.c +++ b/libsel4vmmplatsupport/src/arch/arm/guest_image.c
@@ -164,11 +164,24 @@ ZF_LOGE("Error: Unable to find image \'%s\'", image_name); return -1; } - char buf[PAGE_SIZE_4K] = {0}; + + /* Try and load the image 1MiB at a time. Reduce the size by half if + * there isn't enough memory available. The total loading time may be + * faster if a larger buffer is used as it allows for more batching. + */ + size_t read_size = BIT(20); + char *buf = malloc(read_size); + while (buf == NULL) { + read_size /= 2; + if (read_size < 4096) { + ZF_LOGE("Not enough memory for copy buffer"); + } + buf = malloc(read_size); + } size_t offset = 0; while (1) { /* Load the image */ - len = read(fd, buf, sizeof(buf)); + len = read(fd, buf, read_size); if (!len) { break; } @@ -181,6 +194,7 @@ } offset += len; } + free(buf); *resulting_image_size = offset; close(fd); return 0;