Skip to content

Commit

Permalink
[PATCH] No need to protect current->group_info in sys_getgroups(), in…
Browse files Browse the repository at this point in the history
…_group_p() and in_egroup_p()

While doing some benchmarks of an Apache/PHP SMP server, I noticed high
oprofile numbers in in_group_p() and _atomic_dec_and_lock().

rank  percent
  1     4.8911 % __link_path_walk
  2     4.8503 % __d_lookup
*3     4.2911 % _atomic_dec_and_lock
  4     3.9307 % __copy_to_user_ll
  5     4.9004 % sysenter_past_esp
*6     3.3248 % in_group_p

It appears that in_group_p() does an uncessary

get_group_info(current->group_info); /* atomic_inc() */
  ... /* access current->group_info */
put_group_info(current->group_info); /* _atomic_dec_and_lock */

It is not necessary to do this, because the current task holds a reference
on its own group_info, and this reference cannot change during the lookup.

This patch deletes the get_group_info()/put_group_info() pair from
sys_getgroups(), in_group_p() and in_egroup_p() functions.

Signed-off-by: Eric Dumazet <[email protected]>
Cc: Tim Hockin <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Eric Dumazet authored and Linus Torvalds committed Mar 25, 2006
1 parent 76c67de commit 231bed2
Showing 1 changed file with 0 additions and 6 deletions.
6 changes: 0 additions & 6 deletions kernel/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,6 @@ asmlinkage long sys_getgroups(int gidsetsize, gid_t __user *grouplist)
return -EINVAL;

/* no need to grab task_lock here; it cannot change */
get_group_info(current->group_info);
i = current->group_info->ngroups;
if (gidsetsize) {
if (i > gidsetsize) {
Expand All @@ -1434,7 +1433,6 @@ asmlinkage long sys_getgroups(int gidsetsize, gid_t __user *grouplist)
}
}
out:
put_group_info(current->group_info);
return i;
}

Expand Down Expand Up @@ -1475,9 +1473,7 @@ int in_group_p(gid_t grp)
{
int retval = 1;
if (grp != current->fsgid) {
get_group_info(current->group_info);
retval = groups_search(current->group_info, grp);
put_group_info(current->group_info);
}
return retval;
}
Expand All @@ -1488,9 +1484,7 @@ int in_egroup_p(gid_t grp)
{
int retval = 1;
if (grp != current->egid) {
get_group_info(current->group_info);
retval = groups_search(current->group_info, grp);
put_group_info(current->group_info);
}
return retval;
}
Expand Down

0 comments on commit 231bed2

Please sign in to comment.