diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2019-12-05 06:42:31 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2019-12-05 06:42:31 +0200 |
commit | 42a4ae54c2f05bccd2d6d752bbc23652962b6929 (patch) | |
tree | b483ef198239a4c41556a8181d27b9bb7d053b03 | |
parent | 504202bd7fe7d7e85039fface189e721d1aeff7a (diff) | |
download | mariadb-git-42a4ae54c2f05bccd2d6d752bbc23652962b6929.tar.gz |
MDEV-21225 Remove ut_align() and use aligned_malloc()
Before commit 90c52e5291b3ad0935df7da56ec0fcbf530733b4 introduced
aligned_malloc(), InnoDB always used a pattern of over-allocating
memory and invoking ut_align() to guarantee the desired alignment.
It is cleaner to invoke aligned_malloc() and aligned_free() directly.
ut_align(): Remove. In assertions, ut_align_down() can be used instead.
-rw-r--r-- | extra/innochecksum.cc | 27 | ||||
-rw-r--r-- | extra/mariabackup/backup_copy.cc | 3 | ||||
-rw-r--r-- | extra/mariabackup/fil_cur.cc | 11 | ||||
-rw-r--r-- | extra/mariabackup/fil_cur.h | 3 | ||||
-rw-r--r-- | extra/mariabackup/xtrabackup.cc | 28 | ||||
-rw-r--r-- | storage/innobase/buf/buf0buf.cc | 5 | ||||
-rw-r--r-- | storage/innobase/buf/buf0dblwr.cc | 65 | ||||
-rw-r--r-- | storage/innobase/fil/fil0fil.cc | 13 | ||||
-rw-r--r-- | storage/innobase/fsp/fsp0file.cc | 37 | ||||
-rw-r--r-- | storage/innobase/include/buf0buf.h | 2 | ||||
-rw-r--r-- | storage/innobase/include/buf0dblwr.h | 2 | ||||
-rw-r--r-- | storage/innobase/include/fsp0file.h | 9 | ||||
-rw-r--r-- | storage/innobase/include/row0ftsort.h | 4 | ||||
-rw-r--r-- | storage/innobase/include/univ.i | 2 | ||||
-rw-r--r-- | storage/innobase/include/ut0byte.h | 10 | ||||
-rw-r--r-- | storage/innobase/include/ut0byte.ic | 20 | ||||
-rw-r--r-- | storage/innobase/log/log0log.cc | 8 | ||||
-rw-r--r-- | storage/innobase/os/os0file.cc | 18 | ||||
-rw-r--r-- | storage/innobase/page/page0zip.cc | 9 | ||||
-rw-r--r-- | storage/innobase/row/row0ftsort.cc | 24 | ||||
-rw-r--r-- | storage/innobase/row/row0import.cc | 33 |
21 files changed, 97 insertions, 236 deletions
diff --git a/extra/innochecksum.cc b/extra/innochecksum.cc index 3bc00b339b1..dae032ecd74 100644 --- a/extra/innochecksum.cc +++ b/extra/innochecksum.cc @@ -1551,8 +1551,6 @@ int main( /* our input filename. */ char* filename; /* Buffer to store pages read. */ - byte* buf_ptr = NULL; - byte* xdes_ptr = NULL; byte* buf = NULL; byte* xdes = NULL; /* bytes read count */ @@ -1632,10 +1630,10 @@ int main( } - buf_ptr = (byte*) malloc(UNIV_PAGE_SIZE_MAX * 2); - xdes_ptr = (byte*)malloc(UNIV_PAGE_SIZE_MAX * 2); - buf = (byte *) ut_align(buf_ptr, UNIV_PAGE_SIZE_MAX); - xdes = (byte *) ut_align(xdes_ptr, UNIV_PAGE_SIZE_MAX); + buf = static_cast<byte*>(aligned_malloc(UNIV_PAGE_SIZE_MAX, + UNIV_PAGE_SIZE_MAX)); + xdes = static_cast<byte*>(aligned_malloc(UNIV_PAGE_SIZE_MAX, + UNIV_PAGE_SIZE_MAX)); /* The file name is not optional. */ for (int i = 0; i < argc; ++i) { @@ -2014,21 +2012,9 @@ first_non_zero: fclose(log_file); } - free(buf_ptr); - free(xdes_ptr); - - my_end(exit_status); - DBUG_RETURN(exit_status); + goto common_exit; my_exit: - if (buf_ptr) { - free(buf_ptr); - } - - if (xdes_ptr) { - free(xdes_ptr); - } - if (!read_from_stdin && fil_in) { fclose(fil_in); } @@ -2037,6 +2023,9 @@ my_exit: fclose(log_file); } +common_exit: + aligned_free(buf); + aligned_free(xdes); my_end(exit_status); DBUG_RETURN(exit_status); } diff --git a/extra/mariabackup/backup_copy.cc b/extra/mariabackup/backup_copy.cc index 6ede0288e3a..ed977931423 100644 --- a/extra/mariabackup/backup_copy.cc +++ b/extra/mariabackup/backup_copy.cc @@ -466,14 +466,13 @@ struct datafile_cur_t { char abs_path[FN_REFLEN]; MY_STAT statinfo; uint thread_n; - byte* orig_buf; byte* buf; size_t buf_size; size_t buf_read; size_t buf_offset; explicit datafile_cur_t(const char* filename = NULL) : - file(), thread_n(0), orig_buf(NULL), buf(NULL), buf_size(0), + file(), thread_n(0), buf(NULL), buf_size(0), buf_read(0), buf_offset(0) { memset(rel_path, 0, sizeof rel_path); diff --git a/extra/mariabackup/fil_cur.cc b/extra/mariabackup/fil_cur.cc index 453aab802c9..d1b2275a845 100644 --- a/extra/mariabackup/fil_cur.cc +++ b/extra/mariabackup/fil_cur.cc @@ -142,7 +142,7 @@ xb_fil_cur_open( int err; /* Initialize these first so xb_fil_cur_close() handles them correctly in case of error */ - cursor->orig_buf = NULL; + cursor->buf = NULL; cursor->node = NULL; cursor->space_id = node->space->id; @@ -238,10 +238,8 @@ xb_fil_cur_open( /* Allocate read buffer */ cursor->buf_size = XB_FIL_CUR_PAGES * cursor->page_size; - cursor->orig_buf = static_cast<byte *> - (malloc(cursor->buf_size + srv_page_size)); - cursor->buf = static_cast<byte *> - (ut_align(cursor->orig_buf, srv_page_size)); + cursor->buf = static_cast<byte*>(aligned_malloc(cursor->buf_size, + srv_page_size)); cursor->buf_read = 0; cursor->buf_npages = 0; @@ -494,7 +492,8 @@ xb_fil_cur_close( cursor->read_filter->deinit(&cursor->read_filter_ctxt); } - free(cursor->orig_buf); + aligned_free(cursor->buf); + cursor->buf = NULL; if (cursor->node != NULL) { xb_fil_node_close_file(cursor->node); diff --git a/extra/mariabackup/fil_cur.h b/extra/mariabackup/fil_cur.h index b789efde05f..70e4888ba63 100644 --- a/extra/mariabackup/fil_cur.h +++ b/extra/mariabackup/fil_cur.h @@ -44,8 +44,7 @@ struct xb_fil_cur_t { xb_read_filt_t* read_filter; /*!< read filter */ xb_read_filt_ctxt_t read_filter_ctxt; /*!< read filter context */ - byte* orig_buf; /*!< read buffer */ - byte* buf; /*!< aligned pointer for orig_buf */ + byte* buf; /*!< read buffer */ size_t buf_size; /*!< buffer size in bytes */ size_t buf_read; /*!< number of read bytes in buffer after the last cursor read */ diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index 03a82bfc58b..c53c9037bda 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -3269,8 +3269,6 @@ static dberr_t xb_assign_undo_space_start() { pfs_os_file_t file; - byte* buf; - byte* page; bool ret; dberr_t error = DB_SUCCESS; ulint space; @@ -3289,8 +3287,8 @@ static dberr_t xb_assign_undo_space_start() return DB_ERROR; } - buf = static_cast<byte*>(ut_malloc_nokey(2U << srv_page_size_shift)); - page = static_cast<byte*>(ut_align(buf, srv_page_size)); + byte* page = static_cast<byte*> + (aligned_malloc(srv_page_size, srv_page_size)); if (os_file_read(IORequestRead, file, page, 0, srv_page_size) != DB_SUCCESS) { @@ -3337,7 +3335,7 @@ retry: srv_undo_space_id_start = space; func_exit: - ut_free(buf); + aligned_free(page); ret = os_file_close(file); ut_a(ret); @@ -4552,8 +4550,6 @@ xb_space_create_file( pfs_os_file_t* file) /*!<out: file handle */ { bool ret; - byte* buf; - byte* page; *file = os_file_create_simple_no_error_handling( 0, path, OS_FILE_CREATE, OS_FILE_READ_WRITE, false, &ret); @@ -4572,9 +4568,9 @@ xb_space_create_file( return ret; } - buf = static_cast<byte *>(malloc(3U << srv_page_size_shift)); /* Align the memory for file i/o if we might have O_DIRECT set */ - page = static_cast<byte *>(ut_align(buf, srv_page_size)); + byte* page = static_cast<byte*>(aligned_malloc(2 * srv_page_size, + srv_page_size)); memset(page, '\0', srv_page_size); @@ -4608,7 +4604,7 @@ xb_space_create_file( page_zip.data, 0, zip_size); } - free(buf); + aligned_free(page); if (ret != DB_SUCCESS) { msg("mariabackup: could not write the first page to %s", @@ -4821,8 +4817,7 @@ xtrabackup_apply_delta( xb_delta_info_t info(srv_page_size, 0, SRV_TMP_SPACE_ID); ulint page_size; ulint page_size_shift; - byte* incremental_buffer_base = NULL; - byte* incremental_buffer; + byte* incremental_buffer = NULL; size_t offset; @@ -4890,11 +4885,8 @@ xtrabackup_apply_delta( posix_fadvise(dst_file, 0, 0, POSIX_FADV_DONTNEED); /* allocate buffer for incremental backup (4096 pages) */ - incremental_buffer_base = static_cast<byte *> - (malloc((page_size / 4 + 1) * page_size)); incremental_buffer = static_cast<byte *> - (ut_align(incremental_buffer_base, - page_size)); + (aligned_malloc(page_size / 4 * page_size, page_size)); msg("Applying %s to %s...", src_path, dst_path); @@ -5003,7 +4995,7 @@ xtrabackup_apply_delta( incremental_buffers++; } - free(incremental_buffer_base); + aligned_free(incremental_buffer); if (src_file != OS_FILE_CLOSED) { os_file_close(src_file); os_file_delete(0,src_path); @@ -5013,7 +5005,7 @@ xtrabackup_apply_delta( return TRUE; error: - free(incremental_buffer_base); + aligned_free(incremental_buffer); if (src_file != OS_FILE_CLOSED) os_file_close(src_file); if (dst_file != OS_FILE_CLOSED) diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index 6a2bc34c767..7f98be9e729 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -1601,8 +1601,11 @@ buf_chunk_init( opt_large_page_size is smaller than srv_page_size, we may allocate one fewer block than requested. When it is bigger, we may allocate more blocks than requested. */ + static_assert(sizeof(byte*) == sizeof(ulint), "pointer size"); - frame = (byte*) ut_align(chunk->mem, srv_page_size); + frame = reinterpret_cast<byte*>((reinterpret_cast<ulint>(chunk->mem) + + srv_page_size - 1) + & ~(srv_page_size - 1)); chunk->size = (chunk->mem_pfx.m_size >> srv_page_size_shift) - (frame != chunk->mem); diff --git a/storage/innobase/buf/buf0dblwr.cc b/storage/innobase/buf/buf0dblwr.cc index 72f82a88f49..460874e086e 100644 --- a/storage/innobase/buf/buf0dblwr.cc +++ b/storage/innobase/buf/buf0dblwr.cc @@ -126,12 +126,9 @@ static void buf_dblwr_init(const byte *doublewrite) buf_dblwr->in_use = static_cast<bool*>( ut_zalloc_nokey(buf_size * sizeof(bool))); - buf_dblwr->write_buf_unaligned = static_cast<byte*>( - ut_malloc_nokey((1 + buf_size) << srv_page_size_shift)); - buf_dblwr->write_buf = static_cast<byte*>( - ut_align(buf_dblwr->write_buf_unaligned, - srv_page_size)); + aligned_malloc(buf_size << srv_page_size_shift, + srv_page_size)); buf_dblwr->buf_block_arr = static_cast<buf_page_t**>( ut_zalloc_nokey(buf_size * sizeof(void*))); @@ -355,23 +352,18 @@ buf_dblwr_init_or_load_pages( ulint space_id; byte* read_buf; byte* doublewrite; - byte* unaligned_read_buf; ibool reset_space_ids = FALSE; recv_dblwr_t& recv_dblwr = recv_sys.dblwr; /* We do the file i/o past the buffer pool */ - - unaligned_read_buf = static_cast<byte*>( - ut_malloc_nokey(3U << srv_page_size_shift)); - read_buf = static_cast<byte*>( - ut_align(unaligned_read_buf, srv_page_size)); + aligned_malloc(2 * srv_page_size, srv_page_size)); /* Read the trx sys header to check if we are using the doublewrite buffer */ dberr_t err; - IORequest read_request(IORequest::READ); + IORequest read_request(IORequest::READ); err = os_file_read( read_request, @@ -382,9 +374,8 @@ buf_dblwr_init_or_load_pages( ib::error() << "Failed to read the system tablespace header page"; - - ut_free(unaligned_read_buf); - +func_exit: + aligned_free(read_buf); return(err); } @@ -403,8 +394,8 @@ buf_dblwr_init_or_load_pages( buf = buf_dblwr->write_buf; } else { - ut_free(unaligned_read_buf); - return(DB_SUCCESS); + err = DB_SUCCESS; + goto func_exit; } if (mach_read_from_4(doublewrite + TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED) @@ -432,10 +423,7 @@ buf_dblwr_init_or_load_pages( ib::error() << "Failed to read the first double write buffer " "extent"; - - ut_free(unaligned_read_buf); - - return(err); + goto func_exit; } err = os_file_read( @@ -450,10 +438,7 @@ buf_dblwr_init_or_load_pages( ib::error() << "Failed to read the second double write buffer " "extent"; - - ut_free(unaligned_read_buf); - - return(err); + goto func_exit; } /* Check if any of these pages is half-written in data files, in the @@ -480,10 +465,8 @@ buf_dblwr_init_or_load_pages( + i - TRX_SYS_DOUBLEWRITE_BLOCK_SIZE; } - IORequest write_request(IORequest::WRITE); - err = os_file_write( - write_request, path, file, page, + IORequestWrite, path, file, page, source_page_no << srv_page_size_shift, srv_page_size); if (err != DB_SUCCESS) { @@ -491,10 +474,7 @@ buf_dblwr_init_or_load_pages( ib::error() << "Failed to write to the double write" " buffer"; - - ut_free(unaligned_read_buf); - - return(err); + goto func_exit; } } else if (mach_read_from_8(page + FIL_PAGE_LSN)) { /* Each valid page header must contain @@ -509,9 +489,8 @@ buf_dblwr_init_or_load_pages( os_file_flush(file); } - ut_free(unaligned_read_buf); - - return(DB_SUCCESS); + err = DB_SUCCESS; + goto func_exit; } /** Process and remove the double write buffer pages for all tablespaces. */ @@ -520,18 +499,14 @@ buf_dblwr_process() { ulint page_no_dblwr = 0; byte* read_buf; - byte* unaligned_read_buf; recv_dblwr_t& recv_dblwr = recv_sys.dblwr; if (!buf_dblwr) { return; } - unaligned_read_buf = static_cast<byte*>( - ut_malloc_nokey(3U << srv_page_size_shift)); - read_buf = static_cast<byte*>( - ut_align(unaligned_read_buf, srv_page_size)); + aligned_malloc(2 * srv_page_size, srv_page_size)); byte* const buf = read_buf + srv_page_size; for (recv_dblwr_t::list::iterator i = recv_dblwr.pages.begin(); @@ -687,7 +662,7 @@ bad: recv_dblwr.pages.clear(); fil_flush_file_spaces(FIL_TYPE_TABLESPACE); - ut_free(unaligned_read_buf); + aligned_free(read_buf); } /****************************************************************//** @@ -702,15 +677,9 @@ buf_dblwr_free() os_event_destroy(buf_dblwr->b_event); os_event_destroy(buf_dblwr->s_event); - ut_free(buf_dblwr->write_buf_unaligned); - buf_dblwr->write_buf_unaligned = NULL; - + aligned_free(buf_dblwr->write_buf); ut_free(buf_dblwr->buf_block_arr); - buf_dblwr->buf_block_arr = NULL; - ut_free(buf_dblwr->in_use); - buf_dblwr->in_use = NULL; - mutex_free(&buf_dblwr->mutex); ut_free(buf_dblwr); buf_dblwr = NULL; diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index c24c3025823..9565435b498 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -1837,12 +1837,10 @@ dberr_t fil_write_flushed_lsn( lsn_t lsn) { - byte* buf1; byte* buf; dberr_t err = DB_TABLESPACE_NOT_FOUND; - buf1 = static_cast<byte*>(ut_malloc_nokey(2U << srv_page_size_shift)); - buf = static_cast<byte*>(ut_align(buf1, srv_page_size)); + buf = static_cast<byte*>(aligned_malloc(srv_page_size, srv_page_size)); const page_id_t page_id(TRX_SYS_SPACE, 0); @@ -1862,7 +1860,7 @@ fil_write_flushed_lsn( fil_flush_file_spaces(FIL_TYPE_TABLESPACE); } - ut_free(buf1); + aligned_free(buf); return(err); } @@ -2919,7 +2917,6 @@ fil_ibd_create( dberr_t* err) { pfs_os_file_t file; - byte* buf2; byte* page; bool success; bool has_data_dir = FSP_FLAGS_HAS_DATA_DIR(flags) != 0; @@ -2998,9 +2995,9 @@ err_exit: with zeros from the call of os_file_set_size(), until a buffer pool flush would write to it. */ - buf2 = static_cast<byte*>(ut_malloc_nokey(3U << srv_page_size_shift)); /* Align the memory for file i/o if we might have O_DIRECT set */ - page = static_cast<byte*>(ut_align(buf2, srv_page_size)); + page = static_cast<byte*>(aligned_malloc(2 * srv_page_size, + srv_page_size)); memset(page, '\0', srv_page_size); @@ -3048,7 +3045,7 @@ err_exit: IORequestWrite, path, file, page, 0, srv_page_size); } - ut_free(buf2); + aligned_free(page); if (*err != DB_SUCCESS) { ib::error() diff --git a/storage/innobase/fsp/fsp0file.cc b/storage/innobase/fsp/fsp0file.cc index a005ae5dff4..79465906c34 100644 --- a/storage/innobase/fsp/fsp0file.cc +++ b/storage/innobase/fsp/fsp0file.cc @@ -291,13 +291,10 @@ Datafile::read_first_page(bool read_only_mode) } } - m_first_page_buf = static_cast<byte*>( - ut_malloc_nokey(2 * UNIV_PAGE_SIZE_MAX)); - /* Align the memory for a possible read from a raw device */ m_first_page = static_cast<byte*>( - ut_align(m_first_page_buf, srv_page_size)); + aligned_malloc(UNIV_PAGE_SIZE_MAX, srv_page_size)); IORequest request; dberr_t err = DB_ERROR; @@ -379,14 +376,10 @@ Datafile::read_first_page(bool read_only_mode) } /** Free the first page from memory when it is no longer needed. */ -void -Datafile::free_first_page() +void Datafile::free_first_page() { - if (m_first_page_buf) { - ut_free(m_first_page_buf); - m_first_page_buf = NULL; - m_first_page = NULL; - } + aligned_free(m_first_page); + m_first_page= nullptr; } /** Validates the datafile and checks that it conforms with the expected @@ -514,7 +507,6 @@ Datafile::validate_first_page(lsn_t* flush_lsn) error_txt = "Cannot read first page"; } else { - ut_ad(m_first_page_buf); ut_ad(m_first_page); if (flush_lsn != NULL) { @@ -663,11 +655,8 @@ Datafile::find_space_id() << "Page size:" << page_size << ". Pages to analyze:" << page_count; - byte* buf = static_cast<byte*>( - ut_malloc_nokey(2 * UNIV_PAGE_SIZE_MAX)); - byte* page = static_cast<byte*>( - ut_align(buf, UNIV_SECTOR_SIZE)); + aligned_malloc(page_size, page_size)); ulint fsp_flags; /* provide dummy value if the first os_file_read() fails */ @@ -684,19 +673,11 @@ Datafile::find_space_id() } for (ulint j = 0; j < page_count; ++j) { - - dberr_t err; - ulint n_bytes = j * page_size; - IORequest request(IORequest::READ); - - err = os_file_read( - request, m_handle, page, n_bytes, page_size); - - if (err != DB_SUCCESS) { - + if (dberr_t err = os_file_read( + IORequestRead, m_handle, page, + j * page_size, page_size)) { ib::info() << "READ FAIL: page_no:" << j; - continue; } @@ -742,7 +723,7 @@ Datafile::find_space_id() } } - ut_free(buf); + aligned_free(page); ib::info() << "Page size: " << page_size diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 3253b864786..9ed16993ea5 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -687,7 +687,6 @@ inline uint buf_page_full_crc32_size(const byte* buf, bool* comp, bool* cr) return page_size; } -#ifndef UNIV_INNOCHECKSUM # ifdef UNIV_LINUX # include <stdlib.h> # endif @@ -716,6 +715,7 @@ inline void aligned_free(void *ptr) #endif } +#ifndef UNIV_INNOCHECKSUM /**********************************************************************//** Gets the hash value of a block. This can be used in searches in the lock hash table. diff --git a/storage/innobase/include/buf0dblwr.h b/storage/innobase/include/buf0dblwr.h index 68662ac3b89..17fa84a85cc 100644 --- a/storage/innobase/include/buf0dblwr.h +++ b/storage/innobase/include/buf0dblwr.h @@ -150,8 +150,6 @@ struct buf_dblwr_t{ doublewrite buffer, aligned to an address divisible by srv_page_size (which is required by Windows aio) */ - byte* write_buf_unaligned;/*!< pointer to write_buf, - but unaligned */ buf_page_t** buf_block_arr;/*!< array to store pointers to the buffer blocks which have been cached to write_buf */ diff --git a/storage/innobase/include/fsp0file.h b/storage/innobase/include/fsp0file.h index 15485769429..759970bb46d 100644 --- a/storage/innobase/include/fsp0file.h +++ b/storage/innobase/include/fsp0file.h @@ -61,7 +61,6 @@ public: m_flags(), m_exists(), m_is_valid(), - m_first_page_buf(), m_first_page(), m_last_os_error(), m_file_info() @@ -83,7 +82,6 @@ public: m_flags(flags), m_exists(), m_is_valid(), - m_first_page_buf(), m_first_page(), m_last_os_error(), m_file_info() @@ -103,7 +101,6 @@ public: m_flags(file.m_flags), m_exists(file.m_exists), m_is_valid(file.m_is_valid), - m_first_page_buf(), m_first_page(), m_last_os_error(), m_file_info() @@ -162,7 +159,6 @@ public: /* Do not make a copy of the first page, it should be reread if needed */ - m_first_page_buf = NULL; m_first_page = NULL; return(*this); @@ -459,10 +455,7 @@ private: /* true if the tablespace is valid */ bool m_is_valid; - /** Buffer to hold first page */ - byte* m_first_page_buf; - - /** Pointer to the first page held in the buffer above */ + /** Aligned buffer to hold first page */ byte* m_first_page; protected: diff --git a/storage/innobase/include/row0ftsort.h b/storage/innobase/include/row0ftsort.h index a00d4bbba6a..0da8cb32353 100644 --- a/storage/innobase/include/row0ftsort.h +++ b/storage/innobase/include/row0ftsort.h @@ -80,12 +80,8 @@ struct fts_psort_t { /*!< sort file */ row_merge_block_t* merge_block[FTS_NUM_AUX_INDEX]; /*!< buffer to write to file */ - row_merge_block_t* block_alloc[FTS_NUM_AUX_INDEX]; - /*!< buffer to allocated */ row_merge_block_t* crypt_block[FTS_NUM_AUX_INDEX]; /*!< buffer to crypt data */ - row_merge_block_t* crypt_alloc[FTS_NUM_AUX_INDEX]; - /*!< buffer to allocated */ ulint child_status; /*!< child task status */ ulint state; /*!< parent state */ fts_doc_list_t fts_doc_list; /*!< doc list to process */ diff --git a/storage/innobase/include/univ.i b/storage/innobase/include/univ.i index d9652784218..ce87617fa8d 100644 --- a/storage/innobase/include/univ.i +++ b/storage/innobase/include/univ.i @@ -633,8 +633,6 @@ typedef void* os_thread_ret_t; extern ulong srv_page_size_shift; extern ulong srv_page_size; -static const size_t UNIV_SECTOR_SIZE = 512; - /* Dimension of spatial object we support so far. It has its root in myisam/sp_defs.h. We only support 2 dimension data */ #define SPDIMS 2 diff --git a/storage/innobase/include/ut0byte.h b/storage/innobase/include/ut0byte.h index 4ce931e0189..d79f6ab414c 100644 --- a/storage/innobase/include/ut0byte.h +++ b/storage/innobase/include/ut0byte.h @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -62,15 +63,6 @@ ut_uint64_align_up( ulint align_no); /*!< in: align by this number which must be a power of 2 */ /*********************************************************//** -The following function rounds up a pointer to the nearest aligned address. -@return aligned pointer */ -UNIV_INLINE -void* -ut_align( -/*=====*/ - const void* ptr, /*!< in: pointer */ - ulint align_no); /*!< in: align by this number */ -/*********************************************************//** The following function rounds down a pointer to the nearest aligned address. @return aligned pointer */ diff --git a/storage/innobase/include/ut0byte.ic b/storage/innobase/include/ut0byte.ic index e6e60f07886..699111b343b 100644 --- a/storage/innobase/include/ut0byte.ic +++ b/storage/innobase/include/ut0byte.ic @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 1994, 2013, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2019, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -75,25 +76,6 @@ ut_uint64_align_up( } /*********************************************************//** -The following function rounds up a pointer to the nearest aligned address. -@return aligned pointer */ -UNIV_INLINE -void* -ut_align( -/*=====*/ - const void* ptr, /*!< in: pointer */ - ulint align_no) /*!< in: align by this number */ -{ - ut_ad(align_no > 0); - ut_ad(((align_no - 1) & align_no) == 0); - ut_ad(ptr); - - ut_ad(sizeof(void*) == sizeof(ulint)); - - return((void*)((((ulint) ptr) + align_no - 1) & ~(align_no - 1))); -} - -/*********************************************************//** The following function rounds down a pointer to the nearest aligned address. @return aligned pointer */ diff --git a/storage/innobase/log/log0log.cc b/storage/innobase/log/log0log.cc index 958ea15f8ef..8078c608644 100644 --- a/storage/innobase/log/log0log.cc +++ b/storage/innobase/log/log0log.cc @@ -822,14 +822,14 @@ log_buffer_switch() if (log_sys.first_in_use) { log_sys.first_in_use = false; - ut_ad(log_sys.buf == ut_align(log_sys.buf, - OS_FILE_LOG_BLOCK_SIZE)); + ut_ad(log_sys.buf == ut_align_down(log_sys.buf, + OS_FILE_LOG_BLOCK_SIZE)); log_sys.buf += srv_log_buffer_size; } else { log_sys.first_in_use = true; log_sys.buf -= srv_log_buffer_size; - ut_ad(log_sys.buf == ut_align(log_sys.buf, - OS_FILE_LOG_BLOCK_SIZE)); + ut_ad(log_sys.buf == ut_align_down(log_sys.buf, + OS_FILE_LOG_BLOCK_SIZE)); } /* Copy the last block to new buf */ diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index 4b43b1f50b0..2f5dd12b407 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -3627,12 +3627,8 @@ fallback: << srv_page_size_shift; /* Align the buffer for possible raw i/o */ - byte* buf2; - - buf2 = static_cast<byte*>(ut_malloc_nokey(buf_size + srv_page_size)); - - byte* buf = static_cast<byte*>(ut_align(buf2, srv_page_size)); - + byte* buf = static_cast<byte*>(aligned_malloc(buf_size, + srv_page_size)); /* Write buffer full of zeros */ memset(buf, 0, buf_size); @@ -3661,7 +3657,7 @@ fallback: current_size += n_bytes; } - ut_free(buf2); + aligned_free(buf); return(current_size >= size && os_file_flush(file)); } @@ -3959,13 +3955,13 @@ static bool is_linux_native_aio_supported() memset(&io_event, 0x0, sizeof(io_event)); - byte* buf = static_cast<byte*>(ut_malloc_nokey(srv_page_size * 2)); - byte* ptr = static_cast<byte*>(ut_align(buf, srv_page_size)); + byte* ptr = static_cast<byte*>(aligned_malloc(srv_page_size, + srv_page_size)); struct iocb iocb; /* Suppress valgrind warning. */ - memset(buf, 0x00, srv_page_size * 2); + memset(ptr, 0, srv_page_size); memset(&iocb, 0x0, sizeof(iocb)); struct iocb* p_iocb = &iocb; @@ -3988,7 +3984,7 @@ static bool is_linux_native_aio_supported() err = io_getevents(io_ctx, 1, 1, &io_event, NULL); } - ut_free(buf); + aligned_free(ptr); my_close(fd, MYF(MY_WME)); switch (err) { diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc index 7eaa6063007..f862cf8dce0 100644 --- a/storage/innobase/page/page0zip.cc +++ b/storage/innobase/page/page0zip.cc @@ -3285,8 +3285,6 @@ page_zip_validate_low( TRUE=ignore the MIN_REC_FLAG */ { page_zip_des_t temp_page_zip; - byte* temp_page_buf; - page_t* temp_page; ibool valid; if (memcmp(page_zip->data + FIL_PAGE_PREV, page + FIL_PAGE_PREV, @@ -3309,9 +3307,8 @@ page_zip_validate_low( /* page_zip_decompress() expects the uncompressed page to be srv_page_size aligned. */ - temp_page_buf = static_cast<byte*>( - ut_malloc_nokey(2 << srv_page_size_shift)); - temp_page = static_cast<byte*>(ut_align(temp_page_buf, srv_page_size)); + page_t* temp_page = static_cast<byte*>(aligned_malloc(srv_page_size, + srv_page_size)); UNIV_MEM_ASSERT_RW(page, srv_page_size); UNIV_MEM_ASSERT_RW(page_zip->data, page_zip_get_size(page_zip)); @@ -3467,7 +3464,7 @@ func_exit: page_zip_hexdump(page, srv_page_size); page_zip_hexdump(temp_page, srv_page_size); } - ut_free(temp_page_buf); + aligned_free(temp_page); return(valid); } diff --git a/storage/innobase/row/row0ftsort.cc b/storage/innobase/row/row0ftsort.cc index ca3de3e2af0..851be1e4096 100644 --- a/storage/innobase/row/row0ftsort.cc +++ b/storage/innobase/row/row0ftsort.cc @@ -252,14 +252,9 @@ row_fts_psort_info_init( } /* Need to align memory for O_DIRECT write */ - psort_info[j].block_alloc[i] = - static_cast<row_merge_block_t*>(ut_malloc_nokey( - block_size + 1024)); - psort_info[j].merge_block[i] = static_cast<row_merge_block_t*>( - ut_align( - psort_info[j].block_alloc[i], 1024)); + aligned_malloc(block_size, 1024)); if (!psort_info[j].merge_block[i]) { ret = FALSE; @@ -269,23 +264,17 @@ row_fts_psort_info_init( /* If tablespace is encrypted, allocate additional buffer for encryption/decryption. */ if (encrypted) { - /* Need to align memory for O_DIRECT write */ - psort_info[j].crypt_alloc[i] = - static_cast<row_merge_block_t*>(ut_malloc_nokey( - block_size + 1024)); - psort_info[j].crypt_block[i] = static_cast<row_merge_block_t*>( - ut_align( - psort_info[j].crypt_alloc[i], 1024)); + aligned_malloc(block_size, + 1024)); if (!psort_info[j].crypt_block[i]) { ret = FALSE; goto func_exit; } } else { - psort_info[j].crypt_alloc[i] = NULL; psort_info[j].crypt_block[i] = NULL; } } @@ -337,12 +326,9 @@ row_fts_psort_info_destroy( psort_info[j].merge_file[i]); } - ut_free(psort_info[j].block_alloc[i]); + aligned_free(psort_info[j].merge_block[i]); ut_free(psort_info[j].merge_file[i]); - - if (psort_info[j].crypt_alloc[i]) { - ut_free(psort_info[j].crypt_alloc[i]); - } + aligned_free(psort_info[j].crypt_block[i]); } mutex_free(&psort_info[j].mutex); diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc index beca1cffc10..0e352996690 100644 --- a/storage/innobase/row/row0import.cc +++ b/storage/innobase/row/row0import.cc @@ -3656,11 +3656,10 @@ fil_tablespace_iterate( /* Allocate a page to read in the tablespace header, so that we can determine the page size and zip_size (if it is compressed). - We allocate an extra page in case it is a compressed table. One - page is to ensure alignement. */ + We allocate an extra page in case it is a compressed table. */ - void* page_ptr = ut_malloc_nokey(3U << srv_page_size_shift); - byte* page = static_cast<byte*>(ut_align(page_ptr, srv_page_size)); + byte* page = static_cast<byte*>(aligned_malloc(2 * srv_page_size, + srv_page_size)); buf_block_t* block = reinterpret_cast<buf_block_t*> (ut_zalloc_nokey(sizeof *block)); @@ -3712,20 +3711,16 @@ fil_tablespace_iterate( iter.n_io_buffers = n_io_buffers; /* Add an extra page for compressed page scratch area. */ - void* io_buffer = ut_malloc_nokey( - (2 + iter.n_io_buffers) << srv_page_size_shift); - iter.io_buffer = static_cast<byte*>( - ut_align(io_buffer, srv_page_size)); + aligned_malloc((1 + iter.n_io_buffers) + << srv_page_size_shift, srv_page_size)); - void* crypt_io_buffer = NULL; - if (iter.crypt_data) { - crypt_io_buffer = ut_malloc_nokey( - (2 + iter.n_io_buffers) - << srv_page_size_shift); - iter.crypt_io_buffer = static_cast<byte*>( - ut_align(crypt_io_buffer, srv_page_size)); - } + iter.crypt_io_buffer = iter.crypt_data + ? static_cast<byte*>( + aligned_malloc((1 + iter.n_io_buffers) + << srv_page_size_shift, + srv_page_size)) + : NULL; if (block->page.zip.ssize) { ut_ad(iter.n_io_buffers == 1); @@ -3739,8 +3734,8 @@ fil_tablespace_iterate( fil_space_destroy_crypt_data(&iter.crypt_data); } - ut_free(crypt_io_buffer); - ut_free(io_buffer); + aligned_free(iter.crypt_io_buffer); + aligned_free(iter.io_buffer); } if (err == DB_SUCCESS) { @@ -3756,7 +3751,7 @@ fil_tablespace_iterate( os_file_close(file); - ut_free(page_ptr); + aligned_free(page); ut_free(filepath); ut_free(block); |