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
Signature · 2 lines
Joseph===============================================trelane@digitasaru.net
Graduate Student in Physics, Freelance Free Software DeveloperQuoted 10 lines · Joseph Pingenot
#define
NGROUPS_SMALL32
#defineNGROUPS_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]; };
Quoted 2 lines
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.