diff --git a/0039-xen_disk-Avoid-repeated-memory-allo.patch b/0039-xen_disk-Avoid-repeated-memory-allo.patch new file mode 100644 index 00000000..499fbb1f --- /dev/null +++ b/0039-xen_disk-Avoid-repeated-memory-allo.patch @@ -0,0 +1,79 @@ +From f88c2f1b54da7a92420724189a6df37e6b3faed3 Mon Sep 17 00:00:00 2001 +From: Tim Smith +Date: Fri, 2 Nov 2018 10:01:09 +0000 +Subject: [PATCH] xen_disk: Avoid repeated memory allocation + +xen_disk currently allocates memory to hold the data for each ioreq +as that ioreq is used, and frees it afterwards. Because it requires +page-aligned blocks, this interacts poorly with non-page-aligned +allocations and balloons the heap. + +Instead, allocate the maximum possible requirement, which is +BLKIF_MAX_SEGMENTS_PER_REQUEST pages (currently 11 pages) when +the ioreq is created, and keep that allocation until it is destroyed. +Since the ioreqs themselves are re-used via a free list, this +should actually improve memory usage. + +Signed-off-by: Tim Smith +[BSC#1100408] +Signed-off-by: Bruce Rogers +--- + hw/block/xen_disk.c | 7 ++----- + 1 file changed, 2 insertions(+), 5 deletions(-) + +diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c +index d9a55faf27..e9501ee34c 100644 +--- a/hw/block/xen_disk.c ++++ b/hw/block/xen_disk.c +@@ -110,7 +110,6 @@ static void ioreq_reset(struct ioreq *ioreq) + memset(&ioreq->req, 0, sizeof(ioreq->req)); + ioreq->status = 0; + ioreq->start = 0; +- ioreq->buf = NULL; + ioreq->size = 0; + ioreq->presync = 0; + +@@ -135,6 +134,7 @@ static struct ioreq *ioreq_start(struct XenBlkDev *blkdev) + /* allocate new struct */ + ioreq = g_malloc0(sizeof(*ioreq)); + ioreq->blkdev = blkdev; ++ ioreq->buf = qemu_memalign(XC_PAGE_SIZE, BLKIF_MAX_SEGMENTS_PER_REQUEST * XC_PAGE_SIZE); + blkdev->requests_total++; + qemu_iovec_init(&ioreq->v, 1); + } else { +@@ -317,14 +317,12 @@ static void qemu_aio_complete(void *opaque, int ret) + if (ret == 0) { + ioreq_grant_copy(ioreq); + } +- qemu_vfree(ioreq->buf); + break; + case BLKIF_OP_WRITE: + case BLKIF_OP_FLUSH_DISKCACHE: + if (!ioreq->req.nr_segments) { + break; + } +- qemu_vfree(ioreq->buf); + break; + default: + break; +@@ -392,12 +390,10 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) + { + struct XenBlkDev *blkdev = ioreq->blkdev; + +- ioreq->buf = qemu_memalign(XC_PAGE_SIZE, ioreq->size); + if (ioreq->req.nr_segments && + (ioreq->req.operation == BLKIF_OP_WRITE || + ioreq->req.operation == BLKIF_OP_FLUSH_DISKCACHE) && + ioreq_grant_copy(ioreq)) { +- qemu_vfree(ioreq->buf); + goto err; + } + +@@ -1007,6 +1003,7 @@ static int blk_free(struct XenDevice *xendev) + ioreq = QLIST_FIRST(&blkdev->freelist); + QLIST_REMOVE(ioreq, list); + qemu_iovec_destroy(&ioreq->v); ++ qemu_vfree(ioreq->buf); + g_free(ioreq); + } + diff --git a/qemu-linux-user.changes b/qemu-linux-user.changes index 8ee43ab1..bb3487a5 100644 --- a/qemu-linux-user.changes +++ b/qemu-linux-user.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Wed Dec 12 21:33:15 UTC 2018 - Bruce Rogers + +- Patch queue updated from git://github.com/openSUSE/qemu.git opensuse-3.1 +* Patches added: + 0039-xen_disk-Avoid-repeated-memory-allo.patch + ------------------------------------------------------------------- Tue Dec 11 17:38:47 UTC 2018 - Bruce Rogers diff --git a/qemu-linux-user.spec b/qemu-linux-user.spec index 740ea88d..56f931ba 100644 --- a/qemu-linux-user.spec +++ b/qemu-linux-user.spec @@ -70,6 +70,7 @@ Patch0035: 0035-tests-test-thread-pool-is-racy-add-.patch Patch0036: 0036-xen-add-block-resize-support-for-xe.patch Patch0037: 0037-tests-qemu-iotests-Triple-timeout-o.patch Patch0038: 0038-tests-block-io-test-130-needs-some-.patch +Patch0039: 0039-xen_disk-Avoid-repeated-memory-allo.patch # Please do not add QEMU patches manually here. # Run update_git.sh to regenerate this queue. ExcludeArch: s390 @@ -139,6 +140,7 @@ syscall layer occurs on the native hardware and operating system. %patch0036 -p1 %patch0037 -p1 %patch0038 -p1 +%patch0039 -p1 %build ./configure \ diff --git a/qemu-testsuite.changes b/qemu-testsuite.changes index c17c894f..92c7eb72 100644 --- a/qemu-testsuite.changes +++ b/qemu-testsuite.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Wed Dec 12 21:33:13 UTC 2018 - Bruce Rogers + +- fix memory leak in xen_disk (bsc#1100408) + 0039-xen_disk-Avoid-repeated-memory-allo.patch +- Patch queue updated from git://github.com/openSUSE/qemu.git opensuse-3.1 + ------------------------------------------------------------------- Wed Dec 12 09:31:20 UTC 2018 - olaf@aepfle.de diff --git a/qemu-testsuite.spec b/qemu-testsuite.spec index 953daf86..c1a02cfe 100644 --- a/qemu-testsuite.spec +++ b/qemu-testsuite.spec @@ -175,6 +175,7 @@ Patch0035: 0035-tests-test-thread-pool-is-racy-add-.patch Patch0036: 0036-xen-add-block-resize-support-for-xe.patch Patch0037: 0037-tests-qemu-iotests-Triple-timeout-o.patch Patch0038: 0038-tests-block-io-test-130-needs-some-.patch +Patch0039: 0039-xen_disk-Avoid-repeated-memory-allo.patch # Please do not add QEMU patches manually here. # Run update_git.sh to regenerate this queue. @@ -941,6 +942,7 @@ This package provides a service file for starting and stopping KSM. %patch0036 -p1 %patch0037 -p1 %patch0038 -p1 +%patch0039 -p1 pushd roms/seabios %patch1100 -p1 diff --git a/qemu.changes b/qemu.changes index c17c894f..92c7eb72 100644 --- a/qemu.changes +++ b/qemu.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Wed Dec 12 21:33:13 UTC 2018 - Bruce Rogers + +- fix memory leak in xen_disk (bsc#1100408) + 0039-xen_disk-Avoid-repeated-memory-allo.patch +- Patch queue updated from git://github.com/openSUSE/qemu.git opensuse-3.1 + ------------------------------------------------------------------- Wed Dec 12 09:31:20 UTC 2018 - olaf@aepfle.de diff --git a/qemu.spec b/qemu.spec index f7d55c44..acf81969 100644 --- a/qemu.spec +++ b/qemu.spec @@ -175,6 +175,7 @@ Patch0035: 0035-tests-test-thread-pool-is-racy-add-.patch Patch0036: 0036-xen-add-block-resize-support-for-xe.patch Patch0037: 0037-tests-qemu-iotests-Triple-timeout-o.patch Patch0038: 0038-tests-block-io-test-130-needs-some-.patch +Patch0039: 0039-xen_disk-Avoid-repeated-memory-allo.patch # Please do not add QEMU patches manually here. # Run update_git.sh to regenerate this queue. @@ -941,6 +942,7 @@ This package provides a service file for starting and stopping KSM. %patch0036 -p1 %patch0037 -p1 %patch0038 -p1 +%patch0039 -p1 pushd roms/seabios %patch1100 -p1