[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/17] qcow2: Don't round the L1 table allocation up to the sector
From: |
Max Reitz |
Subject: |
[PULL 11/17] qcow2: Don't round the L1 table allocation up to the sector size |
Date: |
Thu, 6 Feb 2020 13:51:26 +0100 |
From: Alberto Garcia <address@hidden>
The L1 table is read from disk using the byte-based bdrv_pread() and
is never accessed beyond its last element, so there's no need to
allocate more memory than that.
Signed-off-by: Alberto Garcia <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block/qcow2-cluster.c | 5 ++---
block/qcow2-refcount.c | 2 +-
block/qcow2-snapshot.c | 3 +--
block/qcow2.c | 2 +-
4 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index e9431f6785..0384fb2339 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -124,12 +124,11 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t
min_size,
#endif
new_l1_size2 = sizeof(uint64_t) * new_l1_size;
- new_l1_table = qemu_try_blockalign(bs->file->bs,
- ROUND_UP(new_l1_size2, 512));
+ new_l1_table = qemu_try_blockalign(bs->file->bs, new_l1_size2);
if (new_l1_table == NULL) {
return -ENOMEM;
}
- memset(new_l1_table, 0, ROUND_UP(new_l1_size2, 512));
+ memset(new_l1_table, 0, new_l1_size2);
if (s->l1_size) {
memcpy(new_l1_table, s->l1_table, s->l1_size * sizeof(uint64_t));
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index f67ac6b2d8..c963bc8de1 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -1262,7 +1262,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
* l1_table_offset when it is the current s->l1_table_offset! Be careful
* when changing this! */
if (l1_table_offset != s->l1_table_offset) {
- l1_table = g_try_malloc0(ROUND_UP(l1_size2, 512));
+ l1_table = g_try_malloc0(l1_size2);
if (l1_size2 && l1_table == NULL) {
ret = -ENOMEM;
goto fail;
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 5ab64da1ec..82c32d4c9b 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -1024,8 +1024,7 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs,
return ret;
}
new_l1_bytes = sn->l1_size * sizeof(uint64_t);
- new_l1_table = qemu_try_blockalign(bs->file->bs,
- ROUND_UP(new_l1_bytes, 512));
+ new_l1_table = qemu_try_blockalign(bs->file->bs, new_l1_bytes);
if (new_l1_table == NULL) {
return -ENOMEM;
}
diff --git a/block/qcow2.c b/block/qcow2.c
index e29fc07068..83db013814 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1491,7 +1491,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState
*bs, QDict *options,
if (s->l1_size > 0) {
s->l1_table = qemu_try_blockalign(bs->file->bs,
- ROUND_UP(s->l1_size * sizeof(uint64_t), 512));
+ s->l1_size * sizeof(uint64_t));
if (s->l1_table == NULL) {
error_setg(errp, "Could not allocate L1 table");
ret = -ENOMEM;
--
2.24.1
- [PULL 02/17] block: Use a GString in bdrv_perm_names(), (continued)
- [PULL 02/17] block: Use a GString in bdrv_perm_names(), Max Reitz, 2020/02/06
- [PULL 03/17] block: fix memleaks in bdrv_refresh_filename, Max Reitz, 2020/02/06
- [PULL 04/17] qcow2: Use a GString in report_unsupported_feature(), Max Reitz, 2020/02/06
- [PULL 05/17] iotests: remove 'linux' from default supported platforms, Max Reitz, 2020/02/06
- [PULL 06/17] iotests: Test 041 only works on certain systems, Max Reitz, 2020/02/06
- [PULL 07/17] iotests: Test 183 does not work on macOS and OpenBSD, Max Reitz, 2020/02/06
- [PULL 08/17] iotests: Check for the availability of the required devices in 267 and 127, Max Reitz, 2020/02/06
- [PULL 09/17] iotests: Skip Python-based tests if QEMU does not support virtio-blk, Max Reitz, 2020/02/06
- [PULL 10/17] iotests: Enable more tests in the 'auto' group to improve test coverage, Max Reitz, 2020/02/06
- [PULL 12/17] qcow2: Tighten cluster_offset alignment assertions, Max Reitz, 2020/02/06
- [PULL 11/17] qcow2: Don't round the L1 table allocation up to the sector size,
Max Reitz <=
- [PULL 13/17] qcow2: Use bs->bl.request_alignment when updating an L1 entry, Max Reitz, 2020/02/06
- [PULL 14/17] qcow2: Don't require aligned offsets in qcow2_co_copy_range_from(), Max Reitz, 2020/02/06
- [PULL 15/17] qcow2: Use BDRV_SECTOR_SIZE instead of the hardcoded value, Max Reitz, 2020/02/06
- [PULL 16/17] block/backup-top: fix failure path, Max Reitz, 2020/02/06
- [PULL 17/17] iotests: add test for backup-top failure on permission activation, Max Reitz, 2020/02/06
- Re: [PULL 00/17] Block patches, Peter Maydell, 2020/02/06