All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: Chunming Zhou <david1.zhou@amd.com>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: christian.koenig@amd.com
Subject: Re: [PATCH 1/2] [WIP]drm/ttm: add waiter list to prevent allocation not in order
Date: Fri, 26 Jan 2018 11:31:43 +0100	[thread overview]
Message-ID: <2beeea26-9426-6956-fbc7-ada52088b6a6@gmail.com> (raw)
In-Reply-To: <20180126102247.17923-1-david1.zhou@amd.com>

Am 26.01.2018 um 11:22 schrieb Chunming Zhou:
> there is a scheduling balance issue about get node like:
> a. process A allocates full memory and use it for submission.
> b. process B tries to allocates memory, will wait for process A BO idle in eviction.
> c. process A completes the job, process B eviction will put process A BO node,
> but in the meantime, process C is comming to allocate BO, whill directly get node successfully, and do submission,
> process B will again wait for process C BO idle.
> d. repeat the above setps, process B could be delayed much more.
>
> later allocation must not be ahead of front in same place.

Again NAK to the whole approach.

At least with amdgpu the problem you described above never occurs 
because evictions are pipelined operations. We could only block for 
deleted regions to become free.

But independent of that incoming memory requests while we make room for 
eviction are intended to be served first.

Changing that is certainly a no-go cause that would favor memory hungry 
applications over small clients.

Regards,
Christian.

>
> Change-Id: I3daa892e50f82226c552cc008a29e55894a98f18
> Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo.c    | 69 +++++++++++++++++++++++++++++++++++++++--
>   include/drm/ttm/ttm_bo_api.h    |  7 +++++
>   include/drm/ttm/ttm_bo_driver.h |  7 +++++
>   3 files changed, 80 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index d33a6bb742a1..558ec2cf465d 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -841,6 +841,58 @@ static int ttm_bo_add_move_fence(struct ttm_buffer_object *bo,
>   	return 0;
>   }
>   
> +static void ttm_man_init_waiter(struct ttm_bo_waiter *waiter,
> +				struct ttm_buffer_object *bo,
> +				const struct ttm_place *place)
> +{
> +	waiter->tbo = bo;
> +	memcpy((void *)&waiter->place, (void *)place, sizeof(*place));
> +	INIT_LIST_HEAD(&waiter->list);
> +}
> +
> +static void ttm_man_add_waiter(struct ttm_mem_type_manager *man,
> +			       struct ttm_bo_waiter *waiter)
> +{
> +	if (!waiter)
> +		return;
> +	spin_lock(&man->wait_lock);
> +	list_add_tail(&waiter->list, &man->waiter_list);
> +	spin_unlock(&man->wait_lock);
> +}
> +
> +static void ttm_man_del_waiter(struct ttm_mem_type_manager *man,
> +			       struct ttm_bo_waiter *waiter)
> +{
> +	if (!waiter)
> +		return;
> +	spin_lock(&man->wait_lock);
> +	if (!list_empty(&waiter->list))
> +		list_del(&waiter->list);
> +	spin_unlock(&man->wait_lock);
> +	kfree(waiter);
> +}
> +
> +int ttm_man_check_bo(struct ttm_mem_type_manager *man,
> +		     struct ttm_buffer_object *bo,
> +		     const struct ttm_place *place)
> +{
> +	struct ttm_bo_waiter *waiter, *tmp;
> +
> +	spin_lock(&man->wait_lock);
> +	list_for_each_entry_safe(waiter, tmp, &man->waiter_list, list) {
> +		if ((bo != waiter->tbo) &&
> +		    ((place->fpfn >= waiter->place.fpfn &&
> +		      place->fpfn <= waiter->place.lpfn) ||
> +		     (place->lpfn <= waiter->place.lpfn && place->lpfn >=
> +		      waiter->place.fpfn)))
> +		    goto later_bo;
> +	}
> +	spin_unlock(&man->wait_lock);
> +	return true;
> +later_bo:
> +	spin_unlock(&man->wait_lock);
> +	return false;
> +}
>   /**
>    * Repeatedly evict memory from the LRU for @mem_type until we create enough
>    * space, or we've evicted everything and there isn't enough space.
> @@ -853,17 +905,26 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
>   {
>   	struct ttm_bo_device *bdev = bo->bdev;
>   	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
> +	struct ttm_bo_waiter waiter;
>   	int ret;
>   
> +	ttm_man_init_waiter(&waiter, bo, place);
> +	ttm_man_add_waiter(man, &waiter);
>   	do {
>   		ret = (*man->func->get_node)(man, bo, place, mem);
> -		if (unlikely(ret != 0))
> +		if (unlikely(ret != 0)) {
> +			ttm_man_del_waiter(man, &waiter);
>   			return ret;
> -		if (mem->mm_node)
> +		}
> +		if (mem->mm_node) {
> +			ttm_man_del_waiter(man, &waiter);
>   			break;
> +		}
>   		ret = ttm_mem_evict_first(bdev, mem_type, place, ctx);
> -		if (unlikely(ret != 0))
> +		if (unlikely(ret != 0)) {
> +			ttm_man_del_waiter(man, &waiter);
>   			return ret;
> +		}
>   	} while (1);
>   	mem->mem_type = mem_type;
>   	return ttm_bo_add_move_fence(bo, man, mem);
> @@ -1450,6 +1511,8 @@ int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
>   	man->use_io_reserve_lru = false;
>   	mutex_init(&man->io_reserve_mutex);
>   	spin_lock_init(&man->move_lock);
> +	spin_lock_init(&man->wait_lock);
> +	INIT_LIST_HEAD(&man->waiter_list);
>   	INIT_LIST_HEAD(&man->io_reserve_lru);
>   
>   	ret = bdev->driver->init_mem_type(bdev, type, man);
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index 2cd025c2abe7..0fce4dbd02e7 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -40,6 +40,7 @@
>   #include <linux/mm.h>
>   #include <linux/bitmap.h>
>   #include <linux/reservation.h>
> +#include <drm/ttm/ttm_placement.h>
>   
>   struct ttm_bo_device;
>   
> @@ -232,6 +233,12 @@ struct ttm_buffer_object {
>   	struct mutex wu_mutex;
>   };
>   
> +struct ttm_bo_waiter {
> +	struct ttm_buffer_object *tbo;
> +	struct ttm_place place;
> +	struct list_head list;
> +};
> +
>   /**
>    * struct ttm_bo_kmap_obj
>    *
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 9b417eb2df20..dc6b8b4c9e06 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -293,6 +293,10 @@ struct ttm_mem_type_manager {
>   	bool io_reserve_fastpath;
>   	spinlock_t move_lock;
>   
> +	/* waiters in list */
> +	spinlock_t wait_lock;
> +	struct list_head waiter_list;
> +
>   	/*
>   	 * Protected by @io_reserve_mutex:
>   	 */
> @@ -748,6 +752,9 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>   		     struct ttm_mem_reg *mem,
>   		     struct ttm_operation_ctx *ctx);
>   
> +int ttm_man_check_bo(struct ttm_mem_type_manager *man,
> +		     struct ttm_buffer_object *bo,
> +		     const struct ttm_place *place);
>   void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem);
>   void ttm_bo_mem_put_locked(struct ttm_buffer_object *bo,
>   			   struct ttm_mem_reg *mem);

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2018-01-26 10:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-26 10:22 [PATCH 1/2] [WIP]drm/ttm: add waiter list to prevent allocation not in order Chunming Zhou
2018-01-26 10:22 ` [PATCH 2/2] [WIP]drm/amdgpu: fix scheduling balance Chunming Zhou
2018-01-26 10:31 ` Christian König [this message]
2018-01-26 12:36   ` [PATCH 1/2] [WIP]drm/ttm: add waiter list to prevent allocation not in order Zhou, David(ChunMing)
     [not found]   ` <2beeea26-9426-6956-fbc7-ada52088b6a6-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-26 12:36     ` Zhou, David(ChunMing)
     [not found]   ` <5a6b20fc.024e650a.6778d.4aafSMTPIN_ADDED_BROKEN@mx.google.com>
     [not found]     ` <5a6b20fc.024e650a.6778d.4aafSMTPIN_ADDED_BROKEN-ATjtLOhZ0NVl57MIdRCFDg@public.gmane.org>
2018-01-26 12:43       ` Christian König
     [not found]         ` <b1a6305e-1ff8-430b-8b72-c08d469de73b-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-26 13:04           ` Christian König
     [not found]             ` <8ba40eb5-095b-2a95-d73a-16c141eb64a9-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-26 13:21               ` Zhou, David(ChunMing)
