All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Riley <davidriley@chromium.org>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: dri-devel@lists.freedesktop.org,
	virtualization@lists.linux-foundation.org,
	"David Airlie" <airlied@linux.ie>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Gurchetan Singh" <gurchetansingh@chromium.org>,
	"Stéphane Marchesin" <marcheu@chromium.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] drm/virtio: Use vmalloc for command buffer allocations.
Date: Tue, 3 Sep 2019 13:27:37 -0700	[thread overview]
Message-ID: <CAASgrz1GKRGncD_6aDUKnDuBiZpZOjkP0P62Ukmk+DN6csKm7w@mail.gmail.com> (raw)
In-Reply-To: <20190902052852.vqejjqrib6tvv2v5@sirius.home.kraxel.org>

On Sun, Sep 1, 2019 at 10:28 PM Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> On Fri, Aug 30, 2019 at 10:49:25AM -0700, David Riley wrote:
> > Hi Gerd,
> >
> > On Fri, Aug 30, 2019 at 4:16 AM Gerd Hoffmann <kraxel@redhat.com> wrote:
> > >
> > >   Hi,
> > >
> > > > > > -     kfree(vbuf->data_buf);
> > > > > > +     kvfree(vbuf->data_buf);
> > > > >
> > > > > if (is_vmalloc_addr(vbuf->data_buf)) ...
> > > > >
> > > > > needed here I gues?
> > > > >
> > > >
> > > > kvfree() handles vmalloc/kmalloc/kvmalloc internally by doing that check.
> > >
> > > Ok.
> > >
> > > > - videobuf_vmalloc_to_sg in drivers/media/v4l2-core/videobuf-dma-sg.c,
> > > > assumes contiguous array of scatterlist and that the buffer being converted
> > > > is page aligned
> > >
> > > Well, vmalloc memory _is_ page aligned.
> >
> > True, but this function gets called for all potential enqueuings (eg
> > resource_create_3d, resource_attach_backing) and I was concerned that
> > some other usage in the future might not have that guarantee.
>
> The vmalloc_to_sg call is wrapped into "if (is_vmalloc())", so this
> should not be a problem.
>
> > > sg_alloc_table_from_pages() does alot of what you need, you just need a
> > > small loop around vmalloc_to_page() create a struct page array
> > > beforehand.
> >
> > That feels like an extra allocation when under memory pressure and
> > more work, to not gain much -- there still needs to be a function that
> > iterates through all the pages.  But I don't feel super strongly about
> > it and can change it if you think that it will be less maintenance
> > overhead.
>
> Lets see how vmalloc_to_sg looks like when it assumes page-aligned
> memory.  It's probably noticeable shorter then.

It's not really.  The allocation of the table is one unit less, and
doesn't need to take into account that data might be an offset within
the page.  It still needs error handling, partial final page handling,
and marking of the end of the scatterlist.  Things could be slightly
simplified to assume that you can always get a contiguous allocation
of the table instead of using sg_alloc_table/for_each_sg, but given
that we're only going down this path when memory is fragmented and in
a fallback, doesn't seem worthwhile to make that trade-off.

I've written a different version of vmalloc_to_sgt which uses
sg_alloc_table_from_pages under the covers and it comes in slightly
shorter (39 lines vs 55 lines), but incurs another allocation as
previously so I'm personally in favour of things as written.
fpga_mgr_buf_load is another function which roughly does the same sort
of operation and it's a bit longer.

I'll post a v2 shortly, but if you think it's worth making the extra
allocation of the pages array to use, I can post that instead.

> cheers,
>   Gerd
>

  parent reply	other threads:[~2019-09-03 20:27 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-29 21:24 [PATCH] drm/virtio: Use vmalloc for command buffer allocations David Riley
2019-08-30  6:08 ` Gerd Hoffmann
2019-08-30  6:08 ` Gerd Hoffmann
2019-08-30  6:36   ` David Riley
2019-08-30  6:36   ` David Riley
2019-08-30 11:16     ` Gerd Hoffmann
2019-08-30 16:24       ` Chia-I Wu
2019-09-02  5:19         ` Gerd Hoffmann
2019-09-02  5:19         ` Gerd Hoffmann
2019-08-30 16:24       ` Chia-I Wu
2019-08-30 17:49       ` David Riley
2019-08-30 17:49         ` David Riley
2019-09-02  5:28         ` Gerd Hoffmann
2019-09-03 20:27           ` David Riley
2019-09-03 20:27           ` David Riley [this message]
2019-09-02  5:28         ` Gerd Hoffmann
2019-08-30 17:49       ` David Riley
2019-08-30 11:16     ` Gerd Hoffmann
2019-08-30 16:18 ` Chia-I Wu
2019-08-30 16:18 ` Chia-I Wu
2019-09-05 22:00 ` [PATCH v2] " David Riley
2019-09-05 22:00   ` David Riley
2019-09-06  5:18   ` Gerd Hoffmann
2019-09-09 17:12     ` David Riley
2019-09-09 17:12       ` David Riley
2019-09-09 17:12     ` David Riley
2019-09-06  5:18   ` Gerd Hoffmann
2019-09-10 20:06 ` [PATCH v3 1/2] drm/virtio: Rewrite virtio_gpu_queue_ctrl_buffer using fenced version David Riley
2019-09-10 20:06 ` David Riley
2019-09-11  5:12   ` Gerd Hoffmann
2019-09-11  5:12     ` Gerd Hoffmann
2019-09-11 17:35     ` David Riley
2019-09-11 17:35       ` David Riley
2019-09-11  5:12   ` Gerd Hoffmann
2019-09-10 20:06 ` [PATCH v3 2/2] drm/virtio: Use vmalloc for command buffer allocations David Riley
2019-09-10 20:06 ` David Riley
2019-09-11 18:14 ` [PATCH v4 0/2] drm/virtio: Use vmalloc for command buffer alllocations David Riley
2019-09-11 18:14 ` David Riley
2019-09-11 18:14 ` [PATCH v4 1/2] drm/virtio: Rewrite virtio_gpu_queue_ctrl_buffer using fenced version David Riley
2019-09-11 18:14 ` David Riley
2019-09-11 18:14 ` [PATCH v4 2/2] drm/virtio: Use vmalloc for command buffer allocations David Riley
2019-09-12  7:51   ` Gerd Hoffmann
2019-09-12  7:51   ` Gerd Hoffmann
2019-09-11 18:14 ` David Riley
  -- strict thread matches above, loose matches on Subject: below --
2019-08-29 21:24 [PATCH] " David Riley

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=CAASgrz1GKRGncD_6aDUKnDuBiZpZOjkP0P62Ukmk+DN6csKm7w@mail.gmail.com \
    --to=davidriley@chromium.org \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gurchetansingh@chromium.org \
    --cc=kraxel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcheu@chromium.org \
    --cc=virtualization@lists.linux-foundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.