[patch 8/10] Change default buffer size increment for readline()

kwc at citi.umich.edu kwc at citi.umich.edu
Mon Jul 3 18:34:33 EDT 2006


Signed-off-by: Kevin Coffman <kwc at citi.umich.edu>

The readline routine expects much smaller messages than we are passing.
Change the default initial allocation and increment value from 128
to 2048.  This saves many calls to realloc().


---

 nfs-utils-1.0.8-kwc/utils/gssd/cacheio.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff -puN utils/gssd/cacheio.c~svcgssd_readline_buffsize utils/gssd/cacheio.c
--- nfs-utils-1.0.8/utils/gssd/cacheio.c~svcgssd_readline_buffsize	2006-06-16 16:01:16.701909000 -0400
+++ nfs-utils-1.0.8-kwc/utils/gssd/cacheio.c	2006-06-16 16:01:16.760850000 -0400
@@ -244,6 +244,8 @@ int qword_get_int(char **bpp, int *anint
 	return 0;
 }
 
+#define READLINE_BUFFER_INCREMENT 2048
+
 int readline(int fd, char **buf, int *lenp)
 {
 	/* read a line into *buf, which is malloced *len long
@@ -254,11 +256,11 @@ int readline(int fd, char **buf, int *le
 	int len;
 
 	if (*lenp == 0) {
-		char *b = malloc(128);
+		char *b = malloc(READLINE_BUFFER_INCREMENT);
 		if (b == NULL)
 			return 0;
 		*buf = b;
-		*lenp = 128;
+		*lenp = READLINE_BUFFER_INCREMENT;
 	}
 	len = read(fd, *buf, *lenp);
 	if (len <= 0) {
@@ -271,7 +273,7 @@ int readline(int fd, char **buf, int *le
 	 */
 		char *new;
 		int nl;
-		*lenp += 128;
+		*lenp += READLINE_BUFFER_INCREMENT;
 		new = realloc(*buf, *lenp);
 		if (new == NULL)
 			return 0;

_


More information about the NFSv4 mailing list