* [PATCH] Input: evdev: Fall back to vmalloc for client event buffer
@ 2013-10-07 13:06 Daniel Stone
2013-10-28 11:50 ` Daniel Stone
2013-10-31 7:26 ` Dmitry Torokhov
0 siblings, 2 replies; 3+ messages in thread
From: Daniel Stone @ 2013-10-07 13:06 UTC (permalink / raw)
To: linux-input; +Cc: Henrik Rydberg
evdev always tries to allocate the event buffer for clients using
kzalloc rather than vmalloc, presumably to avoid mapping overhead where
possible. However, drivers like bcm5974, which claims support for
reporting 16 fingers simultaneously, can have an extraordinarily large
buffer. The resultant contiguous order-4 allocation attempt fails due
to fragmentation, and the device is thus unusable until reboot.
Try kzalloc if we can to avoid the mapping overhead, but if that fails,
fall back to vzalloc.
Signed-off-by: Daniel Stone <daniels@collabora.com>
---
drivers/input/evdev.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index f0f8928..edfca4a 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -18,6 +18,7 @@
#include <linux/poll.h>
#include <linux/sched.h>
#include <linux/slab.h>
+#include <linux/mm.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/input/mt.h>
@@ -289,7 +290,11 @@ static int evdev_release(struct inode *inode, struct file *file)
mutex_unlock(&evdev->mutex);
evdev_detach_client(evdev, client);
- kfree(client);
+
+ if (is_vmalloc_addr(client))
+ vfree(client);
+ else
+ kfree(client);
evdev_close_device(evdev);
@@ -311,10 +316,12 @@ static int evdev_open(struct inode *inode, struct file *file)
unsigned int bufsize = evdev_compute_buffer_size(evdev->handle.dev);
struct evdev_client *client;
int error;
+ int size =
+ sizeof(struct evdev_client) + bufsize * sizeof(struct input_event);
- client = kzalloc(sizeof(struct evdev_client) +
- bufsize * sizeof(struct input_event),
- GFP_KERNEL);
+ client = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
+ if (!client)
+ client = vzalloc(size);
if (!client)
return -ENOMEM;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Input: evdev: Fall back to vmalloc for client event buffer
2013-10-07 13:06 [PATCH] Input: evdev: Fall back to vmalloc for client event buffer Daniel Stone
@ 2013-10-28 11:50 ` Daniel Stone
2013-10-31 7:26 ` Dmitry Torokhov
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Stone @ 2013-10-28 11:50 UTC (permalink / raw)
To: linux-input, dmitry.torokhov; +Cc: Henrik Rydberg
Hi,
On 7 October 2013 14:06, Daniel Stone <daniel@fooishbar.org> wrote:
> evdev always tries to allocate the event buffer for clients using
> kzalloc rather than vmalloc, presumably to avoid mapping overhead where
> possible. However, drivers like bcm5974, which claims support for
> reporting 16 fingers simultaneously, can have an extraordinarily large
> buffer. The resultant contiguous order-4 allocation attempt fails due
> to fragmentation, and the device is thus unusable until reboot.
>
> Try kzalloc if we can to avoid the mapping overhead, but if that fails,
> fall back to vzalloc.
>
> Signed-off-by: Daniel Stone <daniels@collabora.com>
Ping? This bit me again yesterday, and is pretty much guaranteed to
happen eventually, if you suspend and resume enough times.
Cheers,
Daniel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Input: evdev: Fall back to vmalloc for client event buffer
2013-10-07 13:06 [PATCH] Input: evdev: Fall back to vmalloc for client event buffer Daniel Stone
2013-10-28 11:50 ` Daniel Stone
@ 2013-10-31 7:26 ` Dmitry Torokhov
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2013-10-31 7:26 UTC (permalink / raw)
To: Daniel Stone; +Cc: linux-input, Henrik Rydberg
On Mon, Oct 07, 2013 at 02:06:53PM +0100, Daniel Stone wrote:
> evdev always tries to allocate the event buffer for clients using
> kzalloc rather than vmalloc, presumably to avoid mapping overhead where
> possible. However, drivers like bcm5974, which claims support for
> reporting 16 fingers simultaneously, can have an extraordinarily large
> buffer. The resultant contiguous order-4 allocation attempt fails due
> to fragmentation, and the device is thus unusable until reboot.
>
> Try kzalloc if we can to avoid the mapping overhead, but if that fails,
> fall back to vzalloc.
>
> Signed-off-by: Daniel Stone <daniels@collabora.com>
Applied, thank you Daniel.
--
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-10-31 7:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-07 13:06 [PATCH] Input: evdev: Fall back to vmalloc for client event buffer Daniel Stone
2013-10-28 11:50 ` Daniel Stone
2013-10-31 7:26 ` Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).