Skip to contentSkip to conversation

drm/amdgpu: restructure amdgpu_vram_mgr_new

PATCH In review Christian König 3 participants 5 messages Apr 26, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: restructure amdgpu_vram_mgr_new

Merge the two loops, loosen the restriction for big allocations. This reduces the CPU overhead in the good case, but increases it a bit under memory pressure.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 58 +++++++++-----------
 1 file changed, 27 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +27 -31
index 529c5c32a205..e2cbe19404c0 100644
@@ -358,13 +358,13 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
 			       const struct ttm_place *place,
 			       struct ttm_resource *mem)
 {
+	unsigned long lpfn, num_nodes, pages_per_node, pages_left, pages;
 	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
 	struct amdgpu_device *adev = to_amdgpu_device(mgr);
+	uint64_t vis_usage = 0, mem_bytes, max_bytes;
 	struct drm_mm *mm = &mgr->mm;
-	struct drm_mm_node *nodes;
 	enum drm_mm_insert_mode mode;
-	unsigned long lpfn, num_nodes, pages_per_node, pages_left;
-	uint64_t vis_usage = 0, mem_bytes, max_bytes;
+	struct drm_mm_node *nodes;
 	unsigned i;
 	int r;
 
@@ -391,9 +391,10 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
 		pages_per_node = HPAGE_PMD_NR;
 #else
 		/* default to 2MB */
-		pages_per_node = (2UL << (20UL - PAGE_SHIFT));
+		pages_per_node = 2UL << (20UL - PAGE_SHIFT);
 #endif
-		pages_per_node = max((uint32_t)pages_per_node, mem->page_alignment);
+		pages_per_node = max_t(uint32_t, pages_per_node,
+				       mem->page_alignment);
 		num_nodes = DIV_ROUND_UP(mem->num_pages, pages_per_node);
 	}
 
@@ -411,42 +412,37 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
 	mem->start = 0;
 	pages_left = mem->num_pages;
 
-	spin_lock(&mgr->lock);
-	for (i = 0; pages_left >= pages_per_node; ++i) {
-		unsigned long pages = rounddown_pow_of_two(pages_left);
-
-		/* Limit maximum size to 2GB due to SG table limitations */
-		pages = min(pages, (2UL << (30 - PAGE_SHIFT)));
+	/* Limit maximum size to 2GB due to SG table limitations */
+	pages = min(pages_left, 2UL << (30 - PAGE_SHIFT));
 
-		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages,
-						pages_per_node, 0,
-						place->fpfn, lpfn,
-						mode);
-		if (unlikely(r))
-			break;
-
-		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
-		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
-		pages_left -= pages;
-	}
-
-	for (; pages_left; ++i) {
-		unsigned long pages = min(pages_left, pages_per_node);
+	i = 0;
+	spin_lock(&mgr->lock);
+	while (pages_left) {
 		uint32_t alignment = mem->page_alignment;
 
-		if (pages == pages_per_node)
+		if (pages >= pages_per_node)
 			alignment = pages_per_node;
 
-		r = drm_mm_insert_node_in_range(mm, &nodes[i],
-						pages, alignment, 0,
-						place->fpfn, lpfn,
-						mode);
-		if (unlikely(r))
+		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages, alignment,
+						0, place->fpfn, lpfn, mode);
+		if (unlikely(r)) {
+			if (pages > pages_per_node) {
+				if (is_power_of_2(pages))
+					pages = pages / 2;
+				else
+					pages = rounddown_pow_of_two(pages);
+				continue;
+			}
 			goto error;
+		}
 
 		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
 		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
 		pages_left -= pages;
+		++i;
+
+		if (pages > pages_left)
+			pages = pages_left;
 	}
 	spin_unlock(&mgr->lock);
 
Signature · 6 lines
2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#1 lore raw
Quoted 97 lines · Christian König

Merge the two loops, loosen the restriction for big allocations. This reduces the CPU overhead in the good case, but increases it a bit under memory pressure.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 58 +++++++++-----------
  1 file changed, 27 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +23 -31
