2004-10-28 18:03:27

by Joseph Pingenot

[permalink] [raw]
Subject: Max groups one can be a member of linux/sched.h and NGROUPS_SMALL

Hello.

In my quest to try and figure out the max number of groups one can be a
member of (and to learn more about the kernel internals), I stumbled
across the following tidbit:

(excerpted from linux/sched.h)
#define NGROUPS_SMALL 32
#define NGROUPS_PER_BLOCK ((int)(PAGE_SIZE / sizeof(gid_t)))
struct group_info {
int ngroups;
atomic_t usage;
gid_t small_block[NGROUPS_SMALL];
int nblocks;
gid_t *blocks[0];
};

This seems to be the place where group information is stored (linked to from
task_struct).

So, it appears to hold 32 gids, but what is this blocks bit? Is 32 the max
number of groups one can be a member of?

Thanks!

-Joseph

--
Joseph===============================================trelane@digitasaru.net
Graduate Student in Physics, Freelance Free Software Developer


2004-10-28 18:22:49

by Tim Hockin

[permalink] [raw]
Subject: Re: Max groups one can be a member of linux/sched.h and NGROUPS_SMALL

On Thu, Oct 28, 2004 at 01:02:30PM -0500, Joseph Pingenot wrote:
> #define NGROUPS_SMALL 32
> #define NGROUPS_PER_BLOCK ((int)(PAGE_SIZE / sizeof(gid_t)))
> struct group_info {
> int ngroups;
> atomic_t usage;
> gid_t small_block[NGROUPS_SMALL];
> int nblocks;
> gid_t *blocks[0];
> };

> So, it appears to hold 32 gids, but what is this blocks bit? Is 32 the max
> number of groups one can be a member of?

By default, every task has enough room for 32 gids. If you need more than
32, it uses a dynamically allocated 2-d array, stored in blocks. Always
use the GROUP_AT() macro, and you can treat it like a 1-d array. I think
there is a hardlimit of 64k groups, but that is simply a #define that can
be changed. You can have as many groups as you need, dynamically
allocated per-task, with CoW between tasks. Sorted and bsearch()ed.