svn commit: r256432 - in user/andre/mbuf_staging: kern sys
Andre Oppermann
andre at FreeBSD.org
Sun Oct 13 19:25:24 UTC 2013
Author: andre
Date: Sun Oct 13 19:25:23 2013
New Revision: 256432
URL: http://svnweb.freebsd.org/changeset/base/256432
Log:
Remove unused zone arguments from m_init().
Merge _m_align(), _mh_align(), and _mext_align into m_align()
which already handles all these cases.
Optimize m_prepend() by testing for sufficient leading space
instead of always allocating a new mbuf merge _m_prepend()
into it.
Move mbuf allocation function prototypes together.
Constify a some mbuf functions. [Suggested by: bde]
Modified:
user/andre/mbuf_staging/kern/kern_mbuf.c
user/andre/mbuf_staging/kern/uipc_mbuf.c
user/andre/mbuf_staging/sys/mbuf.h
Modified: user/andre/mbuf_staging/kern/kern_mbuf.c
==============================================================================
--- user/andre/mbuf_staging/kern/kern_mbuf.c Sun Oct 13 19:02:16 2013 (r256431)
+++ user/andre/mbuf_staging/kern/kern_mbuf.c Sun Oct 13 19:25:23 2013 (r256432)
@@ -440,7 +440,7 @@ mb_ctor_mbuf(void *mem, int size, void *
m = (struct mbuf *)mem;
flags = args->flags;
- error = m_init(m, NULL, size, how, type, flags);
+ error = m_init(m, size, how, type, flags);
return (error);
}
@@ -641,7 +641,7 @@ mb_ctor_pack(void *mem, int size, void *
trash_ctor(m->m_ext.ext_buf, MCLBYTES, arg, how);
#endif
- error = m_init(m, NULL, size, how, type, flags);
+ error = m_init(m, size, how, type, flags);
/* m_ext is already initialized. */
m->m_data = m->m_ext.ext_buf;
@@ -685,7 +685,7 @@ m_getzone(int size)
* should go away with constant propagation for !MGETHDR.
*/
int
-m_init(struct mbuf *m, uma_zone_t zone, int size, int how, short type,
+m_init(struct mbuf *m, int size, int how, short type,
int flags)
{
int error;
Modified: user/andre/mbuf_staging/kern/uipc_mbuf.c
==============================================================================
--- user/andre/mbuf_staging/kern/uipc_mbuf.c Sun Oct 13 19:02:16 2013 (r256431)
+++ user/andre/mbuf_staging/kern/uipc_mbuf.c Sun Oct 13 19:25:23 2013 (r256432)
@@ -295,6 +295,16 @@ m_prepend(struct mbuf *m, int len, int h
{
struct mbuf *mn;
+ MBUF_CHECKSLEEP(how);
+
+ if (M_LEADINGSPACE(m) >= len) {
+ m->m_data -= len;
+ m->m_len += len;
+ if (m->m_flags & M_PKTHDR)
+ m->m_pkthdr.len += len;
+ return (m);
+ }
+
if (m->m_flags & M_PKTHDR)
mn = m_gethdr(how, m->m_type);
else
@@ -1759,79 +1769,49 @@ m_unshare(struct mbuf *m0, int how)
}
int
-_m_writable(struct mbuf *m)
+_m_writable(const struct mbuf *m)
{
- return (!((m)->m_flags & M_RDONLY) &&
- (!(((m)->m_flags & M_EXT)) || (*((m)->m_ext.ref_cnt) == 1)) );
-}
-
-void
-_m_align(struct mbuf *m, int len)
-{
- KASSERT(!((m)->m_flags & (M_PKTHDR|M_EXT)),
- ("%s: M_ALIGN not normal mbuf", __func__));
- KASSERT((m)->m_data == (m)->m_dat,
- ("%s: M_ALIGN not a virgin mbuf", __func__));
- (m)->m_data += (MLEN - (len)) & ~(sizeof(long) - 1);
+ if ((m->m_flags & M_RDONLY) ||
+ ((m->m_flags & M_EXT) && (*(m->m_ext.ref_cnt) > 1)))
+ return (0);
+ else
+ return (1);
}
-void
-_mh_align(struct mbuf *m, int len)
+int
+_m_leadingspace(const struct mbuf *m)
{
- KASSERT((m)->m_flags & M_PKTHDR && !((m)->m_flags & M_EXT),
- ("%s: MH_ALIGN not PKTHDR mbuf", __func__));
- KASSERT((m)->m_data == (m)->m_pktdat,
- ("%s: MH_ALIGN not a virgin mbuf", __func__));
- (m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1);
-}
+ int space;
-void
-_mext_align(struct mbuf *m, int len)
-{
- KASSERT((m)->m_flags & M_EXT,
- ("%s: MEXT_ALIGN not an M_EXT mbuf", __func__));
- KASSERT((m)->m_data == (m)->m_ext.ext_buf,
- ("%s: MEXT_ALIGN not a virgin mbuf", __func__));
- (m)->m_data += ((m)->m_ext.ext_size - (len)) &
- ~(sizeof(long) - 1);
-}
+ if (m->m_flags & M_EXT)
+ if (M_WRITABLE(m))
+ space = m->m_data - m->m_ext.ext_buf;
+ else
+ space = 0;
+ else if (m->m_flags & M_PKTHDR)
+ space = m->m_data - m->m_pktdat;
+ else
+ space = m->m_data - m->m_dat;
-int
-_m_leadingspace(struct mbuf *m)
-{
- return ((m)->m_flags & M_EXT ?
- (M_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0):
- (m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat :
- (m)->m_data - (m)->m_dat);
+ return (space);
}
int
-_m_trailingspace(struct mbuf *m)
+_m_trailingspace(const struct mbuf *m)
{
- return ((m)->m_flags & M_EXT ?
- (M_WRITABLE(m) ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size
- - ((m)->m_data + (m)->m_len) : 0) :
- &(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len));
-}
+ int space;
-void
-_m_prepend(struct mbuf *m, int plen, int how)
-{
- struct mbuf **_mmp = &(m);
- struct mbuf *_mm = *_mmp;
- int _mplen = (plen);
- int __mhow = (how);
+ if (m->m_flags & M_EXT)
+ if (M_WRITABLE(m))
+ space = m->m_ext.ext_buf + m->m_ext.ext_size -
+ (m->m_data + m->m_len);
+ else
+ space = 0;
+ else
+ space = &m->m_dat[MLEN] - (m->m_data + m->m_len);
- MBUF_CHECKSLEEP(how);
- if (M_LEADINGSPACE(_mm) >= _mplen) {
- _mm->m_data -= _mplen;
- _mm->m_len += _mplen;
- } else
- _mm = m_prepend(_mm, _mplen, __mhow);
- if (_mm != NULL && _mm->m_flags & M_PKTHDR)
- _mm->m_pkthdr.len += _mplen;
- *_mmp = _mm;
+ return (space);
}
#ifdef MBUF_PROFILING
Modified: user/andre/mbuf_staging/sys/mbuf.h
==============================================================================
--- user/andre/mbuf_staging/sys/mbuf.h Sun Oct 13 19:02:16 2013 (r256431)
+++ user/andre/mbuf_staging/sys/mbuf.h Sun Oct 13 19:25:23 2013 (r256432)
@@ -509,7 +509,7 @@ int m_pkthdr_init(struct mbuf *, int);
int m_gettype(int);
void m_extaddref(struct mbuf *, caddr_t, u_int, u_int *,
int (*)(struct mbuf *, void *, void *), void *, void *);
-int m_init(struct mbuf *, uma_zone_t, int, int, short, int);
+int m_init(struct mbuf *, int, int, short, int);
struct mbuf *m_get(int, short);
struct mbuf *m_getclr(int, short);
struct mbuf *m_gethdr(int, short);
@@ -517,6 +517,11 @@ struct mbuf *m_getcl(int, short, int);
void m_clget(struct mbuf *, int);
void *m_cljget(struct mbuf *, int, int);
void m_cljset(struct mbuf *, void *, int);
+struct mbuf *m_free(struct mbuf *);
+void m_freem(struct mbuf *);
+struct mbuf *m_get2(int, int, short, int);
+struct mbuf *m_getjcl(int, short, int, int);
+struct mbuf *m_getm2(struct mbuf *, int, int, short, int);
static __inline void
m_chtype(struct mbuf *m, short new_type)
@@ -560,7 +565,7 @@ m_last(struct mbuf *m)
* be both the local data payload, or an external buffer area, depending on
* whether M_EXT is set).
*/
-int _m_writable(struct mbuf *);
+int _m_writable(const struct mbuf *);
#define M_WRITABLE(m) _m_writable(m)
/* Check if the supplied mbuf has a packet header, or else panic. */
@@ -580,40 +585,25 @@ int _m_writable(struct mbuf *);
/*
* Set the m_data pointer of a newly-allocated mbuf (m_get/MGET) to place an
* object of the specified size at the end of the mbuf, longword aligned.
- */
-void _m_align(struct mbuf *, int);
-#define M_ALIGN(m, len) _m_align(m, len)
-
-/*
* As above, for mbufs allocated with m_gethdr/MGETHDR or initialized by
* M_DUP/MOVE_PKTHDR.
- */
-void _mh_align(struct mbuf *, int);
-#define MH_ALIGN(m, len) _mh_align(m, len)
-
-/*
* As above, for mbuf with external storage.
*/
-void _mext_align(struct mbuf *, int);
-#define MEXT_ALIGN(m, len) _mext_align(m, len)
+#define M_ALIGN(m, len) m_align(m, len)
+#define MH_ALIGN(m, len) m_align(m, len)
+#define MEXT_ALIGN(m, len) m_align(m, len)
/*
* Compute the amount of space available before the current start of data in
* an mbuf.
- *
- * The M_WRITABLE() is a temporary, conservative safety measure: the burden
- * of checking writability of the mbuf data area rests solely with the caller.
*/
-int _m_leadingspace(struct mbuf *);
+int _m_leadingspace(const struct mbuf *);
#define M_LEADINGSPACE(m) _m_leadingspace(m)
/*
* Compute the amount of space available after the end of data in an mbuf.
- *
- * The M_WRITABLE() is a temporary, conservative safety measure: the burden
- * of checking writability of the mbuf data area rests solely with the caller.
*/
-int _m_trailingspace(struct mbuf *);
+int _m_trailingspace(const struct mbuf *);
#define M_TRAILINGSPACE(m) _m_trailingspace(m)
/*
@@ -621,8 +611,7 @@ int _m_trailingspace(struct mbuf *);
* allocated, how specifies whether to wait. If the allocation fails, the
* original mbuf chain is freed and m is set to NULL.
*/
-void _m_prepend(struct mbuf *, int, int);
-#define M_PREPEND(m, plen, how) _m_prepend(m, plen, how)
+#define M_PREPEND(m, plen, how) (m = m_prepend(m, plen, how))
/*
* Change mbuf to new type. This is a relatively expensive operation and
@@ -670,11 +659,6 @@ struct mbuf *m_dup(struct mbuf *, int);
int m_dup_pkthdr(struct mbuf *, struct mbuf *, int);
u_int m_fixhdr(struct mbuf *);
struct mbuf *m_fragment(struct mbuf *, int, int);
-struct mbuf *m_free(struct mbuf *);
-void m_freem(struct mbuf *);
-struct mbuf *m_get2(int, int, short, int);
-struct mbuf *m_getjcl(int, short, int, int);
-struct mbuf *m_getm2(struct mbuf *, int, int, short, int);
struct mbuf *m_getptr(struct mbuf *, int, int *);
u_int m_length(struct mbuf *, struct mbuf **);
int m_mbuftouio(struct uio *, struct mbuf *, int);
More information about the svn-src-user
mailing list