index 529c5c32a205..e2cbe19404c0 100644
@@ -358,13 +358,13 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
  			       const struct ttm_place *place,
  			       struct ttm_resource *mem)
  {
+	unsigned long lpfn, num_nodes, pages_per_node, pages_left, pages;
  	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
  	struct amdgpu_device *adev = to_amdgpu_device(mgr);
+	uint64_t vis_usage = 0, mem_bytes, max_bytes;
  	struct drm_mm *mm = &mgr->mm;
-	struct drm_mm_node *nodes;
  	enum drm_mm_insert_mode mode;
-	unsigned long lpfn, num_nodes, pages_per_node, pages_left;
-	uint64_t vis_usage = 0, mem_bytes, max_bytes;
+	struct drm_mm_node *nodes;
  	unsigned i;
  	int r;
 
@@ -391,9 +391,10 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
  		pages_per_node = HPAGE_PMD_NR;
  #else
  		/* default to 2MB */
-		pages_per_node = (2UL << (20UL - PAGE_SHIFT));
+		pages_per_node = 2UL << (20UL - PAGE_SHIFT);
  #endif
-		pages_per_node = max((uint32_t)pages_per_node, mem->page_alignment);
+		pages_per_node = max_t(uint32_t, pages_per_node,
+				       mem->page_alignment);
  		num_nodes = DIV_ROUND_UP(mem->num_pages, pages_per_node);
  	}
 
@@ -411,42 +412,37 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
  	mem->start = 0;
  	pages_left = mem->num_pages;
 
-	spin_lock(&mgr->lock);
-	for (i = 0; pages_left >= pages_per_node; ++i) {
-		unsigned long pages = rounddown_pow_of_two(pages_left);
-
-		/* Limit maximum size to 2GB due to SG table limitations */
-		pages = min(pages, (2UL << (30 - PAGE_SHIFT)));
+	/* Limit maximum size to 2GB due to SG table limitations */
+	pages = min(pages_left, 2UL << (30 - PAGE_SHIFT));
 
-		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages,
-						pages_per_node, 0,
-						place->fpfn, lpfn,
-						mode);
-		if (unlikely(r))
-			break;
-
-		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
-		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
-		pages_left -= pages;
-	}
-
-	for (; pages_left; ++i) {
-		unsigned long pages = min(pages_left, pages_per_node);
+	i = 0;
+	spin_lock(&mgr->lock);
+	while (pages_left) {
  		uint32_t alignment = mem->page_alignment;
 
-		if (pages == pages_per_node)
+		if (pages >= pages_per_node)
  			alignment = pages_per_node;
 
-		r = drm_mm_insert_node_in_range(mm, &nodes[i],
-						pages, alignment, 0,
-						place->fpfn, lpfn,
-						mode);
-		if (unlikely(r))
+		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages, alignment,
+						0, place->fpfn, lpfn, mode);
+		if (unlikely(r)) {
+			if (pages > pages_per_node) {
+				if (is_power_of_2(pages))
+					pages = pages / 2;
+				else
+					pages = rounddown_pow_of_two(pages);
+				continue;
+			}
  			goto error;
+		}
 

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, · line 448

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +4 -0
  		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
  		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
  		pages_left -= pages;
+		++i;
+
+		if (pages > pages_left)
+			pages = pages_left;
  	}
  	spin_unlock(&mgr->lock);
 

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

#2 lore raw
In reply to Christian König

Am 2021-04-26 um 4:54 a.m. schrieb Christian König:

Quoted 78 lines

Merge the two loops, loosen the restriction for big allocations. This reduces the CPU overhead in the good case, but increases it a bit under memory pressure.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 58 +++++++++-----------
 1 file changed, 27 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +12 -26
index 529c5c32a205..e2cbe19404c0 100644
@@ -358,13 +358,13 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
 			       const struct ttm_place *place,
 			       struct ttm_resource *mem)
 {
+	unsigned long lpfn, num_nodes, pages_per_node, pages_left, pages;
 	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
 	struct amdgpu_device *adev = to_amdgpu_device(mgr);
+	uint64_t vis_usage = 0, mem_bytes, max_bytes;
 	struct drm_mm *mm = &mgr->mm;
-	struct drm_mm_node *nodes;
 	enum drm_mm_insert_mode mode;
-	unsigned long lpfn, num_nodes, pages_per_node, pages_left;
-	uint64_t vis_usage = 0, mem_bytes, max_bytes;
+	struct drm_mm_node *nodes;
 	unsigned i;
 	int r;
 
@@ -391,9 +391,10 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
 		pages_per_node = HPAGE_PMD_NR;
 #else
 		/* default to 2MB */
-		pages_per_node = (2UL << (20UL - PAGE_SHIFT));
+		pages_per_node = 2UL << (20UL - PAGE_SHIFT);
 #endif
-		pages_per_node = max((uint32_t)pages_per_node, mem->page_alignment);
+		pages_per_node = max_t(uint32_t, pages_per_node,
+				       mem->page_alignment);
 		num_nodes = DIV_ROUND_UP(mem->num_pages, pages_per_node);
 	}
 
@@ -411,42 +412,37 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
 	mem->start = 0;
 	pages_left = mem->num_pages;
 
-	spin_lock(&mgr->lock);
-	for (i = 0; pages_left >= pages_per_node; ++i) {
-		unsigned long pages = rounddown_pow_of_two(pages_left);
-
-		/* Limit maximum size to 2GB due to SG table limitations */
-		pages = min(pages, (2UL << (30 - PAGE_SHIFT)));
+	/* Limit maximum size to 2GB due to SG table limitations */
+	pages = min(pages_left, 2UL << (30 - PAGE_SHIFT));
 
-		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages,
-						pages_per_node, 0,
-						place->fpfn, lpfn,
-						mode);
-		if (unlikely(r))
-			break;
-
-		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
-		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
-		pages_left -= pages;
-	}
-
-	for (; pages_left; ++i) {
-		unsigned long pages = min(pages_left, pages_per_node);
+	i = 0;
+	spin_lock(&mgr->lock);
+	while (pages_left) {
 		uint32_t alignment = mem->page_alignment;
 
-		if (pages == pages_per_node)
+		if (pages >= pages_per_node)
 			alignment = pages_per_node;

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, · line 429

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +4 -5
 
-		r = drm_mm_insert_node_in_range(mm, &nodes[i],
-						pages, alignment, 0,
-						place->fpfn, lpfn,
-						mode);
-		if (unlikely(r))
+		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages, alignment,
+						0, place->fpfn, lpfn, mode);
+		if (unlikely(r)) {
+			if (pages > pages_per_node) {

This means we can never allocate chunks smaller than 2MB, except for the tail. And the tail still needs to be allocated in one piece if it's < 2MB.

On the other hand, we should not allow allocations smaller than mem->page_alignment, except for the tail. So should this condition be "if (pages > mem->page_alignment)" to allow maximum flexibility for allocations without physical alignment constraints when memory is very fragmented?

Regards,
  Felix

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +7 -0
+				if (is_power_of_2(pages))
+					pages = pages / 2;
+				else
+					pages = rounddown_pow_of_two(pages);
+				continue;
+			}
 			goto error;
+		}
 

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, · line 448

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +4 -0
 		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
 		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
 		pages_left -= pages;
+		++i;
+
+		if (pages > pages_left)
+			pages = pages_left;
 	}
 	spin_unlock(&mgr->lock);
 

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

#3 lore raw

Am 26.04.21 um 18:02 schrieb Felix Kuehling:

Quoted 80 lines

Am 2021-04-26 um 4:54 a.m. schrieb Christian König:

Quoted 79 lines

Merge the two loops, loosen the restriction for big allocations. This reduces the CPU overhead in the good case, but increases it a bit under memory pressure.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 58 +++++++++-----------
  1 file changed, 27 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +12 -26
index 529c5c32a205..e2cbe19404c0 100644
@@ -358,13 +358,13 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
  			       const struct ttm_place *place,
  			       struct ttm_resource *mem)
  {
+	unsigned long lpfn, num_nodes, pages_per_node, pages_left, pages;
  	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
  	struct amdgpu_device *adev = to_amdgpu_device(mgr);
+	uint64_t vis_usage = 0, mem_bytes, max_bytes;
  	struct drm_mm *mm = &mgr->mm;
-	struct drm_mm_node *nodes;
  	enum drm_mm_insert_mode mode;
-	unsigned long lpfn, num_nodes, pages_per_node, pages_left;
-	uint64_t vis_usage = 0, mem_bytes, max_bytes;
+	struct drm_mm_node *nodes;
  	unsigned i;
  	int r;
 
@@ -391,9 +391,10 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
  		pages_per_node = HPAGE_PMD_NR;
  #else
  		/* default to 2MB */
-		pages_per_node = (2UL << (20UL - PAGE_SHIFT));
+		pages_per_node = 2UL << (20UL - PAGE_SHIFT);
  #endif
-		pages_per_node = max((uint32_t)pages_per_node, mem->page_alignment);
+		pages_per_node = max_t(uint32_t, pages_per_node,
+				       mem->page_alignment);
  		num_nodes = DIV_ROUND_UP(mem->num_pages, pages_per_node);
  	}
 
