In commit 799a753be0c116a6117b0afa84f971fc2bdb9d87 the hostlist range
count was expanded and xmalloc/xfree is used to allocate memory for the
_range structure data. xmalloc is slow in setting the memory allocated
to 0: the size of _range structure will be 12 * 64 * 1024 = 768K bytes.
Replacing xmalloc/xfree with malloc/free improve the performance
notably.

I find this when checking slowness of sinfo after upgrading from 2.6.0
to 2.6.6. The multithread patch (commit
17449c066af69441b741110ef51fc2f534272871) does not help. Replacing
hostlist_push with hostlist_push_host (commit
1b0b135f9579e253ddd5bf680d2ea70ad12f9bda) fixes the problem of sinfo,
but I think the root cause is in xmalloc. 
>From 0af92a01b6e74753c4b7b8119c49439a26404bda Mon Sep 17 00:00:00 2001
From: Hongjia Cao <[email protected]>
Date: Thu, 20 Mar 2014 13:12:02 +0800
Subject: [PATCH] replace xmalloc with malloc in hostlist to improve
 performance

---
 src/common/hostlist.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/common/hostlist.c b/src/common/hostlist.c
index 8a2eb87..db8e83f 100644
--- a/src/common/hostlist.c
+++ b/src/common/hostlist.c
@@ -1835,10 +1835,10 @@ _push_range_list(hostlist_t hl, char *prefix, struct _range *range,
 		*q++ = '\0';
 		if (strrchr(tmp_prefix, '[') != NULL)
 			return -1;	/* third range is illegal */
-		prefix_range = xmalloc(sizeof(struct _range) * MAX_RANGES);
+		prefix_range = malloc(sizeof(struct _range) * MAX_RANGES);
 		nr = _parse_range_list(p, prefix_range, MAX_RANGES, dims);
 		if (nr < 0) {
-			xfree(prefix_range);
+			free(prefix_range);
 			return -1;	/* bad numeric expression */
 		}
 		pre_range = prefix_range;
@@ -1847,7 +1847,7 @@ _push_range_list(hostlist_t hl, char *prefix, struct _range *range,
 			if (prefix_cnt > MAX_PREFIX_CNT) {
 				/* Prevent overflow of memory with user input
 				 * of something like "a[0-999999999].b[0-9]" */
-				xfree(prefix_range);
+				free(prefix_range);
 				return -1;
 			}
 			for (j = pre_range->lo; j <= pre_range->hi; j++) {
@@ -1864,7 +1864,7 @@ _push_range_list(hostlist_t hl, char *prefix, struct _range *range,
 			}
 			pre_range++;
 		}
-		xfree(prefix_range);
+		free(prefix_range);
 		return 0;
 	}
 
@@ -1898,7 +1898,7 @@ _hostlist_create_bracketed(const char *hostlist, char *sep,
 		return NULL;
 	}
 
-	ranges = xmalloc(sizeof(struct _range) * MAX_RANGES);
+	ranges = malloc(sizeof(struct _range) * MAX_RANGES);
 	while ((tok = _next_tok(sep, &str)) != NULL) {
 		strncpy(cur_tok, tok, 1024);
 		if ((p = strrchr(tok, '[')) != NULL) {
@@ -1934,7 +1934,7 @@ _hostlist_create_bracketed(const char *hostlist, char *sep,
 		} else
 			hostlist_push_host_dims(new, cur_tok, dims);
 	}
-	xfree(ranges);
+	free(ranges);
 
 	free(orig);
 	return new;
@@ -1942,7 +1942,7 @@ _hostlist_create_bracketed(const char *hostlist, char *sep,
 error:
 	err = errno = EINVAL;
 	hostlist_destroy(new);
-	xfree(ranges);
+	free(ranges);
 	free(orig);
 	seterrno_ret(err, NULL);
 }
-- 
1.9.0

Reply via email to