* there is enough memory, simply call the check_pool_memory_size()
* with the desired size and it will adjust only if necessary.
*
- * Kern E. Sibbald
+ * Kern E. Sibbald
*
* Version $Id$
*/
#include "bacula.h"
struct s_pool_ctl {
- int32_t size; /* default size */
- int32_t max_allocated; /* max allocated */
- int32_t max_used; /* max buffers used */
- int32_t in_use; /* number in use */
- struct abufhead *free_buf; /* pointer to free buffers */
+ int32_t size; /* default size */
+ int32_t max_allocated; /* max allocated */
+ int32_t max_used; /* max buffers used */
+ int32_t in_use; /* number in use */
+ struct abufhead *free_buf; /* pointer to free buffers */
};
/* Bacula Name length plus extra */
* Define default Pool buffer sizes
*/
static struct s_pool_ctl pool_ctl[] = {
- { 256, 256, 0, 0, NULL }, /* PM_NOPOOL no pooling */
- { NLEN, NLEN,0, 0, NULL }, /* PM_NAME Bacula name */
- { 256, 256, 0, 0, NULL }, /* PM_FNAME filename buffers */
- { 512, 512, 0, 0, NULL }, /* PM_MESSAGE message buffer */
- { 1024, 1024, 0, 0, NULL } /* PM_EMSG error message buffer */
+ { 256, 256, 0, 0, NULL }, /* PM_NOPOOL no pooling */
+ { NLEN, NLEN,0, 0, NULL }, /* PM_NAME Bacula name */
+ { 256, 256, 0, 0, NULL }, /* PM_FNAME filename buffers */
+ { 512, 512, 0, 0, NULL }, /* PM_MESSAGE message buffer */
+ { 1024, 1024, 0, 0, NULL } /* PM_EMSG error message buffer */
};
#else
/* This is used ONLY when stress testing the code */
static struct s_pool_ctl pool_ctl[] = {
- { 20, 20, 0, 0, NULL }, /* PM_NOPOOL no pooling */
- { NLEN, NLEN,0, 0, NULL }, /* PM_NAME Bacula name */
- { 20, 20, 0, 0, NULL }, /* PM_FNAME filename buffers */
- { 20, 20, 0, 0, NULL }, /* PM_MESSAGE message buffer */
- { 20, 20, 0, 0, NULL } /* PM_EMSG error message buffer */
+ { 20, 20, 0, 0, NULL }, /* PM_NOPOOL no pooling */
+ { NLEN, NLEN,0, 0, NULL }, /* PM_NAME Bacula name */
+ { 20, 20, 0, 0, NULL }, /* PM_FNAME filename buffers */
+ { 20, 20, 0, 0, NULL }, /* PM_MESSAGE message buffer */
+ { 20, 20, 0, 0, NULL } /* PM_EMSG error message buffer */
};
#endif
/* Memory allocation control structures and storage. */
struct abufhead {
- int32_t ablen; /* Buffer length in bytes */
- int32_t pool; /* pool */
- struct abufhead *next; /* pointer to next free buffer */
+ int32_t ablen; /* Buffer length in bytes */
+ int32_t pool; /* pool */
+ struct abufhead *next; /* pointer to next free buffer */
};
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
struct abufhead *buf;
if (pool > PM_MAX) {
- Emsg2(M_ABORT, 0, "MemPool index %d larger than max %d\n", pool, PM_MAX);
+ Emsg2(M_ABORT, 0, _("MemPool index %d larger than max %d\n"), pool, PM_MAX);
}
P(mutex);
if (pool_ctl[pool].free_buf) {
pool_ctl[pool].free_buf = buf->next;
pool_ctl[pool].in_use++;
if (pool_ctl[pool].in_use > pool_ctl[pool].max_used) {
- pool_ctl[pool].max_used = pool_ctl[pool].in_use;
+ pool_ctl[pool].max_used = pool_ctl[pool].in_use;
}
V(mutex);
Dmsg3(1800, "sm_get_pool_memory reuse %x to %s:%d\n", buf, fname, lineno);
if ((buf = (struct abufhead *)sm_malloc(fname, lineno, pool_ctl[pool].size+HEAD_SIZE)) == NULL) {
V(mutex);
- Emsg1(M_ABORT, 0, "Out of memory requesting %d bytes\n", pool_ctl[pool].size);
+ Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), pool_ctl[pool].size);
}
buf->ablen = pool_ctl[pool].size;
buf->pool = pool;
int pool = 0;
if ((buf = (struct abufhead *)sm_malloc(fname, lineno, size+HEAD_SIZE)) == NULL) {
- Emsg1(M_ABORT, 0, "Out of memory requesting %d bytes\n", size);
+ Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), size);
}
buf->ablen = size;
buf->pool = pool;
buf = sm_realloc(fname, lineno, cp, size+HEAD_SIZE);
if (buf == NULL) {
V(mutex);
- Emsg1(M_ABORT, 0, "Out of memory requesting %d bytes\n", size);
+ Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), size);
}
((struct abufhead *)buf)->ablen = size;
pool = ((struct abufhead *)buf)->pool;
pool = buf->pool;
pool_ctl[pool].in_use--;
if (pool == 0) {
- free((char *)buf); /* free nonpooled memory */
- } else { /* otherwise link it to the free pool chain */
+ free((char *)buf); /* free nonpooled memory */
+ } else { /* otherwise link it to the free pool chain */
#ifdef DEBUG
struct abufhead *next;
/* Don't let him free the same buffer twice */
for (next=pool_ctl[pool].free_buf; next; next=next->next) {
- if (next == buf) {
+ if (next == buf) {
Dmsg4(1800, "bad free_pool_memory %x pool=%d from %s:%d\n", buf, pool, fname, lineno);
- V(mutex); /* unblock the pool */
- ASSERT(next != buf); /* attempt to free twice */
- }
+ V(mutex); /* unblock the pool */
+ ASSERT(next != buf); /* attempt to free twice */
+ }
}
#endif
buf->next = pool_ctl[pool].free_buf;
#else
-/* ========= NO SMARTALLOC ========================================= */
+/* ========= NO SMARTALLOC ========================================= */
POOLMEM *get_pool_memory(int pool)
{
if ((buf=malloc(pool_ctl[pool].size+HEAD_SIZE)) == NULL) {
V(mutex);
- Emsg1(M_ABORT, 0, "Out of memory requesting %d bytes\n", pool_ctl[pool].size);
+ Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), pool_ctl[pool].size);
}
buf->ablen = pool_ctl[pool].size;
buf->pool = pool;
int pool = 0;
if ((buf=malloc(size+HEAD_SIZE)) == NULL) {
- Emsg1(M_ABORT, 0, "Out of memory requesting %d bytes\n", size);
+ Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), size);
}
buf->ablen = size;
buf->pool = pool;
buf = realloc(cp, size+HEAD_SIZE);
if (buf == NULL) {
V(mutex);
- Emsg1(M_ABORT, 0, "Out of memory requesting %d bytes\n", size);
+ Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), size);
}
((struct abufhead *)buf)->ablen = size;
pool = ((struct abufhead *)buf)->pool;
pool = buf->pool;
pool_ctl[pool].in_use--;
if (pool == 0) {
- free((char *)buf); /* free nonpooled memory */
- } else { /* otherwise link it to the free pool chain */
+ free((char *)buf); /* free nonpooled memory */
+ } else { /* otherwise link it to the free pool chain */
#ifdef DEBUG
struct abufhead *next;
/* Don't let him free the same buffer twice */
for (next=pool_ctl[pool].free_buf; next; next=next->next) {
- if (next == buf) {
- V(mutex);
- ASSERT(next != buf); /* attempt to free twice */
- }
+ if (next == buf) {
+ V(mutex);
+ ASSERT(next != buf); /* attempt to free twice */
+ }
}
#endif
buf->next = pool_ctl[pool].free_buf;
for (int i=1; i<=PM_MAX; i++) {
buf = pool_ctl[i].free_buf;
while (buf) {
- next = buf->next;
- free((char *)buf);
- buf = next;
+ next = buf->next;
+ free((char *)buf);
+ buf = next;
}
pool_ctl[i].free_buf = NULL;
}
Pmsg0(-1, "Pool Maxsize Maxused Inuse\n");
for (int i=0; i<=PM_MAX; i++)
Pmsg4(-1, "%5s %7d %7d %5d\n", pool_name(i), pool_ctl[i].max_allocated,
- pool_ctl[i].max_used, pool_ctl[i].in_use);
+ pool_ctl[i].max_used, pool_ctl[i].in_use);
Pmsg0(-1, "\n");
}
char *cp = mem;
cp -= HEAD_SIZE;
size = ((struct abufhead *)cp)->ablen;
- Dmsg1(000, "max_size=%d\n", size);
+ Dmsg1(900, "max_size=%d\n", size);
return size;
}
buf = (char *)realloc(cp, size+HEAD_SIZE);
if (buf == NULL) {
V(mutex);
- Emsg1(M_ABORT, 0, "Out of memory requesting %d bytes\n", size);
+ Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), size);
}
- Dmsg2(000, "Old buf=0x%x new buf=0x%x\n", cp, buf);
+ Dmsg2(900, "Old buf=0x%x new buf=0x%x\n", cp, buf);
((struct abufhead *)buf)->ablen = size;
pool = ((struct abufhead *)buf)->pool;
if (size > pool_ctl[pool].max_allocated) {
}
mem = buf+HEAD_SIZE;
V(mutex);
- Dmsg3(000, "Old buf=0x%x new buf=0x%x mem=0x%x\n", cp, buf, mem);
+ Dmsg3(900, "Old buf=0x%x new buf=0x%x mem=0x%x\n", cp, buf, mem);
}
int POOL_MEM::strcat(const char *str)