summaryrefslogtreecommitdiff
path: root/src/journal/compress.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-11-21 00:28:00 +0100
committerLennart Poettering <lennart@poettering.net>2012-11-21 00:28:00 +0100
commit93b73b064c663d6248bebfbbbd82989b5ca10fc5 (patch)
tree464aea01e7952ddcf7088a594e0bfdf2e4647a0a /src/journal/compress.c
parentf2cf0403c99e8fa44c14b0ef70af90801f8681f0 (diff)
journal: by default do not decompress dat objects larger than 64K
This introduces a new data threshold setting for sd_journal objects which controls the maximum size of objects to decompress. This is relieves the library from having to decompress full data objects even if a client program is only interested in the initial part of them. This speeds up "systemd-coredumpctl" drastically when invoked without parameters.
Diffstat (limited to 'src/journal/compress.c')
-rw-r--r--src/journal/compress.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/journal/compress.c b/src/journal/compress.c
index 75e70c5ffa..a4427be75a 100644
--- a/src/journal/compress.c
+++ b/src/journal/compress.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <lzma.h>
+#include "macro.h"
#include "compress.h"
bool compress_blob(const void *src, uint64_t src_size, void *dst, uint64_t *dst_size) {
@@ -66,10 +67,11 @@ fail:
}
bool uncompress_blob(const void *src, uint64_t src_size,
- void **dst, uint64_t *dst_alloc_size, uint64_t* dst_size) {
+ void **dst, uint64_t *dst_alloc_size, uint64_t* dst_size, uint64_t dst_max) {
lzma_stream s = LZMA_STREAM_INIT;
lzma_ret ret;
+ uint64_t space;
bool b = false;
assert(src);
@@ -98,7 +100,8 @@ bool uncompress_blob(const void *src, uint64_t src_size,
s.avail_in = src_size;
s.next_out = *dst;
- s.avail_out = *dst_alloc_size;
+ space = dst_max > 0 ? MIN(*dst_alloc_size, dst_max) : *dst_alloc_size;
+ s.avail_out = space;
for (;;) {
void *p;
@@ -111,18 +114,23 @@ bool uncompress_blob(const void *src, uint64_t src_size,
if (ret != LZMA_OK)
goto fail;
- p = realloc(*dst, *dst_alloc_size*2);
+ if (dst_max > 0 && (space - s.avail_out) >= dst_max)
+ break;
+
+ p = realloc(*dst, space*2);
if (!p)
goto fail;
s.next_out = (uint8_t*) p + ((uint8_t*) s.next_out - (uint8_t*) *dst);
- s.avail_out += *dst_alloc_size;
+ s.avail_out += space;
+
+ space *= 2;
*dst = p;
- *dst_alloc_size *= 2;
+ *dst_alloc_size = space;
}
- *dst_size = *dst_alloc_size - s.avail_out;
+ *dst_size = space - s.avail_out;
b = true;
fail: