Skip to contentSkip to conversation

drm/virtio: use kvmalloc for large allocations

PATCH New Doug Horn 2 participants 2 messages Mar 3, 2021 – Mar 4, 2021

Subsystems (4)
lore
Share & tools
lore

Doug Horn

author
#0 lore raw

PATCH 1/1 drm/virtio: use kvmalloc for large allocations

From: Sergey Senozhatsky <[email protected]>

commit ea86f3defd55f141a44146e66cbf8ffb683d60da upstream.

We observed that some of virtio_gpu_object_shmem_init() allocations can be rather costly - order 6 - which can be difficult to fulfill under memory pressure conditions. Switch to kvmalloc_array() in virtio_gpu_object_shmem_init() and let the kernel vmalloc the entries array.

the original patch applied to a different file, this backport moved this change to the proper place for 4.14/4.19/5.4.

---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/virtio/virtgpu_vq.c +3 -3
index a956c73ea85e..374279ba1444 100644
@@ -865,9 +865,9 @@ int virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,
 	}
 
 	/* gets freed when the ring has consumed it */
-	ents = kmalloc_array(obj->pages->nents,
-			     sizeof(struct virtio_gpu_mem_entry),
-			     GFP_KERNEL);
+	ents = kvmalloc_array(obj->pages->nents,
+			      sizeof(struct virtio_gpu_mem_entry),
+			      GFP_KERNEL);
 	if (!ents) {
 		DRM_ERROR("failed to allocate ent list\n");
 		return -ENOMEM;
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog
#1 lore raw

PATCH 1/1 drm/virtio: use kvmalloc for large allocations

From: Sergey Senozhatsky <[email protected]>

commit ea86f3defd55f141a44146e66cbf8ffb683d60da upstream.

We observed that some of virtio_gpu_object_shmem_init() allocations can be rather costly - order 6 - which can be difficult to fulfill under memory pressure conditions. Switch to kvmalloc_array() in virtio_gpu_object_shmem_init() and let the kernel vmalloc the entries array.

---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_vq.c +3 -2
index 92022a83bbd5..bb46e7a0f1b5 100644
@@ -992,8 +992,9 @@ int virtio_gpu_object_attach(struct virtio_gpu_device *vgdev,
 	}
 
 	/* gets freed when the ring has consumed it */
-	ents = kmalloc_array(nents, sizeof(struct virtio_gpu_mem_entry),
-			     GFP_KERNEL);
+	ents = kvmalloc_array(nents,
+			      sizeof(struct virtio_gpu_mem_entry),
+			      GFP_KERNEL);
 	if (!ents) {
 		DRM_ERROR("failed to allocate ent list\n");
 		return -ENOMEM;
Signature · 1 line
2.30.1.766.gb4fecdf3b7-goog