Skip to contentSkip to conversation

qcow2: allocate cluster_cache/cluster_data on demand

PATCH Superseded Stefan Hajnoczi 4 participants 10 messages Aug 18, 2017 – Aug 31, 2017 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qcow2: allocate cluster_cache/cluster_data on demand

Most qcow2 files are uncompressed so it is wasteful to allocate (32 + 1)
* cluster_size + 512 bytes upfront. Allocate s->cluster_cache and s->cluster_data when the first read operation is performance on a compressed cluster.

The buffers are freed in .bdrv_close(). .bdrv_open() no longer has any code paths that can allocate these buffers, so remove the free functions in the error code path.

---
Alexey: Does this improve your memory profiling results?

 block/qcow2-cluster.c | 17 +++++++++++++++++
 block/qcow2.c         | 12 ------------
 2 files changed, 17 insertions(+), 12 deletions(-)
block/qcow2-cluster.c +17 -0
index f06c08f64c..c47600a44e 100644
@@ -1516,6 +1516,23 @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
         nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1;
         sector_offset = coffset & 511;
         csize = nb_csectors * 512 - sector_offset;
+
+        /* Allocate buffers on first decompress operation, most images are
+         * uncompressed and the memory overhead can be avoided.  The buffers
+         * are freed in .bdrv_close().
+         */
+        if (!s->cluster_data) {
+            /* one more sector for decompressed data alignment */
+            s->cluster_data = qemu_try_blockalign(bs->file->bs,
+                    QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512);
+            if (!s->cluster_data) {
+                return -EIO;
+            }
+        }
+        if (!s->cluster_cache) {
+            s->cluster_cache = g_malloc(s->cluster_size);
+        }
+
         BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED);
         ret = bdrv_read(bs->file, coffset >> 9, s->cluster_data,
                         nb_csectors);
block/qcow2.c +0 -12
index 40ba26c111..0ac201910a 100644
@@ -1360,16 +1360,6 @@ static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags,
         goto fail;
     }
 
-    s->cluster_cache = g_malloc(s->cluster_size);
-    /* one more sector for decompressed data alignment */
-    s->cluster_data = qemu_try_blockalign(bs->file->bs, QCOW_MAX_CRYPT_CLUSTERS
-                                                    * s->cluster_size + 512);
-    if (s->cluster_data == NULL) {
-        error_setg(errp, "Could not allocate temporary cluster buffer");
-        ret = -ENOMEM;
-        goto fail;
-    }
-
     s->cluster_cache_offset = -1;
     s->flags = flags;
 
@@ -1507,8 +1497,6 @@ static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags,
     if (s->refcount_block_cache) {
         qcow2_cache_destroy(bs, s->refcount_block_cache);
     }
-    g_free(s->cluster_cache);
-    qemu_vfree(s->cluster_data);
     qcrypto_block_free(s->crypto);
     qapi_free_QCryptoBlockOpenOptions(s->crypto_opts);
     return ret;
Signature · 1 line
2.13.4
#1 lore raw
Quoted 9 lines · Stefan Hajnoczi

Most qcow2 files are uncompressed so it is wasteful to allocate (32 + 1)
* cluster_size + 512 bytes upfront. Allocate s->cluster_cache and s->cluster_data when the first read operation is performance on a compressed cluster.

The buffers are freed in .bdrv_close(). .bdrv_open() no longer has any code paths that can allocate these buffers, so remove the free functions in the error code path.

Quoted 5 lines

---
Alexey: Does this improve your memory profiling results?

Is this a regression from earlier versions? Likely, it is NOT -rc4 material, and thus can wait for 2.11; but it should be fine for -stable as part of 2.10.1 down the road.

Quoted 6 lines

+++ b/block/qcow2-cluster.c

block/qcow2-cluster.c +1 -0
@@ -1516,6 +1516,23 @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
         nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1;
         sector_offset = coffset & 511;
         csize = nb_csectors * 512 - sector_offset;
+

block/qcow2-cluster.c int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) · line 1529

