[systemd-devel] [PATCH] Improve xz compression performance.

2014-07-08 Thread Jon Severinsson
The new lzma2 compression options at the top of compress_blob_xz are
equivalent to using preset 0, exept for using a 1 MiB dictionary
(the same as preset 1). This makes the memory usage at most 7.5 MiB
in the compressor, and 1 MiB in the decompressor, instead of the
previous 92 MiB in the compressor and 8 MiB in the decompressor.

According to test-compress-benchmark this commit makes XZ compression
20 times faster, with no increase in compressed data size.
Using more realistic test data (an ELF binary rather than repeating
ASCII letters 'a' through 'z' in order) it only provides a factor 10
speedup, and at a cost if a 10% increase in compressed data size.
But that is still a worthwhile trade-off.

According to test-compress-benchmark XZ compression is still 25 times
slower than LZ4, but the compressed data is one eighth the size.
Using more realistic test data XZ compression is only 18 times slower
than LZ4, and the compressed data is only one quarter the size.
---
 src/journal/compress.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/journal/compress.c b/src/journal/compress.c
index 49d694a..0bc6879 100644
--- a/src/journal/compress.c
+++ b/src/journal/compress.c
@@ -49,6 +49,8 @@ DEFINE_STRING_TABLE_LOOKUP(object_compressed, int);
 
 int compress_blob_xz(const void *src, uint64_t src_size, void *dst, uint64_t 
*dst_size) {
 #ifdef HAVE_XZ
+const lzma_options_lzma opt = { 1u  20u, NULL, 0, LZMA_LC_DEFAULT, 
LZMA_LP_DEFAULT, LZMA_PB_DEFAULT, LZMA_MODE_FAST, 128, LZMA_MF_HC3, 4};
+const lzma_filter filters[2] = { { LZMA_FILTER_LZMA2, 
(lzma_options_lzma*) opt }, {LZMA_VLI_UNKNOWN, NULL} };
 lzma_ret ret;
 size_t out_pos = 0;
 
@@ -60,8 +62,11 @@ int compress_blob_xz(const void *src, uint64_t src_size, 
void *dst, uint64_t *ds
 /* Returns  0 if we couldn't compress the data or the
  * compressed result is longer than the original */
 
-ret = lzma_easy_buffer_encode(LZMA_PRESET_DEFAULT, LZMA_CHECK_NONE, 
NULL,
-  src, src_size, dst, out_pos, src_size - 
1);
+if (src_size  80)
+return -ENOBUFS;
+
+ret = lzma_stream_buffer_encode((lzma_filter*) filters, 
LZMA_CHECK_NONE, NULL,
+src, src_size, dst, out_pos, src_size 
- 1);
 if (ret != LZMA_OK)
 return -ENOBUFS;
 
-- 
2.0.0

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] Improve xz compression performance.

2014-07-08 Thread David Timothy Strauss
+1 on anything that makes the journal faster on heavy workloads. It
remains a major bottleneck on our systems.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] Improve xz compression performance.

2014-07-08 Thread Zbigniew Jędrzejewski-Szmek
On Tue, Jul 08, 2014 at 06:29:46PM +0200, Jon Severinsson wrote:
 The new lzma2 compression options at the top of compress_blob_xz are
 equivalent to using preset 0, exept for using a 1 MiB dictionary
 (the same as preset 1). This makes the memory usage at most 7.5 MiB
 in the compressor, and 1 MiB in the decompressor, instead of the
 previous 92 MiB in the compressor and 8 MiB in the decompressor.
 
 According to test-compress-benchmark this commit makes XZ compression
 20 times faster, with no increase in compressed data size.
 Using more realistic test data (an ELF binary rather than repeating
 ASCII letters 'a' through 'z' in order) it only provides a factor 10
 speedup, and at a cost if a 10% increase in compressed data size.
 But that is still a worthwhile trade-off.
 
 According to test-compress-benchmark XZ compression is still 25 times
 slower than LZ4, but the compressed data is one eighth the size.
 Using more realistic test data XZ compression is only 18 times slower
 than LZ4, and the compressed data is only one quarter the size.
Nice improvement.

I made some whitespace modifications and added static to the options
and pushed it.

If you modified test-compress-benchmark to use more realistic data,
please send a patch.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel