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 */
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;
}
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--;
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 */
+}
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 */
*/
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