Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Oct 1995 04:19:35 -0700
From:      Julian Elischer <julian>
To:        hackers
Subject:   suggested changes to mbuf routines
Message-ID:  <199510141119.EAA05158@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help


Here are some changes to mbufs that should have very little  effect
to most people but make a great difference to me..

the difference is to bring in the support for 3rd-party 'external objects'
being linked to by an mbuf
the code has been in the kernel for a while,
and it's in 4.3, and OSF1
in similar forms, but for some reason was commented out
in FreeBSD..
does anyone know why?
I did notice that if I had just enabled it then there would ahve been the 
potential for the duplication of an mbuf with an external
reference to  do bad things it the external object was not a 
mbuf cluster.
for this reason I've implimented teh  ext_ref function call
in teh ext struct which is a pointer to a function that 
will increment the reference count of whatever object
has been externally referenced.

Once again I discussed this with mike Karels about 3 years ago,
and I'm surprised to see it still not implimented..
he said back then that it was on his list..

I desperatly need this  for TFS because we hang all sorts of external
'things' off mbufs and tehy need to be freed when the mbuf is freed

I just spent teh best part of a day trying to figure out why my objects were't
getting freed, because I 'assumed' this was in the kernel, and was 
very shocked to find it had been commented out..

anyhow, ehough babble

here are teh diffs
Index: sys/mbuf.h
===================================================================
RCS file: /u1/cvs/src/sys/sys/mbuf.h,v
retrieving revision 1.10
diff -c -r1.10 mbuf.h
*** 1.10	1995/07/29 11:42:46
--- mbuf.h	1995/10/14 09:32:06
***************
*** 89,94 ****
--- 89,96 ----
  	void	(*ext_free)		/* free routine if not the usual */
  		__P((caddr_t, u_int));
  	u_int	ext_size;		/* size of buffer, for ext_free */
+ 	void	(*ext_ref)		/* add a reference to the ext object */
+ 		__P((caddr_t, u_int));
  };
  
  struct mbuf {
***************
*** 232,237 ****
--- 234,241 ----
  	  if ((m)->m_ext.ext_buf != NULL) { \
  		(m)->m_data = (m)->m_ext.ext_buf; \
  		(m)->m_flags |= M_EXT; \
+ 		(m)->m_ext.ext_free = NULL;  \
+ 		(m)->m_ext.ext_ref = NULL;  \
  		(m)->m_ext.ext_size = MCLBYTES;  \
  	  } \
  	}
***************
*** 250,256 ****
   * Free a single mbuf and associated external storage.
   * Place the successor, if any, in n.
   */
- #ifdef notyet
  #define	MFREE(m, n) \
  	{ MBUFLOCK(mbstat.m_mtypes[(m)->m_type]--;) \
  	  if ((m)->m_flags & M_EXT) { \
--- 254,259 ----
***************
*** 263,278 ****
  	  (n) = (m)->m_next; \
  	  FREE((m), mbtypes[(m)->m_type]); \
  	}
- #else /* notyet */
- #define	MFREE(m, nn) \
- 	{ MBUFLOCK(mbstat.m_mtypes[(m)->m_type]--;) \
- 	  if ((m)->m_flags & M_EXT) { \
- 		MCLFREE((m)->m_ext.ext_buf); \
- 	  } \
- 	  (nn) = (m)->m_next; \
- 	  FREE((m), mbtypes[(m)->m_type]); \
- 	}
- #endif
  
  /*
   * Copy mbuf pkthdr from from to to.
--- 266,271 ----
Index: kern/uipc_mbuf.c
===================================================================
RCS file: /u1/cvs/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.12
diff -c -r1.12 uipc_mbuf.c
*** 1.12	1995/09/09 18:10:12
--- uipc_mbuf.c	1995/10/14 09:42:56
***************
*** 335,341 ****
  		n->m_len = min(len, m->m_len - off);
  		if (m->m_flags & M_EXT) {
  			n->m_data = m->m_data + off;
! 			mclrefcnt[mtocl(m->m_ext.ext_buf)]++;
  			n->m_ext = m->m_ext;
  			n->m_flags |= M_EXT;
  		} else
--- 335,346 ----
  		n->m_len = min(len, m->m_len - off);
  		if (m->m_flags & M_EXT) {
  			n->m_data = m->m_data + off;
! 			if(!m->m_ext.ext_free)
! 				mclrefcnt[mtocl(m->m_ext.ext_buf)]++;
! 			else
! 				if(m->m_ext.ext_ref)
! 					(*(m->m_ext.ext_ref))(m->m_ext.ext_buf,
! 							m->m_ext.ext_size);
  			n->m_ext = m->m_ext;
  			n->m_flags |= M_EXT;
  		} else
***************
*** 612,618 ****
  	if (m->m_flags & M_EXT) {
  		n->m_flags |= M_EXT;
  		n->m_ext = m->m_ext;
! 		mclrefcnt[mtocl(m->m_ext.ext_buf)]++;
  		m->m_ext.ext_size = 0; /* For Accounting XXXXXX danger */
  		n->m_data = m->m_data + len;
  	} else {
--- 617,628 ----
  	if (m->m_flags & M_EXT) {
  		n->m_flags |= M_EXT;
  		n->m_ext = m->m_ext;
! 		if(!m->m_ext.ext_free)
! 			mclrefcnt[mtocl(m->m_ext.ext_buf)]++;
! 		else
! 			if(m->m_ext.ext_ref)
! 				(*(m->m_ext.ext_ref))(m->m_ext.ext_buf,
! 						m->m_ext.ext_size);
  		m->m_ext.ext_size = 0; /* For Accounting XXXXXX danger */
  		n->m_data = m->m_data + len;
  	} else {
A




I have these changes ready to check in but want a sanity check first..
(p.s. possibly I should have a bit (like M_EXT) to say that the external
object is a normal mbuf cluster, and that default modes should be used..)




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199510141119.EAA05158>