Remove NGROUPS hardlimit (resend w/o qsort)
Subsystems (4)
PATCH 1/2 Remove NGROUPS hardlimit (resend w/o qsort)
# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.853 -> 1.854
# include/linux/kernel.h 1.24 -> 1.25
# lib/Makefile 1.15 -> 1.16
# include/linux/init_task.h 1.19 -> 1.20
# include/linux/sched.h 1.103 -> 1.104
# kernel/fork.c 1.83 -> 1.84
# kernel/sys.c 1.32 -> 1.33
# include/asm-i386/param.h 1.2 -> 1.3
# kernel/uid16.c 1.2 -> 1.3 # fs/proc/array.c 1.32 -> 1.33 # kernel/exit.c 1.73 -> 1.74
# include/linux/limits.h 1.3 -> 1.4
# (new) -> 1.1 lib/bsearch.c
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/11/11 [email protected] 1.854
# Remove the limit of 32 groups. We now have a per-task, dynamic array of # groups, which is kept sorted and refcounted.
#
# This ChangeSet incorporates all the core functionality. but does not fixup
# all the incorrect usages of groups. That is in a seperate ChangeSet. # -------------------------------------------- # diff -Nru a/fs/proc/array.c b/fs/proc/array.c --- a/fs/proc/array.c Mon Nov 11 17:36:55 2002 +++ b/fs/proc/array.c Mon Nov 11 17:36:55 2002 @@ -172,7 +172,7 @@ p->files ? p->files->max_fds : 0); task_unlock(p);
- for (g = 0; g < p->ngroups; g++)
+ for (g = 0; g < min(p->ngroups, OLD_NGROUPS); g++)
buffer += sprintf(buffer, "%d ", p->groups[g]);
buffer += sprintf(buffer, "\n");
include/asm-i386/param.h +0 -4
@@ -13,10 +13,6 @@#define EXEC_PAGESIZE 4096 -#ifndef NGROUPS -#define NGROUPS 32 -#endif -#ifndef NOGROUP #define NOGROUP (-1)#endif
include/linux/init_task.h +1 -0
@@ -80,6 +80,7 @@ .real_timer = { \ .function = it_real_fn \ }, \ + .ngroups = 0, \ .cap_effective = CAP_INIT_EFF_SET, \ .cap_inheritable = CAP_INIT_INH_SET, \ .cap_permitted = CAP_FULL_SET, \
include/linux/kernel.h +3 -0
@@ -215,4 +215,7 @@#define __FUNCTION__ (__func__)#endif +void *bsearch (const void *key,const void *base,size_t nmemb,size_t size, +int (*compar)(const void *,const void *)); +#endif
include/linux/limits.h +2 -1
@@ -3,7 +3,6 @@#define NR_OPEN 1024 -#define NGROUPS_MAX 32/* supplemental group IDs are available */ #define ARG_MAX 131072/* # bytes of args + environ for exec() */ #define CHILD_MAX 999/* no limit :-) */ #define OPEN_MAX 256/* # open files a process may have */
@@ -18,5 +17,7 @@#define XATTR_LIST_MAX 65536/* size of extended attribute namelist (64k) */ #define RTSIG_MAX 32 + +#define OLD_NGROUPS 32/* old limit of supplemental group IDs */ #endif
include/linux/sched.h +2 -1
@@ -348,7 +348,8 @@uid_t uid,euid,suid,fsuid;gid_t gid,egid,sgid,fsgid;int ngroups; -gid_t groups[NGROUPS ]; +gid_t *groups; +atomic_t *groups_refcount;kernel_cap_t cap_effective, cap_inheritable, cap_permitted; int keep_capabilities:1;struct user_struct *user;
kernel/exit.c +6 -0
@@ -7,6 +7,7 @@#include <linux/config.h> #include <linux/mm.h> #include <linux/slab.h> +#include <linux/vmalloc.h> #include <linux/interrupt.h> #include <linux/smp_lock.h> #include <linux/module.h>
@@ -65,6 +66,11 @@if (p != current)wait_task_inactive (p); + +if (p->ngroups &&atomic_dec_and_test (p->groups_refcount)) { +vfree (p->groups_refcount); +vfree (p->groups); + }atomic_dec (&p->user->processes); security_ops->task_free_security (p);
kernel/fork.c +4 -0
@@ -815,6 +815,10 @@*/ clear_tsk_thread_flag (p,TIF_SYSCALL_TRACE ); +/* increment the groups ref count */ +if (p->ngroups) +atomic_inc (p->groups_refcount); +/* Our parent execution domain becomes current domain These must match for thread signalling to apply */
kernel/sys.c +95 -20
146 lines not on this page · raw message
kernel/uid16.c +48 -15
103 lines not on this page · raw message
lib/Makefile +2 -2
@@ -9,11 +9,11 @@ L_TARGET := lib.a export-objs := cmdline.o dec_and_lock.o rwsem-spinlock.o rwsem.o \ - crc32.o rbtree.o radix-tree.o kobject.o + crc32.o rbtree.o radix-tree.o kobject.o bsearch.o obj-y := errno.o ctype.o string.o vsprintf.o brlock.o cmdline.o \ bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \ - kobject.o + kobject.o bsearch.o obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
lib/bsearch.c new file +49 -0
49 lines not on this page · raw message
Timothy Hockin <[email protected]> said:
[...]
kernel/sys.c line 1070
Quoted 6 lines
kernel/sys.c +6
-0+/* a simple shell-metzner sort */ +static void groupsort (gid_t *grouplist,int gidsetsize) +{ +int right, left, cur, max, stride; + + stride = gidsetsize /2 ;
This guarantees bad performance for certain gidgetsizes... customary wisdom (at least, Knuth sayeth so) is to go:
for(stride = 1; stride < gidgetsize; stride = 3 * stride + 1)
;
do {
stride /= 3;
...
} while (stride > 1) {Quoted 6 lines
kernel/sys.c +6
-0+while (stride) { + max = gidsetsize - stride; + +for (left =0 ; left < max; left++) { + cur = left; +while (cur >=0 ) {
kernel/sys.c line 1086
Quoted 10 lines
kernel/sys.c +10
-0+ right = cur + stride; +if (grouplist[right] < grouplist[cur]) { +gid_t tmp = grouplist[cur]; + grouplist[cur] = grouplist[right]; + grouplist[right] = tmp; + cur -= stride; + }else { +break ; + } + }
You should work by stuffing the new element in a temporary variable, and just shift the greater ones up, then stuff the one in
My version of shellsort (h is stride, n is size) goes:
/*
* shellsort.c: Shell sort
*/
#include "sort.h"
void
sort(double a[], int n)
{
int i, j, h;
double tmp; for(h = 1; h < n; h = 3 * h + 1)
;
do {
h /= 3;
for(i = h; i < n; i++) {
tmp = a[i];
for(j = i - h; j >= 0 && tmp < a[j]; j -= h)
a[j + h] = a[j];
a[j + h] = tmp;
}
} while(h > 1);}
This gets around bad h (stride) values, and does just a bit more than 1 assignment per element moved in the inner loop (you do 3). Plus it is shorter ;-)
Signature · 4 lines
Dr. Horst H. von Brand User #22616 counter.li.org Departamento de Informatica Fono: +56 32 654431 Universidad Tecnica Federico Santa Maria +56 32 654239 Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513