1
1
/*****************************************************************************
3
Copyright (c) 1995, 2010, Innobase Oy. All Rights Reserved.
3
Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
5
5
This program is free software; you can redistribute it and/or modify it under
6
6
the terms of the GNU General Public License as published by the Free Software
160
160
/********************************************************************//**
161
Applies a random read-ahead in buf_pool if there are at least a threshold
162
value of accessed pages from the random read-ahead area. Does not read any
163
page, not even the one at the position (space, offset), if the read-ahead
164
mechanism is not activated. NOTE 1: the calling thread may own latches on
165
pages: to avoid deadlocks this function must be written such that it cannot
166
end up waiting for these latches! NOTE 2: the calling thread must want
167
access to the page given: this rule is set to prevent unintended read-aheads
168
performed by ibuf routines, a situation which could result in a deadlock if
169
the OS does not support asynchronous i/o.
170
@return number of page read requests issued; NOTE that if we read ibuf
171
pages, it may happen that the page at the given page number does not
172
get read even if we return a positive value! */
175
buf_read_ahead_random(
176
/*==================*/
177
ulint space, /*!< in: space id */
178
ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
179
ulint offset) /*!< in: page number of a page which the current thread
185
/* We have currently disabled random readahead */
190
/********************************************************************//**
161
191
High-level function which reads a page asynchronously from a file to the
162
192
buffer buf_pool if it is not already there. Sets the io_fix flag and sets
163
193
an exclusive lock on the buffer frame. The flag is cleared and the x-lock
171
201
ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
172
202
ulint offset) /*!< in: page number */
174
buf_pool_t* buf_pool = buf_pool_get(space, offset);
175
204
ib_int64_t tablespace_version;
179
209
tablespace_version = fil_space_get_version(space);
211
count = buf_read_ahead_random(space, zip_size, offset);
181
213
/* We do the i/o in the synchronous aio mode to save thread
182
214
switches: hence TRUE */
184
count = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
186
tablespace_version, offset);
187
srv_buf_pool_reads += count;
216
count2 = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
218
tablespace_version, offset);
219
srv_buf_pool_reads+= count2;
188
220
if (err == DB_TABLESPACE_DELETED) {
189
221
ut_print_timestamp(stderr);
198
230
/* Flush pages from the end of the LRU list if necessary */
199
buf_flush_free_margin(buf_pool);
231
buf_flush_free_margin();
201
233
/* Increment number of I/O operations used for LRU policy. */
202
234
buf_LRU_stat_inc_io();
236
return((count + count2) > 0);
207
239
/********************************************************************//**
237
269
ulint offset) /*!< in: page number of a page; NOTE: the current thread
238
270
must want access to this page (see NOTE 3 above) */
240
buf_pool_t* buf_pool = buf_pool_get(space, offset);
241
272
ib_int64_t tablespace_version;
242
273
buf_page_t* bpage;
243
274
buf_frame_t* frame;
289
320
tablespace_version = fil_space_get_version(space);
291
buf_pool_mutex_enter(buf_pool);
322
buf_pool_mutex_enter();
293
324
if (high > fil_space_get_size(space)) {
294
buf_pool_mutex_exit(buf_pool);
325
buf_pool_mutex_exit();
295
326
/* The area is not whole, return */
317
348
/* How many out of order accessed pages can we ignore
318
349
when working out the access pattern for linear readahead */
319
350
threshold = ut_min((64 - srv_read_ahead_threshold),
320
BUF_READ_AHEAD_AREA(buf_pool));
351
BUF_READ_AHEAD_AREA);
324
355
for (i = low; i < high; i++) {
325
bpage = buf_page_hash_get(buf_pool, space, i);
356
bpage = buf_page_hash_get(space, i);
327
if (bpage == NULL || !buf_page_is_accessed(bpage)) {
358
if ((bpage == NULL) || !buf_page_is_accessed(bpage)) {
328
359
/* Not accessed */
331
362
} else if (pred_bpage) {
332
/* Note that buf_page_is_accessed() returns
333
the time of the first access. If some blocks
334
of the extent existed in the buffer pool at
335
the time of a linear access pattern, the first
336
access times may be nonmonotonic, even though
337
the latest access times were linear. The
338
threshold (srv_read_ahead_factor) should help
339
a little against this. */
340
int res = ut_ulint_cmp(
341
buf_page_is_accessed(bpage),
342
buf_page_is_accessed(pred_bpage));
363
int res = (ut_ulint_cmp(
364
buf_page_get_LRU_position(bpage),
365
buf_page_get_LRU_position(pred_bpage)));
343
366
/* Accesses not in the right order */
344
367
if (res != 0 && res != asc_or_desc) {
360
383
/* If we got this far, we know that enough pages in the area have
361
384
been accessed in the right order: linear read-ahead can be sensible */
363
bpage = buf_page_hash_get(buf_pool, space, offset);
386
bpage = buf_page_hash_get(space, offset);
365
388
if (bpage == NULL) {
366
buf_pool_mutex_exit(buf_pool);
389
buf_pool_mutex_exit();
520
543
#ifdef UNIV_IBUF_DEBUG
521
544
ut_a(n_stored < UNIV_PAGE_SIZE);
546
while (buf_pool->n_pend_reads
547
> buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {
548
os_thread_sleep(500000);
524
551
for (i = 0; i < n_stored; i++) {
526
buf_pool_t* buf_pool;
527
ulint zip_size = fil_space_get_zip_size(space_ids[i]);
529
buf_pool = buf_pool_get(space_ids[i], space_versions[i]);
531
while (buf_pool->n_pend_reads
532
> buf_pool->curr_size / BUF_READ_AHEAD_PEND_LIMIT) {
533
os_thread_sleep(500000);
552
ulint zip_size = fil_space_get_zip_size(space_ids[i]);
536
555
if (UNIV_UNLIKELY(zip_size == ULINT_UNDEFINED)) {
606
625
tablespace_version = fil_space_get_version(space);
608
627
for (i = 0; i < n_stored; i++) {
609
buf_pool_t* buf_pool;
613
631
os_aio_print_debug = FALSE;
614
buf_pool = buf_pool_get(space, page_nos[i]);
615
633
while (buf_pool->n_pend_reads >= recv_n_pool_free_frames / 2) {
617
635
os_aio_simulated_wake_handler_threads();
618
os_thread_sleep(10000);
636
os_thread_sleep(500000);
624
642
"InnoDB: Error: InnoDB has waited for"
625
" 10 seconds for pending\n"
643
" 50 seconds for pending\n"
626
644
"InnoDB: reads to the buffer pool to"
627
645
" be finished.\n"
628
646
"InnoDB: Number of pending reads %lu,"