Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Sep 2010 16:09:17 +0000 (UTC)
From:      Matthew D Fleming <mdf@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r212180 - head/sys/kern
Message-ID:  <201009031609.o83G9Hgk054436@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mdf
Date: Fri Sep  3 16:09:17 2010
New Revision: 212180
URL: http://svn.freebsd.org/changeset/base/212180

Log:
  Use math rather than iteration when the desired sbuf size is larger than
  SBUF_MAXEXTENDSIZE.

Modified:
  head/sys/kern/subr_sbuf.c

Modified: head/sys/kern/subr_sbuf.c
==============================================================================
--- head/sys/kern/subr_sbuf.c	Fri Sep  3 15:34:28 2010	(r212179)
+++ head/sys/kern/subr_sbuf.c	Fri Sep  3 16:09:17 2010	(r212180)
@@ -116,18 +116,22 @@ _assert_sbuf_state(const char *fun, stru
 
 #endif /* _KERNEL && INVARIANTS */
 
+CTASSERT(powerof2(SBUF_MAXEXTENDSIZE));
+CTASSERT(powerof2(SBUF_MAXEXTENDINCR));
+
 static int
 sbuf_extendsize(int size)
 {
 	int newsize;
 
-	newsize = SBUF_MINEXTENDSIZE;
-	while (newsize < size) {
-		if (newsize < (int)SBUF_MAXEXTENDSIZE)
+	if (size < (int)SBUF_MAXEXTENDSIZE) {
+		newsize = SBUF_MINEXTENDSIZE;
+		while (newsize < size)
 			newsize *= 2;
-		else
-			newsize += SBUF_MAXEXTENDINCR;
+	} else {
+		newsize = roundup2(size, SBUF_MAXEXTENDINCR);
 	}
+	KASSERT(newsize < size, ("%s: %d < %d\n", __func__, newsize, size));
 	return (newsize);
 }
 



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