~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/buf0buf.ic

  • Committer: Brian Aker
  • Date: 2009-02-05 09:11:16 UTC
  • Revision ID: brian@tangent.org-20090205091116-iy0ersp6bhyzt1ad
Removed dead variables.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
 
3
 
Copyright (C) 1995, 2010, Innobase Oy. All Rights Reserved.
4
 
Copyright (C) 2008, Google Inc.
5
 
 
6
 
Portions of this file contain modifications contributed and copyrighted by
7
 
Google, Inc. Those modifications are gratefully acknowledged and are described
8
 
briefly in the InnoDB documentation. The contributions by Google are
9
 
incorporated with their permission, and subject to the conditions contained in
10
 
the file COPYING.Google.
11
 
 
12
 
This program is free software; you can redistribute it and/or modify it under
13
 
the terms of the GNU General Public License as published by the Free Software
14
 
Foundation; version 2 of the License.
15
 
 
16
 
This program is distributed in the hope that it will be useful, but WITHOUT
17
 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19
 
 
20
 
You should have received a copy of the GNU General Public License along with
21
 
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22
 
St, Fifth Floor, Boston, MA 02110-1301 USA
23
 
 
24
 
*****************************************************************************/
25
 
 
26
 
/**************************************************//**
27
 
@file include/buf0buf.ic
 
1
/******************************************************
28
2
The database buffer buf_pool
29
3
 
 
4
(c) 1995 Innobase Oy
 
5
 
30
6
Created 11/5/1995 Heikki Tuuri
31
7
*******************************************************/
32
8
 
33
 
#include "mtr0mtr.h"
34
9
#include "buf0flu.h"
35
10
#include "buf0lru.h"
36
11
#include "buf0rea.h"
37
 
#include "srv0srv.h"
38
 
 
39
 
/*********************************************************************//**
40
 
Gets the current size of buffer buf_pool in bytes.
41
 
@return size in bytes */
42
 
UNIV_INLINE
43
 
ulint
44
 
buf_pool_get_curr_size(void)
45
 
/*========================*/
46
 
{
47
 
        return(srv_buf_pool_curr_size);
48
 
}
49
 
 
50
 
/********************************************************************//**
51
 
Calculates the index of a buffer pool to the buf_pool[] array.
52
 
@return the position of the buffer pool in buf_pool[] */
53
 
UNIV_INLINE
54
 
ulint
55
 
buf_pool_index(
56
 
/*===========*/
57
 
        const buf_pool_t*       buf_pool)       /*!< in: buffer pool */
58
 
{
59
 
        ulint   i = buf_pool - buf_pool_ptr;
60
 
        ut_ad(i < MAX_BUFFER_POOLS);
61
 
        ut_ad(i < srv_buf_pool_instances);
62
 
        return(i);
63
 
}
64
 
 
65
 
/******************************************************************//**
66
 
Returns the buffer pool instance given a page instance
67
 
@return buf_pool */
68
 
UNIV_INLINE
69
 
buf_pool_t*
70
 
buf_pool_from_bpage(
71
 
/*================*/
72
 
        const buf_page_t*       bpage) /*!< in: buffer pool page */
73
 
{
74
 
        ulint   i;
75
 
        i = bpage->buf_pool_index;
76
 
        ut_ad(i < srv_buf_pool_instances);
77
 
        return(&buf_pool_ptr[i]);
78
 
}
79
 
 
80
 
/******************************************************************//**
81
 
Returns the buffer pool instance given a block instance
82
 
@return buf_pool */
83
 
UNIV_INLINE
84
 
buf_pool_t*
85
 
buf_pool_from_block(
86
 
/*================*/
87
 
        const buf_block_t*      block) /*!< in: block */
88
 
{
89
 
        return(buf_pool_from_bpage(&block->page));
90
 
}
91
 
 
92
 
/*********************************************************************//**
93
 
Gets the current size of buffer buf_pool in pages.
94
 
@return size in pages*/
95
 
UNIV_INLINE
96
 
ulint
97
 
buf_pool_get_n_pages(void)
98
 
/*======================*/
99
 
{
100
 
        return(buf_pool_get_curr_size() / UNIV_PAGE_SIZE);
101
 
}
102
 
 
103
 
/********************************************************************//**
104
 
Reads the freed_page_clock of a buffer block.
105
 
@return freed_page_clock */
 
12
#include "mtr0mtr.h"
 
13
 
 
14
/************************************************************************
 
15
Reads the freed_page_clock of a buffer block. */
106
16
UNIV_INLINE
107
17
ulint
108
18
buf_page_get_freed_page_clock(
109
19
/*==========================*/
110
 
        const buf_page_t*       bpage)  /*!< in: block */
 
20
                                        /* out: freed_page_clock */
 
21
        const buf_page_t*       bpage)  /* in: block */
111
22
{
112
 
        /* This is sometimes read without holding buf_pool->mutex. */
113
23
        return(bpage->freed_page_clock);
114
24
}
115
25
 
116
 
/********************************************************************//**
117
 
Reads the freed_page_clock of a buffer block.
118
 
@return freed_page_clock */
 
26
/************************************************************************
 
27
Reads the freed_page_clock of a buffer block. */
119
28
UNIV_INLINE
120
29
ulint
121
30
buf_block_get_freed_page_clock(
122
31
/*===========================*/
123
 
        const buf_block_t*      block)  /*!< in: block */
 
32
                                        /* out: freed_page_clock */
 
33
        const buf_block_t*      block)  /* in: block */
124
34
{
125
35
        return(buf_page_get_freed_page_clock(&block->page));
126
36
}
127
37
 
128
 
/********************************************************************//**
 
38
/************************************************************************
129
39
Recommends a move of a block to the start of the LRU list if there is danger
130
40
of dropping from the buffer pool. NOTE: does not reserve the buffer pool
131
 
mutex.
132
 
@return TRUE if should be made younger */
 
41
mutex. */
133
42
UNIV_INLINE
134
43
ibool
135
44
buf_page_peek_if_too_old(
136
45
/*=====================*/
137
 
        const buf_page_t*       bpage)  /*!< in: block to make younger */
138
 
