Subject: m_copyback patch.
To: None <tech-kern@NetBSD.ORG>
From: Darren Reed <darrenr@cyber.com.au>
List: tech-kern
Date: 01/11/1998 17:44:56
Included below is a patch to help m_copyback() be less wasteful when
copying data back into mbuf's.  Currently, (for example), if an mbuf
is allocated with 10 bytes of data (m_len == 10), and m_copyback()
is called to write 11 bytes into the mbuf, it will write the 10 in
and then attempt to allocate another mbuf to put the extra byte in.

This patch is aimed to address this problem by extending the size
of the mbuf upto MLEN/MHLEN (max) as appropriate.

Does anyone have any problems with it being committed ?

Darren


*** /sys/kern/uipc_mbuf.c.orig	Sun Jan 11 17:14:50 1998
--- /sys/kern/uipc_mbuf.c	Sun Jan 11 17:28:19 1998
***************
*** 767,772 ****
--- 767,782 ----
  	}
  	while (len > 0) {
  		mlen = min (m->m_len - off, len);
+ 		if ((mlen < len) && (m->m_len < MLEN))
+ 			if (m->m_flags & M_PKTHDR) {
+ 				if (m->m_len < MHLEN) {
+ 					m->m_len = min(m->m_len + len, MHLEN);
+ 					mlen = min (m->m_len - off, len);
+ 				}
+ 			} else {
+ 				m->m_len = min(m->m_len + len, MLEN);
+ 				mlen = min (m->m_len - off, len);
+ 			}
  		bcopy(cp, mtod(m, caddr_t) + off, (unsigned)mlen);
  		cp += mlen;
  		len -= mlen;