38
38
#include "srv0start.h"
39
39
#include "srv0srv.h"
41
/** The size in blocks of the area where the random read-ahead algorithm counts
42
the accessed pages when deciding whether to read-ahead */
43
#define BUF_READ_AHEAD_RANDOM_AREA BUF_READ_AHEAD_AREA
45
/** There must be at least this many pages in buf_pool in the area to start
46
a random read-ahead */
47
#define BUF_READ_AHEAD_RANDOM_THRESHOLD (1 + BUF_READ_AHEAD_RANDOM_AREA / 2)
41
49
/** The linear read-ahead area size */
42
50
#define BUF_READ_AHEAD_LINEAR_AREA BUF_READ_AHEAD_AREA
54
62
@return 1 if a read request was queued, 0 if the page already resided
55
63
in buf_pool, or if the page is in the doublewrite buffer blocks in
56
64
which case it is never read into the pool, or if the tablespace does
57
not exist or is being dropped
58
@return 1 if read request is issued. 0 if it is not */
65
not exist or is being dropped */
160
167
/********************************************************************//**
168
Applies a random read-ahead in buf_pool if there are at least a threshold
169
value of accessed pages from the random read-ahead area. Does not read any
170
page, not even the one at the position (space, offset), if the read-ahead
171
mechanism is not activated. NOTE 1: the calling thread may own latches on
172
pages: to avoid deadlocks this function must be written such that it cannot
173
end up waiting for these latches! NOTE 2: the calling thread must want
174
access to the page given: this rule is set to prevent unintended read-aheads
175
performed by ibuf routines, a situation which could result in a deadlock if
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
buf_read_ahead_random(
183
/*==================*/
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
192
/* We have currently disabled random readahead */
197
/********************************************************************//**
161
198
High-level function which reads a page asynchronously from a file to the
162
199
buffer buf_pool if it is not already there. Sets the io_fix flag and sets
163
200
an exclusive lock on the buffer frame. The flag is cleared and the x-lock
164
released by the i/o-handler thread.
165
@return TRUE if page has been read in, FALSE in case of failure */
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 */
170
209
ulint space, /*!< in: space id */
174
213
ib_int64_t tablespace_version;
178
218
tablespace_version = fil_space_get_version(space);
220
count = buf_read_ahead_random(space, zip_size, offset);
180
222
/* We do the i/o in the synchronous aio mode to save thread
181
223
switches: hence TRUE */
183
count = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
185
tablespace_version, offset);
186
srv_buf_pool_reads += count;
225
count2 = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
227
tablespace_version, offset);
228
srv_buf_pool_reads+= count2;
187
229
if (err == DB_TABLESPACE_DELETED) {
188
230
ut_print_timestamp(stderr);
329
371
} else if (pred_bpage) {
330
/* Note that buf_page_is_accessed() returns
331
the time of the first access. If some blocks
332
of the extent existed in the buffer pool at
333
the time of a linear access pattern, the first
334
access times may be nonmonotonic, even though
335
the latest access times were linear. The
336
threshold (srv_read_ahead_factor) should help
337
a little against this. */
338
int res = ut_ulint_cmp(
339
buf_page_is_accessed(bpage),
340
buf_page_is_accessed(pred_bpage));
372
int res = (ut_ulint_cmp(
373
buf_page_get_LRU_position(bpage),
374
buf_page_get_LRU_position(pred_bpage)));
341
375
/* Accesses not in the right order */
342
376
if (res != 0 && res != asc_or_desc) {