Quoted 10 lines
block/qcow2-cluster.c +10 -0
+        /* Allocate buffers on first decompress operation, most images are
+         * uncompressed and the memory overhead can be avoided.  The buffers
+         * are freed in .bdrv_close().
+         */
+        if (!s->cluster_data) {
+            /* one more sector for decompressed data alignment */
+            s->cluster_data = qemu_try_blockalign(bs->file->bs,
+                    QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512);
+            if (!s->cluster_data) {
+                return -EIO;

Is -ENOMEM any better than -EIO here?

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Tested-by on v1 1/1
#9 lore raw
In reply to Stefan Hajnoczi
Quoted 9 lines · Stefan Hajnoczi

Most qcow2 files are uncompressed so it is wasteful to allocate (32 + 1)
* cluster_size + 512 bytes upfront. Allocate s->cluster_cache and s->cluster_data when the first read operation is performance on a compressed cluster.

The buffers are freed in .bdrv_close(). .bdrv_open() no longer has any code paths that can allocate these buffers, so remove the free functions in the error code path.

Quoted 5 lines

---
Alexey: Does this improve your memory profiling results?

Yes, it does:

was:
12.81% (1,023,193,088B)
now:
05.36% (393,893,888B)

Quoted 63 lines
 block/qcow2-cluster.c | 17 +++++++++++++++++
 block/qcow2.c         | 12 ------------
 2 files changed, 17 insertions(+), 12 deletions(-)
block/qcow2-cluster.c +17 -0
index f06c08f64c..c47600a44e 100644
@@ -1516,6 +1516,23 @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
         nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1;
         sector_offset = coffset & 511;
         csize = nb_csectors * 512 - sector_offset;
+
+        /* Allocate buffers on first decompress operation, most images are
+         * uncompressed and the memory overhead can be avoided.  The buffers
+         * are freed in .bdrv_close().
+         */
+        if (!s->cluster_data) {
+            /* one more sector for decompressed data alignment */
+            s->cluster_data = qemu_try_blockalign(bs->file->bs,
+                    QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512);
+            if (!s->cluster_data) {
+                return -EIO;
+            }
+        }
+        if (!s->cluster_cache) {
+            s->cluster_cache = g_malloc(s->cluster_size);
+        }
+
         BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED);
         ret = bdrv_read(bs->file, coffset >> 9, s->cluster_data,
                         nb_csectors);
block/qcow2.c +0 -12
index 40ba26c111..0ac201910a 100644
@@ -1360,16 +1360,6 @@ static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags,
         goto fail;
     }
 
-    s->cluster_cache = g_malloc(s->cluster_size);
-    /* one more sector for decompressed data alignment */
-    s->cluster_data = qemu_try_blockalign(bs->file->bs, QCOW_MAX_CRYPT_CLUSTERS
-                                                    * s->cluster_size + 512);
-    if (s->cluster_data == NULL) {
-        error_setg(errp, "Could not allocate temporary cluster buffer");
-        ret = -ENOMEM;
-        goto fail;
-    }
-
     s->cluster_cache_offset = -1;
     s->flags = flags;
 
@@ -1507,8 +1497,6 @@ static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags,
     if (s->refcount_block_cache) {
         qcow2_cache_destroy(bs, s->refcount_block_cache);
     }
-    g_free(s->cluster_cache);
-    qemu_vfree(s->cluster_data);
     qcrypto_block_free(s->crypto);
     qapi_free_QCryptoBlockOpenOptions(s->crypto_opts);
     return ret;
Signature · 1 line
Alexey
#2 lore raw
In reply to Eric Blake
Quoted 10 lines · Eric Blake
Quoted 9 lines · Stefan Hajnoczi

Most qcow2 files are uncompressed so it is wasteful to allocate (32 + 1)
* cluster_size + 512 bytes upfront. Allocate s->cluster_cache and s->cluster_data when the first read operation is performance on a compressed cluster.

The buffers are freed in .bdrv_close(). .bdrv_open() no longer has any code paths that can allocate these buffers, so remove the free functions in the error code path.

Quoted 7 lines
Quoted 5 lines

---
Alexey: Does this improve your memory profiling results?

Is this a regression from earlier versions?

Hm, I have not thought about this.

So. I did bisect and this started happening from
9a4c0e220d8a4f82b5665d0ee95ef94d8e1509d5
"hw/virtio-pci: fix virtio behaviour"

Before that, the very same command line would take less than 1GB of resident memory. That thing basically enforces virtio-1.0 for QEMU <=2.6 which means that upstream with "-machine pseries-2.6" works fine (less than 1GB), "-machine pseries-2.7" does not (close to 7GB, sometime even 9GB).

Then I tried bisecting again, with "scsi=off,disable-modern=off,disable-legacy=on" on my 150 virtio-block devices, started from
e266d421490e0 "virtio-pci: add flags to enable/disable legacy/modern" (it added the disable-modern switch) which uses 2GB of memory.

