Skip to contentSkip to conversation

drm/amd/amdgpu: not allow gtt size exceed system memory size

PATCH In review Roger He 4 participants 6 messages Nov 10, 2017 – Nov 14, 2017 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Roger He

author
#0 lore raw

PATCH 1/1 drm/amd/amdgpu: not allow gtt size exceed system memory size

since sometimes VRAM size is bigger than system memory

Change-Id I5b14d18ed7a9f79810cc50c023ac9e240bddf101
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +8 -3
index cdbdf67..f103ccc 100644
@@ -1330,9 +1330,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 	DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
 		 (unsigned) (adev->mc.real_vram_size / (1024 * 1024)));
 
-	if (amdgpu_gtt_size == -1)
-		gtt_size = max((AMDGPU_DEFAULT_GTT_SIZE_MB << 20),
-			       adev->mc.mc_vram_size);
+	if (amdgpu_gtt_size == -1) {
+		struct sysinfo si;
+
+		si_meminfo(&si);
+		gtt_size = min(max((AMDGPU_DEFAULT_GTT_SIZE_MB << 20),
+			       adev->mc.mc_vram_size),
+			       ((uint64_t)si.totalram * si.mem_unit));
+	}
 	else
 		gtt_size = (uint64_t)amdgpu_gtt_size << 20;
 	r = ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_TT, gtt_size >> PAGE_SHIFT);
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1510313635-16473-1-git-send-email-Hongbo.He-5C7GfCeVMHo@public.gmane.org

#2 lore raw

Am 10.11.2017 um 12:33 schrieb Roger He:

Quoted 16 lines

since sometimes VRAM size is bigger than system memory

Change-Id I5b14d18ed7a9f79810cc50c023ac9e240bddf101
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
index cdbdf67..f103ccc 100644
@@ -1330,9 +1330,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
  	DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
  		 (unsigned) (adev->mc.real_vram_size / (1024 * 1024)));
 

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_init(struct amdgpu_device *adev) · line 1339

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +7 -3
-	if (amdgpu_gtt_size == -1)
-		gtt_size = max((AMDGPU_DEFAULT_GTT_SIZE_MB << 20),
-			       adev->mc.mc_vram_size);
+	if (amdgpu_gtt_size == -1) {
+		struct sysinfo si;
+
+		si_meminfo(&si);
+		gtt_size = min(max((AMDGPU_DEFAULT_GTT_SIZE_MB << 20),
+			       adev->mc.mc_vram_size),
+			       ((uint64_t)si.totalram * si.mem_unit));

TTM starts to try to swap things out when more than 50% of system memory are used, 75% is the default hard limit where it starts to block new allocations.

So I would go with 75% here as well and code this as:

gtt_size = AMDGPU_DEFAULT_GTT_SIZE_MB << 20;
gtt_size = max(gtt_size, adev->mc.mc_vram_size);
gtt_size = min(gtt_size, ((uint64_t)si.totalram * si.mem_unit) * 75 / 100);

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_init(struct amdgpu_device *adev) · line 1343

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
+		
 
 
+	}
  	else
  		gtt_size = (uint64_t)amdgpu_gtt_size << 20;
  	r = ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_TT, gtt_size >> PAGE_SHIFT);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): f83b76d4-1538-8648-4910-9953395af5be-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

author
#4 lore raw

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Friday, November 10, 2017 8:02 PM
To: He, Roger <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amd/amdgpu: not allow gtt size exceed system memory size

Am 10.11.2017 um 12:33 schrieb Roger He:

Quoted 17 lines

since sometimes VRAM size is bigger than system memory