{
139
 
        buf_pool_t*             buf_pool = buf_pool_from_bpage(bpage);
140
 
 
141
 
        if (UNIV_UNLIKELY(buf_pool->freed_page_clock == 0)) {
142
 
                /* If eviction has not started yet, do not update the
143
 
                statistics or move blocks in the LRU list.  This is
144
 
                either the warm-up phase or an in-memory workload. */
145
 
                return(FALSE);
146
 
        } else if (buf_LRU_old_threshold_ms && bpage->old) {
147
 
                unsigned        access_time = buf_page_is_accessed(bpage);
148
 
 
149
 
                if (access_time > 0
150
 
                    && ((ib_uint32_t) (ut_time_ms() - access_time))
151
 
                    >= buf_LRU_old_threshold_ms) {
152
 
                        return(TRUE);
153
 
                }
154
 
 
155
 
                buf_pool->stat.n_pages_not_made_young++;
156
 
                return(FALSE);
 
46
                                        /* out: TRUE if should be made
 
47
                                        younger */
 
48
        const buf_page_t*       bpage)  /* in: block to make younger */
 
49
{
 
50
        return(buf_pool->freed_page_clock
 
51
               >= buf_page_get_freed_page_clock(bpage)
 
52
               + 1 + (buf_pool->curr_size / 4));
 
53
}
 
54
 
 
55
/*************************************************************************
 
56
Gets the current size of buffer buf_pool in bytes. */
 
57
UNIV_INLINE
 
58
ulint
 
59
buf_pool_get_curr_size(void)
 
60
/*========================*/
 
61
                        /* out: size in bytes */
 
62
{
 
63
        return(buf_pool->curr_size * UNIV_PAGE_SIZE);
 
64
}
 
65
 
 
66
/************************************************************************
 
67
Gets the smallest oldest_modification lsn for any page in the pool. Returns
 
68
zero if all modified pages have been flushed to disk. */
 
69
UNIV_INLINE
 
70
ib_uint64_t
 
71
buf_pool_get_oldest_modification(void)
 
72
/*==================================*/
 
73
                                /* out: oldest modification in pool,
 
74
                                zero if none */
 
75
{
 
76
        buf_page_t*     bpage;
 
77
        ib_uint64_t     lsn;
 
78
 
 
79
        buf_pool_mutex_enter();
 
80
 
 
81
        bpage = UT_LIST_GET_LAST(buf_pool->flush_list);
 
82
 
 
83
        if (bpage == NULL) {
 
84
                lsn = 0;
157
85
        } else {
158
 
                /* FIXME: bpage->freed_page_clock is 31 bits */
159
 
                return((buf_pool->freed_page_clock & ((1UL << 31) - 1))
160
 
                       > ((ulint) bpage->freed_page_clock
161
 
                          + (buf_pool->curr_size
162
 
                             * (BUF_LRU_OLD_RATIO_DIV - buf_pool->LRU_old_ratio)
163
 
                             / (BUF_LRU_OLD_RATIO_DIV * 4))));
 
86
                ut_ad(bpage->in_flush_list);
 
87
                lsn = bpage->oldest_modification;
164
88
        }
165
 
}
166
 
 
167
 
/*********************************************************************//**
168
 
Gets the state of a block.
169
 
@return state */
 
89
 
 
90
        buf_pool_mutex_exit();
 
91
 
 
92
        return(lsn);
 
93
}
 
94
 
 
95
/***********************************************************************
 
96
Increments the buf_pool clock by one and returns its new value. Remember
 
97
that in the 32 bit version the clock wraps around at 4 billion! */
 
98
UNIV_INLINE
 
99
ulint
 
100
buf_pool_clock_tic(void)
 
101
/*====================*/
 
102
                        /* out: new clock value */
 
103
{
 
104
        ut_ad(buf_pool_mutex_own());
 
105
 
 
106
        buf_pool->ulint_clock++;
 
107
 
 
108
        return(buf_pool->ulint_clock);
 
109
}
 
110
 
 
111
/*************************************************************************
 
112
Gets the state of a block. */
170
113
UNIV_INLINE
171
114
enum buf_page_state
172
115
buf_page_get_state(
173
116
/*===============*/
174
 
        const buf_page_t*       bpage)  /*!< in: pointer to the control block */
 
117
                                        /* out: state */
 
118
        const buf_page_t*       bpage)  /* in: pointer to the control block */
175
119
{
176
120
        enum buf_page_state     state = (enum buf_page_state) bpage->state;
177
121
 
193
137
 
194
138
        return(state);
195
139
}
196
 
/*********************************************************************//**
197
 
Gets the state of a block.
198
 
@return state */
 
140
/*************************************************************************
 
141
Gets the state of a block. */
199
142
UNIV_INLINE
200
143
enum buf_page_state
201
144
buf_block_get_state(
202
145
/*================*/
203
 
        const buf_block_t*      block)  /*!< in: pointer to the control block */
 
146
                                        /* out: state */
 
147
        const buf_block_t*      block)  /* in: pointer to the control block */
204
148
{
205
149
        return(buf_page_get_state(&block->page));
206
150
}
207
 
/*********************************************************************//**
 
151
/*************************************************************************
208
152
Sets the state of a block. */
209
153
UNIV_INLINE
210
154
void
211
155
buf_page_set_state(
212
156
/*===============*/
213
 
        buf_page_t*             bpage,  /*!< in/out: pointer to control block */
214
 
        enum buf_page_state     state)  /*!< in: state */
 
157
        buf_page_t*             bpage,  /* in/out: pointer to control block */
 
158
        enum buf_page_state     state)  /* in: state */
215
159
{
216
160
#ifdef UNIV_DEBUG
217
161
        enum buf_page_state     old_state       = buf_page_get_state(bpage);
250
194
        ut_ad(buf_page_get_state(bpage) == state);
251
195
}
252
196
 
253
 
/*********************************************************************//**
 
197
/*************************************************************************
254
198
Sets the state of a block. */
255
199
UNIV_INLINE
256
200
void
257
201
buf_block_set_state(
258
202
/*================*/
259
 
        buf_block_t*            block,  /*!< in/out: pointer to control block */
260
 
        enum buf_page_state     state)  /*!< in: state */
 
203
        buf_block_t*            block,  /* in/out: pointer to control block */
 
204
        enum buf_page_state     state)  /* in: state */
261
205
{
262
206
        buf_page_set_state(&block->page, state);
263
207
}
264
208
 
265
 
/*********************************************************************//**
266
 
Determines if a block is mapped to a tablespace.
267
 
@return TRUE if mapped */
 
209
/*************************************************************************
 
210
Determines if a block is mapped to a tablespace. */
268
211
UNIV_INLINE
269
212
ibool
270
213
buf_page_in_file(
271
214
/*=============*/
272
 
        const buf_page_t*       bpage)  /*!< in: pointer to control block */
 
215
                                        /* out: TRUE if mapped */
 
216
        const buf_page_t*       bpage)  /* in: pointer to control block */
273
217
{
274
218
        switch (buf_page_get_state(bpage)) {
275
219
        case BUF_BLOCK_ZIP_FREE:
291
235
        return(FALSE);
292
236
}
293
237
 
294
 
#ifndef UNIV_HOTBACKUP
295
 
/*********************************************************************//**
296
 
Determines if a block should be on unzip_LRU list.
297
 
@return TRUE if block belongs to unzip_LRU */
 
238
/*************************************************************************
 
239
Determines if a block should be on unzip_LRU list. */
298
240
UNIV_INLINE
299
241
ibool
300
242
buf_page_belongs_to_unzip_LRU(
301
243
/*==========================*/
302
 
        const buf_page_t*       bpage)  /*!< in: pointer to control block */
 
244
                                        /* out: TRUE if block belongs
 
245
                                        to unzip_LRU */
 
246
        const buf_page_t*       bpage)  /* in: pointer to control block */
303
247
{
304
248
        ut_ad(buf_page_in_file(bpage));
305
249
 
307
251
               && buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE);
308
252
}
309
253
 
310
 
/*********************************************************************//**
311
 
Gets the mutex of a block.
312
 
@return pointer to mutex protecting bpage */
 
254
/*************************************************************************
 
255
Determine the approximate LRU list position of a block. */
 
256
UNIV_INLINE
 
257
ulint
 
258
buf_page_get_LRU_position(
 
259
/*======================*/
 
260
                                        /* out: LRU list position */
 
261
        const buf_page_t*       bpage)  /* in: control block */
 
262
{
 
263
        ut_ad(buf_page_in_file(bpage));
 
264
 
 
265
        return(bpage->LRU_position);
 
266
}
 
267
 
 
268
/*************************************************************************
 
269
Gets the mutex of a block. */
313
270
UNIV_INLINE
314
271
mutex_t*
315
272
buf_page_get_mutex(
316
273
/*===============*/
317
 
        const buf_page_t*       bpage)  /*!< in: pointer to control block */
 
