From owner-svn-src-head@FreeBSD.ORG Sun Jan 18 21:09:34 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BE44C1065674; Sun, 18 Jan 2009 21:09:34 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AC7B38FC12; Sun, 18 Jan 2009 21:09:34 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n0IL9YYg087256; Sun, 18 Jan 2009 21:09:34 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n0IL9YHY087255; Sun, 18 Jan 2009 21:09:34 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <200901182109.n0IL9YHY087255@svn.freebsd.org> From: Alexander Motin Date: Sun, 18 Jan 2009 21:09:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r187410 - head/sys/netgraph X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Jan 2009 21:09:36 -0000 Author: mav Date: Sun Jan 18 21:09:34 2009 New Revision: 187410 URL: http://svn.freebsd.org/changeset/base/187410 Log: If source mbuf chain consists of only one mbuf, use it directly as source buffer to avoid extra copying. Modified: head/sys/netgraph/ng_mppc.c Modified: head/sys/netgraph/ng_mppc.c ============================================================================== --- head/sys/netgraph/ng_mppc.c Sun Jan 18 20:19:55 2009 (r187409) +++ head/sys/netgraph/ng_mppc.c Sun Jan 18 21:09:34 2009 (r187410) @@ -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