mirror of https://github.com/xemu-project/xemu.git
block/block-copy: add memory limit
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 <vsementsov@virtuozzo.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-id: 20191022111805.3432-6-vsementsov@virtuozzo.com Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
f16ba00de9
commit
7f739d0e53
|
@ -21,6 +21,7 @@
|
||||||
#include "qemu/units.h"
|
#include "qemu/units.h"
|
||||||
|
|
||||||
#define BLOCK_COPY_MAX_COPY_RANGE (16 * MiB)
|
#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,
|
static void coroutine_fn block_copy_wait_inflight_reqs(BlockCopyState *s,
|
||||||
int64_t start,
|
int64_t start,
|
||||||
|
@ -64,6 +65,7 @@ void block_copy_state_free(BlockCopyState *s)
|
||||||
}
|
}
|
||||||
|
|
||||||
bdrv_release_dirty_bitmap(s->copy_bitmap);
|
bdrv_release_dirty_bitmap(s->copy_bitmap);
|
||||||
|
shres_destroy(s->mem);
|
||||||
g_free(s);
|
g_free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +97,7 @@ BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
|
||||||
.cluster_size = cluster_size,
|
.cluster_size = cluster_size,
|
||||||
.len = bdrv_dirty_bitmap_size(copy_bitmap),
|
.len = bdrv_dirty_bitmap_size(copy_bitmap),
|
||||||
.write_flags = write_flags,
|
.write_flags = write_flags,
|
||||||
|
.mem = shres_create(BLOCK_COPY_MAX_MEM),
|
||||||
};
|
};
|
||||||
|
|
||||||
s->copy_range_size = QEMU_ALIGN_DOWN(max_transfer, cluster_size),
|
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);
|
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);
|
ret = block_copy_do_copy(s, start, chunk_end, error_is_read);
|
||||||
|
co_put_to_shres(s->mem, chunk_end - start);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
bdrv_set_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
|
bdrv_set_dirty_bitmap(s->copy_bitmap, start, chunk_end - start);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#define BLOCK_COPY_H
|
#define BLOCK_COPY_H
|
||||||
|
|
||||||
#include "block/block.h"
|
#include "block/block.h"
|
||||||
|
#include "qemu/co-shared-resource.h"
|
||||||
|
|
||||||
typedef struct BlockCopyInFlightReq {
|
typedef struct BlockCopyInFlightReq {
|
||||||
int64_t start_byte;
|
int64_t start_byte;
|
||||||
|
@ -69,6 +70,8 @@ typedef struct BlockCopyState {
|
||||||
*/
|
*/
|
||||||
ProgressResetCallbackFunc progress_reset_callback;
|
ProgressResetCallbackFunc progress_reset_callback;
|
||||||
void *progress_opaque;
|
void *progress_opaque;
|
||||||
|
|
||||||
|
SharedResource *mem;
|
||||||
} BlockCopyState;
|
} BlockCopyState;
|
||||||
|
|
||||||
BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
|
BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
|
||||||
|
|
Loading…
Reference in New Issue