Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Oct 1996 17:08:22 -0700
From:      Julian Elischer <julian@whistle.com>
To:        Mark Tinguely <tinguely@plains.nodak.edu>
Cc:        freebsd-atm@freebsd.org, freebsd-hackers@freebsd.org
Subject:   Re: custom free for external mbuf
Message-ID:  <3266C049.2F1CF0FB@whistle.com>
References:  <199610172223.RAA09577@plains.nodak.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
Mark Tinguely wrote:
you are looking at a very old version.....
look at 2.2


> 
> Religous debate time. :)
> 
> in sys/mbuf.h the external mbuf is defined :
> 
> struct m_ext {
>         caddr_t ext_buf;                /* start of buffer */
>         void    (*ext_free)             /* free routine if not the usual */
>                 __P((caddr_t, u_int));
>         u_int   ext_size;               /* size of buffer, for ext_free */
> };

under 2.2 it is:
/*
 * description of external storage mapped into mbuf,
 * valid if M_EXT set 
 */
struct m_ext {
        caddr_t ext_buf;        /* start of buffer */
        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));
};
        (then later we see)
> #ifdef notyet
> #define MFREE(m, n) \
>         { MBUFLOCK(mbstat.m_mtypes[(m)->m_type]--;) \
>           if ((m)->m_flags & M_EXT) { \
>                 if ((m)->m_ext.ext_free) \
>                         (*((m)->m_ext.ext_free))((m)->m_ext.ext_buf, \
>                             (m)->m_ext.ext_size); \
>                 else \
>                         MCLFREE((m)->m_ext.ext_buf); \
>           } \
>           (n) = (m)->m_next; \
>           FREE((m), mbtypes[(m)->m_type]); \
>         }
>         (more deleted)
> 
> from greping the rest of the sources, this is *the* place an external
> mbuf could call another free routine and it is obviously ifdef out.

not in 2.2
and it is used heavily by myself

> 
> what I am thinking about doing is making a new breed of mbuf that is
> prebuilt to look like an external mbuf, but is permanent in that its free
> routine does not throw away the mbuf external data, mbuf structure, nor the
> association between mbuf and external data.
> 
> why do I want these permanent mbufs? because I am working with ATM and I don't
> want to deal with the allocation, association, tear-down, overhead of many
> small PDU packets.
sure why not, but don't break what's already there..

also see the method OSF uses which is equally neat, and
can use MALLOC'd memory
easily for  this.
(ask matt thomas)

> 
> If I add a new flag entry (say M_PERM) and change the MFREE routine (here
> I show changes to the "notyet" part of MFREE, the current MFREE changes
> would be simular):
> 
>          if ((m)->m_flags & M_EXT) { \
> +               if ((m)->m_flags & M_PERM) { \
> +                   if ((m)->m_ext.ext_free) \
> +                       (*((m)->m_ext.ext_free))((m), \
> +                           (m)->m_ext.ext_size); \
> +               } \
> +               else \
>                 if ((m)->m_ext.ext_free) \
>                         (*((m)->m_ext.ext_free))((m)->m_ext.ext_buf, \
>                             (m)->m_ext.ext_size); \
>                 else \
>                         MCLFREE((m)->m_ext.ext_buf); \
>           } \
>           (n) = (m)->m_next; \
> +        if ((m)->m_flags & M_PERM == 0) { \
>           FREE((m), mbtypes[(m)->m_type]); \
>          } \
>         }
> 

please go look at 2.2 before changing things
the routine is only ever called from there,
but the function pointers might be set up in many palces..
especially in 3rd party software..
so don't break it...please



> notice, I need to send the address of the mbuf to my recycle "free" program.
> and I cannot let it FREE the mbuf lower down in the MFREE routine.
> 
> with this, I can send these permanent mbufs anywhere a regular external
> mbuf is used (in protocols like IP stack and sockets).
> 
> Is there some reason the existing sys/mbuf.h does not allow external mbuf
> to call the custom ext_free?
it was broken by someone?
I do it under bsd4.3 ,osf1, mach and freebsd2.2.

> 
> Does anyone have strong reason to not do this (like those extra instruction
> will cause significant overhead, etc)?
as 2.2 already does this I doubt it..


julian

> 
> --mark.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3266C049.2F1CF0FB>