Author: mjg Date: Sat Nov 14 19:21:46 2020 New Revision: 367694 URL: https://svnweb.freebsd.org/changeset/base/367694
Log: thread: batch resource limit free calls Modified: head/sys/kern/kern_resource.c head/sys/kern/kern_thread.c head/sys/sys/resourcevar.h Modified: head/sys/kern/kern_resource.c ============================================================================== --- head/sys/kern/kern_resource.c Sat Nov 14 19:20:58 2020 (r367693) +++ head/sys/kern/kern_resource.c Sat Nov 14 19:21:46 2020 (r367694) @@ -1236,6 +1236,14 @@ lim_free(struct plimit *limp) free((void *)limp, M_PLIMIT); } +void +lim_freen(struct plimit *limp, int n) +{ + + if (refcount_releasen(&limp->pl_refcnt, n)) + free((void *)limp, M_PLIMIT); +} + /* * Make a copy of the plimit structure. * We share these structures copy-on-write after fork. Modified: head/sys/kern/kern_thread.c ============================================================================== --- head/sys/kern/kern_thread.c Sat Nov 14 19:20:58 2020 (r367693) +++ head/sys/kern/kern_thread.c Sat Nov 14 19:21:46 2020 (r367694) @@ -537,6 +537,8 @@ thread_reap(void) struct thread *itd, *ntd; struct tidbatch tidbatch; int tdcount; + struct plimit *lim; + int limcount; /* * Reading upfront is pessimal if followed by concurrent atomic_swap, @@ -552,11 +554,23 @@ thread_reap(void) tidbatch_prep(&tidbatch); tdcount = 0; + lim = NULL; + limcount = 0; while (itd != NULL) { ntd = itd->td_zombie; EVENTHANDLER_DIRECT_INVOKE(thread_dtor, itd); tidbatch_add(&tidbatch, itd); - thread_cow_free(itd); + MPASS(itd->td_realucred != NULL); + crcowfree(itd); + MPASS(itd->td_limit != NULL); + if (lim != itd->td_limit) { + if (limcount != 0) { + lim_freen(lim, limcount); + limcount = 0; + } + } + lim = itd->td_limit; + limcount++; thread_free_batched(itd); tidbatch_process(&tidbatch); tdcount++; @@ -571,6 +585,8 @@ thread_reap(void) if (tdcount != 0) { thread_count_sub(tdcount); } + MPASS(limcount != 0); + lim_freen(lim, limcount); } /* Modified: head/sys/sys/resourcevar.h ============================================================================== --- head/sys/sys/resourcevar.h Sat Nov 14 19:20:58 2020 (r367693) +++ head/sys/sys/resourcevar.h Sat Nov 14 19:21:46 2020 (r367694) @@ -145,6 +145,7 @@ rlim_t lim_cur(struct thread *td, int which); rlim_t lim_cur_proc(struct proc *p, int which); void lim_fork(struct proc *p1, struct proc *p2); void lim_free(struct plimit *limp); +void lim_freen(struct plimit *limp, int n); struct plimit *lim_hold(struct plimit *limp); rlim_t lim_max(struct thread *td, int which); _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"