summaryrefslogtreecommitdiff
path: root/storage/xtradb/buf/buf0buf.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2017-05-23 11:09:47 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2017-05-23 11:09:47 +0300
commit8f643e2063c9890a353149f39ef85b2cf3151fd0 (patch)
treec5468b905c8858dc1cc80ccb2072a923b28c8783 /storage/xtradb/buf/buf0buf.cc
parent3aecedb2f8f99c446a5ba0b02efcf422a252c9e8 (diff)
parentb61700c22104b513caa9a85e5c6529aa5f2bf4e4 (diff)
downloadmariadb-git-8f643e2063c9890a353149f39ef85b2cf3151fd0.tar.gz
Merge 10.1 into 10.2
Diffstat (limited to 'storage/xtradb/buf/buf0buf.cc')
-rw-r--r--storage/xtradb/buf/buf0buf.cc86
1 files changed, 56 insertions, 30 deletions
diff --git a/storage/xtradb/buf/buf0buf.cc b/storage/xtradb/buf/buf0buf.cc
index 67c265cb827..4678b0eb6a8 100644
--- a/storage/xtradb/buf/buf0buf.cc
+++ b/storage/xtradb/buf/buf0buf.cc
@@ -65,6 +65,18 @@ Created 11/5/1995 Heikki Tuuri
#include "fil0pagecompress.h"
#include "ha_prototypes.h"
+#ifdef UNIV_LINUX
+#include <stdlib.h>
+#endif
+
+#ifdef HAVE_LZO
+#include "lzo/lzo1x.h"
+#endif
+
+#ifdef HAVE_SNAPPY
+#include "snappy-c.h"
+#endif
+
/** Decrypt a page.
@param[in,out] bpage Page control block
@param[in,out] space tablespace
@@ -77,6 +89,26 @@ buf_page_decrypt_after_read(buf_page_t* bpage, fil_space_t* space)
/* prototypes for new functions added to ha_innodb.cc */
trx_t* innobase_get_trx();
+inline void* aligned_malloc(size_t size, size_t align) {
+ void *result;
+#ifdef _MSC_VER
+ result = _aligned_malloc(size, align);
+#else
+ if(posix_memalign(&result, align, size)) {
+ result = 0;
+ }
+#endif
+ return result;
+}
+
+inline void aligned_free(void *ptr) {
+#ifdef _MSC_VER
+ _aligned_free(ptr);
+#else
+ free(ptr);
+#endif
+}
+
static inline
void
_increment_page_get_statistics(buf_block_t* block, trx_t* trx)
@@ -108,10 +140,6 @@ _increment_page_get_statistics(buf_block_t* block, trx_t* trx)
return;
}
-#ifdef HAVE_LZO
-#include "lzo/lzo1x.h"
-#endif
-
/*
IMPLEMENTATION OF THE BUFFER POOL
=================================
@@ -1531,7 +1559,7 @@ buf_pool_init_instance(
ut_a(srv_n_page_hash_locks != 0);
ut_a(srv_n_page_hash_locks <= MAX_PAGE_HASH_LOCKS);
- buf_pool->page_hash = ha_create(2 * buf_pool->curr_size,
+ buf_pool->page_hash = ib_create(2 * buf_pool->curr_size,
srv_n_page_hash_locks,
MEM_HEAP_FOR_PAGE_HASH,
SYNC_BUF_PAGE_HASH);
@@ -1640,20 +1668,14 @@ buf_pool_free_instance(
if (buf_pool->tmp_arr) {
for(ulint i = 0; i < buf_pool->tmp_arr->n_slots; i++) {
buf_tmp_buffer_t* slot = &(buf_pool->tmp_arr->slots[i]);
-#ifdef HAVE_LZO
- if (slot && slot->lzo_mem) {
- ut_free(slot->lzo_mem);
- slot->lzo_mem = NULL;
- }
-#endif
- if (slot && slot->crypt_buf_free) {
- ut_free(slot->crypt_buf_free);
- slot->crypt_buf_free = NULL;
+ if (slot && slot->crypt_buf) {
+ aligned_free(slot->crypt_buf);
+ slot->crypt_buf = NULL;
}
- if (slot && slot->comp_buf_free) {
- ut_free(slot->comp_buf_free);
- slot->comp_buf_free = NULL;
+ if (slot && slot->comp_buf) {
+ aligned_free(slot->comp_buf);
+ slot->comp_buf = NULL;
}
}
}
@@ -6174,22 +6196,27 @@ buf_pool_reserve_tmp_slot(
buf_pool_mutex_exit(buf_pool);
/* Allocate temporary memory for encryption/decryption */
- if (free_slot->crypt_buf_free == NULL) {
- free_slot->crypt_buf_free = static_cast<byte *>(ut_malloc(UNIV_PAGE_SIZE*2));
- free_slot->crypt_buf = static_cast<byte *>(ut_align(free_slot->crypt_buf_free, UNIV_PAGE_SIZE));
- memset(free_slot->crypt_buf_free, 0, UNIV_PAGE_SIZE *2);
+ if (free_slot->crypt_buf == NULL) {
+ free_slot->crypt_buf = static_cast<byte*>(aligned_malloc(UNIV_PAGE_SIZE, UNIV_PAGE_SIZE));
+ memset(free_slot->crypt_buf, 0, UNIV_PAGE_SIZE);
}
/* For page compressed tables allocate temporary memory for
compression/decompression */
- if (compressed && free_slot->comp_buf_free == NULL) {
- free_slot->comp_buf_free = static_cast<byte *>(ut_malloc(UNIV_PAGE_SIZE*2));
- free_slot->comp_buf = static_cast<byte *>(ut_align(free_slot->comp_buf_free, UNIV_PAGE_SIZE));
- memset(free_slot->comp_buf_free, 0, UNIV_PAGE_SIZE *2);
-#ifdef HAVE_LZO
- free_slot->lzo_mem = static_cast<byte *>(ut_malloc(LZO1X_1_15_MEM_COMPRESS));
- memset(free_slot->lzo_mem, 0, LZO1X_1_15_MEM_COMPRESS);
+ if (compressed && free_slot->comp_buf == NULL) {
+ ulint size = UNIV_PAGE_SIZE;
+
+ /* Both snappy and lzo compression methods require that
+ output buffer used for compression is bigger than input
+ buffer. Increase the allocated buffer size accordingly. */
+#if HAVE_SNAPPY
+ size = snappy_max_compressed_length(size);
+#endif
+#if HAVE_LZO
+ size += LZO1X_1_15_MEM_COMPRESS;
#endif
+ free_slot->comp_buf = static_cast<byte*>(aligned_malloc(size, UNIV_PAGE_SIZE));
+ memset(free_slot->comp_buf, 0, size);
}
return (free_slot);
@@ -6277,8 +6304,7 @@ buf_page_encrypt_before_write(
fsp_flags_get_page_compression_level(space->flags),
fil_space_get_block_size(space, bpage->offset),
encrypted,
- &out_len,
- IF_LZO(slot->lzo_mem, NULL));
+ &out_len);
bpage->real_size = out_len;