Bug 100298

Summary: weston dmabuf fd leak
Product: Wayland Reporter: kevan.lan <lby>
Component: westonAssignee: Wayland bug list <wayland-bugs>
Status: RESOLVED NOTOURBUG QA Contact:
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: client_debug log

Description kevan.lan 2017-03-21 09:35:35 UTC
I add a gstwaylandsink  use dmabuf, weston come up dmabuf fd leak.


lr-x------    1 root     root            64 Jan 18 09:08 340 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 341 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 342 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 343 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 344 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 345 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 346 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 347 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 348 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 349 -> anon_inode:dmabuf
lrwx------    1 root     root            64 Jan 18 09:08 35 -> socket:[2817]
lr-x------    1 root     root            64 Jan 18 09:08 350 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 351 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 352 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 353 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 354 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 355 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 356 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 357 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 358 -> anon_inode:dmabuf
lr-x------    1 root     root            64 Jan 18 09:08 359 -> anon_inode:dmabuf
.......

static void
create_dmabuf_buffer(struct display *display, struct buffer *buffer)
{
	struct zwp_linux_buffer_params_v1 *params;
	uint64_t modifier;
	uint32_t flags;
	unsigned i;

	modifier = 0;
	flags = 0;

	/* XXX: apparently some webcams may actually provide y-inverted images,
	 * in which case we should set
	 * flags = ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT
	 */
	params = zwp_linux_dmabuf_v1_create_params(display->dmabuf);
	for (i = 0; i < display->format.num_planes; ++i)
		zwp_linux_buffer_params_v1_add(params,
		                               buffer->dmabuf_fds[i],
		                               i, /* plane_idx */
		                               buffer->data_offsets[i], /* offset */
		                               display->format.strides[i],
		                               modifier >> 32,
		                               modifier & 0xffffffff);
	zwp_linux_buffer_params_v1_add_listener(params, &params_listener,
	                                        buffer);
	zwp_linux_buffer_params_v1_create(params,
	                                  display->format.width,
	                                  display->format.height,
	                                  display->drm_format,
	                                  flags);

}
static void
create_succeeded(void *data,
		 struct zwp_linux_buffer_params_v1 *params,
		 struct wl_buffer *new_buffer)
{
	struct buffer *buffer = data;
	unsigned i;
	buffer->buffer = new_buffer;
	wl_buffer_add_listener(buffer->buffer, &buffer_listener, buffer);

	zwp_linux_buffer_params_v1_destroy(params);

}


Beacause buffer->dmabuf_fds[i](variational) get form vpudec,I need call "create_dmabuf_buffer"  constantly when show frames.
Comment 1 Daniel Stone 2017-03-21 11:25:04 UTC
The FDs are closed in linux_dmabuf_buffer_destroy, called from destroy_linux_dmabuf_wl_buffer. Can you check with WAYLAND_DEBUG=client, that the client is actually destroying the wl_buffer objects it creates?
Comment 2 kevan.lan 2017-03-21 11:45:28 UTC
Created attachment 130340 [details]
client_debug log
Comment 3 kevan.lan 2017-03-21 11:52:21 UTC
(In reply to kevan.lan from comment #2)
> Created attachment 130340 [details]
> client_debug log

Thanks Daniel Stone.

I add a client_debug log.
It seems that  the client is not destroy the wl_buffer objects.

How to destroy the wl_buffer objects by client ?
Comment 4 kevan.lan 2017-03-21 12:44:14 UTC
I add wl_buffer_destroy(buffer->buffer) to fix it.Thanks Daniel Stone.
Comment 5 Link Mauve 2018-02-07 13:13:45 UTC
This was a client issue, nothing we can do without having per-client quotas to detect bogus clients.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.