Source-Changes-HG archive

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

[src/trunk]: src/sys/rump/net/lib/libsockin Only allocate a "struct iovec" ar...



details:   https://anonhg.NetBSD.org/src/rev/d946c43a5951
branches:  trunk
changeset: 748319:d946c43a5951
user:      tron <tron%NetBSD.org@localhost>
date:      Tue Oct 20 12:17:44 2009 +0000

description:
Only allocate a "struct iovec" array from the healp if a reasonably sized
stack array isn't large enough.

diffstat:

 sys/rump/net/lib/libsockin/sockin.c |  18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)

diffs (54 lines):

diff -r 112b3366a135 -r d946c43a5951 sys/rump/net/lib/libsockin/sockin.c
--- a/sys/rump/net/lib/libsockin/sockin.c       Tue Oct 20 10:42:41 2009 +0000
+++ b/sys/rump/net/lib/libsockin/sockin.c       Tue Oct 20 12:17:44 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sockin.c,v 1.19 2009/10/18 22:55:56 tron Exp $ */
+/*     $NetBSD: sockin.c,v 1.20 2009/10/20 12:17:44 tron Exp $ */
 
 /*
  * Copyright (c) 2008, 2009 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sockin.c,v 1.19 2009/10/18 22:55:56 tron Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sockin.c,v 1.20 2009/10/20 12:17:44 tron Exp $");
 
 #include <sys/param.h>
 #include <sys/condvar.h>
@@ -408,7 +408,7 @@
                struct sockaddr *saddr;
                struct msghdr mhdr;
                size_t iov_max, i;
-               struct iovec *iov;
+               struct iovec iov_buf[32], *iov;
                struct mbuf *m2;
                size_t tot;
                int s;
@@ -419,10 +419,13 @@
                for (m2 = m; m2 != NULL; m2 = m2->m_next) {
                        iov_max++;
                }
-               if (iov_max == 0)
-                       iov_max = 1;
 
-               iov = kmem_alloc(sizeof(struct iovec) * iov_max, KM_SLEEP);
+               if (iov_max <= __arraycount(iov_buf)) {
+                       iov = iov_buf;
+               } else {
+                       iov = kmem_alloc(sizeof(struct iovec) * iov_max,
+                           KM_SLEEP);
+               }
 
                tot = 0;
                for (i = 0, m2 = m; m2 != NULL; m2 = m2->m_next, i++) {
@@ -442,7 +445,8 @@
 
                rumpuser_net_sendmsg(s, &mhdr, 0, &error);
 
-               kmem_free(iov, sizeof(struct iovec) * iov_max);
+               if (iov != iov_buf)
+                       kmem_free(iov, sizeof(struct iovec) * iov_max);
 
                m_freem(m);
                m_freem(control);



Home | Main Index | Thread Index | Old Index