InnoDB Plugin  1.0
buf0buf.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1995, 2014, 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*
513 /*=============================*/
514  ulint space,
515  ulint offset);
516 /********************************************************************/
522 UNIV_INTERN
523 buf_page_t*
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 
611 /*******************************************************************/
613 UNIV_INLINE
614 void
616 /*===========*/
617  buf_block_t* block);
619 /*******************************************************************/
621 UNIV_INLINE
622 void
624 /*===========*/
625  buf_block_t* block);
627 # ifdef UNIV_SYNC_DEBUG
628 
632 # define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(f,l,b)
633 # else /* UNIV_SYNC_DEBUG */
634 
638 # define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(b)
639 # endif /* UNIV_SYNC_DEBUG */
640 #else /* !UNIV_HOTBACKUP */
641 # define buf_block_modify_clock_inc(block) ((void) 0)
642 #endif /* !UNIV_HOTBACKUP */
643 /********************************************************************/
646 UNIV_INTERN
647 ibool
649 /*==================*/
650  bool check_lsn,
652  const byte* read_buf,
653  ulint zip_size)
655  __attribute__((nonnull, warn_unused_result));
656 /********************************************************************/
659 bool
661 /*===============*/
662  const byte* read_buf,
663  const ulint zip_size);
665 #ifndef UNIV_HOTBACKUP
666 /**********************************************************************/
669 UNIV_INLINE
670 void
672 /*=================*/
673  const void* ptr,
674  ulint* space,
675  fil_addr_t* addr);
676 /**********************************************************************/
680 UNIV_INLINE
681 ulint
683 /*========================*/
684  const buf_block_t* block)
685  __attribute__((pure));
686 #ifdef UNIV_DEBUG
687 /*********************************************************************/
691 UNIV_INTERN
694 /*==================*/
695  buf_pool_t* buf_pool,
696  const void* data);
697 #endif /* UNIV_DEBUG */
698 
699 /***********************************************************************
700 FIXME_FTS: Gets the frame the pointer is pointing to. */
701 UNIV_INLINE
703 buf_frame_align(
704 /*============*/
705  /* out: pointer to frame */
706  byte* ptr); /* in: pointer to a frame */
707 
708 
709 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
710 /*********************************************************************/
713 UNIV_INTERN
714 ibool
715 buf_validate(void);
716 /*==============*/
717 #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
718 #if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
719 /*********************************************************************/
721 UNIV_INTERN
722 void
723 buf_print(void);
724 /*============*/
725 #endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
726 #endif /* !UNIV_HOTBACKUP */
732 };
733 
734 /********************************************************************/
736 UNIV_INTERN
737 void
739 /*===========*/
740  const byte* read_buf,
741  ulint zip_size,
743  ulint flags)
746  UNIV_COLD __attribute__((nonnull));
747 /********************************************************************/
750 UNIV_INTERN
751 ibool
753 /*===============*/
754  buf_block_t* block,
755  ibool check);
756 #ifndef UNIV_HOTBACKUP
757 #ifdef UNIV_DEBUG
758 /*********************************************************************/
761 UNIV_INTERN
762 ulint
764 /*==============================*/
765 #endif /* UNIV_DEBUG */
766 /*********************************************************************/
769 UNIV_INTERN
770 ulint
772 /*============================*/
773 /*********************************************************************/
775 UNIV_INTERN
776 void
778 /*=========*/
779  FILE* file);
780 /*******************************************************************/
784 UNIV_INTERN
785 void
787 /*====================*/
788  buf_pool_t* buf_pool,
789  ulint pool_id,
790  buf_pool_info_t* all_pool_info);
792 /*********************************************************************/
796 UNIV_INTERN
797 ulint
799 /*============================*/
800 /**********************************************************************/
802 UNIV_INTERN
803 void
805 /*=================*/
806  buf_pool_t* buf_pool);
807 /**********************************************************************/
809 UNIV_INTERN
810 void
812 /*=================*/
813 /*********************************************************************/
816 UNIV_INTERN
817 ibool
818 buf_all_freed(void);
819 /*===============*/
820 /*********************************************************************/
824 UNIV_INTERN
825 ulint
827 /*==============================*/
828 /*********************************************************************/
832 UNIV_INTERN
833 void
834 buf_pool_invalidate(void);
835 /*=====================*/
836 #endif /* !UNIV_HOTBACKUP */
837 
838 /*========================================================================
839 --------------------------- LOWER LEVEL ROUTINES -------------------------
840 =========================================================================*/
841 
842 #ifdef UNIV_SYNC_DEBUG
843 /*********************************************************************/
847 UNIV_INLINE
848 void
850 /*====================*/
851  buf_block_t* block,
853  ulint level);
854 #else /* UNIV_SYNC_DEBUG */
855 # define buf_block_dbg_add_level(block, level) /* nothing */
856 #endif /* UNIV_SYNC_DEBUG */
857 /*********************************************************************/
860 UNIV_INLINE
861 enum buf_page_state
863 /*===============*/
864  const buf_page_t* bpage);
865 /*********************************************************************/
868 UNIV_INLINE
869 enum buf_page_state
871 /*================*/
872  const buf_block_t* block)
873  __attribute__((pure));
874 /*********************************************************************/
876 UNIV_INLINE
877 void
879 /*===============*/
880  buf_page_t* bpage,
881  enum buf_page_state state);
882 /*********************************************************************/
884 UNIV_INLINE
885 void
887 /*================*/
888  buf_block_t* block,
889  enum buf_page_state state);
890 /*********************************************************************/
893 UNIV_INLINE
894 ibool
896 /*=============*/
897  const buf_page_t* bpage)
898  __attribute__((pure));
899 #ifndef UNIV_HOTBACKUP
900 /*********************************************************************/
903 UNIV_INLINE
904 ibool
906 /*==========================*/
907  const buf_page_t* bpage)
908  __attribute__((pure));
909 
910 /*********************************************************************/
913 UNIV_INLINE
914 ib_mutex_t*
916 /*===============*/
917  const buf_page_t* bpage)
918  __attribute__((pure));
919 
920 /*********************************************************************/
923 UNIV_INLINE
926 /*====================*/
927  const buf_page_t* bpage)
928  __attribute__((pure));
929 /*********************************************************************/
931 UNIV_INLINE
932 void
934 /*====================*/
935  buf_page_t* bpage,
936  buf_flush_t flush_type);
937 /*********************************************************************/
939 UNIV_INLINE
940 void
942 /*====================*/
943  buf_block_t* block,
944  ulint space,
945  ulint page_no);
946 /*********************************************************************/
949 UNIV_INLINE
950 enum buf_io_fix
952 /*================*/
953  const buf_page_t* bpage)
954  __attribute__((pure));
955 /*********************************************************************/
958 UNIV_INLINE
959 enum buf_io_fix
961 /*================*/
962  const buf_block_t* block)
963  __attribute__((pure));
964 /*********************************************************************/
966 UNIV_INLINE
967 void
969 /*================*/
970  buf_page_t* bpage,
971  enum buf_io_fix io_fix);
972 /*********************************************************************/
974 UNIV_INLINE
975 void
977 /*=================*/
978  buf_block_t* block,
979  enum buf_io_fix io_fix);
980 /*********************************************************************/
989 UNIV_INLINE
990 void
992 /*================*/
993  buf_page_t* bpage);
994 /*********************************************************************/
996 UNIV_INLINE
997 void
999 /*==================*/
1000  buf_page_t* bpage);
1001 /********************************************************************/
1004 UNIV_INLINE
1005 ibool
1007 /*==================*/
1008  const buf_page_t* bpage)
1009  __attribute__((pure));
1010 
1011 /*********************************************************************/
1014 UNIV_INLINE
1015 ibool
1017 /*============*/
1018  const buf_page_t* bpage)
1019  __attribute__((pure));
1020 /*********************************************************************/
1022 UNIV_INLINE
1023 void
1025 /*=============*/
1026  buf_page_t* bpage,
1027  ibool old);
1028 /*********************************************************************/
1031 UNIV_INLINE
1032 unsigned
1034 /*=================*/
1035  const buf_page_t* bpage)
1036  __attribute__((nonnull, pure));
1037 /*********************************************************************/
1039 UNIV_INLINE
1040 void
1042 /*==================*/
1043  buf_page_t* bpage)
1044  __attribute__((nonnull));
1045 /*********************************************************************/
1050 UNIV_INLINE
1051 buf_block_t*
1053 /*===============*/
1054  buf_page_t* bpage)
1055  __attribute__((pure));
1056 #endif /* !UNIV_HOTBACKUP */
1057 #ifdef UNIV_DEBUG
1058 /*********************************************************************/
1061 UNIV_INLINE
1062 buf_frame_t*
1064 /*================*/
1065  const buf_block_t* block)
1066  __attribute__((pure));
1067 #else /* UNIV_DEBUG */
1068 # define buf_block_get_frame(block) (block)->frame
1069 #endif /* UNIV_DEBUG */
1070 /*********************************************************************/
1073 UNIV_INLINE
1074 ulint
1076 /*===============*/
1077  const buf_page_t* bpage)
1078  __attribute__((pure));
1079 /*********************************************************************/
1082 UNIV_INLINE
1083 ulint
1085 /*================*/
1086  const buf_block_t* block)
1087  __attribute__((pure));
1088 /*********************************************************************/
1091 UNIV_INLINE
1092 ulint
1094 /*=================*/
1095  const buf_page_t* bpage)
1096  __attribute__((pure));
1097 /*********************************************************************/
1100 UNIV_INLINE
1101 ulint
1103 /*==================*/
1104  const buf_block_t* block)
1105  __attribute__((pure));
1106 /*********************************************************************/
1109 UNIV_INLINE
1110 ulint
1112 /*==================*/
1113  const buf_page_t* bpage)
1114  __attribute__((pure));
1115 /*********************************************************************/
1118 UNIV_INLINE
1119 ulint
1121 /*===================*/
1122  const buf_block_t* block)
1123  __attribute__((pure));
1124 /*********************************************************************/
1127 #define buf_block_get_page_zip(block) \
1128  ((block)->page.zip.data ? &(block)->page.zip : NULL)
1129 #ifndef UNIV_HOTBACKUP
1130 /*******************************************************************/
1133 UNIV_INTERN
1134 buf_block_t*
1136 /*============*/
1137  const byte* ptr);
1138 /********************************************************************/
1142 UNIV_INTERN
1143 ibool
1145 /*=======================*/
1146  const void* ptr);
1151 #define buf_pool_is_block_mutex(m) \
1152  buf_pointer_is_block_field((const void*)(m))
1153 
1156 #define buf_pool_is_block_lock(l) \
1157  buf_pointer_is_block_field((const void*)(l))
1158 
1159 #if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
1160 /*********************************************************************/
1164 UNIV_INLINE
1165 const page_zip_des_t*
1167 /*===================*/
1168  const byte* ptr);
1169 #endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
1170 /********************************************************************/
1180 UNIV_INTERN
1181 buf_page_t*
1183 /*===================*/
1184  dberr_t* err,
1185  ulint mode,
1186  ulint space,
1187  ulint zip_size,
1188  ibool unzip,
1189  ib_int64_t tablespace_version,
1192  ulint offset);
1193 /********************************************************************/
1197 UNIV_INTERN
1198 bool
1200 /*=================*/
1201  buf_page_t* bpage);
1202 /********************************************************************/
1206 UNIV_INLINE
1207 ulint
1209 /*==================*/
1210  ulint space,
1211  ulint offset)
1212  __attribute__((const));
1213 /********************************************************************/
1216 UNIV_INLINE
1217 ulint
1219 /*===========*/
1220  const buf_pool_t* buf_pool)
1221  __attribute__((nonnull, const));
1222 /******************************************************************/
1225 UNIV_INLINE
1226 buf_pool_t*
1228 /*================*/
1229  const buf_page_t* bpage);
1230 /******************************************************************/
1233 UNIV_INLINE
1234 buf_pool_t*
1236 /*================*/
1237  const buf_block_t* block);
1238 /******************************************************************/
1241 UNIV_INLINE
1242 buf_pool_t*
1243 buf_pool_get(
1244 /*==========*/
1245  ulint space,
1246  ulint offset);
1247 /******************************************************************/
1250 UNIV_INLINE
1251 buf_pool_t*
1253 /*================*/
1254  ulint index);
1256 /******************************************************************/
1259 UNIV_INLINE
1260 buf_page_t*
1262 /*==================*/
1263  buf_pool_t* buf_pool,
1264  ulint space,
1265  ulint offset,
1266  ulint fold);
1267 /******************************************************************/
1275 UNIV_INLINE
1276 buf_page_t*
1278 /*=====================*/
1282  buf_pool_t* buf_pool,
1283  ulint space,
1284  ulint offset,
1285  rw_lock_t** lock,
1290  ulint lock_mode,
1293  bool watch = false);
1295 /******************************************************************/
1303 UNIV_INLINE
1304 buf_block_t*
1306 /*=====================*/
1310  buf_pool_t* buf_pool,
1311  ulint space,
1312  ulint offset,
1313  rw_lock_t** lock,
1318  ulint lock_mode);
1321 /* There are four different ways we can try to get a bpage or block
1322 from the page hash:
1323 1) Caller already holds the appropriate page hash lock: in the case call
1324 buf_page_hash_get_low() function.
1325 2) Caller wants to hold page hash lock in x-mode
1326 3) Caller wants to hold page hash lock in s-mode
1327 4) Caller doesn't want to hold page hash lock */
1328 #define buf_page_hash_get_s_locked(b, s, o, l) \
1329  buf_page_hash_get_locked(b, s, o, l, RW_LOCK_SHARED)
1330 #define buf_page_hash_get_x_locked(b, s, o, l) \
1331  buf_page_hash_get_locked(b, s, o, l, RW_LOCK_EX)
1332 #define buf_page_hash_get(b, s, o) \
1333  buf_page_hash_get_locked(b, s, o, NULL, 0)
1334 #define buf_page_get_also_watch(b, s, o) \
1335  buf_page_hash_get_locked(b, s, o, NULL, 0, true)
1336 
1337 #define buf_block_hash_get_s_locked(b, s, o, l) \
1338  buf_block_hash_get_locked(b, s, o, l, RW_LOCK_SHARED)
1339 #define buf_block_hash_get_x_locked(b, s, o, l) \
1340  buf_block_hash_get_locked(b, s, o, l, RW_LOCK_EX)
1341 #define buf_block_hash_get(b, s, o) \
1342  buf_block_hash_get_locked(b, s, o, NULL, 0)
1343 
1344 /*********************************************************************/
1347 UNIV_INTERN
1348 ulint
1349 buf_get_free_list_len(void);
1350 /*=======================*/
1351 
1352 /********************************************************************/
1355 UNIV_INTERN
1356 ibool
1358 /*=======================*/
1359  buf_pool_t* buf_pool,
1360  const buf_page_t* bpage)
1361  __attribute__((nonnull, warn_unused_result));
1362 /****************************************************************/
1365 UNIV_INTERN
1366 buf_page_t*
1368 /*===============*/
1369  ulint space,
1370  ulint offset,
1371  ulint fold)
1372  __attribute__((warn_unused_result));
1373 /****************************************************************/
1376 UNIV_INTERN
1377 void
1379 /*=================*/
1380  ulint space,
1381  ulint offset);
1382 /****************************************************************/
1387 UNIV_INTERN
1388 ibool
1390 /*====================*/
1391  ulint space,
1392  ulint offset)
1393  __attribute__((warn_unused_result));
1394 /********************************************************************/
1396 UNIV_INTERN
1397 void
1399 /*===================*/
1400  ulint* LRU_len,
1401  ulint* free_len,
1402  ulint* flush_list_len);
1403 /********************************************************************/
1405 UNIV_INTERN
1406 void
1408 /*=============================*/
1409  buf_pools_list_size_t* buf_pools_list_size);
1411 /********************************************************************/
1413 UNIV_INTERN
1414 void
1416 /*===============*/
1417  buf_pool_stat_t*tot_stat);
1418 /*********************************************************************/
1421 UNIV_INLINE
1422 buf_block_t*
1424 /*====================*/
1425  const buf_pool_t* buf_pool,
1426  ulint n,
1427  ulint* chunk_size);
1429 /********************************************************************/
1431 UNIV_INTERN
1432 void
1434 /*==========================*/
1435  buf_frame_t* page,
1436  ulint zip_size,
1437  lsn_t lsn);
1439 #endif /* !UNIV_HOTBACKUP */
1440 
1445 #define BUF_PAGE_STATE_BITS 3
1446 
1447 struct buf_page_t{
1454  /* @{ */
1455 
1456  ib_uint32_t space;
1458  ib_uint32_t offset;
1461 #ifdef PAGE_ATOMIC_REF_COUNT
1462  ib_uint32_t buf_fix_count;
1463 
1466  byte io_fix;
1467 
1468  byte state;
1469 #else
1470  unsigned buf_fix_count:19;
1471 
1474  unsigned io_fix:2;
1475 
1483  unsigned state:BUF_PAGE_STATE_BITS;
1484 
1485 #endif /* PAGE_ATOMIC_REF_COUNT */
1486 
1487 #ifndef UNIV_HOTBACKUP
1488  unsigned flush_type:2;
1492  unsigned buf_pool_index:6;
1494 # if MAX_BUFFER_POOLS > 64
1495 # error "MAX_BUFFER_POOLS > 64; redefine buf_pool_index:6"
1496 # endif
1497  /* @} */
1498 #endif /* !UNIV_HOTBACKUP */
1505 #ifndef UNIV_HOTBACKUP
1509 #ifdef UNIV_DEBUG
1512 #endif /* UNIV_DEBUG */
1513 
1516  /* @{ */
1517 
1518  UT_LIST_NODE_T(buf_page_t) list;
1545 #ifdef UNIV_DEBUG
1561 #endif /* UNIV_DEBUG */
1562  lsn_t newest_modification;
1568  lsn_t oldest_modification;
1581  /* @} */
1585  /* @{ */
1586 
1587  UT_LIST_NODE_T(buf_page_t) LRU;
1589 #ifdef UNIV_DEBUG
1593 #endif /* UNIV_DEBUG */
1594  unsigned old:1;
1596  unsigned freed_page_clock:31;
1604  /* @} */
1605  unsigned access_time;
1609 # if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
1615 # endif /* UNIV_DEBUG_FILE_ACCESSES || UNIV_DEBUG */
1616 #endif /* !UNIV_HOTBACKUP */
1617 };
1618 
1622 
1624  /* @{ */
1625 
1630  byte* frame;
1634 #ifndef UNIV_HOTBACKUP
1635  UT_LIST_NODE_T(buf_block_t) unzip_LRU;
1640 #ifdef UNIV_DEBUG
1644 #endif /* UNIV_DEBUG */
1653  unsigned lock_hash_val:32;
1669  /* @} */
1671  /* @{ */
1672 
1673  ib_uint64_t modify_clock;
1684  /* @} */
1687  /* @{ */
1688 
1691  ulint n_fields;
1693  ulint n_bytes;
1699  /* @} */
1700 
1713  /* @{ */
1714 
1715 #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1716  ulint n_pointers;
1719 #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1720  unsigned curr_n_fields:10;
1722  unsigned curr_n_bytes:15;
1724  unsigned curr_left_side:1;
1734  /* @} */
1735 # ifdef UNIV_SYNC_DEBUG
1736 
1737  /* @{ */
1742  /* @} */
1743 # endif
1744 #endif /* !UNIV_HOTBACKUP */
1745 };
1746 
1750 #define buf_block_state_valid(block) \
1751 (buf_block_get_state(block) >= BUF_BLOCK_NOT_USED \
1752  && (buf_block_get_state(block) <= BUF_BLOCK_REMOVE_HASH))
1753 
1754 #ifndef UNIV_HOTBACKUP
1755 /**********************************************************************/
1757 /* @{ */
1758 #define BUF_POOL_ZIP_FOLD_PTR(ptr) ((ulint) (ptr) / UNIV_PAGE_SIZE)
1759 #define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
1760 #define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t*) (b))
1761 /* @} */
1762 
1765  union {
1766  ulint size;
1767  byte bytes[FIL_PAGE_DATA];
1776  } stamp;
1777 
1779  UT_LIST_NODE_T(buf_buddy_free_t) list;
1781 };
1782 
1785  ulint n_page_gets;
1793  ulint n_pages_created;
1795  ulint n_ra_pages_read_rnd;
1797  ulint n_ra_pages_read;
1799  ulint n_ra_pages_evicted;
1802  ulint n_pages_made_young;
1804  ulint n_pages_not_made_young;
1808  ulint LRU_bytes;
1810 };
1811 
1815  ulint used;
1817  ib_uint64_t relocated;
1819  ib_uint64_t relocated_usec;
1820 };
1821 
1827 struct buf_pool_t{
1828 
1830  /* @{ */
1831  ib_mutex_t mutex;
1833  ib_mutex_t zip_mutex;
1837  ulint instance_no;
1841  ulint LRU_old_ratio;
1843 #ifdef UNIV_DEBUG
1844  ulint buddy_n_frames;
1846 #endif
1847 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1849 #endif
1850  ulint n_chunks;
1852  ulint curr_size;
1853  hash_table_t* page_hash;
1864  hash_table_t* zip_hash;
1868  ulint n_pend_reads;
1872  time_t last_printout_time;
1875  buf_buddy_stat_t buddy_stat[BUF_BUDDY_SIZES_MAX + 1];
1881  /* @} */
1882 
1885  /* @{ */
1886 
1887  ib_mutex_t flush_list_mutex;
1895  const buf_page_t* flush_list_hp;
1899  UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
1902  ibool init_flush[BUF_FLUSH_N_TYPES];
1905  ulint n_flush[BUF_FLUSH_N_TYPES];
1908  os_event_t no_flush[BUF_FLUSH_N_TYPES];
1912  ib_rbt_t* flush_rbt;
1926  ulint freed_page_clock;
1935  ibool try_LRU_scan;
1945  /* @} */
1946 
1948  /* @{ */
1949 
1950  UT_LIST_BASE_NODE_T(buf_page_t) free;
1953  UT_LIST_BASE_NODE_T(buf_page_t) LRU;
1955  buf_page_t* LRU_old;
1962  ulint LRU_old_len;
1970  UT_LIST_BASE_NODE_T(buf_block_t) unzip_LRU;
1974  /* @} */
1979  /* @{ */
1980 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1981  UT_LIST_BASE_NODE_T(buf_page_t) zip_clean;
1983 #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
1984  UT_LIST_BASE_NODE_T(buf_buddy_free_t) zip_free[BUF_BUDDY_SIZES_MAX];
1987  buf_page_t* watch;
1992 #if BUF_BUDDY_LOW > UNIV_ZIP_SIZE_MIN
1993 # error "BUF_BUDDY_LOW > UNIV_ZIP_SIZE_MIN"
1994 #endif
1995  /* @} */
1996 };
1997 
2000 /* @{ */
2001 
2003 #define buf_pool_mutex_own(b) mutex_own(&b->mutex)
2004 
2005 #define buf_pool_mutex_enter(b) do { \
2006  ut_ad(!mutex_own(&b->zip_mutex)); \
2007  mutex_enter(&b->mutex); \
2008 } while (0)
2009 
2011 #define buf_flush_list_mutex_own(b) mutex_own(&b->flush_list_mutex)
2012 
2014 #define buf_flush_list_mutex_enter(b) do { \
2015  mutex_enter(&b->flush_list_mutex); \
2016 } while (0)
2017 
2018 # define buf_flush_list_mutex_exit(b) do { \
2019  mutex_exit(&b->flush_list_mutex); \
2020 } while (0)
2021 
2023 #define buf_block_mutex_own(b) mutex_own(&(b)->mutex)
2024 
2026 #define buf_block_mutex_enter(b) do { \
2027  mutex_enter(&(b)->mutex); \
2028 } while (0)
2029 
2031 #define buf_block_mutex_exit(b) do { \
2032  mutex_exit(&(b)->mutex); \
2033 } while (0)
2034 
2035 
2037 # define buf_page_hash_lock_get(b, f) \
2038  hash_get_lock(b->page_hash, f)
2039 
2040 #ifdef UNIV_SYNC_DEBUG
2041 
2042 # define buf_page_hash_lock_held_s(b, p) \
2043  rw_lock_own(buf_page_hash_lock_get(b, \
2044  buf_page_address_fold(p->space, \
2045  p->offset)), \
2046  RW_LOCK_SHARED)
2047 
2049 # define buf_page_hash_lock_held_x(b, p) \
2050  rw_lock_own(buf_page_hash_lock_get(b, \
2051  buf_page_address_fold(p->space, \
2052  p->offset)), \
2053  RW_LOCK_EX)
2054 
2056 # define buf_page_hash_lock_held_s_or_x(b, p) \
2057  (buf_page_hash_lock_held_s(b, p) \
2058  || buf_page_hash_lock_held_x(b, p))
2059 
2060 # define buf_block_hash_lock_held_s(b, p) \
2061  buf_page_hash_lock_held_s(b, &(p->page))
2062 
2063 # define buf_block_hash_lock_held_x(b, p) \
2064  buf_page_hash_lock_held_x(b, &(p->page))
2065 
2066 # define buf_block_hash_lock_held_s_or_x(b, p) \
2067  buf_page_hash_lock_held_s_or_x(b, &(p->page))
2068 #else /* UNIV_SYNC_DEBUG */
2069 # define buf_page_hash_lock_held_s(b, p) (TRUE)
2070 # define buf_page_hash_lock_held_x(b, p) (TRUE)
2071 # define buf_page_hash_lock_held_s_or_x(b, p) (TRUE)
2072 # define buf_block_hash_lock_held_s(b, p) (TRUE)
2073 # define buf_block_hash_lock_held_x(b, p) (TRUE)
2074 # define buf_block_hash_lock_held_s_or_x(b, p) (TRUE)
2075 #endif /* UNIV_SYNC_DEBUG */
2076 
2077 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2078 
2079 # define buf_pool_mutex_exit_forbid(b) do { \
2080  ut_ad(buf_pool_mutex_own(b)); \
2081  b->mutex_exit_forbidden++; \
2082 } while (0)
2083 
2084 # define buf_pool_mutex_exit_allow(b) do { \
2085  ut_ad(buf_pool_mutex_own(b)); \
2086  ut_a(b->mutex_exit_forbidden); \
2087  b->mutex_exit_forbidden--; \
2088 } while (0)
2089 
2090 # define buf_pool_mutex_exit(b) do { \
2091  ut_a(!b->mutex_exit_forbidden); \
2092  mutex_exit(&b->mutex); \
2093 } while (0)
2094 #else
2095 
2096 # define buf_pool_mutex_exit_forbid(b) ((void) 0)
2097 
2098 # define buf_pool_mutex_exit_allow(b) ((void) 0)
2099 
2100 # define buf_pool_mutex_exit(b) mutex_exit(&b->mutex)
2101 #endif
2102 #endif /* !UNIV_HOTBACKUP */
2103 /* @} */
2104 
2105 /**********************************************************************
2106 Let us list the consistency conditions for different control block states.
2107 
2108 NOT_USED: is in free list, not in LRU list, not in flush list, nor
2109  page hash table
2110 READY_FOR_USE: is not in free list, LRU list, or flush list, nor page
2111  hash table
2112 MEMORY: is not in free list, LRU list, or flush list, nor page
2113  hash table
2114 FILE_PAGE: space and offset are defined, is in page hash table
2115  if io_fix == BUF_IO_WRITE,
2116  pool: no_flush[flush_type] is in reset state,
2117  pool: n_flush[flush_type] > 0
2118 
2119  (1) if buf_fix_count == 0, then
2120  is in LRU list, not in free list
2121  is in flush list,
2122  if and only if oldest_modification > 0
2123  is x-locked,
2124  if and only if io_fix == BUF_IO_READ
2125  is s-locked,
2126  if and only if io_fix == BUF_IO_WRITE
2127 
2128  (2) if buf_fix_count > 0, then
2129  is not in LRU list, not in free list
2130  is in flush list,
2131  if and only if oldest_modification > 0
2132  if io_fix == BUF_IO_READ,
2133  is x-locked
2134  if io_fix == BUF_IO_WRITE,
2135  is s-locked
2136 
2137 State transitions:
2138 
2139 NOT_USED => READY_FOR_USE
2140 READY_FOR_USE => MEMORY
2141 READY_FOR_USE => FILE_PAGE
2142 MEMORY => NOT_USED
2143 FILE_PAGE => NOT_USED NOTE: This transition is allowed if and only if
2144  (1) buf_fix_count == 0,
2145  (2) oldest_modification == 0, and
2146  (3) io_fix == 0.
2147 */
2148 
2149 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
2150 
2152  void operator()(const buf_page_t* elem) const
2153  {
2154  ut_a(elem->in_LRU_list);
2155  }
2156 };
2157 
2160  void operator()(const buf_page_t* elem) const
2161  {
2162  ut_a(elem->in_free_list);
2163  }
2164 };
2165 
2167  void operator()(const buf_block_t* elem) const
2168  {
2169  ut_a(elem->page.in_LRU_list);
2170  ut_a(elem->in_unzip_LRU_list);
2171  }
2172 };
2173 #endif /* UNIV_DEBUG || defined UNIV_BUF_DEBUG */
2174 
2175 #ifndef UNIV_NONINL
2176 #include "buf0buf.ic"
2177 #endif
2178 
2179 #endif