From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: Matthew Auld <matthew.auld@intel.com>,
intel-gfx@lists.freedesktop.org,
dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 6/7] drm/i915: Use vma resources for async unbinding
Date: Tue, 21 Dec 2021 17:07:03 +0100 [thread overview]
Message-ID: <6a8a85c1c60ccd865fbd5afe169649cbc6574449.camel@linux.intel.com> (raw)
In-Reply-To: <a617dbed-be44-4617-1bab-e3cc298450b6@intel.com>
On Tue, 2021-12-21 at 14:02 +0000, Matthew Auld wrote:
> On 17/12/2021 14:52, Thomas Hellström wrote:
> > Implement async (non-blocking) unbinding by not syncing the vma
> > before
> > calling unbind on the vma_resource.
> > Add the resulting unbind fence to the object's dma_resv from where
> > it is
> > picked up by the ttm migration code.
> > Ideally these unbind fences should be coalesced with the migration
> > blit
> > fence to avoid stalling the migration blit waiting for unbind, as
> > they
> > can certainly go on in parallel, but since we don't yet have a
> > reasonable data structure to use to coalesce fences and attach the
> > resulting fence to a timeline, we defer that for now.
> >
> > Note that with async unbinding, even while the unbind waits for the
> > preceding bind to complete before unbinding, the vma itself might
> > have been
> > destroyed in the process, clearing the vma pages. Therefore we can
> > only allow async unbinding if we have a refcounted sg-list and keep
> > a
> > refcount on that for the vma resource pages to stay intact until
> > binding occurs. If this condition is not met, a request for an
> > async
> > unbind is diverted to a sync unbind.
> >
> > v2:
> > - Use a separate kmem_cache for vma resources for now to isolate
> > their
> > memory allocation and aid debugging.
> > - Move the check for vm closed to the actual unbinding thread.
> > Regardless
> > of whether the vm is closed, we need the unbind fence to
> > properly wait
> > for capture.
> > - Clear vma_res::vm on unbind and update its documentation.
> >
> > Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
>
> <snip>
>
> > @@ -416,6 +420,7 @@ int i915_vma_bind(struct i915_vma *vma,
> > {
> > u32 bind_flags;
> > u32 vma_flags;
> > + int ret;
> >
> > lockdep_assert_held(&vma->vm->mutex);
> > GEM_BUG_ON(!drm_mm_node_allocated(&vma->node));
> > @@ -424,12 +429,12 @@ int i915_vma_bind(struct i915_vma *vma,
> > if (GEM_DEBUG_WARN_ON(range_overflows(vma->node.start,
> > vma->node.size,
> > vma->vm->total))) {
> > - kfree(vma_res);
> > + i915_vma_resource_free(vma_res);
> > return -ENODEV;
> > }
> >
> > if (GEM_DEBUG_WARN_ON(!flags)) {
> > - kfree(vma_res);
> > + i915_vma_resource_free(vma_res);
> > return -EINVAL;
> > }
> >
> > @@ -441,12 +446,30 @@ int i915_vma_bind(struct i915_vma *vma,
> >
> > bind_flags &= ~vma_flags;
> > if (bind_flags == 0) {
> > - kfree(vma_res);
> > + i915_vma_resource_free(vma_res);
> > return 0;
> > }
> >
> > GEM_BUG_ON(!vma->pages);
> >
> > + /* Wait for or await async unbinds touching our range */
> > + if (work && bind_flags & vma->vm->bind_async_flags)
> > + ret = i915_vma_resource_bind_dep_await(vma->vm,
> > + &work-
> > >base.chain,
> > + vma-
> > >node.start,
> > + vma-
> > >node.size,
> > + true,
> > + GFP_NOWAIT |
> > +
> > __GFP_RETRY_MAYFAIL |
> > +
> > __GFP_NOWARN);
> > + else
> > + ret = i915_vma_resource_bind_dep_sync(vma->vm, vma-
> > >node.start,
> > + vma-
> > >node.size, true);
>
> Is there nothing scary here with coloring? Say with cache coloring,
> to
> ensure we unbind the neighbouring nodes(if they are conflicting)
> before
> doing the bind, or is async unbinding only ever going to be used for
> the
> ppGTT?
>
> And then I guess there might also be memory coloring where we likely
> need to ensure that all the unbinds within the overlapping PT(s) have
> been completed before doing the bind, since the bind will also
> increment
> the usage count of the PT, potentially preventing it from being
> destroyed, which will skip nuking the PDE state, AFAIK. Previously
> the
> drm_mm node(s) would still be present, which would trigger the
> eviction.
> Although it might be that we just end up aligning everything to 2M,
> and
> so drop the memory coloring anyway, so maybe no need to worry about
> this
> yet...
Hmm. This indeed sounds that there were some important considerations
left out. I was under the impression that only previously scheduled
unbinds touching the same range would have need to have finished.
Currently there's only ppGTT async unbinding, but I figure moving
forward we don't want to restrict it.
I wonder whether instead of keeping an interval tree of pending unbinds
we should keep just a single fence per VM of the last pending unbind,
and move to the RB tree as a separate optimization step if needed. That
would AFAICT keep the current semantics of all unbinds that were
scheduled before the current bind are completed before the bind. Do you
think that would be sufficient?
Thanks,
Thomas
next prev parent reply other threads:[~2021-12-21 16:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-17 14:52 [PATCH v3 0/7] drm/i915: Asynchronous vma unbinding Thomas Hellström
2021-12-17 14:52 ` [PATCH v3 1/7] drm/i915: Avoid using the i915_fence_array when collecting dependencies Thomas Hellström
2021-12-21 11:11 ` Matthew Auld
2021-12-17 14:52 ` [PATCH v3 2/7] drm/i915: Break out the i915_deps utility Thomas Hellström
2021-12-21 11:13 ` Matthew Auld
2021-12-17 14:52 ` [PATCH v3 3/7] drm/i915: Require the vm mutex for i915_vma_bind() Thomas Hellström
2021-12-21 11:32 ` Matthew Auld
2021-12-17 14:52 ` [PATCH v3 4/7] drm/i915: Initial introduction of vma resources Thomas Hellström
2021-12-17 14:52 ` [PATCH v3 5/7] drm/i915: Use the vma resource as argument for gtt binding / unbinding Thomas Hellström
2021-12-17 14:52 ` [PATCH v3 6/7] drm/i915: Use vma resources for async unbinding Thomas Hellström
2021-12-21 14:02 ` Matthew Auld
2021-12-21 16:07 ` Thomas Hellström [this message]
2021-12-21 17:08 ` Matthew Auld
2021-12-17 14:52 ` [PATCH v3 7/7] drm/i915: Use struct vma_resource instead of struct vma_snapshot Thomas Hellström
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=6a8a85c1c60ccd865fbd5afe169649cbc6574449.camel@linux.intel.com \
--to=thomas.hellstrom@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=matthew.auld@intel.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).