Re: [PATCH 1/2] lib: add fast lzo decompressor

From: Andreas Robinson
Date: Fri Apr 03 2009 - 06:55:07 EST


On Fri, 2009-04-03 at 07:59 +1100, Nigel Cunningham wrote:

> static int toi_compress_write_page(unsigned long index,
> struct page *buffer_page, unsigned int buf_size)
> {
> int ret, cpu = smp_processor_id();
> struct cpu_context *ctx = &per_cpu(contexts, cpu);
>
> if (!ctx->transform)
> return next_driver->write_page(index, buffer_page, buf_size);
>
> ctx->buffer_start = kmap(buffer_page);
>
> ctx->len = buf_size;

The LZO compressor can produce more bytes than it consumes but here the
output buffer is the same size as the input.
This macro in linux/lzo.h defines how big the buffer needs to be:
#define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)

If there are multiple threads perhaps they clobber each other's output
buffers?

> ret = crypto_comp_compress(ctx->transform,
> ctx->buffer_start, buf_size,
> ctx->page_buffer, &ctx->len);
>
> kunmap(buffer_page);
>
> if (ret) {
> printk(KERN_INFO "Compression failed.\n");
> return ret;
> }
>
> mutex_lock(&stats_lock);
> toi_compress_bytes_in += buf_size;
> toi_compress_bytes_out += ctx->len;
> mutex_unlock(&stats_lock);
>
> if (ctx->len < buf_size) /* some compression */
> return next_driver->write_page(index,
> virt_to_page(ctx->page_buffer),
> ctx->len);
> else
> return next_driver->write_page(index, buffer_page, buf_size);
> }


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/