37
38
#include "srv0start.h"
38
39
#include "srv0srv.h"
40
/* The size in blocks of the area where the random read-ahead algorithm counts
41
/** The size in blocks of the area where the random read-ahead algorithm counts
41
42
the accessed pages when deciding whether to read-ahead */
42
43
#define BUF_READ_AHEAD_RANDOM_AREA BUF_READ_AHEAD_AREA
44
/* There must be at least this many pages in buf_pool in the area to start
45
/** There must be at least this many pages in buf_pool in the area to start
45
46
a random read-ahead */
46
#define BUF_READ_AHEAD_RANDOM_THRESHOLD (5 + buf_read_ahead_random_area / 8)
47
#define BUF_READ_AHEAD_RANDOM_THRESHOLD (1 + BUF_READ_AHEAD_RANDOM_AREA / 2)
48
/* The linear read-ahead area size */
49
/** The linear read-ahead area size */
49
50
#define BUF_READ_AHEAD_LINEAR_AREA BUF_READ_AHEAD_AREA
51
/* The linear read-ahead threshold */
52
#define LINEAR_AREA_THRESHOLD_COEF 5 / 8
54
/* If there are buf_pool->curr_size per the number below pending reads, then
52
/** If there are buf_pool->curr_size per the number below pending reads, then
55
53
read-ahead is not done: this is to prevent flooding the buffer pool with
56
54
i/o-fixed buffer blocks */
57
55
#define BUF_READ_AHEAD_PEND_LIMIT 2
59
/************************************************************************
57
/********************************************************************//**
60
58
Low-level function which reads a page asynchronously from a file to the
61
59
buffer buf_pool if it is not already there, in which case does nothing.
62
60
Sets the io_fix flag and sets an exclusive lock on the buffer frame. The
63
flag is cleared and the x-lock released by an i/o-handler thread. */
61
flag is cleared and the x-lock released by an i/o-handler thread.
62
@return 1 if a read request was queued, 0 if the page already resided
63
in buf_pool, or if the page is in the doublewrite buffer blocks in
64
which case it is never read into the pool, or if the tablespace does
65
not exist or is being dropped */
68
/* out: 1 if a read request was queued, 0 if the page
69
already resided in buf_pool, or if the page is in
70
the doublewrite buffer blocks in which case it is never
71
read into the pool, or if the tablespace does not
72
exist or is being dropped */
73
ulint* err, /* out: DB_SUCCESS or DB_TABLESPACE_DELETED if we are
70
ulint* err, /*!< out: DB_SUCCESS or DB_TABLESPACE_DELETED if we are
74
71
trying to read from a non-existent tablespace, or a
75
72
tablespace which is just now being dropped */
76
ibool sync, /* in: TRUE if synchronous aio is desired */
77
ulint mode, /* in: BUF_READ_IBUF_PAGES_ONLY, ...,
73
ibool sync, /*!< in: TRUE if synchronous aio is desired */
74
ulint mode, /*!< in: BUF_READ_IBUF_PAGES_ONLY, ...,
78
75
ORed to OS_AIO_SIMULATED_WAKE_LATER (see below
79
76
at read-ahead functions) */
80
ulint space, /* in: space id */
81
ulint zip_size,/* in: compressed page size, or 0 */
82
ibool unzip, /* in: TRUE=request uncompressed page */
83
ib_int64_t tablespace_version, /* in: if the space memory object has
77
ulint space, /*!< in: space id */
78
ulint zip_size,/*!< in: compressed page size, or 0 */
79
ibool unzip, /*!< in: TRUE=request uncompressed page */
80
ib_int64_t tablespace_version, /*!< in: if the space memory object has
84
81
this timestamp different from what we are giving here,
85
82
treat the tablespace as dropped; this is a timestamp we
86
83
use to stop dangling page reads from a tablespace
87
84
which we have DISCARDed + IMPORTed back */
88
ulint offset) /* in: page number */
85
ulint offset) /*!< in: page number */
176
173
end up waiting for these latches! NOTE 2: the calling thread must want
177
174
access to the page given: this rule is set to prevent unintended read-aheads
178
175
performed by ibuf routines, a situation which could result in a deadlock if
179
the OS does not support asynchronous i/o. */
176
the OS does not support asynchronous i/o.
177
@return number of page read requests issued; NOTE that if we read ibuf
178
pages, it may happen that the page at the given page number does not
179
get read even if we return a positive value! */
182
182
buf_read_ahead_random(
183
183
/*==================*/
184
/* out: number of page read requests issued; NOTE
185
that if we read ibuf pages, it may happen that
186
the page at the given page number does not get
187
read even if we return a value > 0! */
188
ulint space, /* in: space id */
189
ulint zip_size,/* in: compressed page size in bytes, or 0 */
190
ulint offset) /* in: page number of a page which the current thread
184
ulint space, /*!< in: space id */
185
ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
186
ulint offset) /*!< in: page number of a page which the current thread
191
187
wants to access */
193
ib_int64_t tablespace_version;
194
ulint recent_blocks = 0;
196
ulint LRU_recent_limit;
201
ulint buf_read_ahead_random_area;
203
if (srv_startup_is_before_trx_rollback_phase) {
204
/* No read-ahead to avoid thread deadlocks */
208
if (ibuf_bitmap_page(zip_size, offset)
209
|| trx_sys_hdr_page(space, offset)) {
211
/* If it is an ibuf bitmap page or trx sys hdr, we do
212
no read-ahead, as that could break the ibuf page access
218
/* Remember the tablespace version before we ask te tablespace size
219
below: if DISCARD + IMPORT changes the actual .ibd file meanwhile, we
220
do not try to read outside the bounds of the tablespace! */
222
tablespace_version = fil_space_get_version(space);
224
buf_read_ahead_random_area = BUF_READ_AHEAD_RANDOM_AREA;
226
low = (offset / buf_read_ahead_random_area)
227
* buf_read_ahead_random_area;
228
high = (offset / buf_read_ahead_random_area + 1)
229
* buf_read_ahead_random_area;
230
if (high > fil_space_get_size(space)) {
232
high = fil_space_get_size(space);
235
/* Get the minimum LRU_position field value for an initial segment
236
of the LRU list, to determine which blocks have recently been added
237
to the start of the list. */
239
LRU_recent_limit = buf_LRU_get_recent_limit();
241
buf_pool_mutex_enter();
243
if (buf_pool->n_pend_reads
244
> buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {
245
buf_pool_mutex_exit();
250
/* Count how many blocks in the area have been recently accessed,
251
that is, reside near the start of the LRU list. */
253
for (i = low; i < high; i++) {
254
const buf_page_t* bpage = buf_page_hash_get(space, i);
257
&& buf_page_is_accessed(bpage)
258
&& (buf_page_get_LRU_position(bpage) > LRU_recent_limit)) {
262
if (recent_blocks >= BUF_READ_AHEAD_RANDOM_THRESHOLD) {
264
buf_pool_mutex_exit();
270
buf_pool_mutex_exit();
192
/* We have currently disabled random readahead */
275
/* Read all the suitable blocks within the area */
278
ibuf_mode = BUF_READ_IBUF_PAGES_ONLY;
280
ibuf_mode = BUF_READ_ANY_PAGE;
285
for (i = low; i < high; i++) {
286
/* It is only sensible to do read-ahead in the non-sync aio
287
mode: hence FALSE as the first parameter */
289
if (!ibuf_bitmap_page(zip_size, i)) {
290
count += buf_read_page_low(
292
ibuf_mode | OS_AIO_SIMULATED_WAKE_LATER,
293
space, zip_size, FALSE,
294
tablespace_version, i);
295
if (err == DB_TABLESPACE_DELETED) {
296
ut_print_timestamp(stderr);
298
" InnoDB: Warning: in random"
299
" readahead trying to access\n"
300
"InnoDB: tablespace %lu page %lu,\n"
301
"InnoDB: but the tablespace does not"
302
" exist or is just being dropped.\n",
303
(ulong) space, (ulong) i);
308
/* In simulated aio we wake the aio handler threads only after
309
queuing all aio requests, in native aio the following call does
312
os_aio_simulated_wake_handler_threads();
315
if (buf_debug_prints && (count > 0)) {
317
"Random read-ahead space %lu offset %lu pages %lu\n",
318
(ulong) space, (ulong) offset,
321
#endif /* UNIV_DEBUG */
323
++srv_read_ahead_rnd;
327
/************************************************************************
197
/********************************************************************//**
328
198
High-level function which reads a page asynchronously from a file to the
329
199
buffer buf_pool if it is not already there. Sets the io_fix flag and sets
330
200
an exclusive lock on the buffer frame. The flag is cleared and the x-lock
331
201
released by the i/o-handler thread. Does a random read-ahead if it seems
203
@return number of page read requests issued: this can be greater than
204
1 if read-ahead occurred */
337
/* out: number of page read requests issued: this can
338
be > 1 if read-ahead occurred */
339
ulint space, /* in: space id */
340
ulint zip_size,/* in: compressed page size in bytes, or 0 */
341
ulint offset) /* in: page number */
209
ulint space, /*!< in: space id */
210
ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
211
ulint offset) /*!< in: page number */
343
213
ib_int64_t tablespace_version;
651
527
buf_read_ibuf_merge_pages(
652
528
/*======================*/
653
ibool sync, /* in: TRUE if the caller
529
ibool sync, /*!< in: TRUE if the caller
654
530
wants this function to wait
655
531
for the highest address page
656
532
to get read in, before this
657
533
function returns */
658
const ulint* space_ids, /* in: array of space ids */
659
const ib_int64_t* space_versions,/* in: the spaces must have
534
const ulint* space_ids, /*!< in: array of space ids */
535
const ib_int64_t* space_versions,/*!< in: the spaces must have
660
536
this version number
661
537
(timestamp), otherwise we
662
538
discard the read; we use this
663
539
to cancel reads if DISCARD +
664
540
IMPORT may have changed the
665
541
tablespace size */
666
const ulint* page_nos, /* in: array of page numbers
542
const ulint* page_nos, /*!< in: array of page numbers
667
543
to read, with the highest page
668
544
number the last in the
670
ulint n_stored) /* in: number of elements
546
ulint n_stored) /*!< in: number of elements
720
596
#endif /* UNIV_DEBUG */
723
/************************************************************************
599
/********************************************************************//**
724
600
Issues read requests for pages which recovery wants to read in. */
727
603
buf_read_recv_pages(
728
604
/*================*/
729
ibool sync, /* in: TRUE if the caller
605
ibool sync, /*!< in: TRUE if the caller
730
606
wants this function to wait
731
607
for the highest address page
732
608
to get read in, before this
733
609
function returns */
734
ulint space, /* in: space id */
735
ulint zip_size, /* in: compressed page size in
610
ulint space, /*!< in: space id */
611
ulint zip_size, /*!< in: compressed page size in
737
const ulint* page_nos, /* in: array of page numbers
613
const ulint* page_nos, /*!< in: array of page numbers
738
614
to read, with the highest page
739
615
number the last in the
741
ulint n_stored) /* in: number of page numbers
617
ulint n_stored) /*!< in: number of page numbers
744
620
ib_int64_t tablespace_version;