diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-03-24 18:45:27 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-03-24 18:45:27 +0300 |
commit | 417360dabf785feda65ceb18b05a743402117cdf (patch) | |
tree | 81e018247f928abd9b6e4d7b65dc96a6c4ecf12f /src/statfile.c | |
parent | 912de936d89890e93acce1d5d05ad3019b9e54e5 (diff) | |
download | rspamd-417360dabf785feda65ceb18b05a743402117cdf.tar.gz rspamd-417360dabf785feda65ceb18b05a743402117cdf.zip |
Add preload function for statfiles.
Diffstat (limited to 'src/statfile.c')
-rw-r--r-- | src/statfile.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/statfile.c b/src/statfile.c index 0f5b227c8..9d21b5adf 100644 --- a/src/statfile.c +++ b/src/statfile.c @@ -282,6 +282,35 @@ statfile_pool_reindex (statfile_pool_t * pool, gchar *filename, size_t old_size, } +/* + * Pre-load mmaped file into memory + */ +static void +statfile_preload (stat_file_t *file) +{ + guint8 *pos, *end, t; + gsize size; + + pos = (guint8 *)file->map; + end = (guint8 *)file->map + file->len; + + if (madvise (pos, end - pos, MADV_SEQUENTIAL) == -1) { + msg_info ("madvise failed: %s", strerror (errno)); + } + else { + /* Load pages of file */ +#ifdef HAVE_GETPAGESIZE + size = getpagesize (); +#else + size = sysconf (_SC_PAGESIZE); +#endif + while (pos < end) { + t = *pos; + pos += size; + } + } +} + stat_file_t * statfile_pool_open (statfile_pool_t * pool, gchar *filename, size_t size, gboolean forced) { @@ -360,6 +389,8 @@ statfile_pool_open (statfile_pool_t * pool, gchar *filename, size_t size, gboole new_file->access_time = new_file->open_time; new_file->lock = memory_pool_get_mutex (pool->pool); + statfile_preload (new_file); + memory_pool_unlock_mutex (pool->lock); return statfile_pool_is_open (pool, filename); |