diff options
author | Peter Hurley <peter@hurleysoftware.com> | 2013-06-15 09:36:04 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-07-23 19:47:08 -0400 |
commit | 11b9faa44df76189b8346ff602a2c01c610c37eb (patch) | |
tree | 90cd2ccef4e11ae1b362a2585f191ded97cc280d | |
parent | 9dd5139f973f55ab4b2e9aff8171781f1e55b29d (diff) |
tty: Merge tty_buffer_find() into tty_buffer_alloc()
tty_buffer_find() implements a simple free list lookaside cache.
Merge this functionality into tty_buffer_alloc() to reflect the
more traditional alloc/free symmetry.
Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/tty_buffer.c | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c index 56d460295c87..a428fa2f7259 100644 --- a/drivers/tty/tty_buffer.c +++ b/drivers/tty/tty_buffer.c | |||
@@ -64,6 +64,8 @@ void tty_buffer_free_all(struct tty_port *port) | |||
64 | * @size: desired size (characters) | 64 | * @size: desired size (characters) |
65 | * | 65 | * |
66 | * Allocate a new tty buffer to hold the desired number of characters. | 66 | * Allocate a new tty buffer to hold the desired number of characters. |
67 | * We round our buffers off in 256 character chunks to get better | ||
68 | * allocation behaviour. | ||
67 | * Return NULL if out of memory or the allocation would exceed the | 69 | * Return NULL if out of memory or the allocation would exceed the |
68 | * per device queue | 70 | * per device queue |
69 | * | 71 | * |
@@ -72,14 +74,29 @@ void tty_buffer_free_all(struct tty_port *port) | |||
72 | 74 | ||
73 | static struct tty_buffer *tty_buffer_alloc(struct tty_port *port, size_t size) | 75 | static struct tty_buffer *tty_buffer_alloc(struct tty_port *port, size_t size) |
74 | { | 76 | { |
77 | struct tty_buffer **tbh = &port->buf.free; | ||
75 | struct tty_buffer *p; | 78 | struct tty_buffer *p; |
76 | 79 | ||
80 | /* Round the buffer size out */ | ||
81 | size = __ALIGN_MASK(size, TTYB_ALIGN_MASK); | ||
82 | |||
83 | if (size <= MIN_TTYB_SIZE) { | ||
84 | if (*tbh) { | ||
85 | p = *tbh; | ||
86 | *tbh = p->next; | ||
87 | goto found; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | /* Should possibly check if this fails for the largest buffer we | ||
92 | have queued and recycle that ? */ | ||
77 | if (port->buf.memory_used + size > 65536) | 93 | if (port->buf.memory_used + size > 65536) |
78 | return NULL; | 94 | return NULL; |
79 | p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC); | 95 | p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC); |
80 | if (p == NULL) | 96 | if (p == NULL) |
81 | return NULL; | 97 | return NULL; |
82 | 98 | ||
99 | found: | ||
83 | tty_buffer_reset(p, size); | 100 | tty_buffer_reset(p, size); |
84 | port->buf.memory_used += size; | 101 | port->buf.memory_used += size; |
85 | return p; | 102 | return p; |
@@ -172,37 +189,6 @@ void tty_buffer_flush(struct tty_struct *tty) | |||
172 | } | 189 | } |
173 | 190 | ||
174 | /** | 191 | /** |
175 | * tty_buffer_find - find a free tty buffer | ||
176 | * @tty: tty owning the buffer | ||
177 | * @size: characters wanted | ||
178 | * | ||
179 | * Locate an existing suitable tty buffer or if we are lacking one then | ||
180 | * allocate a new one. We round our buffers off in 256 character chunks | ||
181 | * to get better allocation behaviour. | ||
182 | * | ||
183 | * Locking: Caller must hold tty->buf.lock | ||
184 | */ | ||
185 | |||
186 | static struct tty_buffer *tty_buffer_find(struct tty_port *port, size_t size) | ||
187 | { | ||
188 | struct tty_buffer **tbh = &port->buf.free; | ||
189 | if (size <= MIN_TTYB_SIZE) { | ||
190 | if (*tbh) { | ||
191 | struct tty_buffer *t = *tbh; | ||
192 | |||
193 | *tbh = t->next; | ||
194 | tty_buffer_reset(t, t->size); | ||
195 | port->buf.memory_used += t->size; | ||
196 | return t; | ||
197 | } | ||
198 | } | ||
199 | /* Round the buffer size out */ | ||
200 | size = __ALIGN_MASK(size, TTYB_ALIGN_MASK); | ||
201 | return tty_buffer_alloc(port, size); | ||
202 | /* Should possibly check if this fails for the largest buffer we | ||
203 | have queued and recycle that ? */ | ||
204 | } | ||
205 | /** | ||
206 | * tty_buffer_request_room - grow tty buffer if needed | 192 | * tty_buffer_request_room - grow tty buffer if needed |
207 | * @tty: tty structure | 193 | * @tty: tty structure |
208 | * @size: size desired | 194 | * @size: size desired |
@@ -230,7 +216,7 @@ int tty_buffer_request_room(struct tty_port *port, size_t size) | |||
230 | 216 | ||
231 | if (left < size) { | 217 | if (left < size) { |
232 | /* This is the slow path - looking for new buffers to use */ | 218 | /* This is the slow path - looking for new buffers to use */ |
233 | if ((n = tty_buffer_find(port, size)) != NULL) { | 219 | if ((n = tty_buffer_alloc(port, size)) != NULL) { |
234 | if (b != NULL) { | 220 | if (b != NULL) { |
235 | b->next = n; | 221 | b->next = n; |
236 | b->commit = b->used; | 222 | b->commit = b->used; |