On a System where you use the maximum socketbuffer size of 256kbyte you
can run out of memory after less then 9k open sockets.

My patch adds a new uvm_constraint for the mbufs with a bigger memory area.
I choose this area after reading the comments in sys/arch/amd64/include/pmap.h.
This patch further changes the maximum sucketbuffer size from 256k to 1gb as
it is described in the rfc1323 S2.3.

I tested this diff with the ix, em and urndis driver. I know that this
diff only works
for amd64 right now, but i wanted to send this diff as a proposal what could be
done. Maybe somebody has a different solution for this Problem or can me why
this is a bad idea.


Index: arch/amd64/amd64/bus_dma.c
===================================================================
RCS file: /openbsd/src/sys/arch/amd64/amd64/bus_dma.c,v
retrieving revision 1.49
diff -u -p -u -p -r1.49 bus_dma.c
--- arch/amd64/amd64/bus_dma.c  17 Dec 2015 17:16:04 -0000      1.49
+++ arch/amd64/amd64/bus_dma.c  22 Jun 2016 11:33:17 -0000
@@ -584,7 +584,7 @@ _bus_dmamap_load_buffer(bus_dma_tag_t t,
                 */
                pmap_extract(pmap, vaddr, (paddr_t *)&curaddr);

-               if (curaddr > dma_constraint.ucr_high)
+               if (curaddr > mbuf_constraint.ucr_high)
                        panic("Non dma-reachable buffer at curaddr %#lx(raw)",
                            curaddr);

Index: arch/amd64/amd64/machdep.c
===================================================================
RCS file: /openbsd/src/sys/arch/amd64/amd64/machdep.c,v
retrieving revision 1.221
diff -u -p -u -p -r1.221 machdep.c
--- arch/amd64/amd64/machdep.c  21 May 2016 00:56:43 -0000      1.221
+++ arch/amd64/amd64/machdep.c  22 Jun 2016 11:33:17 -0000
@@ -202,9 +202,11 @@ struct vm_map *phys_map = NULL;
 /* UVM constraint ranges. */
 struct uvm_constraint_range  isa_constraint = { 0x0, 0x00ffffffUL };
 struct uvm_constraint_range  dma_constraint = { 0x0, 0xffffffffUL };
+struct uvm_constraint_range  mbuf_constraint = { 0x0, 0xfffffffffUL };
 struct uvm_constraint_range *uvm_md_constraints[] = {
     &isa_constraint,
     &dma_constraint,
+    &mbuf_constraint,
     NULL,
 };

Index: kern/uipc_mbuf.c
===================================================================
RCS file: /openbsd/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.226
diff -u -p -u -p -r1.226 uipc_mbuf.c
--- kern/uipc_mbuf.c    13 Jun 2016 21:24:43 -0000      1.226
+++ kern/uipc_mbuf.c    22 Jun 2016 11:33:18 -0000
@@ -153,7 +153,7 @@ mbinit(void)

        pool_init(&mbpool, MSIZE, 0, 0, 0, "mbufpl", NULL);
        pool_setipl(&mbpool, IPL_NET);
-       pool_set_constraints(&mbpool, &kp_dma_contig);
+       pool_set_constraints(&mbpool, &kp_mbuf_contig);
        pool_setlowat(&mbpool, mblowat);

        pool_init(&mtagpool, PACKET_TAG_MAXSIZE + sizeof(struct m_tag),
@@ -166,7 +166,7 @@ mbinit(void)
                pool_init(&mclpools[i], mclsizes[i], 0, 0, 0,
                    mclnames[i], NULL);
                pool_setipl(&mclpools[i], IPL_NET);
-               pool_set_constraints(&mclpools[i], &kp_dma_contig);
+               pool_set_constraints(&mclpools[i], &kp_mbuf_contig);
                pool_setlowat(&mclpools[i], mcllowat);
        }

Index: sys/socketvar.h
===================================================================
RCS file: /openbsd/src/sys/sys/socketvar.h,v
retrieving revision 1.60
diff -u -p -u -p -r1.60 socketvar.h
--- sys/socketvar.h     25 Feb 2016 07:39:09 -0000      1.60
+++ sys/socketvar.h     22 Jun 2016 11:33:18 -0000
@@ -112,7 +112,7 @@ struct socket {
                short   sb_flags;       /* flags, see below */
                u_short sb_timeo;       /* timeout for read/write */
        } so_rcv, so_snd;
-#define        SB_MAX          (256*1024)      /* default for max chars in 
sockbuf */
+#define        SB_MAX          (1024*1024*1024)/* default for max chars in 
sockbuf */
 #define        SB_LOCK         0x01            /* lock on data queue */
 #define        SB_WANT         0x02            /* someone is waiting to lock */
 #define        SB_WAIT         0x04            /* someone is waiting for 
data/space */
Index: uvm/uvm_extern.h
===================================================================
RCS file: /openbsd/src/sys/uvm/uvm_extern.h,v
retrieving revision 1.139
diff -u -p -u -p -r1.139 uvm_extern.h
--- uvm/uvm_extern.h    5 Jun 2016 08:35:57 -0000       1.139
+++ uvm/uvm_extern.h    22 Jun 2016 11:33:18 -0000
@@ -234,6 +234,7 @@ extern struct uvmexp uvmexp;
 /* Constraint ranges, set by MD code. */
 extern struct uvm_constraint_range  isa_constraint;
 extern struct uvm_constraint_range  dma_constraint;
+extern struct uvm_constraint_range  mbuf_constraint;
 extern struct uvm_constraint_range  no_constraint;
 extern struct uvm_constraint_range *uvm_md_constraints[];

@@ -398,6 +399,7 @@ extern const struct kmem_pa_mode kp_zero
 extern const struct kmem_pa_mode kp_dma;
 extern const struct kmem_pa_mode kp_dma_contig;
 extern const struct kmem_pa_mode kp_dma_zero;
+extern const struct kmem_pa_mode kp_mbuf_contig;
 extern const struct kmem_pa_mode kp_pageable;
 extern const struct kmem_pa_mode kp_none;

Index: uvm/uvm_km.c
===================================================================
RCS file: /openbsd/src/sys/uvm/uvm_km.c,v
retrieving revision 1.128
diff -u -p -u -p -r1.128 uvm_km.c
--- uvm/uvm_km.c        26 Sep 2015 17:55:00 -0000      1.128
+++ uvm/uvm_km.c        22 Jun 2016 11:33:18 -0000
@@ -1016,6 +1016,11 @@ const struct kmem_pa_mode kp_dma_zero =
        .kp_zero = 1
 };

+const struct kmem_pa_mode kp_mbuf_contig = {
+       .kp_constraint = &mbuf_constraint,
+       .kp_maxseg = 1
+};
+
 const struct kmem_pa_mode kp_zero = {
        .kp_constraint = &no_constraint,
        .kp_zero = 1

Reply via email to