I ended up with ada434cd0b44 "virtio-pci: implement cfg capability".

Then I removed proxy->modern_as on v2.10.0-rc3 (see below) and got 1.5GB of used memory (yay!)

I do not really know how to reinterpret all of this, do you?

Note: 1GB..9GB numbers from below are the peak values from valgrind's massif. This is pretty much resident memory used by QEMU process. In my testing I did not enable KVM and I did not start the guest (i.e. used -S). 150 virtio-block devices, 2GB RAM for the guest.

Also, while bisecting, I only paid attention if it is 1..2GB or 6..9GB - all tests did fit these 2 ranges, for any given sha1 the amount of memory would be stable but among "good" commits it could change between 1GB and 2GB.

hw/virtio/virtio-pci.c +0 -0
index 5d14bd6..7ad447a 100644
@@ -1783,6 +1783,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev,

Error **errp)

                        /* PCI BAR regions must be powers of 2 */
                        pow2ceil(proxy->notify.offset + proxy->notify.size));

+#if 0

     memory_region_init_alias(&proxy->modern_cfg,
                              OBJECT(proxy),
                              "virtio-pci-cfg",
@@ -1791,7 +1792,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev,
Error **errp)
                              memory_region_size(&proxy->modern_bar));

     address_space_init(&proxy->modern_as, &proxy->modern_cfg,
"virtio-pci-cfg-as");
-
+#endif
     if (proxy->disable_legacy == ON_OFF_AUTO_AUTO) {
         proxy->disable_legacy = pcie_port ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
     }

@@ -1860,10 +1861,10 @@ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp)

static void virtio_pci_exit(PCIDevice *pci_dev)
{
- VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
+ //VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);

     msix_uninit_exclusive_bar(pci_dev);

- address_space_destroy(&proxy->modern_as);
+ //address_space_destroy(&proxy->modern_as);
}

static void virtio_pci_reset(DeviceState *qdev)

Quoted 23 lines

Likely, it is NOT -rc4
material, and thus can wait for 2.11; but it should be fine for -stable as part of 2.10.1 down the road.

Quoted 6 lines

+++ b/block/qcow2-cluster.c

(quoted diff) +1 -0
@@ -1516,6 +1516,23 @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
         nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1;
         sector_offset = coffset & 511;
         csize = nb_csectors * 512 - sector_offset;
+

Review int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) · line 1529

