Subject: RFC: Small tweak to M_CLUSTER semantics.
To: None <tech-net@netbsd.org>
From: Matt Thomas <matt@3am-software.com>
List: tech-net
Date: 01/20/2004 16:18:57
It's been postulated that it might be useful to have multiple mbuf cluster
sizes.  However, the implementation of MCLGET makes this inconvenient.

The following change to mbuf.h add a _MCLGET macro which is a generic
implementation of MCLGET.  In addition, the pool_cache is have in
m_ext.ext_arg so that it can be accessed to the free routine.  (this
actually save some instructions on powerpc).

With these changes, it's relatively simple to add a new MCLGET1K
macro for example.  (or MCLGET4K or ...)

Comments?

Index: mbuf.h
===================================================================
RCS file: /cvsroot/src/sys/sys/mbuf.h,v
retrieving revision 1.88
diff -u -3 -p -r1.88 mbuf.h
--- mbuf.h      13 Nov 2003 01:48:12 -0000      1.88
+++ mbuf.h      21 Jan 2004 00:11:04 -0000
@@ -538,11 +538,11 @@ do 
{                                                                      \
   * MEXTADD adds pre-allocated external storage to
   * a normal mbuf; the flag M_EXT is set upon success.
   */
-#define        MCLGET(m, 
how)                                                  \
+#define        _MCLGET(m, pool_cache, size, 
how)                                       \
  do {                                                                   \
         MBUFLOCK(                                                       \
                 (m)->m_ext.ext_buf =                                    \
-                   pool_cache_get_paddr(&mclpool_cache,                \
+                   pool_cache_get_paddr((pool_cache),          \
                         (how) == M_WAIT ? (PR_WAITOK|PR_LIMITFAIL) : 0, \
                         &(m)->m_ext.ext_paddr);                         \
                 if ((m)->m_ext.ext_buf != NULL)                         \
@@ -552,14 +552,19 @@ do 
{                                                                      \
                 (m)->m_data = (m)->m_ext.ext_buf;                       \
                 (m)->m_flags = ((m)->m_flags & ~M_EXTCOPYFLAGS) |       \
                                 M_EXT|M_CLUSTER;                        \
-               (m)->m_ext.ext_size = MCLBYTES;                         \
+               (m)->m_ext.ext_size = (size);                           \
                 (m)->m_ext.ext_free = NULL;                             \
-               (m)->m_ext.ext_arg = NULL;                              \
+               (m)->m_ext.ext_arg = 
(pool_cache);                              \
                 /* ext_paddr initialized above */                       \
                 MCLINITREFERENCE(m);                                    \
         }                                                               \
  } while (/* CONSTCOND */ 0)

+/*
+ * The standard mbuf cluster pool.
+ */
+#define        MCLGET(m, how)  _MCLGET((m), &mclpool_cache, MCLBYTES, (how))
+
  #define        MEXTMALLOC(m, size, 
how)                                        \
  do {                                                                   \
         (m)->m_ext.ext_buf =                                            \
@@ -596,8 +601,8 @@ do 
{                                                                        \
                 _MCLDEREFERENCE(m);                                     \
                 splx(_ms_);                                             \
         } else if ((m)->m_flags & M_CLUSTER) {                          \
-               pool_cache_put_paddr(&mclpool_cache, (m)->m_ext.ext_buf,\
-                   (m)->m_ext.ext_paddr);                              \
+               pool_cache_put_paddr((m)->m_ext.ext_arg,                \
+                   (m)->m_ext.ext_buf, (m)->m_ext.ext_paddr);          \
                 splx(_ms_);                                             \
         } else if ((m)->m_ext.ext_free) {                               \
                 /*                                                      \
@@ -646,7 +651,7 @@ do 
{                                                                        \
                                 _MCLDEREFERENCE(m);                     \
                                 pool_cache_put(&mbpool_cache, (m));     \
                         } else if ((m)->m_flags & M_CLUSTER) {          \
-                               pool_cache_put_paddr(&mclpool_cache,    \
+                               pool_cache_put_paddr((m)->m_ext.ext_arg,\
                                     (m)->m_ext.ext_buf,                 \
                                     (m)->m_ext.ext_paddr);              \
                                 pool_cache_put(&mbpool_cache, (m));     \


-- 
Matt Thomas                     email: matt@3am-software.com
3am Software Foundry              www: http://3am-software.com/bio/matt/
Cupertino, CA              disclaimer: I avow all knowledge of this message.