1 # name : innodb_opt_lru_count.patch
2 # introduced : 11 or before
3 # maintainer : Yasufumi
6 # Any small change to this file in the main branch
7 # should be done or reviewed by the maintainer!
8 diff -ruN a/storage/innobase/buf/buf0buddy.c b/storage/innobase/buf/buf0buddy.c
9 --- a/storage/innobase/buf/buf0buddy.c 2010-11-03 07:01:13.000000000 +0900
10 +++ b/storage/innobase/buf/buf0buddy.c 2010-12-03 15:20:49.593024343 +0900
12 ut_ad(buf_page_get_state(ut_list_node_313)
13 == BUF_BLOCK_ZIP_FREE)));
14 #endif /* !UNIV_DEBUG_VALGRIND */
15 - bpage = UT_LIST_GET_FIRST(buf_pool->zip_free[i]);
16 + bpage = UT_LIST_GET_LAST(buf_pool->zip_free[i]);
19 UNIV_MEM_VALID(bpage, BUF_BUDDY_LOW << i);
20 diff -ruN a/storage/innobase/buf/buf0buf.c b/storage/innobase/buf/buf0buf.c
21 --- a/storage/innobase/buf/buf0buf.c 2010-12-03 15:18:48.866986963 +0900
22 +++ b/storage/innobase/buf/buf0buf.c 2010-12-03 15:20:49.595987311 +0900
24 block->page.in_zip_hash = FALSE;
25 block->page.in_flush_list = FALSE;
26 block->page.in_free_list = FALSE;
27 - block->page.in_LRU_list = FALSE;
28 block->in_unzip_LRU_list = FALSE;
29 #endif /* UNIV_DEBUG */
30 + block->page.in_LRU_list = FALSE;
31 #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
32 block->n_pointers = 0;
33 #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
36 memcpy(dpage, bpage, sizeof *dpage);
38 - ut_d(bpage->in_LRU_list = FALSE);
39 + bpage->in_LRU_list = FALSE;
40 ut_d(bpage->in_page_hash = FALSE);
42 /* relocate buf_pool->LRU */
44 bpage->in_zip_hash = FALSE;
45 bpage->in_flush_list = FALSE;
46 bpage->in_free_list = FALSE;
47 - bpage->in_LRU_list = FALSE;
48 #endif /* UNIV_DEBUG */
49 + bpage->in_LRU_list = FALSE;
51 ut_d(bpage->in_page_hash = TRUE);
54 ibuf_merge_or_delete_for_page(NULL, space, offset, zip_size, TRUE);
56 /* Flush pages from the end of the LRU list if necessary */
57 - buf_flush_free_margin(buf_pool);
58 + buf_flush_free_margin(buf_pool, FALSE);
62 diff -ruN a/storage/innobase/buf/buf0flu.c b/storage/innobase/buf/buf0flu.c
63 --- a/storage/innobase/buf/buf0flu.c 2010-12-03 15:18:48.868953442 +0900
64 +++ b/storage/innobase/buf/buf0flu.c 2010-12-03 15:20:49.599986956 +0900
66 buf_page_in_file(bpage) and in the LRU list */
69 - buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
70 - ut_ad(buf_pool_mutex_own(buf_pool));
71 + //buf_pool_t* buf_pool = buf_pool_from_bpage(bpage);
72 + //ut_ad(buf_pool_mutex_own(buf_pool));
74 - ut_ad(mutex_own(buf_page_get_mutex(bpage)));
75 - ut_ad(bpage->in_LRU_list);
76 + //ut_ad(mutex_own(buf_page_get_mutex(bpage)));
77 + //ut_ad(bpage->in_LRU_list);
79 - if (UNIV_LIKELY(buf_page_in_file(bpage))) {
80 + if (UNIV_LIKELY(bpage->in_LRU_list && buf_page_in_file(bpage))) {
82 return(bpage->oldest_modification == 0
83 && buf_page_get_io_fix(bpage) == BUF_IO_NONE
84 && bpage->buf_fix_count == 0);
87 + /* permited not to own LRU_mutex.. */
89 ut_print_timestamp(stderr);
91 " InnoDB: Error: buffer block state %lu"
93 (ulong) buf_page_get_state(bpage));
94 ut_print_buf(stderr, bpage, sizeof(buf_page_t));
100 @@ -1983,8 +1986,14 @@
104 + ibool have_LRU_mutex = FALSE;
106 - buf_pool_mutex_enter(buf_pool);
107 + if(UT_LIST_GET_LEN(buf_pool->unzip_LRU))
108 + have_LRU_mutex = TRUE;
110 + //buf_pool_mutex_enter(buf_pool);
111 + if (have_LRU_mutex)
112 + buf_pool_mutex_enter(buf_pool);
114 n_replaceable = UT_LIST_GET_LEN(buf_pool->free);
116 @@ -1995,7 +2004,13 @@
117 + BUF_FLUSH_EXTRA_MARGIN(buf_pool))
118 && (distance < BUF_LRU_FREE_SEARCH_LEN(buf_pool))) {
120 - mutex_t* block_mutex = buf_page_get_mutex(bpage);
121 + mutex_t* block_mutex;
122 + if (!bpage->in_LRU_list) {
123 + /* reatart. but it is very optimistic */
124 + bpage = UT_LIST_GET_LAST(buf_pool->LRU);
127 + block_mutex = buf_page_get_mutex(bpage);
129 mutex_enter(block_mutex);
131 @@ -2010,11 +2025,18 @@
132 bpage = UT_LIST_GET_PREV(LRU, bpage);
135 - buf_pool_mutex_exit(buf_pool);
136 + //buf_pool_mutex_exit(buf_pool);
137 + if (have_LRU_mutex)
138 + buf_pool_mutex_exit(buf_pool);
140 if (n_replaceable >= BUF_FLUSH_FREE_BLOCK_MARGIN(buf_pool)) {
143 + } else if (!have_LRU_mutex) {
144 + /* confirm it again with LRU_mutex for exactness */
145 + have_LRU_mutex = TRUE;
150 return(BUF_FLUSH_FREE_BLOCK_MARGIN(buf_pool)
151 @@ -2032,7 +2054,8 @@
153 buf_flush_free_margin(
154 /*==================*/
155 - buf_pool_t* buf_pool) /*!< in: Buffer pool instance */
156 + buf_pool_t* buf_pool, /*!< in: Buffer pool instance */
161 @@ -2043,7 +2066,7 @@
163 n_flushed = buf_flush_LRU(buf_pool, n_to_flush);
165 - if (n_flushed == ULINT_UNDEFINED) {
166 + if (wait && n_flushed == ULINT_UNDEFINED) {
167 /* There was an LRU type flush batch already running;
168 let us wait for it to end */
170 @@ -2056,8 +2079,9 @@
171 Flushes pages from the end of all the LRU lists. */
174 -buf_flush_free_margins(void)
175 +buf_flush_free_margins(
176 /*========================*/
181 @@ -2066,7 +2090,7 @@
183 buf_pool = buf_pool_from_array(i);
185 - buf_flush_free_margin(buf_pool);
186 + buf_flush_free_margin(buf_pool, wait);
190 diff -ruN a/storage/innobase/buf/buf0lru.c b/storage/innobase/buf/buf0lru.c
191 --- a/storage/innobase/buf/buf0lru.c 2010-11-03 07:01:13.000000000 +0900
192 +++ b/storage/innobase/buf/buf0lru.c 2010-12-03 15:20:49.602952786 +0900
195 /* No free block was found: try to flush the LRU list */
197 - buf_flush_free_margin(buf_pool);
198 + buf_flush_free_margin(buf_pool, TRUE);
199 ++srv_buf_pool_wait_free;
201 os_aio_simulated_wake_handler_threads();
202 @@ -1193,7 +1193,7 @@
204 /* Remove the block from the LRU list */
205 UT_LIST_REMOVE(LRU, buf_pool->LRU, bpage);
206 - ut_d(bpage->in_LRU_list = FALSE);
207 + bpage->in_LRU_list = FALSE;
209 buf_unzip_LRU_remove_block_if_needed(bpage);
211 @@ -1272,7 +1272,7 @@
213 ut_ad(!bpage->in_LRU_list);
214 UT_LIST_ADD_LAST(LRU, buf_pool->LRU, bpage);
215 - ut_d(bpage->in_LRU_list = TRUE);
216 + bpage->in_LRU_list = TRUE;
218 if (UT_LIST_GET_LEN(buf_pool->LRU) > BUF_LRU_OLD_MIN_LEN) {
220 @@ -1342,7 +1342,7 @@
221 buf_pool->LRU_old_len++;
224 - ut_d(bpage->in_LRU_list = TRUE);
225 + bpage->in_LRU_list = TRUE;
227 if (UT_LIST_GET_LEN(buf_pool->LRU) > BUF_LRU_OLD_MIN_LEN) {
229 @@ -1593,7 +1593,7 @@
230 buf_page_set_old(b, buf_page_is_old(b));
231 #endif /* UNIV_LRU_DEBUG */
233 - ut_d(b->in_LRU_list = FALSE);
234 + b->in_LRU_list = FALSE;
235 buf_LRU_add_block_low(b, buf_page_is_old(b));
238 diff -ruN a/storage/innobase/buf/buf0rea.c b/storage/innobase/buf/buf0rea.c
239 --- a/storage/innobase/buf/buf0rea.c 2010-12-03 15:18:48.870953384 +0900
240 +++ b/storage/innobase/buf/buf0rea.c 2010-12-03 15:20:49.604956032 +0900
244 /* Flush pages from the end of the LRU list if necessary */
245 - buf_flush_free_margin(buf_pool);
246 + buf_flush_free_margin(buf_pool, TRUE);
248 /* Increment number of I/O operations used for LRU policy. */
249 buf_LRU_stat_inc_io();
251 os_aio_simulated_wake_handler_threads();
253 /* Flush pages from the end of the LRU list if necessary */
254 - buf_flush_free_margin(buf_pool);
255 + buf_flush_free_margin(buf_pool, TRUE);
258 if (buf_debug_prints && (count > 0)) {
260 os_aio_simulated_wake_handler_threads();
262 /* Flush pages from the end of all the LRU lists if necessary */
263 - buf_flush_free_margins();
264 + buf_flush_free_margins(FALSE);
267 if (buf_debug_prints) {
269 os_aio_simulated_wake_handler_threads();
271 /* Flush pages from the end of all the LRU lists if necessary */
272 - buf_flush_free_margins();
273 + buf_flush_free_margins(FALSE);
276 if (buf_debug_prints) {
277 diff -ruN a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h
278 --- a/storage/innobase/include/buf0buf.h 2010-11-03 07:01:13.000000000 +0900
279 +++ b/storage/innobase/include/buf0buf.h 2010-12-03 15:20:49.608986590 +0900
280 @@ -1387,11 +1387,11 @@
282 UT_LIST_NODE_T(buf_page_t) LRU;
283 /*!< node of the LRU list */
286 ibool in_LRU_list; /*!< TRUE if the page is in
287 the LRU list; used in
289 -#endif /* UNIV_DEBUG */
290 +//#endif /* UNIV_DEBUG */
291 unsigned old:1; /*!< TRUE if the block is in the old
292 blocks in buf_pool->LRU_old */
293 unsigned freed_page_clock:31;/*!< the value of
294 diff -ruN a/storage/innobase/include/buf0flu.h b/storage/innobase/include/buf0flu.h
295 --- a/storage/innobase/include/buf0flu.h 2010-11-03 07:01:13.000000000 +0900
296 +++ b/storage/innobase/include/buf0flu.h 2010-12-03 15:20:49.609953185 +0900
299 buf_flush_free_margin(
300 /*==================*/
301 - buf_pool_t* buf_pool);
302 + buf_pool_t* buf_pool,
304 /*********************************************************************//**
305 Flushes pages from the end of all the LRU lists. */
308 -buf_flush_free_margins(void);
309 +buf_flush_free_margins(
310 /*=========================*/
312 #endif /* !UNIV_HOTBACKUP */
313 /********************************************************************//**
314 Initializes a page for writing to the tablespace. */