2020-11-05 04:41:34

by Sergey Senozhatsky

[permalink] [raw]
Subject: [PATCH] drm/virtio: use kvmalloc for large allocations

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.

Signed-off-by: Sergey Senozhatsky <[email protected]>
---
drivers/gpu/drm/virtio/virtgpu_object.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c b/drivers/gpu/drm/virtio/virtgpu_object.c
index 2d3aa7baffe4..d9ad27e00905 100644
--- a/drivers/gpu/drm/virtio/virtgpu_object.c
+++ b/drivers/gpu/drm/virtio/virtgpu_object.c
@@ -184,8 +184,9 @@ static int virtio_gpu_object_shmem_init(struct virtio_gpu_device *vgdev,
*nents = shmem->pages->orig_nents;
}

- *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;
--
2.29.1.341.ge80a0c044ae-goog


2020-11-05 06:56:34

by Gerd Hoffmann

[permalink] [raw]
Subject: Re: [PATCH] drm/virtio: use kvmalloc for large allocations

Hi,

> - *ents = kmalloc_array(*nents, sizeof(struct virtio_gpu_mem_entry),
> - GFP_KERNEL);
> + *ents = kvmalloc_array(*nents,
> + sizeof(struct virtio_gpu_mem_entry),
> + GFP_KERNEL);

Shouldn't that be balanced with a kvfree() elsewhere?

take care,
Gerd

2020-11-05 07:05:00

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH] drm/virtio: use kvmalloc for large allocations

Hi,

On (20/11/05 07:52), Gerd Hoffmann wrote:
> > - *ents = kmalloc_array(*nents, sizeof(struct virtio_gpu_mem_entry),
> > - GFP_KERNEL);
> > + *ents = kvmalloc_array(*nents,
> > + sizeof(struct virtio_gpu_mem_entry),
> > + GFP_KERNEL);
>
> Shouldn't that be balanced with a kvfree() elsewhere?

I think it already is. ents pointer is assigned to vbuf->data_buf,
and free_vbuf() already uses kvfree(vbuf->data_buf) to free it.

-ss

2020-11-05 11:39:01

by Gerd Hoffmann

[permalink] [raw]
Subject: Re: [PATCH] drm/virtio: use kvmalloc for large allocations

On Thu, Nov 05, 2020 at 04:00:54PM +0900, Sergey Senozhatsky wrote:
> Hi,
>
> On (20/11/05 07:52), Gerd Hoffmann wrote:
> > > - *ents = kmalloc_array(*nents, sizeof(struct virtio_gpu_mem_entry),
> > > - GFP_KERNEL);
> > > + *ents = kvmalloc_array(*nents,
> > > + sizeof(struct virtio_gpu_mem_entry),
> > > + GFP_KERNEL);
> >
> > Shouldn't that be balanced with a kvfree() elsewhere?
>
> I think it already is. ents pointer is assigned to vbuf->data_buf,
> and free_vbuf() already uses kvfree(vbuf->data_buf) to free it.

Ah, right, we needed that before elsewhere.
Ok then, pushed to drm-misc-next.

thanks,
Gerd