From: Vsevolod Stakhov Date: Thu, 24 Mar 2011 15:45:27 +0000 (+0300) Subject: Add preload function for statfiles. X-Git-Tag: 0.3.11~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=417360dabf785feda65ceb18b05a743402117cdf;p=thirdparty%2Frspamd.git Add preload function for statfiles. --- diff --git a/src/statfile.c b/src/statfile.c index 0f5b227c8e..9d21b5adff 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);