@@ -49,9 +49,8 @@ Created 10/21/1995 Heikki Tuuri
4949#include " buf0buf.h"
5050#include " srv0mon.h"
5151#include " srv0srv.h"
52- #ifdef HAVE_POSIX_FALLOCATE
52+ #ifdef HAVE_LINUX_UNISTD_H
5353#include " unistd.h"
54- #include " fcntl.h"
5554#endif
5655#ifndef UNIV_HOTBACKUP
5756# include " os0sync.h"
@@ -84,14 +83,10 @@ Created 10/21/1995 Heikki Tuuri
8483#include < linux/falloc.h>
8584#endif
8685
87- #if defined(HAVE_FALLOCATE)
88- #ifndef FALLOC_FL_KEEP_SIZE
89- #define FALLOC_FL_KEEP_SIZE 0x01
90- #endif
91- #ifndef FALLOC_FL_PUNCH_HOLE
92- #define FALLOC_FL_PUNCH_HOLE 0x02
93- #endif
94- #endif
86+ #ifdef HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE
87+ # include < fcntl.h>
88+ # include < linux/falloc.h>
89+ #endif /* HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE */
9590
9691#ifdef HAVE_LZO
9792#include " lzo/lzo1x.h"
@@ -209,6 +204,9 @@ struct os_aio_slot_t{
209204write */
210205byte* buf;/* !< buffer used in i/o */
211206ulint type;/* !< OS_FILE_READ or OS_FILE_WRITE */
207+ ulint is_log;/* !< 1 if OS_FILE_LOG or 0 */
208+ ulint page_size; /* !< UNIV_PAGE_SIZE or zip_size */
209+
212210os_offset_t offset;/* !< file offset in bytes */
213211os_file_t file;/* !< file where to read or write */
214212const char * name;/* !< file name or path */
@@ -4474,6 +4472,7 @@ os_aio_slot_t*
44744472os_aio_array_reserve_slot (
44754473/* ======================*/
44764474ulint type,/* !< in: OS_FILE_READ or OS_FILE_WRITE */
4475+ ulint is_log,/* !< in: 1 is OS_FILE_LOG or 0 */
44774476os_aio_array_t * array,/* !< in: aio array */
44784477fil_node_t * message1,/* !< in: message to be passed along with
44794478the aio operation */
@@ -4486,6 +4485,7 @@ os_aio_array_reserve_slot(
44864485to write */
44874486os_offset_t offset,/* !< in: file offset */
44884487ulint len,/* !< in: length of the block to read or write */
4488+ ulint page_size, /* !< in: page size in bytes */
44894489ulint* write_size)/* !< in/out: Actual write size initialized
44904490 after fist successfull trim
44914491 operation for this page and if
@@ -4580,6 +4580,8 @@ os_aio_array_reserve_slot(
45804580slot->offset = offset;
45814581slot->io_already_done = FALSE ;
45824582slot->write_size = write_size;
4583+ slot->is_log = is_log;
4584+ slot->page_size = page_size;
45834585
45844586if (message1) {
45854587slot->file_block_size = fil_node_get_block_size (message1);
@@ -4836,6 +4838,7 @@ ibool
48364838os_aio_func (
48374839/* ========*/
48384840ulint type,/* !< in: OS_FILE_READ or OS_FILE_WRITE */
4841+ ulint is_log,/* !< in: 1 is OS_FILE_LOG or 0 */
48394842ulint mode,/* !< in: OS_AIO_NORMAL, ..., possibly ORed
48404843to OS_AIO_SIMULATED_WAKE_LATER: the
48414844last flag advises this function not to wake
@@ -4856,6 +4859,7 @@ os_aio_func(
48564859to write */
48574860os_offset_t offset,/* !< in: file offset where to read or write */
48584861ulint n,/* !< in: number of bytes to read or write */
4862+ ulint page_size, /* !< in: page size in bytes */
48594863fil_node_t * message1,/* !< in: message for the aio handler
48604864(can be used to identify a completed
48614865aio operation); ignored if mode is
@@ -4982,8 +4986,8 @@ os_aio_func(
49824986array = NULL ; /* Eliminate compiler warning */
49834987}
49844988
4985- slot = os_aio_array_reserve_slot (type, array, message1, message2, file,
4986- name, buf, offset, n, write_size);
4989+ slot = os_aio_array_reserve_slot (type, is_log, array, message1, message2, file,
4990+ name, buf, offset, n, page_size , write_size);
49874991
49884992if (type == OS_FILE_READ) {
49894993if (srv_use_native_aio) {
@@ -5251,7 +5255,10 @@ os_aio_windows_handle(
52515255ret_val = ret && len == slot->len ;
52525256}
52535257
5254- if (slot->type == OS_FILE_WRITE && srv_use_trim && os_fallocate_failed == FALSE ) {
5258+ if (slot->type == OS_FILE_WRITE &&
5259+ !slot->is_log &&
5260+ srv_use_trim &&
5261+ os_fallocate_failed == FALSE ) {
52555262// Deallocate unused blocks from file system
52565263os_file_trim (slot);
52575264}
@@ -5345,7 +5352,10 @@ os_aio_linux_collect(
53455352/* We have not overstepped to next segment. */
53465353ut_a (slot->pos < end_pos);
53475354
5348- if (slot->type == OS_FILE_WRITE && srv_use_trim && os_fallocate_failed == FALSE ) {
5355+ if (slot->type == OS_FILE_WRITE &&
5356+ !slot->is_log &&
5357+ srv_use_trim &&
5358+ os_fallocate_failed == FALSE ) {
53495359// Deallocate unused blocks from file system
53505360os_file_trim (slot);
53515361}
@@ -6220,19 +6230,13 @@ os_file_trim(
62206230{
62216231
62226232size_t len = slot->len ;
6223- size_t trim_len = UNIV_PAGE_SIZE - len;
6233+ size_t trim_len = slot-> page_size - len;
62246234os_offset_t off = slot->offset + len;
62256235size_t bsize = slot->file_block_size ;
62266236
6227- // len here should be alligned to sector size
6228- ut_ad ((trim_len % bsize) == 0 );
6229- ut_ad ((len % bsize) == 0 );
6230- ut_ad (bsize != 0 );
6231- ut_ad ((off % bsize) == 0 );
6232-
62336237#ifdef UNIV_TRIM_DEBUG
62346238fprintf (stderr, " Note: TRIM: write_size %lu trim_len %lu len %lu off %lu bz %lu\n " ,
6235- *slot->write_size , trim_len, len, off, bsize);
6239+ slot-> write_size ? *slot->write_size : 0 , trim_len, len, off, bsize);
62366240#endif
62376241
62386242// Nothing to do if trim length is zero or if actual write
@@ -6247,22 +6251,19 @@ os_file_trim(
62476251 *slot->write_size > 0 &&
62486252 len >= *slot->write_size )) {
62496253
6250- # ifdef UNIV_PAGECOMPRESS_DEBUG
6251- fprintf (stderr, " Note: TRIM: write_size %lu trim_len %lu len %lu \n " ,
6252- *slot-> write_size , trim_len, len );
6253- # endif
6254+ if (slot-> write_size ) {
6255+ if (*slot-> write_size > 0 && len >= *slot-> write_size ) {
6256+ srv_stats. page_compressed_trim_op_saved . inc ( );
6257+ }
62546258
6255- if (*slot->write_size > 0 && len >= *slot->write_size ) {
6256- srv_stats.page_compressed_trim_op_saved .inc ();
6259+ *slot->write_size = len;
62576260}
62586261
6259- *slot->write_size = len;
6260-
62616262return (TRUE );
62626263}
62636264
62646265#ifdef __linux__
6265- #if defined(HAVE_FALLOCATE )
6266+ #if defined(HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE )
62666267int ret = fallocate (slot->file , FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, off, trim_len);
62676268
62686269if (ret) {
@@ -6300,7 +6301,7 @@ os_file_trim(
63006301*slot->write_size = 0 ;
63016302}
63026303
6303- #endif /* HAVE_FALLOCATE ... */
6304+ #endif /* HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE ... */
63046305
63056306#elif defined(_WIN32)
63066307FILE_LEVEL_TRIM flt;
0 commit comments