Commit 4b07b77f authored by marko's avatar marko

branches/zip: Make zlib use InnoDB memory heaps when processing BLOBs.

page_zip_set_alloc(): New function, to configure zlib to use a memory heap.

btr_store_big_rec_extern_fields(): Reduce memLevel, so that a heap of
256 kilobytes will suffice.  Use page_zip_set_alloc().

btr_copy_externally_stored_field_prefix_low(): Use page_zip_set_alloc().

page_zip_compress(), page_zip_decompress(): Use page_zip_set_alloc().
parent 13efcc13
......@@ -3658,6 +3658,7 @@ btr_store_big_rec_extern_fields(
ulint hint_page_no;
ulint i;
mtr_t mtr;
mem_heap_t* heap = NULL;
page_zip_des_t* page_zip;
z_stream c_stream;
......@@ -3679,11 +3680,16 @@ btr_store_big_rec_extern_fields(
if (UNIV_LIKELY_NULL(page_zip)) {
int err;
c_stream.zalloc = (alloc_func) 0;
c_stream.zfree = (free_func) 0;
c_stream.opaque = (voidpf) 0;
/* Zlib deflate needs 128 kilobytes for the default
window size, plus 512 << memLevel, plus a few
kilobytes for small objects. We use reduced memLevel
to limit the memory consumption, and preallocate the
heap, hoping to avoid memory fragmentation. */
heap = mem_heap_create(250000);
page_zip_set_alloc(&c_stream, heap);
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
err = deflateInit2(&c_stream, Z_DEFAULT_COMPRESSION,
Z_DEFLATED, 15, 7, Z_DEFAULT_STRATEGY);
ut_a(err == Z_OK);
}
......@@ -3736,6 +3742,7 @@ btr_store_big_rec_extern_fields(
if (UNIV_LIKELY_NULL(page_zip)) {
deflateEnd(&c_stream);
mem_heap_free(heap);
}
return(DB_OUT_OF_FILE_SPACE);
......@@ -3965,6 +3972,7 @@ btr_store_big_rec_extern_fields(
if (UNIV_LIKELY_NULL(page_zip)) {
deflateEnd(&c_stream);
mem_heap_free(heap);
}
return(DB_SUCCESS);
......@@ -4437,10 +4445,12 @@ btr_copy_externally_stored_field_prefix_low(
if (UNIV_UNLIKELY(zip_size)) {
int err;
z_stream d_stream;
mem_heap_t* heap;
d_stream.zalloc = (alloc_func) 0;
d_stream.zfree = (free_func) 0;
d_stream.opaque = (voidpf) 0;
/* Zlib inflate needs 32 kilobytes for the default
window size, plus a few kilobytes for small objects. */
heap = mem_heap_create(40000);
page_zip_set_alloc(&d_stream, heap);
err = inflateInit(&d_stream);
ut_a(err == Z_OK);
......@@ -4452,6 +4462,7 @@ btr_copy_externally_stored_field_prefix_low(
btr_copy_zblob_prefix(&d_stream, zip_size,
space_id, page_no, offset);
inflateEnd(&d_stream);
mem_heap_free(heap);
return(d_stream.total_out);
} else {
return(btr_copy_blob_prefix(buf, len, space_id,
......
......@@ -18,7 +18,7 @@ Created June 2005 by Marko Makela
#include "page0types.h"
#include "buf0types.h"
#include "dict0types.h"
#include "ut0byte.h"
#include "mem0mem.h"
/**************************************************************************
Determine the size of a compressed page in bytes. */
......@@ -71,6 +71,15 @@ page_zip_des_init(
page_zip_des_t* page_zip); /* in/out: compressed page
descriptor */
/**************************************************************************
Configure the zlib allocator to use the given memory heap. */
void
page_zip_set_alloc(
/*===============*/
void* stream, /* in/out: zlib stream */
mem_heap_t* heap); /* in: memory heap to use */
/**************************************************************************
Compress a page. */
......
......@@ -600,6 +600,22 @@ page_zip_free(
{
}
/**************************************************************************
Configure the zlib allocator to use the given memory heap. */
void
page_zip_set_alloc(
/*===============*/
void* stream, /* in/out: zlib stream */
mem_heap_t* heap) /* in: memory heap to use */
{
z_stream* strm = stream;
strm->zalloc = page_zip_malloc;
strm->zfree = page_zip_free;
strm->opaque = heap;
}
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
/* Set this variable in a debugger to enable
excessive logging in page_zip_compress(). */
......@@ -993,9 +1009,7 @@ page_zip_compress(
buf_end = buf + page_zip_get_size(page_zip) - PAGE_DATA;
/* Compress the data payload. */
c_stream.zalloc = page_zip_malloc;
c_stream.zfree = page_zip_free;
c_stream.opaque = heap;
page_zip_set_alloc(&c_stream, heap);
err = deflateInit2(&c_stream, Z_DEFAULT_COMPRESSION,
Z_DEFLATED, UNIV_PAGE_SIZE_SHIFT,
......@@ -2279,9 +2293,7 @@ page_zip_decompress(
memcpy(page + (PAGE_NEW_SUPREMUM - REC_N_NEW_EXTRA_BYTES + 1),
supremum_extra_data, sizeof supremum_extra_data);
d_stream.zalloc = page_zip_malloc;
d_stream.zfree = page_zip_free;
d_stream.opaque = heap;
page_zip_set_alloc(&d_stream, heap);
if (UNIV_UNLIKELY(inflateInit2(&d_stream, UNIV_PAGE_SIZE_SHIFT)
!= Z_OK)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment