Make xl use m_getcl() to allocate an mbuf and a cluster in one shot,

as opposed to one after the other.  This is faster in both -CURRENT
and -STABLE.  Additionally, there is less code duplication for
error-checking.

One thing to note is that this code seems to return(1) when no buffers
are available; perhaps ENOBUFS should be the correct return value?

Partially submitted & tested by: Hiten Pandya <hiten@unixdaemons.com>
MFC after: 1 week
This commit is contained in:
bmilekic 2003-02-22 14:46:31 +00:00
parent 2455f59b36
commit ce390560bb

View File

@ -1939,16 +1939,10 @@ xl_newbuf(sc, c)
int error;
u_int32_t baddr;
MGETHDR(m_new, M_DONTWAIT, MT_DATA);
m_new = m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR);
if (m_new == NULL)
return(ENOBUFS);
MCLGET(m_new, M_DONTWAIT);
if (!(m_new->m_flags & M_EXT)) {
m_freem(m_new);
return(ENOBUFS);
}
m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
/* Force longword alignment for packet payload. */
@ -2441,24 +2435,16 @@ xl_encap(sc, c, m_head)
* and would waste cycles.
*/
if (error) {
struct mbuf *m_new = NULL;
struct mbuf *m_new;
MGETHDR(m_new, M_DONTWAIT, MT_DATA);
m_new = m_head->m_pkthdr.len > MHLEN ?
m_getcl(M_DONTWAIT, MT_DATA, M_PKTHDR) :
m_get(M_DONTWAIT, MT_DATA);
if (m_new == NULL) {
m_freem(m_head);
printf("xl%d: no memory for tx list\n", sc->xl_unit);
return(1);
}
if (m_head->m_pkthdr.len > MHLEN) {
MCLGET(m_new, M_DONTWAIT);
if (!(m_new->m_flags & M_EXT)) {
m_freem(m_new);
m_freem(m_head);
printf("xl%d: no memory for tx list\n",
sc->xl_unit);
return(1);
}
}
m_copydata(m_head, 0, m_head->m_pkthdr.len,
mtod(m_new, caddr_t));
m_new->m_pkthdr.len = m_new->m_len = m_head->m_pkthdr.len;