]> source.dussan.org Git - rspamd.git/commitdiff
Add preload function for statfiles.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 24 Mar 2011 15:45:27 +0000 (18:45 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 24 Mar 2011 15:45:27 +0000 (18:45 +0300)
src/statfile.c

index 0f5b227c8e8e03eefe5de6bade2f5bd2aea66cc3..9d21b5adff12ff60cdd8b299bd0d0598abe00df4 100644 (file)
@@ -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);