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

Mateusz Guzik mjg at FreeBSD.org
Tue Dec 11 12:01:47 UTC 2018


Author: mjg
Date: Tue Dec 11 12:01:46 2018
New Revision: 341818
URL: https://svnweb.freebsd.org/changeset/base/341818

Log:
  Make lim_cur inline if possible.
  
  It is a function call only to accomodate *some* ABIs which install a hook.
  They only care for 3 types of limits: DATA, STACK, VMEM
  
  Instead of always calling the func, see at compilation time if the requested
  limit is something else and just do the read if so.
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/kern/kern_resource.c
  head/sys/sys/resourcevar.h

Modified: head/sys/kern/kern_resource.c
==============================================================================
--- head/sys/kern/kern_resource.c	Tue Dec 11 11:58:44 2018	(r341817)
+++ head/sys/kern/kern_resource.c	Tue Dec 11 12:01:46 2018	(r341818)
@@ -1168,7 +1168,7 @@ lim_max_proc(struct proc *p, int which)
  * The which parameter which specifies the index into the rlimit array
  */
 rlim_t
-lim_cur(struct thread *td, int which)
+(lim_cur)(struct thread *td, int which)
 {
 	struct rlimit rl;
 

Modified: head/sys/sys/resourcevar.h
==============================================================================
--- head/sys/sys/resourcevar.h	Tue Dec 11 11:58:44 2018	(r341817)
+++ head/sys/sys/resourcevar.h	Tue Dec 11 12:01:46 2018	(r341818)
@@ -132,6 +132,19 @@ struct plimit
 	*lim_alloc(void);
 void	 lim_copy(struct plimit *dst, struct plimit *src);
 rlim_t	 lim_cur(struct thread *td, int which);
+#define lim_cur(td, which)	({					\
+	rlim_t _rlim;							\
+	struct thread *_td = (td);					\
+	int _which = (which);						\
+	if (__builtin_constant_p(which) && which != RLIMIT_DATA &&	\
+	    which != RLIMIT_STACK && which != RLIMIT_VMEM) {		\
+		_rlim = td->td_limit->pl_rlimit[which].rlim_cur;	\
+	} else {							\
+		_rlim = lim_cur(_td, _which);				\
+	}								\
+	_rlim;								\
+})
+
 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);


More information about the svn-src-head mailing list