Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CVS commit: src/sys



On Fri, 10 Oct 2008, Andrew Doran wrote:

> > Log Message:
> > Convert socket options code to use a sockopt structure
> > instead of laying everything into an mbuf.
>
> - This does M_WAITOK allocations while holding sockets locked, which
>   will snarl up socket I/O if the system is low on memory.

Well, that was written before socket locking was merged, seems I (at
least) need to keep up with ramifications, sigh.

While I don't think NOWAIT is the 'best' option here it would be the
easiest to implement as the alloc is carried out at disparate times some
of which may be safe and some not. I'll look into that this weekend.

> - Why does it use malloc() and not kmem_alloc()?

No particular reason. Having not upgraded my userland until recently I
have only just noticed the comment in malloc.9 about discouraging its use
and I must have missed the announcement. Thats easy to change over though
(below) and I'll do it shortly ..

iain

--- /usr/src/sys/kern/uipc_socket.c     2008-08-06 16:16:59.000000000 +0100
+++ uipc_socket.c       2008-10-10 19:34:30.000000000 +0100
@@ -77,7 +77,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_socket.
 #include <sys/proc.h>
 #include <sys/file.h>
 #include <sys/filedesc.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
 #include <sys/mbuf.h>
 #include <sys/domain.h>
 #include <sys/kernel.h>
@@ -1860,7 +1860,7 @@ sockopt_alloc(struct sockopt *sopt, size
        KASSERT(sopt->sopt_size == 0);

        if (len > sizeof(sopt->sopt_buf))
-               sopt->sopt_data = malloc(len, M_SOOPTS, M_WAITOK | M_ZERO);
+               sopt->sopt_data = kmem_zalloc(len, KM_SLEEP);
        else
                sopt->sopt_data = sopt->sopt_buf;

@@ -1890,7 +1890,7 @@ sockopt_destroy(struct sockopt *sopt)
 {

        if (sopt->sopt_data != sopt->sopt_buf)
-               free(sopt->sopt_data, M_SOOPTS);
+               kmem_free(sopt->sopt_data, sopt->sopt_size);

        memset(sopt, 0, sizeof(*sopt));
 }


Home | Main Index | Thread Index | Old Index