Commit 6087b2da authored by Badari Pulavarty's avatar Badari Pulavarty Committed by Linus Torvalds

optimize compat_core_sys_select() by a using stack space for small fd sets

Optimize select by a using stack space for small fd sets.
core_sys_select() already has this optimization.  This is for compat
version.
Signed-off-by: default avatarBadari Pulavarty <pbadari@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7bb44ade
...@@ -1544,9 +1544,10 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp, ...@@ -1544,9 +1544,10 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp,
compat_ulong_t __user *outp, compat_ulong_t __user *exp, s64 *timeout) compat_ulong_t __user *outp, compat_ulong_t __user *exp, s64 *timeout)
{ {
fd_set_bits fds; fd_set_bits fds;
char *bits; void *bits;
int size, max_fds, ret = -EINVAL; int size, max_fds, ret = -EINVAL;
struct fdtable *fdt; struct fdtable *fdt;
long stack_fds[SELECT_STACK_ALLOC/sizeof(long)];
if (n < 0) if (n < 0)
goto out_nofds; goto out_nofds;
...@@ -1564,11 +1565,14 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp, ...@@ -1564,11 +1565,14 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp,
* since we used fdset we need to allocate memory in units of * since we used fdset we need to allocate memory in units of
* long-words. * long-words.
*/ */
ret = -ENOMEM;
size = FDS_BYTES(n); size = FDS_BYTES(n);
bits = kmalloc(6 * size, GFP_KERNEL); bits = stack_fds;
if (!bits) if (size > sizeof(stack_fds) / 6) {
goto out_nofds; bits = kmalloc(6 * size, GFP_KERNEL);
ret = -ENOMEM;
if (!bits)
goto out_nofds;
}
fds.in = (unsigned long *) bits; fds.in = (unsigned long *) bits;
fds.out = (unsigned long *) (bits + size); fds.out = (unsigned long *) (bits + size);
fds.ex = (unsigned long *) (bits + 2*size); fds.ex = (unsigned long *) (bits + 2*size);
...@@ -1600,7 +1604,8 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp, ...@@ -1600,7 +1604,8 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp,
compat_set_fd_set(n, exp, fds.res_ex)) compat_set_fd_set(n, exp, fds.res_ex))
ret = -EFAULT; ret = -EFAULT;
out: out:
kfree(bits); if (bits != stack_fds)
kfree(bits);
out_nofds: out_nofds:
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment