Merge lp:~akopytov/percona-server/bug1131187 into lp:percona-server/5.5

Proposed by Alexey Kopytov
Status: Merged
Approved by: Stewart Smith
Approved revision: 451
Merged at revision: 480
Proposed branch: lp:~akopytov/percona-server/bug1131187
Merge into: lp:percona-server/5.5
Diff against target: 327 lines (+75/-37)
7 files modified
Percona-Server/storage/innobase/include/read0read.h (+14/-4)
Percona-Server/storage/innobase/include/trx0purge.h (+1/-0)
Percona-Server/storage/innobase/include/trx0trx.h (+1/-3)
Percona-Server/storage/innobase/read/read0read.c (+45/-16)
Percona-Server/storage/innobase/row/row0sel.c (+1/-1)
Percona-Server/storage/innobase/trx/trx0purge.c (+6/-3)
Percona-Server/storage/innobase/trx/trx0trx.c (+7/-10)
To merge this branch: bzr merge lp:~akopytov/percona-server/bug1131187
Reviewer Review Type Date Requested Status
Stewart Smith (community) Approve
Review via email: mp+149835@code.launchpad.net

Description of the change

  Bug #1131187: Remove malloc() from read_view_create_low()

  Avoid malloc() thrashing in read_view_create_low() by using a
  pre-allocated view array.

http://jenkins.percona.com/view/PS%205.5/job/percona-server-5.5-param/682/

To post a comment you must log in.
451. By Alexey Kopytov

Bug #1131187: Remove malloc() from read_view_create_low()

Avoid malloc() thrashing in read_view_create_low() by using a
pre-allocated view array.