2018-01-26 13:21             ` Zhou, David(ChunMing)
     [not found]             ` <5a6b2b4c.c441650a.c40de.5db1SMTPIN_ADDED_BROKEN@mx.google.com>
2018-01-26 13:24               ` Christian König
     [not found]                 ` <acdfee36-ae2f-b90f-cab7-ebe8fd40fbd6-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-26 13:50                   ` Zhou, David(ChunMing)
2018-01-26 13:50                 ` Zhou, David(ChunMing)
2018-01-26 13:59                 ` Christian König
2018-01-26 14:35                   ` Christian König
     [not found]                     ` <a6d78bba-bbe9-769b-f9d3-665cdd8c04da-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-01-31 10:30                       ` Chunming Zhou
     [not found]                         ` <cdb7726b-a82d-494c-a98c-ca0100f323cc-5C7GfCeVMHo@public.gmane.org>
2018-01-31 10:54                           ` Christian König
2018-02-05  8:22                             ` Chunming Zhou
     [not found]                               ` <d2ec14e8-d4cd-a312-5e23-ef2e2198d6ea-5C7GfCeVMHo@public.gmane.org>
2018-02-05 12:21                                 ` Christian König

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=2beeea26-9426-6956-fbc7-ada52088b6a6@gmail.com \
    --to=ckoenig.leichtzumerken@gmail.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=david1.zhou@amd.com \
    --cc=dri-devel@lists.freedesktop.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.