11
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15
Place, Suite 330, Boston, MA 02111-1307 USA
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
17
*****************************************************************************/
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)
49
41
/** The linear read-ahead area size */
50
42
#define BUF_READ_AHEAD_LINEAR_AREA BUF_READ_AHEAD_AREA
62
54
@return 1 if a read request was queued, 0 if the page already resided
63
55
in buf_pool, or if the page is in the doublewrite buffer blocks in
64
56
which case it is never read into the pool, or if the tablespace does
65
not exist or is being dropped */
57
not exist or is being dropped
58
@return 1 if read request is issued. 0 if it is not */
167
160
/********************************************************************//**
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
/********************************************************************//**
198
161
High-level function which reads a page asynchronously from a file to the
199
162
buffer buf_pool if it is not already there. Sets the io_fix flag and sets
200
163
an exclusive lock on the buffer frame. The flag is cleared and the x-lock
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 */
164
released by the i/o-handler thread.
165
@return TRUE if page has been read in, FALSE in case of failure */
209
170
ulint space, /*!< in: space id */
213
174
ib_int64_t tablespace_version;
218
178
tablespace_version = fil_space_get_version(space);
220
count = buf_read_ahead_random(space, zip_size, offset);
222
180
/* We do the i/o in the synchronous aio mode to save thread
223
181
switches: hence TRUE */
225
count2 = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
227
tablespace_version, offset);
228
srv_buf_pool_reads+= count2;
183
count = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
185
tablespace_version, offset);
186
srv_buf_pool_reads += count;
229
187
if (err == DB_TABLESPACE_DELETED) {
230
188
ut_print_timestamp(stderr);
371
329
} else if (pred_bpage) {
372
int res = (ut_ulint_cmp(
373
buf_page_get_LRU_position(bpage),
374
buf_page_get_LRU_position(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));
375
341
/* Accesses not in the right order */
376
342
if (res != 0 && res != asc_or_desc) {