svn commit: r256849 - in head/sys: kern sys

Jilles Tjoelker jilles at stack.nl
Sat Nov 2 21:17:31 UTC 2013


On Mon, Oct 21, 2013 at 04:44:53PM +0000, Konstantin Belousov wrote:
> Author: kib
> Date: Mon Oct 21 16:44:53 2013
> New Revision: 256849
> URL: http://svnweb.freebsd.org/changeset/base/256849

> Log:
>   Add a resource limit for the total number of kqueues available to the
>   user.  Kqueue now saves the ucred of the allocating thread, to
>   correctly decrement the counter on close.

>   Under some specific and not real-world use scenario for kqueue, it is
>   possible for the kqueues to consume memory proportional to the square
>   of the number of the filedescriptors available to the process.  Limit
>   allows administrator to prevent the abuse.

>   This is kernel-mode side of the change, with the user-mode enabling
>   commit following.

>   Reported and tested by:	pho
>   Discussed with:	jmg
>   Sponsored by:	The FreeBSD Foundation
>   MFC after:	2 weeks

> [snip]
> +	if (!chgkqcnt(cred->cr_ruidinfo, 1, lim_cur(td->td_proc,
> +	    RLIMIT_KQUEUES))) {
> +		PROC_UNLOCK(p);
> +		crfree(cred);
> +		return (EMFILE);
> +	}

Perhaps this error should be [ENOMEM] instead of [EMFILE] as it is
unrelated to the number of file descriptors in the process. This error
is already listed in the kqueue(2) man page but appears to be not
generated. The rlimit can then be mentioned in the man page.

-- 
Jilles Tjoelker


More information about the svn-src-all mailing list