@@ -49,9 +49,8 @@ Created 10/21/1995 Heikki Tuuri
49
49
#include " buf0buf.h"
50
50
#include " srv0mon.h"
51
51
#include " srv0srv.h"
52
- #ifdef HAVE_POSIX_FALLOCATE
52
+ #ifdef HAVE_LINUX_UNISTD_H
53
53
#include " unistd.h"
54
- #include " fcntl.h"
55
54
#endif
56
55
#ifndef UNIV_HOTBACKUP
57
56
# include " os0sync.h"
@@ -84,14 +83,10 @@ Created 10/21/1995 Heikki Tuuri
84
83
#include < linux/falloc.h>
85
84
#endif
86
85
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 */
95
90
96
91
#ifdef HAVE_LZO
97
92
#include " lzo/lzo1x.h"
@@ -209,6 +204,9 @@ struct os_aio_slot_t{
209
204
write */
210
205
byte* buf; /* !< buffer used in i/o */
211
206
ulint 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
+
212
210
os_offset_t offset; /* !< file offset in bytes */
213
211
os_file_t file; /* !< file where to read or write */
214
212
const char * name; /* !< file name or path */
@@ -4474,6 +4472,7 @@ os_aio_slot_t*
4474
4472
os_aio_array_reserve_slot (
4475
4473
/* ======================*/
4476
4474
ulint type, /* !< in: OS_FILE_READ or OS_FILE_WRITE */
4475
+ ulint is_log, /* !< in: 1 is OS_FILE_LOG or 0 */
4477
4476
os_aio_array_t * array, /* !< in: aio array */
4478
4477
fil_node_t * message1,/* !< in: message to be passed along with
4479
4478
the aio operation */
@@ -4486,6 +4485,7 @@ os_aio_array_reserve_slot(
4486
4485
to write */
4487
4486
os_offset_t offset, /* !< in: file offset */
4488
4487
ulint len, /* !< in: length of the block to read or write */
4488
+ ulint page_size, /* !< in: page size in bytes */
4489
4489
ulint* write_size)/* !< in/out: Actual write size initialized
4490
4490
after fist successfull trim
4491
4491
operation for this page and if
@@ -4580,6 +4580,8 @@ os_aio_array_reserve_slot(
4580
4580
slot->offset = offset;
4581
4581
slot->io_already_done = FALSE ;
4582
4582
slot->write_size = write_size;
4583
+ slot->is_log = is_log;
4584
+ slot->page_size = page_size;
4583
4585
4584
4586
if (message1) {
4585
4587
slot->file_block_size = fil_node_get_block_size (message1);
@@ -4836,6 +4838,7 @@ ibool
4836
4838
os_aio_func (
4837
4839
/* ========*/
4838
4840
ulint type, /* !< in: OS_FILE_READ or OS_FILE_WRITE */
4841
+ ulint is_log, /* !< in: 1 is OS_FILE_LOG or 0 */
4839
4842
ulint mode, /* !< in: OS_AIO_NORMAL, ..., possibly ORed
4840
4843
to OS_AIO_SIMULATED_WAKE_LATER: the
4841
4844
last flag advises this function not to wake
@@ -4856,6 +4859,7 @@ os_aio_func(
4856
4859
to write */
4857
4860
os_offset_t offset, /* !< in: file offset where to read or write */
4858
4861
ulint n, /* !< in: number of bytes to read or write */
4862
+ ulint page_size, /* !< in: page size in bytes */
4859
4863
fil_node_t * message1,/* !< in: message for the aio handler
4860
4864
(can be used to identify a completed
4861
4865
aio operation); ignored if mode is
@@ -4982,8 +4986,8 @@ os_aio_func(
4982
4986
array = NULL ; /* Eliminate compiler warning */
4983
4987
}
4984
4988
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);
4987
4991
4988
4992
if (type == OS_FILE_READ) {
4989
4993
if (srv_use_native_aio) {
@@ -5251,7 +5255,10 @@ os_aio_windows_handle(
5251
5255
ret_val = ret && len == slot->len ;
5252
5256
}
5253
5257
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 ) {
5255
5262
// Deallocate unused blocks from file system
5256
5263
os_file_trim (slot);
5257
5264
}
@@ -5345,7 +5352,10 @@ os_aio_linux_collect(
5345
5352
/* We have not overstepped to next segment. */
5346
5353
ut_a (slot->pos < end_pos);
5347
5354
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 ) {
5349
5359
// Deallocate unused blocks from file system
5350
5360
os_file_trim (slot);
5351
5361
}
@@ -6220,19 +6230,13 @@ os_file_trim(
6220
6230
{
6221
6231
6222
6232
size_t len = slot->len ;
6223
- size_t trim_len = UNIV_PAGE_SIZE - len;
6233
+ size_t trim_len = slot-> page_size - len;
6224
6234
os_offset_t off = slot->offset + len;
6225
6235
size_t bsize = slot->file_block_size ;
6226
6236
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
-
6233
6237
#ifdef UNIV_TRIM_DEBUG
6234
6238
fprintf (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);
6236
6240
#endif
6237
6241
6238
6242
// Nothing to do if trim length is zero or if actual write
@@ -6247,22 +6251,19 @@ os_file_trim(
6247
6251
*slot->write_size > 0 &&
6248
6252
len >= *slot->write_size )) {
6249
6253
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
+ }
6254
6258
6255
- if (*slot->write_size > 0 && len >= *slot->write_size ) {
6256
- srv_stats.page_compressed_trim_op_saved .inc ();
6259
+ *slot->write_size = len;
6257
6260
}
6258
6261
6259
- *slot->write_size = len;
6260
-
6261
6262
return (TRUE );
6262
6263
}
6263
6264
6264
6265
#ifdef __linux__
6265
- #if defined(HAVE_FALLOCATE )
6266
+ #if defined(HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE )
6266
6267
int ret = fallocate (slot->file , FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, off, trim_len);
6267
6268
6268
6269
if (ret) {
@@ -6300,7 +6301,7 @@ os_file_trim(
6300
6301
*slot->write_size = 0 ;
6301
6302
}
6302
6303
6303
- #endif /* HAVE_FALLOCATE ... */
6304
+ #endif /* HAVE_FALLOC_PUNCH_HOLE_AND_KEEP_SIZE ... */
6304
6305
6305
6306
#elif defined(_WIN32)
6306
6307
FILE_LEVEL_TRIM flt;
0 commit comments