274
                                        /* out: pointer to mutex
 
275
                                        protecting bpage */
 
276
        const buf_page_t*       bpage)  /* in: pointer to control block */
318
277
{
319
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
320
 
 
321
278
        switch (buf_page_get_state(bpage)) {
322
279
        case BUF_BLOCK_ZIP_FREE:
323
280
                ut_error;
324
281
                return(NULL);
325
282
        case BUF_BLOCK_ZIP_PAGE:
326
283
        case BUF_BLOCK_ZIP_DIRTY:
327
 
                return(&buf_pool->zip_mutex);
 
284
                return(&buf_pool_zip_mutex);
328
285
        default:
329
286
                return(&((buf_block_t*) bpage)->mutex);
330
287
        }
331
288
}
332
289
 
333
 
/*********************************************************************//**
334
 
Get the flush type of a page.
335
 
@return flush type */
 
290
/*************************************************************************
 
291
Get the flush type of a page. */
336
292
UNIV_INLINE
337
293
enum buf_flush
338
294
buf_page_get_flush_type(
339
295
/*====================*/
340
 
        const buf_page_t*       bpage)  /*!< in: buffer page */
 
296
                                        /* out: flush type */
 
297
        const buf_page_t*       bpage)  /* in: buffer page */
341
298
{
342
299
        enum buf_flush  flush_type = (enum buf_flush) bpage->flush_type;
343
300
 
354
311
#endif /* UNIV_DEBUG */
355
312
        return(flush_type);
356
313
}
357
 
/*********************************************************************//**
 
314
/*************************************************************************
358
315
Set the flush type of a page. */
359
316
UNIV_INLINE
360
317
void
361
318
buf_page_set_flush_type(
362
319
/*====================*/
363
 
        buf_page_t*     bpage,          /*!< in: buffer page */
364
 
        enum buf_flush  flush_type)     /*!< in: flush type */
 
320
        buf_page_t*     bpage,          /* in: buffer page */
 
321
        enum buf_flush  flush_type)     /* in: flush type */
365
322
{
366
323
        bpage->flush_type = flush_type;
367
324
        ut_ad(buf_page_get_flush_type(bpage) == flush_type);
368
325
}
369
326
 
370
 
/*********************************************************************//**
 
327
/*************************************************************************
371
328
Map a block to a file page. */
372
329
UNIV_INLINE
373
330
void
374
331
buf_block_set_file_page(
375
332
/*====================*/
376
 
        buf_block_t*            block,  /*!< in/out: pointer to control block */
377
 
        ulint                   space,  /*!< in: tablespace id */
378
 
        ulint                   page_no)/*!< in: page number */
 
333
        buf_block_t*            block,  /* in/out: pointer to control block */
 
334
        ulint                   space,  /* in: tablespace id */
 
335
        ulint                   page_no)/* in: page number */
379
336
{
380
337
        buf_block_set_state(block, BUF_BLOCK_FILE_PAGE);
381
338
        block->page.space = space;
382
339
        block->page.offset = page_no;
383
340
}
384
341
 
385
 
/*********************************************************************//**
386
 
Gets the io_fix state of a block.
387
 
@return io_fix state */
 
342
/*************************************************************************
 
343
Gets the io_fix state of a block. */
388
344
UNIV_INLINE
389
345
enum buf_io_fix
390
346
buf_page_get_io_fix(
391
347
/*================*/
392
 
        const buf_page_t*       bpage)  /*!< in: pointer to the control block */
 
348
                                        /* out: io_fix state */
 
349
        const buf_page_t*       bpage)  /* in: pointer to the control block */
393
350
{
394
351
        enum buf_io_fix io_fix = (enum buf_io_fix) bpage->io_fix;
395
352
#ifdef UNIV_DEBUG
404
361
        return(io_fix);
405
362
}
406
363
 
407
 
/*********************************************************************//**
408
 
Gets the io_fix state of a block.
409
 
@return io_fix state */
 
364
/*************************************************************************
 
365
Gets the io_fix state of a block. */
410
366
UNIV_INLINE
411
367
enum buf_io_fix
412
368
buf_block_get_io_fix(
413
 
/*=================*/
414
 
        const buf_block_t*      block)  /*!< in: pointer to the control block */
 
369
/*================*/
 
370
                                        /* out: io_fix state */
 
371
        const buf_block_t*      block)  /* in: pointer to the control block */
415
372
{
416
373
        return(buf_page_get_io_fix(&block->page));
417
374
}
418
375
 
419
 
/*********************************************************************//**
 
376
/*************************************************************************
420
377
Sets the io_fix state of a block. */
421
378
UNIV_INLINE
422
379
void
423
380
buf_page_set_io_fix(
424
381
/*================*/
425
 
        buf_page_t*     bpage,  /*!< in/out: control block */
426
 
        enum buf_io_fix io_fix) /*!< in: io_fix state */
 
382
        buf_page_t*     bpage,  /* in/out: control block */
 
383
        enum buf_io_fix io_fix) /* in: io_fix state */
427
384
{
428
 
#ifdef UNIV_DEBUG
429
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
430
 
        ut_ad(buf_pool_mutex_own(buf_pool));
431
 
#endif
 
385
        ut_ad(buf_pool_mutex_own());
432
386
        ut_ad(mutex_own(buf_page_get_mutex(bpage)));
433
387
 
434
388
        bpage->io_fix = io_fix;
435
389
        ut_ad(buf_page_get_io_fix(bpage) == io_fix);
436
390
}
437
391
 
438
 
/*********************************************************************//**
 
392
/*************************************************************************
439
393
Sets the io_fix state of a block. */
440
394
UNIV_INLINE
441
395
void
442
396
buf_block_set_io_fix(
443
397
/*=================*/
444
 
        buf_block_t*    block,  /*!< in/out: control block */
445
 
        enum buf_io_fix io_fix) /*!< in: io_fix state */
 
398
        buf_block_t*    block,  /* in/out: control block */
 
399
        enum buf_io_fix io_fix) /* in: io_fix state */
446
400
{
447
401
        buf_page_set_io_fix(&block->page, io_fix);
448
402
}
449
403
 
450
 
/********************************************************************//**
 
404
/************************************************************************
451
405
Determine if a buffer block can be relocated in memory.  The block
452
406
can be dirty, but it must not be I/O-fixed or bufferfixed. */
453
407
UNIV_INLINE
454
408
ibool
455
409
buf_page_can_relocate(
456
410
/*==================*/
457
 
        const buf_page_t*       bpage)  /*!< control block being relocated */
 
411
        const buf_page_t*       bpage)  /* control block being relocated */
458
412
{
459
 
#ifdef UNIV_DEBUG
460
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
461
 
        ut_ad(buf_pool_mutex_own(buf_pool));
462
 
#endif
 
413
        ut_ad(buf_pool_mutex_own());
463
414
        ut_ad(mutex_own(buf_page_get_mutex(bpage)));
464
415
        ut_ad(buf_page_in_file(bpage));
465
416
        ut_ad(bpage->in_LRU_list);
468
419
               && bpage->buf_fix_count == 0);
469
420
}
470
421
 
471
 
/*********************************************************************//**
472
 
Determine if a block has been flagged old.
473
 
@return TRUE if old */
 
422
/*************************************************************************
 
423
Determine if a block has been flagged old. */
474
424
UNIV_INLINE
475
425
ibool
476
426
buf_page_is_old(
477
427
/*============*/
478
 
        const buf_page_t*       bpage)  /*!< in: control block */
 
