qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Alberto Garcia <berto@igalia.com>
Cc: qemu-block@nongnu.org, qemu-devel@nongnu.org,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 1/3] qcow2: mark the memory as no longer needed after qcow2_cache_empty()
Date: Tue, 2 Jun 2015 12:05:59 +0200	[thread overview]
Message-ID: <20150602100559.GI3765@noname.str.redhat.com> (raw)
In-Reply-To: <3587410bf941dc495ec4e41201d1d53a21f7e6fb.1432891306.git.berto@igalia.com>

Am 29.05.2015 um 11:24 hat Alberto Garcia geschrieben:
> After having emptied the cache, the data in the cache tables is no
> longer useful, so we can tell the kernel that we are done with it. In
> Linux this frees the resources associated with it.
> 
> The effect of this can be seen in the HMP commit operation: it moves
> data from the top to the base image (and fills both caches), then it
> empties the top image. At this point the data in that cache is no
> longer needed so it's just wasting memory.
> 
> Signed-off-by: Alberto Garcia <berto@igalia.com>
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/qcow2-cache.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
> index ed92a09..ed14a92 100644
> --- a/block/qcow2-cache.c
> +++ b/block/qcow2-cache.c
> @@ -22,8 +22,10 @@
>   * THE SOFTWARE.
>   */
>  
> +#include <sys/mman.h>
>  #include "block/block_int.h"
>  #include "qemu-common.h"
> +#include "qemu/osdep.h"
>  #include "qcow2.h"
>  #include "trace.h"

This breaks the mingw build:

/mnt/qemu/block/qcow2-cache.c:25:22: fatal error: sys/mman.h: No such file or directory
 #include <sys/mman.h>

> @@ -60,6 +62,22 @@ static inline int qcow2_cache_get_table_idx(BlockDriverState *bs,
>      return idx;
>  }
>  
> +static void qcow2_cache_table_release(BlockDriverState *bs, Qcow2Cache *c,
> +                                      int i, int num_tables)
> +{
> +#if QEMU_MADV_DONTNEED != QEMU_MADV_INVALID
> +    BDRVQcowState *s = bs->opaque;
> +    void *t = qcow2_cache_get_table_addr(bs, c, i);
> +    long align = sysconf(_SC_PAGESIZE);

It seems that getpagesize() is usually used in qemu.

> +    size_t mem_size = (size_t) s->cluster_size * num_tables;
> +    size_t offset = QEMU_ALIGN_UP((uintptr_t) t, align) - (uintptr_t) t;
> +    size_t length = QEMU_ALIGN_DOWN(mem_size - offset, align);

Instead of all the aligning here, shouldn't we just make sure that the
tables are created with the right alignment?

> +    if (length > 0) {
> +        qemu_madvise((uint8_t *) t + offset, length, QEMU_MADV_DONTNEED);
> +    }
> +#endif
> +}

Kevin

  reply	other threads:[~2015-06-02 10:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-29  9:24 [Qemu-devel] [PATCH v4 0/3] Clean unused entries in the qcow2 L2/refcount cache Alberto Garcia
2015-05-29  9:24 ` [Qemu-devel] [PATCH 1/3] qcow2: mark the memory as no longer needed after qcow2_cache_empty() Alberto Garcia
2015-06-02 10:05   ` Kevin Wolf [this message]
2015-06-02 10:50     ` Alberto Garcia
2015-06-02 10:56       ` Kevin Wolf
2015-06-02 11:08         ` Alberto Garcia
2015-05-29  9:24 ` [Qemu-devel] [PATCH 2/3] qcow2: add option to clean unused cache entries after some time Alberto Garcia
2015-06-02 11:04   ` Kevin Wolf
2015-05-29  9:24 ` [Qemu-devel] [PATCH 3/3] qcow2: reorder fields in Qcow2CachedTable to reduce padding Alberto Garcia
2015-06-02 11:07   ` Kevin Wolf
  -- strict thread matches above, loose matches on Subject: below --
2015-05-27  9:46 [Qemu-devel] [PATCH v3 0/3] Clean unused entries in the qcow2 L2/refcount cache Alberto Garcia
2015-05-27  9:46 ` [Qemu-devel] [PATCH 1/3] qcow2: mark the memory as no longer needed after qcow2_cache_empty() Alberto Garcia
2015-05-26 17:14 [Qemu-devel] [PATCH v2 0/3] Clean unused entries in the qcow2 L2/refcount cache Alberto Garcia
2015-05-26 17:14 ` [Qemu-devel] [PATCH 1/3] qcow2: mark the memory as no longer needed after qcow2_cache_empty() Alberto Garcia
2015-05-18 16:48 [Qemu-devel] [PATCH 0/3] Clean unused entries in the qcow2 L2/refcount cache Alberto Garcia
2015-05-18 16:48 ` [Qemu-devel] [PATCH 1/3] qcow2: mark the memory as no longer needed after qcow2_cache_empty() Alberto Garcia
2015-05-26 15:39   ` Max Reitz
2015-05-26 15:51     ` Alberto Garcia
2015-05-26 15:51       ` Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150602100559.GI3765@noname.str.redhat.com \
    --to=kwolf@redhat.com \
    --cc=berto@igalia.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).