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
1=== modified file 'Percona-Server/storage/innobase/include/read0read.h'
2--- Percona-Server/storage/innobase/include/read0read.h 2012-04-18 23:24:45 +0000
3+++ Percona-Server/storage/innobase/include/read0read.h 2013-03-15 09:57:21 +0000
4@@ -44,8 +44,8 @@
5 /*===============*/
6 trx_id_t cr_trx_id, /*!< in: trx_id of creating
7 transaction, or 0 used in purge */
8- mem_heap_t* heap); /*!< in: memory heap from which
9- allocated */
10+ read_view_t* view); /*!< in: pre-allocated view array or
11+ NULL if a new one needs to be created */
12 /*********************************************************************//**
13 Makes a copy of the oldest existing read view, or opens a new. The view
14 must be closed with ..._close.
15@@ -56,8 +56,8 @@
16 /*==============================*/
17 trx_id_t cr_trx_id, /*!< in: trx_id of creating
18 transaction, or 0 used in purge */
19- mem_heap_t* heap); /*!< in: memory heap from which
20- allocated */
21+ read_view_t* view); /*!< in: pre-allocated view array or
22+ NULL if a new one needs to be created */
23 /*********************************************************************//**
24 Closes a read view. */
25 UNIV_INTERN
26@@ -66,6 +66,13 @@
27 /*============*/
28 read_view_t* view); /*!< in: read view */
29 /*********************************************************************//**
30+Frees memory allocated by a read view. */
31+UNIV_INTERN
32+void
33+read_view_free(
34+/*===========*/
35+ read_view_t* view); /*< in: read view */
36+/*********************************************************************//**
37 Closes a consistent read view for MySQL. This function is called at an SQL
38 statement end if the trx isolation level is <= TRX_ISO_READ_COMMITTED. */
39 UNIV_INTERN
40@@ -145,6 +152,9 @@
41 this is the "low water mark". */
42 ulint n_trx_ids;
43 /*!< Number of cells in the trx_ids array */
44+ ulint max_trx_ids;
45+ /*!< Maximum number of cells in the trx_ids
46+ array */
47 trx_id_t* trx_ids;/*!< Additional trx ids which the read should
48 not see: typically, these are the active
49 transactions at the time when the read is
50
51=== modified file 'Percona-Server/storage/innobase/include/trx0purge.h'
52--- Percona-Server/storage/innobase/include/trx0purge.h 2013-02-18 04:48:10 +0000
53+++ Percona-Server/storage/innobase/include/trx0purge.h 2013-03-15 09:57:21 +0000
54@@ -143,6 +143,7 @@
55 obtaining an s-latch here. */
56 read_view_t* view; /*!< The purge will not remove undo logs
57 which are >= this view (purge view) */
58+ read_view_t* prebuilt_view; /*!< Pre-built view array */
59 ulonglong n_pages_handled;/*!< Approximate number of undo log
60 pages processed in purge */
61 ulonglong handle_limit; /*!< Target of how many pages to get
62
63=== modified file 'Percona-Server/storage/innobase/include/trx0trx.h'
64--- Percona-Server/storage/innobase/include/trx0trx.h 2012-05-10 07:49:14 +0000
65+++ Percona-Server/storage/innobase/include/trx0trx.h 2013-03-15 09:57:21 +0000
66@@ -686,9 +686,6 @@
67 UT_LIST_BASE_NODE_T(lock_t)
68 trx_locks; /*!< locks reserved by the transaction */
69 /*------------------------------*/
70- mem_heap_t* global_read_view_heap;
71- /* memory heap for the global read
72- view */
73 read_view_t* global_read_view;
74 /* consistent read view associated
75 to a transaction or NULL */
76@@ -698,6 +695,7 @@
77 associated to a transaction (i.e.
78 same as global_read_view) or read view
79 associated to a cursor */
80+ read_view_t* prebuilt_view; /* pre-built view array */
81 /*------------------------------*/
82 UT_LIST_BASE_NODE_T(trx_named_savept_t)
83 trx_savepoints; /*!< savepoints set with SAVEPOINT ...,
84
85=== modified file 'Percona-Server/storage/innobase/read/read0read.c'
86--- Percona-Server/storage/innobase/read/read0read.c 2012-04-18 23:24:45 +0000
87+++ Percona-Server/storage/innobase/read/read0read.c 2013-03-15 09:57:21 +0000
88@@ -145,14 +145,27 @@
89 read_view_create_low(
90 /*=================*/
91 ulint n, /*!< in: number of cells in the trx_ids array */
92- mem_heap_t* heap) /*!< in: memory heap from which allocated */
93+ read_view_t* view) /*!< in: pre-allocated view array or NULL if a
94+ new one needs to be created */
95 {
96- read_view_t* view;
97-
98- view = mem_heap_alloc(heap, sizeof(read_view_t));
99+ if (view == NULL) {
100+ view = ut_malloc(sizeof(read_view_t));
101+ view->max_trx_ids = 0;
102+ view->trx_ids = NULL;
103+ }
104+
105+ if (UNIV_UNLIKELY(view->max_trx_ids < n)) {
106+
107+ /* avoid frequent reallocations by extending the array to the
108+ desired size + 10% */
109+
110+ view->max_trx_ids = n + n / 10;
111+ view->trx_ids = ut_realloc(view->trx_ids,
112+ view->max_trx_ids *
113+ sizeof *view->trx_ids);
114+ }
115
116 view->n_trx_ids = n;
117- view->trx_ids = mem_heap_alloc(heap, n * sizeof *view->trx_ids);
118
119 return(view);
120 }
121@@ -169,8 +182,8 @@
122 /*==============================*/
123 trx_id_t cr_trx_id, /*!< in: trx_id of creating
124 transaction, or 0 used in purge */
125- mem_heap_t* heap) /*!< in: memory heap from which
126- allocated */
127+ read_view_t* view) /*!< in: pre-allocated view array or
128+ NULL if a new one needs to be created */
129 {
130 read_view_t* old_view;
131 read_view_t* view_copy;
132@@ -185,7 +198,7 @@
133
134 if (old_view == NULL) {
135
136- return(read_view_open_now(cr_trx_id, heap));
137+ return(read_view_open_now(cr_trx_id, view));
138 }
139
140 n = old_view->n_trx_ids;
141@@ -196,7 +209,7 @@
142 needs_insert = FALSE;
143 }
144
145- view_copy = read_view_create_low(n, heap);
146+ view_copy = read_view_create_low(n, view);
147
148 /* Insert the id of the creator in the right place of the descending
149 array of ids, if needs_insert is TRUE: */
150@@ -251,16 +264,15 @@
151 /*===============*/
152 trx_id_t cr_trx_id, /*!< in: trx_id of creating
153 transaction, or 0 used in purge */
154- mem_heap_t* heap) /*!< in: memory heap from which
155- allocated */
156+ read_view_t* view) /*!< in: current read view or NULL if it
157+ doesn't exist yet */
158 {
159- read_view_t* view;
160 trx_t* trx;
161 ulint n;
162
163 ut_ad(mutex_own(&kernel_mutex));
164
165- view = read_view_create_low(UT_LIST_GET_LEN(trx_sys->trx_list), heap);
166+ view = read_view_create_low(UT_LIST_GET_LEN(trx_sys->trx_list), view);
167
168 view->creator_trx_id = cr_trx_id;
169 view->type = VIEW_NORMAL;
170@@ -329,6 +341,23 @@
171 }
172
173 /*********************************************************************//**
174+Frees resource allocated by a read view. */
175+UNIV_INTERN
176+void
177+read_view_free(
178+/*===========*/
179+ read_view_t* view) /*< in: read view */
180+{
181+ ut_ad(mutex_own(&kernel_mutex));
182+
183+ if (view->trx_ids != NULL) {
184+ ut_free(view->trx_ids);
185+ }
186+
187+ ut_free(view);
188+}
189+
190+/*********************************************************************//**
191 Closes a consistent read view for MySQL. This function is called at an SQL
192 statement end if the trx isolation level is <= TRX_ISO_READ_COMMITTED. */
193 UNIV_INTERN
194@@ -343,8 +372,6 @@
195
196 read_view_close(trx->global_read_view);
197
198- mem_heap_empty(trx->global_read_view_heap);
199-
200 trx->read_view = NULL;
201 trx->global_read_view = NULL;
202
203@@ -425,7 +452,7 @@
204 mutex_enter(&kernel_mutex);
205
206 curview->read_view = read_view_create_low(
207- UT_LIST_GET_LEN(trx_sys->trx_list), curview->heap);
208+ UT_LIST_GET_LEN(trx_sys->trx_list), NULL);
209
210 view = curview->read_view;
211 view->creator_trx_id = cr_trx->id;
212@@ -503,6 +530,8 @@
213 mutex_enter(&kernel_mutex);
214
215 read_view_close(curview->read_view);
216+ read_view_free(curview->read_view);
217+
218 trx->read_view = trx->global_read_view;
219
220 mutex_exit(&kernel_mutex);
221
222=== modified file 'Percona-Server/storage/innobase/row/row0sel.c'
223--- Percona-Server/storage/innobase/row/row0sel.c 2013-02-21 12:47:29 +0000
224+++ Percona-Server/storage/innobase/row/row0sel.c 2013-03-15 09:57:21 +0000
225@@ -4897,7 +4897,7 @@
226 && !trx->read_view) {
227
228 trx->read_view = read_view_open_now(
229- trx->id, trx->global_read_view_heap);
230+ trx->id, NULL);
231 trx->global_read_view = trx->read_view;
232 }
233 }
234
235=== modified file 'Percona-Server/storage/innobase/trx/trx0purge.c'
236--- Percona-Server/storage/innobase/trx/trx0purge.c 2013-02-18 04:48:10 +0000
237+++ Percona-Server/storage/innobase/trx/trx0purge.c 2013-03-15 09:57:21 +0000
238@@ -263,8 +263,9 @@
239
240 purge_sys->query = trx_purge_graph_build();
241
242- purge_sys->view = read_view_oldest_copy_or_open_new(0,
243- purge_sys->heap);
244+ purge_sys->prebuilt_view =
245+ read_view_oldest_copy_or_open_new(0, NULL);
246+ purge_sys->view = purge_sys->prebuilt_view;
247 }
248
249 /************************************************************************
250@@ -289,6 +290,8 @@
251 mutex_enter(&kernel_mutex);
252
253 read_view_close(purge_sys->view);
254+ read_view_free(purge_sys->prebuilt_view);
255+ purge_sys->prebuilt_view = NULL;
256 purge_sys->view = NULL;
257
258 mutex_exit(&kernel_mutex);
259@@ -1177,7 +1180,7 @@
260 }
261
262 purge_sys->view = read_view_oldest_copy_or_open_new(
263- 0, purge_sys->heap);
264+ 0, purge_sys->prebuilt_view);
265
266 mutex_exit(&kernel_mutex);
267
268
269=== modified file 'Percona-Server/storage/innobase/trx/trx0trx.c'
270--- Percona-Server/storage/innobase/trx/trx0trx.c 2013-02-26 09:00:37 +0000
271+++ Percona-Server/storage/innobase/trx/trx0trx.c 2013-03-15 09:57:21 +0000
272@@ -190,9 +190,9 @@
273 trx->declared_to_be_inside_innodb = FALSE;
274 trx->n_tickets_to_enter_innodb = 0;
275
276- trx->global_read_view_heap = mem_heap_create(256);
277 trx->global_read_view = NULL;
278 trx->read_view = NULL;
279+ trx->prebuilt_view = NULL;
280
281 trx->io_reads = 0;
282 trx->io_read = 0;
283@@ -355,11 +355,12 @@
284
285 ut_a(UT_LIST_GET_LEN(trx->trx_locks) == 0);
286
287- if (trx->global_read_view_heap) {
288- mem_heap_free(trx->global_read_view_heap);
289+ if (trx->prebuilt_view != NULL) {
290+ read_view_free(trx->prebuilt_view);
291 }
292
293 trx->global_read_view = NULL;
294+ trx->prebuilt_view = NULL;
295
296 ut_a(trx->read_view == NULL);
297
298@@ -412,10 +413,6 @@
299 mem_heap_free(trx->lock_heap);
300 }
301
302- if (trx->global_read_view_heap) {
303- mem_heap_free(trx->global_read_view_heap);
304- }
305-
306 ut_a(ib_vector_is_empty(trx->autoinc_locks));
307 ib_vector_free(trx->autoinc_locks);
308
309@@ -1045,7 +1042,6 @@
310
311 if (trx->global_read_view) {
312 read_view_close(trx->global_read_view);
313- mem_heap_empty(trx->global_read_view_heap);
314 trx->global_read_view = NULL;
315 }
316
317@@ -1187,8 +1183,9 @@
318 mutex_enter(&kernel_mutex);
319
320 if (!trx->read_view) {
321- trx->read_view = read_view_open_now(
322- trx->id, trx->global_read_view_heap);
323+ trx->read_view = read_view_open_now(trx->id,
324+ trx->prebuilt_view);
325+ trx->prebuilt_view = trx->read_view;
326 trx->global_read_view = trx->read_view;
327 }
328

Subscribers

People subscribed via source and target branches