~percona-dev/percona-server/release-5.1.51-11-bug_fix_611844

« back to all changes in this revision

Viewing changes to innodb_buffer_pool_shm.patch

fix innodb_buffer_pool_shm.patch for -Wpointer-arith warnings of GCC

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
+       ptrdiff_t       frame_offset)
63
63
+{
64
64
+       /* block_init */
65
 
+       block->frame = ((void*)(block->frame) + frame_offset);
 
65
+       block->frame += frame_offset;
66
66
+
67
67
+       UNIV_MEM_DESC(block->frame, UNIV_PAGE_SIZE, block);
68
68
+
79
79
+#endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */
80
80
+
81
81
+       if (block->page.zip.data)
82
 
+               block->page.zip.data = ((void*)(block->page.zip.data) + frame_offset);
 
82
+               block->page.zip.data += frame_offset;
83
83
+
84
84
+       block->is_hashed = FALSE;
85
85
+
144
144
+               "InnoDB: Otherwise, data corruption in datafiles may result.\n");
145
145
+
146
146
+               /* FIXME: This is vague id still */
147
 
+               binary_id = (ulint) ((void*)mtr_commit - (void*)btr_root_get)
148
 
+                         + (ulint) ((void*)os_get_os_version - (void*)buf_calc_page_new_checksum)
149
 
+                         + (ulint) ((void*)page_dir_find_owner_slot - (void*)dfield_data_is_binary_equal)
150
 
+                         + (ulint) ((void*)que_graph_publish - (void*)dict_casedn_str)
151
 
+                         + (ulint) ((void*)read_view_oldest_copy_or_open_new - (void*)fil_space_get_version)
152
 
+                         + (ulint) ((void*)rec_get_n_extern_new - (void*)fsp_get_size_low)
153
 
+                         + (ulint) ((void*)row_get_trx_id_offset - (void*)ha_create_func)
154
 
+                         + (ulint) ((void*)srv_set_io_thread_op_info - (void*)thd_is_replication_slave_thread)
155
 
+                         + (ulint) ((void*)mutex_create_func - (void*)ibuf_inside)
156
 
+                         + (ulint) ((void*)trx_set_detailed_error - (void*)lock_check_trx_id_sanity)
157
 
+                         + (ulint) ((void*)ut_time - (void*)mem_heap_strdup);
 
147
+               binary_id = (ulint) ((byte*)mtr_commit - (byte*)btr_root_get)
 
148
+                         + (ulint) ((byte*)os_get_os_version - (byte*)buf_calc_page_new_checksum)
 
149
+                         + (ulint) ((byte*)page_dir_find_owner_slot - (byte*)dfield_data_is_binary_equal)
 
150
+                         + (ulint) ((byte*)que_graph_publish - (byte*)dict_casedn_str)
 
151
+                         + (ulint) ((byte*)read_view_oldest_copy_or_open_new - (byte*)fil_space_get_version)
 
152
+                         + (ulint) ((byte*)rec_get_n_extern_new - (byte*)fsp_get_size_low)
 
153
+                         + (ulint) ((byte*)row_get_trx_id_offset - (byte*)ha_create_func)
 
154
+                         + (ulint) ((byte*)srv_set_io_thread_op_info - (byte*)thd_is_replication_slave_thread)
 
155
+                         + (ulint) ((byte*)mutex_create_func - (byte*)ibuf_inside)
 
156
+                         + (ulint) ((byte*)trx_set_detailed_error - (byte*)lock_check_trx_id_sanity)
 
157
+                         + (ulint) ((byte*)ut_time - (byte*)mem_heap_strdup);
158
158
+
159
159
+               chunk->mem = os_shm_alloc(&chunk->mem_size, srv_buffer_pool_shm_key, &is_new);
160
160
+
170
170
+
171
171
+               shm_info = chunk->mem;
172
172
+
173
 