Quoted 10 lines
(quoted diff) +10 -0
+        /* Allocate buffers on first decompress operation, most images are
+         * uncompressed and the memory overhead can be avoided.  The buffers
+         * are freed in .bdrv_close().
+         */
+        if (!s->cluster_data) {
+            /* one more sector for decompressed data alignment */
+            s->cluster_data = qemu_try_blockalign(bs->file->bs,
+                    QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512);
+            if (!s->cluster_data) {
+                return -EIO;

Is -ENOMEM any better than -EIO here?

Signature · 1 line
Alexey
#3 lore raw
Quoted 38 lines · Alexey Kardashevskiy
Quoted 10 lines · Eric Blake
Quoted 9 lines · Stefan Hajnoczi

Most qcow2 files are uncompressed so it is wasteful to allocate (32 + 1)
* cluster_size + 512 bytes upfront. Allocate s->cluster_cache and s->cluster_data when the first read operation is performance on a compressed cluster.

The buffers are freed in .bdrv_close(). .bdrv_open() no longer has any code paths that can allocate these buffers, so remove the free functions in the error code path.

Quoted 7 lines
Quoted 5 lines

---
Alexey: Does this improve your memory profiling results?

Is this a regression from earlier versions?

Hm, I have not thought about this.

So. I did bisect and this started happening from
9a4c0e220d8a4f82b5665d0ee95ef94d8e1509d5
"hw/virtio-pci: fix virtio behaviour"

Before that, the very same command line would take less than 1GB of resident memory. That thing basically enforces virtio-1.0 for QEMU <=2.6 which means that upstream with "-machine pseries-2.6" works fine (less than 1GB), "-machine pseries-2.7" does not (close to 7GB, sometime even 9GB).

Then I tried bisecting again, with "scsi=off,disable-modern=off,disable-legacy=on" on my 150 virtio-block devices, started from
e266d421490e0 "virtio-pci: add flags to enable/disable legacy/modern" (it added the disable-modern switch) which uses 2GB of memory.

I ended up with ada434cd0b44 "virtio-pci: implement cfg capability".

Quoted 7 lines

Then I removed proxy->modern_as on v2.10.0-rc3 (see below) and got 1.5GB of used memory (yay!)

I do not really know how to reinterpret all of this, do you?

Note: 1GB..9GB numbers from below are the peak values from valgrind's

s/from below/from above/ , sorry, bad cut-n-paste :)

Signature · 1 line
Alexey
#4 lore raw
Quoted 42 lines · Alexey Kardashevskiy
Quoted 41 lines · Alexey Kardashevskiy
Quoted 10 lines · Eric Blake
Quoted 9 lines · Stefan Hajnoczi

Most qcow2 files are uncompressed so it is wasteful to allocate (32 + 1)
* cluster_size + 512 bytes upfront. Allocate s->cluster_cache and s->cluster_data when the first read operation is performance on a compressed cluster.

The buffers are freed in .bdrv_close(). .bdrv_open() no longer has any code paths that can allocate these buffers, so remove the free functions in the error code path.

Quoted 7 lines
Quoted 5 lines

---
Alexey: Does this improve your memory profiling results?

Is this a regression from earlier versions?

Hm, I have not thought about this.

So. I did bisect and this started happening from
9a4c0e220d8a4f82b5665d0ee95ef94d8e1509d5
"hw/virtio-pci: fix virtio behaviour"

Before that, the very same command line would take less than 1GB of resident memory. That thing basically enforces virtio-1.0 for QEMU <=2.6 which means that upstream with "-machine pseries-2.6" works fine (less than 1GB), "-machine pseries-2.7" does not (close to 7GB, sometime even 9GB).

Then I tried bisecting again, with "scsi=off,disable-modern=off,disable-legacy=on" on my 150 virtio-block devices, started from
e266d421490e0 "virtio-pci: add flags to enable/disable legacy/modern" (it added the disable-modern switch) which uses 2GB of memory.

I ended up with ada434cd0b44 "virtio-pci: implement cfg capability".

Then I removed proxy->modern_as on v2.10.0-rc3 (see below) and got 1.5GB of used memory (yay!)

Quoted 6 lines
Quoted 4 lines

I do not really know how to reinterpret all of this, do you?

Note: 1GB..9GB numbers from below are the peak values from valgrind's

s/from below/from above/ , sorry, bad cut-n-paste :)

Just realized - I should have replied with this to "Memory use with >100 virtio devices" actually, sorry for the confusion.

Signature · 1 line
Alexey
#8 lore raw
In reply to Eric Blake
Quoted 16 lines · Eric Blake
Quoted 9 lines · Stefan Hajnoczi

Most qcow2 files are uncompressed so it is wasteful to allocate (32 + 1)
* cluster_size + 512 bytes upfront. Allocate s->cluster_cache and s->cluster_data when the first read operation is performance on a compressed cluster.

The buffers are freed in .bdrv_close(). .bdrv_open() no longer has any code paths that can allocate these buffers, so remove the free functions in the error code path.

Quoted 5 lines

---
Alexey: Does this improve your memory profiling results?

Quoted 3 lines

Is this a regression from earlier versions? Likely, it is NOT -rc4 material, and thus can wait for 2.11; but it should be fine for -stable as part of 2.10.1 down the road.

It's not a regression. s->cluster_data was always allocated upfront in .bdrv_open().

Quoted 10 lines
Quoted 10 lines

+++ b/block/qcow2-cluster.c

block/qcow2-cluster.c +5 -0
@@ -1516,6 +1516,23 @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
         nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1;
         sector_offset = coffset & 511;
         csize = nb_csectors * 512 - sector_offset;
+
+        /* Allocate buffers on first decompress operation, most images are
+         * uncompressed and the memory overhead can be avoided.  The buffers
+         * are freed in .bdrv_close().
+         */
Quoted 8 lines

block/qcow2-cluster.c int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) · line 1529

