]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add some limits for auto mempool adjustment
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 24 Aug 2017 20:49:09 +0000 (21:49 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 24 Aug 2017 20:49:09 +0000 (21:49 +0100)
src/libutil/mem_pool.c

index 9856e9198fefcaff561e4f59112192ea4592af05..4a2f54b6414d3ba27991592b51159d3191e1efd4 100644 (file)
@@ -403,6 +403,7 @@ memory_pool_alloc_common (rspamd_mempool_t * pool, gsize size,
                if (cur == NULL || free < size) {
                        /* Allocate new chain element */
                        if (pool->elt_len >= size + MEM_ALIGNMENT) {
+                               pool->entry->elts[pool->entry->cur_elts].fragmentation += size;
                                new = rspamd_mempool_chain_new (pool->elt_len + MEM_ALIGNMENT,
                                                pool_type);
                        }
@@ -632,6 +633,14 @@ rspamd_mempool_adjust_entry (struct rspamd_mempool_entry_point *e)
                e->cur_suggestion *= (1 + (((double)sel_pos) / e->cur_suggestion)) * 1.5;
        }
 
+       /* Some sane limits counting mempool architecture */
+       if (e->cur_suggestion < 1024) {
+               e->cur_suggestion = 1024;
+       }
+       else if (e->cur_suggestion > 1024 * 1024 * 10) {
+               e->cur_suggestion = 1024 * 1024 * 10;
+       }
+
        memset (e->elts, 0, sizeof (e->elts));
 }