session = g_malloc0 (sizeof (struct rspamd_controller_session));
session->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- "csession");
+ "csession", 0);
session->ctx = ctx;
session->cfg = ctx->cfg;
session->lang_det = ctx->lang_det;
struct rspamd_config *cfg;
rspamd_mempool_t *pool;
- pool = rspamd_mempool_new (8 * 1024 * 1024, "cfg");
+ pool = rspamd_mempool_new (8 * 1024 * 1024, "cfg", 0);
cfg = rspamd_mempool_alloc0 (pool, sizeof (*cfg));
/* Allocate larger pool for cfg */
cfg->cfg_pool = pool;
bk = g_malloc0 (sizeof (*bk));
bk->path = g_strdup (path);
bk->expired = 0;
- bk->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "fuzzy_backend");
+ bk->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
+ "fuzzy_backend", 0);
bk->db = rspamd_sqlite3_open_or_create (bk->pool, bk->path,
create_tables_sql, 1, err);
priv->parser.buf = rspamd_fstring_sized_new (RSPAMD_MILTER_MESSAGE_CHUNK + 5);
priv->event_loop = ev_base;
priv->state = RSPAMD_MILTER_READ_MORE;
- priv->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "milter");
+ priv->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "milter", 0);
priv->discard_on_reject = milter_ctx->discard_on_reject;
priv->quarantine_on_reject = milter_ctx->quarantine_on_reject;
priv->ev.timeout = timeout;
cache = g_malloc0 (sizeof (struct rspamd_symcache));
cache->static_pool =
- rspamd_mempool_new (rspamd_mempool_suggest_size (), "symcache");
+ rspamd_mempool_new (rspamd_mempool_suggest_size (), "symcache", 0);
cache->items_by_symbol = g_hash_table_new (rspamd_str_hash,
rspamd_str_equal);
cache->items_by_id = g_ptr_array_new ();
* Create new task
*/
struct rspamd_task *
-rspamd_task_new (struct rspamd_worker *worker, struct rspamd_config *cfg,
+rspamd_task_new (struct rspamd_worker *worker,
+ struct rspamd_config *cfg,
rspamd_mempool_t *pool,
struct rspamd_lang_detector *lang_det,
struct ev_loop *event_loop)
guint flags = 0;
if (pool == NULL) {
- task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "task");
+ task_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "task", 0);
flags |= RSPAMD_TASK_FLAG_OWN_POOL;
}
else {
if (map) {
pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- map->tag);
+ map->tag, 0);
}
else {
pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- NULL);
+ NULL, 0);
}
htb = rspamd_mempool_alloc0 (pool, sizeof (*htb));
if (map) {
pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- map->tag);
+ map->tag, 0);
}
else {
pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- NULL);
+ NULL, 0);
}
r = rspamd_mempool_alloc0 (pool, sizeof (*r));
rspamd_mempool_t *pool;
pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- map->tag);
+ map->tag, 0);
re_map = rspamd_mempool_alloc0 (pool, sizeof (*re_map));
re_map->pool = pool;
* @return new memory pool object
*/
rspamd_mempool_t *
-rspamd_mempool_new_ (gsize size, const gchar *tag, const gchar *loc)
+rspamd_mempool_new_ (gsize size, const gchar *tag, gint flags, const gchar *loc)
{
rspamd_mempool_t *new_pool;
gpointer map;
/*
* Memory layout:
* struct rspamd_mempool_t
+ * <optional debug hash table>
* struct rspamd_mempool_specific
* struct _pool_chain
* alignment (if needed)
guchar *mem_chunk;
gint ret = posix_memalign ((void **)&mem_chunk, MIN_MEM_ALIGNMENT,
total_size);
+ gsize priv_offset;
if (ret != 0 || mem_chunk == NULL) {
g_error ("%s: failed to allocate %"G_GSIZE_FORMAT" bytes: %d - %s",
/* Set memory layout */
new_pool = (rspamd_mempool_t *)mem_chunk;
+ if (flags & RSPAMD_MEMPOOL_DEBUG) {
+ /* Allocate debug table */
+ GHashTable *debug_tbl = (GHashTable *)(mem_chunk + sizeof (rspamd_mempool_t));
+
+ debug_tbl = g_hash_table_new (rspamd_str_hash, rspamd_str_equal);
+ priv_offset = sizeof (rspamd_mempool_t) + sizeof (GHashTable *);
+ }
+ else {
+ priv_offset = sizeof (rspamd_mempool_t);
+ }
+
new_pool->priv = (struct rspamd_mempool_specific *)(mem_chunk +
- sizeof (rspamd_mempool_t));
- /* Zere memory for specific and for the first chain */
+ priv_offset);
+ /* Zero memory for specific and for the first chain */
memset (new_pool->priv, 0, sizeof (struct rspamd_mempool_specific) +
sizeof (struct _pool_chain));
new_pool->priv->entry = entry;
new_pool->priv->elt_len = size;
+ new_pool->priv->flags = flags;
if (tag) {
rspamd_strlcpy (new_pool->tag.tagname, tag, sizeof (new_pool->tag.tagname));
nchain = (struct _pool_chain *)
(mem_chunk +
- sizeof (rspamd_mempool_t) +
- sizeof (struct rspamd_mempool_specific));
+ priv_offset +
+ sizeof (struct rspamd_mempool_specific));
guchar *unaligned = mem_chunk +
- sizeof (rspamd_mempool_t) +
+ priv_offset +
sizeof (struct rspamd_mempool_specific) +
sizeof (struct _pool_chain);
static void *
memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size,
- enum rspamd_mempool_chain_type pool_type)
+ enum rspamd_mempool_chain_type pool_type,
+ const gchar *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
static void *
memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size,
- enum rspamd_mempool_chain_type pool_type)
+ enum rspamd_mempool_chain_type pool_type, const gchar *loc)
{
guint8 *tmp;
struct _pool_chain *new, *cur;
void *
-rspamd_mempool_alloc (rspamd_mempool_t * pool, gsize size)
+rspamd_mempool_alloc_ (rspamd_mempool_t * pool, gsize size, const gchar *loc)
{
- return memory_pool_alloc_common (pool, size, RSPAMD_MEMPOOL_NORMAL);
+ return memory_pool_alloc_common (pool, size, RSPAMD_MEMPOOL_NORMAL, loc);
}
void *
-rspamd_mempool_alloc0 (rspamd_mempool_t * pool, gsize size)
+rspamd_mempool_alloc0_ (rspamd_mempool_t * pool, gsize size, const gchar *loc)
{
- void *pointer = rspamd_mempool_alloc (pool, size);
-
+ void *pointer = rspamd_mempool_alloc_ (pool, size, loc);
memset (pointer, 0, size);
return pointer;
}
void *
-rspamd_mempool_alloc0_shared (rspamd_mempool_t * pool, gsize size)
+rspamd_mempool_alloc0_shared_ (rspamd_mempool_t * pool, gsize size, const gchar *loc)
{
void *pointer = rspamd_mempool_alloc_shared (pool, size);
}
void *
-rspamd_mempool_alloc_shared (rspamd_mempool_t * pool, gsize size)
+rspamd_mempool_alloc_shared_ (rspamd_mempool_t * pool, gsize size, const gchar *loc)
{
- return memory_pool_alloc_common (pool, size, RSPAMD_MEMPOOL_SHARED);
+ return memory_pool_alloc_common (pool, size, RSPAMD_MEMPOOL_SHARED, loc);
}
gchar *
-rspamd_mempool_strdup (rspamd_mempool_t * pool, const gchar *src)
+rspamd_mempool_strdup_ (rspamd_mempool_t * pool, const gchar *src, const gchar *loc)
{
gsize len;
gchar *newstr;
}
len = strlen (src);
- newstr = rspamd_mempool_alloc (pool, len + 1);
+ newstr = rspamd_mempool_alloc_ (pool, len + 1, loc);
memcpy (newstr, src, len);
newstr[len] = '\0';
}
gchar *
-rspamd_mempool_fstrdup (rspamd_mempool_t * pool, const struct f_str_s *src)
+rspamd_mempool_fstrdup_ (rspamd_mempool_t * pool, const struct f_str_s *src,
+ const gchar *loc)
{
gchar *newstr;
return NULL;
}
- newstr = rspamd_mempool_alloc (pool, src->len + 1);
+ newstr = rspamd_mempool_alloc_ (pool, src->len + 1, loc);
memcpy (newstr, src->str, src->len);
newstr[src->len] = '\0';
}
gchar *
-rspamd_mempool_ftokdup (rspamd_mempool_t *pool, const rspamd_ftok_t *src)
+rspamd_mempool_ftokdup_ (rspamd_mempool_t *pool, const rspamd_ftok_t *src,
+ const gchar *loc)
{
gchar *newstr;
return NULL;
}
- newstr = rspamd_mempool_alloc (pool, src->len + 1);
+ newstr = rspamd_mempool_alloc_ (pool, src->len + 1, loc);
memcpy (newstr, src->begin, src->len);
newstr[src->len] = '\0';
struct _pool_destructors *cur;
POOL_MTX_LOCK ();
- cur = rspamd_mempool_alloc (pool, sizeof (*cur));
+ cur = rspamd_mempool_alloc_ (pool, sizeof (*cur), line);
cur->func = func;
cur->data = data;
cur->function = function;
* @param size size of pool's page
* @return new memory pool object
*/
-rspamd_mempool_t *rspamd_mempool_new_ (gsize size, const gchar *tag, const gchar *loc);
+rspamd_mempool_t *rspamd_mempool_new_ (gsize size, const gchar *tag, gint flags,
+ const gchar *loc);
-#define rspamd_mempool_new(size, tag) rspamd_mempool_new_((size), (tag), G_STRLOC)
+#define rspamd_mempool_new(size, tag, flags) \
+ rspamd_mempool_new_((size), (tag), (flags), G_STRLOC)
/**
* Get memory from pool
* @param size bytes to allocate
* @return pointer to allocated object
*/
-void *rspamd_mempool_alloc (rspamd_mempool_t *pool, gsize size)
+void *rspamd_mempool_alloc_ (rspamd_mempool_t *pool, gsize size, const gchar *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
+#define rspamd_mempool_alloc(pool, size) \
+ rspamd_mempool_alloc_((pool), (size), G_STRLOC)
/**
* Get memory and set it to zero
* @param size bytes to allocate
* @return pointer to allocated object
*/
-void *rspamd_mempool_alloc0 (rspamd_mempool_t *pool, gsize size)
+void *rspamd_mempool_alloc0_ (rspamd_mempool_t *pool, gsize size, const gchar *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
+#define rspamd_mempool_alloc0(pool, size) \
+ rspamd_mempool_alloc0_((pool), (size), G_STRLOC)
/**
* Make a copy of string in pool
* @param src source string
* @return pointer to newly created string that is copy of src
*/
-gchar *rspamd_mempool_strdup (rspamd_mempool_t *pool, const gchar *src)
+gchar *rspamd_mempool_strdup_ (rspamd_mempool_t *pool, const gchar *src, const gchar *loc)
RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT);
+#define rspamd_mempool_strdup(pool, src) \
+ rspamd_mempool_strdup_ ((pool), (src), G_STRLOC)
/**
* Make a copy of fixed string in pool as null terminated string
* @param src source string
* @return pointer to newly created string that is copy of src
*/
-gchar *rspamd_mempool_fstrdup (rspamd_mempool_t *pool,
- const struct f_str_s *src) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT);
+gchar *rspamd_mempool_fstrdup_ (rspamd_mempool_t *pool,
+ const struct f_str_s *src,
+ const gchar *loc)
+RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT);
+#define rspamd_mempool_fstrdup(pool, src) \
+ rspamd_mempool_fstrdup_ ((pool), (src), G_STRLOC)
struct f_str_tok;
* @param src source string
* @return pointer to newly created string that is copy of src
*/
-gchar *rspamd_mempool_ftokdup (rspamd_mempool_t *pool,
- const struct f_str_tok *src) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT);
+gchar *rspamd_mempool_ftokdup_ (rspamd_mempool_t *pool,
+ const struct f_str_tok *src,
+ const gchar *loc)
+RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT);
+#define rspamd_mempool_ftokdup(pool, src) \
+ rspamd_mempool_ftokdup_ ((pool), (src), G_STRLOC)
/**
* Allocate piece of shared memory
* @param pool memory pool object
* @param size bytes to allocate
*/
-void *rspamd_mempool_alloc_shared (rspamd_mempool_t *pool, gsize size)
+void *rspamd_mempool_alloc_shared_ (rspamd_mempool_t *pool, gsize size, const gchar *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
+#define rspamd_mempool_alloc_shared(pool, size) \
+ rspamd_mempool_alloc_shared_((pool), (size), G_STRLOC)
-void *rspamd_mempool_alloc0_shared (rspamd_mempool_t *pool, gsize size)
+void *rspamd_mempool_alloc0_shared_ (rspamd_mempool_t *pool, gsize size, const gchar *loc)
RSPAMD_ATTR_ALLOC_SIZE(2) RSPAMD_ATTR_ALLOC_ALIGN(MIN_MEM_ALIGNMENT) RSPAMD_ATTR_RETURNS_NONNUL;
+#define rspamd_mempool_alloc0_shared(pool, size) \
+ rspamd_mempool_alloc0_shared_((pool), (size), G_STRLOC)
/**
* Add destructor callback to pool
struct _pool_destructors *dtors_head, *dtors_tail;
GPtrArray *trash_stack;
GHashTable *variables; /**< private memory pool variables */
+ struct rspamd_mempool_entry_point *entry;
gsize elt_len; /**< size of an element */
gsize used_memory;
- gsize wasted_memory;
- struct rspamd_mempool_entry_point *entry;
+ guint wasted_memory;
+ gint flags;
};
/**
return NULL;
}
- tree->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+ tree->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL, 0);
tree->size = 0;
tree->duplicates = 0;
tree->tree = btrie_init (tree->pool);
ctx = g_malloc0 (sizeof (*ctx));
memcpy (&ctx->limits, &default_limits, sizeof (ctx->limits));
ctx->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- "upstreams");
+ "upstreams", 0);
ctx->upstreams = g_queue_new ();
REF_INIT_RETAIN (ctx, rspamd_upstream_ctx_dtor);
{
LUA_TRACE_POINT;
struct memory_pool_s *mempool = rspamd_mempool_new (
- rspamd_mempool_suggest_size (), "lua"), **pmempool;
+ rspamd_mempool_suggest_size (), "lua", 0), **pmempool;
if (mempool) {
pmempool = lua_newuserdata (L, sizeof (struct memory_pool_s *));
{
if (!regexp_static_pool) {
regexp_static_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- "regexp_lua_pool");
+ "regexp_lua_pool", 0);
}
rspamd_lua_new_class (L, "rspamd{regexp}", regexplib_m);
}
else {
own_pool = TRUE;
- pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "url");
+ pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "url", 0);
text = luaL_checklstring (L, 1, &length);
}
}
if (start != NULL) {
- pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+ pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL, 0);
hc = rspamd_mempool_alloc0 (pool, sizeof (*hc));
in = g_byte_array_sized_new (len);
g_byte_array_append (in, start, len);
}
}
else {
- pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "lua util");
+ pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
+ "lua util", 0);
own_pool = TRUE;
}
}
}
else {
- pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "lua util");
+ pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
+ "lua util", 0);
own_pool = TRUE;
}
}
rspamd_mempool_t *pool = rspamd_mempool_new (
- rspamd_mempool_suggest_size (), "lua_control");
+ rspamd_mempool_suggest_size (), "lua_control", 0);
cbd = rspamd_mempool_alloc0 (pool, sizeof (*cbd));
cbd->pool = pool;
cbd->event_loop = event_loop;
fuzzy_module_ctx = rspamd_mempool_alloc0 (cfg->cfg_pool,
sizeof (struct fuzzy_ctx));
- fuzzy_module_ctx->fuzzy_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+ fuzzy_module_ctx->fuzzy_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
+ NULL, 0);
/* TODO: this should match rules count actually */
fuzzy_module_ctx->keypairs_cache = rspamd_keypair_cache_new (32);
fuzzy_module_ctx->fuzzy_rules = g_ptr_array_new ();
rspamd_main->pid = getpid ();
rspamd_main->type = process_quark;
rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- "rspamadm");
+ "rspamadm", 0);
rspamadm_fill_internal_commands (all_commands);
help_command.command_data = all_commands;
rspamd_main = (struct rspamd_main *) g_malloc0 (sizeof (struct rspamd_main));
rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- "main");
+ "main", 0);
rspamd_main->stat = rspamd_mempool_alloc0_shared (rspamd_main->server_pool,
sizeof (struct rspamd_stat));
rspamd_main->cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_DEFAULT);
session->client_addr = NULL;
nsession->ctx = session->ctx;
nsession->worker = session->worker;
- nsession->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "proxy");
+ nsession->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "proxy", 0);
nsession->client_sock = session->client_sock;
session->client_sock = -1;
nsession->mirror_conns = g_ptr_array_sized_new (nsession->ctx->mirrors->len);
session->mirror_conns = g_ptr_array_sized_new (ctx->mirrors->len);
session->pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
- "proxy");
+ "proxy", 0);
session->ctx = ctx;
session->worker = worker;
cfg = (struct rspamd_config *)g_malloc (sizeof (struct rspamd_config));
bzero (cfg, sizeof (struct rspamd_config));
- cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+ cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL, 0);
cfg->dns_retransmits = 2;
cfg->dns_timeout = 0.5;
- pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+ pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL, 0);
s = rspamd_session_create (pool, session_fin, NULL, NULL, NULL);
pid_t pid;
int ret;
- pool = rspamd_mempool_new (sizeof (TEST_BUF), NULL);
+ pool = rspamd_mempool_new (sizeof (TEST_BUF), NULL, 0);
tmp = rspamd_mempool_alloc (pool, sizeof (TEST_BUF));
tmp2 = rspamd_mempool_alloc (pool, sizeof (TEST_BUF) * 2);
tmp3 = rspamd_mempool_alloc_shared (pool, sizeof (TEST_BUF));
g_assert (strncmp (tmp, TEST_BUF, sizeof (TEST_BUF)) == 0);
g_assert (strncmp (tmp2, TEST2_BUF, sizeof (TEST2_BUF)) == 0);
g_assert (strncmp (tmp3, TEST_BUF, sizeof (TEST_BUF)) == 0);
-
+
rspamd_mempool_delete (pool);
rspamd_mempool_stat (&st);
-
+
}
gsize i;
gpointer val;
- pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "btrie");
+ pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "btrie", 0);
tree = btrie_init (pool);
while (t->ip != NULL) {
addrs[i].mask6 = ottery_rand_range(128);
}
- pool = rspamd_mempool_new (65536, "btrie");
+ pool = rspamd_mempool_new (65536, "btrie", 0);
btrie = btrie_init (pool);
msg_notice ("btrie performance (%z elts)", nelts);
rspamd_main = (struct rspamd_main *)g_malloc (sizeof (struct rspamd_main));
memset (rspamd_main, 0, sizeof (struct rspamd_main));
- rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+ rspamd_main->server_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL, 0);
cfg = rspamd_config_new (RSPAMD_CONFIG_INIT_DEFAULT);
cfg->libs_ctx = rspamd_init_libs ();
rspamd_main->cfg = cfg;
- cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL);
+ cfg->cfg_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), NULL, 0);
cfg->log_type = RSPAMD_LOG_CONSOLE;
cfg->log_level = G_LOG_LEVEL_MESSAGE;