[ovs-dev] [PATCH][V3] lib/ovs-thread: enforce min thread stack size to 512k
Alexandru Ardelean
ardeleanalex at gmail.com
Thu Feb 4 07:20:34 UTC 2016
In case of certain libc implementations (such as musl libc)
that have a really small default pthread stack size.
Will reference this discussion:
http://patchwork.ozlabs.org/patch/572340/
Thanks to Robert McKay for reporting and Russel and Ben
for reviewing.
Signed-off-by: Russell Bryant <russell at ovn.org>
Signed-off-by: Ben Pfaff <blp at ovn.org>
Signed-off-by: Robert McKay <robert at mckay.com>
Signed-off-by: Alexandru Ardelean <ardeleanalex at gmail.com>
---
lib/ovs-thread.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index 6ebda07..b6684d4 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -345,8 +345,11 @@ ovsthread_wrapper(void *aux_)
pthread_t
ovs_thread_create(const char *name, void *(*start)(void *), void *arg)
{
+#define OVS_MIN_THREAD_STACK_SIZE (512 * 1024)
struct ovsthread_aux *aux;
pthread_t thread;
+ pthread_attr_t attr;
+ size_t stacksize;
int error;
forbid_forking("multiple threads exist");
@@ -358,10 +361,29 @@ ovs_thread_create(const char *name, void *(*start)(void *), void *arg)
aux->arg = arg;
ovs_strlcpy(aux->name, name, sizeof aux->name);
+ pthread_attr_init(&attr);
+ error = pthread_attr_getstacksize(&attr, &stacksize);
+ if (error) {
+ free(aux);
+ ovs_abort(error, "pthread_attr_getstacksize failed");
+ goto out;
+ }
+
+ if (stacksize < OVS_MIN_THREAD_STACK_SIZE) {
+ error = pthread_attr_setstacksize(&attr, OVS_MIN_THREAD_STACK_SIZE);
+ if (error) {
+ free(aux);
+ ovs_abort(error, "pthread_attr_setstacksize failed");
+ goto out;
+ }
+ }
+
error = pthread_create(&thread, NULL, ovsthread_wrapper, aux);
if (error) {
ovs_abort(error, "pthread_create failed");
}
+out:
+ pthread_attr_destroy(&attr);
return thread;
}
--
2.1.4
More information about the dev
mailing list