[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 40/69] block/block-copy: add memory limit
From: |
Max Reitz |
Subject: |
[PULL 40/69] block/block-copy: add memory limit |
Date: |
Mon, 28 Oct 2019 13:14:32 +0100 |
From: Vladimir Sementsov-Ogievskiy <address@hidden>
Currently total allocation for parallel requests to block-copy instance
is unlimited. Let's limit it to 128 MiB.
For now block-copy is used only in backup, so actually we limit total
allocation for backup job.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
include/block/block-copy.h | 3 +++
block/block-copy.c | 5 +++++
2 files changed, 8 insertions(+)
diff --git a/include/block/block-copy.h b/include/block/block-copy.h
index e2e135ff1b..edcdf0072d 100644
--- a/include/block/block-copy.h
+++ b/include/block/block-copy.h
@@ -16,6 +16,7 @@
#define BLOCK_COPY_H
#include "block/block.h"
+#include "qemu/co-shared-resource.h"
typedef struct BlockCopyInFlightReq {
int64_t start_byte;
@@ -69,6 +70,8 @@ typedef struct BlockCopyState {
*/
ProgressResetCallbackFunc progress_reset_callback;
void *progress_opaque;
+
+ SharedResource *mem;
} BlockCopyState;
BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
diff --git a/block/block-copy.c b/block/block-copy.c
index 845b2423dc..7f0ebb58f8 100644
--- a/block/block-copy.c
+++ b/block/block-copy.c
@@ -21,6 +21,7 @@
#include "qemu/units.h"
#define BLOCK_COPY_MAX_COPY_RANGE (16 * MiB)
+#define BLOCK_COPY_MAX_MEM (128 * MiB)
static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s,
int64_t start,
@@ -64,6 +65,7 @@ void block_copy_state_free(BlockCopyState *s)
}
bdrv_release_dirty_bitmap(s->copy_bitmap);
+ shres_destroy(s->mem);
g_free(s);
}
@@ -95,6 +97,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source,
BdrvChild *target,
.cluster_size = cluster_size,
.len = bdrv_dirty_bitmap_size(copy_bitmap),
.write_flags = write_flags,
+ .mem = shres_create(BLOCK_COPY_MAX_MEM),
};
s->copy_range_size = QEMU_ALIGN_DOWN(max_transfer, cluster_size),
@@ -313,7 +316,9 @@ int coroutine_fn block_copy(BlockCopyState *s,
bdrv_reset_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
+ co_get_from_shres(s->mem, chunk_end - start);
ret = block_copy_do_copy(s, start, chunk_end, error_is_read);
+ co_put_to_shres(s->mem, chunk_end - start);
if (ret < 0) {
bdrv_set_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
break;
--
2.21.0
- [PULL 31/69] iotests/222: Create socket in $SOCK_DIR, (continued)
- [PULL 31/69] iotests/222: Create socket in $SOCK_DIR, Max Reitz, 2019/10/28
- [PULL 29/69] iotests/208: Create socket in $SOCK_DIR, Max Reitz, 2019/10/28
- [PULL 32/69] iotests/223: Create socket in $SOCK_DIR, Max Reitz, 2019/10/28
- [PULL 35/69] iotests: Drop TEST_DIR filter from _filter_nbd, Max Reitz, 2019/10/28
- [PULL 34/69] iotests/267: Create socket in $SOCK_DIR, Max Reitz, 2019/10/28
- [PULL 33/69] iotests/240: Create socket in $SOCK_DIR, Max Reitz, 2019/10/28
- [PULL 36/69] block/block-copy: allocate buffer in block_copy_with_bounce_buffer, Max Reitz, 2019/10/28
- [PULL 37/69] block/block-copy: limit copy_range_size to 16 MiB, Max Reitz, 2019/10/28
- [PULL 38/69] block/block-copy: refactor copying, Max Reitz, 2019/10/28
- [PULL 39/69] util: introduce SharedResource, Max Reitz, 2019/10/28
- [PULL 40/69] block/block-copy: add memory limit,
Max Reitz <=
- [PULL 41/69] block/block-copy: increase buffered copy request, Max Reitz, 2019/10/28
- [PULL 42/69] block/nvme: add support for write zeros, Max Reitz, 2019/10/28
- [PULL 43/69] block/nvme: add support for discard, Max Reitz, 2019/10/28
- [PULL 44/69] mirror: Do not dereference invalid pointers, Max Reitz, 2019/10/28
- [PULL 45/69] include: Move endof() up from hw/virtio/virtio.h, Max Reitz, 2019/10/28
- [PULL 46/69] qcow2: Use endof(), Max Reitz, 2019/10/28
- [PULL 49/69] qcow2: Make qcow2_write_snapshots() public, Max Reitz, 2019/10/28
- [PULL 47/69] qcow2: Add Error ** to qcow2_read_snapshots(), Max Reitz, 2019/10/28
- [PULL 51/69] qcow2: Write v3-compliant snapshot list on upgrade, Max Reitz, 2019/10/28
- [PULL 50/69] qcow2: Put qcow2_upgrade() into its own function, Max Reitz, 2019/10/28