All of lore.kernel.org
 help / color / mirror / Atom feed
* Memory freeing when dmabuf fds are exported with VIDIOC_EXPBUF
@ 2016-07-27  7:51 Kazunori Kobayashi
  2016-07-27 12:57 ` Laurent Pinchart
  0 siblings, 1 reply; 12+ messages in thread
From: Kazunori Kobayashi @ 2016-07-27  7:51 UTC (permalink / raw)
  To: Laurent Pinchart; +Cc: linux-media, Damian Hobson-Garcia

Hi,

I have a question about memory freeing by calling REQBUF(0) before all the
dmabuf fds exported with VIDIOC_EXPBUF are closed.

In calling REQBUF(0), videobuf2-core returns -EBUSY when the reference count
of a vb2 buffer is more than 1. When dmabuf fds are not exported (usual V4L2_MEMORY_MMAP case),
the check is no problem, but when dmabuf fds are exported and some of them are
not closed (in other words the references to that memory are left),
we cannot succeed in calling REQBUF(0) despite being able to free the memory
after all the references are dropped.

Actually REQBUF(0) does not force a vb2 buffer to be freed but decreases
the refcount of it. Also all the vb2 memory allocators that support dmabuf exporting
(dma-contig, dma-sg, vmalloc) implements memory freeing by release() of dma_buf_ops,
so I think there is no need to return -EBUSY when exporting dmabuf fds.

Could you please tell me what you think?

The code that I am talking about is in drivers/media/v4l2-core/videobuf2-core.c:

   if (*count == 0 || q->num_buffers != 0 || q->memory != memory) {
          /*
           * We already have buffers allocated, so first check if they
           * are not in use and can be freed.
           */
          mutex_lock(&q->mmap_lock);
          if (q->memory == VB2_MEMORY_MMAP && __buffers_in_use(q)) {
                  mutex_unlock(&q->mmap_lock);
                  dprintk(1, "memory in use, cannot free\n");
                  return -EBUSY;
          }

Regards,
Kobayashi
-- 
---------------------------------
IGEL Co.,Ltd. Kazunori Kobayashi
kkobayas@igel.co.jp
http://www.igel.co.jp/

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-10-03 15:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-27  7:51 Memory freeing when dmabuf fds are exported with VIDIOC_EXPBUF Kazunori Kobayashi
2016-07-27 12:57 ` Laurent Pinchart
2016-08-01 10:56   ` Hans Verkuil
2016-08-01 12:17     ` Laurent Pinchart
2016-08-01 12:27       ` Hans Verkuil
2016-08-01 13:49         ` Laurent Pinchart
2016-08-01 13:59           ` Hans Verkuil
2016-08-01 16:02             ` Laurent Pinchart
2016-08-01 16:16               ` Steven Toth
2016-08-01 16:56                 ` Laurent Pinchart
2016-08-03  3:23     ` Damian Hobson-Garcia
2017-10-03 15:00     ` Nicolas Dufresne

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.