@@ -411,42 +412,37 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
  	mem->start = 0;
  	pages_left = mem->num_pages;
 
-	spin_lock(&mgr->lock);
-	for (i = 0; pages_left >= pages_per_node; ++i) {
-		unsigned long pages = rounddown_pow_of_two(pages_left);
-
-		/* Limit maximum size to 2GB due to SG table limitations */
-		pages = min(pages, (2UL << (30 - PAGE_SHIFT)));
+	/* Limit maximum size to 2GB due to SG table limitations */
+	pages = min(pages_left, 2UL << (30 - PAGE_SHIFT));
 
-		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages,
-						pages_per_node, 0,
-						place->fpfn, lpfn,
-						mode);
-		if (unlikely(r))
-			break;
-
-		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
-		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
-		pages_left -= pages;
-	}
-
-	for (; pages_left; ++i) {
-		unsigned long pages = min(pages_left, pages_per_node);
+	i = 0;
+	spin_lock(&mgr->lock);
+	while (pages_left) {
  		uint32_t alignment = mem->page_alignment;
 
-		if (pages == pages_per_node)
+		if (pages >= pages_per_node)
  			alignment = pages_per_node;
 
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, · line 429

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +4 -5
-		r = drm_mm_insert_node_in_range(mm, &nodes[i],
-						pages, alignment, 0,
-						place->fpfn, lpfn,
-						mode);
-		if (unlikely(r))
+		r = drm_mm_insert_node_in_range(mm, &nodes[i], pages, alignment,
+						0, place->fpfn, lpfn, mode);
+		if (unlikely(r)) {
+			if (pages > pages_per_node) {

This means we can never allocate chunks smaller than 2MB, except for the tail. And the tail still needs to be allocated in one piece if it's < 2MB.

Correct, but that was the behavior before as well.

Quoted 5 lines

On the other hand, we should not allow allocations smaller than mem->page_alignment, except for the tail. So should this condition be "if (pages > mem->page_alignment)" to allow maximum flexibility for allocations without physical alignment constraints when memory is very fragmented?

See a few lines above:

pages_per_node = max_t(uint32_t, pages_per_node, page_alignment);

So pages_per_node is always larger than page_alignment and we actually can't allocate less than pages_per_node in one allocation or we would overflow the nodes array.

Regards,
Christian.

Quoted 14 lines

Regards,
  Felix

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +7 -0
+				if (is_power_of_2(pages))
+					pages = pages / 2;
+				else
+					pages = rounddown_pow_of_two(pages);
+				continue;
+			}
  			goto error;
+		}
 
Quoted 10 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man, · line 448

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +4 -0
  		vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
  		amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
  		pages_left -= pages;
+		++i;
+
+		if (pages > pages_left)
+			pages = pages_left;
  	}
  	spin_unlock(&mgr->lock);
 

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

Reviewed-by
#4 lore raw

Am 2021-04-26 um 12:12 p.m. schrieb Christian König:

Quoted 105 lines

Am 26.04.21 um 18:02 schrieb Felix Kuehling:

Quoted 85 lines

Am 2021-04-26 um 4:54 a.m. schrieb Christian König:

Quoted 84 lines

Merge the two loops, loosen the restriction for big allocations. This reduces the CPU overhead in the good case, but increases it a bit under memory pressure.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 58
+++++++++-----------

  1 file changed, 27 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +3 -3
index 529c5c32a205..e2cbe19404c0 100644
@@ -358,13 +358,13 @@ static int amdgpu_vram_mgr_new(struct
 ttm_resource_manager *man,
                      const struct ttm_place *place,
                      struct ttm_resource *mem)
   {
+    unsigned long lpfn, num_nodes, pages_per_node, pages_left, pages;
       struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
       struct amdgpu_device *adev = to_amdgpu_device(mgr);
+    uint64_t vis_usage = 0, mem_bytes, max_bytes;
       struct drm_mm *mm = &mgr->mm;
-    struct drm_mm_node *nodes;
       enum drm_mm_insert_mode mode;
-    unsigned long lpfn, num_nodes, pages_per_node, pages_left;
-    uint64_t vis_usage = 0, mem_bytes, max_bytes;
+    struct drm_mm_node *nodes;
       unsigned i;
       int r;

  @@ -391,9 +391,10 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
          pages_per_node = HPAGE_PMD_NR;
  #else
          /* default to 2MB */
-        pages_per_node = (2UL << (20UL - PAGE_SHIFT));
+        pages_per_node = 2UL << (20UL - PAGE_SHIFT); #endif
-        pages_per_node = max((uint32_t)pages_per_node, mem->page_alignment);
+        pages_per_node = max_t(uint32_t, pages_per_node, +                       mem->page_alignment);
          num_nodes = DIV_ROUND_UP(mem->num_pages, pages_per_node); }
  @@ -411,42 +412,37 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
      mem->start = 0;
      pages_left = mem->num_pages;
  -    spin_lock(&mgr->lock);
-    for (i = 0; pages_left >= pages_per_node; ++i) {
-        unsigned long pages = rounddown_pow_of_two(pages_left); -
-        /* Limit maximum size to 2GB due to SG table limitations */ -        pages = min(pages, (2UL << (30 - PAGE_SHIFT))); +    /* Limit maximum size to 2GB due to SG table limitations */ +    pages = min(pages_left, 2UL << (30 - PAGE_SHIFT));
  -        r = drm_mm_insert_node_in_range(mm, &nodes[i], pages, -                        pages_per_node, 0,
-                        place->fpfn, lpfn,
-                        mode);
-        if (unlikely(r))
-            break;

drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +3 -8
-
-        vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]);
-        amdgpu_vram_mgr_virt_start(mem, &nodes[i]);
-        pages_left -= pages;
-    }
-
-    for (; pages_left; ++i) {
-        unsigned long pages = min(pages_left, pages_per_node);
+    i = 0;
+    spin_lock(&mgr->lock);
+    while (pages_left) {

          uint32_t alignment = mem->page_alignment; -        if (pages == pages_per_node)
+        if (pages >= pages_per_node)
              alignment = pages_per_node;
  -        r = drm_mm_insert_node_in_range(mm, &nodes[i], -                        pages, alignment, 0,
-                        place->fpfn, lpfn,
-                        mode);
-        if (unlikely(r))

Quoted 8 lines
Quoted 5 lines

+        r = drm_mm_insert_node_in_range(mm, &nodes[i], pages, alignment,
+                        0, place->fpfn, lpfn, mode); +        if (unlikely(r)) {
+            if (pages > pages_per_node) {

This means we can never allocate chunks smaller than 2MB, except for the tail. And the tail still needs to be allocated in one piece if it's < 2MB.

Correct, but that was the behavior before as well.

Quoted 5 lines

On the other hand, we should not allow allocations smaller than mem->page_alignment, except for the tail. So should this condition be "if (pages > mem->page_alignment)" to allow maximum flexibility for allocations without physical alignment constraints when memory is very fragmented?

Quoted 7 lines

See a few lines above:

pages_per_node = max_t(uint32_t, pages_per_node, page_alignment);

So pages_per_node is always larger than page_alignment and we actually can't allocate less than pages_per_node in one allocation or we would overflow the nodes array.

Makes sense. The patch is

Quoted 28 lines

Regards,
Christian.

Quoted 23 lines

Regards,
   Felix

Quoted 18 lines

+                if (is_power_of_2(pages))
+                    pages = pages / 2;
+                else
+                    pages = rounddown_pow_of_two(pages); +                continue;
+            }
              goto error;
+        }
            vis_usage += amdgpu_vram_mgr_vis_size(adev, &nodes[i]); amdgpu_vram_mgr_virt_start(mem, &nodes[i]); pages_left -= pages;
+        ++i;
+
+        if (pages > pages_left)
+            pages = pages_left;
      }
      spin_unlock(&mgr->lock);

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