/* Define to 1 if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H
+/* Set if have malloc_trim */
+#undef HAVE_MALLOC_TRIM
+
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
[echo 'configure: cannot find needed function.'; exit 1]
)
+AC_CHECK_FUNCS(malloc_trim, [AC_DEFINE(HAVE_MALLOC_TRIM, 1, [Set if have malloc_trim])])
+
AC_CHECK_FUNCS(fchdir, [AC_DEFINE(HAVE_FCHDIR)])
AC_CHECK_FUNCS(strtoll, [AC_DEFINE(HAVE_STRTOLL)])
AC_CHECK_FUNCS(posix_fadvise)
int memory_cmd(UAContext *ua, const char *cmd)
{
+ garbage_collect_memory();
list_dir_status_header(ua);
sm_dump(false, true);
return 1;
parse_ua_args(ua);
run_cmd(ua, ua->cmd);
free_rx(&rx);
- close_memory_pool(); /* release freed pool memory */
+ garbage_collect_memory(); /* release unused memory */
return 1;
bail_out:
}
free_rx(&rx);
- close_memory_pool(); /* release freed pool memory */
+ garbage_collect_memory(); /* release unused memory */
return 0;
}
}
}
#endif
+ /*
+ * At this point, the tree is built, so we can garbage collect
+ * any memory released by the SQL engine that RedHat has
+ * not returned to the OS :-(
+ */
+ garbage_collect_memory();
+
/*
* Look at the first JobId on the list (presumably the oldest) and
* if it is marked purged, don't do the manual selection because
bsock->tls = NULL;
bsock->errors = 0;
bsock->m_blocking = 1;
- bsock->msg = get_pool_memory(PM_MESSAGE);
+ bsock->msg = get_pool_memory(PM_BSOCK);
bsock->errmsg = get_pool_memory(PM_MESSAGE);
bsock->set_who(bstrdup(who));
bsock->set_host(bstrdup(host));
{
BSOCK *bsock = (BSOCK *)malloc(sizeof(BSOCK));
memcpy(bsock, osock, sizeof(BSOCK));
- bsock->msg = get_pool_memory(PM_MESSAGE);
+ bsock->msg = get_pool_memory(PM_BSOCK);
bsock->errmsg = get_pool_memory(PM_MESSAGE);
if (osock->who()) {
bsock->set_who(bstrdup(osock->who()));
{
memset(this, 0, sizeof(BSOCK));
m_blocking = 1;
- msg = get_pool_memory(PM_MESSAGE);
+ msg = get_pool_memory(PM_BSOCK);
errmsg = get_pool_memory(PM_MESSAGE);
/*
* ****FIXME**** reduce this to a few hours once
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2003-2010 Free Software Foundation Europe e.V.
+ Copyright (C) 2003-2011 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
free(table);
table = NULL;
+ garbage_collect_memory();
Dmsg0(100, "Done destroy.\n");
}
free_common_jcr(jcr);
close_msg(NULL); /* flush any daemon messages */
- garbage_collect_memory_pool();
Dmsg0(dbglvl, "Exit free_jcr\n");
}
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
*/
#include "bacula.h"
+#ifdef HAVE_MALLOC_TRIM
+#include <malloc.h>
+#endif
struct s_pool_ctl {
int32_t size; /* default size */
{ 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 */
+ { 1024, 1024, 0, 0, NULL }, /* PM_EMSG error message buffer */
+ { 4096, 4096, 0, 0, NULL } /* PM_BSOCK message buffer */
};
#else
{ 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_EMSG error message buffer */
+ { 20, 20, 0, 0, NULL } /* PM_BSOCK message buffer */
};
#endif
if (now >= last_garbage_collection + garbage_interval) {
last_garbage_collection = now;
V(mutex);
- close_memory_pool();
+ garbage_collect_memory();
} else {
V(mutex);
}
}
-/* Release all pooled memory */
+/* Release all freed pooled memory */
void close_memory_pool()
{
struct abufhead *buf, *next;
}
+/*
+ * Garbage collect and trim memory if possible
+ * This should be called after all big memory usages
+ * if possible.
+ */
+void garbage_collect_memory()
+{
+ close_memory_pool(); /* release free chain */
+#ifdef HAVE_MALLOC_TRIM
+ P(mutex);
+ malloc_trim(8192);
+ V(mutex);
+#endif
+}
+
#ifdef DEBUG
static const char *pool_name(int pool)
{
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
extern void close_memory_pool();
extern void print_memory_pool_stats();
+extern void garbage_collect_memory();
#define PM_NOPOOL 0 /* nonpooled memory */
#define PM_FNAME 2 /* file name buffer */
#define PM_MESSAGE 3 /* daemon message */
#define PM_EMSG 4 /* error message */
-#define PM_MAX PM_EMSG /* Number of types */
+#define PM_BSOCK 5 /* BSOCK buffer */
+#define PM_MAX PM_BSOCK /* Number of types */
class POOL_MEM {
char *mem;
}
Dmsg3(100, "Total size=%u blocks=%u freed_blocks=%u\n", root->total_size, root->blocks, freed_blocks);
free(root);
+ garbage_collect_memory();
return;
}