Revision history for this message
Stewart Smith (stewart) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Percona-Server/storage/innobase/include/read0read.h'
--- Percona-Server/storage/innobase/include/read0read.h 2012-04-18 23:24:45 +0000
+++ Percona-Server/storage/innobase/include/read0read.h 2013-03-15 09:57:21 +0000
@@ -44,8 +44,8 @@
44/*===============*/44/*===============*/
45 trx_id_t cr_trx_id, /*!< in: trx_id of creating45 trx_id_t cr_trx_id, /*!< in: trx_id of creating
46 transaction, or 0 used in purge */46 transaction, or 0 used in purge */
47 mem_heap_t* heap); /*!< in: memory heap from which47 read_view_t* view); /*!< in: pre-allocated view array or
48 allocated */48 NULL if a new one needs to be created */
49/*********************************************************************//**49/*********************************************************************//**
50Makes a copy of the oldest existing read view, or opens a new. The view50Makes a copy of the oldest existing read view, or opens a new. The view
51must be closed with ..._close.51must be closed with ..._close.
@@ -56,8 +56,8 @@
56/*==============================*/56/*==============================*/
57 trx_id_t cr_trx_id, /*!< in: trx_id of creating57 trx_id_t cr_trx_id, /*!< in: trx_id of creating
58 transaction, or 0 used in purge */58 transaction, or 0 used in purge */
59 mem_heap_t* heap); /*!< in: memory heap from which59 read_view_t* view); /*!< in: pre-allocated view array or
60 allocated */60 NULL if a new one needs to be created */
61/*********************************************************************//**61/*********************************************************************//**
62Closes a read view. */62Closes a read view. */
63UNIV_INTERN63UNIV_INTERN
@@ -66,6 +66,13 @@
66/*============*/66/*============*/
67 read_view_t* view); /*!< in: read view */67 read_view_t* view); /*!< in: read view */
68/*********************************************************************//**68/*********************************************************************//**
69Frees memory allocated by a read view. */
70UNIV_INTERN
71void
72read_view_free(
73/*===========*/
74 read_view_t* view); /*< in: read view */
75/*********************************************************************//**
69Closes a consistent read view for MySQL. This function is called at an SQL76Closes a consistent read view for MySQL. This function is called at an SQL
70statement end if the trx isolation level is <= TRX_ISO_READ_COMMITTED. */77statement end if the trx isolation level is <= TRX_ISO_READ_COMMITTED. */
71UNIV_INTERN78UNIV_INTERN
@@ -145,6 +152,9 @@
145 this is the "low water mark". */152 this is the "low water mark". */
146 ulint n_trx_ids;153 ulint n_trx_ids;
147 /*!< Number of cells in the trx_ids array */154 /*!< Number of cells in the trx_ids array */
155 ulint max_trx_ids;
156 /*!< Maximum number of cells in the trx_ids
157 array */
148 trx_id_t* trx_ids;/*!< Additional trx ids which the read should158 trx_id_t* trx_ids;/*!< Additional trx ids which the read should
149 not see: typically, these are the active159 not see: typically, these are the active
150 transactions at the time when the read is160 transactions at the time when the read is
151161
=== modified file 'Percona-Server/storage/innobase/include/trx0purge.h'
--- Percona-Server/storage/innobase/include/trx0purge.h 2013-02-18 04:48:10 +0000
+++ Percona-Server/storage/innobase/include/trx0purge.h 2013-03-15 09:57:21 +0000
@@ -143,6 +143,7 @@
143 obtaining an s-latch here. */143 obtaining an s-latch here. */
144 read_view_t* view; /*!< The purge will not remove undo logs144 read_view_t* view; /*!< The purge will not remove undo logs
145 which are >= this view (purge view) */145 which are >= this view (purge view) */
146 read_view_t* prebuilt_view; /*!< Pre-built view array */
146 ulonglong n_pages_handled;/*!< Approximate number of undo log147 ulonglong n_pages_handled;/*!< Approximate number of undo log
147 pages processed in purge */148 pages processed in purge */
148 ulonglong handle_limit; /*!< Target of how many pages to get149 ulonglong handle_limit; /*!< Target of how many pages to get
149150
=== modified file 'Percona-Server/storage/innobase/include/trx0trx.h'
--- Percona-Server/storage/innobase/include/trx0trx.h 2012-05-10 07:49:14 +0000
+++ Percona-Server/storage/innobase/include/trx0trx.h 2013-03-15 09:57:21 +0000
@@ -686,9 +686,6 @@
686 UT_LIST_BASE_NODE_T(lock_t)686 UT_LIST_BASE_NODE_T(lock_t)
687 trx_locks; /*!< locks reserved by the transaction */687 trx_locks; /*!< locks reserved by the transaction */
688 /*------------------------------*/688 /*------------------------------*/
689 mem_heap_t* global_read_view_heap;
690 /* memory heap for the global read
691 view */
692 read_view_t* global_read_view;689 read_view_t* global_read_view;
693 /* consistent read view associated690 /* consistent read view associated
694 to a transaction or NULL */691 to a transaction or NULL */
@@ -698,6 +695,7 @@
698 associated to a transaction (i.e.695 associated to a transaction (i.e.
699 same as global_read_view) or read view696 same as global_read_view) or read view
700 associated to a cursor */697 associated to a cursor */
698 read_view_t* prebuilt_view; /* pre-built view array */
701 /*------------------------------*/699 /*------------------------------*/
702 UT_LIST_BASE_NODE_T(trx_named_savept_t)700 UT_LIST_BASE_NODE_T(trx_named_savept_t)
703 trx_savepoints; /*!< savepoints set with SAVEPOINT ...,701 trx_savepoints; /*!< savepoints set with SAVEPOINT ...,
704702
=== modified file 'Percona-Server/storage/innobase/read/read0read.c'
--- Percona-Server/storage/innobase/read/read0read.c 2012-04-18 23:24:45 +0000
+++ Percona-Server/storage/innobase/read/read0read.c 2013-03-15 09:57:21 +0000
@@ -145,14 +145,27 @@
145read_view_create_low(145read_view_create_low(
146/*=================*/146/*=================*/
147 ulint n, /*!< in: number of cells in the trx_ids array */147 ulint n, /*!< in: number of cells in the trx_ids array */
148 mem_heap_t* heap) /*!< in: memory heap from which allocated */148 read_view_t* view) /*!< in: pre-allocated view array or NULL if a
149 new one needs to be created */
149{150{
150 read_view_t* view;151 if (view == NULL) {
151152 view = ut_malloc(sizeof(read_view_t));
152 view = mem_heap_alloc(heap, sizeof(read_view_t));153 view->max_trx_ids = 0;
154 view->trx_ids = NULL;
155 }
156
157 if (UNIV_UNLIKELY(view->max_trx_ids < n)) {
158
159 /* avoid frequent reallocations by extending the array to the
160 desired size + 10% */
161
162 view->max_trx_ids = n + n / 10;
163 view->trx_ids = ut_realloc(view->trx_ids,
164 view->max_trx_ids *
165 sizeof *view->trx_ids);
166 }
153167
154 view->n_trx_ids = n;168 view->n_trx_ids = n;
155 view->trx_ids = mem_heap_alloc(heap, n * sizeof *view->trx_ids);
156169
157 return(view);170 return(view);
158}171}
@@ -169,8 +182,8 @@
169/*==============================*/182/*==============================*/
170 trx_id_t cr_trx_id, /*!< in: trx_id of creating183 trx_id_t cr_trx_id, /*!< in: trx_id of creating
171 transaction, or 0 used in purge */184 transaction, or 0 used in purge */
172 mem_heap_t* heap) /*!< in: memory heap from which185 read_view_t* view) /*!< in: pre-allocated view array or
173 allocated */186 NULL if a new one needs to be created */
174{187{
175 read_view_t* old_view;188 read_view_t* old_view;
176 read_view_t* view_copy;189 read_view_t* view_copy;
@@ -185,7 +198,7 @@
185198
186 if (old_view == NULL) {199 if (old_view == NULL) {
187200
188 return(read_view_open_now(cr_trx_id, heap));201 return(read_view_open_now(cr_trx_id, view));
189 }202 }
190203
191 n = old_view->n_trx_ids;204 n = old_view->n_trx_ids;
@@ -196,7 +209,7 @@
196 needs_insert = FALSE;209 needs_insert = FALSE;
197 }210 }
198211
199 view_copy = read_view_create_low(n, heap);212 view_copy = read_view_create_low(n, view);
200213
201 /* Insert the id of the creator in the right place of the descending214 /* Insert the id of the creator in the right place of the descending
202 array of ids, if needs_insert is TRUE: */215 array of ids, if needs_insert is TRUE: */
@@ -251,16 +264,15 @@
251/*===============*/264/*===============*/
252 trx_id_t cr_trx_id, /*!< in: trx_id of creating265 trx_id_t cr_trx_id, /*!< in: trx_id of creating
253 transaction, or 0 used in purge */266 transaction, or 0 used in purge */
254 mem_heap_t* heap) /*!< in: memory heap from which267 read_view_t* view) /*!< in: current read view or NULL if it
255 allocated */268 doesn't exist yet */
256{269{
257 read_view_t* view;
258 trx_t* trx;270 trx_t* trx;
259 ulint n;271 ulint n;
260272
261 ut_ad(mutex_own(&kernel_mutex));273 ut_ad(mutex_own(&kernel_mutex));
262274
263 view = read_view_create_low(UT_LIST_GET_LEN(trx_sys->trx_list), heap);275 view = read_view_create_low(UT_LIST_GET_LEN(trx_sys->trx_list), view);
264276
265 view->creator_trx_id = cr_trx_id;277 view->creator_trx_id = cr_trx_id;
266 view->type = VIEW_NORMAL;278 view->type = VIEW_NORMAL;
@@ -329,6 +341,23 @@
329}341}
330342
331/*********************************************************************//**343/*********************************************************************//**
344Frees resource allocated by a read view. */
345UNIV_INTERN
346void
347read_view_free(
348/*===========*/
349 read_view_t* view) /*< in: read view */
350{
351 ut_ad(mutex_own(&kernel_mutex));
352
353 if (view->trx_ids != NULL) {
354 ut_free(view->trx_ids);
355 }
356
357 ut_free(view);
358}
359
360/*********************************************************************//**
332Closes a consistent read view for MySQL. This function is called at an SQL361Closes a consistent read view for MySQL. This function is called at an SQL
333statement end if the trx isolation level is <= TRX_ISO_READ_COMMITTED. */362statement end if the trx isolation level is <= TRX_ISO_READ_COMMITTED. */
334UNIV_INTERN363UNIV_INTERN
@@ -343,8 +372,6 @@
343372
344 read_view_close(trx->global_read_view);373 read_view_close(trx->global_read_view);
345374
346 mem_heap_empty(trx->global_read_view_heap);
347
348 trx->read_view = NULL;375 trx->read_view = NULL;
349 trx->global_read_view = NULL;376 trx->global_read_view = NULL;
350377
@@ -425,7 +452,7 @@
425 mutex_enter(&kernel_mutex);452 mutex_enter(&kernel_mutex);
426453
427 curview->read_view = read_view_create_low(454 curview->read_view = read_view_create_low(
428 UT_LIST_GET_LEN(trx_sys->trx_list), curview->heap);455 UT_LIST_GET_LEN(trx_sys->trx_list), NULL);
429456
430 view = curview->read_view;457 view = curview->read_view;
431 view->creator_trx_id = cr_trx->id;458 view->creator_trx_id = cr_trx->id;
@@ -503,6 +530,8 @@
503 mutex_enter(&kernel_mutex);530 mutex_enter(&kernel_mutex);
504531
505 read_view_close(curview->read_view);532 read_view_close(curview->read_view);
533 read_view_free(curview->read_view);
534
506 trx->read_view = trx->global_read_view;535 trx->read_view = trx->global_read_view;
507536
508 mutex_exit(&kernel_mutex);537 mutex_exit(&kernel_mutex);
509538
=== modified file 'Percona-Server/storage/innobase/row/row0sel.c'
--- Percona-Server/storage/innobase/row/row0sel.c 2013-02-21 12:47:29 +0000
+++ Percona-Server/storage/innobase/row/row0sel.c 2013-03-15 09:57:21 +0000
@@ -4897,7 +4897,7 @@
4897 && !trx->read_view) {4897 && !trx->read_view) {
48984898
4899 trx->read_view = read_view_open_now(4899 trx->read_view = read_view_open_now(
4900 trx->id, trx->global_read_view_heap);4900 trx->id, NULL);
4901 trx->global_read_view = trx->read_view;4901 trx->global_read_view = trx->read_view;
4902 }4902 }
4903 }4903 }
49044904
=== modified file 'Percona-Server/storage/innobase/trx/trx0purge.c'
--- Percona-Server/storage/innobase/trx/trx0purge.c 2013-02-18 04:48:10 +0000
+++ Percona-Server/storage/innobase/trx/trx0purge.c 2013-03-15 09:57:21 +0000
@@ -263,8 +263,9 @@
263263
264 purge_sys->query = trx_purge_graph_build();264 purge_sys->query = trx_purge_graph_build();
265265
266 purge_sys->view = read_view_oldest_copy_or_open_new(0,266 purge_sys->prebuilt_view =
267 purge_sys->heap);267 read_view_oldest_copy_or_open_new(0, NULL);
268 purge_sys->view = purge_sys->prebuilt_view;
268}269}
269270
270/************************************************************************271/************************************************************************
@@ -289,6 +290,8 @@
289 mutex_enter(&kernel_mutex);290 mutex_enter(&kernel_mutex);
290291
291 read_view_close(purge_sys->view);292 read_view_close(purge_sys->view);
293 read_view_free(purge_sys->prebuilt_view);
294 purge_sys->prebuilt_view = NULL;
292 purge_sys->view = NULL;295 purge_sys->view = NULL;
293296
294 mutex_exit(&kernel_mutex);297 mutex_exit(&kernel_mutex);
@@ -1177,7 +1180,7 @@
1177 }1180 }
11781181
1179 purge_sys->view = read_view_oldest_copy_or_open_new(1182 purge_sys->view = read_view_oldest_copy_or_open_new(
1180 0, purge_sys->heap);1183 0, purge_sys->prebuilt_view);
11811184
1182 mutex_exit(&kernel_mutex);1185 mutex_exit(&kernel_mutex);
11831186
11841187
=== modified file 'Percona-Server/storage/innobase/trx/trx0trx.c'
--- Percona-Server/storage/innobase/trx/trx0trx.c 2013-02-26 09:00:37 +0000
+++ Percona-Server/storage/innobase/trx/trx0trx.c 2013-03-15 09:57:21 +0000
@@ -190,9 +190,9 @@
190 trx->declared_to_be_inside_innodb = FALSE;190 trx->declared_to_be_inside_innodb = FALSE;
191 trx->n_tickets_to_enter_innodb = 0;191 trx->n_tickets_to_enter_innodb = 0;
192192
193 trx->global_read_view_heap = mem_heap_create(256);
194 trx->global_read_view = NULL;193 trx->global_read_view = NULL;
195 trx->read_view = NULL;194 trx->read_view = NULL;
195 trx->prebuilt_view = NULL;
196196
197 trx->io_reads = 0;197 trx->io_reads = 0;
198 trx->io_read = 0;198 trx->io_read = 0;
@@ -355,11 +355,12 @@
355355
356 ut_a(UT_LIST_GET_LEN(trx->trx_locks) == 0);356 ut_a(UT_LIST_GET_LEN(trx->trx_locks) == 0);
357357
358 if (trx->global_read_view_heap) {358 if (trx->prebuilt_view != NULL) {
359 mem_heap_free(trx->global_read_view_heap);359 read_view_free(trx->prebuilt_view);
360 }360 }
361361
362 trx->global_read_view = NULL;362 trx->global_read_view = NULL;
363 trx->prebuilt_view = NULL;
363364
364 ut_a(trx->read_view == NULL);365 ut_a(trx->read_view == NULL);
365366
@@ -412,10 +413,6 @@
412 mem_heap_free(trx->lock_heap);413 mem_heap_free(trx->lock_heap);
413 }414 }
414415
415 if (trx->global_read_view_heap) {
416 mem_heap_free(trx->global_read_view_heap);
417 }
418
419 ut_a(ib_vector_is_empty(trx->autoinc_locks));416 ut_a(ib_vector_is_empty(trx->autoinc_locks));
420 ib_vector_free(trx->autoinc_locks);417 ib_vector_free(trx->autoinc_locks);
421418
@@ -1045,7 +1042,6 @@
10451042
1046 if (trx->global_read_view) {1043 if (trx->global_read_view) {
1047 read_view_close(trx->global_read_view);1044 read_view_close(trx->global_read_view);
1048 mem_heap_empty(trx->global_read_view_heap);
1049 trx->global_read_view = NULL;1045 trx->global_read_view = NULL;
1050 }1046 }
10511047
@@ -1187,8 +1183,9 @@
1187 mutex_enter(&kernel_mutex);1183 mutex_enter(&kernel_mutex);
11881184
1189 if (!trx->read_view) {1185 if (!trx->read_view) {
1190 trx->read_view = read_view_open_now(1186 trx->read_view = read_view_open_now(trx->id,
1191 trx->id, trx->global_read_view_heap);1187 trx->prebuilt_view);
1188 trx->prebuilt_view = trx->read_view;
1192 trx->global_read_view = trx->read_view;1189 trx->global_read_view = trx->read_view;
1193 }1190 }
11941191

Subscribers

People subscribed via source and target branches