55
61
prints info whenever read or flush
57
63
#endif /* UNIV_DEBUG */
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 */
64
extern ulint srv_buf_pool_write_requests; /* variable to count write request
79
67
/************************************************************************
80
68
Creates the buffer pool. */
85
73
/* out, own: buf_pool object, NULL if not
86
74
enough memory or error */
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
/*=================*/
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
114
85
/*************************************************************************
115
Gets the current size of buffer buf_pool in bytes. */
86
Gets the current size of buffer buf_pool in bytes. In the case of AWE, the
87
size of AWE window (= the frames). */
118
90
buf_pool_get_curr_size(void);
119
91
/*========================*/
120
92
/* 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 */
121
101
/************************************************************************
122
102
Gets the smallest oldest_modification lsn for any page in the pool. Returns
123
zero if all modified pages have been flushed to disk. */
103
ut_dulint_zero if all modified pages have been flushed to disk. */
126
106
buf_pool_get_oldest_modification(void);
127
107
/*==================================*/
128
108
/* out: oldest modification in pool,
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. */
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. */
146
buf_block_t* block); /* in, own: block to be freed */
123
buf_frame_t* frame); /* in: buffer frame */
147
124
/*************************************************************************
148
125
Copies contents of a buffer frame to a given buffer. */
154
byte* buf, /* in: buffer to copy to */
155
const buf_frame_t* frame); /* in: buffer frame */
131
byte* buf, /* in: buffer to copy to */
132
buf_frame_t* frame); /* in: buffer frame */
156
133
/******************************************************************
157
134
NOTE! The following macros should be used instead of buf_page_get_gen,
158
135
to improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed
160
#define buf_page_get(SP, ZS, OF, LA, MTR) buf_page_get_gen(\
161
SP, ZS, OF, LA, NULL,\
137
#define buf_page_get(SP, OF, LA, MTR) buf_page_get_gen(\
162
139
BUF_GET, __FILE__, __LINE__, MTR)
163
140
/******************************************************************
164
141
Use these macros to bufferfix a page with no latching. Remember not to
166
143
the contents of the page! We have separated this case, because it is
167
144
error-prone programming not to set a latch, and it should be used
169
#define buf_page_get_with_no_latch(SP, ZS, OF, MTR) buf_page_get_gen(\
170
SP, ZS, OF, RW_NO_LATCH, NULL,\
146
#define buf_page_get_with_no_latch(SP, OF, MTR) buf_page_get_gen(\
147
SP, OF, RW_NO_LATCH, NULL,\
171
148
BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)
172
149
/******************************************************************
173
150
NOTE! The following macros should be used instead of buf_page_get_gen, to
174
151
improve debugging. Only values RW_S_LATCH and RW_X_LATCH are allowed as LA! */
175
#define buf_page_get_nowait(SP, ZS, OF, LA, MTR) buf_page_get_gen(\
176
SP, ZS, OF, LA, NULL,\
152
#define buf_page_get_nowait(SP, OF, LA, MTR) buf_page_get_gen(\
177
154
BUF_GET_NOWAIT, __FILE__, __LINE__, MTR)
178
155
/******************************************************************
179
156
NOTE! The following macros should be used instead of
180
157
buf_page_optimistic_get_func, to improve debugging. Only values RW_S_LATCH and
181
158
RW_X_LATCH are allowed as LA! */
182
#define buf_page_optimistic_get(LA, BL, MC, MTR) \
183
buf_page_optimistic_get_func(LA, BL, MC, __FILE__, __LINE__, MTR)
159
#define buf_page_optimistic_get(LA, BL, G, MC, MTR) \
160
buf_page_optimistic_get_func(LA, BL, G, MC, __FILE__, __LINE__, MTR)
184
161
/************************************************************************
185
162
This is the general function used to get optimistic access to a database
189
166
buf_page_optimistic_get_func(
190
167
/*=========================*/
191
168
/* out: TRUE if success */
192
169
ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
193
170
buf_block_t* block, /* in: guessed block */
194
ib_uint64_t modify_clock,/* in: modify clock value if mode is
171
buf_frame_t* guess, /* in: guessed frame; note that AWE may move
173
dulint modify_clock,/* in: modify clock value if mode is
195
174
..._GUESS_ON_CLOCK */
196
175
const char* file, /* in: file name */
197
176
ulint line, /* in: line where called */
198
177
mtr_t* mtr); /* in: mini-transaction */
199
178
/************************************************************************
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
/************************************************************************
200
198
This is used to get access to a known database page, when no waiting can be
204
202
buf_page_get_known_nowait(
205
203
/*======================*/
206
204
/* out: TRUE if success */
207
205
ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH */
208
buf_block_t* block, /* in: the known page */
206
buf_frame_t* guess, /* in: the known page frame */
209
207
ulint mode, /* in: BUF_MAKE_YOUNG or BUF_KEEP_OLD */
210
208
const char* file, /* in: file name */
211
209
ulint line, /* in: line where called */
212
210
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 */
248
211
/************************************************************************
249
212
This is the general function used to get access to a database page. */
252
215
buf_page_get_gen(
253
216
/*=============*/
254
/* out: pointer to the block or NULL */
217
/* out: pointer to the frame or NULL */
255
218
ulint space, /* in: space id */
256
ulint zip_size,/* in: compressed page size in bytes
257
or 0 for uncompressed pages */
258
219
ulint offset, /* in: page number */
259
220
ulint rw_latch,/* in: RW_S_LATCH, RW_X_LATCH, RW_NO_LATCH */
260
buf_block_t* guess, /* in: guessed block or NULL */
221
buf_frame_t* guess, /* in: guessed frame or NULL */
261
222
ulint mode, /* in: BUF_GET, BUF_GET_IF_IN_POOL,
262
223
BUF_GET_NO_LATCH */
263
224
const char* file, /* in: file name */
267
228
Initializes a page to the buffer buf_pool. The page is usually not read
268
229
from a file even if it cannot be found in the buffer buf_pool. This is one
269
230
of the functions which perform to a block a state transition NOT_USED =>
270
FILE_PAGE (the other is buf_page_get_gen). */
231
FILE_PAGE (the other is buf_page_init_for_read above). */
275
/* out: pointer to the block, page bufferfixed */
236
/* out: pointer to the frame, page bufferfixed */
276
237
ulint space, /* in: space id */
277
238
ulint offset, /* in: offset of the page within space in units of
279
ulint zip_size,/* in: compressed page size, or 0 */
280
240
mtr_t* mtr); /* in: mini-transaction handle */
281
#ifdef UNIV_HOTBACKUP
282
241
/************************************************************************
283
242
Inits a page to the buffer buf_pool, for use in ibbackup --restore. */
286
245
buf_page_init_for_backup_restore(
287
246
/*=============================*/
288
247
ulint space, /* in: space id */
289
248
ulint offset, /* in: offset of the page within space
290
249
in units of a page */
291
ulint zip_size,/* in: compressed page size in bytes
292
or 0 for uncompressed pages */
293
250
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 */
302
251
/************************************************************************
303
252
Decrements the bufferfix count of a buffer control block and releases
304
253
a latch, if specified. */
332
281
ulint space, /* in: space id */
333
282
ulint offset);/* in: page number */
334
283
/************************************************************************
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
/************************************************************************
335
297
Resets the check_index_page_at_flush field of a page if found in the buffer
339
301
buf_reset_check_index_page_at_flush(
340
302
/*================================*/
341
303
ulint space, /* in: space id */
342
304
ulint offset);/* in: page number */
343
#ifdef UNIV_DEBUG_FILE_ACCESSES
344
305
/************************************************************************
345
306
Sets file_page_was_freed TRUE if the page is found in the buffer pool.
346
307
This function should be called when we free a file page and want the
347
308
debug version to check that it is not accessed any more unless
351
312
buf_page_set_file_page_was_freed(
352
313
/*=============================*/
353
/* out: control block if found in page hash table,
314
/* out: control block if found from page hash table,
354
315
otherwise NULL */
355
316
ulint space, /* in: space id */
356
ulint offset);/* in: page number */
317
ulint offset); /* in: page number */
357
318
/************************************************************************
358
319
Sets file_page_was_freed FALSE if the page is found in the buffer pool.
359
320
This function should be called when we free a file page and want the
360
321
debug version to check that it is not accessed any more unless
364
325
buf_page_reset_file_page_was_freed(
365
326
/*===============================*/
366
/* out: control block if found in page hash table,
327
/* out: control block if found from page hash table,
367
328
otherwise NULL */
368
329
ulint space, /* in: space id */
369
330
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));
390
331
/************************************************************************
391
332
Recommends a move of a block to the start of the LRU list if there is danger
392
333
of dropping from the buffer pool. NOTE: does not reserve the buffer pool
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 */
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 */
401
341
/************************************************************************
402
342
Returns the current state of is_hashed of a page. FALSE if the page is
403
343
not in the pool. NOTE that this operation does not fix the page in the
404
344
pool if it is found there. */
407
347
buf_page_peek_if_search_hashed(
408
348
/*===========================*/
414
354
Gets the youngest modification log sequence number for a frame.
415
355
Returns zero if not file page or no modification occurred yet. */
418
buf_page_get_newest_modification(
419
/*=============================*/
420
/* out: newest modification to page */
421
const buf_page_t* bpage); /* in: block containing the
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 */
423
372
/************************************************************************
424
373
Increments the modify clock of a frame by 1. The caller must (1) own the
425
374
buf_pool mutex and block bufferfix count has to be zero, (2) or own an x-lock
429
378
buf_block_modify_clock_inc(
430
379
/*=======================*/
431
381
buf_block_t* block); /* in: block */
432
382
/************************************************************************
433
383
Returns the value of the modify clock. The caller must have an s-lock
434
384
or x-lock on the block. */
437
387
buf_block_get_modify_clock(
438
388
/*=======================*/
479
445
buf_ptr_get_fsp_addr(
480
446
/*=================*/
481
const void* ptr, /* in: pointer to a buffer frame */
447
byte* ptr, /* in: pointer to a buffer frame */
482
448
ulint* space, /* out: space id */
483
449
fil_addr_t* addr); /* out: page offset and byte offset */
484
450
/**************************************************************************
485
Gets the hash value of a block. This can be used in searches in the
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. */
489
buf_block_get_lock_hash_val(
455
buf_frame_get_lock_hash_val(
490
456
/*========================*/
491
/* out: lock hash value */
492
const buf_block_t* block) /* in: block */
493
__attribute__((pure));
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 */
494
485
#ifdef UNIV_DEBUG
495
486
/*************************************************************************
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
/*************************************************************************
508
487
Validates the buffer pool data structure. */
511
490
buf_validate(void);
512
491
/*==============*/
513
#endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
514
#if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
515
492
/*************************************************************************
516
493
Prints info of the buffer pool data structure. */
521
#endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
498
#endif /* UNIV_DEBUG */
522
499
/************************************************************************
523
500
Prints a page to stderr. */
528
const byte* read_buf, /* in: a database page */
529
ulint zip_size); /* in: compressed page size, or
530
0 for uncompressed pages */
505
byte* read_buf); /* in: a database page */
531
506
/*************************************************************************
532
507
Returns the number of latched pages in the buffer pool. */
535
510
buf_get_latched_pages_number(void);
536
511
/*==============================*/
537
512
/*************************************************************************
538
513
Returns the number of pending buf pool ios. */
541
516
buf_get_n_pending_ios(void);
542
517
/*=======================*/
543
518
/*************************************************************************
544
519
Prints info of the buffer i/o. */
594
582
page if we know the latching order level of the acquired latch. */
597
buf_block_dbg_add_level(
598
/*====================*/
599
buf_block_t* block, /* in: buffer page
600
where we have acquired latch */
585
buf_page_dbg_add_level(
586
/*===================*/
587
buf_frame_t* frame, /* in: buffer page where we have acquired
601
589
ulint level); /* in: latching order level */
602
590
#endif /* UNIV_SYNC_DEBUG */
603
591
/*************************************************************************
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
/*************************************************************************
793
592
Gets a pointer to the memory frame of a block. */
796
595
buf_block_get_frame(
797
596
/*================*/
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));
597
/* out: pointer to the frame */
598
buf_block_t* block); /* in: pointer to the control block */
813
599
/*************************************************************************
814
600
Gets the space id of a block. */
817
603
buf_block_get_space(
818
604
/*================*/
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));
606
buf_block_t* block); /* in: pointer to the control block */
831
607
/*************************************************************************
832
608
Gets the page number of a block. */
835
611
buf_block_get_page_no(
836
612
/*==================*/
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
613
/* out: page number */
614
buf_block_t* block); /* in: pointer to the control block */
864
615
/***********************************************************************
865
616
Gets the block to whose frame the pointer is pointing to. */
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 */
621
/* out: pointer to block */
622
byte* ptr); /* in: pointer to a frame */
882
623
/************************************************************************
883
624
This function is used to get info if there is an io operation
884
625
going on on a buffer page. */
896
646
then this function does nothing.
897
647
Sets the io_fix flag to BUF_IO_READ and sets a non-recursive exclusive lock
898
648
on the buffer frame. The io-handler must take care that the flag is cleared
899
and the lock released later. */
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
902
654
buf_page_init_for_read(
903
655
/*===================*/
904
656
/* out: pointer to the block or NULL */
905
657
ulint* err, /* out: DB_SUCCESS or DB_TABLESPACE_DELETED */
906
658
ulint mode, /* in: BUF_READ_IBUF_PAGES_ONLY, ... */
907
659
ulint space, /* in: space id */
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
660
ib_longlong tablespace_version,/* in: prevents reading from a wrong
911
661
version of the tablespace in case we have done
912
662
DISCARD + IMPORT */
913
663
ulint offset);/* in: page number */
914
664
/************************************************************************
915
665
Completes an asynchronous read or write request of a file page to or from
916
666
the buffer pool. */
919
669
buf_page_io_complete(
920
670
/*=================*/
921
buf_page_t* bpage); /* in: pointer to the block in question */
671
buf_block_t* block); /* in: pointer to the block in question */
922
672
/************************************************************************
923
673
Calculates a folded value of a file page address to use in the page hash
959
698
/* out: new clock value */
960
699
/*************************************************************************
961
700
Gets the current length of the free list of buffer blocks. */
964
703
buf_get_free_list_len(void);
965
704
/*=======================*/
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 */
1080
708
/* The buffer control block structure */
1082
710
struct buf_block_struct{
1084
712
/* 1. General fields */
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 */
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 */
1100
720
byte* frame; /* pointer to buffer frame which
1101
721
is of size UNIV_PAGE_SIZE, and
1102
722
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 */
1104
737
mutex_t mutex; /* mutex protecting this block:
1105
738
state (also protected by the buffer
1106
739
pool mutex), io_fix, buf_fix_count,
1119
752
buffer pool which are index pages,
1120
753
but this flag is not set because
1121
754
we do not keep track of all pages */
1123
/* 2. Optimistic search field */
1125
ib_uint64_t modify_clock; /* this clock is incremented every
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
1126
822
time a pointer to a record on the
1127
823
page may become obsolete; this is
1128
824
used in the optimistic cursor
1156
852
An exception to this is when we init or create a page
1157
853
in the buffer pool in buf0buf.c. */
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
855
ibool is_hashed; /* TRUE if hash index has already been
1165
856
built on this page; note that it does
1166
857
not guarantee that the index is
1167
858
complete, though: there may have been
1168
859
hash collisions, record deletions,
1170
unsigned curr_n_fields:10;/* prefix length for hash indexing:
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:
1171
865
number of full fields */
1172
unsigned curr_n_bytes:15;/* number of bytes in hash indexing */
1173
unsigned curr_left_side:1;/* TRUE or FALSE in hash indexing */
866
ulint curr_n_bytes; /* number of bytes in hash indexing */
867
ibool curr_left_side; /* TRUE or FALSE in hash indexing */
1174
868
dict_index_t* index; /* Index for which the adaptive
1175
869
hash index has been created. */
1176
/* 4. Debug fields */
870
/* 6. Debug fields */
1177
871
#ifdef UNIV_SYNC_DEBUG
1178
872
rw_lock_t debug_latch; /* in the debug version, each thread
1179
873
which bufferfixes the block acquires
1180
874
an s-latch here; so we can use the
1181
875
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 */
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))
882
#define BUF_BLOCK_MAGIC_N 41526563
1196
884
/* The buffer pool structure. NOTE! The definition appears here only for
1197
885
other modules of this directory (buf) to see it. Do not use from outside! */
1201
889
/* 1. General fields */
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 */
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 */
1214
927
ulint n_pend_reads; /* number of pending read operations */
1215
ulint n_pend_unzip; /* number of pending decompressions */
1217
929
time_t last_printout_time; /* when buf_print was last time
1280
999
see buf0lru.c for the restrictions
1281
1000
on this value; not defined if
1282
1001
LRU_old == NULL */
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"
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 */
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)
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
1347
1023
/************************************************************************
1348
1024
Let us list the consistency conditions for different control block states.