Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 29 Apr 2014 19:48:11 +0000 (UTC)
From:      "Alexander V. Chernikov" <melifaro@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r265104 - head/sys/net
Message-ID:  <201404291948.s3TJmBcw005371@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: melifaro
Date: Tue Apr 29 19:48:11 2014
New Revision: 265104
URL: http://svnweb.freebsd.org/changeset/base/265104

Log:
  Partially revert r265019 - allocating 512 bytes on stack
  can be too much for architectures like ARM. Always use rounded
  malloc instead.
  
  Discussed with:	jmallett
  MFC after:	4 weeks

Modified:
  head/sys/net/rtsock.c

Modified: head/sys/net/rtsock.c
==============================================================================
--- head/sys/net/rtsock.c	Tue Apr 29 19:14:42 2014	(r265103)
+++ head/sys/net/rtsock.c	Tue Apr 29 19:48:11 2014	(r265104)
@@ -531,7 +531,6 @@ route_output(struct mbuf *m, struct sock
 	sa_family_t saf = AF_UNSPEC;
 	struct rawcb *rp = NULL;
 	struct walkarg w;
-	char msgbuf[512];
 
 	fibnum = so->so_fibnum;
 
@@ -548,20 +547,12 @@ route_output(struct mbuf *m, struct sock
 
 	/*
 	 * Most of current messages are in range 200-240 bytes,
-	 * minimize possible failures by using on-stack buffer
-	 * which should fit for most messages.
-	 * However, use stable memory if we need to handle
-	 * something large.
+	 * minimize possible re-allocation on reply using larger size
+	 * buffer aligned on 1k boundaty.
 	 */
-	if (len < sizeof(msgbuf)) {
-		alloc_len = sizeof(msgbuf);
-		rtm = (struct rt_msghdr *)msgbuf;
-	} else {
-		alloc_len = roundup2(len, 1024);
-		rtm = malloc(alloc_len, M_TEMP, M_NOWAIT);
-		if (rtm == NULL)
-			senderr(ENOBUFS);
-	}
+	alloc_len = roundup2(len, 1024);
+	if ((rtm = malloc(alloc_len, M_TEMP, M_NOWAIT)) == NULL)
+		senderr(ENOBUFS);
 
 	m_copydata(m, 0, len, (caddr_t)rtm);
 	bzero(&info, sizeof(info));
@@ -569,8 +560,7 @@ route_output(struct mbuf *m, struct sock
 
 	if (rtm->rtm_version != RTM_VERSION) {
 		/* Do not touch message since format is unknown */
-		if ((char *)rtm != msgbuf)
-			free(rtm, M_TEMP);
+		free(rtm, M_TEMP);
 		rtm = NULL;
 		senderr(EPROTONOSUPPORT);
 	}
@@ -861,7 +851,7 @@ flush:
 	 */
 	if ((so->so_options & SO_USELOOPBACK) == 0) {
 		if (V_route_cb.any_count <= 1) {
-			if (rtm != NULL && (char *)rtm != msgbuf)
+			if (rtm != NULL)
 				free(rtm, M_TEMP);
 			m_freem(m);
 			return (error);
@@ -899,8 +889,7 @@ flush:
 		} else if (m->m_pkthdr.len > rtm->rtm_msglen)
 			m_adj(m, rtm->rtm_msglen - m->m_pkthdr.len);
 
-		if ((char *)rtm != msgbuf)
-			free(rtm, M_TEMP);
+		free(rtm, M_TEMP);
 	}
 	if (m != NULL) {
 		M_SETFIB(m, fibnum);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201404291948.s3TJmBcw005371>