// $Header$ // Kernel Version: // VERSION = 2 // PATCHLEVEL = 5 // SUBLEVEL = 48 // EXTRAVERSION = --- 2.5/fs/select.c 2002-11-20 19:08:58.000000000 +0100 +++ build-2.5/fs/select.c 2002-11-20 19:00:11.000000000 +0100 @@ -62,6 +62,7 @@ * - the poll table contains 6 wait queue entries. This means that no dynamic * memory allocation is necessary for the wait queues if one of the first * 6 file descriptors has new data. + * - sys_select saves 192 bytes on the stack, enough for 256 file descriptors. * */ @@ -261,14 +262,18 @@ return retval; } -static void *select_bits_alloc(int size) +#define SELECT_INLINE_BYTES 32 +static inline void *select_bits_alloc(int size, void *internal) { + if(size <= SELECT_INLINE_BYTES) + return internal; return kmalloc(6 * size, GFP_KERNEL); } -static void select_bits_free(void *bits, int size) +static inline void select_bits_free(void *bits, void *internal) { - kfree(bits); + if(bits != internal) + kfree(bits); } /* @@ -286,6 +291,7 @@ sys_select(int n, fd_set *inp, fd_set *outp, fd_set *exp, struct timeval *tvp) { fd_set_bits fds; + char ibuf[6*SELECT_INLINE_BYTES]; char *bits; long timeout; int ret, size, max_fdset; @@ -325,7 +331,7 @@ */ ret = -ENOMEM; size = FDS_BYTES(n); - bits = select_bits_alloc(size); + bits = select_bits_alloc(size, ibuf); if (!bits) goto out_nofds; fds.in = (unsigned long *) bits; @@ -370,7 +376,7 @@ set_fd_set(n, exp, fds.res_ex); out: - select_bits_free(bits, size); + select_bits_free(bits, ibuf); out_nofds: return ret; }