Drizzled Public API Documentation

buf0buf.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (C) 1995, 2010, Innobase Oy. 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., 51 Franklin
15 St, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 *****************************************************************************/
18 
19 /**************************************************/
26 #pragma once
27 #ifndef buf0buf_h
28 #define buf0buf_h
29 
30 #include "univ.i"
31 #include "fil0fil.h"
32 #include "mtr0types.h"
33 #include "buf0types.h"
34 #include "hash0hash.h"
35 #include "ut0byte.h"
36 #include "page0types.h"
37 #ifndef UNIV_HOTBACKUP
38 #include "ut0rbt.h"
39 #include "os0proc.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 /* @} */
59 /* @{ */
60 #define BUF_MAKE_YOUNG 51
65 #define BUF_KEEP_OLD 52
67 /* @} */
68 
69 #define MAX_BUFFER_POOLS 64
72 #define BUF_POOL_WATCH_SIZE 1
75 extern buf_pool_t* buf_pool_ptr;
77 #ifdef UNIV_DEBUG
78 extern ibool buf_debug_prints;
81 #endif /* UNIV_DEBUG */
82 #else /* !UNIV_HOTBACKUP */
83 extern buf_block_t* back_block1;
84 extern buf_block_t* back_block2;
85 #endif /* !UNIV_HOTBACKUP */
86 
88 #define BUF_NO_CHECKSUM_MAGIC 0xDEADBEEFUL
89 
94 enum buf_page_state {
95  BUF_BLOCK_ZIP_FREE = 0,
116 };
117 
121 struct buf_pool_info_struct{
122  /* General buffer pool info */
123  ulint pool_unique_id;
124  ulint pool_size;
125  ulint lru_len;
126  ulint old_lru_len;
128  ulint flush_list_len;
129  ulint n_pend_unzip;
131  ulint n_pend_reads;
133  ulint n_pending_flush_lru;
140  ulint n_pages_read;
143  ulint n_page_gets;
152  /* Buffer pool access stats */
158  double pages_created_rate;
160  ulint page_read_delta;
164  ulint not_young_making_delta;
167  /* Statistics about read ahead algorithm. */
173  /* Stats about LRU eviction */
174  ulint unzip_lru_len;
176  /* Counters for LRU policy */
177  ulint io_sum;
178  ulint io_cur;
180  ulint unzip_sum;
181  ulint unzip_cur;
184 };
185 
188 #ifndef UNIV_HOTBACKUP
189 /********************************************************************/
191 UNIV_INLINE
192 void
194 /*===========================*/
195 
196 /********************************************************************/
198 UNIV_INLINE
199 void
201 /*==========================*/
202 
203 /********************************************************************/
206 UNIV_INTERN
207 ulint
208 buf_pool_init(
209 /*=========*/
210  ulint size,
211  ulint n_instances);
212 /********************************************************************/
215 UNIV_INTERN
216 void
217 buf_pool_free(
218 /*==========*/
219  ulint n_instances);
221 /********************************************************************/
225 UNIV_INTERN
226 void
227 buf_pool_drop_hash_index(void);
228 /*==========================*/
229 
230 /********************************************************************/
234 UNIV_INTERN
235 void
236 buf_relocate(
237 /*=========*/
238  buf_page_t* bpage,
241  buf_page_t* dpage)
242  __attribute__((nonnull));
243 /********************************************************************/
245 UNIV_INTERN
246 void
247 buf_pool_resize(void);
248 /*=================*/
249 /*********************************************************************/
252 UNIV_INLINE
253 ulint
255 /*========================*/
256 /*********************************************************************/
259 UNIV_INLINE
260 ulint
262 /*=======================*/
263 /********************************************************************/
267 UNIV_INTERN
268 ib_uint64_t
269 buf_pool_get_oldest_modification(void);
270 /*==================================*/
271 /********************************************************************/
274 UNIV_INTERN
276 buf_block_alloc(
277 /*============*/
278  buf_pool_t* buf_pool);
281 /********************************************************************/
283 UNIV_INLINE
284 void
286 /*===========*/
287  buf_block_t* block);
288 #endif /* !UNIV_HOTBACKUP */
289 /*********************************************************************/
292 UNIV_INLINE
293 byte*
295 /*===========*/
296  byte* buf,
297  const buf_frame_t* frame);
298 #ifndef UNIV_HOTBACKUP
299 /**************************************************************/
303 #define buf_page_get(SP, ZS, OF, LA, MTR) buf_page_get_gen(\
304  SP, ZS, OF, LA, NULL,\
305  BUF_GET, __FILE__, __LINE__, MTR)
306 /**************************************************************/
312 #define buf_page_get_with_no_latch(SP, ZS, OF, MTR) buf_page_get_gen(\
313  SP, ZS, OF, RW_NO_LATCH, NULL,\
314  BUF_GET_NO_LATCH, __FILE__, __LINE__, MTR)
315 /********************************************************************/
319 UNIV_INTERN
320 ibool
321 buf_page_optimistic_get(
322 /*====================*/
323  ulint rw_latch,
324  buf_block_t* block,
325  ib_uint64_t modify_clock,
327  const char* file,
328  ulint line,
329  mtr_t* mtr);
330 /********************************************************************/
334 UNIV_INTERN
335 ibool
336 buf_page_get_known_nowait(
337 /*======================*/
338  ulint rw_latch,
339  buf_block_t* block,
340  ulint mode,
341  const char* file,
342  ulint line,
343  mtr_t* mtr);
345 /*******************************************************************/
349 UNIV_INTERN
350 const buf_block_t*
351 buf_page_try_get_func(
352 /*==================*/
353  ulint space_id,
354  ulint page_no,
355  const char* file,
356  ulint line,
357  mtr_t* mtr);
365 #define buf_page_try_get(space_id, page_no, mtr) \
366  buf_page_try_get_func(space_id, page_no, __FILE__, __LINE__, mtr);
367 
368 /********************************************************************/
377 UNIV_INTERN
379 buf_page_get_zip(
380 /*=============*/
381  ulint space,
382  ulint zip_size,
383  ulint offset);
384 /********************************************************************/
387 UNIV_INTERN
389 buf_page_get_gen(
390 /*=============*/
391  ulint space,
392  ulint zip_size,
394  ulint offset,
395  ulint rw_latch,
396  buf_block_t* guess,
397  ulint mode,
400  const char* file,
401  ulint line,
402  mtr_t* mtr);
403 /********************************************************************/
409 UNIV_INTERN
411 buf_page_create(
412 /*============*/
413  ulint space,
414  ulint offset,
416  ulint zip_size,
417  mtr_t* mtr);
418 #else /* !UNIV_HOTBACKUP */
419 /********************************************************************/
421 UNIV_INTERN
422 void
423 buf_page_init_for_backup_restore(
424 /*=============================*/
425  ulint space,
426  ulint offset,
428  ulint zip_size,
430  buf_block_t* block);
431 #endif /* !UNIV_HOTBACKUP */
432 
433 #ifndef UNIV_HOTBACKUP
434 /********************************************************************/
436 UNIV_INLINE
437 void
439 /*=================*/
440  buf_page_t* bpage);
441 /********************************************************************/
444 UNIV_INLINE
445 void
447 /*=============*/
448  buf_block_t* block,
449  ulint rw_latch);
451 /********************************************************************/
455 UNIV_INTERN
456 void
457 buf_page_make_young(
458 /*================*/
459  buf_page_t* bpage);
460 /********************************************************************/
467 UNIV_INLINE
468 ibool
470 /*==========*/
471  ulint space,
472  ulint offset);
473 /********************************************************************/
476 UNIV_INTERN
477 void
478 buf_reset_check_index_page_at_flush(
479 /*================================*/
480  ulint space,
481  ulint offset);
482 #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
483 /********************************************************************/
489 UNIV_INTERN
490 buf_page_t*
491 buf_page_set_file_page_was_freed(
492 /*=============================*/
493  ulint space,
494  ulint offset);
495 /********************************************************************/
501 UNIV_INTERN
502 buf_page_t*
503 buf_page_reset_file_page_was_freed(
504 /*===============================*/
505  ulint space,
506  ulint offset);
507 #endif /* UNIV_DEBUG_FILE_ACCESSES || UNIV_DEBUG */
508 /********************************************************************/
511 UNIV_INLINE
512 ulint
514 /*==========================*/
515  const buf_page_t* bpage)
516  __attribute__((pure));
517 /********************************************************************/
520 UNIV_INLINE
521 ulint
523 /*===========================*/
524  const buf_block_t* block)
525  __attribute__((pure));
526 
527 /********************************************************************/
532 UNIV_INLINE
533 ibool
535 /*=====================*/
536  const buf_page_t* bpage);
537 /********************************************************************/
542 UNIV_INTERN
543 ibool
544 buf_page_peek_if_search_hashed(
545 /*===========================*/
546  ulint space,
547  ulint offset);
548 /********************************************************************/
552 UNIV_INLINE
553 ib_uint64_t
555 /*=============================*/
556  const buf_page_t* bpage);
558 /********************************************************************/
562 UNIV_INLINE
563 void
565 /*=======================*/
566  buf_block_t* block);
567 /********************************************************************/
571 UNIV_INLINE
572 ib_uint64_t
574 /*=======================*/
575  buf_block_t* block);
576 #else /* !UNIV_HOTBACKUP */
577 # define buf_block_modify_clock_inc(block) ((void) 0)
578 #endif /* !UNIV_HOTBACKUP */
579 /********************************************************************/
584 UNIV_INTERN
585 ulint
586 buf_calc_page_new_checksum(
587 /*=======================*/
588  const byte* page);
589 /********************************************************************/
597 UNIV_INTERN
598 ulint
599 buf_calc_page_old_checksum(
600 /*=======================*/
601  const byte* page);
602 /********************************************************************/
605 UNIV_INTERN
606 ibool
607 buf_page_is_corrupted(
608 /*==================*/
609  const byte* read_buf,
610  ulint zip_size);
612 #ifndef UNIV_HOTBACKUP
613 /**********************************************************************/
616 UNIV_INLINE
617 void
619 /*=================*/
620  const void* ptr,
621  ulint* space,
622  fil_addr_t* addr);
623 /**********************************************************************/
627 UNIV_INLINE
628 ulint
630 /*========================*/
631  const buf_block_t* block)
632  __attribute__((pure));
633 #ifdef UNIV_DEBUG
634 /*********************************************************************/
638 UNIV_INTERN
640 buf_pool_contains_zip(
641 /*==================*/
642  buf_pool_t* buf_pool,
643  const void* data);
644 #endif /* UNIV_DEBUG */
645 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
646 /*********************************************************************/
649 UNIV_INTERN
650 ibool
651 buf_validate(void);
652 /*==============*/
653 #endif /* UNIV_DEBUG || UNIV_BUF_DEBUG */
654 #if defined UNIV_DEBUG_PRINT || defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
655 /*********************************************************************/
657 UNIV_INTERN
658 void
659 buf_print(void);
660 /*============*/
661 #endif /* UNIV_DEBUG_PRINT || UNIV_DEBUG || UNIV_BUF_DEBUG */
662 #endif /* !UNIV_HOTBACKUP */
663 /********************************************************************/
665 UNIV_INTERN
666 void
667 buf_page_print(
668 /*===========*/
669  const byte* read_buf,
670  ulint zip_size);
672 /********************************************************************/
675 UNIV_INTERN
676 ibool
677 buf_zip_decompress(
678 /*===============*/
679  buf_block_t* block,
680  ibool check);
681 #ifndef UNIV_HOTBACKUP
682 #ifdef UNIV_DEBUG
683 /*********************************************************************/
686 UNIV_INTERN
687 ulint
688 buf_get_latched_pages_number(void);
689 /*==============================*/
690 #endif /* UNIV_DEBUG */
691 /*********************************************************************/
694 UNIV_INTERN
695 ulint
696 buf_get_n_pending_ios(void);
697 /*=======================*/
698 /*********************************************************************/
700 UNIV_INTERN
701 void
702 buf_print_io(
703 /*=========*/
704  FILE* file);
705 /*********************************************************************/
709 UNIV_INTERN
710 ulint
711 buf_get_modified_ratio_pct(void);
712 /*============================*/
713 /**********************************************************************/
715 UNIV_INTERN
716 void
717 buf_refresh_io_stats(
718 /*=================*/
719  buf_pool_t* buf_pool);
720 /**********************************************************************/
722 UNIV_INTERN
723 void
724 buf_refresh_io_stats_all(void);
725 /*=================*/
726 /*********************************************************************/
729 UNIV_INTERN
730 ibool
731 buf_all_freed(void);
732 /*===============*/
733 /*********************************************************************/
737 UNIV_INTERN
738 ibool
739 buf_pool_check_no_pending_io(void);
740 /*==============================*/
741 /*********************************************************************/
745 UNIV_INTERN
746 void
747 buf_pool_invalidate(void);
748 /*=====================*/
749 #endif /* !UNIV_HOTBACKUP */
750 
751 /*========================================================================
752 --------------------------- LOWER LEVEL ROUTINES -------------------------
753 =========================================================================*/
754 
755 #ifdef UNIV_SYNC_DEBUG
756 /*********************************************************************/
760 UNIV_INLINE
761 void
762 buf_block_dbg_add_level(
763 /*====================*/
764  buf_block_t* block,
766  ulint level);
767 #else /* UNIV_SYNC_DEBUG */
768 # define buf_block_dbg_add_level(block, level) /* nothing */
769 #endif /* UNIV_SYNC_DEBUG */
770 /*********************************************************************/
773 UNIV_INLINE
774 enum buf_page_state
776 /*===============*/
777  const buf_page_t* bpage);
778 /*********************************************************************/
781 UNIV_INLINE
782 enum buf_page_state
784 /*================*/
785  const buf_block_t* block)
786  __attribute__((pure));
787 /*********************************************************************/
789 UNIV_INLINE
790 void
792 /*===============*/
793  buf_page_t* bpage,
794  enum buf_page_state state);
795 /*********************************************************************/
797 UNIV_INLINE
798 void
800 /*================*/
801  buf_block_t* block,
802  enum buf_page_state state);
803 /*********************************************************************/
806 UNIV_INLINE
807 ibool
809 /*=============*/
810  const buf_page_t* bpage)
811  __attribute__((pure));
812 #ifndef UNIV_HOTBACKUP
813 /*********************************************************************/
816 UNIV_INLINE
817 ibool
819 /*==========================*/
820  const buf_page_t* bpage)
821  __attribute__((pure));
822 
823 /*********************************************************************/
826 UNIV_INLINE
827 mutex_t*
829 /*===============*/
830  const buf_page_t* bpage)
831  __attribute__((pure));
832 
833 /*********************************************************************/
836 UNIV_INLINE
837 enum buf_flush
839 /*====================*/
840  const buf_page_t* bpage)
841  __attribute__((pure));
842 /*********************************************************************/
844 UNIV_INLINE
845 void
847 /*====================*/
848  buf_page_t* bpage,
849  enum buf_flush flush_type);
850 /*********************************************************************/
852 UNIV_INLINE
853 void
855 /*====================*/
856  buf_block_t* block,
857  ulint space,
858  ulint page_no);
859 /*********************************************************************/
862 UNIV_INLINE
863 enum buf_io_fix
865 /*================*/
866  const buf_page_t* bpage)
867  __attribute__((pure));
868 /*********************************************************************/
871 UNIV_INLINE
872 enum buf_io_fix
874 /*================*/
875  const buf_block_t* block)
876  __attribute__((pure));
877 /*********************************************************************/
879 UNIV_INLINE
880 void
882 /*================*/
883  buf_page_t* bpage,
884  enum buf_io_fix io_fix);
885 /*********************************************************************/
887 UNIV_INLINE
888 void
890 /*=================*/
891  buf_block_t* block,
892  enum buf_io_fix io_fix);
894 /********************************************************************/
897 UNIV_INLINE
898 ibool
900 /*==================*/
901  const buf_page_t* bpage)
902  __attribute__((pure));
903 
904 /*********************************************************************/
907 UNIV_INLINE
908 ibool
910 /*============*/
911  const buf_page_t* bpage)
912  __attribute__((pure));
913 /*********************************************************************/
915 UNIV_INLINE
916 void
918 /*=============*/
919  buf_page_t* bpage,
920  ibool old);
921 /*********************************************************************/
924 UNIV_INLINE
925 unsigned
927 /*=================*/
928  const buf_page_t* bpage)
929  __attribute__((nonnull, pure));
930 /*********************************************************************/
932 UNIV_INLINE
933 void
935 /*==================*/
936  buf_page_t* bpage,
937  ulint time_ms)
938  __attribute__((nonnull));
939 /*********************************************************************/
944 UNIV_INLINE
947 /*===============*/
948  buf_page_t* bpage)
949  __attribute__((pure));
950 #endif /* !UNIV_HOTBACKUP */
951 #ifdef UNIV_DEBUG
952 /*********************************************************************/
955 UNIV_INLINE
957 buf_block_get_frame(
958 /*================*/
959  const buf_block_t* block)
960  __attribute__((pure));
961 #else /* UNIV_DEBUG */
962 # define buf_block_get_frame(block) (block)->frame
963 #endif /* UNIV_DEBUG */
964 /*********************************************************************/
967 UNIV_INLINE
968 ulint
970 /*===============*/
971  const buf_page_t* bpage)
972  __attribute__((pure));
973 /*********************************************************************/
976 UNIV_INLINE
977 ulint
979 /*================*/
980  const buf_block_t* block)
981  __attribute__((pure));
982 /*********************************************************************/
985 UNIV_INLINE
986 ulint
988 /*=================*/
989  const buf_page_t* bpage)
990  __attribute__((pure));
991 /*********************************************************************/
994 UNIV_INLINE
995 ulint
997 /*==================*/
998  const buf_block_t* block)
999  __attribute__((pure));
1000 /*********************************************************************/
1003 UNIV_INLINE
1004 ulint
1006 /*==================*/
1007  const buf_page_t* bpage)
1008  __attribute__((pure));
1009 /*********************************************************************/
1012 UNIV_INLINE
1013 ulint
1015 /*===================*/
1016  const buf_block_t* block)
1017  __attribute__((pure));
1018 /*********************************************************************/
1021 #define buf_block_get_page_zip(block) \
1022  (UNIV_LIKELY_NULL((block)->page.zip.data) ? &(block)->page.zip : NULL)
1023 #ifndef UNIV_HOTBACKUP
1024 /*******************************************************************/
1027 UNIV_INTERN
1028 buf_block_t*
1029 buf_block_align(
1030 /*============*/
1031  const byte* ptr);
1032 /********************************************************************/
1036 UNIV_INTERN
1037 ibool
1038 buf_pointer_is_block_field(
1039 /*=======================*/
1040  const void* ptr);
1045 #define buf_pool_is_block_mutex(m) \
1046  buf_pointer_is_block_field((const void*)(m))
1047 
1050 #define buf_pool_is_block_lock(l) \
1051  buf_pointer_is_block_field((const void*)(l))
1052 
1053 #if defined UNIV_DEBUG || defined UNIV_ZIP_DEBUG
1054 /*********************************************************************/
1058 UNIV_INLINE
1059 const page_zip_des_t*
1060 buf_frame_get_page_zip(
1061 /*===================*/
1062  const byte* ptr);
1063 #endif /* UNIV_DEBUG || UNIV_ZIP_DEBUG */
1064 /********************************************************************/
1074 UNIV_INTERN
1075 buf_page_t*
1076 buf_page_init_for_read(
1077 /*===================*/
1078  ulint* err,
1079  ulint mode,
1080  ulint space,
1081  ulint zip_size,
1082  ibool unzip,
1083  ib_int64_t tablespace_version,
1086  ulint offset);
1087 /********************************************************************/
1090 UNIV_INTERN
1091 void
1092 buf_page_io_complete(
1093 /*=================*/
1094  buf_page_t* bpage);
1095 /********************************************************************/
1099 UNIV_INLINE
1100 ulint
1102 /*==================*/
1103  ulint space,
1104  ulint offset)
1105  __attribute__((const));
1106 /********************************************************************/
1109 UNIV_INLINE
1110 ulint
1112 /*===========*/
1113  const buf_pool_t* buf_pool)
1114  __attribute__((nonnull, const));
1115 /******************************************************************/
1118 UNIV_INLINE
1119 buf_pool_t*
1121 /*================*/
1122  const buf_page_t* bpage);
1123 /******************************************************************/
1126 UNIV_INLINE
1127 buf_pool_t*
1129 /*================*/
1130  const buf_block_t* block);
1131 /******************************************************************/
1134 UNIV_INLINE
1135 buf_pool_t*
1136 buf_pool_get(
1137 /*==========*/
1138  ulint space,
1139  ulint offset);
1140 /******************************************************************/
1143 UNIV_INLINE
1144 buf_pool_t*
1146 /*================*/
1147  ulint index);
1149 /******************************************************************/
1152 UNIV_INLINE
1153 buf_page_t*
1155 /*==================*/
1156  buf_pool_t* buf_pool,
1157  ulint space,
1158  ulint offset,
1160  ulint fold);
1162 /******************************************************************/
1165 UNIV_INLINE
1166 buf_page_t*
1168 /*==============*/
1169  buf_pool_t* buf_pool,
1170  ulint space,
1171  ulint offset);
1173 /******************************************************************/
1177 UNIV_INLINE
1178 buf_block_t*
1180 /*===============*/
1181  buf_pool_t* buf_pool,
1182  ulint space,
1183  ulint offset);
1185 /*********************************************************************/
1188 UNIV_INTERN
1189 ulint
1190 buf_get_free_list_len(void);
1191 /*=======================*/
1192 
1193 /********************************************************************
1194 Determine if a block is a sentinel for a buffer pool watch.
1195 @return TRUE if a sentinel for a buffer pool watch, FALSE if not */
1196 UNIV_INTERN
1197 ibool
1198 buf_pool_watch_is_sentinel(
1199 /*=======================*/
1200  buf_pool_t* buf_pool,
1201  const buf_page_t* bpage)
1202  UNIV_WARN_UNUSED_RESULT;
1203 /****************************************************************/
1206 UNIV_INTERN
1207 buf_page_t*
1208 buf_pool_watch_set(
1209 /*===============*/
1210  ulint space,
1211  ulint offset,
1212  ulint fold)
1213  UNIV_WARN_UNUSED_RESULT;
1214 /****************************************************************/
1217 UNIV_INTERN
1218 void
1219 buf_pool_watch_unset(
1220 /*=================*/
1221  ulint space,
1222  ulint offset);
1223 /****************************************************************/
1228 UNIV_INTERN
1229 ibool
1230 buf_pool_watch_occurred(
1231 /*====================*/
1232  ulint space,
1233  ulint offset)
1234  UNIV_WARN_UNUSED_RESULT;
1235 /********************************************************************/
1237 UNIV_INTERN
1238 void
1239 buf_get_total_list_len(
1240 /*===================*/
1241  ulint* LRU_len,
1242  ulint* free_len,
1243  ulint* flush_list_len);
1244 /********************************************************************/
1246 UNIV_INTERN
1247 void
1248 buf_get_total_stat(
1249 /*===============*/
1250  buf_pool_stat_t*tot_stat);
1252 #endif /* !UNIV_HOTBACKUP */
1253 
1257 struct buf_page_struct{
1264  /* @{ */
1265 
1266  unsigned space:32;
1268  unsigned offset:32;
1271  unsigned state:3;
1278 #ifndef UNIV_HOTBACKUP
1279  unsigned flush_type:2;
1283  unsigned io_fix:2;
1286  unsigned buf_fix_count:19;
1288  unsigned buf_pool_index:6;
1290 # if MAX_BUFFER_POOLS > 64
1291 # error "MAX_BUFFER_POOLS > 64; redefine buf_pool_index:6"
1292 # endif
1293  /* @} */
1294 #endif /* !UNIV_HOTBACKUP */
1301 #ifndef UNIV_HOTBACKUP
1302  buf_page_t* hash;
1305 #ifdef UNIV_DEBUG
1306  ibool in_page_hash;
1307  ibool in_zip_hash;
1308 #endif /* UNIV_DEBUG */
1309 
1312  /* @{ */
1313 
1314  UT_LIST_NODE_T(buf_page_t) list;
1342 #ifdef UNIV_DEBUG
1343  ibool in_flush_list;
1354  ibool in_free_list;
1358 #endif /* UNIV_DEBUG */
1359  ib_uint64_t newest_modification;
1365  ib_uint64_t oldest_modification;
1378  /* @} */
1382  /* @{ */
1383 
1386 #ifdef UNIV_DEBUG
1387  ibool in_LRU_list;
1390 #endif /* UNIV_DEBUG */
1391  unsigned old:1;
1393  unsigned freed_page_clock:31;
1401  unsigned access_time:32;
1404  /* @} */
1405 # if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
1406  ibool file_page_was_freed;
1409 # endif /* UNIV_DEBUG_FILE_ACCESSES || UNIV_DEBUG */
1410 #endif /* !UNIV_HOTBACKUP */
1411 };
1412 
1415 struct buf_block_struct{
1416 
1418  /* @{ */
1419 
1420  buf_page_t page;
1424  byte* frame;
1428 #ifndef UNIV_HOTBACKUP
1429  UT_LIST_NODE_T(buf_block_t) unzip_LRU;
1434 #ifdef UNIV_DEBUG
1435  ibool in_unzip_LRU_list;
1438 #endif /* UNIV_DEBUG */
1439  mutex_t mutex;
1445  rw_lock_t lock;
1447  unsigned lock_hash_val:32;
1463  /* @} */
1465  /* @{ */
1466 
1467  ib_uint64_t modify_clock;
1478  /* @} */
1481  /* @{ */
1482 
1483  ulint n_hash_helps;
1485  ulint n_fields;
1487  ulint n_bytes;
1489  ibool left_side;
1493  /* @} */
1494 
1504  /* @{ */
1505 
1506 #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
1507  ulint n_pointers;
1510 #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
1511  unsigned is_hashed:1;
1518  unsigned curr_n_fields:10;
1520  unsigned curr_n_bytes:15;
1522  unsigned curr_left_side:1;
1523  dict_index_t* index;
1525  /* @} */
1526 # ifdef UNIV_SYNC_DEBUG
1527 
1528  /* @{ */
1529  rw_lock_t debug_latch;
1533  /* @} */
1534 # endif
1535 #endif /* !UNIV_HOTBACKUP */
1536 };
1537 
1541 #define buf_block_state_valid(block) \
1542 (buf_block_get_state(block) >= BUF_BLOCK_NOT_USED \
1543  && (buf_block_get_state(block) <= BUF_BLOCK_REMOVE_HASH))
1544 
1545 #ifndef UNIV_HOTBACKUP
1546 /**********************************************************************/
1548 /* @{ */
1549 #define BUF_POOL_ZIP_FOLD_PTR(ptr) ((ulint) (ptr) / UNIV_PAGE_SIZE)
1550 #define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
1551 #define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t*) (b))
1552 /* @} */
1553 
1555 struct buf_pool_stat_struct{
1556  ulint n_page_gets;
1563  ulint n_pages_written;
1564  ulint n_pages_created;
1566  ulint n_ra_pages_read;
1571  ulint n_pages_made_young;
1573  ulint n_pages_not_made_young;
1577 };
1578 
1580 struct buf_buddy_stat_struct {
1582  ulint used;
1584  ib_uint64_t relocated;
1586  ib_uint64_t relocated_usec;
1587 };
1588 
1594 struct buf_pool_struct{
1597  /* @{ */
1598  mutex_t mutex;
1600  mutex_t zip_mutex;
1604  ulint instance_no;
1606  ulint old_pool_size;
1608  ulint LRU_old_ratio;
1610 #ifdef UNIV_DEBUG
1611  ulint buddy_n_frames;
1613 #endif
1614 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1615  ulint mutex_exit_forbidden;
1616 #endif
1617  ulint n_chunks;
1618  buf_chunk_t* chunks;
1619  ulint curr_size;
1628  ulint n_pend_reads;
1635  buf_buddy_stat_t buddy_stat[BUF_BUDDY_SIZES_MAX + 1];
1641  /* @} */
1642 
1645  /* @{ */
1646 
1654  UT_LIST_BASE_NODE_T(buf_page_t) flush_list;
1660  ulint n_flush[BUF_FLUSH_N_TYPES];
1663  os_event_t no_flush[BUF_FLUSH_N_TYPES];
1667  ib_rbt_t* flush_rbt;
1681  ulint freed_page_clock;
1690  ulint LRU_flush_ended;
1694  /* @} */
1695 
1697  /* @{ */
1698 
1704  buf_page_t* LRU_old;
1711  ulint LRU_old_len;
1719  UT_LIST_BASE_NODE_T(buf_block_t) unzip_LRU;
1723  /* @} */
1728  /* @{ */
1729  UT_LIST_BASE_NODE_T(buf_page_t) zip_clean;
1731  UT_LIST_BASE_NODE_T(buf_page_t) zip_free[BUF_BUDDY_SIZES_MAX];
1739 #if BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE
1740 # error "BUF_BUDDY_LOW > PAGE_ZIP_MIN_SIZE"
1741 #endif
1742  /* @} */
1743 };
1744 
1747 /* @{ */
1748 
1750 #define buf_pool_mutex_own(b) mutex_own(&b->mutex)
1751 
1752 #define buf_pool_mutex_enter(b) do { \
1753  ut_ad(!mutex_own(&b->zip_mutex)); \
1754  mutex_enter(&b->mutex); \
1755 } while (0)
1756 
1758 #define buf_flush_list_mutex_own(b) mutex_own(&b->flush_list_mutex)
1759 
1761 #define buf_flush_list_mutex_enter(b) do { \
1762  mutex_enter(&b->flush_list_mutex); \
1763 } while (0)
1764 
1765 # define buf_flush_list_mutex_exit(b) do { \
1766  mutex_exit(&b->flush_list_mutex); \
1767 } while (0)
1768 
1769 
1770 
1771 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
1772 
1773 # define buf_pool_mutex_exit_forbid(b) do { \
1774  ut_ad(buf_pool_mutex_own(b)); \
1775  b->mutex_exit_forbidden++; \
1776 } while (0)
1777 
1778 # define buf_pool_mutex_exit_allow(b) do { \
1779  ut_ad(buf_pool_mutex_own(b)); \
1780  ut_a(b->mutex_exit_forbidden); \
1781  b->mutex_exit_forbidden--; \
1782 } while (0)
1783 
1784 # define buf_pool_mutex_exit(b) do { \
1785  ut_a(!b->mutex_exit_forbidden); \
1786  mutex_exit(&b->mutex); \
1787 } while (0)
1788 #else
1789 
1790 # define buf_pool_mutex_exit_forbid(b) ((void) 0)
1791 
1792 # define buf_pool_mutex_exit_allow(b) ((void) 0)
1793 
1794 # define buf_pool_mutex_exit(b) mutex_exit(&b->mutex)
1795 #endif
1796 #endif /* !UNIV_HOTBACKUP */
1797 /* @} */
1798 
1799 /**********************************************************************
1800 Let us list the consistency conditions for different control block states.
1801 
1802 NOT_USED: is in free list, not in LRU list, not in flush list, nor
1803  page hash table
1804 READY_FOR_USE: is not in free list, LRU list, or flush list, nor page
1805  hash table
1806 MEMORY: is not in free list, LRU list, or flush list, nor page
1807  hash table
1808 FILE_PAGE: space and offset are defined, is in page hash table
1809  if io_fix == BUF_IO_WRITE,
1810  pool: no_flush[flush_type] is in reset state,
1811  pool: n_flush[flush_type] > 0
1812 
1813  (1) if buf_fix_count == 0, then
1814  is in LRU list, not in free list
1815  is in flush list,
1816  if and only if oldest_modification > 0
1817  is x-locked,
1818  if and only if io_fix == BUF_IO_READ
1819  is s-locked,
1820  if and only if io_fix == BUF_IO_WRITE
1821 
1822  (2) if buf_fix_count > 0, then
1823  is not in LRU list, not in free list
1824  is in flush list,
1825  if and only if oldest_modification > 0
1826  if io_fix == BUF_IO_READ,
1827  is x-locked
1828  if io_fix == BUF_IO_WRITE,
1829  is s-locked
1830 
1831 State transitions:
1832 
1833 NOT_USED => READY_FOR_USE
1834 READY_FOR_USE => MEMORY
1835 READY_FOR_USE => FILE_PAGE
1836 MEMORY => NOT_USED
1837 FILE_PAGE => NOT_USED NOTE: This transition is allowed if and only if
1838  (1) buf_fix_count == 0,
1839  (2) oldest_modification == 0, and
1840  (3) io_fix == 0.
1841 */
1842 
1843 #ifndef UNIV_NONINL
1844 #include "buf0buf.ic"
1845 #endif
1846 
1847 #endif