don't overflow doing long writes on ptc (from thomas@utah-cs)
[unix-history] / usr / src / sys / kern / uipc_mbuf.c
index 323539d..6bd164d 100644 (file)
@@ -1,21 +1,23 @@
-/*     uipc_mbuf.c     1.38    82/10/09        */
+/*     uipc_mbuf.c     6.1     83/07/29        */
+
+#include "../machine/pte.h"
 
 #include "../h/param.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/proc.h"
 
 #include "../h/param.h"
 #include "../h/dir.h"
 #include "../h/user.h"
 #include "../h/proc.h"
-#include "../h/pte.h"
 #include "../h/cmap.h"
 #include "../h/map.h"
 #include "../h/mbuf.h"
 #include "../h/vm.h"
 #include "../h/cmap.h"
 #include "../h/map.h"
 #include "../h/mbuf.h"
 #include "../h/vm.h"
+#include "../h/kernel.h"
 
 mbinit()
 {
 
 
 mbinit()
 {
 
-       if (m_clalloc(4, MPG_MBUFS) == 0)
+       if (m_clalloc(4096/CLBYTES, MPG_MBUFS) == 0)
                goto bad;
                goto bad;
-       if (m_clalloc(32, MPG_CLUSTERS) == 0)
+       if (m_clalloc(8*4096/CLBYTES, MPG_CLUSTERS) == 0)
                goto bad;
        return;
 bad:
                goto bad;
        return;
 bad:
@@ -34,13 +36,17 @@ m_clalloc(ncl, how)
 
        npg = ncl * CLSIZE;
        s = splimp();           /* careful: rmalloc isn't reentrant */
 
        npg = ncl * CLSIZE;
        s = splimp();           /* careful: rmalloc isn't reentrant */
-       mbx = rmalloc(mbmap, npg);
+       mbx = rmalloc(mbmap, (long)npg);
        splx(s);
        if (mbx == 0)
                return (0);
        m = cltom(mbx / CLSIZE);
        splx(s);
        if (mbx == 0)
                return (0);
        m = cltom(mbx / CLSIZE);
-       if (memall(&Mbmap[mbx], npg, proc, CSYS) == 0)
+       if (memall(&Mbmap[mbx], npg, proc, CSYS) == 0) {
+               s = splimp();
+               rmfree(mbmap, (long)npg, (long)mbx);
+               splx(s);
                return (0);
                return (0);
+       }
        vmaccess(&Mbmap[mbx], (caddr_t)m, npg);
        switch (how) {
 
        vmaccess(&Mbmap[mbx], (caddr_t)m, npg);
        switch (how) {
 
@@ -60,7 +66,8 @@ m_clalloc(ncl, how)
        case MPG_MBUFS:
                for (i = ncl * CLBYTES / sizeof (*m); i > 0; i--) {
                        m->m_off = 0;
        case MPG_MBUFS:
                for (i = ncl * CLBYTES / sizeof (*m); i > 0; i--) {
                        m->m_off = 0;
-                       m->m_free = 0;
+                       m->m_type = MT_DATA;
+                       mbstat.m_mtypes[MT_DATA]++;
                        mbstat.m_mbufs++;
                        (void) m_free(m);
                        m++;
                        mbstat.m_mbufs++;
                        (void) m_free(m);
                        m++;
@@ -99,22 +106,22 @@ steal:
  * for critical paths.
  */
 struct mbuf *
  * for critical paths.
  */
 struct mbuf *
-m_get(canwait)
-       int canwait;
+m_get(canwait, type)
+       int canwait, type;
 {
        register struct mbuf *m;
 
 {
        register struct mbuf *m;
 
-       MGET(m, canwait);
+       MGET(m, canwait, type);
        return (m);
 }
 
 struct mbuf *
        return (m);
 }
 
 struct mbuf *
-m_getclr(canwait)
-       int canwait;
+m_getclr(canwait, type)
+       int canwait, type;
 {
        register struct mbuf *m;
 
 {
        register struct mbuf *m;
 
-       m = m_get(canwait);
+       m = m_get(canwait, type);
        if (m == 0)
                return (0);
        bzero(mtod(m, caddr_t), MLEN);
        if (m == 0)
                return (0);
        bzero(mtod(m, caddr_t), MLEN);
@@ -133,8 +140,8 @@ m_free(m)
 
 /*ARGSUSED*/
 struct mbuf *
 
 /*ARGSUSED*/
 struct mbuf *
-m_more(type)
-       int type;
+m_more(canwait, type)
+       int canwait, type;
 {
        register struct mbuf *m;
 
 {
        register struct mbuf *m;
 
@@ -142,8 +149,8 @@ m_more(type)
                mbstat.m_drops++;
                return (NULL);
        }
                mbstat.m_drops++;
                return (NULL);
        }
-#define m_more(x) (panic("m_more"), (struct mbuf *)0)
-       MGET(m, type);
+#define m_more(x,y) (panic("m_more"), (struct mbuf *)0)
+       MGET(m, canwait, type);
 #undef m_more
        return (m);
 }
 #undef m_more
        return (m);
 }
@@ -174,11 +181,13 @@ m_copy(m, off, len)
 {
        register struct mbuf *n, **np;
        struct mbuf *top, *p;
 {
        register struct mbuf *n, **np;
        struct mbuf *top, *p;
+       int type;
 
        if (len == 0)
                return (0);
        if (off < 0 || len < 0)
                panic("m_copy");
 
        if (len == 0)
                return (0);
        if (off < 0 || len < 0)
                panic("m_copy");
+       type = m->m_type;
        while (off > 0) {
                if (m == 0)
                        panic("m_copy");
        while (off > 0) {
                if (m == 0)
                        panic("m_copy");
@@ -195,7 +204,7 @@ m_copy(m, off, len)
                                panic("m_copy");
                        break;
                }
                                panic("m_copy");
                        break;
                }
-               MGET(n, 1);
+               MGET(n, M_WAIT, type);
                *np = n;
                if (n == 0)
                        goto nospace;
                *np = n;
                if (n == 0)
                        goto nospace;
@@ -290,7 +299,7 @@ m_pullup(m0, len)
        n = m0;
        if (len > MLEN)
                goto bad;
        n = m0;
        if (len > MLEN)
                goto bad;
-       MGET(m, M_DONTWAIT);
+       MGET(m, M_DONTWAIT, n->m_type);
        if (m == 0)
                goto bad;
        m->m_len = 0;
        if (m == 0)
                goto bad;
        m->m_len = 0;