diff options
Diffstat (limited to 'sys/kern/uipc_mbuf.c')
-rw-r--r-- | sys/kern/uipc_mbuf.c | 109 |
1 files changed, 40 insertions, 69 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index e962670..ea4fd80 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -92,7 +92,6 @@ m_get2(int size, int how, short type, int flags) { struct mb_args args; struct mbuf *m, *n; - uma_zone_t zone; args.flags = flags; args.type = type; @@ -101,24 +100,15 @@ m_get2(int size, int how, short type, int flags) return (uma_zalloc_arg(zone_mbuf, &args, how)); if (size <= MCLBYTES) return (uma_zalloc_arg(zone_pack, &args, how)); - if (size > MJUM16BYTES) + + if (size > MJUMPAGESIZE) return (NULL); m = uma_zalloc_arg(zone_mbuf, &args, how); if (m == NULL) return (NULL); -#if MJUMPAGESIZE != MCLBYTES - if (size <= MJUMPAGESIZE) - zone = zone_jumbop; - else -#endif - if (size <= MJUM9BYTES) - zone = zone_jumbo9; - else - zone = zone_jumbo16; - - n = uma_zalloc_arg(zone, m, how); + n = uma_zalloc_arg(zone_jumbop, m, how); if (n == NULL) { uma_zfree(zone_mbuf, m); return (NULL); @@ -405,7 +395,7 @@ m_demote(struct mbuf *m0, int all) m_freem(m->m_nextpkt); m->m_nextpkt = NULL; } - m->m_flags = m->m_flags & (M_EXT|M_RDONLY|M_FREELIST|M_NOFREE); + m->m_flags = m->m_flags & (M_EXT|M_RDONLY|M_NOFREE); } } @@ -540,8 +530,8 @@ m_dup_pkthdr(struct mbuf *to, struct mbuf *from, int how) #if 0 /* * The mbuf allocator only initializes the pkthdr - * when the mbuf is allocated with MGETHDR. Many users - * (e.g. m_copy*, m_prepend) use MGET and then + * when the mbuf is allocated with m_gethdr(). Many users + * (e.g. m_copy*, m_prepend) use m_get() and then * smash the pkthdr as needed causing these * assertions to trip. For now just disable them. */ @@ -573,15 +563,15 @@ m_prepend(struct mbuf *m, int len, int how) struct mbuf *mn; if (m->m_flags & M_PKTHDR) - MGETHDR(mn, how, m->m_type); + mn = m_gethdr(how, m->m_type); else - MGET(mn, how, m->m_type); + mn = m_get(how, m->m_type); if (mn == NULL) { m_freem(m); return (NULL); } if (m->m_flags & M_PKTHDR) - M_MOVE_PKTHDR(mn, m); + m_move_pkthdr(mn, m); mn->m_next = m; m = mn; if(m->m_flags & M_PKTHDR) { @@ -631,9 +621,9 @@ m_copym(struct mbuf *m, int off0, int len, int wait) break; } if (copyhdr) - MGETHDR(n, wait, m->m_type); + n = m_gethdr(wait, m->m_type); else - MGET(n, wait, m->m_type); + n = m_get(wait, m->m_type); *np = n; if (n == NULL) goto nospace; @@ -832,7 +822,7 @@ m_copypacket(struct mbuf *m, int how) struct mbuf *top, *n, *o; MBUF_CHECKSLEEP(how); - MGET(n, how, m->m_type); + n = m_get(how, m->m_type); top = n; if (n == NULL) goto nospace; @@ -850,7 +840,7 @@ m_copypacket(struct mbuf *m, int how) m = m->m_next; while (m) { - MGET(o, how, m->m_type); + o = m_get(how, m->m_type); if (o == NULL) goto nospace; @@ -1106,12 +1096,11 @@ m_pullup(struct mbuf *n, int len) } else { if (len > MHLEN) goto bad; - MGET(m, M_NOWAIT, n->m_type); + m = m_get(M_NOWAIT, n->m_type); if (m == NULL) goto bad; - m->m_len = 0; if (n->m_flags & M_PKTHDR) - M_MOVE_PKTHDR(m, n); + m_move_pkthdr(m, n); } space = &m->m_dat[MLEN] - (m->m_data + m->m_len); do { @@ -1154,12 +1143,11 @@ m_copyup(struct mbuf *n, int len, int dstoff) if (len > (MHLEN - dstoff)) goto bad; - MGET(m, M_NOWAIT, n->m_type); + m = m_get(M_NOWAIT, n->m_type); if (m == NULL) goto bad; - m->m_len = 0; if (n->m_flags & M_PKTHDR) - M_MOVE_PKTHDR(m, n); + m_move_pkthdr(m, n); m->m_data += dstoff; space = &m->m_dat[MLEN] - (m->m_data + m->m_len); do { @@ -1210,7 +1198,7 @@ m_split(struct mbuf *m0, int len0, int wait) return (NULL); remain = m->m_len - len; if (m0->m_flags & M_PKTHDR) { - MGETHDR(n, wait, m0->m_type); + n = m_gethdr(wait, m0->m_type); if (n == NULL) return (NULL); n->m_pkthdr.rcvif = m0->m_pkthdr.rcvif; @@ -1236,7 +1224,7 @@ m_split(struct mbuf *m0, int len0, int wait) m->m_next = NULL; return (n); } else { - MGET(n, wait, m->m_type); + n = m_get(wait, m->m_type); if (n == NULL) return (NULL); M_ALIGN(n, remain); @@ -1889,14 +1877,22 @@ m_mbuftouio(struct uio *uio, struct mbuf *m, int len) void m_align(struct mbuf *m, int len) { +#ifdef INVARIANTS + const char *msg = "%s: not a virgin mbuf"; +#endif int adjust; - if (m->m_flags & M_EXT) + if (m->m_flags & M_EXT) { + KASSERT(m->m_data == m->m_ext.ext_buf, (msg, __func__)); adjust = m->m_ext.ext_size - len; - else if (m->m_flags & M_PKTHDR) + } else if (m->m_flags & M_PKTHDR) { + KASSERT(m->m_data == m->m_pktdat, (msg, __func__)); adjust = MHLEN - len; - else + } else { + KASSERT(m->m_data == m->m_dat, (msg, __func__)); adjust = MLEN - len; + } + m->m_data += adjust &~ (sizeof(long)-1); } @@ -1978,43 +1974,18 @@ m_unshare(struct mbuf *m0, int how) } /* - * Allocate new space to hold the copy... - */ - /* XXX why can M_PKTHDR be set past the first mbuf? */ - if (mprev == NULL && (m->m_flags & M_PKTHDR)) { - /* - * NB: if a packet header is present we must - * allocate the mbuf separately from any cluster - * because M_MOVE_PKTHDR will smash the data - * pointer and drop the M_EXT marker. - */ - MGETHDR(n, how, m->m_type); - if (n == NULL) { - m_freem(m0); - return (NULL); - } - M_MOVE_PKTHDR(n, m); - MCLGET(n, how); - if ((n->m_flags & M_EXT) == 0) { - m_free(n); - m_freem(m0); - return (NULL); - } - } else { - n = m_getcl(how, m->m_type, m->m_flags); - if (n == NULL) { - m_freem(m0); - return (NULL); - } - } - /* - * ... and copy the data. We deal with jumbo mbufs - * (i.e. m_len > MCLBYTES) by splitting them into - * clusters. We could just malloc a buffer and make - * it external but too many device drivers don't know - * how to break up the non-contiguous memory when + * Allocate new space to hold the copy and copy the data. + * We deal with jumbo mbufs (i.e. m_len > MCLBYTES) by + * splitting them into clusters. We could just malloc a + * buffer and make it external but too many device drivers + * don't know how to break up the non-contiguous memory when * doing DMA. */ + n = m_getcl(how, m->m_type, m->m_flags); + if (n == NULL) { + m_freem(m0); + return (NULL); + } len = m->m_len; off = 0; mfirst = n; |