svn commit: r187954 - in stable/7/sys: . contrib/pf dev/ath/ath_hal dev/cxgb netgraph

Alexander Motin mav at FreeBSD.org
Sat Jan 31 04:44:21 PST 2009


Author: mav
Date: Sat Jan 31 12:44:20 2009
New Revision: 187954
URL: http://svn.freebsd.org/changeset/base/187954

Log:
  MFC rev. 187410
  
  If source mbuf chain consists of only one mbuf, use it directly as source
  buffer to avoid extra copying.

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)
  stable/7/sys/dev/ath/ath_hal/   (props changed)
  stable/7/sys/dev/cxgb/   (props changed)
  stable/7/sys/netgraph/ng_mppc.c

Modified: stable/7/sys/netgraph/ng_mppc.c
==============================================================================
--- stable/7/sys/netgraph/ng_mppc.c	Sat Jan 31 12:41:44 2009	(r187953)
+++ stable/7/sys/netgraph/ng_mppc.c	Sat Jan 31 12:44:20 2009	(r187954)
@@ -489,22 +489,29 @@ ng_mppc_compress(node_p node, struct mbu
 	if ((d->cfg.bits & MPPC_BIT) != 0) {
 		u_short flags = MPPC_MANDATORY_COMPRESS_FLAGS;
 		u_char *inbuf, *outbuf;
-		int outlen, inlen;
+		int outlen, inlen, ina;
 		u_char *source, *dest;
 		u_long sourceCnt, destCnt;
 		int rtn;
 
 		/* Work with contiguous regions of memory. */
 		inlen = m->m_pkthdr.len;
-		inbuf = malloc(inlen, M_NETGRAPH_MPPC, M_NOWAIT);
-		if (inbuf == NULL)
-			goto err1;
-		m_copydata(m, 0, inlen, (caddr_t)inbuf);
+		if (m->m_next == NULL) {
+			inbuf = mtod(m, u_char *);
+			ina = 0;
+		} else {
+			inbuf = malloc(inlen, M_NETGRAPH_MPPC, M_NOWAIT);
+			if (inbuf == NULL)
+				goto err1;
+			m_copydata(m, 0, inlen, (caddr_t)inbuf);
+			ina = 1;
+		}
 
 		outlen = MPPC_MAX_BLOWUP(inlen);
 		outbuf = malloc(outlen, M_NETGRAPH_MPPC, M_NOWAIT);
 		if (outbuf == NULL) {
-			free(inbuf, M_NETGRAPH_MPPC);
+			if (ina)
+				free(inbuf, M_NETGRAPH_MPPC);
 err1:
 			m_freem(m);
 			MPPC_InitCompressionHistory(d->history);
@@ -544,7 +551,8 @@ err1:
 		d->flushed = (rtn & MPPC_EXPANDED) != 0
 		    || (flags & MPPC_SAVE_HISTORY) == 0;
 
-		free(inbuf, M_NETGRAPH_MPPC);
+		if (ina)
+			free(inbuf, M_NETGRAPH_MPPC);
 		free(outbuf, M_NETGRAPH_MPPC);
 
 		/* Check mbuf chain reload result. */
@@ -731,36 +739,43 @@ failed:
 	/* Decompress packet */
 	if ((header & MPPC_FLAG_COMPRESSED) != 0) {
 		int flags = MPPC_MANDATORY_DECOMPRESS_FLAGS;
-		u_char *decompbuf, *source, *dest;
+		u_char *inbuf, *outbuf;
+		int inlen, outlen, ina;
+		u_char *source, *dest;
 		u_long sourceCnt, destCnt;
-		int decomplen, rtn;
-		u_char *buf;
-		int len;
+		int rtn;
 
 		/* Copy payload into a contiguous region of memory. */
-		len = m->m_pkthdr.len;
-		buf = malloc(len, M_NETGRAPH_MPPC, M_NOWAIT);
-		if (buf == NULL) {
-			m_freem(m);
-			return (ENOMEM);
+		inlen = m->m_pkthdr.len;
+		if (m->m_next == NULL) {
+                	inbuf = mtod(m, u_char *);
+			ina = 0;
+		} else {
+		        inbuf = malloc(inlen, M_NETGRAPH_MPPC, M_NOWAIT);
+			if (inbuf == NULL) {
+				m_freem(m);
+				return (ENOMEM);
+			}
+			m_copydata(m, 0, inlen, (caddr_t)inbuf);
+			ina = 1;
 		}
-		m_copydata(m, 0, len, (caddr_t)buf);
 
 		/* Allocate a buffer for decompressed data */
-		decompbuf = malloc(MPPC_DECOMP_BUFSIZE + MPPC_DECOMP_SAFETY,
+		outbuf = malloc(MPPC_DECOMP_BUFSIZE + MPPC_DECOMP_SAFETY,
 		    M_NETGRAPH_MPPC, M_NOWAIT);
-		if (decompbuf == NULL) {
+		if (outbuf == NULL) {
 			m_freem(m);
-			free(buf, M_NETGRAPH_MPPC);
+			if (ina)
+				free(inbuf, M_NETGRAPH_MPPC);
 			return (ENOMEM);
 		}
-		decomplen = MPPC_DECOMP_BUFSIZE;
+		outlen = MPPC_DECOMP_BUFSIZE;
 
 		/* Prepare to decompress */
-		source = buf;
-		sourceCnt = len;
-		dest = decompbuf;
-		destCnt = decomplen;
+		source = inbuf;
+		sourceCnt = inlen;
+		dest = outbuf;
+		destCnt = outlen;
 		if ((header & MPPC_FLAG_RESTART) != 0)
 			flags |= MPPC_RESTART_HISTORY;
 
@@ -774,22 +789,24 @@ failed:
 		    || (rtn & MPPC_DECOMP_OK) != MPPC_DECOMP_OK) {
 			log(LOG_ERR, "%s: decomp returned 0x%x",
 			    __func__, rtn);
-			free(buf, M_NETGRAPH_MPPC);
-			free(decompbuf, M_NETGRAPH_MPPC);
+			if (ina)
+				free(inbuf, M_NETGRAPH_MPPC);
+			free(outbuf, M_NETGRAPH_MPPC);
 			goto failed;
 		}
 
 		/* Replace compressed data with decompressed data */
-		free(buf, M_NETGRAPH_MPPC);
-		len = decomplen - destCnt;
+		if (ina)
+			free(inbuf, M_NETGRAPH_MPPC);
+		outlen -= destCnt;
 	
-		m_copyback(m, 0, len, (caddr_t)decompbuf);
-		if (m->m_pkthdr.len < len) {
+		m_copyback(m, 0, outlen, (caddr_t)outbuf);
+		if (m->m_pkthdr.len < outlen) {
 			m_freem(m);
 			m = NULL;
-		} else if (len < m->m_pkthdr.len)
-			m_adj(m, len - m->m_pkthdr.len);
-		free(decompbuf, M_NETGRAPH_MPPC);
+		} else if (outlen < m->m_pkthdr.len)
+			m_adj(m, outlen - m->m_pkthdr.len);
+		free(outbuf, M_NETGRAPH_MPPC);
 	}
 #endif
 


More information about the svn-src-all mailing list