Skip to contentSkip to conversation

tty: Keep the default buffering to sub-page units

PATCH In review Alan Cox 2 participants 2 messages Feb 17, 2010

Subsystems (2)
lore
Share & tools
lore

Alan Cox

author
#0 lore raw

PATCH 1/1 tty: Keep the default buffering to sub-page units

We allocate during interrupts so while our buffering is normally diced up small anyway on some hardware at speed we can pressure the VM excessively for page pairs. We don't really need big buffers to be linear so don't try so hard.

In order to make this work well we will tidy up excess callers to request_room, which cannot itself enforce this break up.

---

 drivers/char/tty_buffer.c |    5 +++--
 include/linux/tty.h       |   10 ++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/char/tty_buffer.c +3 -2
index 66fa4e1..8402eda 100644
@@ -247,7 +247,7 @@ int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
 {
 	int copied = 0;
 	do {
-		int space = tty_buffer_request_room(tty, size - copied);
+		int space = tty_buffer_request_room(tty, goal);
 		struct tty_buffer *tb = tty->buf.tail;
 		/* If there is no space then tb may be NULL */
 		if (unlikely(space == 0))
@@ -283,7 +283,8 @@ int tty_insert_flip_string_flags(struct tty_struct *tty,
 {
 	int copied = 0;
 	do {
-		int space = tty_buffer_request_room(tty, size - copied);
+		int goal = min(size - copied, TTY_BUFFER_PAGE);
+		int space = tty_buffer_request_room(tty, goal);
 		struct tty_buffer *tb = tty->buf.tail;
 		/* If there is no space then tb may be NULL */
 		if (unlikely(space == 0))
include/linux/tty.h +10 -0
index 6abfcf5..d96e588 100644
@@ -68,6 +68,16 @@ struct tty_buffer {
 	unsigned long data[0];
 };
 
+/*
+ * We default to dicing tty buffer allocations to this many characters
+ * in order to avoid multiple page allocations. We assume tty_buffer itself
+ * is under 256 bytes. See tty_buffer_find for the allocation logic this
+ * must match
+ */
+
+#define TTY_BUFFER_PAGE		((PAGE_SIZE  - 256) / 2)
+
+
 struct tty_bufhead {
 	struct delayed_work work;
 	spinlock_t lock;
#1 lore raw
Quoted 21 lines · Alan Cox

We allocate during interrupts so while our buffering is normally diced up small anyway on some hardware at speed we can pressure the VM excessively for page pairs. We don't really need big buffers to be linear so don't try so hard.

In order to make this work well we will tidy up excess callers to request_room, which cannot itself enforce this break up.

---

 drivers/char/tty_buffer.c |    5 +++--
 include/linux/tty.h       |   10 ++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/char/tty_buffer.c +0 -0
index 66fa4e1..8402eda 100644

drivers/char/tty_buffer.c int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars, · line 250

Quoted 5 lines
drivers/char/tty_buffer.c +1 -1
@@ -247,7 +247,7 @@ int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
 {
 	int copied = 0;
 	do {
-		int space = tty_buffer_request_room(tty, size - copied);
+		int space = tty_buffer_request_room(tty, goal);

This causes the build error:

CC drivers/char/tty_buffer.o
drivers/char/tty_buffer.c: In function ‘tty_insert_flip_string’:
drivers/char/tty_buffer.c:250: error: ‘goal’ undeclared (first use in this function) drivers/char/tty_buffer.c:250: error: (Each undeclared identifier is reported only once drivers/char/tty_buffer.c:250: error: for each function it appears in.)

So I'll drop it for now.

Care to fix this?

thanks,

greg k-h