AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Felix Kuehling <felix.kuehling@amd.com>
To: amd-gfx@lists.freedesktop.org, "Sierra Guiza,
	Alejandro (Alex)" <Alex.Sierra@amd.com>,
	Philip Yang <Philip.Yang@amd.com>
Subject: Re: [PATCH 1/2] drm/amdgpu: remove acc_size from reserve/unreserve mem
Date: Wed, 18 May 2022 17:31:03 -0400	[thread overview]
Message-ID: <63fe88f7-fa3c-67be-73ab-8fed555e4c52@amd.com> (raw)
In-Reply-To: <1e136059-5e56-8709-c252-bee43dec2c1d@amd.com>

On 2022-05-18 13:55, philip yang wrote:
>
>
> On 2022-05-17 19:11, Alex Sierra wrote:
>> TTM used to track the "acc_size" of all BOs internally. We needed to
>> keep track of it in our memory reservation to avoid TTM running out
>> of memory in its own accounting. However, that "acc_size" accounting
>> has since been removed from TTM. Therefore we don't really need to
>> track it any more.
>
> acc_size is size of amdgpu_bo data structure plus size of pages array 
> and dma_address array, it is needed for each BO, so should track as 
> system_mem_needed. It can be removed from ttm_mem_needed as this is 
> not allocated by TTM as GTT memory.
>
You have a point, I didn't think of that. The fact that TTM isn't 
tracking the data structure sizes any more doesn't mean, we shouldn't 
account for it in our own system memory usage.

That said, do we actually have DMA address arrays for VRAM allocations?

Also, acc_size doesn't track the extra dmabuf BOs we create for DMA 
mappings on multiple GPUs. So I'm not sure how useful the acc_size 
tracking is at this point. The system memory limit is currently 15/16 of 
total memory. Maybe that leaves enough reserve for data structure sizes?

Regards,
   Felix


