[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v3 01/29] migrate: Update ram_block_discard_rang
From: |
Dr. David Alan Gilbert |
Subject: |
Re: [Qemu-devel] [PATCH v3 01/29] migrate: Update ram_block_discard_range for shared |
Date: |
Wed, 28 Feb 2018 19:54:03 +0000 |
User-agent: |
Mutt/1.9.2 (2017-12-15) |
* Peter Xu (address@hidden) wrote:
> On Fri, Feb 16, 2018 at 01:15:57PM +0000, Dr. David Alan Gilbert (git) wrote:
> > From: "Dr. David Alan Gilbert" <address@hidden>
> >
> > The choice of call to discard a block is getting more complicated
> > for other cases. We use fallocate PUNCH_HOLE in any file cases;
> > it works for both hugepage and for tmpfs.
> > We use the DONTNEED for non-hugepage cases either where they're
> > anonymous or where they're private.
> >
> > Care should be taken when trying other backing files.
> >
> > Signed-off-by: Dr. David Alan Gilbert <address@hidden>
> > ---
> > exec.c | 60
> > ++++++++++++++++++++++++++++++++++++++++++++++--------------
> > trace-events | 3 ++-
> > 2 files changed, 48 insertions(+), 15 deletions(-)
> >
> > diff --git a/exec.c b/exec.c
> > index e8d7b335b6..b1bb477776 100644
> > --- a/exec.c
> > +++ b/exec.c
> > @@ -3702,6 +3702,7 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t
> > start, size_t length)
> > }
> >
> > if ((start + length) <= rb->used_length) {
> > + bool need_madvise, need_fallocate;
> > uint8_t *host_endaddr = host_startaddr + length;
> > if ((uintptr_t)host_endaddr & (rb->page_size - 1)) {
> > error_report("ram_block_discard_range: Unaligned end address:
> > %p",
> > @@ -3711,29 +3712,60 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t
> > start, size_t length)
> >
> > errno = ENOTSUP; /* If we are missing MADVISE etc */
> >
> > - if (rb->page_size == qemu_host_page_size) {
> > -#if defined(CONFIG_MADVISE)
> > - /* Note: We need the madvise MADV_DONTNEED behaviour of
> > definitely
> > - * freeing the page.
> > - */
> > - ret = madvise(host_startaddr, length, MADV_DONTNEED);
> > -#endif
> > - } else {
> > - /* Huge page case - unfortunately it can't do DONTNEED, but
> > - * it can do the equivalent by FALLOC_FL_PUNCH_HOLE in the
> > - * huge page file.
> > + /* The logic here is messy;
> > + * madvise DONTNEED fails for hugepages
> > + * fallocate works on hugepages and shmem
> > + */
> > + need_madvise = (rb->page_size == qemu_host_page_size);
> > + need_fallocate = rb->fd != -1;
> > + if (need_fallocate) {
> > + /* For a file, this causes the area of the file to be zero'd
> > + * if read, and for hugetlbfs also causes it to be unmapped
> > + * so a userfault will trigger.
> > */
> > #ifdef CONFIG_FALLOCATE_PUNCH_HOLE
> > ret = fallocate(rb->fd, FALLOC_FL_PUNCH_HOLE |
> > FALLOC_FL_KEEP_SIZE,
> > start, length);
> > + if (ret) {
> > + ret = -errno;
> > + error_report("ram_block_discard_range: Failed to fallocate
> > "
> > + "%s:%" PRIx64 " +%zx (%d)",
> > + rb->idstr, start, length, ret);
> > + goto err;
> > + }
> > +#else
> > + ret = -ENOSYS;
> > + error_report("ram_block_discard_range: fallocate not
> > available/file"
> > + "%s:%" PRIx64 " +%zx (%d)",
> > + rb->idstr, start, length, ret);
> > + goto err;
> > #endif
> > }
> > - if (ret) {
> > - ret = -errno;
> > - error_report("ram_block_discard_range: Failed to discard range
> > "
> > + if (need_madvise) {
> > + /* For normal RAM this causes it to be unmapped,
> > + * for shared memory it causes the local mapping to disappear
> > + * and to fall back on the file contents (which we just
> > + * fallocate'd away).
> > + */
> > +#if defined(CONFIG_MADVISE)
> > + ret = madvise(host_startaddr, length, MADV_DONTNEED);
> > + if (ret) {
> > + ret = -errno;
> > + error_report("ram_block_discard_range: Failed to discard
> > range "
> > + "%s:%" PRIx64 " +%zx (%d)",
> > + rb->idstr, start, length, ret);
> > + goto err;
> > + }
> > +#else
> > + ret = -ENOSYS;
> > + error_report("ram_block_discard_range: MADVISE not available"
> > "%s:%" PRIx64 " +%zx (%d)",
> > rb->idstr, start, length, ret);
> > + goto err;
> > +#endif
> > }
> > + trace_ram_block_discard_range(rb->idstr, host_startaddr,
> > + need_madvise, need_fallocate, ret);
>
> Nit: worth to log the length too if it's named as "range"?
Done.
> Either with/without:
>
> Reviewed-by: Peter Xu <address@hidden>
Thanks.
Dave
>
> --
> Peter Xu
--
Dr. David Alan Gilbert / address@hidden / Manchester, UK
- [Qemu-devel] [PATCH v3 00/29] postcopy+vhost-user/shared ram, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 01/29] migrate: Update ram_block_discard_range for shared, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 02/29] qemu_ram_block_host_offset, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 03/29] postcopy: use UFFDIO_ZEROPAGE only when available, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 04/29] postcopy: Add notifier chain, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 05/29] postcopy: Add vhost-user flag for postcopy and check it, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 08/29] libvhost-user: Open userfaultfd, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 07/29] libvhost-user: Support sending fds back to qemu, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 06/29] vhost-user: Add 'VHOST_USER_POSTCOPY_ADVISE' message, Dr. David Alan Gilbert (git), 2018/02/16
- [Qemu-devel] [PATCH v3 09/29] postcopy: Allow registering of fd handler, Dr. David Alan Gilbert (git), 2018/02/16