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 /extra | |
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.
Diffstat (limited to 'extra')
-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 |
5 files changed, 25 insertions, 47 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) |