MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
buf0buf.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #ifndef buf0buf_h
27 #define buf0buf_h
28 
29 #include "univ.i"
30 #include "fil0fil.h"
31 #include "mtr0types.h"
32 #include "buf0types.h"
33 #include "hash0hash.h"
34 #include "ut0byte.h"
35 #include "page0types.h"
36 #ifndef UNIV_HOTBACKUP
37 #include "ut0rbt.h"
38 #include "os0proc.h"
39 #include "log0log.h"
40 
42 /* @{ */
43 #define BUF_GET 10
44 #define BUF_GET_IF_IN_POOL 11
45 #define BUF_PEEK_IF_IN_POOL 12
47 #define BUF_GET_NO_LATCH 14
53 #define BUF_GET_IF_IN_POOL_OR_WATCH 15
54 
57 #define BUF_GET_POSSIBLY_FREED 16
58 
60 /* @} */
62 /* @{ */
63 #define BUF_MAKE_YOUNG 51
68 #define BUF_KEEP_OLD 52
70 /* @} */
71 
72 #define MAX_BUFFER_POOLS_BITS 6
75 #define MAX_BUFFER_POOLS (1 << MAX_BUFFER_POOLS_BITS)
76 
79 #define BUF_POOL_WATCH_SIZE (srv_n_purge_threads + 1)
80 
82 #define MAX_PAGE_HASH_LOCKS 1024
85 extern buf_pool_t* buf_pool_ptr;
87 #ifdef UNIV_DEBUG
88 extern ibool buf_debug_prints;
91 #endif /* UNIV_DEBUG */
92 extern ulint srv_buf_pool_instances;
93 extern ulint srv_buf_pool_curr_size;
94 #else /* !UNIV_HOTBACKUP */
95 extern buf_block_t* back_block1;
96 extern buf_block_t* back_block2;
97 #endif /* !UNIV_HOTBACKUP */
98 
100 #define BUF_NO_CHECKSUM_MAGIC 0xDEADBEEFUL
101 
126 };
127 
128 
132  /* General buffer pool info */
134  ulint pool_size;
135  ulint lru_len;
136  ulint old_lru_len;
139  ulint n_pend_unzip;
141  ulint n_pend_reads;
152  ulint n_pages_read;
155  ulint n_page_gets;
166  /* Buffer pool access stats */
181  /* Statistics about read ahead algorithm. */
189  /* Stats about LRU eviction */
192  /* Counters for LRU policy */
193  ulint io_sum;
194  ulint io_cur;
196  ulint unzip_sum;
197  ulint unzip_cur;
200 };
201 
204  ulint LRU_bytes;
207 };
208 
209 #ifndef UNIV_HOTBACKUP
210 /********************************************************************/
212 UNIV_INLINE
213 void
215 /*===========================*/
216 
217 /********************************************************************/
219 UNIV_INLINE
220 void
222 /*==========================*/
223 
224 /********************************************************************/
227 UNIV_INTERN
228 dberr_t
230 /*=========*/
231  ulint size,
232  ulint n_instances);
233 /********************************************************************/
236 UNIV_INTERN
237 void
239 /*==========*/
240  ulint n_instances);
242 /********************************************************************/
244 UNIV_INTERN
245 void
247 /*===========================*/
248 
249 /********************************************************************/
253 UNIV_INTERN
254 void
256 /*=========*/
257  buf_page_t* bpage,
260  buf_page_t* dpage)
261  __attribute__((nonnull));
262 /*********************************************************************/
265 UNIV_INLINE
266 ulint
268 /*========================*/
269 /*********************************************************************/
272 UNIV_INLINE
273 ulint
275 /*=======================*/
276 /********************************************************************/
280 UNIV_INTERN
281 lsn_t
283 /*==================================*/
284 
285 /********************************************************************/
288 UNIV_INLINE
289 buf_page_t*
291 /*===========================*/
292  __attribute__((malloc));
293 /********************************************************************/
295 UNIV_INLINE
296 void
298 /*=====================*/
299  buf_page_t* bpage)
300  __attribute__((nonnull));
301 
302 /********************************************************************/
305 UNIV_INTERN
308 /*============*/
309  buf_pool_t* buf_pool);
312 /********************************************************************/
314 UNIV_INLINE
315 void
317 /*===========*/
318  buf_block_t* block);
319 #endif /* !UNIV_HOTBACKUP */
320 /*********************************************************************/
323 UNIV_INLINE
324 byte*
326 /*===========*/
327  byte* buf,
328  const buf_frame_t* frame);
329 #ifndef UNIV_HOTBACKUP
330 /**************************************************************/
334 #define buf_page_get(SP, ZS, OF, LA, MTR) buf_page_get_gen(\
335  SP, ZS, OF, LA, NULL,\
336  BUF_GET, __FILE__, __LINE__, MTR)
337 /**************************************************************/
343 #define buf_page_get_with_no_latch(SP, ZS, OF, MTR) buf_page_get_gen(\
344  SP, ZS, OF, RW_NO_LATCH, NULL,\
345  BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)
346 /********************************************************************/
350 UNIV_INTERN
351 ibool
353 /*====================*/
354  ulint rw_latch,
355  buf_block_t* block,
356  ib_uint64_t modify_clock,
357  const char* file,
358  ulint line,
359  mtr_t* mtr);
360 /********************************************************************/
364 UNIV_INTERN
365 ibool
367 /*======================*/
368  ulint rw_latch,
369  buf_block_t* block,
370  ulint mode,
371  const char* file,
372  ulint line,
373  mtr_t* mtr);
375 /*******************************************************************/
379 UNIV_INTERN
380 const buf_block_t*
382 /*==================*/
383  ulint space_id,
384  ulint page_no,
385  const char* file,
386  ulint line,
387  mtr_t* mtr);
395 #define buf_page_try_get(space_id, page_no, mtr) \
396  buf_page_try_get_func(space_id, page_no, __FILE__, __LINE__, mtr);
397 
398 /********************************************************************/
407 UNIV_INTERN
408 buf_page_t*
410 /*=============*/
411  ulint space,
412  ulint zip_size,
413  ulint offset);
414 /********************************************************************/
417 UNIV_INTERN
420 /*=============*/
421  ulint space,
422  ulint zip_size,
424  ulint offset,
425  ulint rw_latch,
426  buf_block_t* guess,
427  ulint mode,
430  const char* file,
431  ulint line,
432  mtr_t* mtr);
433 /********************************************************************/
439 UNIV_INTERN
442 /*============*/
443  ulint space,
444  ulint offset,
446  ulint zip_size,
447  mtr_t* mtr);
448 #else /* !UNIV_HOTBACKUP */
449 /********************************************************************/
451 UNIV_INTERN
452 void
453 buf_page_init_for_backup_restore(
454 /*=============================*/
455  ulint space,
456  ulint offset,
458  ulint zip_size,
460  buf_block_t* block);
461 #endif /* !UNIV_HOTBACKUP */
462 
463 #ifndef UNIV_HOTBACKUP
464 /********************************************************************/
466 UNIV_INLINE
467 void
469 /*=================*/
470  buf_page_t* bpage);
471 /********************************************************************/
474 UNIV_INLINE
475 void
477 /*=============*/
478  buf_block_t* block,
479  ulint rw_latch);
481 /********************************************************************/
485 UNIV_INTERN
486 void
488 /*================*/
489  buf_page_t* bpage);
490 /********************************************************************/
497 UNIV_INLINE
498 ibool
500 /*==========*/
501  ulint space,
502  ulint offset);
503 #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
504 /********************************************************************/
510 UNIV_INTERN
511 buf_page_t*
512 buf_page_set_file_page_was_freed(
513 /*=============================*/
514  ulint space,
515  ulint offset);
516 /********************************************************************/
522 UNIV_INTERN
523 buf_page_t*
524 buf_page_reset_file_page_was_freed(
525 /*===============================*/
526  ulint space,
527  ulint offset);
528 #endif /* UNIV_DEBUG_FILE_ACCESSES || UNIV_DEBUG */
529 /********************************************************************/
532 UNIV_INLINE
533 ulint
535 /*==========================*/
536  const buf_page_t* bpage)
537  __attribute__((pure));
538 /********************************************************************/
541 UNIV_INLINE
542 ulint
544 /*===========================*/
545  const buf_block_t* block)
546  __attribute__((pure));
547 
548 /********************************************************************/
555 UNIV_INLINE
556 ibool
558 /*===================*/
559  const buf_page_t* bpage);
560 /********************************************************************/
565 UNIV_INLINE
566 ibool
568 /*=====================*/
569  const buf_page_t* bpage);
570 /********************************************************************/
574 UNIV_INLINE
575 lsn_t
577 /*=============================*/
578  const buf_page_t* bpage);
580 /********************************************************************/
584 UNIV_INLINE
585 void
587 /*=======================*/
588  buf_block_t* block);
589 /********************************************************************/
593 UNIV_INLINE
594 ib_uint64_t
596 /*=======================*/
597  buf_block_t* block);
598 /*******************************************************************/
600 UNIV_INLINE
601 void
603 /*=======================*/
604 # ifdef UNIV_SYNC_DEBUG
605  const char* file,
606  ulint line,
607 # endif /* UNIV_SYNC_DEBUG */
608  buf_block_t* block)
609  __attribute__((nonnull));
610 # ifdef UNIV_SYNC_DEBUG
611 
615 # define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(f,l,b)
616 # else /* UNIV_SYNC_DEBUG */
617 
621 # define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(b)
622 # endif /* UNIV_SYNC_DEBUG */
623 #else /* !UNIV_HOTBACKUP */
624 # define buf_block_modify_clock_inc(block) ((void) 0)
625 #endif /* !UNIV_HOTBACKUP */
626 /********************************************************************/
629 UNIV_INTERN
630 ibool
632 /*==================*/
633  bool check_lsn,
635  const byte* read_buf,
636  ulint zip_size)
638  __attribute__((nonnull, warn_unused_result));
639 #ifndef UNIV_HOTBACKUP
640 /**********************************************************************/
643 UNIV_INLINE
644 void
646 /*=================*/
647  const void* ptr,
648  ulint* space,
649  fil_addr_t* addr);
650 /**********************************************************************/
654 UNIV_INLINE
655 ulint
657 /*========================*/
658  const buf_block_t* block)
659  __attribute__((pure));
660 #ifdef UNIV_DEBUG
661 /*********************************************************************/
665 UNIV_INTERN
667 buf_pool_contains_zip(
668 /*==================*/
669  buf_pool_t* buf_pool,
670  const void* data);
671 #endif /* UNIV_DEBUG */
672 
673 /***********************************************************************
674 FIXME_FTS: Gets the frame the pointer is pointing to. */
675 UNIV_INLINE
677 buf_frame_align(
678 /*============*/
679  /* out: pointer to frame */
680  byte* ptr); /* in: pointer to a frame */
681 
682 
683 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
684 /*********************************************************************/
687 UNIV_INTERN
688 ibool
689 buf_validate(void);
690 /*==============*/
691 #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
692 #if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
693 /*********************************************************************/
695 UNIV_INTERN
696 void
697 buf_print(void);
698 /*============*/
699 #endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
700 #endif /* !UNIV_HOTBACKUP */
706 };
707 
708 /********************************************************************/
710 UNIV_INTERN
711 void
713 /*===========*/
714  const byte* read_buf,
715  ulint zip_size,
717  ulint flags)
720  UNIV_COLD __attribute__((nonnull));
721 /********************************************************************/
724 UNIV_INTERN
725 ibool
727 /*===============*/
728  buf_block_t* block,
729  ibool check);
730 #ifndef UNIV_HOTBACKUP
731 #ifdef UNIV_DEBUG
732 /*********************************************************************/
735 UNIV_INTERN
736 ulint
737 buf_get_latched_pages_number(void);
738 /*==============================*/
739 #endif /* UNIV_DEBUG */
740 /*********************************************************************/
743 UNIV_INTERN
744 ulint
746 /*============================*/
747 /*********************************************************************/
749 UNIV_INTERN
750 void
752 /*=========*/
753  FILE* file);
754 /*******************************************************************/
758 UNIV_INTERN
759 void
761 /*====================*/
762  buf_pool_t* buf_pool,
763  ulint pool_id,
764  buf_pool_info_t* all_pool_info);
766 /*********************************************************************/
770 UNIV_INTERN
771 ulint
773 /*============================*/
774 /**********************************************************************/
776 UNIV_INTERN
777 void
779 /*=================*/
780  buf_pool_t* buf_pool);
781 /**********************************************************************/
783 UNIV_INTERN
784 void
786 /*=================*/
787 /*********************************************************************/
790 UNIV_INTERN
791 ibool
792 buf_all_freed(void);
793 /*===============*/
794 /*********************************************************************/
798 UNIV_INTERN
799 ulint
801 /*==============================*/
802 /*********************************************************************/
806 UNIV_INTERN
807 void
808 buf_pool_invalidate(void);
809 /*=====================*/
810 #endif /* !UNIV_HOTBACKUP */
811 
812 /*========================================================================
813 --------------------------- LOWER LEVEL ROUTINES -------------------------
814 =========================================================================*/
815 
816 #ifdef UNIV_SYNC_DEBUG
817 /*********************************************************************/
821 UNIV_INLINE
822 void
823 buf_block_dbg_add_level(
824 /*====================*/
825  buf_block_t* block,
827  ulint level);
828 #else /* UNIV_SYNC_DEBUG */
829 # define buf_block_dbg_add_level(block, level) /* nothing */
830 #endif /* UNIV_SYNC_DEBUG */
831 /*********************************************************************/
834 UNIV_INLINE
835 enum buf_page_state
837 /*===============*/
838  const buf_page_t* bpage);
839 /*********************************************************************/
842 UNIV_INLINE
843 enum buf_page_state
845 /*================*/
846  const buf_block_t* block)
847  __attribute__((pure));
848 /*********************************************************************/
850 UNIV_INLINE
851 void
853 /*===============*/
854  buf_page_t* bpage,
855  enum buf_page_state state);
856 /*********************************************************************/
858 UNIV_INLINE
859 void
861 /*================*/
862  buf_block_t* block,
863  enum buf_page_state state);
864 /*********************************************************************/
867 UNIV_INLINE
868 ibool
870 /*=============*/
871  const buf_page_t* bpage)
872  __attribute__((pure));
873 #ifndef UNIV_HOTBACKUP
874 /*********************************************************************/
877 UNIV_INLINE
878 ibool
880 /*==========================*/
881  const buf_page_t* bpage)
882  __attribute__((pure));
883 
884 /*********************************************************************/
887 UNIV_INLINE
888 ib_mutex_t*
890 /*===============*/
891  const buf_page_t* bpage)
892  __attribute__((pure));
893 
894 /*********************************************************************/
897 UNIV_INLINE
900 /*====================*/
901  const buf_page_t* bpage)
902  __attribute__((pure));
903 /*********************************************************************/
905 UNIV_INLINE
906 void
908 /*====================*/
909  buf_page_t* bpage,
910  buf_flush_t flush_type);
911 /*********************************************************************/
913 UNIV_INLINE
914 void
916 /*====================*/
917  buf_block_t* block,
918  ulint space,
919  ulint page_no);
920 /*********************************************************************/
923 UNIV_INLINE
924 enum buf_io_fix
926 /*================*/
927  const buf_page_t* bpage)
928  __attribute__((pure));
929 /*********************************************************************/
932 UNIV_INLINE
933 enum buf_io_fix
935 /*================*/
936  const buf_block_t* block)
937  __attribute__((pure));
938 /*********************************************************************/
940 UNIV_INLINE
941 void
943 /*================*/
944  buf_page_t* bpage,
945  enum buf_io_fix io_fix);
946 /*********************************************************************/
948 UNIV_INLINE
949 void
951 /*=================*/
952  buf_block_t* block,
953  enum buf_io_fix io_fix);
954 /*********************************************************************/
963 UNIV_INLINE
964 void
966 /*================*/
967  buf_page_t* bpage);
968 /*********************************************************************/
970 UNIV_INLINE
971 void
973 /*==================*/
974  buf_page_t* bpage);
975 /********************************************************************/
978 UNIV_INLINE
979 ibool
981 /*==================*/
982  const buf_page_t* bpage)
983  __attribute__((pure));
984 
985 /*********************************************************************/
988 UNIV_INLINE
989 ibool
991 /*============*/
992  const buf_page_t* bpage)
993  __attribute__((pure));
994 /*********************************************************************/
996 UNIV_INLINE
997 void
999 /*=============*/
1000  buf_page_t* bpage,
1001  ibool old);
1002 /*********************************************************************/
1005 UNIV_INLINE
1006 unsigned
1008 /*=================*/
1009  const buf_page_t* bpage)
1010  __attribute__((nonnull, pure));
1011 /*********************************************************************/
1013 UNIV_INLINE
1014 void
1016 /*==================*/
1017  buf_page_t* bpage)
1018  __attribute__((nonnull));
1019 /*********************************************************************/
1024 UNIV_INLINE
1025 buf_block_t*
1027 /*===============*/
1028  buf_page_t* bpage)
1029  __attribute__((pure));
1030 #endif /* !UNIV_HOTBACKUP */
1031 #ifdef UNIV_DEBUG
1032 /*********************************************************************/
1035 UNIV_INLINE
1036 buf_frame_t*
1037 buf_block_get_frame(
1038 /*================*/
1039  const buf_block_t* block)
1040  __attribute__((pure));
1041 #else /* UNIV_DEBUG */
1042 # define buf_block_get_frame(block) (block)->frame
1043 #endif /* UNIV_DEBUG */
1044 /*********************************************************************/
1047 UNIV_INLINE
1048 ulint
1050 /*===============*/
1051  const buf_page_t* bpage)
1052  __attribute__((pure));
1053 /*********************************************************************/
1056 UNIV_INLINE
1057 ulint
1059 /*================*/
1060  const buf_block_t* block)
1061  __attribute__((pure));
1062 /*********************************************************************/
1065 UNIV_INLINE
1066 ulint
1068 /*=================*/
1069  const buf_page_t* bpage)
1070  __attribute__((pure));
1071 /*********************************************************************/
1074 UNIV_INLINE
1075 ulint
1077 /*==================*/
1078  const buf_block_t* block)
1079  __attribute__((pure));
1080 /*********************************************************************/
1083 UNIV_INLINE
1084 ulint
1086 /*==================*/
1087  const buf_page_t* bpage)
1088  __attribute__((pure));
1089 /*********************************************************************/
1092 UNIV_INLINE
1093 ulint
1095 /*===================*/
1096  const buf_block_t* block)
1097  __attribute__((pure));
1098 /*********************************************************************/
1101 #define buf_block_get_page_zip(block) \
1102  ((block)->page.zip.data ? &(block)->page.zip : NULL)
1103 #ifndef UNIV_HOTBACKUP
1104 /*******************************************************************/
1107 UNIV_INTERN
1108 buf_block_t*
1110 /*============*/
1111  const byte* ptr);
1112 /********************************************************************/
1116 UNIV_INTERN
1117 ibool
1119 /*=======================*/
1120  const void* ptr);
1125 #define buf_pool_is_block_mutex(m) \
1126  buf_pointer_is_block_field((const void*)(m))
1127 
1130 #define buf_pool_is_block_lock(l) \
1131  buf_pointer_is_block_field((const void*)(l))
1132 
1133 #if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
1134 /*********************************************************************/
1138 UNIV_INLINE
1139 const page_zip_des_t*
1140 buf_frame_get_page_zip(
1141 /*===================*/
1142  const byte* ptr);
1143 #endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
1144 /********************************************************************/
1154 UNIV_INTERN
1155 buf_page_t*
1157 /*===================*/
1158  dberr_t* err,
1159  ulint mode,
1160  ulint space,
1161  ulint zip_size,
1162  ibool unzip,
1163  ib_int64_t tablespace_version,
1166  ulint offset);
1167 /********************************************************************/
1171 UNIV_INTERN
1172 bool
1174 /*=================*/
1175  buf_page_t* bpage);
1176 /********************************************************************/
1180 UNIV_INLINE
1181 ulint
1183 /*==================*/
1184  ulint space,
1185  ulint offset)
1186  __attribute__((const));
1187 /********************************************************************/
1190 UNIV_INLINE
1191 ulint
1193 /*===========*/
1194  const buf_pool_t* buf_pool)
1195  __attribute__((nonnull, const));
1196 /******************************************************************/
1199 UNIV_INLINE
1200 buf_pool_t*
1202 /*================*/
1203  const buf_page_t* bpage);
1204 /******************************************************************/
1207 UNIV_INLINE
1208 buf_pool_t*
1210 /*================*/
1211  const buf_block_t* block);
1212 /******************************************************************/
1215 UNIV_INLINE
1216 buf_pool_t*
1217 buf_pool_get(
1218 /*==========*/
1219  ulint space,
1220  ulint offset);
1221 /******************************************************************/
1224 UNIV_INLINE
1225 buf_pool_t*
1227 /*================*/
1228  ulint index);
1230 /******************************************************************/
1233 UNIV_INLINE
1234 buf_page_t*
1236 /*==================*/
1237  buf_pool_t* buf_pool,
1238  ulint space,
1239  ulint offset,
1240  ulint fold);
1241 /******************************************************************/
1249 UNIV_INLINE
1250 buf_page_t*
1252 /*=====================*/
1256  buf_pool_t* buf_pool,
1257  ulint space,
1258  ulint offset,
1259  rw_lock_t** lock,
1264  ulint lock_mode);
1267 /******************************************************************/
1275 UNIV_INLINE
1276 buf_block_t*
1278 /*=====================*/
1282  buf_pool_t* buf_pool,
1283  ulint space,
1284  ulint offset,
1285  rw_lock_t** lock,
1290  ulint lock_mode);
1293 /* There are four different ways we can try to get a bpage or block
1294 from the page hash:
1295 1) Caller already holds the appropriate page hash lock: in the case call
1296 buf_page_hash_get_low() function.
1297 2) Caller wants to hold page hash lock in x-mode
1298 3) Caller wants to hold page hash lock in s-mode
1299 4) Caller doesn't want to hold page hash lock */
1300 #define buf_page_hash_get_s_locked(b, s, o, l) \
1301  buf_page_hash_get_locked(b, s, o, l, RW_LOCK_SHARED)
1302 #define buf_page_hash_get_x_locked(b, s, o, l) \
1303  buf_page_hash_get_locked(b, s, o, l, RW_LOCK_EX)
1304 #define buf_page_hash_get(b, s, o) \
1305  buf_page_hash_get_locked(b, s, o, NULL, 0)
1306 
1307 #define buf_block_hash_get_s_locked(b, s, o, l) \
1308  buf_block_hash_get_locked(b, s, o, l, RW_LOCK_SHARED)
1309 #define buf_block_hash_get_x_locked(b, s, o, l) \
1310  buf_block_hash_get_locked(b, s, o, l, RW_LOCK_EX)
1311 #define buf_block_hash_get(b, s, o) \
1312  buf_block_hash_get_locked(b, s, o, NULL, 0)
1313 
1314 /*********************************************************************/
1317 UNIV_INTERN
1318 ulint
1319 buf_get_free_list_len(void);
1320 /*=======================*/
1321 
1322 /********************************************************************/
1325 UNIV_INTERN
1326 ibool
1328 /*=======================*/
1329  buf_pool_t* buf_pool,
1330  const buf_page_t* bpage)
1331  __attribute__((nonnull, warn_unused_result));
1332 /****************************************************************/
1335 UNIV_INTERN
1336 buf_page_t*
1338 /*===============*/
1339  ulint space,
1340  ulint offset,
1341  ulint fold)
1342  __attribute__((warn_unused_result));
1343 /****************************************************************/
1346 UNIV_INTERN
1347 void
1349 /*=================*/
1350  ulint space,
1351  ulint offset);
1352 /****************************************************************/
1357 UNIV_INTERN
1358 ibool
1360 /*====================*/
1361  ulint space,
1362  ulint offset)
1363  __attribute__((warn_unused_result));
1364 /********************************************************************/
1366 UNIV_INTERN
1367 void
1369 /*===================*/
1370  ulint* LRU_len,
1371  ulint* free_len,
1372  ulint* flush_list_len);
1373 /********************************************************************/
1375 UNIV_INTERN
1376 void
1378 /*=============================*/
1379  buf_pools_list_size_t* buf_pools_list_size);
1381 /********************************************************************/
1383 UNIV_INTERN
1384 void
1386 /*===============*/
1387  buf_pool_stat_t*tot_stat);
1388 /*********************************************************************/
1391 UNIV_INLINE
1392 buf_block_t*
1394 /*====================*/
1395  const buf_pool_t* buf_pool,
1396  ulint n,
1397  ulint* chunk_size);
1399 /********************************************************************/
1401 UNIV_INTERN
1402 void
1404 /*==========================*/
1405  buf_frame_t* page,
1406  ulint zip_size,
1407  lsn_t lsn);
1409 #endif /* !UNIV_HOTBACKUP */
1410 
1415 #define BUF_PAGE_STATE_BITS 3
1416 
1417 struct buf_page_t{
1424  /* @{ */
1425 
1426  unsigned space:32;
1428  unsigned offset:32;
1431  unsigned state:BUF_PAGE_STATE_BITS;
1448 #ifndef UNIV_HOTBACKUP
1449  unsigned flush_type:2;
1453  unsigned io_fix:2;
1456  unsigned buf_fix_count:19;
1458  unsigned buf_pool_index:6;
1460 # if MAX_BUFFER_POOLS > 64
1461 # error "MAX_BUFFER_POOLS > 64; redefine buf_pool_index:6"
1462 # endif
1463  /* @} */
1464 #endif /* !UNIV_HOTBACKUP */
1471 #ifndef UNIV_HOTBACKUP
1475 #ifdef UNIV_DEBUG
1476  ibool in_page_hash;
1477  ibool in_zip_hash;
1478 #endif /* UNIV_DEBUG */
1479 
1482  /* @{ */
1483 
1484  UT_LIST_NODE_T(buf_page_t) list;
1511 #ifdef UNIV_DEBUG
1512  ibool in_flush_list;
1523  ibool in_free_list;
1527 #endif /* UNIV_DEBUG */
1528  lsn_t newest_modification;
1534  lsn_t oldest_modification;
1547  /* @} */
1551  /* @{ */
1552 
1555 #ifdef UNIV_DEBUG
1556  ibool in_LRU_list;
1559 #endif /* UNIV_DEBUG */
1560  unsigned old:1;
1562  unsigned freed_page_clock:31;
1570  /* @} */
1571  unsigned access_time;
1575 # if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
1576  ibool file_page_was_freed;
1581 # endif /* UNIV_DEBUG_FILE_ACCESSES || UNIV_DEBUG */
1582 #endif /* !UNIV_HOTBACKUP */
1583 };
1584 
1588 
1590  /* @{ */
1591 
1596  byte* frame;
1600 #ifndef UNIV_HOTBACKUP
1601  UT_LIST_NODE_T(buf_block_t) unzip_LRU;
1606 #ifdef UNIV_DEBUG
1607  ibool in_unzip_LRU_list;
1610 #endif /* UNIV_DEBUG */
1619  unsigned lock_hash_val:32;
1635  /* @} */
1637  /* @{ */
1638 
1639  ib_uint64_t modify_clock;
1650  /* @} */
1653  /* @{ */
1654 
1657  ulint n_fields;
1659  ulint n_bytes;
1661  ibool left_side;
1665  /* @} */
1666 
1679  /* @{ */
1680 
1681 #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1682  ulint n_pointers;
1685 #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1686  unsigned curr_n_fields:10;
1688  unsigned curr_n_bytes:15;
1690  unsigned curr_left_side:1;
1700  /* @} */
1701 # ifdef UNIV_SYNC_DEBUG
1702 
1703  /* @{ */
1704  rw_lock_t debug_latch;
1708  /* @} */
1709 # endif
1710 #endif /* !UNIV_HOTBACKUP */
1711 };
1712 
1716 #define buf_block_state_valid(block) \
1717 (buf_block_get_state(block) >= BUF_BLOCK_NOT_USED \
1718  && (buf_block_get_state(block) <= BUF_BLOCK_REMOVE_HASH))
1719 
1720 #ifndef UNIV_HOTBACKUP
1721 /**********************************************************************/
1723 /* @{ */
1724 #define BUF_POOL_ZIP_FOLD_PTR(ptr) ((ulint) (ptr) / UNIV_PAGE_SIZE)
1725 #define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
1726 #define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t*) (b))
1727 /* @} */
1728 
1731  union {
1732  ulint size;
1733  byte bytes[FIL_PAGE_DATA];
1742  } stamp;
1743 
1747 };
1748 
1751  ulint n_page_gets;
1759  ulint n_pages_created;
1761  ulint n_ra_pages_read_rnd;
1763  ulint n_ra_pages_read;
1765  ulint n_ra_pages_evicted;
1768  ulint n_pages_made_young;
1770  ulint n_pages_not_made_young;
1774  ulint LRU_bytes;
1776 };
1777 
1781  ulint used;
1783  ib_uint64_t relocated;
1785  ib_uint64_t relocated_usec;
1786 };
1787 
1793 struct buf_pool_t{
1794 
1796  /* @{ */
1797  ib_mutex_t mutex;
1799  ib_mutex_t zip_mutex;
1803  ulint instance_no;
1807  ulint LRU_old_ratio;
1809 #ifdef UNIV_DEBUG
1810  ulint buddy_n_frames;
1812 #endif
1813 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1814  ulint mutex_exit_forbidden;
1815 #endif
1816  ulint n_chunks;
1817  buf_chunk_t* chunks;
1818  ulint curr_size;
1819  hash_table_t* page_hash;
1830  hash_table_t* zip_hash;
1834  ulint n_pend_reads;
1838  time_t last_printout_time;
1841  buf_buddy_stat_t buddy_stat[BUF_BUDDY_SIZES_MAX + 1];
1847  /* @} */
1848 
1851  /* @{ */
1852 
1853  ib_mutex_t flush_list_mutex;
1861  const buf_page_t* flush_list_hp;
1865  UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
1868  ibool init_flush[BUF_FLUSH_N_TYPES];
1871  ulint n_flush[BUF_FLUSH_N_TYPES];
1874  os_event_t no_flush[BUF_FLUSH_N_TYPES];
1878  ib_rbt_t* flush_rbt;
1892  ulint freed_page_clock;
1901  ibool try_LRU_scan;
1911  /* @} */
1912 
1914  /* @{ */
1915 
1916  UT_LIST_BASE_NODE_T(buf_page_t) free;
1919  UT_LIST_BASE_NODE_T(buf_page_t) LRU;
1921  buf_page_t* LRU_old;
1928  ulint LRU_old_len;
1936  UT_LIST_BASE_NODE_T(buf_block_t) unzip_LRU;
1940  /* @} */
1945  /* @{ */
1946 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1947  UT_LIST_BASE_NODE_T(buf_page_t) zip_clean;
1949 #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
1950  UT_LIST_BASE_NODE_T(buf_buddy_free_t) zip_free[BUF_BUDDY_SIZES_MAX];
1953  buf_page_t* watch;
1958 #if BUF_BUDDY_LOW > UNIV_ZIP_SIZE_MIN
1959 # error "BUF_BUDDY_LOW > UNIV_ZIP_SIZE_MIN"
1960 #endif
1961  /* @} */
1962 };
1963 
1966 /* @{ */
1967 
1969 #define buf_pool_mutex_own(b) mutex_own(&b->mutex)
1970 
1971 #define buf_pool_mutex_enter(b) do { \
1972  ut_ad(!mutex_own(&b->zip_mutex)); \
1973  mutex_enter(&b->mutex); \
1974 } while (0)
1975 
1977 #define buf_flush_list_mutex_own(b) mutex_own(&b->flush_list_mutex)
1978 
1980 #define buf_flush_list_mutex_enter(b) do { \
1981  mutex_enter(&b->flush_list_mutex); \
1982 } while (0)
1983 
1984 # define buf_flush_list_mutex_exit(b) do { \
1985  mutex_exit(&b->flush_list_mutex); \
1986 } while (0)
1987 
1988 
1989 
1991 # define buf_page_hash_lock_get(b, f) \
1992  hash_get_lock(b->page_hash, f)
1993 
1994 #ifdef UNIV_SYNC_DEBUG
1995 
1996 # define buf_page_hash_lock_held_s(b, p) \
1997  rw_lock_own(buf_page_hash_lock_get(b, \
1998  buf_page_address_fold(p->space, \
1999  p->offset)), \
2000  RW_LOCK_SHARED)
2001 
2003 # define buf_page_hash_lock_held_x(b, p) \
2004  rw_lock_own(buf_page_hash_lock_get(b, \
2005  buf_page_address_fold(p->space, \
2006  p->offset)), \
2007  RW_LOCK_EX)
2008 
2010 # define buf_page_hash_lock_held_s_or_x(b, p) \
2011  (buf_page_hash_lock_held_s(b, p) \
2012  || buf_page_hash_lock_held_x(b, p))
2013 
2014 # define buf_block_hash_lock_held_s(b, p) \
2015  buf_page_hash_lock_held_s(b, &(p->page))
2016 
2017 # define buf_block_hash_lock_held_x(b, p) \
2018  buf_page_hash_lock_held_x(b, &(p->page))
2019 
2020 # define buf_block_hash_lock_held_s_or_x(b, p) \
2021  buf_page_hash_lock_held_s_or_x(b, &(p->page))
2022 #else /* UNIV_SYNC_DEBUG */
2023 # define buf_page_hash_lock_held_s(b, p) (TRUE)
2024 # define buf_page_hash_lock_held_x(b, p) (TRUE)
2025 # define buf_page_hash_lock_held_s_or_x(b, p) (TRUE)
2026 # define buf_block_hash_lock_held_s(b, p) (TRUE)
2027 # define buf_block_hash_lock_held_x(b, p) (TRUE)
2028 # define buf_block_hash_lock_held_s_or_x(b, p) (TRUE)
2029 #endif /* UNIV_SYNC_DEBUG */
2030 
2031 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2032 
2033 # define buf_pool_mutex_exit_forbid(b) do { \
2034  ut_ad(buf_pool_mutex_own(b)); \
2035  b->mutex_exit_forbidden++; \
2036 } while (0)
2037 
2038 # define buf_pool_mutex_exit_allow(b) do { \
2039  ut_ad(buf_pool_mutex_own(b)); \
2040  ut_a(b->mutex_exit_forbidden); \
2041  b->mutex_exit_forbidden--; \
2042 } while (0)
2043 
2044 # define buf_pool_mutex_exit(b) do { \
2045  ut_a(!b->mutex_exit_forbidden); \
2046  mutex_exit(&b->mutex); \
2047 } while (0)
2048 #else
2049 
2050 # define buf_pool_mutex_exit_forbid(b) ((void) 0)
2051 
2052 # define buf_pool_mutex_exit_allow(b) ((void) 0)
2053 
2054 # define buf_pool_mutex_exit(b) mutex_exit(&b->mutex)
2055 #endif
2056 #endif /* !UNIV_HOTBACKUP */
2057 /* @} */
2058 
2059 /**********************************************************************
2060 Let us list the consistency conditions for different control block states.
2061 
2062 NOT_USED: is in free list, not in LRU list, not in flush list, nor
2063  page hash table
2064 READY_FOR_USE: is not in free list, LRU list, or flush list, nor page
2065  hash table
2066 MEMORY: is not in free list, LRU list, or flush list, nor page
2067  hash table
2068 FILE_PAGE: space and offset are defined, is in page hash table
2069  if io_fix == BUF_IO_WRITE,
2070  pool: no_flush[flush_type] is in reset state,
2071  pool: n_flush[flush_type] > 0
2072 
2073  (1) if buf_fix_count == 0, then
2074  is in LRU list, not in free list
2075  is in flush list,
2076  if and only if oldest_modification > 0
2077  is x-locked,
2078  if and only if io_fix == BUF_IO_READ
2079  is s-locked,
2080  if and only if io_fix == BUF_IO_WRITE
2081 
2082  (2) if buf_fix_count > 0, then
2083  is not in LRU list, not in free list
2084  is in flush list,
2085  if and only if oldest_modification > 0
2086  if io_fix == BUF_IO_READ,
2087  is x-locked
2088  if io_fix == BUF_IO_WRITE,
2089  is s-locked
2090 
2091 State transitions:
2092 
2093 NOT_USED => READY_FOR_USE
2094 READY_FOR_USE => MEMORY
2095 READY_FOR_USE => FILE_PAGE
2096 MEMORY => NOT_USED
2097 FILE_PAGE => NOT_USED NOTE: This transition is allowed if and only if
2098  (1) buf_fix_count == 0,
2099  (2) oldest_modification == 0, and
2100  (3) io_fix == 0.
2101 */
2102 
2103 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2104 
2105 struct CheckInLRUList {
2106  void operator()(const buf_page_t* elem) const
2107  {
2108  ut_a(elem->in_LRU_list);
2109  }
2110 };
2111 
2113 struct CheckInFreeList {
2114  void operator()(const buf_page_t* elem) const
2115  {
2116  ut_a(elem->in_free_list);
2117  }
2118 };
2119 
2120 struct CheckUnzipLRUAndLRUList {
2121  void operator()(const buf_block_t* elem) const
2122  {
2123  ut_a(elem->page.in_LRU_list);
2124  ut_a(elem->in_unzip_LRU_list);
2125  }
2126 };
2127 #endif /* UNIV_DEBUG || defined UNIV_BUF_DEBUG */
2128 
2129 #ifndef UNIV_NONINL
2130 #include "buf0buf.ic"
2131 #endif
2132 
2133 #endif