From 0c4f341b65b5f8f4e369f4c9774e3040a94a499a Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Tue, 11 Apr 2006 22:34:19 +0000 Subject: [PATCH] Make the sbcast buffer large right from the start to avoid realloc calls. --- src/common/pack.c | 8 ++++++++ src/common/pack.h | 1 + src/common/slurm_protocol_pack.c | 6 +++++- src/common/slurm_xlator.h | 1 + src/sbcast/agent.c | 2 +- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/common/pack.c b/src/common/pack.c index 7fbb12500e6..2ee6ac36082 100644 --- a/src/common/pack.c +++ b/src/common/pack.c @@ -49,6 +49,7 @@ */ strong_alias(create_buf, slurm_create_buf); strong_alias(free_buf, slurm_free_buf); +strong_alias(grow_buf, slurm_grow_buf); strong_alias(init_buf, slurm_init_buf); strong_alias(xfer_buf_data, slurm_xfer_buf_data); strong_alias(pack_time, slurm_pack_time); @@ -96,6 +97,13 @@ void free_buf(Buf my_buf) xfree(my_buf); } +/* Grow a buffer by the specified amount */ +void grow_buf (Buf buffer, int size) +{ + buffer->size += size; + xrealloc(buffer->head, buffer->size); +} + /* init_buf - create an empty buffer of the given size */ Buf init_buf(int size) { diff --git a/src/common/pack.h b/src/common/pack.h index 588bca7133e..d8f5c791735 100644 --- a/src/common/pack.h +++ b/src/common/pack.h @@ -66,6 +66,7 @@ typedef struct slurm_buf * Buf; Buf create_buf (char *data, int size); void free_buf(Buf my_buf); Buf init_buf(int size); +void grow_buf (Buf my_buf, int size); void *xfer_buf_data(Buf my_buf); void pack_time(time_t val, Buf buffer); diff --git a/src/common/slurm_protocol_pack.c b/src/common/slurm_protocol_pack.c index 6157420897d..21fb012ceb0 100644 --- a/src/common/slurm_protocol_pack.c +++ b/src/common/slurm_protocol_pack.c @@ -3581,9 +3581,13 @@ _unpack_checkpoint_resp_msg(checkpoint_resp_msg_t **msg_ptr, Buf buffer) static void _pack_file_bcast(file_bcast_msg_t * msg , Buf buffer ) { - int i; + int buf_size = 1024, i; xassert ( msg != NULL ); + for (i=0; i<FILE_BLOCKS; i++) + buf_size += msg->block_len[i]; + grow_buf(buffer, buf_size); + pack16 ( msg->block_no, buffer ); pack16 ( msg->last_block, buffer ); pack16 ( msg->force, buffer ); diff --git a/src/common/slurm_xlator.h b/src/common/slurm_xlator.h index 442b5348983..e3e15ba47d6 100644 --- a/src/common/slurm_xlator.h +++ b/src/common/slurm_xlator.h @@ -187,6 +187,7 @@ /* pack.[ch] functions */ #define create_buf slurm_create_buf #define free_buf slurm_free_buf +#define grow_buf slurm_grow_buf #define init_buf slurm_init_buf #define xfer_buf_data slurm_xfer_buf_data #define pack_time slurm_pack_time diff --git a/src/sbcast/agent.c b/src/sbcast/agent.c index d2aaf473591..56399d14c1d 100644 --- a/src/sbcast/agent.c +++ b/src/sbcast/agent.c @@ -50,7 +50,7 @@ #include "src/sbcast/sbcast.h" #define MAX_RETRIES 10 -#define MAX_THREADS 3 /* These can be huge messages, so +#define MAX_THREADS 4 /* These can be huge messages, so * only run MAX_THREADS at one time */ typedef struct thd { pthread_t thread; /* thread ID */ -- GitLab