Merge lp:~alien-d/maria/mariadb-al13n-bug_886368 into lp:maria/5.5

Proposed by Maarten Vanraes
Status: Needs review
Proposed branch: lp:~alien-d/maria/mariadb-al13n-bug_886368
Merge into: lp:maria/5.5
Diff against target: 129 lines (+66/-38)
1 file modified
sql/mysqld.cc (+66/-38)
To merge this branch: bzr merge lp:~alien-d/maria/mariadb-al13n-bug_886368
Reviewer Review Type Date Requested Status
Maria-captains Pending
Review via email: mp+82950@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

3152. By Maarten Vanraes

see bug 886368

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'sql/mysqld.cc'
2--- sql/mysqld.cc 2011-11-02 13:10:09 +0000
3+++ sql/mysqld.cc 2011-11-21 23:55:27 +0000
4@@ -3020,6 +3020,70 @@
5 }
6
7
8+/* pthread_attr_setstacksize without so much platform-dependency */
9+/* returns the actual stack size if possible */
10+static size_t my_setstacksize(pthread_attr_t *attr, size_t stacksize)
11+{
12+ size_t guard_size = 0;
13+
14+#if defined(__ia64__) || defined(__ia64)
15+ /*
16+ On IA64, half of the requested stack size is used for "normal stack"
17+ and half for "register stack". The space measured by check_stack_overrun
18+ is the "normal stack", so double the request to make sure we have the
19+ caller-expected amount of normal stack.
20+
21+ NOTE: there is no guarantee that the register stack can't grow faster
22+ than normal stack, so it's very unclear that we won't dump core due to
23+ stack overrun despite check_stack_overrun's efforts. Experimentation
24+ shows that in the execution_constants test, the register stack grows
25+ less than half as fast as normal stack, but perhaps other scenarios are
26+ less forgiving. If it turns out that more space is needed for the
27+ register stack, that could be forced (rather inefficiently) by using a
28+ multiplier higher than 2 here.
29+ */
30+ stacksize *= 2;
31+#endif
32+
33+ /*
34+ On many machines, the "guard space" is subtracted from the requested
35+ stack size, and that space is quite large on some platforms. So add
36+ it to our request, if we can find out what it is.
37+
38+ FIXME: autoconfiscate use of pthread_attr_getguardsize
39+ */
40+ if (pthread_attr_getguardsize(attr, &guard_size))
41+ guard_size = 0; /* if can't find it out, treat as 0 */
42+
43+ pthread_attr_setstacksize(attr, stacksize + guard_size);
44+
45+ /* Retrieve actual stack size if possible */
46+#ifdef HAVE_PTHREAD_ATTR_GETSTACKSIZE
47+ {
48+ size_t real_stack_size= 0;
49+ /* We must ignore real_stack_size = 0 as Solaris 2.9 can return 0 here */
50+ if (pthread_attr_getstacksize(attr, &real_stack_size) == 0 &&
51+ real_stack_size > guard_size)
52+ {
53+ real_stack_size -= guard_size;
54+ if (real_stack_size < stacksize)
55+ {
56+ if (global_system_variables.log_warnings)
57+ sql_print_warning("Asked for %ld thread stack, but got %ld",
58+ (long) stacksize, (long) real_stack_size);
59+ stacksize= real_stack_size;
60+ }
61+ }
62+ }
63+#endif
64+
65+#if defined(__ia64__) || defined(__ia64)
66+ stacksize /= 2;
67+#endif
68+ return stacksize;
69+}
70+
71+
72 static void start_signal_handler(void)
73 {
74 int error;
75@@ -3030,15 +3094,7 @@
76 #if !defined(HAVE_DEC_3_2_THREADS)
77 pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_SYSTEM);
78 (void) pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED);
79-#if defined(__ia64__) || defined(__ia64)
80- /*
81- Peculiar things with ia64 platforms - it seems we only have half the
82- stack size in reality, so we have to double it here
83- */
84- pthread_attr_setstacksize(&thr_attr,my_thread_stack_size*2);
85-#else
86- pthread_attr_setstacksize(&thr_attr,my_thread_stack_size);
87-#endif
88+ (void) my_setstacksize(&thr_attr,my_thread_stack_size);
89 #endif
90
91 mysql_mutex_lock(&LOCK_thread_count);
92@@ -4856,36 +4912,8 @@
93 unireg_abort(1); // Will do exit
94
95 init_signals();
96-#if defined(__ia64__) || defined(__ia64)
97- /*
98- Peculiar things with ia64 platforms - it seems we only have half the
99- stack size in reality, so we have to double it here
100- */
101- pthread_attr_setstacksize(&connection_attrib,my_thread_stack_size*2);
102-#else
103- pthread_attr_setstacksize(&connection_attrib,my_thread_stack_size);
104-#endif
105 #ifdef HAVE_PTHREAD_ATTR_GETSTACKSIZE
106- {
107- /* Retrieve used stack size; Needed for checking stack overflows */
108- size_t stack_size= 0;
109- pthread_attr_getstacksize(&connection_attrib, &stack_size);
110-#if defined(__ia64__) || defined(__ia64)
111- stack_size/= 2;
112-#endif
113- /* We must check if stack_size = 0 as Solaris 2.9 can return 0 here */
114- if (stack_size && stack_size < my_thread_stack_size)
115- {
116- if (global_system_variables.log_warnings)
117- sql_print_warning("Asked for %lu thread stack, but got %ld",
118- my_thread_stack_size, (long) stack_size);
119-#if defined(__ia64__) || defined(__ia64)
120- my_thread_stack_size= stack_size*2;
121-#else
122- my_thread_stack_size= stack_size;
123-#endif
124- }
125- }
126+ my_thread_stack_size = my_setstacksize(&connection_attrib,my_thread_stack_size);
127 #endif
128
129 (void) thr_setconcurrency(concurrency); // 10 by default

Subscribers

People subscribed via source and target branches