generalize the buffer pool so that NFS can become a client
[unix-history] / usr / src / sys / kern / uipc_mbuf.c
index d7e2e45..d301a64 100644 (file)
@@ -1,9 +1,19 @@
 /*
 /*
- * Copyright (c) 1982, 1986 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
  *
  *
- *     @(#)uipc_mbuf.c 7.2 (Berkeley) %G%
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ *     @(#)uipc_mbuf.c 7.4.1.3 (Berkeley) %G%
  */
 
 #include "../machine/pte.h"
  */
 
 #include "../machine/pte.h"
@@ -25,10 +35,15 @@ mbinit()
 {
        int s;
 
 {
        int s;
 
+#if CLBYTES < 4096
+#define NCL_INIT       (4096/CLBYTES)
+#else
+#define NCL_INIT       1
+#endif
        s = splimp();
        s = splimp();
-       if (m_clalloc(4096/CLBYTES, MPG_MBUFS, M_DONTWAIT) == 0)
+       if (m_clalloc(NCL_INIT, MPG_MBUFS, M_DONTWAIT) == 0)
                goto bad;
                goto bad;
-       if (m_clalloc(4096/CLBYTES, MPG_CLUSTERS, M_DONTWAIT) == 0)
+       if (m_clalloc(NCL_INIT, MPG_CLUSTERS, M_DONTWAIT) == 0)
                goto bad;
        splx(s);
        return;
                goto bad;
        splx(s);
        return;
@@ -59,7 +74,7 @@ m_clalloc(ncl, how, canwait)
                }
                return (0);
        }
                }
                return (0);
        }
-       m = cltom(mbx / CLSIZE);
+       m = cltom(mbx * NBPG / MCLBYTES);
        if (memall(&Mbmap[mbx], npg, proc, CSYS) == 0) {
                rmfree(mbmap, (long)npg, (long)mbx);
                return (0);
        if (memall(&Mbmap[mbx], npg, proc, CSYS) == 0) {
                rmfree(mbmap, (long)npg, (long)mbx);
                return (0);
@@ -68,11 +83,12 @@ m_clalloc(ncl, how, canwait)
        switch (how) {
 
        case MPG_CLUSTERS:
        switch (how) {
 
        case MPG_CLUSTERS:
+               ncl = ncl * CLBYTES / MCLBYTES;
                for (i = 0; i < ncl; i++) {
                        m->m_off = 0;
                        m->m_next = mclfree;
                        mclfree = m;
                for (i = 0; i < ncl; i++) {
                        m->m_off = 0;
                        m->m_next = mclfree;
                        mclfree = m;
-                       m += CLBYTES / sizeof (*m);
+                       m += MCLBYTES / sizeof (*m);
                        mbstat.m_clfree++;
                }
                mbstat.m_clusters += ncl;
                        mbstat.m_clfree++;
                }
                mbstat.m_clusters += ncl;
@@ -88,24 +104,10 @@ m_clalloc(ncl, how, canwait)
                        m++;
                }
                break;
                        m++;
                }
                break;
-
-       case MPG_SPACE:
-               mbstat.m_space++;
-               break;
        }
        return ((caddr_t)m);
 }
 
        }
        return ((caddr_t)m);
 }
 
-m_pgfree(addr, n)
-       caddr_t addr;
-       int n;
-{
-
-#ifdef lint
-       addr = addr; n = n;
-#endif
-}
-
 /*
  * Must be called at splimp.
  */
 /*
  * Must be called at splimp.
  */
@@ -188,6 +190,8 @@ m_more(canwait, type)
                        mbstat.m_wait++;
                        m_want++;
                        sleep((caddr_t)&mfree, PZERO - 1);
                        mbstat.m_wait++;
                        m_want++;
                        sleep((caddr_t)&mfree, PZERO - 1);
+                       if (mfree)
+                               break;
                } else {
                        mbstat.m_drops++;
                        return (NULL);
                } else {
                        mbstat.m_drops++;
                        return (NULL);
@@ -218,6 +222,7 @@ m_freem(m)
  * Mbuffer utility routines.
  */
 
  * Mbuffer utility routines.
  */
 
+/*
 /*
  * Make a copy of an mbuf chain starting "off" bytes from the beginning,
  * continuing for "len" bytes.  If len is M_COPYALL, copy to end of mbuf.
 /*
  * Make a copy of an mbuf chain starting "off" bytes from the beginning,
  * continuing for "len" bytes.  If len is M_COPYALL, copy to end of mbuf.
@@ -276,6 +281,40 @@ nospace:
        return (0);
 }
 
        return (0);
 }
 
+/*
+ * Copy data from an mbuf chain starting "off" bytes from the beginning,
+ * continuing for "len" bytes, into the indicated buffer.
+ */
+m_copydata(m, off, len, cp)
+       register struct mbuf *m;
+       register int off;
+       register int len;
+       caddr_t cp;
+{
+       register unsigned count;
+
+       if (off < 0 || len < 0)
+               panic("m_copydata");
+       while (off > 0) {
+               if (m == 0)
+                       panic("m_copydata");
+               if (off < m->m_len)
+                       break;
+               off -= m->m_len;
+               m = m->m_next;
+       }
+       while (len > 0) {
+               if (m == 0)
+                       panic("m_copydata");
+               count = MIN(m->m_len - off, len);
+               bcopy(mtod(m, caddr_t) + off, cp, count);
+               len -= count;
+               cp += count;
+               off = 0;
+               m = m->m_next;
+       }
+}
+
 m_cat(m, n)
        register struct mbuf *m, *n;
 {
 m_cat(m, n)
        register struct mbuf *m, *n;
 {