Change-Id I5b14d18ed7a9f79810cc50c023ac9e240bddf101
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
index cdbdf67..f103ccc 100644
@@ -1330,9 +1330,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
  	DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
  		 (unsigned) (adev->mc.real_vram_size / (1024 * 1024)));
 

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_init(struct amdgpu_device *adev) · line 1339

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +7 -3
-	if (amdgpu_gtt_size == -1)
-		gtt_size = max((AMDGPU_DEFAULT_GTT_SIZE_MB << 20),
-			       adev->mc.mc_vram_size);
+	if (amdgpu_gtt_size == -1) {
+		struct sysinfo si;
+
+		si_meminfo(&si);
+		gtt_size = min(max((AMDGPU_DEFAULT_GTT_SIZE_MB << 20),
+			       adev->mc.mc_vram_size),
+			       ((uint64_t)si.totalram * si.mem_unit));

TTM starts to try to swap things out when more than 50% of system memory are used, 75% is the default hard limit where it starts to block new allocations.

So I would go with 75% here as well and code this as:

gtt_size = AMDGPU_DEFAULT_GTT_SIZE_MB << 20; gtt_size = max(gtt_size, adev->mc.mc_vram_size); gtt_size = min(gtt_size, ((uint64_t)si.totalram * si.mem_unit) * 75 / 100);

[Roger]: but in amdgpu_info_ioctl, for GTT size, reported to UMD already is *3/4

	case AMDGPU_INFO_MEMORY: {
		
		mem.gtt.heap_usage =
			amdgpu_gtt_mgr_usage(&adev->mman.bdev.man[TTM_PL_TT]);
		mem.gtt.max_allocation = mem.gtt.usable_heap_size * 3 / 4;
	
	So is it duplicated  if *75/100 here?

Regards,
Christian.

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
+		
 
 
+	}
  	else
  		gtt_size = (uint64_t)amdgpu_gtt_size << 20;
  	r = ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_TT, gtt_size >> 

PAGE_SHIFT);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): MWHPR1201MB01271934D0A23FFFAF7A20E0FD540-3iK1xFAIwjq9imrIu4W8xGrFom/aUZj6nBOFsp37pqbUKgpGm//BTAC/[email protected]

#6 lore raw

Am 10.11.2017 um 13:23 schrieb He, Roger:

Quoted 41 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Friday, November 10, 2017 8:02 PM
To: He, Roger <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amd/amdgpu: not allow gtt size exceed system memory size

Am 10.11.2017 um 12:33 schrieb Roger He:

Quoted 17 lines

since sometimes VRAM size is bigger than system memory

Change-Id I5b14d18ed7a9f79810cc50c023ac9e240bddf101
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 11 ++++++++---
   1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
index cdbdf67..f103ccc 100644
@@ -1330,9 +1330,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
   	DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
   		 (unsigned) (adev->mc.real_vram_size / (1024 * 1024)));
 

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_init(struct amdgpu_device *adev) · line 1339

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +7 -3
-	if (amdgpu_gtt_size == -1)
-		gtt_size = max((AMDGPU_DEFAULT_GTT_SIZE_MB << 20),
-			       adev->mc.mc_vram_size);
+	if (amdgpu_gtt_size == -1) {
+		struct sysinfo si;
+
+		si_meminfo(&si);
+		gtt_size = min(max((AMDGPU_DEFAULT_GTT_SIZE_MB << 20),
+			       adev->mc.mc_vram_size),
+			       ((uint64_t)si.totalram * si.mem_unit));

TTM starts to try to swap things out when more than 50% of system memory are used, 75% is the default hard limit where it starts to block new allocations.

So I would go with 75% here as well and code this as:

gtt_size = AMDGPU_DEFAULT_GTT_SIZE_MB << 20; gtt_size = max(gtt_size, adev->mc.mc_vram_size); gtt_size = min(gtt_size, ((uint64_t)si.totalram * si.mem_unit) * 75 / 100);

Quoted 8 lines

[Roger]: but in amdgpu_info_ioctl, for GTT size, reported to UMD already is *3/4

	case AMDGPU_INFO_MEMORY: {
		
		mem.gtt.heap_usage =
			amdgpu_gtt_mgr_usage(&adev->mman.bdev.man[TTM_PL_TT]);
		mem.gtt.max_allocation = mem.gtt.usable_heap_size * 3 / 4;
	
	So is it duplicated  if *75/100 here?

Good point, but that's only the maximum allocation size of a BO in GTT space, not how big GTT space itself is.

And since this is only the available memory and since GTT isn't fragmented this is pretty much a complete useless value. We should probably change it to something like "total gtt size" - "size of pinned objects in gtt".

But this is a separate problem I think,
Christian.

Quoted 5 lines

Regards,
Christian.

Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
+		
 
+	}
   	else
   		gtt_size = (uint64_t)amdgpu_gtt_size << 20;
   	r = ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_TT, gtt_size >>

PAGE_SHIFT);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#7 lore raw
In reply to a message not in the archive
Quoted 32 lines · Christian König