428
                                        /* out: TRUE if old */
 
429
        const buf_page_t*       bpage)  /* in: control block */
479
430
{
480
 
#ifdef UNIV_DEBUG
481
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
482
 
        ut_ad(buf_pool_mutex_own(buf_pool));
483
 
#endif
484
431
        ut_ad(buf_page_in_file(bpage));
485
432
 
486
433
        return(bpage->old);
487
434
}
488
435
 
489
 
/*********************************************************************//**
 
436
/*************************************************************************
490
437
Flag a block old. */
491
438
UNIV_INLINE
492
439
void
493
440
buf_page_set_old(
494
441
/*=============*/
495
 
        buf_page_t*     bpage,  /*!< in/out: control block */
496
 
        ibool           old)    /*!< in: old */
 
442
        buf_page_t*     bpage,  /* in/out: control block */
 
443
        ibool           old)    /* in: old */
497
444
{
498
 
#ifdef UNIV_DEBUG
499
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
500
 
#endif /* UNIV_DEBUG */
501
445
        ut_a(buf_page_in_file(bpage));
502
 
        ut_ad(buf_pool_mutex_own(buf_pool));
 
446
        ut_ad(buf_pool_mutex_own());
503
447
        ut_ad(bpage->in_LRU_list);
504
448
 
505
449
#ifdef UNIV_LRU_DEBUG
506
 
        ut_a((buf_pool->LRU_old_len == 0) == (buf_pool->LRU_old == NULL));
507
 
        /* If a block is flagged "old", the LRU_old list must exist. */
508
 
        ut_a(!old || buf_pool->LRU_old);
509
 
 
510
 
        if (UT_LIST_GET_PREV(LRU, bpage) && UT_LIST_GET_NEXT(LRU, bpage)) {
511
 
                const buf_page_t*       prev = UT_LIST_GET_PREV(LRU, bpage);
512
 
                const buf_page_t*       next = UT_LIST_GET_NEXT(LRU, bpage);
513
 
                if (prev->old == next->old) {
514
 
                        ut_a(prev->old == old);
515
 
                } else {
516
 
                        ut_a(!prev->old);
517
 
                        ut_a(buf_pool->LRU_old == (old ? bpage : next));
518
 
                }
 
450
        if (UT_LIST_GET_PREV(LRU, bpage) && UT_LIST_GET_NEXT(LRU, bpage)
 
451
            && UT_LIST_GET_PREV(LRU, bpage)->old
 
452
            == UT_LIST_GET_NEXT(LRU, bpage)->old) {
 
453
                ut_a(UT_LIST_GET_PREV(LRU, bpage)->old == old);
519
454
        }
520
455
#endif /* UNIV_LRU_DEBUG */
521
456
 
522
457
        bpage->old = old;
523
458
}
524
459
 
525
 
/*********************************************************************//**
526
 
Determine the time of first access of a block in the buffer pool.
527
 
@return ut_time_ms() at the time of first access, 0 if not accessed */
 
460
/*************************************************************************
 
461
Determine if a block has been accessed in the buffer pool. */
528
462
UNIV_INLINE
529
 
unsigned
 
463
ibool
530
464
buf_page_is_accessed(
531
465
/*=================*/
532
 
        const buf_page_t*       bpage)  /*!< in: control block */
 
466
                                        /* out: TRUE if accessed */
 
467
        const buf_page_t*       bpage)  /* in: control block */
533
468
{
534
469
        ut_ad(buf_page_in_file(bpage));
535
470
 
536
 
        return(bpage->access_time);
 
471
        return(bpage->accessed);
537
472
}
538
473
 
539
 
/*********************************************************************//**
 
474
/*************************************************************************
540
475
Flag a block accessed. */
541
476
UNIV_INLINE
542
477
void
543
478
buf_page_set_accessed(
544
479
/*==================*/
545
 
        buf_page_t*     bpage,          /*!< in/out: control block */
546
 
        ulint           time_ms)        /*!< in: ut_time_ms() */
 
480
        buf_page_t*     bpage,          /* in/out: control block */
 
481
        ibool           accessed)       /* in: accessed */
547
482
{
548
 
#ifdef UNIV_DEBUG
549
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
550
 
        ut_ad(buf_pool_mutex_own(buf_pool));
551
 
#endif
552
483
        ut_a(buf_page_in_file(bpage));
 
484
        ut_ad(mutex_own(buf_page_get_mutex(bpage)));
553
485
 
554
 
        if (!bpage->access_time) {
555
 
                /* Make this the time of the first access. */
556
 
                bpage->access_time = time_ms;
557
 
        }
 
486
        bpage->accessed = accessed;
558
487
}
559
488
 
560
 
/*********************************************************************//**
 
489
/*************************************************************************
561
490
Gets the buf_block_t handle of a buffered file block if an uncompressed
562
 
page frame exists, or NULL.
563
 
@return control block, or NULL */
 
491
page frame exists, or NULL. */
564
492
UNIV_INLINE
565
493
buf_block_t*
566
494
buf_page_get_block(
567
495
/*===============*/
568
 
        buf_page_t*     bpage)  /*!< in: control block, or NULL */
 
496
                                /* out: control block, or NULL */
 
497
        buf_page_t*     bpage)  /* in: control block, or NULL */
569
498
{
570
499
        if (UNIV_LIKELY(bpage != NULL)) {
571
500
                ut_ad(buf_page_in_file(bpage));
577
506
 
578
507
        return(NULL);
579
508
}
580
 
#endif /* !UNIV_HOTBACKUP */
581
509
 
582
510
#ifdef UNIV_DEBUG
583
 
/*********************************************************************//**
584
 
Gets a pointer to the memory frame of a block.
585
 
@return pointer to the frame */
 
511
/*************************************************************************
 
512
Gets a pointer to the memory frame of a block. */
586
513
UNIV_INLINE
587
514
buf_frame_t*
588
515
buf_block_get_frame(
589
516
/*================*/
590
 
        const buf_block_t*      block)  /*!< in: pointer to the control block */
 
517
                                        /* out: pointer to the frame */
 
518
        const buf_block_t*      block)  /* in: pointer to the control block */
591
519
{
592
520
        ut_ad(block);
593
521
 
599
527
                ut_error;
600
528
                break;
601
529
        case BUF_BLOCK_FILE_PAGE:
602
 
# ifndef UNIV_HOTBACKUP
603
530
                ut_a(block->page.buf_fix_count > 0);
604
 
# endif /* !UNIV_HOTBACKUP */
605
531
                /* fall through */
606
532
        case BUF_BLOCK_READY_FOR_USE:
607
533
        case BUF_BLOCK_MEMORY:
614
540
}
615
541
#endif /* UNIV_DEBUG */
616
542
 
617
 
/*********************************************************************//**
618
 
Gets the space id of a block.
619
 
@return space id */
 
543
/*************************************************************************
 
544
Gets the space id of a block. */
620
545
UNIV_INLINE
621
546
ulint
622
547
buf_page_get_space(
623
548
/*===============*/
624
 
        const buf_page_t*       bpage)  /*!< in: pointer to the control block */
 
549
                                        /* out: space id */
 
550
        const buf_page_t*       bpage)  /* in: pointer to the control block */
625
551
{
626
552
        ut_ad(bpage);
627
553
        ut_a(buf_page_in_file(bpage));
629
555
        return(bpage->space);
630
556
}
631
557
 
632
 
/*********************************************************************//**
633
 
Gets the space id of a block.
634
 
@return space id */
 
558
/*************************************************************************
 
559
Gets the space id of a block. */
635
560
UNIV_INLINE
636
561
ulint
637
562
buf_block_get_space(
638
563
/*================*/
639
 
        const buf_block_t*      block)  /*!< in: pointer to the control block */
 
564
                                        /* out: space id */
 
565
        const buf_block_t*      block)  /* in: pointer to the control block */
640
566
{
641
567
        ut_ad(block);
642
568
        ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
644
570
        return(block->page.space);
645
571
}
646
572
 
647
 
/*********************************************************************//**
648
 
Gets the page number of a block.
649
 
@return page number */
 
573
/*************************************************************************
 
574
Gets the page number of a block. */
650
575
UNIV_INLINE
651
576
ulint
652
577
buf_page_get_page_no(
653
578
/*=================*/
654
 
        const buf_page_t*       bpage)  /*!< in: pointer to the control block */
 
579
                                        /* out: page number */
 
580
        const buf_page_t*       bpage)  /* in: pointer to the control block */
655
581
{
656
582
        ut_ad(bpage);
657
583
        ut_a(buf_page_in_file(bpage));
659
585
        return(bpage->offset);
660
586
}
661
587
 
662
 
/*********************************************************************//**
663
 
Gets the page number of a block.
664
 
@return page number */
 
588
/*************************************************************************
 
589
Gets the page number of a block. */
665
590
UNIV_INLINE
666
591
ulint
667
592
buf_block_get_page_no(
668
593
/*==================*/
669
 
        const buf_block_t*      block)  /*!< in: pointer to the control block */
 
594
                                        /* out: page number */
 
595
        const buf_block_t*      block)  /* in: pointer to the control block */
670
596
{
671
597
        ut_ad(block);
672
598
        ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
674
600
        return(block->page.offset);
675
601
}
676
602
 
677
 
/*********************************************************************//**
678
 
Gets the compressed page size of a block.
679
 
@return compressed page size, or 0 */
 
603
/*************************************************************************
 
604
Gets the compressed page size of a block. */
680
605
UNIV_INLINE
681
606
ulint
682
607
buf_page_get_zip_size(
683
608
/*==================*/
684
 
        const buf_page_t*       bpage)  /*!< in: pointer to the control block */
 
609
                                        /* out: compressed page size, or 0 */
 
610
        const buf_page_t*       bpage)  /* in: pointer to the control block */
685
611
{
686
612
        return(bpage->zip.ssize ? 512 << bpage->zip.ssize : 0);
687
613
}
688
614
 
689
 
/*********************************************************************//**
690
 
Gets the compressed page size of a block.
691
 
@return compressed page size, or 0 */
 
615
/*************************************************************************
 
616
Gets the compressed page size of a block. */
692
617
UNIV_INLINE
693
618
ulint
694
619
buf_block_get_zip_size(
695
620
/*===================*/
696
 
        const buf_block_t*      block)  /*!< in: pointer to the control block */
 
621
                                        /* out: compressed page size, or 0 */
 
622
        const buf_block_t*      block)  /* in: pointer to the control block */
697
623
{
698
624
        return(block->page.zip.ssize ? 512 << block->page.zip.ssize : 0);
699
625
}
700
626
 
701
 
#ifndef UNIV_HOTBACKUP
702
627
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
703
 
/*********************************************************************//**
 
628
/***********************************************************************
 
629
Gets the block to whose frame the pointer is pointing to. */
 
630
UNIV_INLINE
 
631
const buf_block_t*
 
632
buf_block_align(
 
633
/*============*/
 
634
                                /* out: pointer to block */
 
635
        const byte*     ptr)    /* in: pointer to a frame */
 
636
{
 
637
        const buf_block_t*      block;
 
638
        ulint                   space_id, page_no;
 
639
 
 
640
        ptr = (const byte*) ut_align_down(ptr, UNIV_PAGE_SIZE);
 
641
        page_no = mach_read_from_4(ptr + FIL_PAGE_OFFSET);
 
642
        space_id = mach_read_from_4(ptr + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
 
643
 
 
644
        block = (const buf_block_t*) buf_page_hash_get(space_id, page_no);
 
645
        ut_ad(block);
 
646
        ut_ad(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
 
647
        ut_ad(block->frame == ptr);
 
648
        return(block);
 
649
}
 
650
 
 
651
/*************************************************************************
704
652
Gets the compressed page descriptor corresponding to an uncompressed page
705
 
if applicable.
706
 
@return compressed page descriptor, or NULL */
 
653
if applicable. */
707
654
UNIV_INLINE
708
655
const page_zip_des_t*
709
656
buf_frame_get_page_zip(
710
657
/*===================*/
711
 
        const byte*     ptr)    /*!< in: pointer to the page */
 
658
                                /* out: compressed page descriptor, or NULL */
 
659
        const byte*     ptr)    /* in: pointer to the page */
712
660
{
713
 
        return(buf_block_get_page_zip(buf_block_align(ptr)));
 
661
        const page_zip_des_t*   page_zip;
 
662
        buf_pool_mutex_enter();
 
663
        page_zip = buf_block_get_page_zip(buf_block_align(ptr));
 
664
        buf_pool_mutex_exit();
 
665
        return(page_zip);
714
666
}
715
667
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
716
 
#endif /* !UNIV_HOTBACKUP */
717
668
 
718
 
/**********************************************************************//**
 
669
/**************************************************************************
719
670
Gets the space id, page offset, and byte offset within page of a
720
671
pointer pointing to a buffer frame containing a file page. */
721
672
UNIV_INLINE
722
673
void
723
674
buf_ptr_get_fsp_addr(
724
675
/*=================*/
725
 
        const void*     ptr,    /*!< in: pointer to a buffer frame */
726
 
        ulint*          space,  /*!< out: space id */
727
 
        fil_addr_t*     addr)   /*!< out: page offset and byte offset */
 
676
        const void*     ptr,    /* in: pointer to a buffer frame */
 
677
        ulint*          space,  /* out: space id */
 
678
        fil_addr_t*     addr)   /* out: page offset and byte offset */
728
679
{
729
680
        const page_t*   page = (const page_t*) ut_align_down(ptr,
730
681
                                                             UNIV_PAGE_SIZE);
734
685
        addr->boffset = ut_align_offset(ptr, UNIV_PAGE_SIZE);
735
686
}
736
687
 
737
 
#ifndef UNIV_HOTBACKUP
738
 
/**********************************************************************//**
 
688
/**************************************************************************
739
689
Gets the hash value of the page the pointer is pointing to. This can be used
740
 
in searches in the lock hash table.
741
 
@return lock hash value */
 
690
in searches in the lock hash table. */
742
691
UNIV_INLINE
743
692
ulint
744
693
buf_block_get_lock_hash_val(
745
694
/*========================*/
746
 
        const buf_block_t*      block)  /*!< in: block */
 
695
                                        /* out: lock hash value */
 
696
        const buf_block_t*      block)  /* in: block */
747
697
{
748
 
        ut_ad(block);
749
 
        ut_ad(buf_page_in_file(&block->page));
750
 
#ifdef UNIV_SYNC_DEBUG
751
 
        ut_ad(rw_lock_own(&(((buf_block_t*) block)->lock), RW_LOCK_EXCLUSIVE)
752
 
              || rw_lock_own(&(((buf_block_t*) block)->lock), RW_LOCK_SHARED));
753
 
#endif /* UNIV_SYNC_DEBUG */
754
698
        return(block->lock_hash_val);
755
699
}
756
700
 
757
 
/********************************************************************//**
 
701
/************************************************************************
 
702
Allocates a buffer block. */
 
703
UNIV_INLINE
 
704
buf_block_t*
 
705
buf_block_alloc(
 
706
/*============*/
 
707
                                /* out, own: the allocated block,
 
708
                                in state BUF_BLOCK_MEMORY */
 
709
        ulint   zip_size)       /* in: compressed page size in bytes,
 
710
                                or 0 if uncompressed tablespace */
 
711
{
 
712
        buf_block_t*    block;
 
713
 
 
714
        block = buf_LRU_get_free_block(zip_size);
 
715
 
 
716
        buf_block_set_state(block, BUF_BLOCK_MEMORY);
 
717
 
 
718
        return(block);
 
719
}
 
720
 
 
721
/************************************************************************
758
722
Frees a buffer block which does not contain a file page. */
759
723
UNIV_INLINE
760
724
void
761
725
buf_block_free(
762
726
/*===========*/
763
 
        buf_block_t*    block)  /*!< in, own: block to be freed */
 
727
        buf_block_t*    block)  /* in, own: block to be freed */
764
728
{
765
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage((buf_page_t*)block);
766
 
 
767
 
        buf_pool_mutex_enter(buf_pool);
 
729
        buf_pool_mutex_enter();
768
730
 
769
731
        mutex_enter(&block->mutex);
770
732
 
774
736
 
775
737
        mutex_exit(&block->mutex);
776
738
 
777
 
        buf_pool_mutex_exit(buf_pool);
 
739
        buf_pool_mutex_exit();
778
740
}
779
 
#endif /* !UNIV_HOTBACKUP */
780
741
 
781
 
/*********************************************************************//**
782
 
Copies contents of a buffer frame to a given buffer.
783
 
@return buf */
 
742
/*************************************************************************
 
743
Copies contents of a buffer frame to a given buffer. */
784
744
UNIV_INLINE
785
745
byte*
786
746
buf_frame_copy(
787
747
/*===========*/
788
 
        byte*                   buf,    /*!< in: buffer to copy to */
789
 
        const buf_frame_t*      frame)  /*!< in: buffer frame */
 
748
                                        /* out: buf */
 
749
        byte*                   buf,    /* in: buffer to copy to */
 
750
        const buf_frame_t*      frame)  /* in: buffer frame */
790
751
{
791
752
        ut_ad(buf && frame);
792
753
 
795
756
        return(buf);
796
757
}
797
758
 
798
 
#ifndef UNIV_HOTBACKUP
799
 
/********************************************************************//**
 
759
/************************************************************************
800
760
Calculates a folded value of a file page address to use in the page hash
801
 
table.
802
 
@return the folded value */
 
761
table. */
803
762
UNIV_INLINE
804
763
ulint
805
764
buf_page_address_fold(
806
765
/*==================*/
807
 
        ulint   space,  /*!< in: space id */
808
 
        ulint   offset) /*!< in: offset of the page within space */
 
766
                        /* out: the folded value */
 
767
        ulint   space,  /* in: space id */
 
768
        ulint   offset) /* in: offset of the page within space */
809
769
{
810
770
        return((space << 20) + space + offset);
811
771
}
812
772
 
813
 
/********************************************************************//**
 
773
/************************************************************************
 
774
This function is used to get info if there is an io operation
 
775
going on on a buffer page. */
 
776
UNIV_INLINE
 
777
ibool
 
778
buf_page_io_query(
 
779
/*==============*/
 
780
                                /* out: TRUE if io going on */
 
781
        buf_page_t*     bpage)  /* in: buf_pool block, must be bufferfixed */
 
782
{
 
783
        ibool   io_fixed;
 
784
 
 
785
        buf_pool_mutex_enter();
 
786
 
 
787
        ut_ad(buf_page_in_file(bpage));
 
788
        ut_ad(bpage->buf_fix_count > 0);
 
789
 
 
790
        io_fixed = buf_page_get_io_fix(bpage) != BUF_IO_NONE;
 
791
        buf_pool_mutex_exit();
 
792
 
 
793
        return(io_fixed);
 
794
}
 
795
 
 
796
/************************************************************************
814
797
Gets the youngest modification log sequence number for a frame.
815
 
Returns zero if not file page or no modification occurred yet.
816
 
@return newest modification to page */
 
798
Returns zero if not file page or no modification occurred yet. */
817
799
UNIV_INLINE
818
800
ib_uint64_t
819
801
buf_page_get_newest_modification(
820
802
/*=============================*/
821
 
        const buf_page_t*       bpage)  /*!< in: block containing the
 
803
                                        /* out: newest modification to page */
 
804
        const buf_page_t*       bpage)  /* in: block containing the
822
805
                                        page frame */
823
806
{
824
807
        ib_uint64_t     lsn;
825
 
        mutex_t*        block_mutex = buf_page_get_mutex(bpage);
826
808
 
827
 
        mutex_enter(block_mutex);
 
809
        buf_pool_mutex_enter();
828
810
 
829
811
        if (buf_page_in_file(bpage)) {
830
812
                lsn = bpage->newest_modification;
832
814
                lsn = 0;
833
815
        }
834
816
 
835
 
        mutex_exit(block_mutex);
 
817
        buf_pool_mutex_exit();
836
818
 
837
819
        return(lsn);
838
820
}
839
821
 
840
 
/********************************************************************//**
 
822
/************************************************************************
841
823
Increments the modify clock of a frame by 1. The caller must (1) own the
842
824
buf_pool mutex and block bufferfix count has to be zero, (2) or own an x-lock
843
825
on the block. */
845
827
void
846
828
buf_block_modify_clock_inc(
847
829
/*=======================*/
848
 
        buf_block_t*    block)  /*!< in: block */
 
830
        buf_block_t*    block)  /* in: block */
849
831
{
850
832
#ifdef UNIV_SYNC_DEBUG
851
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage((buf_page_t*)block);
852
 
 
853
 
        ut_ad((buf_pool_mutex_own(buf_pool)
 
833
        ut_ad((buf_pool_mutex_own()
854
834
               && (block->page.buf_fix_count == 0))
855
835
              || rw_lock_own(&(block->lock), RW_LOCK_EXCLUSIVE));
856
836
#endif /* UNIV_SYNC_DEBUG */
858
838
        block->modify_clock++;
859
839
}
860
840
 
861
 
/********************************************************************//**
 
841
/************************************************************************
862
842
Returns the value of the modify clock. The caller must have an s-lock
863
 
or x-lock on the block.
864
 
@return value */
 
843
or x-lock on the block. */
865
844
UNIV_INLINE
866
845
ib_uint64_t
867
846
buf_block_get_modify_clock(
868
847
/*=======================*/
869
 
        buf_block_t*    block)  /*!< in: block */
 
848
                                /* out: value */
 
849
        buf_block_t*    block)  /* in: block */
870
850
{
871
851
#ifdef UNIV_SYNC_DEBUG
872
852
        ut_ad(rw_lock_own(&(block->lock), RW_LOCK_SHARED)
876
856
        return(block->modify_clock);
877
857
}
878
858
 
879
 
/*******************************************************************//**
 
859
/***********************************************************************
880
860
Increments the bufferfix count. */
881
861
UNIV_INLINE
882
862
void
883
863
buf_block_buf_fix_inc_func(
884
864
/*=======================*/
885
865
#ifdef UNIV_SYNC_DEBUG
886
 
        const char*     file,   /*!< in: file name */
887
 
        ulint           line,   /*!< in: line */
 
866
        const char*     file,   /* in: file name */
 
867
        ulint           line,   /* in: line */
888
868
#endif /* UNIV_SYNC_DEBUG */
889
 
        buf_block_t*    block)  /*!< in/out: block to bufferfix */
 
869
        buf_block_t*    block)  /* in: block to bufferfix */
890
870
{
891
871
#ifdef UNIV_SYNC_DEBUG
892
872
        ibool   ret;
893
873
 
894
 
        ret = rw_lock_s_lock_nowait(&(block->debug_latch), file, line);
 
874
        ret = rw_lock_s_lock_func_nowait(&(block->debug_latch), file, line);
895
875
        ut_a(ret);
896
876
#endif /* UNIV_SYNC_DEBUG */
897
877
        ut_ad(mutex_own(&block->mutex));
899
879
        block->page.buf_fix_count++;
900
880
}
901
881
#ifdef UNIV_SYNC_DEBUG
902
 
/** Increments the bufferfix count.
903
 
@param b        in/out: block to bufferfix
904
 
@param f        in: file name where requested
905
 
@param l        in: line number where requested */
906
882
# define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(f,l,b)
907
883
#else /* UNIV_SYNC_DEBUG */
908
 
/** Increments the bufferfix count.
909
 
@param b        in/out: block to bufferfix
910
 
@param f        in: file name where requested
911
 
@param l        in: line number where requested */
912
884
# define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(b)
913
885
#endif /* UNIV_SYNC_DEBUG */
914
886
 
915
 
/*******************************************************************//**
 
887
/***********************************************************************
916
888
Decrements the bufferfix count. */
917
889
UNIV_INLINE
918
890
void
919
891
buf_block_buf_fix_dec(
920
892
/*==================*/
921
 
        buf_block_t*    block)  /*!< in/out: block to bufferunfix */
 
893
        buf_block_t*    block)  /* in: block to bufferunfix */
922
894
{
923
895
        ut_ad(mutex_own(&block->mutex));
924
896
 
928
900
#endif
929
901
}
930
902
 
931
 
/******************************************************************//**
932
 
Returns the buffer pool instance given space and offset of page
933
 
@return buffer pool */
934
 
UNIV_INLINE
935
 
buf_pool_t*
936
 
buf_pool_get(
937
 
/*==========*/
938
 
        ulint   space,  /*!< in: space id */
939
 
        ulint   offset) /*!< in: offset of the page within space */
940
 
{
941
 
        ulint   fold;
942
 
        ulint   index;
943
 
        ulint   ignored_offset;
944
 
 
945
 
        ignored_offset = offset >> 6; /* 2log of BUF_READ_AHEAD_AREA (64)*/
946
 
        fold = buf_page_address_fold(space, ignored_offset);
947
 
        index = fold % srv_buf_pool_instances;
948
 
        return(&buf_pool_ptr[index]);
949
 
}
950
 
 
951
 
/******************************************************************//**
952
 
Returns the buffer pool instance given its array index
953
 
@return buffer pool */
954
 
UNIV_INLINE
955
 
buf_pool_t*
956
 
buf_pool_from_array(
957
 
/*================*/
958
 
        ulint   index)          /*!< in: array index to get
959
 
                                buffer pool instance from */
960
 
{
961
 
        ut_ad(index < MAX_BUFFER_POOLS);
962
 
        ut_ad(index < srv_buf_pool_instances);
963
 
        return(&buf_pool_ptr[index]);
964
 
}
965
 
 
966
 
/******************************************************************//**
967
 
Returns the control block of a file page, NULL if not found.
968
 
@return block, NULL if not found */
 
903
/**********************************************************************
 
904
Returns the control block of a file page, NULL if not found. */
969
905
UNIV_INLINE
970
906
buf_page_t*
971
 
buf_page_hash_get_low(
972
 
/*==================*/
973
 
        buf_pool_t*     buf_pool,       /*!< buffer pool instance */
974
 
        ulint           space,          /*!< in: space id */
975
 
        ulint           offset,         /*!< in: offset of the page
976
 
                                        within space */
977
 
        ulint           fold)           /*!< in: buf_page_address_fold(
978
 
                                        space, offset) */
 
907
buf_page_hash_get(
 
908
/*==============*/
 
909
                        /* out: block, NULL if not found */
 
910
        ulint   space,  /* in: space id */
 
911
        ulint   offset) /* in: offset of the page within space */
979
912
{
980
913
        buf_page_t*     bpage;
 
914
        ulint           fold;
981
915
 
982
916
        ut_ad(buf_pool);
983
 
        ut_ad(buf_pool_mutex_own(buf_pool));
984
 
        ut_ad(fold == buf_page_address_fold(space, offset));
 
917
        ut_ad(buf_pool_mutex_own());
985
918
 
986
919
        /* Look for the page in the hash table */
987
920
 
 
921
        fold = buf_page_address_fold(space, offset);
 
922
 
988
923
        HASH_SEARCH(hash, buf_pool->page_hash, fold, buf_page_t*, bpage,
989
 
                    ut_ad(bpage->in_page_hash && !bpage->in_zip_hash
990
 
                          && buf_page_in_file(bpage)),
991
924
                    bpage->space == space && bpage->offset == offset);
992
925
        if (bpage) {
993
926
                ut_a(buf_page_in_file(bpage));
994
927
                ut_ad(bpage->in_page_hash);
995
928
                ut_ad(!bpage->in_zip_hash);
996
 
#if UNIV_WORD_SIZE == 4
997
 
                /* On 32-bit systems, there is no padding in
998
 
                buf_page_t.  On other systems, Valgrind could complain
999
 
                about uninitialized pad bytes. */
1000
929
                UNIV_MEM_ASSERT_RW(bpage, sizeof *bpage);
1001
 
#endif
1002
 
        }
1003
 
 
1004
 
        return(bpage);
1005
 
}
1006
 
 
1007
 
/******************************************************************//**
1008
 
Returns the control block of a file page, NULL if not found.
1009
 
@return block, NULL if not found or not a real control block */
1010
 
UNIV_INLINE
1011
 
buf_page_t*
1012
 
buf_page_hash_get(
1013
 
/*==============*/
1014
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
1015
 
        ulint           space,          /*!< in: space id */
1016
 
        ulint           offset)         /*!< in: offset of the page
1017
 
                                        within space */
1018
 
{
1019
 
        buf_page_t*     bpage;
1020
 
        ulint           fold    = buf_page_address_fold(space, offset);
1021
 
 
1022
 
        bpage   = buf_page_hash_get_low(buf_pool, space, offset, fold);
1023
 
 
1024
 
        if (bpage && buf_pool_watch_is_sentinel(buf_pool, bpage)) {
1025
 
                bpage = NULL;
1026
 
        }
1027
 
 
1028
 
        return(bpage);
1029
 
}
1030
 
 
1031
 
/******************************************************************//**
 
930
        }
 
931
 
 
932
        return(bpage);
 
933
}
 
934
 
 
935
/**********************************************************************
1032
936
Returns the control block of a file page, NULL if not found
1033
 
or an uncompressed page frame does not exist.
1034
 
@return block, NULL if not found */
 
937
or an uncompressed page frame does not exist. */
1035
938
UNIV_INLINE
1036
939
buf_block_t*
1037
940
buf_block_hash_get(
1038
941
/*===============*/
1039
 
        buf_pool_t*     buf_pool,       /*!< in: buffer pool instance */
1040
 
        ulint           space,          /*!< in: space id */
1041
 
        ulint           offset)         /*!< in: offset of the page
1042
 
                                        within space */
 
942
                        /* out: block, NULL if not found */
 
943
        ulint   space,  /* in: space id */
 
944
        ulint   offset) /* in: offset of the page within space */
1043
945
{
1044
 
        buf_block_t*    block;
1045
 
 
1046
 
        block = buf_page_get_block(buf_page_hash_get(buf_pool, space, offset));
1047
 
 
1048
 
        return(block);
 
946
        return(buf_page_get_block(buf_page_hash_get(space, offset)));
1049
947
}
1050
948
 
1051
 
/********************************************************************//**
1052
 
Returns TRUE if the page can be found in the buffer pool hash table.
1053
 
 
1054
 
NOTE that it is possible that the page is not yet read from disk,
1055
 
though.
1056
 
 
1057
 
@return TRUE if found in the page hash table */
 
949
/************************************************************************
 
950
Returns TRUE if the page can be found in the buffer pool hash table. NOTE
 
951
that it is possible that the page is not yet read from disk, though. */
1058
952
UNIV_INLINE
1059
953
ibool
1060
954
buf_page_peek(
1061
955
/*==========*/
1062
 
        ulint   space,  /*!< in: space id */
1063
 
        ulint   offset) /*!< in: page number */
 
956
                        /* out: TRUE if found from page hash table,
 
957
                        NOTE that the page is not necessarily yet read
 
958
                        from disk! */
 
959
        ulint   space,  /* in: space id */
 
960
        ulint   offset) /* in: page number */
1064
961
{
1065
962
        const buf_page_t*       bpage;
1066
 
        buf_pool_t*             buf_pool = buf_pool_get(space, offset);
1067
 
 
1068
 
        buf_pool_mutex_enter(buf_pool);
1069
 
 
1070
 
        bpage = buf_page_hash_get(buf_pool, space, offset);
1071
 
 
1072
 
        buf_pool_mutex_exit(buf_pool);
 
963
 
 
964
        buf_pool_mutex_enter();
 
965
 
 
966
        bpage = buf_page_hash_get(space, offset);
 
967
 
 
968
        buf_pool_mutex_exit();
1073
969
 
1074
970
        return(bpage != NULL);
1075
971
}
1076
972
 
1077
 
/********************************************************************//**
 
973
/************************************************************************
1078
974
Releases a compressed-only page acquired with buf_page_get_zip(). */
1079
975
UNIV_INLINE
1080
976
void
1081
977
buf_page_release_zip(
1082
978
/*=================*/
1083
 
        buf_page_t*     bpage)          /*!< in: buffer block */
 
979
        buf_page_t*     bpage)          /* in: buffer block */
1084
980
{
1085
981
        buf_block_t*    block;
1086
 
        buf_pool_t*     buf_pool = buf_pool_from_bpage(bpage);
1087
982
 
1088
983
        ut_ad(bpage);
1089
984
        ut_a(bpage->buf_fix_count > 0);
1091
986
        switch (buf_page_get_state(bpage)) {
1092
987
        case BUF_BLOCK_ZIP_PAGE:
1093
988
        case BUF_BLOCK_ZIP_DIRTY:
1094
 
                mutex_enter(&buf_pool->zip_mutex);
 
989
                mutex_enter(&buf_pool_zip_mutex);
1095
990
                bpage->buf_fix_count--;
1096
 
                mutex_exit(&buf_pool->zip_mutex);
 
991
                mutex_exit(&buf_pool_zip_mutex);
1097
992
                return;
1098
993
        case BUF_BLOCK_FILE_PAGE:
1099
994
                block = (buf_block_t*) bpage;
1112
1007
                break;
1113
1008
        }
1114
1009
 
1115
 
        
1116
1010
        ut_error;
1117
1011
}
1118
1012
 
1119
 
/********************************************************************//**
 
1013
/************************************************************************
1120
1014
Decrements the bufferfix count of a buffer control block and releases
1121
1015
a latch, if specified. */
1122
1016
UNIV_INLINE
1123
1017
void
1124
1018
buf_page_release(
1125
1019
/*=============*/
1126
 
        buf_block_t*    block,          /*!< in: buffer block */
1127
 
        ulint           rw_latch)       /*!< in: RW_S_LATCH, RW_X_LATCH,
 
1020
        buf_block_t*    block,          /* in: buffer block */
 
1021
        ulint           rw_latch,       /* in: RW_S_LATCH, RW_X_LATCH,
1128
1022
                                        RW_NO_LATCH */
 
1023
        mtr_t*          mtr)            /* in: mtr */
1129
1024
{
1130
1025
        ut_ad(block);
1131
1026
 
1132
1027
        ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
1133
1028
        ut_a(block->page.buf_fix_count > 0);
1134
1029
 
 
1030
        if (rw_latch == RW_X_LATCH && mtr->modifications) {
 
1031
                buf_pool_mutex_enter();
 
1032
                buf_flush_note_modification(block, mtr);
 
1033
                buf_pool_mutex_exit();
 
1034
        }
 
1035
 
1135
1036
        mutex_enter(&block->mutex);
1136
1037
 
1137
1038
#ifdef UNIV_SYNC_DEBUG
1149
1050
}
1150
1051
 
1151
1052
#ifdef UNIV_SYNC_DEBUG
1152
 
/*********************************************************************//**
 
1053
/*************************************************************************
1153
1054
Adds latch level info for the rw-lock protecting the buffer frame. This
1154
1055
should be called in the debug version after a successful latching of a
1155
1056
page if we know the latching order level of the acquired latch. */
1157
1058
void
1158
1059
buf_block_dbg_add_level(
1159
1060
/*====================*/
1160
 
        buf_block_t*    block,  /*!< in: buffer page
 
1061
        buf_block_t*    block,  /* in: buffer page
1161
1062
                                where we have acquired latch */
1162
 
        ulint           level)  /*!< in: latching order level */
 
1063
        ulint           level)  /* in: latching order level */
1163
1064
{
1164
1065
        sync_thread_add_level(&block->lock, level);
1165
1066
}
1166
1067
#endif /* UNIV_SYNC_DEBUG */
1167
 
/********************************************************************//**
1168
 
Acquire mutex on all buffer pool instances. */
1169
 
UNIV_INLINE
1170
 
void
1171
 
buf_pool_mutex_enter_all(void)
1172
 
/*==========================*/
1173
 
{
1174
 
        ulint   i;
1175
 
 
1176
 
        for (i = 0; i < srv_buf_pool_instances; i++) {
1177
 
                buf_pool_t*     buf_pool;
1178
 
 
1179
 
                buf_pool = buf_pool_from_array(i);
1180
 
                buf_pool_mutex_enter(buf_pool);
1181
 
        }
1182
 
}
1183
 
 
1184
 
/********************************************************************//**
1185
 
Release mutex on all buffer pool instances. */
1186
 
UNIV_INLINE
1187
 
void
1188
 
buf_pool_mutex_exit_all(void)
1189
 
/*=========================*/
1190
 
{
1191
 
        ulint   i;
1192
 
 
1193
 
        for (i = 0; i < srv_buf_pool_instances; i++) {
1194
 
                buf_pool_t*     buf_pool;
1195
 
 
1196
 
                buf_pool = buf_pool_from_array(i);
1197
 
                buf_pool_mutex_exit(buf_pool);
1198
 
        }
1199
 
}
1200
 
#endif /* !UNIV_HOTBACKUP */