Subject: Retackling NEW_VMCMD()
To: None <tech-kern@netbsd.org>
From: Bang Jun-Young <junyoung@netbsd.org>
List: tech-kern
Date: 08/28/2003 18:55:51
Hi, this is another story. :-)

Currently, NEW_VMCMD() is only expanded to a real function new_vmcmd()
if DEBUG is defined. For the normal case, it's expanded inline. But it is
never called within a performance-critical loop, so inlining it gives no
advantanges but a bigger kernel.

By removing DEBUG & macro stuff and always calling new_vmcmd(), I could
save a bunch of kernel size, approx. 4kB:

-rwxr-xr-x  1 junyoung  junyoung  6854276 Aug 28 17:26 netbsd
-rwxr-xr-x  1 junyoung  junyoung  6858538 Aug 28 13:02 netbsd.old

Here is a patch:

Index: sys/exec.h
===================================================================
RCS file: /cvsroot/src/sys/sys/exec.h,v
retrieving revision 1.100
diff -u -u -r1.100 exec.h
--- sys/exec.h	2003/08/08 18:54:16	1.100
+++ sys/exec.h	2003/08/28 08:27:55
@@ -247,7 +247,6 @@
 int	exec_remove		__P((const struct execsw *));
 #endif /* LKM */

-#ifdef DEBUG
 void	new_vmcmd __P((struct exec_vmcmd_set *,
 		    int (*) __P((struct proc *, struct exec_vmcmd *)),
 		    u_long, u_long, struct vnode *, u_long, u_int, int));
@@ -255,24 +254,6 @@
 	new_vmcmd(evsp,proc,len,addr,vp,offset,prot,0)
 #define	NEW_VMCMD2(evsp,proc,len,addr,vp,offset,prot,flags) \
 	new_vmcmd(evsp,proc,len,addr,vp,offset,prot,flags)
-#else	/* DEBUG */
-#define	NEW_VMCMD(evsp,proc,len,addr,vp,offset,prot) \
-	NEW_VMCMD2(evsp,proc,len,addr,vp,offset,prot,0)
-#define	NEW_VMCMD2(evsp,proc,len,addr,vp,offset,prot,flags) do { \
-	struct exec_vmcmd *vcp; \
-	if ((evsp)->evs_used >= (evsp)->evs_cnt) \
-		vmcmdset_extend(evsp); \
-	vcp = &(evsp)->evs_cmds[(evsp)->evs_used++]; \
-	vcp->ev_proc = (proc); \
-	vcp->ev_len = (len); \
-	vcp->ev_addr = (addr); \
-	if ((vcp->ev_vp = (vp)) != NULLVP) \
-		VREF(vp); \
-	vcp->ev_offset = (offset); \
-	vcp->ev_prot = (prot); \
-	vcp->ev_flags = (flags); \
-} while (/* CONSTCOND */ 0)
-#endif /* DEBUG */

 #endif /* _KERNEL */
Index: kern/exec_subr.c
===================================================================
RCS file: /cvsroot/src/sys/kern/exec_subr.c,v
retrieving revision 1.40
diff -u -u -r1.40 exec_subr.c
--- kern/exec_subr.c	2003/08/24 17:52:47	1.40
+++ kern/exec_subr.c	2003/08/28 08:31:39
@@ -50,14 +50,11 @@
  * (calls, extends, kills).
  */

-#ifdef DEBUG
 /*
  * new_vmcmd():
  *	create a new vmcmd structure and fill in its fields based
  *	on function call arguments.  make sure objects ref'd by
  *	the vmcmd are 'held'.
- *
- * If not debugging, this is a macro, so it's expanded inline.
  */

 void
@@ -80,7 +77,6 @@
 	vcp->ev_prot = prot;
 	vcp->ev_flags = flags;
 }
-#endif /* DEBUG */

 void
 vmcmdset_extend(struct exec_vmcmd_set *evsp)

What do you think?

Jun-Young

--
Bang Jun-Young <junyoung@NetBSD.org>