> Regards,
>
> Philip
>
>> Signed-off-by: Alex Sierra<alex.sierra@amd.com>
>> ---
>>   .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 57 ++++++-------------
>>   1 file changed, 16 insertions(+), 41 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> index fada3b149361..e985cf9c7ec0 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
>> @@ -108,17 +108,8 @@ void amdgpu_amdkfd_reserve_system_mem(uint64_t size)
>>    * compromise that should work in most cases without reserving too
>>    * much memory for page tables unnecessarily (factor 16K, >> 14).
>>    */
>> -#define ESTIMATE_PT_SIZE(mem_size) ((mem_size) >> 14)
>> -
>> -static size_t amdgpu_amdkfd_acc_size(uint64_t size)
>> -{
>> -	size >>= PAGE_SHIFT;
>> -	size *= sizeof(dma_addr_t) + sizeof(void *);
>>   
>> -	return __roundup_pow_of_two(sizeof(struct amdgpu_bo)) +
>> -		__roundup_pow_of_two(sizeof(struct ttm_tt)) +
>> -		PAGE_ALIGN(size);
>> -}
>> +#define ESTIMATE_PT_SIZE(mem_size) ((mem_size) >> 14)
>>   
>>   /**
>>    * amdgpu_amdkfd_reserve_mem_limit() - Decrease available memory by size
>> @@ -136,28 +127,22 @@ static int amdgpu_amdkfd_reserve_mem_limit(struct amdgpu_device *adev,
>>   {
>>   	uint64_t reserved_for_pt =
>>   		ESTIMATE_PT_SIZE(amdgpu_amdkfd_total_mem_size);
>> -	size_t acc_size, system_mem_needed, ttm_mem_needed, vram_needed;
>> +	size_t system_mem_needed, ttm_mem_needed, vram_needed;
>>   	int ret = 0;
>>   
>> -	acc_size = amdgpu_amdkfd_acc_size(size);
>> -
>> +	system_mem_needed = 0;
>> +	ttm_mem_needed = 0;
>>   	vram_needed = 0;
>>   	if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_GTT) {
>> -		system_mem_needed = acc_size + size;
>> -		ttm_mem_needed = acc_size + size;
>> +		system_mem_needed = size;
>> +		ttm_mem_needed = size;
>>   	} else if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
>> -		system_mem_needed = acc_size;
>> -		ttm_mem_needed = acc_size;
>>   		vram_needed = size;
>>   	} else if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_USERPTR) {
>> -		system_mem_needed = acc_size + size;
>> -		ttm_mem_needed = acc_size;
>> -	} else if (alloc_flag &
>> -		   (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL |
>> -		    KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) {
>> -		system_mem_needed = acc_size;
>> -		ttm_mem_needed = acc_size;
>> -	} else {
>> +		system_mem_needed = size;
>> +	} else if (!(alloc_flag &
>> +				(KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL |
>> +				 KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP))) {
>>   		pr_err("%s: Invalid BO type %#x\n", __func__, alloc_flag);
>>   		return -ENOMEM;
>>   	}
>> @@ -193,28 +178,18 @@ static int amdgpu_amdkfd_reserve_mem_limit(struct amdgpu_device *adev,
>>   static void unreserve_mem_limit(struct amdgpu_device *adev,
>>   		uint64_t size, u32 alloc_flag)
>>   {
>> -	size_t acc_size;
>> -
>> -	acc_size = amdgpu_amdkfd_acc_size(size);
>> -
>>   	spin_lock(&kfd_mem_limit.mem_limit_lock);
>>   
>>   	if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_GTT) {
>> -		kfd_mem_limit.system_mem_used -= (acc_size + size);
>> -		kfd_mem_limit.ttm_mem_used -= (acc_size + size);
>> +		kfd_mem_limit.system_mem_used -= size;
>> +		kfd_mem_limit.ttm_mem_used -= size;
>>   	} else if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
>> -		kfd_mem_limit.system_mem_used -= acc_size;
>> -		kfd_mem_limit.ttm_mem_used -= acc_size;
>>   		adev->kfd.vram_used -= size;
>>   	} else if (alloc_flag & KFD_IOC_ALLOC_MEM_FLAGS_USERPTR) {
>> -		kfd_mem_limit.system_mem_used -= (acc_size + size);
>> -		kfd_mem_limit.ttm_mem_used -= acc_size;
>> -	} else if (alloc_flag &
>> -		   (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL |
>> -		    KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) {
>> -		kfd_mem_limit.system_mem_used -= acc_size;
>> -		kfd_mem_limit.ttm_mem_used -= acc_size;
>> -	} else {
>> +		kfd_mem_limit.system_mem_used -= size;
>> +	} else if (!(alloc_flag &
>> +				(KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL |
>> +				 KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP))) {
>>   		pr_err("%s: Invalid BO type %#x\n", __func__, alloc_flag);
>>   		goto release;
>>   	}

  reply	other threads:[~2022-05-18 21:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-17 23:11 [PATCH 1/2] drm/amdgpu: remove acc_size from reserve/unreserve mem Alex Sierra
2022-05-17 23:11 ` [PATCH 2/2] drm/amdkfd: track unified memory reservation with xnack off Alex Sierra
2022-05-18 18:36   ` philip yang
2022-05-18 21:40     ` Felix Kuehling
2022-05-19 14:01       ` philip yang
2022-05-19 15:14         ` Felix Kuehling
2022-05-18 17:55 ` [PATCH 1/2] drm/amdgpu: remove acc_size from reserve/unreserve mem philip yang
2022-05-18 21:31   ` Felix Kuehling [this message]
2022-05-19 14:25     ` philip yang
  -- strict thread matches above, loose matches on Subject: below --
2022-05-19 16:21 Alex Sierra
2022-05-19 23:09 ` Felix Kuehling
2022-06-07 17:17 Alex Sierra

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=63fe88f7-fa3c-67be-73ab-8fed555e4c52@amd.com \
    --to=felix.kuehling@amd.com \
    --cc=Alex.Sierra@amd.com \
    --cc=Philip.Yang@amd.com \
    --cc=amd-gfx@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox