+#if MCLBYTES < 4096
+#define NCL_INIT (4096/CLBYTES)
+#else
+#define NCL_INIT 1
+#endif
+ s = splimp();
+ if (m_clalloc(NCL_INIT, M_DONTWAIT) == 0)
+ goto bad;
+ splx(s);
+ return;
+bad:
+ panic("mbinit");
+}
+
+/*
+ * Allocate some number of mbuf clusters
+ * and place on cluster free list.
+ * Must be called at splimp.
+ */
+/* ARGSUSED */
+m_clalloc(ncl, canwait)
+ register int ncl;
+{
+ int npg, mbx;
+ register caddr_t p;
+ register int i;
+ static int logged;
+
+ npg = ncl * CLSIZE;
+ mbx = rmalloc(mbmap, (long)npg);
+ if (mbx == 0) {
+ if (logged == 0) {
+ logged++;
+ log(LOG_ERR, "mbuf map full\n");
+ }
+ return (0);
+ }
+ p = cltom(mbx * NBPG / MCLBYTES);
+ if (memall(&Mbmap[mbx], npg, proc, CSYS) == 0) {
+ rmfree(mbmap, (long)npg, (long)mbx);
+ return (0);
+ }
+ vmaccess(&Mbmap[mbx], p, npg);
+ ncl = ncl * CLBYTES / MCLBYTES;
+ for (i = 0; i < ncl; i++) {
+ ((union mcluster *)p)->mcl_next = mclfree;
+ mclfree = (union mcluster *)p;
+ p += MCLBYTES;
+ mbstat.m_clfree++;
+ }
+ mbstat.m_clusters += ncl;
+ return (1);
+}
+
+/*
+ * When MGET failes, ask protocols to free space when short of memory,
+ * then re-attempt to allocate an mbuf.
+ */