Quoted 6 lines
block/qcow2-cluster.c +6 -0
+        if (!s->cluster_data) {
+            /* one more sector for decompressed data alignment */
+            s->cluster_data = qemu_try_blockalign(bs->file->bs,
+                    QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512);
+            if (!s->cluster_data) {
+                return -EIO;

Is -ENOMEM any better than -EIO here?

There is another instance of -ENOMEM in qcow2.c so it seems reasonable to use the more specific ENOMEM error code.

I'll resend the patch.

Stefan

#5 lore raw
In reply to Alexey Kardashevskiy
Quoted 36 lines · Alexey Kardashevskiy
Quoted 10 lines · Eric Blake
Quoted 9 lines · Stefan Hajnoczi

Most qcow2 files are uncompressed so it is wasteful to allocate (32 + 1)
* cluster_size + 512 bytes upfront. Allocate s->cluster_cache and s->cluster_data when the first read operation is performance on a compressed cluster.

The buffers are freed in .bdrv_close(). .bdrv_open() no longer has any code paths that can allocate these buffers, so remove the free functions in the error code path.

Quoted 7 lines
Quoted 5 lines

---
Alexey: Does this improve your memory profiling results?

Is this a regression from earlier versions?

Hm, I have not thought about this.

So. I did bisect and this started happening from
9a4c0e220d8a4f82b5665d0ee95ef94d8e1509d5
"hw/virtio-pci: fix virtio behaviour"

Before that, the very same command line would take less than 1GB of resident memory. That thing basically enforces virtio-1.0 for QEMU <=2.6 which means that upstream with "-machine pseries-2.6" works fine (less than 1GB), "-machine pseries-2.7" does not (close to 7GB, sometime even 9GB).

Then I tried bisecting again, with "scsi=off,disable-modern=off,disable-legacy=on" on my 150 virtio-block devices, started from
e266d421490e0 "virtio-pci: add flags to enable/disable legacy/modern" (it added the disable-modern switch) which uses 2GB of memory.

Quoted 6 lines

I ended up with ada434cd0b44 "virtio-pci: implement cfg capability".

Then I removed proxy->modern_as on v2.10.0-rc3 (see below) and got 1.5GB of used memory (yay!)

I do not really know how to reinterpret all of this, do you?

Anyone, ping? Should I move the conversation to the original thread? Any hacks to try with libc?

Quoted 81 lines

Note: 1GB..9GB numbers from below are the peak values from valgrind's massif. This is pretty much resident memory used by QEMU process. In my testing I did not enable KVM and I did not start the guest (i.e. used -S). 150 virtio-block devices, 2GB RAM for the guest.

Also, while bisecting, I only paid attention if it is 1..2GB or 6..9GB - all tests did fit these 2 ranges, for any given sha1 the amount of memory would be stable but among "good" commits it could change between 1GB and 2GB.

hw/virtio/virtio-pci.c +1 -0
index 5d14bd6..7ad447a 100644
@@ -1783,6 +1783,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev,
 Error **errp)
                        /* PCI BAR regions must be powers of 2 */
                        pow2ceil(proxy->notify.offset + proxy->notify.size));
 
+#if 0
     memory_region_init_alias(&proxy->modern_cfg,
                              OBJECT(proxy),
                              "virtio-pci-cfg",
hw/virtio/virtio-pci.c +1 -1
@@ -1791,7 +1792,7 @@ static void virtio_pci_realize(PCIDevice *pci_dev,
 Error **errp)
                              memory_region_size(&proxy->modern_bar));
 
     address_space_init(&proxy->modern_as, &proxy->modern_cfg,
 "virtio-pci-cfg-as");
-
+#endif
     if (proxy->disable_legacy == ON_OFF_AUTO_AUTO) {
         proxy->disable_legacy = pcie_port ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF;
     }
hw/virtio/virtio-pci.c +2 -2
@@ -1860,10 +1861,10 @@ static void virtio_pci_realize(PCIDevice *pci_dev,
 Error **errp)
 
 static void virtio_pci_exit(PCIDevice *pci_dev)
 {
-    VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
+    //VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
 
     msix_uninit_exclusive_bar(pci_dev);
-    address_space_destroy(&proxy->modern_as);
+    //address_space_destroy(&proxy->modern_as);
 }
 

static void virtio_pci_reset(DeviceState *qdev)

Quoted 23 lines

Likely, it is NOT -rc4
material, and thus can wait for 2.11; but it should be fine for -stable as part of 2.10.1 down the road.

Quoted 6 lines

+++ b/block/qcow2-cluster.c

(quoted diff) +1 -0
@@ -1516,6 +1516,23 @@ int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
         nb_csectors = ((cluster_offset >> s->csize_shift) & s->csize_mask) + 1;
         sector_offset = coffset & 511;
         csize = nb_csectors * 512 - sector_offset;
+

Review int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) · line 1529

