diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2012-10-05 20:37:54 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2012-10-05 20:37:54 +0400 |
commit | 21f0f09256917dd5dff8d3cf4680322f96c67b7f (patch) | |
tree | 512bff36311841fbd9ac1e3ad91f30f43ae7d3a0 /src | |
parent | 3789849b7b2e617d0a287fe77490b6643f3a6b74 (diff) | |
download | rspamd-21f0f09256917dd5dff8d3cf4680322f96c67b7f.tar.gz rspamd-21f0f09256917dd5dff8d3cf4680322f96c67b7f.zip |
* Use mlock to speed up classifiers by locking statfiles in the RAM.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/statfile.c | 28 | ||||
-rw-r--r-- | src/statfile.h | 7 |
3 files changed, 36 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c index 8bdcc5979..406df0adf 100644 --- a/src/main.c +++ b/src/main.c @@ -401,6 +401,8 @@ fork_worker (struct rspamd_main *rspamd, struct worker_conf *cf) case 0: /* Update pid for logging */ update_log_pid (cf->type, rspamd->logger); + /* Lock statfile pool if possible */ + statfile_pool_lockall (rspamd->statfile_pool); /* Drop privilleges */ drop_priv (rspamd); /* Set limits */ diff --git a/src/statfile.c b/src/statfile.c index 15c41550a..0c1cee2e0 100644 --- a/src/statfile.c +++ b/src/statfile.c @@ -214,6 +214,7 @@ statfile_pool_new (memory_pool_t *pool, size_t max_size) new->max = max_size; new->files = memory_pool_alloc0 (new->pool, STATFILES_MAX * sizeof (stat_file_t)); new->lock = memory_pool_get_mutex (new->pool); + new->mlock_ok = TRUE; return new; } @@ -375,7 +376,14 @@ statfile_pool_open (statfile_pool_t * pool, gchar *filename, size_t size, gboole rspamd_strlcpy (new_file->filename, filename, sizeof (new_file->filename)); new_file->len = st.st_size; - /* Aqquire lock for this operation */ + /* Try to lock pages in RAM */ + if (pool->mlock_ok) { + if (mlock (new_file->map, new_file->len) == -1) { + msg_warn ("mlock of statfile failed, maybe you need to increase RLIMIT_MEMLOCK limit for a process: %s", strerror (errno)); + pool->mlock_ok = FALSE; + } + } + /* Acquire lock for this operation */ lock_file (new_file->fd, FALSE); if (statfile_pool_check (new_file) == -1) { pool->opened--; @@ -948,4 +956,22 @@ get_statfile_by_symbol (statfile_pool_t *pool, struct classifier_config *ccf, return res; } +void +statfile_pool_lockall (statfile_pool_t *pool) +{ + stat_file_t *file; + gint i; + + if (pool->mlock_ok) { + for (i = 0; i < pool->opened; i ++) { + file = &pool->files[i]; + if (mlock (file->map, file->len) == -1) { + msg_warn ("mlock of statfile failed, maybe you need to increase RLIMIT_MEMLOCK limit for a process: %s", strerror (errno)); + pool->mlock_ok = FALSE; + return; + } + } + } + /* Do not try to lock if mlock failed */ +} diff --git a/src/statfile.h b/src/statfile.h index edb58e5db..5f7e856e5 100644 --- a/src/statfile.h +++ b/src/statfile.h @@ -94,6 +94,7 @@ typedef struct statfile_pool_s { memory_pool_mutex_t *lock; /**< mutex */ struct event *invalidate_event; /**< event for pool invalidation */ struct timeval invalidate_tv; + gboolean mlock_ok; /**< whether it is possible to use mlock (2) to avoid statfiles unloading */ } statfile_pool_t; /* Forwarded declarations */ @@ -140,6 +141,12 @@ gint statfile_pool_close (statfile_pool_t *pool, stat_file_t *file, gboolean kee void statfile_pool_delete (statfile_pool_t *pool); /** + * Try to lock all statfiles in memory + * @param pool statfile pool object + */ +void statfile_pool_lockall (statfile_pool_t *pool); + +/** * Lock specified file for exclusive use (eg. learning) * @param pool statfile pool object * @param filename name of statfile |