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 * 3. 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
35 * $FreeBSD: src/sys/kern/kern_resource.c,v 1.55.2.5 2001/11/03 01:41:08 ps Exp $
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/sysmsg.h>
42 #include <sys/kernel.h>
43 #include <sys/resourcevar.h>
44 #include <sys/malloc.h>
48 #include <sys/lockf.h>
51 #include <vm/vm_param.h>
54 #include <vm/vm_map.h>
56 #include <sys/thread2.h>
57 #include <sys/spinlock2.h>
59 static int donice (struct proc
*chgp
, int n
);
60 static int doionice (struct proc
*chgp
, int n
);
62 static MALLOC_DEFINE(M_UIDINFO
, "uidinfo", "uidinfo structures");
63 #define UIHASH(uid) (&uihashtbl[(uid) & uihash])
64 static struct spinlock uihash_lock
;
65 static LIST_HEAD(uihashhead
, uidinfo
) *uihashtbl
;
66 static u_long uihash
; /* size of hash table - 1 */
68 static struct uidinfo
*uilookup (uid_t uid
);
71 * Resource controls and accounting.
74 struct getpriority_info
{
79 static int getpriority_callback(struct proc
*p
, void *data
);
85 sys_getpriority(struct sysmsg
*sysmsg
, const struct getpriority_args
*uap
)
87 struct getpriority_info info
;
88 thread_t curtd
= curthread
;
89 struct proc
*curp
= curproc
;
92 int low
= PRIO_MAX
+ 1;
103 lwkt_gettoken_shared(&p
->p_token
);
104 if (PRISON_CHECK(curtd
->td_ucred
, p
->p_ucred
))
106 lwkt_reltoken(&p
->p_token
);
113 lwkt_gettoken_shared(&curp
->p_token
);
116 lwkt_reltoken(&curp
->p_token
);
117 } else if ((pg
= pgfind(who
)) == NULL
) {
119 } /* else ref held from pgfind */
121 lwkt_gettoken_shared(&pg
->pg_token
);
122 LIST_FOREACH(p
, &pg
->pg_members
, p_pglist
) {
123 if (PRISON_CHECK(curtd
->td_ucred
, p
->p_ucred
) &&
128 lwkt_reltoken(&pg
->pg_token
);
133 who
= curtd
->td_ucred
->cr_uid
;
136 allproc_scan(getpriority_callback
, &info
, 0);
144 if (low
== PRIO_MAX
+ 1) {
148 sysmsg
->sysmsg_result
= low
;
155 * Figure out the current lowest nice priority for processes owned
156 * by the specified user.
160 getpriority_callback(struct proc
*p
, void *data
)
162 struct getpriority_info
*info
= data
;
164 lwkt_gettoken_shared(&p
->p_token
);
165 if (PRISON_CHECK(curthread
->td_ucred
, p
->p_ucred
) &&
166 p
->p_ucred
->cr_uid
== info
->who
&&
167 p
->p_nice
< info
->low
) {
168 info
->low
= p
->p_nice
;
170 lwkt_reltoken(&p
->p_token
);
174 struct setpriority_info
{
181 static int setpriority_callback(struct proc
*p
, void *data
);
187 sys_setpriority(struct sysmsg
*sysmsg
, const struct setpriority_args
*uap
)
189 struct setpriority_info info
;
190 thread_t curtd
= curthread
;
191 struct proc
*curp
= curproc
;
194 int found
= 0, error
= 0;
197 switch (uap
->which
) {
200 lwkt_gettoken(&curp
->p_token
);
201 error
= donice(curp
, uap
->prio
);
203 lwkt_reltoken(&curp
->p_token
);
207 lwkt_gettoken(&p
->p_token
);
208 if (PRISON_CHECK(curtd
->td_ucred
, p
->p_ucred
)) {
209 error
= donice(p
, uap
->prio
);
212 lwkt_reltoken(&p
->p_token
);
219 lwkt_gettoken_shared(&curp
->p_token
);
222 lwkt_reltoken(&curp
->p_token
);
223 } else if ((pg
= pgfind(who
)) == NULL
) {
225 } /* else ref held from pgfind */
227 lwkt_gettoken(&pg
->pg_token
);
229 LIST_FOREACH(p
, &pg
->pg_members
, p_pglist
) {
231 lwkt_gettoken(&p
->p_token
);
232 if (p
->p_pgrp
== pg
&&
233 PRISON_CHECK(curtd
->td_ucred
, p
->p_ucred
)) {
234 error
= donice(p
, uap
->prio
);
237 lwkt_reltoken(&p
->p_token
);
238 if (p
->p_pgrp
!= pg
) {
244 lwkt_reltoken(&pg
->pg_token
);
249 who
= curtd
->td_ucred
->cr_uid
;
250 info
.prio
= uap
->prio
;
254 allproc_scan(setpriority_callback
, &info
, 0);
271 setpriority_callback(struct proc
*p
, void *data
)
273 struct setpriority_info
*info
= data
;
276 lwkt_gettoken(&p
->p_token
);
277 if (p
->p_ucred
->cr_uid
== info
->who
&&
278 PRISON_CHECK(curthread
->td_ucred
, p
->p_ucred
)) {
279 error
= donice(p
, info
->prio
);
284 lwkt_reltoken(&p
->p_token
);
289 * Caller must hold chgp->p_token
292 donice(struct proc
*chgp
, int n
)
294 struct ucred
*cr
= curthread
->td_ucred
;
297 if (cr
->cr_uid
&& cr
->cr_ruid
&&
298 cr
->cr_uid
!= chgp
->p_ucred
->cr_uid
&&
299 cr
->cr_ruid
!= chgp
->p_ucred
->cr_uid
)
305 if (n
< chgp
->p_nice
&& caps_priv_check(cr
, SYSCAP_NOSCHED
))
308 FOREACH_LWP_IN_PROC(lp
, chgp
) {
310 chgp
->p_usched
->resetpriority(lp
);
317 struct ioprio_get_info
{
322 static int ioprio_get_callback(struct proc
*p
, void *data
);
328 sys_ioprio_get(struct sysmsg
*sysmsg
, const struct ioprio_get_args
*uap
)
330 struct ioprio_get_info info
;
331 thread_t curtd
= curthread
;
332 struct proc
*curp
= curproc
;
335 int high
= IOPRIO_MIN
-2;
339 switch (uap
->which
) {
342 high
= curp
->p_ionice
;
346 lwkt_gettoken_shared(&p
->p_token
);
347 if (PRISON_CHECK(curtd
->td_ucred
, p
->p_ucred
))
349 lwkt_reltoken(&p
->p_token
);
356 lwkt_gettoken_shared(&curp
->p_token
);
359 lwkt_reltoken(&curp
->p_token
);
360 } else if ((pg
= pgfind(who
)) == NULL
) {
362 } /* else ref held from pgfind */
364 lwkt_gettoken_shared(&pg
->pg_token
);
365 LIST_FOREACH(p
, &pg
->pg_members
, p_pglist
) {
366 if (PRISON_CHECK(curtd
->td_ucred
, p
->p_ucred
) &&
370 lwkt_reltoken(&pg
->pg_token
);
375 who
= curtd
->td_ucred
->cr_uid
;
378 allproc_scan(ioprio_get_callback
, &info
, 0);
385 if (high
== IOPRIO_MIN
-2) {
389 sysmsg
->sysmsg_result
= high
;
396 * Figure out the current lowest nice priority for processes owned
397 * by the specified user.
401 ioprio_get_callback(struct proc
*p
, void *data
)
403 struct ioprio_get_info
*info
= data
;
405 lwkt_gettoken_shared(&p
->p_token
);
406 if (PRISON_CHECK(curthread
->td_ucred
, p
->p_ucred
) &&
407 p
->p_ucred
->cr_uid
== info
->who
&&
408 p
->p_ionice
> info
->high
) {
409 info
->high
= p
->p_ionice
;
411 lwkt_reltoken(&p
->p_token
);
416 struct ioprio_set_info
{
423 static int ioprio_set_callback(struct proc
*p
, void *data
);
429 sys_ioprio_set(struct sysmsg
*sysmsg
, const struct ioprio_set_args
*uap
)
431 struct ioprio_set_info info
;
432 thread_t curtd
= curthread
;
433 struct proc
*curp
= curproc
;
436 int found
= 0, error
= 0;
439 switch (uap
->which
) {
442 lwkt_gettoken(&curp
->p_token
);
443 error
= doionice(curp
, uap
->prio
);
444 lwkt_reltoken(&curp
->p_token
);
449 lwkt_gettoken(&p
->p_token
);
450 if (PRISON_CHECK(curtd
->td_ucred
, p
->p_ucred
)) {
451 error
= doionice(p
, uap
->prio
);
454 lwkt_reltoken(&p
->p_token
);
461 lwkt_gettoken_shared(&curp
->p_token
);
464 lwkt_reltoken(&curp
->p_token
);
465 } else if ((pg
= pgfind(who
)) == NULL
) {
467 } /* else ref held from pgfind */
469 lwkt_gettoken(&pg
->pg_token
);
471 LIST_FOREACH(p
, &pg
->pg_members
, p_pglist
) {
473 lwkt_gettoken(&p
->p_token
);
474 if (p
->p_pgrp
== pg
&&
475 PRISON_CHECK(curtd
->td_ucred
, p
->p_ucred
)) {
476 error
= doionice(p
, uap
->prio
);
479 lwkt_reltoken(&p
->p_token
);
480 if (p
->p_pgrp
!= pg
) {
486 lwkt_reltoken(&pg
->pg_token
);
491 who
= curtd
->td_ucred
->cr_uid
;
492 info
.prio
= uap
->prio
;
496 allproc_scan(ioprio_set_callback
, &info
, 0);
513 ioprio_set_callback(struct proc
*p
, void *data
)
515 struct ioprio_set_info
*info
= data
;
518 lwkt_gettoken(&p
->p_token
);
519 if (p
->p_ucred
->cr_uid
== info
->who
&&
520 PRISON_CHECK(curthread
->td_ucred
, p
->p_ucred
)) {
521 error
= doionice(p
, info
->prio
);
526 lwkt_reltoken(&p
->p_token
);
531 doionice(struct proc
*chgp
, int n
)
533 struct ucred
*cr
= curthread
->td_ucred
;
535 if (cr
->cr_uid
&& cr
->cr_ruid
&&
536 cr
->cr_uid
!= chgp
->p_ucred
->cr_uid
&&
537 cr
->cr_ruid
!= chgp
->p_ucred
->cr_uid
)
543 if (n
< chgp
->p_ionice
&&
544 caps_priv_check(cr
, SYSCAP_NOSCHED
))
558 sys_lwp_rtprio(struct sysmsg
*sysmsg
, const struct lwp_rtprio_args
*uap
)
560 struct ucred
*cr
= curthread
->td_ucred
;
566 error
= copyin(uap
->rtp
, &rtp
, sizeof(struct rtprio
));
582 lwkt_gettoken(&p
->p_token
);
588 if (uap
->tid
== -1) {
590 * sadly, tid can be 0 so we can't use 0 here
593 lp
= curthread
->td_lwp
;
595 lp
= lwp_rb_tree_RB_LOOKUP(&p
->p_lwp_tree
, uap
->tid
);
603 * Make sure that this lwp is not ripped if any of the following
604 * code blocks, e.g. copyout.
607 switch (uap
->function
) {
609 error
= copyout(&lp
->lwp_rtprio
, uap
->rtp
,
610 sizeof(struct rtprio
));
613 if (cr
->cr_uid
&& cr
->cr_ruid
&&
614 cr
->cr_uid
!= p
->p_ucred
->cr_uid
&&
615 cr
->cr_ruid
!= p
->p_ucred
->cr_uid
) {
619 /* disallow setting rtprio in most cases if not superuser */
620 if (caps_priv_check(cr
, SYSCAP_NOSCHED
)) {
621 /* can't set someone else's */
622 if (uap
->pid
) { /* XXX */
626 /* can't set realtime priority */
628 * Realtime priority has to be restricted for reasons which should be
629 * obvious. However, for idle priority, there is a potential for
630 * system deadlock if an idleprio process gains a lock on a resource
631 * that other processes need (and the idleprio process can't run
632 * due to a CPU-bound normal process). Fix me! XXX
634 if (RTP_PRIO_IS_REALTIME(rtp
.type
)) {
643 case RTP_PRIO_REALTIME
:
644 case RTP_PRIO_NORMAL
:
646 if (rtp
.prio
> RTP_PRIO_MAX
) {
649 lp
->lwp_rtprio
= rtp
;
666 lwkt_reltoken(&p
->p_token
);
673 * Set realtime priority
678 sys_rtprio(struct sysmsg
*sysmsg
, const struct rtprio_args
*uap
)
680 struct ucred
*cr
= curthread
->td_ucred
;
686 error
= copyin(uap
->rtp
, &rtp
, sizeof(struct rtprio
));
701 lwkt_gettoken(&p
->p_token
);
704 lp
= FIRST_LWP_IN_PROC(p
);
705 switch (uap
->function
) {
707 error
= copyout(&lp
->lwp_rtprio
, uap
->rtp
,
708 sizeof(struct rtprio
));
711 if (cr
->cr_uid
&& cr
->cr_ruid
&&
712 cr
->cr_uid
!= p
->p_ucred
->cr_uid
&&
713 cr
->cr_ruid
!= p
->p_ucred
->cr_uid
) {
717 /* disallow setting rtprio in most cases if not superuser */
718 if (caps_priv_check(cr
, SYSCAP_NOSCHED
)) {
719 /* can't set someone else's */
724 /* can't set realtime priority */
726 * Realtime priority has to be restricted for reasons which should be
727 * obvious. However, for idle priority, there is a potential for
728 * system deadlock if an idleprio process gains a lock on a resource
729 * that other processes need (and the idleprio process can't run
730 * due to a CPU-bound normal process). Fix me! XXX
732 if (RTP_PRIO_IS_REALTIME(rtp
.type
)) {
741 case RTP_PRIO_REALTIME
:
742 case RTP_PRIO_NORMAL
:
744 if (rtp
.prio
> RTP_PRIO_MAX
) {
748 lp
->lwp_rtprio
= rtp
;
762 lwkt_reltoken(&p
->p_token
);
770 * Transform the running time and tick information in lwp lp's thread into user,
771 * system, and interrupt time usage.
773 * Since we are limited to statclock tick granularity this is a statisical
774 * calculation which will be correct over the long haul, but should not be
775 * expected to measure fine grained deltas.
777 * It is possible to catch a lwp in the midst of being created, so
778 * check whether lwp_thread is NULL or not.
781 calcru(struct lwp
*lp
, struct timeval
*up
, struct timeval
*sp
)
786 * Calculate at the statclock level. YYY if the thread is owned by
787 * another cpu we need to forward the request to the other cpu, or
788 * have a token to interlock the information in order to avoid racing
789 * thread destruction.
791 if ((td
= lp
->lwp_thread
) != NULL
) {
793 up
->tv_sec
= td
->td_uticks
/ 1000000;
794 up
->tv_usec
= td
->td_uticks
% 1000000;
795 sp
->tv_sec
= td
->td_sticks
/ 1000000;
796 sp
->tv_usec
= td
->td_sticks
% 1000000;
802 * Aggregate resource statistics of all lwps of a process.
804 * proc.p_ru keeps track of all statistics directly related to a proc. This
805 * consists of RSS usage and nswap information and aggregate numbers for all
806 * former lwps of this proc.
808 * proc.p_cru is the sum of all stats of reaped children.
810 * lwp.lwp_ru contains the stats directly related to one specific lwp, meaning
811 * packet, scheduler switch or page fault counts, etc. This information gets
812 * added to lwp.lwp_proc.p_ru when the lwp exits.
815 calcru_proc(struct proc
*p
, struct rusage
*ru
)
817 struct timeval upt
, spt
;
823 FOREACH_LWP_IN_PROC(lp
, p
) {
824 calcru(lp
, &upt
, &spt
);
825 timevaladd(&ru
->ru_utime
, &upt
);
826 timevaladd(&ru
->ru_stime
, &spt
);
827 for (rip1
= &ru
->ru_first
, rip2
= &lp
->lwp_ru
.ru_first
;
828 rip1
<= &ru
->ru_last
;
839 sys_getrusage(struct sysmsg
*sysmsg
, const struct getrusage_args
*uap
)
841 struct proc
*p
= curproc
;
846 lwkt_gettoken(&p
->p_token
);
854 case RUSAGE_CHILDREN
:
862 lwkt_reltoken(&p
->p_token
);
865 error
= copyout(rup
, uap
->rusage
, sizeof(struct rusage
));
870 ruadd(struct rusage
*ru
, struct rusage
*ru2
)
875 timevaladd(&ru
->ru_utime
, &ru2
->ru_utime
);
876 timevaladd(&ru
->ru_stime
, &ru2
->ru_stime
);
877 if (ru
->ru_maxrss
< ru2
->ru_maxrss
)
878 ru
->ru_maxrss
= ru2
->ru_maxrss
;
879 ip
= &ru
->ru_first
; ip2
= &ru2
->ru_first
;
880 for (i
= &ru
->ru_last
- &ru
->ru_first
; i
>= 0; i
--)
885 * Find the uidinfo structure for a uid. This structure is used to
886 * track the total resource consumption (process count, socket buffer
887 * size, etc.) for the uid and impose limits.
892 spin_init(&uihash_lock
, "uihashinit");
893 uihashtbl
= hashinit(maxproc
/ 16, M_UIDINFO
, &uihash
);
897 * NOTE: Must be called with uihash_lock held
899 static struct uidinfo
*
902 struct uihashhead
*uipp
;
906 LIST_FOREACH(uip
, uipp
, ui_hash
) {
907 if (uip
->ui_uid
== uid
)
914 * Helper function to creat ea uid that could not be found.
915 * This function will properly deal with races.
917 * WARNING! Should only be used by this source file and by the proc0
923 struct uidinfo
*uip
, *tmp
;
926 * Allocate space and check for a race
928 uip
= kmalloc(sizeof(*uip
), M_UIDINFO
, M_WAITOK
| M_ZERO
);
931 * Initialize structure and enter it into the hash table
933 spin_init(&uip
->ui_lock
, "uicreate");
935 uip
->ui_ref
= 1; /* we're returning a ref */
936 varsymset_init(&uip
->ui_varsymset
, NULL
);
937 uip
->ui_pcpu
= kmalloc(sizeof(*uip
->ui_pcpu
) * ncpus
,
938 M_UIDINFO
, M_WAITOK
| M_ZERO
);
941 * Somebody may have already created the uidinfo for this
942 * uid. If so, return that instead.
944 spin_lock(&uihash_lock
);
948 spin_unlock(&uihash_lock
);
950 spin_uninit(&uip
->ui_lock
);
951 varsymset_clean(&uip
->ui_varsymset
);
952 kfree(uip
->ui_pcpu
, M_UIDINFO
);
953 kfree(uip
, M_UIDINFO
);
956 LIST_INSERT_HEAD(UIHASH(uid
), uip
, ui_hash
);
957 spin_unlock(&uihash_lock
);
963 * Find the uidinfo for a uid, creating one if necessary
969 thread_t td
= curthread
;
972 uip
= td
->td_ucred
->cr_uidinfo
;
973 if (uip
->ui_uid
== uid
) {
977 uip
= td
->td_ucred
->cr_ruidinfo
;
978 if (uip
->ui_uid
== uid
) {
984 spin_lock_shared(&uihash_lock
);
987 spin_unlock_shared(&uihash_lock
);
991 spin_unlock_shared(&uihash_lock
);
997 * Helper funtion to remove a uidinfo whos reference count may
998 * have transitioned to 0. The reference count is likely 0
1001 static __inline
void
1004 struct uidinfo
*uip
;
1007 * If we are still the only holder after acquiring the uihash_lock
1008 * we can safely unlink the uip and destroy it. Otherwise we lost
1009 * a race and must fail.
1011 spin_lock(&uihash_lock
);
1012 uip
= uilookup(uid
);
1013 if (uip
&& uip
->ui_ref
== 0) {
1014 LIST_REMOVE(uip
, ui_hash
);
1015 spin_unlock(&uihash_lock
);
1018 * The uip is now orphaned and we can destroy it at our
1021 if (uip
->ui_sbsize
!= 0)
1022 kprintf("freeing uidinfo: uid = %d, sbsize = %jd\n",
1023 uip
->ui_uid
, (intmax_t)uip
->ui_sbsize
);
1024 if (uip
->ui_proccnt
!= 0)
1025 kprintf("freeing uidinfo: uid = %d, proccnt = %ld\n",
1026 uip
->ui_uid
, uip
->ui_proccnt
);
1028 varsymset_clean(&uip
->ui_varsymset
);
1029 lockuninit(&uip
->ui_varsymset
.vx_lock
);
1030 spin_uninit(&uip
->ui_lock
);
1031 kfree(uip
->ui_pcpu
, M_UIDINFO
);
1032 kfree(uip
, M_UIDINFO
);
1034 spin_unlock(&uihash_lock
);
1039 * Bump the ref count
1042 uihold(struct uidinfo
*uip
)
1044 KKASSERT(uip
->ui_ref
>= 0);
1045 atomic_add_int(&uip
->ui_ref
, 1);
1049 * Drop the ref count. The last-drop code still needs to remove the
1050 * uidinfo from the hash table which it does by re-looking-it-up.
1052 * NOTE: The uip can be ripped out from under us after the fetchadd.
1055 uidrop(struct uidinfo
*uip
)
1059 KKASSERT(uip
->ui_ref
> 0);
1062 if (atomic_fetchadd_int(&uip
->ui_ref
, -1) == 1) {
1068 uireplace(struct uidinfo
**puip
, struct uidinfo
*nuip
)
1075 * Change the count associated with number of processes
1076 * a given user is using.
1078 * NOTE: When 'max' is 0, don't enforce a limit.
1080 * NOTE: Due to concurrency, the count can sometimes exceed the max
1081 * by a small amount.
1084 chgproccnt(struct uidinfo
*uip
, int diff
, int max
)
1088 /* don't allow them to exceed max, but allow subtraction */
1089 if (diff
> 0 && uip
->ui_proccnt
+ diff
> max
&& max
!= 0) {
1092 atomic_add_long(&uip
->ui_proccnt
, diff
);
1093 if (uip
->ui_proccnt
< 0)
1094 kprintf("negative proccnt for uid = %d\n", uip
->ui_uid
);
1101 * Change the total socket buffer size a user has used.
1104 chgsbsize(struct uidinfo
*uip
, u_long
*hiwat
, u_long to
, rlim_t max
)
1110 sbsize
= atomic_fetchadd_long(&uip
->ui_sbsize
, to
- *hiwat
);
1111 new = sbsize
+ to
- *hiwat
;
1115 * If we are trying to increase the socket buffer size
1116 * Scale down the hi water mark when we exceed the user's
1117 * allowed socket buffer space.
1119 * We can't scale down too much or we will blow up atomic packet
1122 if (to
> *hiwat
&& to
> MCLBYTES
&& new > max
) {
1123 to
= to
* max
/ new;