Quoted 10 lines
(quoted diff) +10 -0
+        /* Allocate buffers on first decompress operation, most images are
+         * uncompressed and the memory overhead can be avoided.  The buffers
+         * are freed in .bdrv_close().
+         */
+        if (!s->cluster_data) {
+            /* one more sector for decompressed data alignment */
+            s->cluster_data = qemu_try_blockalign(bs->file->bs,
+                    QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size + 512);
+            if (!s->cluster_data) {
+                return -EIO;

Is -ENOMEM any better than -EIO here?

Signature · 1 line
Alexey
#6 lore raw
Quoted 39 lines · Alexey Kardashevskiy
Quoted 38 lines · Alexey Kardashevskiy
Quoted 10 lines · Eric Blake
Quoted 9 lines · Stefan Hajnoczi

Most qcow2 files are uncompressed so it is wasteful to allocate (32 + 1)
* cluster_size + 512 bytes upfront. Allocate s->cluster_cache and s->cluster_data when the first read operation is performance on a compressed cluster.

The buffers are freed in .bdrv_close(). .bdrv_open() no longer has any code paths that can allocate these buffers, so remove the free functions in the error code path.

Quoted 7 lines
Quoted 5 lines

---
Alexey: Does this improve your memory profiling results?

Is this a regression from earlier versions?

Hm, I have not thought about this.

So. I did bisect and this started happening from
9a4c0e220d8a4f82b5665d0ee95ef94d8e1509d5
"hw/virtio-pci: fix virtio behaviour"

Before that, the very same command line would take less than 1GB of resident memory. That thing basically enforces virtio-1.0 for QEMU <=2.6 which means that upstream with "-machine pseries-2.6" works fine (less than 1GB), "-machine pseries-2.7" does not (close to 7GB, sometime even 9GB).

Then I tried bisecting again, with "scsi=off,disable-modern=off,disable-legacy=on" on my 150 virtio-block devices, started from
e266d421490e0 "virtio-pci: add flags to enable/disable legacy/modern" (it added the disable-modern switch) which uses 2GB of memory.

I ended up with ada434cd0b44 "virtio-pci: implement cfg capability".

Quoted 8 lines
Quoted 4 lines

Then I removed proxy->modern_as on v2.10.0-rc3 (see below) and got 1.5GB of used memory (yay!)

I do not really know how to reinterpret all of this, do you?

Anyone, ping? Should I move the conversation to the original thread? Any hacks to try with libc?

I suggest a new top-level thread with Michael Tsirkin CCed.

Stefan

#7 lore raw
Quoted 43 lines · Stefan Hajnoczi
Quoted 42 lines · Alexey Kardashevskiy
Quoted 41 lines · Alexey Kardashevskiy
Quoted 10 lines · Eric Blake
Quoted 9 lines · Stefan Hajnoczi

Most qcow2 files are uncompressed so it is wasteful to allocate (32 + 1)
* cluster_size + 512 bytes upfront. Allocate s->cluster_cache and s->cluster_data when the first read operation is performance on a compressed cluster.

The buffers are freed in .bdrv_close(). .bdrv_open() no longer has any code paths that can allocate these buffers, so remove the free functions in the error code path.

Quoted 7 lines
Quoted 5 lines

---
Alexey: Does this improve your memory profiling results?

Is this a regression from earlier versions?

Hm, I have not thought about this.

So. I did bisect and this started happening from
9a4c0e220d8a4f82b5665d0ee95ef94d8e1509d5
"hw/virtio-pci: fix virtio behaviour"

Before that, the very same command line would take less than 1GB of resident memory. That thing basically enforces virtio-1.0 for QEMU <=2.6 which means that upstream with "-machine pseries-2.6" works fine (less than 1GB), "-machine pseries-2.7" does not (close to 7GB, sometime even 9GB).

Then I tried bisecting again, with "scsi=off,disable-modern=off,disable-legacy=on" on my 150 virtio-block devices, started from
e266d421490e0 "virtio-pci: add flags to enable/disable legacy/modern" (it added the disable-modern switch) which uses 2GB of memory.

I ended up with ada434cd0b44 "virtio-pci: implement cfg capability".

Then I removed proxy->modern_as on v2.10.0-rc3 (see below) and got 1.5GB of used memory (yay!)

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I do not really know how to reinterpret all of this, do you?

Anyone, ping? Should I move the conversation to the original thread? Any hacks to try with libc?

I suggest a new top-level thread with Michael Tsirkin CCed.

I am continuing in the original "Memory use with >100 virtio devices" thread and the problem is more generic than virtio, it is just easier to reproduce it with virtio, that's all.

Signature · 1 line
Alexey