Am 10.11.2017 um 12:33 schrieb Roger He:

Quoted 16 lines

since sometimes VRAM size is bigger than system memory

Change-Id I5b14d18ed7a9f79810cc50c023ac9e240bddf101

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 11 ++++++++---

  1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
index cdbdf67..f103ccc 100644
@@ -1330,9 +1330,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
       DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
            (unsigned) (adev->mc.real_vram_size / (1024 * 1024)));

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_init(struct amdgpu_device *adev) · line 1339

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +7 -2
   -    if (amdgpu_gtt_size == -1)
-        gtt_size = max((AMDGPU_DEFAULT_GTT_SIZE_MB << 20),
-                   adev->mc.mc_vram_size);
+    if (amdgpu_gtt_size == -1) {
+        struct sysinfo si;
+
+        si_meminfo(&si);
+        gtt_size = min(max((AMDGPU_DEFAULT_GTT_SIZE_MB << 20),
+                   adev->mc.mc_vram_size),
+                   ((uint64_t)si.totalram * si.mem_unit));

TTM starts to try to swap things out when more than 50% of system memory are used, 75% is the default hard limit where it starts to block new allocations.

Quoted 1 line

So I would go with 75% here as well and code this as:

I believe those limits can be tweaked in /sys/devices/virtual/drm/ttm/memory_accounting. Therefore I'd be against hard-coding strict limits in the driver.

Regards,
  Felix

Quoted 20 lines

gtt_size = AMDGPU_DEFAULT_GTT_SIZE_MB << 20;
gtt_size = max(gtt_size, adev->mc.mc_vram_size);
gtt_size = min(gtt_size, ((uint64_t)si.totalram * si.mem_unit) * 75 / 100);

Regards,
Christian.

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
+       
 
 
+    }

      else
          gtt_size = (uint64_t)amdgpu_gtt_size << 20;
      r = ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_TT, gtt_size >> PAGE_SHIFT);

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): d0cbf4ad-1ba3-9348-bdd4-8cee543603e2-5C7GfCeVMHo@public.gmane.org

#9 lore raw

Am 13.11.2017 um 23:34 schrieb Felix Kuehling:

Quoted 32 lines · Christian König
Quoted 31 lines

Am 10.11.2017 um 12:33 schrieb Roger He:

Quoted 16 lines

since sometimes VRAM size is bigger than system memory

Change-Id I5b14d18ed7a9f79810cc50c023ac9e240bddf101
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 11 ++++++++---
   1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
index cdbdf67..f103ccc 100644
@@ -1330,9 +1330,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
       DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
            (unsigned) (adev->mc.real_vram_size / (1024 * 1024)));

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_init(struct amdgpu_device *adev) · line 1339

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +7 -2
   -    if (amdgpu_gtt_size == -1)
-        gtt_size = max((AMDGPU_DEFAULT_GTT_SIZE_MB << 20),
-                   adev->mc.mc_vram_size);
+    if (amdgpu_gtt_size == -1) {
+        struct sysinfo si;
+
+        si_meminfo(&si);
+        gtt_size = min(max((AMDGPU_DEFAULT_GTT_SIZE_MB << 20),
+                   adev->mc.mc_vram_size),
+                   ((uint64_t)si.totalram * si.mem_unit));

TTM starts to try to swap things out when more than 50% of system memory are used, 75% is the default hard limit where it starts to block new allocations.

Quoted 4 lines
Quoted 1 line

So I would go with 75% here as well and code this as:

I believe those limits can be tweaked in /sys/devices/virtual/drm/ttm/memory_accounting. Therefore I'd be against hard-coding strict limits in the driver.

Well, it's not a strict limit. You can still overwrite it with a module parameter.

Regards,
Christian.

Quoted 21 lines

Regards,
  Felix

Quoted 17 lines

gtt_size = AMDGPU_DEFAULT_GTT_SIZE_MB << 20;
gtt_size = max(gtt_size, adev->mc.mc_vram_size);
gtt_size = min(gtt_size, ((uint64_t)si.totalram * si.mem_unit) * 75 / 100);

Regards,
Christian.

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
+
 
+    }
       else
           gtt_size = (uint64_t)amdgpu_gtt_size << 20;
       r = ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_TT, gtt_size >>

PAGE_SHIFT);

Quoted 8 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx