61
55
prints info whenever read or flush
63
57
#endif /* UNIV_DEBUG */
64
extern ulint srv_buf_pool_write_requests; /* variable to count write request
59
/* States of a control block (@see buf_page_struct).
60
The enumeration values must be 0..7. */
62
BUF_BLOCK_ZIP_FREE = 0, /* contains a free compressed page */
63
BUF_BLOCK_ZIP_PAGE, /* contains a clean compressed page */
64
BUF_BLOCK_ZIP_DIRTY, /* contains a compressed page that is
65
in the buf_pool->flush_list */
67
/* The constants for compressed-only pages must precede
68
BUF_BLOCK_NOT_USED; @see buf_block_state_valid() */
70
BUF_BLOCK_NOT_USED, /* is in the free list */
71
BUF_BLOCK_READY_FOR_USE, /* when buf_LRU_get_free_block returns
72
a block, it is in this state */
73
BUF_BLOCK_FILE_PAGE, /* contains a buffered file page */
74
BUF_BLOCK_MEMORY, /* contains some main memory object */
75
BUF_BLOCK_REMOVE_HASH /* hash index should be removed
76
before putting to the free list */
67
79
/************************************************************************
68
80
Creates the buffer pool. */
73
85
/* out, own: buf_pool object, NULL if not
74
86
enough memory or error */
75
ulint max_size, /* in: maximum size of the buf_pool in
77
ulint curr_size, /* in: current size to use, must be <=
78
max_size, currently must be equal to
80
ulint n_frames); /* in: number of frames; if AWE is used,
81
this is the size of the address space window
82
where physical memory pages are mapped; if
83
AWE is not used then this must be the same
87
/************************************************************************
88
Frees the buffer pool at shutdown. This must not be invoked before
89
freeing all mutexes. */
95
/************************************************************************
96
Relocate a buffer control block. Relocates the block on the LRU list
97
and in buf_pool->page_hash. Does not relocate bpage->list.
98
The caller must take care of relocating bpage->list. */
103
buf_page_t* bpage, /* in/out: control block being relocated;
104
buf_page_get_state(bpage) must be
105
BUF_BLOCK_ZIP_DIRTY or BUF_BLOCK_ZIP_PAGE */
106
buf_page_t* dpage) /* in/out: destination control block */
107
__attribute__((nonnull));
108
/************************************************************************
109
Resizes the buffer pool. */
112
buf_pool_resize(void);
113
/*=================*/
85
114
/*************************************************************************
86
Gets the current size of buffer buf_pool in bytes. In the case of AWE, the
87
size of AWE window (= the frames). */
115
Gets the current size of buffer buf_pool in bytes. */
90
118
buf_pool_get_curr_size(void);
91
119
/*========================*/
92
120
/* out: size in bytes */
93
/*************************************************************************
94
Gets the maximum size of buffer pool in bytes. In the case of AWE, the
95
size of AWE window (= the frames). */
98
buf_pool_get_max_size(void);
99
/*=======================*/
100
/* out: size in bytes */
101
121
/************************************************************************
102
122
Gets the smallest oldest_modification lsn for any page in the pool. Returns
103
ut_dulint_zero if all modified pages have been flushed to disk. */
123
zero if all modified pages have been flushed to disk. */
106
126
buf_pool_get_oldest_modification(void);
107
127
/*==================================*/
108
128
/* out: oldest modification in pool,
109
ut_dulint_zero if none */
110
/*************************************************************************
111
Allocates a buffer frame. */
114
buf_frame_alloc(void);
115
/*==================*/
116
/* out: buffer frame */
117
/*************************************************************************
118
Frees a buffer frame which does not contain a file page. */
130
/************************************************************************
131
Allocates a buffer block. */
136
/* out, own: the allocated block,
137
in state BUF_BLOCK_MEMORY */
138
ulint zip_size); /* in: compressed page size in bytes,
139
or 0 if uncompressed tablespace */
140
/************************************************************************
141
Frees a buffer block which does not contain a file page. */
123
buf_frame_t* frame); /* in: buffer frame */
146
buf_block_t* block); /* in, own: block to be freed */
124
147
/*************************************************************************
125
148
Copies contents of a buffer frame to a given buffer. */
131
byte* buf, /* in: buffer to copy to */
132
buf_frame_t* frame); /* in: buffer frame */
154
byte* buf, /* in: buffer to copy to */
155
const buf_frame_t* frame); /* in: buffer frame */
133
156
/******************************************************************
134
157
NOTE! The following macros should be used instead of buf_page_get_gen,
135
158
to improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed
137
#define buf_page_get(SP, OF, LA, MTR) buf_page_get_gen(\
160
#define buf_page_get(SP, ZS, OF, LA, MTR) buf_page_get_gen(\
161
SP, ZS, OF, LA, NULL,\
139
162
BUF_GET, __FILE__, __LINE__, MTR)
140
163
/******************************************************************
141
164
Use these macros to bufferfix a page with no latching. Remember not to
143
166
the contents of the page! We have separated this case, because it is
144
167
error-prone programming not to set a latch, and it should be used
146
#define buf_page_get_with_no_latch(SP, OF, MTR) buf_page_get_gen(\
147
SP, OF, RW_NO_LATCH, NULL,\
169
#define buf_page_get_with_no_latch(SP, ZS, OF, MTR) buf_page_get_gen(\
170
SP, ZS, OF, RW_NO_LATCH, NULL,\
148
171
BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)
149
172
/******************************************************************
150
173
NOTE! The following macros should be used instead of buf_page_get_gen, to
151
174
improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed as LA! */
152
#define buf_page_get_nowait(SP, OF, LA, MTR) buf_page_get_gen(\
175
#define buf_page_get_nowait(SP, ZS, OF, LA, MTR) buf_page_get_gen(\
176
SP, ZS, OF, LA, NULL,\
154
177
BUF_GET_NOWAIT, __FILE__, __LINE__, MTR)
155
178
/******************************************************************
156
179
NOTE! The following macros should be used instead of
157
180
buf_page_optimistic_get_func, to improve debugging. Only values RW_S_LATCH and
158
181
RW_X_LATCH are allowed as LA! */
159
#define buf_page_optimistic_get(LA, BL, G, MC, MTR) \
160
buf_page_optimistic_get_func(LA, BL, G, MC, __FILE__, __LINE__, MTR)
182
#define buf_page_optimistic_get(LA, BL, MC, MTR) \
183
buf_page_optimistic_get_func(LA, BL, MC, __FILE__, __LINE__, MTR)
161
184
/************************************************************************
162
185
This is the general function used to get optimistic access to a database
166
189
buf_page_optimistic_get_func(
167
190
/*=========================*/
168
191
/* out: TRUE if success */
169
192
ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
170
193
buf_block_t* block, /* in: guessed block */
171
buf_frame_t* guess, /* in: guessed frame; note that AWE may move
173
dulint modify_clock,/* in: modify clock value if mode is
194
ib_uint64_t modify_clock,/* in: modify clock value if mode is
174
195
..._GUESS_ON_CLOCK */
175
196
const char* file, /* in: file name */
176
197
ulint line, /* in: line where called */
177
198
mtr_t* mtr); /* in: mini-transaction */
178
199
/************************************************************************
179
Tries to get the page, but if file io is required, releases all latches
180
in mtr down to the given savepoint. If io is required, this function
181
retrieves the page to buffer buf_pool, but does not bufferfix it or latch
185
buf_page_get_release_on_io(
186
/*=======================*/
187
/* out: pointer to the frame, or NULL
188
if not in buffer buf_pool */
189
ulint space, /* in: space id */
190
ulint offset, /* in: offset of the page within space
191
in units of a page */
192
buf_frame_t* guess, /* in: guessed frame or NULL */
193
ulint rw_latch, /* in: RW_X_LATCH, RW_S_LATCH,
195
ulint savepoint, /* in: mtr savepoint */
196
mtr_t* mtr); /* in: mtr */
197
/************************************************************************
198
200
This is used to get access to a known database page, when no waiting can be
202
204
buf_page_get_known_nowait(
203
205
/*======================*/
204
206
/* out: TRUE if success */
205
207
ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
206
buf_frame_t* guess, /* in: the known page frame */
208
buf_block_t* block, /* in: the known page */
207
209
ulint mode, /* in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
208
210
const char* file, /* in: file name */
209
211
ulint line, /* in: line where called */
210
212
mtr_t* mtr); /* in: mini-transaction */
214
/***********************************************************************
215
Given a tablespace id and page number tries to get that page. If the
216
page is not in the buffer pool it is not loaded and NULL is returned.
217
Suitable for using when holding the kernel mutex. */
220
buf_page_try_get_func(
221
/*==================*/
222
ulint space_id,/* in: tablespace id */
223
ulint page_no,/* in: page number */
224
const char* file, /* in: file name */
225
ulint line, /* in: line where called */
226
mtr_t* mtr); /* in: mini-transaction */
228
#define buf_page_try_get(space_id, page_no, mtr) \
229
buf_page_try_get_func(space_id, page_no, __FILE__, __LINE__, mtr);
231
/************************************************************************
232
Get read access to a compressed page (usually of type
233
FIL_PAGE_TYPE_ZBLOB or FIL_PAGE_TYPE_ZBLOB2).
234
The page must be released with buf_page_release_zip().
235
NOTE: the page is not protected by any latch. Mutual exclusion has to
236
be implemented at a higher level. In other words, all possible
237
accesses to a given page through this function must be protected by
238
the same set of mutexes or latches. */
243
/* out: pointer to the block,
244
or NULL if not compressed */
245
ulint space, /* in: space id */
246
ulint zip_size,/* in: compressed page size */
247
ulint offset);/* in: page number */
211
248
/************************************************************************
212
249
This is the general function used to get access to a database page. */
215
252
buf_page_get_gen(
216
253
/*=============*/
217
/* out: pointer to the frame or NULL */
254
/* out: pointer to the block or NULL */
218
255
ulint space, /* in: space id */
256
ulint zip_size,/* in: compressed page size in bytes
257
or 0 for uncompressed pages */
219
258
ulint offset, /* in: page number */
220
259
ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
221
buf_frame_t* guess, /* in: guessed frame or NULL */
260
buf_block_t* guess, /* in: guessed block or NULL */
222
261
ulint mode, /* in: BUF_GET, BUF_GET_IF_IN_POOL,
223
262
BUF_GET_NO_LATCH */
224
263
const char* file, /* in: file name */
228
267
Initializes a page to the buffer buf_pool. The page is usually not read
229
268
from a file even if it cannot be found in the buffer buf_pool. This is one
230
269
of the functions which perform to a block a state transition NOT_USED =>
231
FILE_PAGE (the other is buf_page_init_for_read above). */
270
FILE_PAGE (the other is buf_page_get_gen). */
236
/* out: pointer to the frame, page bufferfixed */
275
/* out: pointer to the block, page bufferfixed */
237
276
ulint space, /* in: space id */
238
277
ulint offset, /* in: offset of the page within space in units of
279
ulint zip_size,/* in: compressed page size, or 0 */
240
280
mtr_t* mtr); /* in: mini-transaction handle */
281
#ifdef UNIV_HOTBACKUP
241
282
/************************************************************************
242
283
Inits a page to the buffer buf_pool, for use in ibbackup --restore. */
245
286
buf_page_init_for_backup_restore(
246
287
/*=============================*/
247
288
ulint space, /* in: space id */
248
289
ulint offset, /* in: offset of the page within space
249
290
in units of a page */
291
ulint zip_size,/* in: compressed page size in bytes
292
or 0 for uncompressed pages */
250
293
buf_block_t* block); /* in: block to init */
294
#endif /* UNIV_HOTBACKUP */
295
/************************************************************************
296
Releases a compressed-only page acquired with buf_page_get_zip(). */
299
buf_page_release_zip(
300
/*=================*/
301
buf_page_t* bpage); /* in: buffer block */
251
302
/************************************************************************
252
303
Decrements the bufferfix count of a buffer control block and releases
253
304
a latch, if specified. */
281
332
ulint space, /* in: space id */
282
333
ulint offset);/* in: page number */
283
334
/************************************************************************
284
Returns the buffer control block if the page can be found in the buffer
285
pool. NOTE that it is possible that the page is not yet read
286
from disk, though. This is a very low-level function: use with care! */
291
/* out: control block if found from page hash table,
292
otherwise NULL; NOTE that the page is not necessarily
293
yet read from disk! */
294
ulint space, /* in: space id */
295
ulint offset);/* in: page number */
296
/************************************************************************
297
335
Resets the check_index_page_at_flush field of a page if found in the buffer
301
339
buf_reset_check_index_page_at_flush(
302
340
/*================================*/
303
341
ulint space, /* in: space id */
304
342
ulint offset);/* in: page number */
343
#ifdef UNIV_DEBUG_FILE_ACCESSES
305
344
/************************************************************************
306
345
Sets file_page_was_freed TRUE if the page is found in the buffer pool.
307
346
This function should be called when we free a file page and want the
308
347
debug version to check that it is not accessed any more unless
312
351
buf_page_set_file_page_was_freed(
313
352
/*=============================*/
314
/* out: control block if found from page hash table,
353
/* out: control block if found in page hash table,
315
354
otherwise NULL */
316
355
ulint space, /* in: space id */
317
ulint offset); /* in: page number */
356
ulint offset);/* in: page number */
318
357
/************************************************************************
319
358
Sets file_page_was_freed FALSE if the page is found in the buffer pool.
320
359
This function should be called when we free a file page and want the
321
360
debug version to check that it is not accessed any more unless
325
364
buf_page_reset_file_page_was_freed(
326
365
/*===============================*/
327
/* out: control block if found from page hash table,
366
/* out: control block if found in page hash table,
328
367
otherwise NULL */
329
368
ulint space, /* in: space id */
330
369
ulint offset); /* in: page number */
370
#endif /* UNIV_DEBUG_FILE_ACCESSES */
371
/************************************************************************
372
Reads the freed_page_clock of a buffer block. */
375
buf_page_get_freed_page_clock(
376
/*==========================*/
377
/* out: freed_page_clock */
378
const buf_page_t* bpage) /* in: block */
379
__attribute__((pure));
380
/************************************************************************
381
Reads the freed_page_clock of a buffer block. */
384
buf_block_get_freed_page_clock(
385
/*===========================*/
386
/* out: freed_page_clock */
387
const buf_block_t* block) /* in: block */
388
__attribute__((pure));
331
390
/************************************************************************
332
391
Recommends a move of a block to the start of the LRU list if there is danger
333
392
of dropping from the buffer pool. NOTE: does not reserve the buffer pool
337
buf_block_peek_if_too_old(
338
/*======================*/
339
/* out: TRUE if should be made younger */
340
buf_block_t* block); /* in: block to make younger */
396
buf_page_peek_if_too_old(
397
/*=====================*/
398
/* out: TRUE if should be made
400
const buf_page_t* bpage); /* in: block to make younger */
341
401
/************************************************************************
342
402
Returns the current state of is_hashed of a page. FALSE if the page is
343
403
not in the pool. NOTE that this operation does not fix the page in the
344
404
pool if it is found there. */
347
407
buf_page_peek_if_search_hashed(
348
408
/*===========================*/
354
414
Gets the youngest modification log sequence number for a frame.
355
415
Returns zero if not file page or no modification occurred yet. */
358
buf_frame_get_newest_modification(
359
/*==============================*/
360
/* out: newest modification to page */
361
buf_frame_t* frame); /* in: pointer to a frame */
362
/************************************************************************
363
Increments the modify clock of a frame by 1. The caller must (1) own the
364
pool mutex and block bufferfix count has to be zero, (2) or own an x-lock
368
buf_frame_modify_clock_inc(
369
/*=======================*/
371
buf_frame_t* frame); /* in: pointer to a frame */
418
buf_page_get_newest_modification(
419
/*=============================*/
420
/* out: newest modification to page */
421
const buf_page_t* bpage); /* in: block containing the
372
423
/************************************************************************
373
424
Increments the modify clock of a frame by 1. The caller must (1) own the
374
425
buf_pool mutex and block bufferfix count has to be zero, (2) or own an x-lock
378
429
buf_block_modify_clock_inc(
379
430
/*=======================*/
381
431
buf_block_t* block); /* in: block */
382
432
/************************************************************************
383
433
Returns the value of the modify clock. The caller must have an s-lock
384
434
or x-lock on the block. */
387
437
buf_block_get_modify_clock(
388
438
/*=======================*/
445
479
buf_ptr_get_fsp_addr(
446
480
/*=================*/
447
byte* ptr, /* in: pointer to a buffer frame */
481
const void* ptr, /* in: pointer to a buffer frame */
448
482
ulint* space, /* out: space id */
449
483
fil_addr_t* addr); /* out: page offset and byte offset */
450
484
/**************************************************************************
451
Gets the hash value of the page the pointer is pointing to. This can be used
452
in searches in the lock hash table. */
485
Gets the hash value of a block. This can be used in searches in the
455
buf_frame_get_lock_hash_val(
489
buf_block_get_lock_hash_val(
456
490
/*========================*/
457
/* out: lock hash value */
458
byte* ptr); /* in: pointer to within a buffer frame */
459
/**************************************************************************
460
Gets the mutex number protecting the page record lock hash chain in the lock
467
byte* ptr); /* in: pointer to within a buffer frame */
468
/***********************************************************************
469
Gets the frame the pointer is pointing to. */
474
/* out: pointer to frame */
475
byte* ptr); /* in: pointer to a frame */
476
/***********************************************************************
477
Checks if a pointer points to the block array of the buffer pool (blocks, not
483
/* out: TRUE if pointer to block */
484
void* ptr); /* in: pointer to memory */
491
/* out: lock hash value */
492
const buf_block_t* block) /* in: block */
493
__attribute__((pure));
485
494
#ifdef UNIV_DEBUG
486
495
/*************************************************************************
496
Finds a block in the buffer pool that points to a
497
given compressed page. */
500
buf_pool_contains_zip(
501
/*==================*/
502
/* out: buffer block pointing to
503
the compressed page, or NULL */
504
const void* data); /* in: pointer to compressed page */
505
#endif /* UNIV_DEBUG */
506
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
507
/*************************************************************************
487
508
Validates the buffer pool data structure. */
490
511
buf_validate(void);
491
512
/*==============*/
513
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
514
#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
492
515
/*************************************************************************
493
516
Prints info of the buffer pool data structure. */
498
#endif /* UNIV_DEBUG */
521
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
499
522
/************************************************************************
500
523
Prints a page to stderr. */
505
byte* read_buf); /* in: a database page */
528
const byte* read_buf, /* in: a database page */
529
ulint zip_size); /* in: compressed page size, or
530
0 for uncompressed pages */
506
531
/*************************************************************************
507
532
Returns the number of latched pages in the buffer pool. */
510
535
buf_get_latched_pages_number(void);
511
536
/*==============================*/
512
537
/*************************************************************************
513
538
Returns the number of pending buf pool ios. */
516
541
buf_get_n_pending_ios(void);
517
542
/*=======================*/
518
543
/*************************************************************************
519
544
Prints info of the buffer i/o. */
582
594
page if we know the latching order level of the acquired latch. */
585
buf_page_dbg_add_level(
586
/*===================*/
587
buf_frame_t* frame, /* in: buffer page where we have acquired
597
buf_block_dbg_add_level(
598
/*====================*/
599
buf_block_t* block, /* in: buffer page
600
where we have acquired latch */
589
601
ulint level); /* in: latching order level */
590
602
#endif /* UNIV_SYNC_DEBUG */
591
603
/*************************************************************************
604
Gets the state of a block. */
610
const buf_page_t* bpage); /* in: pointer to the control block */
611
/*************************************************************************
612
Gets the state of a block. */
618
const buf_block_t* block) /* in: pointer to the control block */
619
__attribute__((pure));
620
/*************************************************************************
621
Sets the state of a block. */
626
buf_page_t* bpage, /* in/out: pointer to control block */
627
enum buf_page_state state); /* in: state */
628
/*************************************************************************
629
Sets the state of a block. */
634
buf_block_t* block, /* in/out: pointer to control block */
635
enum buf_page_state state); /* in: state */
636
/*************************************************************************
637
Determines if a block is mapped to a tablespace. */
642
/* out: TRUE if mapped */
643
const buf_page_t* bpage) /* in: pointer to control block */
644
__attribute__((pure));
645
/*************************************************************************
646
Determines if a block should be on unzip_LRU list. */
649
buf_page_belongs_to_unzip_LRU(
650
/*==========================*/
651
/* out: TRUE if block belongs
653
const buf_page_t* bpage) /* in: pointer to control block */
654
__attribute__((pure));
655
/*************************************************************************
656
Determine the approximate LRU list position of a block. */
659
buf_page_get_LRU_position(
660
/*======================*/
661
/* out: LRU list position */
662
const buf_page_t* bpage) /* in: control block */
663
__attribute__((pure));
665
/*************************************************************************
666
Gets the mutex of a block. */
671
/* out: pointer to mutex
673
const buf_page_t* bpage) /* in: pointer to control block */
674
__attribute__((pure));
676
/*************************************************************************
677
Get the flush type of a page. */
680
buf_page_get_flush_type(
681
/*====================*/
682
/* out: flush type */
683
const buf_page_t* bpage) /* in: buffer page */
684
__attribute__((pure));
685
/*************************************************************************
686
Set the flush type of a page. */
689
buf_page_set_flush_type(
690
/*====================*/
691
buf_page_t* bpage, /* in: buffer page */
692
enum buf_flush flush_type); /* in: flush type */
693
/*************************************************************************
694
Map a block to a file page. */
697
buf_block_set_file_page(
698
/*====================*/
699
buf_block_t* block, /* in/out: pointer to control block */
700
ulint space, /* in: tablespace id */
701
ulint page_no);/* in: page number */
702
/*************************************************************************
703
Gets the io_fix state of a block. */
708
/* out: io_fix state */
709
const buf_page_t* bpage) /* in: pointer to the control block */
710
__attribute__((pure));
711
/*************************************************************************
712
Gets the io_fix state of a block. */
715
buf_block_get_io_fix(
717
/* out: io_fix state */
718
const buf_block_t* block) /* in: pointer to the control block */
719
__attribute__((pure));
720
/*************************************************************************
721
Sets the io_fix state of a block. */
726
buf_page_t* bpage, /* in/out: control block */
727
enum buf_io_fix io_fix);/* in: io_fix state */
728
/*************************************************************************
729
Sets the io_fix state of a block. */
732
buf_block_set_io_fix(
733
/*=================*/
734
buf_block_t* block, /* in/out: control block */
735
enum buf_io_fix io_fix);/* in: io_fix state */
737
/************************************************************************
738
Determine if a buffer block can be relocated in memory. The block
739
can be dirty, but it must not be I/O-fixed or bufferfixed. */
742
buf_page_can_relocate(
743
/*==================*/
744
const buf_page_t* bpage) /* control block being relocated */
745
__attribute__((pure));
747
/*************************************************************************
748
Determine if a block has been flagged old. */
753
/* out: TRUE if old */
754
const buf_page_t* bpage) /* in: control block */
755
__attribute__((pure));
756
/*************************************************************************
762
buf_page_t* bpage, /* in/out: control block */
763
ibool old); /* in: old */
764
/*************************************************************************
765
Determine if a block has been accessed in the buffer pool. */
768
buf_page_is_accessed(
769
/*=================*/
770
/* out: TRUE if accessed */
771
const buf_page_t* bpage) /* in: control block */
772
__attribute__((pure));
773
/*************************************************************************
774
Flag a block accessed. */
777
buf_page_set_accessed(
778
/*==================*/
779
buf_page_t* bpage, /* in/out: control block */
780
ibool accessed); /* in: accessed */
781
/*************************************************************************
782
Gets the buf_block_t handle of a buffered file block if an uncompressed
783
page frame exists, or NULL. */
788
/* out: control block, or NULL */
789
buf_page_t* bpage) /* in: control block, or NULL */
790
__attribute__((pure));
792
/*************************************************************************
592
793
Gets a pointer to the memory frame of a block. */
595
796
buf_block_get_frame(
596
797
/*================*/
597
/* out: pointer to the frame */
598
buf_block_t* block); /* in: pointer to the control block */
798
/* out: pointer to the frame */
799
const buf_block_t* block) /* in: pointer to the control block */
800
__attribute__((pure));
801
#else /* UNIV_DEBUG */
802
# define buf_block_get_frame(block) (block)->frame
803
#endif /* UNIV_DEBUG */
804
/*************************************************************************
805
Gets the space id of a block. */
811
const buf_page_t* bpage) /* in: pointer to the control block */
812
__attribute__((pure));
599
813
/*************************************************************************
600
814
Gets the space id of a block. */
603
817
buf_block_get_space(
604
818
/*================*/
606
buf_block_t* block); /* in: pointer to the control block */
820
const buf_block_t* block) /* in: pointer to the control block */
821
__attribute__((pure));
822
/*************************************************************************
823
Gets the page number of a block. */
826
buf_page_get_page_no(
827
/*=================*/
828
/* out: page number */
829
const buf_page_t* bpage) /* in: pointer to the control block */
830
__attribute__((pure));
607
831
/*************************************************************************
608
832
Gets the page number of a block. */
611
835
buf_block_get_page_no(
612
836
/*==================*/
613
/* out: page number */
614
buf_block_t* block); /* in: pointer to the control block */
837
/* out: page number */
838
const buf_block_t* block) /* in: pointer to the control block */
839
__attribute__((pure));
840
/*************************************************************************
841
Gets the compressed page size of a block. */
844
buf_page_get_zip_size(
845
/*==================*/
846
/* out: compressed page size, or 0 */
847
const buf_page_t* bpage) /* in: pointer to the control block */
848
__attribute__((pure));
849
/*************************************************************************
850
Gets the compressed page size of a block. */
853
buf_block_get_zip_size(
854
/*===================*/
855
/* out: compressed page size, or 0 */
856
const buf_block_t* block) /* in: pointer to the control block */
857
__attribute__((pure));
858
/*************************************************************************
859
Gets the compressed page descriptor corresponding to an uncompressed page
861
#define buf_block_get_page_zip(block) \
862
(UNIV_LIKELY_NULL((block)->page.zip.data) ? &(block)->page.zip : NULL)
863
#if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
615
864
/***********************************************************************
616
865
Gets the block to whose frame the pointer is pointing to. */
621
/* out: pointer to block */
622
byte* ptr); /* in: pointer to a frame */
870
/* out: pointer to block */
871
const byte* ptr); /* in: pointer to a frame */
872
/*************************************************************************
873
Gets the compressed page descriptor corresponding to an uncompressed page
876
const page_zip_des_t*
877
buf_frame_get_page_zip(
878
/*===================*/
879
/* out: compressed page descriptor, or NULL */
880
const byte* ptr); /* in: pointer to the page */
881
#endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
623
882
/************************************************************************
624
883
This function is used to get info if there is an io operation
625
884
going on on a buffer page. */
646
896
then this function does nothing.
647
897
Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock
648
898
on the buffer frame. The io-handler must take care that the flag is cleared
649
and the lock released later. This is one of the functions which perform the
650
state transition NOT_USED => FILE_PAGE to a block (the other is
899
and the lock released later. */
654
902
buf_page_init_for_read(
655
903
/*===================*/
656
904
/* out: pointer to the block or NULL */
657
905
ulint* err, /* out: DB_SUCCESS or DB_TABLESPACE_DELETED */
658
906
ulint mode, /* in: BUF_READ_IBUF_PAGES_ONLY, ... */
659
907
ulint space, /* in: space id */
660
ib_longlong tablespace_version,/* in: prevents reading from a wrong
908
ulint zip_size,/* in: compressed page size, or 0 */
909
ibool unzip, /* in: TRUE=request uncompressed page */
910
ib_int64_t tablespace_version,/* in: prevents reading from a wrong
661
911
version of the tablespace in case we have done
662
912
DISCARD + IMPORT */
663
913
ulint offset);/* in: page number */
664
914
/************************************************************************
665
915
Completes an asynchronous read or write request of a file page to or from
666
916
the buffer pool. */
669
919
buf_page_io_complete(
670
920
/*=================*/
671
buf_block_t* block); /* in: pointer to the block in question */
921
buf_page_t* bpage); /* in: pointer to the block in question */
672
922
/************************************************************************
673
923
Calculates a folded value of a file page address to use in the page hash
698
959
/* out: new clock value */
699
960
/*************************************************************************
700
961
Gets the current length of the free list of buffer blocks. */
703
964
buf_get_free_list_len(void);
704
965
/*=======================*/
969
/* The common buffer control block structure
970
for compressed and uncompressed frames */
972
struct buf_page_struct{
973
/* None of the following bit-fields must be modified without
974
holding buf_page_get_mutex() [block->mutex or buf_pool_zip_mutex],
975
since they can be stored in the same machine word. Some of them are
976
additionally protected by buf_pool_mutex. */
978
unsigned space:32; /* tablespace id */
979
unsigned offset:32; /* page number */
981
unsigned state:3; /* state of the control block
982
(@see enum buf_page_state); also
983
protected by buf_pool_mutex.
984
State transitions from
985
BUF_BLOCK_READY_FOR_USE to
986
BUF_BLOCK_MEMORY need not be
987
protected by buf_page_get_mutex(). */
988
unsigned flush_type:2; /* if this block is currently being
989
flushed to disk, this tells the
990
flush_type (@see enum buf_flush) */
991
unsigned accessed:1; /* TRUE if the page has been accessed
992
while in the buffer pool: read-ahead
993
may read in pages which have not been
994
accessed yet; a thread is allowed to
995
read this for heuristic purposes
996
without holding any mutex or latch */
997
unsigned io_fix:2; /* type of pending I/O operation
998
(@see enum buf_io_fix); also
999
protected by buf_pool_mutex */
1000
unsigned buf_fix_count:24;/* count of how manyfold this block
1001
is currently bufferfixed */
1003
page_zip_des_t zip; /* compressed page; zip.data
1004
(but not the data it points to) is
1005
also protected by buf_pool_mutex */
1006
buf_page_t* hash; /* node used in chaining to
1007
buf_pool->page_hash or
1008
buf_pool->zip_hash */
1010
ibool in_page_hash; /* TRUE if in buf_pool->page_hash */
1011
ibool in_zip_hash; /* TRUE if in buf_pool->zip_hash */
1012
#endif /* UNIV_DEBUG */
1014
/* 2. Page flushing fields; protected by buf_pool_mutex */
1016
UT_LIST_NODE_T(buf_page_t) list;
1017
/* based on state, this is a list
1018
node in one of the following lists
1021
BUF_BLOCK_NOT_USED: free
1022
BUF_BLOCK_FILE_PAGE: flush_list
1023
BUF_BLOCK_ZIP_DIRTY: flush_list
1024
BUF_BLOCK_ZIP_PAGE: zip_clean
1025
BUF_BLOCK_ZIP_FREE: zip_free[] */
1027
ibool in_flush_list; /* TRUE if in buf_pool->flush_list;
1028
when buf_pool_mutex is free, the
1029
following should hold: in_flush_list
1030
== (state == BUF_BLOCK_FILE_PAGE
1031
|| state == BUF_BLOCK_ZIP_DIRTY) */
1032
ibool in_free_list; /* TRUE if in buf_pool->free; when
1033
buf_pool_mutex is free, the following
1034
should hold: in_free_list
1035
== (state == BUF_BLOCK_NOT_USED) */
1036
#endif /* UNIV_DEBUG */
1037
ib_uint64_t newest_modification;
1038
/* log sequence number of the youngest
1039
modification to this block, zero if
1041
ib_uint64_t oldest_modification;
1042
/* log sequence number of the START of
1043
the log entry written of the oldest
1044
modification to this block which has
1045
not yet been flushed on disk; zero if
1046
all modifications are on disk */
1048
/* 3. LRU replacement algorithm fields; protected by buf_pool_mutex */
1050
UT_LIST_NODE_T(buf_page_t) LRU;
1051
/* node of the LRU list */
1053
ibool in_LRU_list; /* TRUE if the page is in the LRU list;
1054
used in debugging */
1055
#endif /* UNIV_DEBUG */
1056
unsigned old:1; /* TRUE if the block is in the old
1057
blocks in the LRU list */
1058
unsigned LRU_position:31;/* value which monotonically decreases
1059
(or may stay constant if old==TRUE)
1060
toward the end of the LRU list, if
1061
buf_pool->ulint_clock has not wrapped
1062
around: NOTE that this value can only
1063
be used in heuristic algorithms,
1064
because of the possibility of a
1066
unsigned freed_page_clock:32;/* the value of
1067
buf_pool->freed_page_clock when this
1068
block was the last time put to the
1069
head of the LRU list; a thread is
1070
allowed to read this for heuristic
1071
purposes without holding any mutex or
1073
#ifdef UNIV_DEBUG_FILE_ACCESSES
1074
ibool file_page_was_freed;
1075
/* this is set to TRUE when fsp
1076
frees a page in buffer pool */
1077
#endif /* UNIV_DEBUG_FILE_ACCESSES */
708
1080
/* The buffer control block structure */
710
1082
struct buf_block_struct{
712
1084
/* 1. General fields */
714
ulint magic_n; /* magic number to check */
715
ulint state; /* state of the control block:
716
BUF_BLOCK_NOT_USED, ...; changing
717
this is only allowed when a thread
718
has BOTH the buffer pool mutex AND
719
block->mutex locked */
1086
buf_page_t page; /* page information; this must
1087
be the first field, so that
1088
buf_pool->page_hash can point
1089
to buf_page_t or buf_block_t */
1090
UT_LIST_NODE_T(buf_block_t) unzip_LRU;
1091
/* node of the decompressed LRU list;
1092
a block is in the unzip_LRU list
1093
if page.state == BUF_BLOCK_FILE_PAGE
1094
and page.zip.data != NULL */
1096
ibool in_unzip_LRU_list;/* TRUE if the page is in the
1097
decompressed LRU list;
1098
used in debugging */
1099
#endif /* UNIV_DEBUG */
720
1100
byte* frame; /* pointer to buffer frame which
721
1101
is of size UNIV_PAGE_SIZE, and
722
1102
aligned to an address divisible by
723
UNIV_PAGE_SIZE; if AWE is used, this
724
will be NULL for the pages which are
725
currently not mapped into the virtual
726
address space window of the buffer
728
os_awe_t* awe_info; /* if AWE is used, then an array of
730
UNIV_PAGE_SIZE / OS_AWE_X86_PAGE_SIZE
731
(normally = 4) physical memory
732
pages; otherwise NULL */
733
ulint space; /* space id of the page */
734
ulint offset; /* page number within the space */
735
ulint lock_hash_val; /* hashed value of the page address
736
in the record lock hash table */
737
1104
mutex_t mutex; /* mutex protecting this block:
738
1105
state (also protected by the buffer
739
1106
pool mutex), io_fix, buf_fix_count,
752
1119
buffer pool which are index pages,
753
1120
but this flag is not set because
754
1121
we do not keep track of all pages */
755
/* 2. Page flushing fields */
757
UT_LIST_NODE_T(buf_block_t) flush_list;
758
/* node of the modified, not yet
759
flushed blocks list */
760
dulint newest_modification;
761
/* log sequence number of the youngest
762
modification to this block, zero if
764
dulint oldest_modification;
765
/* log sequence number of the START of
766
the log entry written of the oldest
767
modification to this block which has
768
not yet been flushed on disk; zero if
769
all modifications are on disk */
770
ulint flush_type; /* if this block is currently being
771
flushed to disk, this tells the
772
flush_type: BUF_FLUSH_LRU or
775
/* 3. LRU replacement algorithm fields */
777
UT_LIST_NODE_T(buf_block_t) free;
778
/* node of the free block list */
779
ibool in_free_list; /* TRUE if in the free list; used in
781
UT_LIST_NODE_T(buf_block_t) LRU;
782
/* node of the LRU list */
783
UT_LIST_NODE_T(buf_block_t) awe_LRU_free_mapped;
784
/* in the AWE version node in the
785
list of free and LRU blocks which are
787
ibool in_LRU_list; /* TRUE of the page is in the LRU list;
789
ulint LRU_position; /* value which monotonically
790
decreases (or may stay constant if
791
the block is in the old blocks) toward
792
the end of the LRU list, if the pool
793
ulint_clock has not wrapped around:
794
NOTE that this value can only be used
795
in heuristic algorithms, because of
796
the possibility of a wrap-around! */
797
ulint freed_page_clock;/* the value of freed_page_clock
798
of the buffer pool when this block was
799
the last time put to the head of the
800
LRU list; a thread is allowed to
801
read this for heuristic purposes
802
without holding any mutex or latch */
803
ibool old; /* TRUE if the block is in the old
804
blocks in the LRU list */
805
ibool accessed; /* TRUE if the page has been accessed
806
while in the buffer pool: read-ahead
807
may read in pages which have not been
808
accessed yet; this is protected by
809
block->mutex; a thread is allowed to
810
read this for heuristic purposes
811
without holding any mutex or latch */
812
ulint buf_fix_count; /* count of how manyfold this block
813
is currently bufferfixed; this is
814
protected by block->mutex */
815
ulint io_fix; /* if a read is pending to the frame,
816
io_fix is BUF_IO_READ, in the case
817
of a write BUF_IO_WRITE, otherwise 0;
818
this is protected by block->mutex */
819
/* 4. Optimistic search field */
821
dulint modify_clock; /* this clock is incremented every
1123
/* 2. Optimistic search field */
1125
ib_uint64_t modify_clock; /* this clock is incremented every
822
1126
time a pointer to a record on the
823
1127
page may become obsolete; this is
824
1128
used in the optimistic cursor
852
1156
An exception to this is when we init or create a page
853
1157
in the buffer pool in buf0buf.c. */
855
ibool is_hashed; /* TRUE if hash index has already been
1160
ulint n_pointers; /* used in debugging: the number of
1161
pointers in the adaptive hash index
1162
pointing to this frame */
1163
#endif /* UNIV_DEBUG */
1164
unsigned is_hashed:1; /* TRUE if hash index has already been
856
1165
built on this page; note that it does
857
1166
not guarantee that the index is
858
1167
complete, though: there may have been
859
1168
hash collisions, record deletions,
861
ulint n_pointers; /* used in debugging: the number of
862
pointers in the adaptive hash index
863
pointing to this frame */
864
ulint curr_n_fields; /* prefix length for hash indexing:
1170
unsigned curr_n_fields:10;/* prefix length for hash indexing:
865
1171
number of full fields */
866
ulint curr_n_bytes; /* number of bytes in hash indexing */
867
ibool curr_left_side; /* TRUE or FALSE in hash indexing */
1172
unsigned curr_n_bytes:15;/* number of bytes in hash indexing */
1173
unsigned curr_left_side:1;/* TRUE or FALSE in hash indexing */
868
1174
dict_index_t* index; /* Index for which the adaptive
869
1175
hash index has been created. */
870
/* 6. Debug fields */
1176
/* 4. Debug fields */
871
1177
#ifdef UNIV_SYNC_DEBUG
872
1178
rw_lock_t debug_latch; /* in the debug version, each thread
873
1179
which bufferfixes the block acquires
874
1180
an s-latch here; so we can use the
875
1181
debug utilities in sync0rw */
877
ibool file_page_was_freed;
878
/* this is set to TRUE when fsp
879
frees a page in buffer pool */
882
#define BUF_BLOCK_MAGIC_N 41526563
1185
/* Check if a buf_block_t object is in a valid state. */
1186
#define buf_block_state_valid(block) \
1187
(buf_block_get_state(block) >= BUF_BLOCK_NOT_USED \
1188
&& (buf_block_get_state(block) <= BUF_BLOCK_REMOVE_HASH))
1190
/**************************************************************************
1191
Compute the hash fold value for blocks in buf_pool->zip_hash. */
1192
#define BUF_POOL_ZIP_FOLD_PTR(ptr) ((ulint) (ptr) / UNIV_PAGE_SIZE)
1193
#define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
1194
#define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t*) (b))
884
1196
/* The buffer pool structure. NOTE! The definition appears here only for
885
1197
other modules of this directory (buf) to see it. Do not use from outside! */
889
1201
/* 1. General fields */
891
mutex_t mutex; /* mutex protecting the buffer pool
892
struct and control blocks, except the
893
read-write lock in them */
894
byte* frame_mem; /* pointer to the memory area which
895
was allocated for the frames; in AWE
896
this is the virtual address space
897
window where we map pages stored
898
in physical memory */
899
byte* frame_zero; /* pointer to the first buffer frame:
900
this may differ from frame_mem, because
901
this is aligned by the frame size */
902
byte* high_end; /* pointer to the end of the buffer
904
ulint n_frames; /* number of frames */
905
buf_block_t* blocks; /* array of buffer control blocks */
906
buf_block_t** blocks_of_frames;/* inverse mapping which can be used
907
to retrieve the buffer control block
908
of a frame; this is an array which
909
lists the blocks of frames in the
911
frame_zero + UNIV_PAGE_SIZE, ...
912
a control block is always assigned
913
for each frame, even if the frame does
914
not contain any data; note that in AWE
915
there are more control blocks than
917
os_awe_t* awe_info; /* if AWE is used, AWE info for the
918
physical 4 kB memory pages associated
919
with buffer frames */
920
ulint max_size; /* number of control blocks ==
921
maximum pool size in pages */
922
ulint curr_size; /* current pool size in pages;
923
currently always the same as
925
hash_table_t* page_hash; /* hash table of the file pages */
1203
ulint n_chunks; /* number of buffer pool chunks */
1204
buf_chunk_t* chunks; /* buffer pool chunks */
1205
ulint curr_size; /* current pool size in pages */
1206
hash_table_t* page_hash; /* hash table of buf_page_t or
1207
buf_block_t file pages,
1208
buf_page_in_file() == TRUE,
1209
indexed by (space_id, offset) */
1210
hash_table_t* zip_hash; /* hash table of buf_block_t blocks
1211
whose frames are allocated to the
1213
indexed by block->frame */
927
1214
ulint n_pend_reads; /* number of pending read operations */
1215
ulint n_pend_unzip; /* number of pending decompressions */
929
1217
time_t last_printout_time; /* when buf_print was last time
999
1280
see buf0lru.c for the restrictions
1000
1281
on this value; not defined if
1001
1282
LRU_old == NULL */
1002
UT_LIST_BASE_NODE_T(buf_block_t) awe_LRU_free_mapped;
1003
/* list of those blocks which are
1004
in the LRU list or the free list, and
1005
where the page is mapped to a frame;
1006
thus, frames allocated, e.g., to the
1007
locki table, are not in this list */
1284
UT_LIST_BASE_NODE_T(buf_block_t) unzip_LRU;
1285
/* base node of the unzip_LRU list */
1287
/* 4. Fields for the buddy allocator of compressed pages */
1288
UT_LIST_BASE_NODE_T(buf_page_t) zip_clean;
1289
/* unmodified compressed pages */
1290
UT_LIST_BASE_NODE_T(buf_page_t) zip_free[BUF_BUDDY_SIZES];
1291
/* buddy free lists */
1292
#if BUF_BUDDY_HIGH != UNIV_PAGE_SIZE
1293
# error "BUF_BUDDY_HIGH != UNIV_PAGE_SIZE"
1295
#if BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE
1296
# error "BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE"
1010
/* States of a control block */
1011
#define BUF_BLOCK_NOT_USED 211 /* is in the free list */
1012
#define BUF_BLOCK_READY_FOR_USE 212 /* when buf_get_free_block returns
1013
a block, it is in this state */
1014
#define BUF_BLOCK_FILE_PAGE 213 /* contains a buffered file page */
1015
#define BUF_BLOCK_MEMORY 214 /* contains some main memory object */
1016
#define BUF_BLOCK_REMOVE_HASH 215 /* hash index should be removed
1017
before putting to the free list */
1019
/* Io_fix states of a control block; these must be != 0 */
1020
#define BUF_IO_READ 561
1021
#define BUF_IO_WRITE 562
1300
/* mutex protecting the buffer pool struct and control blocks, except the
1301
read-write lock in them */
1302
extern mutex_t buf_pool_mutex;
1303
/* mutex protecting the control blocks of compressed-only pages
1304
(of type buf_page_t, not buf_block_t) */
1305
extern mutex_t buf_pool_zip_mutex;
1307
/* Accessors for buf_pool_mutex. Use these instead of accessing
1308
buf_pool_mutex directly. */
1310
/* Test if buf_pool_mutex is owned. */
1311
#define buf_pool_mutex_own() mutex_own(&buf_pool_mutex)
1312
/* Acquire the buffer pool mutex. */
1313
#define buf_pool_mutex_enter() do { \
1314
ut_ad(!mutex_own(&buf_pool_zip_mutex)); \
1315
mutex_enter(&buf_pool_mutex); \
1318
#if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1319
/** Flag to forbid the release of the buffer pool mutex.
1320
Protected by buf_pool_mutex. */
1321
extern ulint buf_pool_mutex_exit_forbidden;
1322
/* Forbid the release of the buffer pool mutex. */
1323
# define buf_pool_mutex_exit_forbid() do { \
1324
ut_ad(buf_pool_mutex_own()); \
1325
buf_pool_mutex_exit_forbidden++; \
1327
/* Allow the release of the buffer pool mutex. */
1328
# define buf_pool_mutex_exit_allow() do { \
1329
ut_ad(buf_pool_mutex_own()); \
1330
ut_a(buf_pool_mutex_exit_forbidden); \
1331
buf_pool_mutex_exit_forbidden--; \
1333
/* Release the buffer pool mutex. */
1334
# define buf_pool_mutex_exit() do { \
1335
ut_a(!buf_pool_mutex_exit_forbidden); \
1336
mutex_exit(&buf_pool_mutex); \
1339
/* Forbid the release of the buffer pool mutex. */
1340
# define buf_pool_mutex_exit_forbid() ((void) 0)
1341
/* Allow the release of the buffer pool mutex. */
1342
# define buf_pool_mutex_exit_allow() ((void) 0)
1343
/* Release the buffer pool mutex. */
1344
# define buf_pool_mutex_exit() mutex_exit(&buf_pool_mutex)
1023
1347
/************************************************************************
1024
1348
Let us list the consistency conditions for different control block states.