summaryrefslogtreecommitdiffstats
path: root/src/statfile.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2012-10-05 20:37:54 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2012-10-05 20:37:54 +0400
commit21f0f09256917dd5dff8d3cf4680322f96c67b7f (patch)
tree512bff36311841fbd9ac1e3ad91f30f43ae7d3a0 /src/statfile.c
parent3789849b7b2e617d0a287fe77490b6643f3a6b74 (diff)
downloadrspamd-21f0f09256917dd5dff8d3cf4680322f96c67b7f.tar.gz
rspamd-21f0f09256917dd5dff8d3cf4680322f96c67b7f.zip
* Use mlock to speed up classifiers by locking statfiles in the RAM.
Diffstat (limited to 'src/statfile.c')
-rw-r--r--src/statfile.c28
1 files changed, 27 insertions, 1 deletions
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 */
+}