gamin opens too many files

Chuck Swiger cswiger at
Wed Mar 29 14:24:46 UTC 2006

Alex Dupre wrote:
> David Syphers wrote:
>> I recently was getting messages about maxing out the number of open files on 
>> my system, and discovered that gam_server has gone crazy. Right after 
>> booting, opening KDE, I have nearly 2600 open files on my computer, and 2200 
>> of those are opened by gam_server, according to fstat. And clearly that 
>> number can go up to nearly 8000, as I've got kern.maxfiles at 8136.
> That's absolutely normal for KDE. It will monitor many directories
> (/etc, your home, your desktop, some share dirs), so you have to
> increase the kern.maxfiles parameter as suggested by gamin's pkg-message.

Whoever wrote gamin should read "excessive use of fstat() considered harmful
when using distributed filesystems".  :-)

I don't expect to run KDE/gamin myself, so I'm not going write a specific patch,
but someone interested in fixing gamin to not consume thousands of file
descriptors could start with:

    struct rlimit rl;

    if (getrlimit(RLIMIT_NOFILE, 0) == 0) {
        printf("number of file descriptors available: %d\n", rl.rlim_cur);
    } else {
        perror("FATAL: getrlimit() call failed");

...and pay attention to rl.rlim_cur-- ie, monitor no more files than 80% of that
value.  If this gam_server is running with superuser permissions (why?), perhaps
consuming up to 50% of rl.rlim_max might not be completely unreasonable.


More information about the freebsd-ports mailing list