diff options
author | kib <kib@FreeBSD.org> | 2013-10-21 16:46:12 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2013-10-21 16:46:12 +0000 |
commit | 734382a525a0efc40130c452c5a765dc2249ad55 (patch) | |
tree | 04786befd82e74b0298aa6139cca4192ba215854 /usr.bin | |
parent | 80e669df9e8ddb312b35886be11c306ee738b4f1 (diff) | |
download | FreeBSD-src-734382a525a0efc40130c452c5a765dc2249ad55.zip FreeBSD-src-734382a525a0efc40130c452c5a765dc2249ad55.tar.gz |
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
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/limits/limits.c | 16 | ||||
-rw-r--r-- | usr.bin/procstat/procstat_rlimit.c | 5 |
2 files changed, 14 insertions, 7 deletions
diff --git a/usr.bin/limits/limits.c b/usr.bin/limits/limits.c index 3c5fd6d..8316743 100644 --- a/usr.bin/limits/limits.c +++ b/usr.bin/limits/limits.c @@ -89,7 +89,8 @@ static struct { { " sbsize%-4s %8s", " bytes\n", 1 }, { " vmemoryuse%-4s %8s", " kB\n", 1024 }, { " pseudo-terminals%-4s %8s", "\n", 1 }, - { " swapuse%-4s %8s", " kB\n", 1024 } + { " swapuse%-4s %8s", " kB\n", 1024 }, + { " kqueues%-4s %8s", "\n", 1 }, } }, { "sh", "unlimited", "", " -H", " -S", "", @@ -106,7 +107,8 @@ static struct { { "ulimit%s -b %s", ";\n", 1 }, { "ulimit%s -v %s", ";\n", 1024 }, { "ulimit%s -p %s", ";\n", 1 }, - { "ulimit%s -w %s", ";\n", 1024 } + { "ulimit%s -w %s", ";\n", 1024 }, + { "ulimit%s -k %s", ";\n", 1 }, } }, { "csh", "unlimited", "", " -h", "", NULL, @@ -123,7 +125,8 @@ static struct { { "limit%s sbsize %s", ";\n", 1 }, { "limit%s vmemoryuse %s", ";\n", 1024 }, { "limit%s pseudoterminals %s", ";\n", 1 }, - { "limit%s swapuse %s", ";\n", 1024 } + { "limit%s swapuse %s", ";\n", 1024 }, + { "limit%s kqueues %s", ";\n", 1 }, } }, { "bash|bash2", "unlimited", "", " -H", " -S", "", @@ -157,7 +160,8 @@ static struct { { "limit%s sbsize %s", ";\n", 1 }, { "limit%s vmemoryuse %s", ";\n", 1024 }, { "limit%s pseudoterminals %s", ";\n", 1 }, - { "limit%s swapuse %s", ";\n", 1024 } + { "limit%s swapuse %s", ";\n", 1024 }, + { "limit%s kqueues %s", ";\n", 1 }, } }, { "ksh|pdksh", "unlimited", "", " -H", " -S", "", @@ -232,7 +236,8 @@ static struct { { "sbsize", login_getcapsize }, { "vmemoryuse", login_getcapsize }, { "pseudoterminals",login_getcapnum }, - { "swapuse", login_getcapsize } + { "swapuse", login_getcapsize }, + { "kqueues", login_getcapnum }, }; /* @@ -647,6 +652,7 @@ resource_num(int which, int ch, const char *str) case RLIMIT_NPROC: case RLIMIT_NOFILE: case RLIMIT_NPTS: + case RLIMIT_KQUEUES: res = strtoq(s, &e, 0); s = e; break; diff --git a/usr.bin/procstat/procstat_rlimit.c b/usr.bin/procstat/procstat_rlimit.c index f3ed5fc..f7f67af 100644 --- a/usr.bin/procstat/procstat_rlimit.c +++ b/usr.bin/procstat/procstat_rlimit.c @@ -46,7 +46,7 @@ static struct { const char *name; const char *suffix; -} rlimit_param[13] = { +} rlimit_param[14] = { {"cputime", "sec"}, {"filesize", "B "}, {"datasize", "B "}, @@ -60,9 +60,10 @@ static struct { {"vmemoryuse", "B "}, {"pseudo-terminals", " "}, {"swapuse", "B "}, + {"kqueues", " "}, }; -#if RLIM_NLIMITS > 13 +#if RLIM_NLIMITS > 14 #error "Resource limits have grown. Add new entries to rlimit_param[]." #endif |