Commit 6e2c59d4 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 73bb3415
...@@ -3658,6 +3658,7 @@ btr_store_big_rec_extern_fields( ...@@ -3658,6 +3658,7 @@ btr_store_big_rec_extern_fields(
ulint hint_page_no; ulint hint_page_no;
ulint i; ulint i;
mtr_t mtr; mtr_t mtr;
mem_heap_t* heap = NULL;
page_zip_des_t* page_zip; page_zip_des_t* page_zip;
z_stream c_stream; z_stream c_stream;
...@@ -3679,11 +3680,16 @@ btr_store_big_rec_extern_fields( ...@@ -3679,11 +3680,16 @@ btr_store_big_rec_extern_fields(
if (UNIV_LIKELY_NULL(page_zip)) { if (UNIV_LIKELY_NULL(page_zip)) {
int err; int err;
c_stream.zalloc = (alloc_func) 0; /* Zlib deflate needs 128 kilobytes for the default
c_stream.zfree = (free_func) 0; window size, plus 512 << memLevel, plus a few
c_stream.opaque = (voidpf) 0; 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); ut_a(err == Z_OK);
} }
...@@ -3736,6 +3742,7 @@ btr_store_big_rec_extern_fields( ...@@ -3736,6 +3742,7 @@ btr_store_big_rec_extern_fields(
if (UNIV_LIKELY_NULL(page_zip)) { if (UNIV_LIKELY_NULL(page_zip)) {
deflateEnd(&c_stream); deflateEnd(&c_stream);
mem_heap_free(heap);
} }
return(DB_OUT_OF_FILE_SPACE); return(DB_OUT_OF_FILE_SPACE);
...@@ -3965,6 +3972,7 @@ next_zip_page: ...@@ -3965,6 +3972,7 @@ next_zip_page:
if (UNIV_LIKELY_NULL(page_zip)) { if (UNIV_LIKELY_NULL(page_zip)) {
deflateEnd(&c_stream); deflateEnd(&c_stream);
mem_heap_free(heap);
} }
return(DB_SUCCESS); return(DB_SUCCESS);
...@@ -4437,10 +4445,12 @@ btr_copy_externally_stored_field_prefix_low( ...@@ -4437,10 +4445,12 @@ btr_copy_externally_stored_field_prefix_low(
if (UNIV_UNLIKELY(zip_size)) { if (UNIV_UNLIKELY(zip_size)) {
int err; int err;
z_stream d_stream; z_stream d_stream;
mem_heap_t* heap;
d_stream.zalloc = (alloc_func) 0; /* Zlib inflate needs 32 kilobytes for the default
d_stream.zfree = (free_func) 0; window size, plus a few kilobytes for small objects. */
d_stream.opaque = (voidpf) 0; heap = mem_heap_create(40000);
page_zip_set_alloc(&d_stream, heap);
err = inflateInit(&d_stream); err = inflateInit(&d_stream);
ut_a(err == Z_OK); ut_a(err == Z_OK);
...@@ -4452,6 +4462,7 @@ btr_copy_externally_stored_field_prefix_low( ...@@ -4452,6 +4462,7 @@ btr_copy_externally_stored_field_prefix_low(
btr_copy_zblob_prefix(&d_stream, zip_size, btr_copy_zblob_prefix(&d_stream, zip_size,
space_id, page_no, offset); space_id, page_no, offset);
inflateEnd(&d_stream); inflateEnd(&d_stream);
mem_heap_free(heap);
return(d_stream.total_out); return(d_stream.total_out);
} else { } else {
return(btr_copy_blob_prefix(buf, len, space_id, return(btr_copy_blob_prefix(buf, len, space_id,
......
...@@ -18,7 +18,7 @@ Created June 2005 by Marko Makela ...@@ -18,7 +18,7 @@ Created June 2005 by Marko Makela
#include "page0types.h" #include "page0types.h"
#include "buf0types.h" #include "buf0types.h"
#include "dict0types.h" #include "dict0types.h"
#include "ut0byte.h" #include "mem0mem.h"
/************************************************************************** /**************************************************************************
Determine the size of a compressed page in bytes. */ Determine the size of a compressed page in bytes. */
...@@ -71,6 +71,15 @@ page_zip_des_init( ...@@ -71,6 +71,15 @@ page_zip_des_init(
page_zip_des_t* page_zip); /* in/out: compressed page page_zip_des_t* page_zip); /* in/out: compressed page
descriptor */ 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. */ Compress a page. */
......
...@@ -600,6 +600,22 @@ page_zip_free( ...@@ -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 #if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
/* Set this variable in a debugger to enable /* Set this variable in a debugger to enable
excessive logging in page_zip_compress(). */ excessive logging in page_zip_compress(). */
...@@ -993,9 +1009,7 @@ page_zip_compress( ...@@ -993,9 +1009,7 @@ page_zip_compress(
buf_end = buf + page_zip_get_size(page_zip) - PAGE_DATA; buf_end = buf + page_zip_get_size(page_zip) - PAGE_DATA;
/* Compress the data payload. */ /* Compress the data payload. */
c_stream.zalloc = page_zip_malloc; page_zip_set_alloc(&c_stream, heap);
c_stream.zfree = page_zip_free;
c_stream.opaque = heap;
err = deflateInit2(&c_stream, Z_DEFAULT_COMPRESSION, err = deflateInit2(&c_stream, Z_DEFAULT_COMPRESSION,
Z_DEFLATED, UNIV_PAGE_SIZE_SHIFT, Z_DEFLATED, UNIV_PAGE_SIZE_SHIFT,
...@@ -2279,9 +2293,7 @@ zlib_error: ...@@ -2279,9 +2293,7 @@ zlib_error:
memcpy(page + (PAGE_NEW_SUPREMUM - REC_N_NEW_EXTRA_BYTES + 1), memcpy(page + (PAGE_NEW_SUPREMUM - REC_N_NEW_EXTRA_BYTES + 1),
supremum_extra_data, sizeof supremum_extra_data); supremum_extra_data, sizeof supremum_extra_data);
d_stream.zalloc = page_zip_malloc; page_zip_set_alloc(&d_stream, heap);
d_stream.zfree = page_zip_free;
d_stream.opaque = heap;
if (UNIV_UNLIKELY(inflateInit2(&d_stream, UNIV_PAGE_SIZE_SHIFT) if (UNIV_UNLIKELY(inflateInit2(&d_stream, UNIV_PAGE_SIZE_SHIFT)
!= Z_OK)) { != 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