Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: improve tty_insert_flip_char() slow path

While working on improving the fast path of tty_insert_flip_char(),
I noticed that by calling tty_buffer_request_room(), we needlessly
move to the separate flag buffer mode for the tty, even when all
characters use TTY_NORMAL as the flag.

This changes the code to call __tty_buffer_request_room() with the
correct flag, which will then allocate a regular buffer when it rounds
out of space but no special flags have been used. I'm guessing that
this is the behavior that Peter Hurley intended when he introduced
the compacted flip buffers.

Fixes: acc0f67f307f ("tty: Halve flip buffer GFP_ATOMIC memory consumption")
Cc: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Arnd Bergmann and committed by
Greg Kroah-Hartman
065ea0a7 979990c6

+3 -2
+3 -2
drivers/tty/tty_buffer.c
··· 375 375 struct tty_buffer *tb = port->buf.tail; 376 376 int flags = (flag == TTY_NORMAL) ? TTYB_NORMAL : 0; 377 377 378 - if (!tty_buffer_request_room(port, 1)) 378 + if (!__tty_buffer_request_room(port, 1, flags)) 379 379 return 0; 380 380 381 - *flag_buf_ptr(tb, tb->used) = flag; 381 + if (~tb->flags & TTYB_NORMAL) 382 + *flag_buf_ptr(tb, tb->used) = flag; 382 383 *char_buf_ptr(tb, tb->used++) = ch; 383 384 384 385 return 1;