2 * Copyright (c) 1982, 1986, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include "opt_compat.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/sysproto.h>
46 #include <sys/kernel.h>
48 #include <sys/malloc.h>
49 #include <sys/mutex.h>
51 #include <sys/refcount.h>
52 #include <sys/resourcevar.h>
53 #include <sys/sched.h>
55 #include <sys/syscallsubr.h>
56 #include <sys/sysent.h>
60 #include <vm/vm_param.h>
62 #include <vm/vm_map.h>
65 static MALLOC_DEFINE(M_PLIMIT, "plimit", "plimit structures");
66 static MALLOC_DEFINE(M_UIDINFO, "uidinfo", "uidinfo structures");
67 #define UIHASH(uid) (&uihashtbl[(uid) & uihash])
68 static struct mtx uihashtbl_mtx;
69 static LIST_HEAD(uihashhead, uidinfo) *uihashtbl;
70 static u_long uihash; /* size of hash table - 1 */
72 static void calcru1(struct proc *p, struct rusage_ext *ruxp,
73 struct timeval *up, struct timeval *sp);
74 static int donice(struct thread *td, struct proc *chgp, int n);
75 static struct uidinfo *uilookup(uid_t uid);
78 * Resource controls and accounting.
81 #ifndef _SYS_SYSPROTO_H_
82 struct getpriority_args {
93 register struct getpriority_args *uap;
101 switch (uap->which) {
105 low = td->td_proc->p_nice;
110 if (p_cansee(td, p) == 0)
117 sx_slock(&proctree_lock);
119 pg = td->td_proc->p_pgrp;
122 pg = pgfind(uap->who);
124 sx_sunlock(&proctree_lock);
128 sx_sunlock(&proctree_lock);
129 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
131 if (!p_cansee(td, p)) {
142 uap->who = td->td_ucred->cr_uid;
143 sx_slock(&allproc_lock);
144 LIST_FOREACH(p, &allproc, p_list) {
146 if (!p_cansee(td, p) &&
147 p->p_ucred->cr_uid == uap->who) {
153 sx_sunlock(&allproc_lock);
160 if (low == PRIO_MAX + 1 && error == 0)
162 td->td_retval[0] = low;
166 #ifndef _SYS_SYSPROTO_H_
167 struct setpriority_args {
179 struct setpriority_args *uap;
181 struct proc *curp, *p;
183 int found = 0, error = 0;
186 switch (uap->which) {
190 error = donice(td, curp, uap->prio);
196 if (p_cansee(td, p) == 0)
197 error = donice(td, p, uap->prio);
204 sx_slock(&proctree_lock);
209 pg = pgfind(uap->who);
211 sx_sunlock(&proctree_lock);
215 sx_sunlock(&proctree_lock);
216 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
218 if (!p_cansee(td, p)) {
219 error = donice(td, p, uap->prio);
229 uap->who = td->td_ucred->cr_uid;
230 sx_slock(&allproc_lock);
231 FOREACH_PROC_IN_SYSTEM(p) {
233 if (p->p_ucred->cr_uid == uap->who &&
235 error = donice(td, p, uap->prio);
240 sx_sunlock(&allproc_lock);
247 if (found == 0 && error == 0)
253 * Set "nice" for a (whole) process.
256 donice(struct thread *td, struct proc *p, int n)
260 PROC_LOCK_ASSERT(p, MA_OWNED);
261 if ((error = p_cansched(td, p)))
267 if (n < p->p_nice && suser(td) != 0)
269 mtx_lock_spin(&sched_lock);
271 mtx_unlock_spin(&sched_lock);
276 * Set realtime priority.
280 #ifndef _SYS_SYSPROTO_H_
290 struct thread *td; /* curthread */
291 register struct rtprio_args *uap;
299 /* Perform copyin before acquiring locks if needed. */
300 if (uap->function == RTP_SET)
301 cierror = copyin(uap->rtp, &rtp, sizeof(struct rtprio));
315 switch (uap->function) {
317 if ((error = p_cansee(td, p)))
319 mtx_lock_spin(&sched_lock);
321 * Return OUR priority if no pid specified,
322 * or if one is, report the highest priority
323 * in the process. There isn't much more you can do as
324 * there is only room to return a single priority.
325 * XXXKSE: maybe need a new interface to report
326 * priorities of multiple system scope threads.
327 * Note: specifying our own pid is not the same
328 * as leaving it zero.
331 pri_to_rtp(td->td_ksegrp, &rtp);
335 rtp.type = RTP_PRIO_IDLE;
336 rtp.prio = RTP_PRIO_MAX;
337 FOREACH_KSEGRP_IN_PROC(p, kg) {
338 pri_to_rtp(kg, &rtp2);
339 if (rtp2.type < rtp.type ||
340 (rtp2.type == rtp.type &&
341 rtp2.prio < rtp.prio)) {
342 rtp.type = rtp2.type;
343 rtp.prio = rtp2.prio;
347 mtx_unlock_spin(&sched_lock);
349 return (copyout(&rtp, uap->rtp, sizeof(struct rtprio)));
351 if ((error = p_cansched(td, p)) || (error = cierror))
354 /* Disallow setting rtprio in most cases if not superuser. */
355 if (suser(td) != 0) {
356 /* can't set someone else's */
361 /* can't set realtime priority */
363 * Realtime priority has to be restricted for reasons which should be
364 * obvious. However, for idle priority, there is a potential for
365 * system deadlock if an idleprio process gains a lock on a resource
366 * that other processes need (and the idleprio process can't run
367 * due to a CPU-bound normal process). Fix me! XXX
370 if (RTP_PRIO_IS_REALTIME(rtp.type)) {
372 if (rtp.type != RTP_PRIO_NORMAL) {
380 * If we are setting our own priority, set just our
381 * KSEGRP but if we are doing another process,
382 * do all the groups on that process. If we
383 * specify our own pid we do the latter.
385 mtx_lock_spin(&sched_lock);
387 error = rtp_to_pri(&rtp, td->td_ksegrp);
389 FOREACH_KSEGRP_IN_PROC(p, kg) {
390 if ((error = rtp_to_pri(&rtp, kg)) != 0) {
395 mtx_unlock_spin(&sched_lock);
406 rtp_to_pri(struct rtprio *rtp, struct ksegrp *kg)
409 mtx_assert(&sched_lock, MA_OWNED);
410 if (rtp->prio > RTP_PRIO_MAX)
412 switch (RTP_PRIO_BASE(rtp->type)) {
413 case RTP_PRIO_REALTIME:
414 kg->kg_user_pri = PRI_MIN_REALTIME + rtp->prio;
416 case RTP_PRIO_NORMAL:
417 kg->kg_user_pri = PRI_MIN_TIMESHARE + rtp->prio;
420 kg->kg_user_pri = PRI_MIN_IDLE + rtp->prio;
425 sched_class(kg, rtp->type);
426 if (curthread->td_ksegrp == kg) {
427 sched_prio(curthread, kg->kg_user_pri); /* XXX dubious */
433 pri_to_rtp(struct ksegrp *kg, struct rtprio *rtp)
436 mtx_assert(&sched_lock, MA_OWNED);
437 switch (PRI_BASE(kg->kg_pri_class)) {
439 rtp->prio = kg->kg_user_pri - PRI_MIN_REALTIME;
442 rtp->prio = kg->kg_user_pri - PRI_MIN_TIMESHARE;
445 rtp->prio = kg->kg_user_pri - PRI_MIN_IDLE;
450 rtp->type = kg->kg_pri_class;
453 #if defined(COMPAT_43)
454 #ifndef _SYS_SYSPROTO_H_
455 struct osetrlimit_args {
466 register struct osetrlimit_args *uap;
472 if ((error = copyin(uap->rlp, &olim, sizeof(struct orlimit))))
474 lim.rlim_cur = olim.rlim_cur;
475 lim.rlim_max = olim.rlim_max;
476 error = kern_setrlimit(td, uap->which, &lim);
480 #ifndef _SYS_SYSPROTO_H_
481 struct ogetrlimit_args {
492 register struct ogetrlimit_args *uap;
499 if (uap->which >= RLIM_NLIMITS)
503 lim_rlimit(p, uap->which, &rl);
507 * XXX would be more correct to convert only RLIM_INFINITY to the
508 * old RLIM_INFINITY and fail with EOVERFLOW for other larger
509 * values. Most 64->32 and 32->16 conversions, including not
510 * unimportant ones of uids are even more broken than what we
511 * do here (they blindly truncate). We don't do this correctly
512 * here since we have little experience with EOVERFLOW yet.
513 * Elsewhere, getuid() can't fail...
515 olim.rlim_cur = rl.rlim_cur > 0x7fffffff ? 0x7fffffff : rl.rlim_cur;
516 olim.rlim_max = rl.rlim_max > 0x7fffffff ? 0x7fffffff : rl.rlim_max;
517 error = copyout(&olim, uap->rlp, sizeof(olim));
520 #endif /* COMPAT_43 */
522 #ifndef _SYS_SYSPROTO_H_
523 struct __setrlimit_args {
534 register struct __setrlimit_args *uap;
539 if ((error = copyin(uap->rlp, &alim, sizeof(struct rlimit))))
541 error = kern_setrlimit(td, uap->which, &alim);
546 kern_setrlimit(td, which, limp)
551 struct plimit *newlim, *oldlim;
553 register struct rlimit *alimp;
557 if (which >= RLIM_NLIMITS)
561 * Preserve historical bugs by treating negative limits as unsigned.
563 if (limp->rlim_cur < 0)
564 limp->rlim_cur = RLIM_INFINITY;
565 if (limp->rlim_max < 0)
566 limp->rlim_max = RLIM_INFINITY;
570 newlim = lim_alloc();
573 alimp = &oldlim->pl_rlimit[which];
574 if (limp->rlim_cur > alimp->rlim_max ||
575 limp->rlim_max > alimp->rlim_max)
576 if ((error = suser_cred(td->td_ucred, SUSER_ALLOWJAIL))) {
581 if (limp->rlim_cur > limp->rlim_max)
582 limp->rlim_cur = limp->rlim_max;
583 lim_copy(newlim, oldlim);
584 alimp = &newlim->pl_rlimit[which];
589 mtx_lock_spin(&sched_lock);
590 p->p_cpulimit = limp->rlim_cur;
591 mtx_unlock_spin(&sched_lock);
594 if (limp->rlim_cur > maxdsiz)
595 limp->rlim_cur = maxdsiz;
596 if (limp->rlim_max > maxdsiz)
597 limp->rlim_max = maxdsiz;
601 if (limp->rlim_cur > maxssiz)
602 limp->rlim_cur = maxssiz;
603 if (limp->rlim_max > maxssiz)
604 limp->rlim_max = maxssiz;
605 oldssiz = alimp->rlim_cur;
609 if (limp->rlim_cur > maxfilesperproc)
610 limp->rlim_cur = maxfilesperproc;
611 if (limp->rlim_max > maxfilesperproc)
612 limp->rlim_max = maxfilesperproc;
616 if (limp->rlim_cur > maxprocperuid)
617 limp->rlim_cur = maxprocperuid;
618 if (limp->rlim_max > maxprocperuid)
619 limp->rlim_max = maxprocperuid;
620 if (limp->rlim_cur < 1)
622 if (limp->rlim_max < 1)
631 if (which == RLIMIT_STACK) {
633 * Stack is allocated to the max at exec time with only
634 * "rlim_cur" bytes accessible. If stack limit is going
635 * up make more accessible, if going down make inaccessible.
637 if (limp->rlim_cur != oldssiz) {
642 if (limp->rlim_cur > oldssiz) {
643 prot = p->p_sysent->sv_stackprot;
644 size = limp->rlim_cur - oldssiz;
645 addr = p->p_sysent->sv_usrstack -
649 size = oldssiz - limp->rlim_cur;
650 addr = p->p_sysent->sv_usrstack - oldssiz;
652 addr = trunc_page(addr);
653 size = round_page(size);
654 (void)vm_map_protect(&p->p_vmspace->vm_map,
655 addr, addr + size, prot, FALSE);
660 * The data size limit may need to be changed to a value
661 * that makes sense for the 32 bit binary.
663 if (p->p_sysent->sv_fixlimits != NULL)
664 p->p_sysent->sv_fixlimits(p);
668 #ifndef _SYS_SYSPROTO_H_
669 struct __getrlimit_args {
681 register struct __getrlimit_args *uap;
687 if (uap->which >= RLIM_NLIMITS)
691 lim_rlimit(p, uap->which, &rlim);
693 error = copyout(&rlim, uap->rlp, sizeof(struct rlimit));
698 * Transform the running time and tick information for children of proc p
699 * into user and system time usage.
708 PROC_LOCK_ASSERT(p, MA_OWNED);
709 calcru1(p, &p->p_crux, up, sp);
713 * Transform the running time and tick information in proc p into user
714 * and system time usage. If appropriate, include the current time slice
718 calcru(struct proc *p, struct timeval *up, struct timeval *sp)
720 struct rusage_ext rux;
724 PROC_LOCK_ASSERT(p, MA_OWNED);
725 mtx_assert(&sched_lock, MA_NOTOWNED);
726 mtx_lock_spin(&sched_lock);
729 * If we are getting stats for the current process, then add in the
730 * stats that this thread has accumulated in its current time slice.
731 * We reset the thread and CPU state as if we had performed a context
734 if (curthread->td_proc == p) {
737 p->p_rux.rux_runtime += u - PCPU_GET(switchtime);
738 PCPU_SET(switchtime, u);
739 p->p_rux.rux_uticks += td->td_uticks;
741 p->p_rux.rux_iticks += td->td_iticks;
743 p->p_rux.rux_sticks += td->td_sticks;
746 /* Work on a copy of p_rux so we can let go of sched_lock */
748 mtx_unlock_spin(&sched_lock);
749 calcru1(p, &rux, up, sp);
750 /* Update the result from the p_rux copy */
751 p->p_rux.rux_uu = rux.rux_uu;
752 p->p_rux.rux_su = rux.rux_su;
753 p->p_rux.rux_tu = rux.rux_tu;
757 calcru1(struct proc *p, struct rusage_ext *ruxp, struct timeval *up,
760 /* {user, system, interrupt, total} {ticks, usec}: */
761 u_int64_t ut, uu, st, su, it, tt, tu;
763 ut = ruxp->rux_uticks;
764 st = ruxp->rux_sticks;
765 it = ruxp->rux_iticks;
768 /* Avoid divide by zero */
772 tu = cputick2usec(ruxp->rux_runtime);
773 if ((int64_t)tu < 0) {
774 /* XXX: this should be an assert /phk */
775 printf("calcru: negative runtime of %jd usec for pid %d (%s)\n",
776 (intmax_t)tu, p->p_pid, p->p_comm);
780 if (tu >= ruxp->rux_tu) {
782 * The normal case, time increased.
783 * Enforce monotonicity of bucketed numbers.
786 if (uu < ruxp->rux_uu)
789 if (su < ruxp->rux_su)
791 } else if (tu + 3 > ruxp->rux_tu || 101 * tu > 100 * ruxp->rux_tu) {
793 * When we calibrate the cputicker, it is not uncommon to
794 * see the presumably fixed frequency increase slightly over
795 * time as a result of thermal stabilization and NTP
796 * discipline (of the reference clock). We therefore ignore
797 * a bit of backwards slop because we expect to catch up
798 * shortly. We use a 3 microsecond limit to catch low
799 * counts and a 1% limit for high counts.
804 } else { /* tu < ruxp->rux_tu */
806 * What happene here was likely that a laptop, which ran at
807 * a reduced clock frequency at boot, kicked into high gear.
808 * The wisdom of spamming this message in that case is
809 * dubious, but it might also be indicative of something
810 * serious, so lets keep it and hope laptops can be made
811 * more truthful about their CPU speed via ACPI.
813 printf("calcru: runtime went backwards from %ju usec "
814 "to %ju usec for pid %d (%s)\n",
815 (uintmax_t)ruxp->rux_tu, (uintmax_t)tu,
816 p->p_pid, p->p_comm);
825 up->tv_sec = uu / 1000000;
826 up->tv_usec = uu % 1000000;
827 sp->tv_sec = su / 1000000;
828 sp->tv_usec = su % 1000000;
831 #ifndef _SYS_SYSPROTO_H_
832 struct getrusage_args {
834 struct rusage *rusage;
842 register struct thread *td;
843 register struct getrusage_args *uap;
848 error = kern_getrusage(td, uap->who, &ru);
850 error = copyout(&ru, uap->rusage, sizeof(struct rusage));
855 kern_getrusage(td, who, rup)
867 *rup = p->p_stats->p_ru;
868 calcru(p, &rup->ru_utime, &rup->ru_stime);
871 case RUSAGE_CHILDREN:
872 *rup = p->p_stats->p_cru;
873 calccru(p, &rup->ru_utime, &rup->ru_stime);
885 ruadd(ru, rux, ru2, rux2)
887 struct rusage_ext *rux;
889 struct rusage_ext *rux2;
891 register long *ip, *ip2;
894 rux->rux_runtime += rux2->rux_runtime;
895 rux->rux_uticks += rux2->rux_uticks;
896 rux->rux_sticks += rux2->rux_sticks;
897 rux->rux_iticks += rux2->rux_iticks;
898 rux->rux_uu += rux2->rux_uu;
899 rux->rux_su += rux2->rux_su;
900 rux->rux_tu += rux2->rux_tu;
901 if (ru->ru_maxrss < ru2->ru_maxrss)
902 ru->ru_maxrss = ru2->ru_maxrss;
904 ip2 = &ru2->ru_first;
905 for (i = &ru->ru_last - &ru->ru_first; i >= 0; i--)
910 * Allocate a new resource limits structure and initialize its
911 * reference count and mutex pointer.
918 limp = malloc(sizeof(struct plimit), M_PLIMIT, M_WAITOK);
919 refcount_init(&limp->pl_refcnt, 1);
928 refcount_acquire(&limp->pl_refcnt);
937 KASSERT(limp->pl_refcnt > 0, ("plimit refcnt underflow"));
938 if (refcount_release(&limp->pl_refcnt))
939 free((void *)limp, M_PLIMIT);
943 * Make a copy of the plimit structure.
944 * We share these structures copy-on-write after fork.
948 struct plimit *dst, *src;
951 KASSERT(dst->pl_refcnt == 1, ("lim_copy to shared limit"));
952 bcopy(src->pl_rlimit, dst->pl_rlimit, sizeof(src->pl_rlimit));
956 * Return the hard limit for a particular system resource. The
957 * which parameter specifies the index into the rlimit array.
960 lim_max(struct proc *p, int which)
964 lim_rlimit(p, which, &rl);
965 return (rl.rlim_max);
969 * Return the current (soft) limit for a particular system resource.
970 * The which parameter which specifies the index into the rlimit array
973 lim_cur(struct proc *p, int which)
977 lim_rlimit(p, which, &rl);
978 return (rl.rlim_cur);
982 * Return a copy of the entire rlimit structure for the system limit
983 * specified by 'which' in the rlimit structure pointed to by 'rlp'.
986 lim_rlimit(struct proc *p, int which, struct rlimit *rlp)
989 PROC_LOCK_ASSERT(p, MA_OWNED);
990 KASSERT(which >= 0 && which < RLIM_NLIMITS,
991 ("request for invalid resource limit"));
992 *rlp = p->p_limit->pl_rlimit[which];
996 * Find the uidinfo structure for a uid. This structure is used to
997 * track the total resource consumption (process count, socket buffer
998 * size, etc.) for the uid and impose limits.
1004 uihashtbl = hashinit(maxproc / 16, M_UIDINFO, &uihash);
1005 mtx_init(&uihashtbl_mtx, "uidinfo hash", NULL, MTX_DEF);
1009 * Look up a uidinfo struct for the parameter uid.
1010 * uihashtbl_mtx must be locked.
1012 static struct uidinfo *
1016 struct uihashhead *uipp;
1017 struct uidinfo *uip;
1019 mtx_assert(&uihashtbl_mtx, MA_OWNED);
1021 LIST_FOREACH(uip, uipp, ui_hash)
1022 if (uip->ui_uid == uid)
1029 * Find or allocate a struct uidinfo for a particular uid.
1030 * Increase refcount on uidinfo struct returned.
1031 * uifree() should be called on a struct uidinfo when released.
1037 struct uidinfo *old_uip, *uip;
1039 mtx_lock(&uihashtbl_mtx);
1040 uip = uilookup(uid);
1042 mtx_unlock(&uihashtbl_mtx);
1043 uip = malloc(sizeof(*uip), M_UIDINFO, M_WAITOK | M_ZERO);
1044 mtx_lock(&uihashtbl_mtx);
1046 * There's a chance someone created our uidinfo while we
1047 * were in malloc and not holding the lock, so we have to
1048 * make sure we don't insert a duplicate uidinfo.
1050 if ((old_uip = uilookup(uid)) != NULL) {
1051 /* Someone else beat us to it. */
1052 free(uip, M_UIDINFO);
1055 uip->ui_mtxp = mtx_pool_alloc(mtxpool_sleep);
1057 LIST_INSERT_HEAD(UIHASH(uid), uip, ui_hash);
1061 mtx_unlock(&uihashtbl_mtx);
1066 * Place another refcount on a uidinfo struct.
1070 struct uidinfo *uip;
1075 UIDINFO_UNLOCK(uip);
1079 * Since uidinfo structs have a long lifetime, we use an
1080 * opportunistic refcounting scheme to avoid locking the lookup hash
1083 * If the refcount hits 0, we need to free the structure,
1084 * which means we need to lock the hash.
1086 * After locking the struct and lowering the refcount, if we find
1087 * that we don't need to free, simply unlock and return.
1089 * If refcount lowering results in need to free, bump the count
1090 * back up, loose the lock and aquire the locks in the proper
1091 * order to try again.
1095 struct uidinfo *uip;
1098 /* Prepare for optimal case. */
1101 if (--uip->ui_ref != 0) {
1102 UIDINFO_UNLOCK(uip);
1106 /* Prepare for suboptimal case. */
1108 UIDINFO_UNLOCK(uip);
1109 mtx_lock(&uihashtbl_mtx);
1113 * We must subtract one from the count again because we backed out
1114 * our initial subtraction before dropping the lock.
1115 * Since another thread may have added a reference after we dropped the
1116 * initial lock we have to test for zero again.
1118 if (--uip->ui_ref == 0) {
1119 LIST_REMOVE(uip, ui_hash);
1120 mtx_unlock(&uihashtbl_mtx);
1121 if (uip->ui_sbsize != 0)
1122 printf("freeing uidinfo: uid = %d, sbsize = %jd\n",
1123 uip->ui_uid, (intmax_t)uip->ui_sbsize);
1124 if (uip->ui_proccnt != 0)
1125 printf("freeing uidinfo: uid = %d, proccnt = %ld\n",
1126 uip->ui_uid, uip->ui_proccnt);
1127 UIDINFO_UNLOCK(uip);
1128 FREE(uip, M_UIDINFO);
1132 mtx_unlock(&uihashtbl_mtx);
1133 UIDINFO_UNLOCK(uip);
1137 * Change the count associated with number of processes
1138 * a given user is using. When 'max' is 0, don't enforce a limit
1141 chgproccnt(uip, diff, max)
1142 struct uidinfo *uip;
1148 /* Don't allow them to exceed max, but allow subtraction. */
1149 if (diff > 0 && uip->ui_proccnt + diff > max && max != 0) {
1150 UIDINFO_UNLOCK(uip);
1153 uip->ui_proccnt += diff;
1154 if (uip->ui_proccnt < 0)
1155 printf("negative proccnt for uid = %d\n", uip->ui_uid);
1156 UIDINFO_UNLOCK(uip);
1161 * Change the total socket buffer size a user has used.
1164 chgsbsize(uip, hiwat, to, max)
1165 struct uidinfo *uip;
1173 new = uip->ui_sbsize + to - *hiwat;
1174 /* Don't allow them to exceed max, but allow subtraction. */
1175 if (to > *hiwat && new > max) {
1176 UIDINFO_UNLOCK(uip);
1179 uip->ui_sbsize = new;
1180 UIDINFO_UNLOCK(uip);
1183 printf("negative sbsize for uid = %d\n", uip->ui_uid);