From 271414535e0b6cc5b9b6af50cf4f75e4fa64eab0 Mon Sep 17 00:00:00 2001 From: Moinak Ghosh Date: Sat, 21 Dec 2013 20:42:38 +0530 Subject: [PATCH] Drastically reduce memory consumption of PPMD8 in adaptive mode (Use lower max model order). --- adaptive_compress.c | 1 + ppmd_compress.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/adaptive_compress.c b/adaptive_compress.c index 4714b0f..4f99be4 100644 --- a/adaptive_compress.c +++ b/adaptive_compress.c @@ -164,6 +164,7 @@ adapt2_init(void **data, int *level, int nthreads, uint64_t chunksize, adat->ppmd_data = NULL; adat->bsc_data = NULL; lv = *level; + if (lv > 10) lv = 10; rv = ppmd_init(&(adat->ppmd_data), &lv, nthreads, chunksize, file_version, op); lv = *level; if (rv == 0) diff --git a/ppmd_compress.c b/ppmd_compress.c index fafc362..609af42 100644 --- a/ppmd_compress.c +++ b/ppmd_compress.c @@ -30,6 +30,7 @@ #include #include #include +#include /* * PPMd model order to working set memory size mappings. @@ -52,6 +53,9 @@ static unsigned int ppmd8_mem_sz[] = { (1200 << 20) }; +static pthread_mutex_t mem_init_lock = PTHREAD_MUTEX_INITIALIZER; +static int mem_inited = 0; + static ISzAlloc g_Alloc = { slab_alloc, slab_free, @@ -75,6 +79,13 @@ ppmd_init(void **data, int *level, int nthreads, uint64_t chunksize, { CPpmd8 *_ppmd; + pthread_mutex_lock(&mem_init_lock); + if (!mem_inited) { + slab_cache_add(sizeof (CPpmd8)); + slab_cache_add(ppmd8_mem_sz[*level]); + mem_inited = 1; + } + pthread_mutex_unlock(&mem_init_lock); _ppmd = (CPpmd8 *)slab_alloc(NULL, sizeof (CPpmd8)); if (!_ppmd) return (-1);