+               zip_hash_tmp = (hash_table_t*)((void*)chunk->mem + chunk->mem_size - zip_hash_mem_size);
 
173
+               zip_hash_tmp = (hash_table_t*)((byte*)chunk->mem + chunk->mem_size - zip_hash_mem_size);
174
174
+
175
175
+               if (is_new) {
176
176
+                       strncpy(shm_info->head_str, BUF_SHM_INFO_HEAD, 8);
227
227
+                       ut_a(shm_info->zip_hash_n == zip_hash_n);
228
228
+
229
229
+                       /* check checksum */
230
 
+                       checksum = ut_fold_binary(chunk->mem + sizeof(buf_shm_info_t),
 
230
+                       checksum = ut_fold_binary((byte*)chunk->mem + sizeof(buf_shm_info_t),
231
231
+                                                 chunk->mem_size - sizeof(buf_shm_info_t));
232
232
+                       if (shm_info->checksum != checksum) {
233
233
+                               fprintf(stderr,
260
260
        /* Allocate the block descriptors from
261
261
        the start of the memory block. */
262
262
+       if (srv_buffer_pool_shm_key) {
263
 
+               chunk->blocks = chunk->mem + sizeof(buf_shm_info_t);
 
263
+               chunk->blocks = (buf_block_t*)((byte*)chunk->mem + sizeof(buf_shm_info_t));
264
264
+       } else {
265
265
        chunk->blocks = chunk->mem;
266
266
+       }
267
267
 
268
268
        /* Align a pointer to the first frame.  Note that when
269
269
        os_large_page_size is smaller than UNIV_PAGE_SIZE,
270
 
@@ -795,8 +1003,13 @@
 
270
@@ -795,8 +1006,13 @@
271
271
        it is bigger, we may allocate more blocks than requested. */
272
272
 
273
273
        frame = ut_align(chunk->mem, UNIV_PAGE_SIZE);
281
281
 
282
282
        /* Subtract the space needed for block descriptors. */
283
283
        {
284
 
@@ -810,6 +1023,98 @@
 
284
@@ -810,6 +1026,98 @@
285
285
                chunk->size = size;
286
286
        }
287
287
 
301
301
+               }
302
302
+
303
303
+               chunk->size = shm_info->chunk_backup.size;
304
 
+               phys_offset = (void*)frame - (void*)((void*)chunk->mem + shm_info->frame_offset);
305
 
+               logi_offset = (void*)frame - (void*)chunk->blocks[0].frame;
 
304
+               phys_offset = frame - (byte*)chunk->mem + shm_info->frame_offset;
 
305
+               logi_offset = frame - chunk->blocks[0].frame;
306
306
+               previous_frame_address = chunk->blocks[0].frame;
307
 
+               blocks_offset = (void*)chunk->blocks - (void*)shm_info->chunk_backup.blocks;
 
307
+               blocks_offset = (byte*)chunk->blocks - (byte*)shm_info->chunk_backup.blocks;
308
308
+
309
309
+               if (phys_offset || logi_offset || blocks_offset) {
310
310
+                       fprintf(stderr,
315
315
+                       "InnoDB: Pysical offset                  : %ld (%#lx)\n"
316
316
+                       "InnoDB: Logical offset (frames)         : %ld (%#lx)\n"
317
317
+                       "InnoDB: Logical offset (blocks)         : %ld (%#lx)\n",
318
 
+                               (void*)((void*)chunk->mem + shm_info->frame_offset),
319
 
+                               (void*)chunk->blocks[0].frame, (void*)frame,
 
318
+                               (byte*)chunk->mem + shm_info->frame_offset,
 
319
+                               chunk->blocks[0].frame, frame,
320
320
+                               phys_offset, phys_offset, logi_offset, logi_offset,
321
321
+                               blocks_offset, blocks_offset);
322
322
+               } else {
328
328
+                       fprintf(stderr,
329
329
+                       "InnoDB: Aligning physical offset...");
330
330
+
331
 
+                       memmove((void*)frame, (void*)((void*)chunk->mem + shm_info->frame_offset),
 
331
+                       memmove(frame, (byte*)chunk->mem + shm_info->frame_offset,
332
332
+                               chunk->size * UNIV_PAGE_SIZE);
333
333
+
334
334
+                       fprintf(stderr,
356
356
+                                       previous_frame_address, logi_offset, blocks_offset);
357
357
+                       if (shm_info->buf_pool_backup.LRU_old)
358
358
+                               shm_info->buf_pool_backup.LRU_old =
359
 
+                                       ((void*)(shm_info->buf_pool_backup.LRU_old)
 
359
+                                       (buf_page_t*)((byte*)(shm_info->buf_pool_backup.LRU_old)
360
360
+                                               + (((void*)shm_info->buf_pool_backup.LRU_old > previous_frame_address)
361
361
+                                                 ? logi_offset : blocks_offset));
362
362
+
380
380
        /* Init block structs and assign frames for them. Then we
381
381
        assign the frames to the first blocks (we already mapped the
382
382
        memory above). */
383
 
@@ -833,6 +1138,11 @@
 
383
@@ -833,6 +1141,11 @@
384
384
                block++;
385
385
                frame += UNIV_PAGE_SIZE;
386
386
        }
387
387
+       }
388
388
+
389
389
+       if (shm_info) {
390
 
+               shm_info->frame_offset = (void*)chunk->blocks[0].frame - (void*)chunk->mem;
 
390
+               shm_info->frame_offset = chunk->blocks[0].frame - (byte*)chunk->mem;
391
391
+       }
392
392
 
393
393
        return(chunk);
394
394
 }
395
 
@@ -1014,6 +1324,8 @@
 
395
@@ -1014,6 +1327,8 @@
396
396
                UNIV_MEM_UNDESC(block);
397
397
        }
398
398
 
401
401
        os_mem_free_large(chunk->mem, chunk->mem_size);
402
402
 }
403
403
 
404
 
@@ -1063,7 +1375,10 @@
 
404
@@ -1063,7 +1378,10 @@
405
405
        srv_buf_pool_curr_size = buf_pool->curr_size * UNIV_PAGE_SIZE;
406
406
 
407
407
        buf_pool->page_hash = hash_create(2 * buf_pool->curr_size);
412
412
 
413
413
        buf_pool->last_printout_time = time(NULL);
414
414
 
415
 
@@ -1078,6 +1393,86 @@
 
415
@@ -1078,6 +1396,86 @@
416
416
        --------------------------- */
417
417
        /* All fields are initialized by mem_zalloc(). */
418
418
 
419
419
+       if (srv_buffer_pool_shm_key) {
420
420
+               buf_shm_info_t* shm_info;
421
421
+
422
 
+               ut_a(chunk->blocks == chunk->mem + sizeof(buf_shm_info_t));
 
422
+               ut_a((byte*)chunk->blocks == (byte*)chunk->mem + sizeof(buf_shm_info_t));
423
423
+               shm_info = chunk->mem;
424
424
+
425
 
+               buf_pool->zip_hash = (hash_table_t*)((void*)chunk->mem + shm_info->zip_hash_offset);
 
425
+               buf_pool->zip_hash = (hash_table_t*)((byte*)chunk->mem + shm_info->zip_hash_offset);
426
426
+
427
427
+               if(shm_info->is_new) {
428
428
+                       shm_info->is_new = FALSE; /* initialization was finished */
499
499
        mutex_exit(&LRU_list_mutex);
500
500
        rw_lock_x_unlock(&page_hash_latch);
501
501
        buf_pool_mutex_exit();
502
 
@@ -1102,6 +1497,30 @@
 
502
@@ -1102,6 +1500,30 @@
503
503
        buf_chunk_t*    chunk;
504
504
        buf_chunk_t*    chunks;
505
505
 
510
510
+
511
511
+               chunk = buf_pool->chunks;
512
512
+               shm_info = chunk->mem;
513
 
+               ut_a(chunk->blocks == chunk->mem + sizeof(buf_shm_info_t));
 
513
+               ut_a((byte*)chunk->blocks == (byte*)chunk->mem + sizeof(buf_shm_info_t));
514
514
+
515
515
+               /* validation the shared memory segment doesn't have unrecoverable contents. */
516
516
+               /* Currently, validation became not needed */
520
520
+               memcpy(&(shm_info->chunk_backup), chunk, sizeof(buf_chunk_t));
521
521
+
522
522
+               if (srv_fast_shutdown < 2) {
523
 
+                       shm_info->checksum = ut_fold_binary(chunk->mem + sizeof(buf_shm_info_t),
 
523
+                       shm_info->checksum = ut_fold_binary((byte*)chunk->mem + sizeof(buf_shm_info_t),
524
524
+                                                           chunk->mem_size - sizeof(buf_shm_info_t));
525
525
+                       shm_info->clean = TRUE;
526
526
+               }
530
530
        chunks = buf_pool->chunks;
531
531
        chunk = chunks + buf_pool->n_chunks;
532
532
 
533
 
@@ -1110,10 +1529,13 @@
 
533
@@ -1110,10 +1532,13 @@
534
534
                would fail at shutdown. */
535
535
                os_mem_free_large(chunk->mem, chunk->mem_size);
536
536
        }
544
544
        mem_free(buf_pool);
545
545
        buf_pool = NULL;
546
546
 }
547
 
@@ -1308,6 +1730,11 @@
 
547
@@ -1308,6 +1733,11 @@
548
548
        //buf_pool_mutex_enter();
549
549
        mutex_enter(&LRU_list_mutex);
550
550
 
556
556
 shrink_again:
557
557
        if (buf_pool->n_chunks <= 1) {
558
558
 
559
 
@@ -1551,6 +1978,11 @@
 
559
@@ -1551,6 +1981,11 @@
560
560
 buf_pool_resize(void)
561
561
 /*=================*/
562
562
 {
608
608
+       offset = (sizeof(hash_table_t) + 7) / 8;
609
609
+       offset *= 8;
610
610
+
611
 
+       table->array = (hash_cell_t*)(((void*)table) + offset);
 
611
+       table->array = (hash_cell_t*)(((byte*)table) + offset);
612
612
+       table->n_cells = prime;
613
613
+# if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG
614
614
+       table->adaptive = FALSE;
634
634
+       offset = (sizeof(hash_table_t) + 7) / 8;
635
635
+       offset *= 8;
636
636
+
637
 
+       table->array = (hash_cell_t*)(((void*)table) + offset);
 
637
+       table->array = (hash_cell_t*)(((byte*)table) + offset);
638
638
+       ut_ad(table->magic_n == HASH_TABLE_MAGIC_N);
639
639
+}
640
640
+
694
694
+/* the fold should be relative when srv_buffer_pool_shm_key is enabled */
695
695
+#define BUF_POOL_ZIP_FOLD_PTR(ptr) (!srv_buffer_pool_shm_key\
696
696
+                                       ?((ulint) (ptr) / UNIV_PAGE_SIZE)\
697
 
+                                       :((ulint) ((void*)ptr - (void*)(buf_pool->chunks->blocks->frame)) / UNIV_PAGE_SIZE))
 
697
+                                       :((ulint) ((byte*)ptr - (byte*)(buf_pool->chunks->blocks->frame)) / UNIV_PAGE_SIZE))
698
698
 #define BUF_POOL_ZIP_FOLD(b) BUF_POOL_ZIP_FOLD_PTR((b)->frame)
699
699
 #define BUF_POOL_ZIP_FOLD_BPAGE(b) BUF_POOL_ZIP_FOLD((buf_block_t*) (b))
700
700
 /* @} */
748
748
+               NODE_TYPE*      node2222;\
749
749
+\
750
750
+               if ((TABLE)->array[i2222].node) \
751
 
+                       (TABLE)->array[i2222].node \
752
 
+                       += (((TABLE)->array[i2222].node > (void*)FADDR)?FOFFSET:BOFFSET);\
 
751
+                       (TABLE)->array[i2222].node = (void*)((byte*)(TABLE)->array[i2222].node \
 
752
+                       + (((TABLE)->array[i2222].node > (void*)FADDR)?FOFFSET:BOFFSET));\
753
753
+               node2222 = HASH_GET_FIRST((TABLE), i2222);\
754
754
+\
755
755
+               while (node2222) {\
756
756
+                       if (node2222->PTR_NAME) \
757
 
+                               node2222->PTR_NAME = ((void*)node2222->PTR_NAME) \
758
 
+                               + ((((void*)node2222->PTR_NAME) > (void*)FADDR)?FOFFSET:BOFFSET);\
 
757
+                               node2222->PTR_NAME = (void*)((byte*)(node2222->PTR_NAME) \
 
758
+                               + ((((void*)node2222->PTR_NAME) > (void*)FADDR)?FOFFSET:BOFFSET));\
759
759
+\
760
760
+                       node2222 = node2222->PTR_NAME;\
761
761
+               }\
840
840
+       TYPE*   ut_list_node_313;                                       \
841
841
+                                                                       \
842
842
+       if ((BASE).start)                                               \
843
 
+               (BASE).start = ((void*)((BASE).start)                   \
 
843
+               (BASE).start = (void*)((byte*)((BASE).start)                    \
844
844
+                       + (((void*)((BASE).start) > (void*)FADDR)?FOFFSET:BOFFSET));\
845
845
+       if ((BASE).end)                                                 \
846
 
+               (BASE).end   = ((void*)((BASE).end)                     \
 
846
+               (BASE).end   = (void*)((byte*)((BASE).end)                      \
847
847
+                       + (((void*)((BASE).end) > (void*)FADDR)?FOFFSET:BOFFSET));\
848
848
+                                                                       \
849
849
+       ut_list_node_313 = (BASE).start;                                \
851
851
+       for (ut_list_i_313 = (BASE).count; ut_list_i_313--; ) {         \
852
852
+               ut_a(ut_list_node_313);                                 \
853
853
+               if ((ut_list_node_313->NAME).prev)                      \
854
 
+                       (ut_list_node_313->NAME).prev = ((void*)((ut_list_node_313->NAME).prev)\
 
854
+                       (ut_list_node_313->NAME).prev = (void*)((byte*)((ut_list_node_313->NAME).prev)\
855
855
+                               + (((void*)((ut_list_node_313->NAME).prev) > (void*)FADDR)?FOFFSET:BOFFSET));\
856
856
+               if ((ut_list_node_313->NAME).next)                      \
857
 
+                       (ut_list_node_313->NAME).next = ((void*)((ut_list_node_313->NAME).next)\
 
857
+                       (ut_list_node_313->NAME).next = (void*)((byte*)((ut_list_node_313->NAME).next)\
858
858
+                               + (((void*)((ut_list_node_313->NAME).next)> (void*)FADDR)?FOFFSET:BOFFSET));\
859
859
+               ut_list_node_313 = (ut_list_node_313->NAME).next;       \
860
860
+       }                                                               \
894
894
+       ibool*  is_new)
895
895
+{
896
896
+       void*   ptr;
 
897
+#if defined HAVE_SYS_IPC_H && HAVE_SYS_SHM_H
897
898
+       ulint   size;
898
899
+       int     shmid;
899
900
+
900
901
+       *is_new = FALSE;
901
 
+#if defined HAVE_SYS_IPC_H && HAVE_SYS_SHM_H
902
902
+       fprintf(stderr,
903
903
+               "InnoDB: The shared memory segment containing the buffer pool is: key  %#x (%d).\n",
904
904
+               key, key);