mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	connection: Dynamically resize connection buffers
When using fixed size connection buffers, if either the client or the
server is sending requests faster than the other end can cope with, the
connection buffers will fill up, eventually killing the connection.
This can be a problem for example with Xwayland mapping a lot of
windows, faster than the Wayland compositor can cope with, or a
high-rate mouse flooding the Wayland client with pointer events.
To avoid the issue, resize the connection buffers dynamically when they
get full.
Both data and fd buffers are resized on demand.
The default max buffer size is controlled via the wl_display interface
while each client's connection buffer size is adjustable for finer
control.
The purpose is to explicitly have larger connection buffers for specific
clients such as Xwayland, or set a larger buffer size for the client
with pointer focus to deal with a higher input events rate.
v0: Manuel:
   Dynamically resize connection buffers - Both data and fd buffers are
   resized on demand.
v1: Olivier
1. Add support for unbounded buffers on the client side and growable
   (yet limited) connection buffers on the server side.
2. Add the API to set the default maximum size and a limit for a given
   client.
3. Add tests for growable connection buffers and adjustable limits.
v2: Additional fixes by John:
1. Fix the size calculation in ring_buffer_check_space()
2. Fix wl_connection_read() to return gracefully once it has read up to
   the max buffer size, rather than returning an error.
3. If wl_connection_flush() fails with EAGAIN but the transmit
   ring-buffer has space remaining (or can be expanded),
   wl_connection_queue() should store the message rather than
   returning an error.
4. When the receive ring-buffer is at capacity but more data is
   available to be read, wl_connection_read() should attempt to
   expand the ring-buffer in order to read the remaining data.
v3: Thomas Lukaszewicz <tluk@chromium.org>
   Add a test for unbounded buffers
v4: Add a client API as well to force bounded buffers (unbounded
    by default (Olivier)
v5: Simplify ring_buffer_ensure_space() (Sebastian)
Co-authored-by: Olivier Fourdan <ofourdan@redhat.com>
Co-authored-by: John Lindgren <john@jlindgren.net>
Co-authored-by: Sebastian Wick <sebastian@sebastianwick.net>
Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
Signed-off-by: John Lindgren <john@jlindgren.net>
Signed-off-by: Sebastian Wick <sebastian@sebastianwick.net>
Closes: https://gitlab.freedesktop.org/wayland/wayland/-/issues/237
			
			
This commit is contained in:
		
							parent
							
								
									36cef8653f
								
							
						
					
					
						commit
						d074d52902
					
				
					 9 changed files with 460 additions and 87 deletions
				
			
		| 
						 | 
				
			
			@ -1269,7 +1269,7 @@ wl_display_connect_to_fd(int fd)
 | 
			
		|||
	 */
 | 
			
		||||
	display->proxy.version = 0;
 | 
			
		||||
 | 
			
		||||
	display->connection = wl_connection_create(display->fd);
 | 
			
		||||
	display->connection = wl_connection_create(display->fd, 0);
 | 
			
		||||
	if (display->connection == NULL)
 | 
			
		||||
		goto err_connection;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2238,6 +2238,32 @@ wl_display_flush(struct wl_display *display)
 | 
			
		|||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** Adjust the maximum size of the client connection buffers
 | 
			
		||||
 *
 | 
			
		||||
 * \param display The display context object
 | 
			
		||||
 * \param max_buffer_size The maximum size of the connection buffers
 | 
			
		||||
 *
 | 
			
		||||
 * Client buffers are unbounded by default. This function sets a limit to the
 | 
			
		||||
 * size of the connection buffers.
 | 
			
		||||
 *
 | 
			
		||||
 * A value of 0 for \a max_buffer_size requests the buffers to be unbounded.
 | 
			
		||||
 *
 | 
			
		||||
 * The actual size of the connection buffers is a power of two, the requested
 | 
			
		||||
 * \a max_buffer_size is therefore rounded up to the nearest power of two value.
 | 
			
		||||
 *
 | 
			
		||||
 * Lowering the maximum size may not take effect immediately if the current
 | 
			
		||||
 * content of the buffer does not fit within the new size limit.
 | 
			
		||||
 *
 | 
			
		||||
 * \memberof wl_display
 | 
			
		||||
 * \since 1.22.90
 | 
			
		||||
 */
 | 
			
		||||
WL_EXPORT void
 | 
			
		||||
wl_display_set_max_buffer_size(struct wl_display *display,
 | 
			
		||||
                               size_t max_buffer_size)
 | 
			
		||||
{
 | 
			
		||||
	wl_connection_set_max_buffer_size(display->connection, max_buffer_size);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** Set the user data associated with a proxy
 | 
			
		||||
 *
 | 
			
		||||
 * \param proxy The proxy object
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue